关于Android4.x系统默认显示方向各种修改

分享到:

1.设置属性值

在device.mk文件中加入
PRODUCT_PROPERTY_OVERRIDES += \
ro.sf.hwrotation=180

2.设置屏幕默认显示方向

在frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp文件中找到方法

GraphicPlane::setDisplayHardware(DisplayHardware *hw)

if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
//displayOrientation
switch (atoi(property)) {
case 90:
displayOrientation = ISurfaceComposer::eOrientation90;
break;
case 270:
displayOrientation = ISurfaceComposer::eOrientation270;
break;
case 180://=============add========
displayOrientation = ISurfaceComposer::eOrientation180;
break;//=============add========
}
}


3.设置屏幕显示动画旋转方向

1).在frameworks/base/core/java/android/view/Surface.java 加入方法

/**
* @hide
*/
public static int getDefaultRotation() {
return android.os.SystemProperties.getInt("ro.sf.hwrotation", 0);
}
/**
* @hide
*/
public static int getDefaultRotationIndex() {
int rotation = getDefaultRotation();
switch(rotation) {
case 0:
return ROTATION_0;
case 90:
return ROTATION_90;
case 180:
return ROTATION_180;
case 270:
return ROTATION_270;

}
return ROTATION_0;
}
2).在frameworks/base/services/java/com/android/server/wm/ScreenRotationAnimation.java
文件中找到(android4.1) 方法setRotation

或(android4.2)方法setRotationInTransaction

修改 deltaRotation(rotation,Surface.ROTATION_0);

为deltaRotation(rotation,Surface. getDefaultRotationIndex());

 

3 .长按Home键,最近程序视图方向

在frameworks/base/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java 文件中修改如下

private int mThumbnailHeight;//================add============

在方法中添加

public void updateValuesFromResources() {
final Resources res = mContext.getResources();
mThumbnailWidth = Math.round(res.getDimension(R.dimen.status_bar_recents_thumbnail_width));
//==========================xjf=========================
mThumbnailHeight = Math.round(res.getDimension(R.dimen.status_bar_recents_thumbnail_height));
//==========================xjf=========================
mFitThumbnailToXY = res.getBoolean(R.bool.config_recents_thumbnail_image_fits_to_xy);
}

 

在方法中添加

private void updateThumbnail(ViewHolder h, Bitmap thumbnail, boolean show, boolean anim) {
。。。。。。。。。。。。。。。。

if (mFitThumbnailToXY) {
h.thumbnailViewImage.setScaleType(ScaleType.FIT_XY);
} else {
Matrix scaleMatrix = new Matrix();
float scale = mThumbnailWidth / (float) thumbnail.getWidth();
scaleMatrix.setScale(scale, scale);
h.thumbnailViewImage.setScaleType(ScaleType.MATRIX);
h.thumbnailViewImage.setImageMatrix(scaleMatrix);
//==========================xjf=========================
if(android.view.Surface.getDefaultRotation() > 0){
Matrix rotateMatrix = new Matrix();
rotateMatrix.setRotate(android.view.Surface.getDefaultRotation(),mThumbnailWidth/2, mThumbnailHeight/2);
h.thumbnailViewImage.setImageMatrix(rotateMatrix);
}
//==========================xjf=========================
}
}

 

4.电源键加音量减,截屏图片方向

在/opt/xiejifu/20141005/20141005/frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java 文件中找到takeScreenshot方法

修改 float degrees = getDegreesForRotation(mDisplay.getRotation());

void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
// We need to orient the screenshot correctly (and the Surface api seems to take screenshots
// only in the natural orientation of the device :!)
mDisplay.getRealMetrics(mDisplayMetrics);
float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels};
//==========================xjf=========================
//float degrees = getDegreesForRotation(mDisplay.getRotation());
int rotation = mDisplay.getRotation();
if(Surface.getDefaultRotation() > 0){
rotation = (rotation + Surface.getDefaultRotationIndex())%4;
}//get def rotation
float degrees = getDegreesForRotation(rotation);
//==========================xjf=========================
boolean requiresRotation = (degrees > 0);
if (requiresRotation) {
// Get the dimensions of the device in its native orientation
mDisplayMatrix.reset();
mDisplayMatrix.preRotate(-degrees);
mDisplayMatrix.mapPoints(dims);
dims[0] = Math.abs(dims[0]);
dims[1] = Math.abs(dims[1]);
}
.........
}

5.NFC点对点,发送截屏图片
packages/apps/Nfc/src/com/android/nfc/SendUi.java

Bitmap createScreenshot() {
.......
//==========================xjf=========================
//float degrees = getDegreesForRotation(mDisplay.getRotation());
int rotation = mDisplay.getRotation();
if(Surface.getDefaultRotation() > 0){
rotation = (rotation + Surface.getDefaultRotationIndex())%4;
}//get def rotation
float degrees = getDegreesForRotation(rotation);
//==========================xjf=========================
.......
}

除了截图,其他修改应该都是全局的。

昵    称:
验证码:

相关文档: