• 关于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=========================
    .......
    }

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

  • 相关阅读:
    Codeforces Round #687 A. Prison Break
    最小生成树自用笔记(Kruskal算法+prim算法)
    Codeforces Round #686 (Div. 3)(A->D)(模拟,vector,数学)
    Acwing 852. spfa判断负环
    Linux内核分析_课程学习总结报告
    结合中断上下文切换和进程上下文切换分析Linux内核的一般执行过程
    深入理解系统调用
    基于mykernel 2.0编写一个操作系统内核
    何评测一个软件工程师的计算机网络知识水平与网络编程技能水平?——参考试题
    TCP三次握手Linux源码解析
  • 原文地址:https://www.cnblogs.com/sardine/p/3403487.html
Copyright © 2020-2023  润新知