Launcher默认支持旋转

简介: Launcher默认支持旋转

launcher界面默认开启旋转

1、默认情况

launcher默认没有开启旋转,长按桌面–》home Settings中有开关可以打开是否允许旋转

<SwitchPreference
        android:key="pref_allowRotation"
        android:title="@string/allow_rotation_title"
        android:summary="@string/allow_rotation_desc"
        android:defaultValue="@bool/allow_rotation"
        android:persistent="true" />


如果要默认打开可以修改allow_rotation值为true(无效)。

2、recent UI界面旋转异常

当默认打开旋转后,home Settings里面的选项会消失。主界面可以正常旋转;但是近期任务界面旋转显示异常。


packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java中

直接返回true

    public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
        // If the device's pixel density was scaled (usually via settings for A11y), use the
        // original dimensions to determine if rotation is allowed of not.
        float originalSmallestWidth = dpiFromPx(
                Math.min(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
        return true;
    }
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
...
public static boolean getAllowRotationDefaultValue(Context context) {
    //默认支持旋转,这里直接return true
        if (context != null && context.getResources().getBoolean(R.bool.allow_rotation)){
            return true;
        }
        // If the device's pixel density was scaled (usually via settings for A11y), use the
        // original dimensions to determine if rotation is allowed of not.
        Resources res = Resources.getSystem();
        int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
                * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE;
        return originalSmallestWidth >= 600;
    }


packages/apps/Launcher3/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java中


  private void initFlags() {
        SysUINavigationMode.Mode currentMode = SysUINavigationMode.getMode(mContext);
        boolean rotationWatcherSupported = mOrientationListener.canDetectOrientation() &&
                currentMode != TWO_BUTTONS;
        setFlag(FLAG_ROTATION_WATCHER_SUPPORTED, rotationWatcherSupported);
 
        // initialize external flags
        updateAutoRotateSetting();
        updateHomeRotationSetting();
    }
    ...
private void updateHomeRotationSetting() {
        setFlag(FLAG_HOME_ROTATION_ALLOWED_IN_PREFS,
                mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, getAllowRotationDefaultValue(mContext)));//这里默认是false
    }

保持旋转设置一致即可


目录
相关文章
|
4天前
|
Java Android开发
Android系统 修改无源码普通应用为默认Launcher和隐藏Settings中应用信息图标
Android系统 修改无源码普通应用为默认Launcher和隐藏Settings中应用信息图标
69 0
|
4天前
|
Java Android开发 开发者
Android10 修改开发者选项中动画缩放默认值
Android10 修改开发者选项中动画缩放默认值
15 0
|
3天前
|
传感器 API Android开发
指定Activity的默认显示方向
指定Activity的默认显示方向
14 2
|
9月前
|
SQL 数据库 Android开发
Android 访问系统相册选中图片,并返回该图片的路径
Android 访问系统相册选中图片,并返回该图片的路径
111 0
|
编解码 Java Android开发
Android加载drawable中图片后自动缩放的原理
Android加载drawable中图片后自动缩放的原理
|
XML Android开发 数据格式
Android横竖屏切换View设置不同尺寸或等比例缩放的XML解决方案
Android横竖屏切换View设置不同尺寸或等比例缩放的XML解决方案 在一些应用中,涉及到横竖屏切换,View要切换成不同大小比例尺寸。
1199 0
|
Android开发
【Android 内存优化】Bitmap 图像尺寸缩小 ( 设置 Options 参数 | inJustDecodeBounds | inSampleSize | 工具类实现 )
【Android 内存优化】Bitmap 图像尺寸缩小 ( 设置 Options 参数 | inJustDecodeBounds | inSampleSize | 工具类实现 )
403 0
PyQt5 技术篇-设置窗口启用默认桌面位置,按屏幕比例
PyQt5 技术篇-设置窗口启用默认桌面位置,按屏幕比例
332 0
PyQt5 技术篇-设置窗口启用默认桌面位置,按屏幕比例