android 4.4 屏幕方向,Android4.4屏幕旋转功能
由于Android4.4系統上去掉了ro.sf.hwrotation屬性的支持,因為不能使用之前的方法進行屏幕旋轉了。暫時沒有找到相應的屬性和后門,于是自己寫了一個屏幕旋轉的臨時代碼,后面找到更好的方法后再替換。具體代碼如下:
~/framework/native/services/surfaceflinger/DisplayDevice.cpp
uint32_t DisplayDevice::getOrientationTransform() const {
...
if (property_get("persist.sys.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
transform = Transform::ROT_90;
break;
case 270:
transform = Transform::ROT_270;
break;
}
}
return transform;
}
status_t DisplayDevice::orientationToTransfrom(
int orientation, int w, int h, Transform* tr)
{
...
if (property_get("persist.sys.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
flags = Transform::ROT_90;
break;
case 270:
flags = Transform::ROT_270;
break;
}
}
tr->set(flags, w, h);
return NO_ERROR;
}
void DisplayDevice::setProjection(int orientation,
const Rect& newViewport, const Rect& newFrame) {
...
if (!frame.isValid()) {
if (property_get("persist.sys.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
case 270:
frame = Rect(h, w);
break;
default:
frame = Rect(w, h);
break;
}
} else
frame = Rect(w, h);
} else {
...
}
}
~/framework/base/services/input/InputReader.cpp
void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
...
if (property_get("persist.sys.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
mSurfaceOrientation = DISPLAY_ORIENTATION_90;
break;
case 270:
mSurfaceOrientation = DISPLAY_ORIENTATION_270;
break;
}
}
switch (mSurfaceOrientation) {
case DISPLAY_ORIENTATION_90:
case DISPLAY_ORIENTATION_270:
}
~/framework/native/services/surfaceflinger/SurfaceFlinger.cpp
status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo* info) {
...
info->w = hwc.getWidth(type);
info->h = hwc.getHeight(type);
if (property_get("persist.sys.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
case 270:
if (type != DisplayDevice::DISPLAY_EXTERNAL) {
info->w = hwc.getHeight(type);
info->h = hwc.getWidth(type);
}
break;
default:
break;
}
}
info->xdpi = xdpi;
info->ydpi = ydpi;
info->fps = float(1e9 / hwc.getRefreshPeriod(type));
...
}
void SurfaceFlinger::onInitializeDisplays() {
...
d.orientation = DisplayState::eOrientationDefault;
char property[PROPERTY_VALUE_MAX];
if (property_get("persist.sys.hwrotation", property, NULL) > 0){
switch (atoi(property)) {
case 0:
d.orientation = DisplayState::eOrientationDefault;
break;
case 90:
d.orientation = DisplayState::eOrientation90;
break;
case 180:
d.orientation = DisplayState::eOrientation180;
break;
case 270:
d.orientation = DisplayState::eOrientation270;
break;
default:
d.orientation = DisplayState::eOrientationDefault;
break;
}
} else {
d.orientation = DisplayState::eOrientationDefault;
}
d.frame.makeInvalid();
d.viewport.makeInvalid();
}
~/framework/base/services/java/com/android/server/wm/WindowManagerService.java
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
...
if (req != mForcedAppOrientation) {
if ("0".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
req = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
else if ("90".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
req = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
else if ("180".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
req = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
else if ("270".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
else
req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
...
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的android 4.4 屏幕方向,Android4.4屏幕旋转功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: l2-008 最长对称子串 (25分)_
- 下一篇: .net core razor ajax