ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-30 16:08:44  阅读:258  来源: 互联网

标签:xjf float Android4 Surface 修改 degrees 默认 rotation android


原文链接:http://www.cnblogs.com/sardine/p/3403487.html

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=========================
.......
}

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

转载于:https://www.cnblogs.com/sardine/p/3403487.html

标签:xjf,float,Android4,Surface,修改,degrees,默认,rotation,android
来源: https://blog.csdn.net/weixin_30533797/article/details/97788342

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有