高通Android 12/13 Launcher3修改RecentView与屏幕方向保持一致

1、背景:

最近同事遇到一个需求说,recentview应用预览与屏幕方向不一致问题,于是加了一些系统日志,实现此需求。简单记录下哈。

源码修改路径汇总如下

 packages/apps/Launcher3/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java
	修改:         packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
	修改:         packages/apps/Launcher3/src/com/android/launcher3/settings/SettingsActivity.java
	修改:         packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java

2、源码修改diff如下所示 

diff --git a/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/QSSI12/packages/app
index 8ccab71..e39c261 100644
--- a/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java
+++ b/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java
@@ -69,7 +69,7 @@ public class RecentsOrientedState implements
         SharedPreferences.OnSharedPreferenceChangeListener {
 
     private static final String TAG = "RecentsOrientedState";
-    private static final boolean DEBUG = false;
+    private static final boolean DEBUG = true;
 
     @Retention(SOURCE)
     @IntDef({ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270})
@@ -288,7 +288,8 @@ public class RecentsOrientedState implements
     }
 
     private void updateHomeRotationSetting() {
-        boolean homeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false);
+       // boolean homeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false);
+               boolean homeRotationEnabled = true;
         setFlag(FLAG_HOME_ROTATION_ALLOWED_IN_PREFS, homeRotationEnabled);
         SystemUiProxy.INSTANCE.get(mContext).setHomeRotationEnabled(homeRotationEnabled);
     }
diff --git a/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java b/QSSI12/packages/apps/
index d833877..801bfd8 100644
--- a/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
+++ b/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
@@ -440,6 +440,7 @@ public class TaskThumbnailView extends View {
 
             int thumbnailRotation = thumbnailData.rotation;
             int deltaRotate = getRotationDelta(currentRotation, thumbnailRotation);
+                       android.util.Log.d("ZM","currentRotation:"+currentRotation+"thumbnailRotation:"+thumbnailRotation+"deltaRot
             RectF thumbnailClipHint = new RectF();
             if (TaskView.clipLeft(dp)) {
                 thumbnailClipHint.left = thumbnailData.insets.left;
+               boolean homeRotationEnabled = true;
         setFlag(FLAG_HOME_ROTATION_ALLOWED_IN_PREFS, homeRotationEnabled);
         SystemUiProxy.INSTANCE.get(mContext).setHomeRotationEnabled(homeRotationEnabled);
     }
diff --git a/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java b/QSSI12/packages/apps/
index d833877..801bfd8 100644
--- a/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
+++ b/QSSI12/packages/apps/Launcher3/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java
@@ -440,6 +440,7 @@ public class TaskThumbnailView extends View {
 
             int thumbnailRotation = thumbnailData.rotation;
             int deltaRotate = getRotationDelta(currentRotation, thumbnailRotation);
+                       android.util.Log.d("ZM","currentRotation:"+currentRotation+"thumbnailRotation:"+thumbnailRotation+"deltaRot
             RectF thumbnailClipHint = new RectF();
             if (TaskView.clipLeft(dp)) {
                 thumbnailClipHint.left = thumbnailData.insets.left;
@@ -568,7 +569,7 @@ public class TaskThumbnailView extends View {
             }
 
             Rect splitScreenInsets = dp.getInsets();
-            if (!isRotated) {
+            if (!isRotated || deltaRotate == 2) {
                 // No Rotation
                 if (dp.isMultiWindowMode) {
                     mClippedInsets.offsetTo(splitScreenInsets.left * scale,
diff --git a/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/settings/SettingsActivity.java b/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/settings/SettingsActivity.java 
index 0c39632..dece103 100644
--- a/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/settings/SettingsActivity.java
+++ b/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/settings/SettingsActivity.java
@@ -254,7 +254,7 @@ public class SettingsActivity extends FragmentActivity
                 case ALLOW_ROTATION_PREFERENCE_KEY:
                     DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get(
                             getContext()).getDeviceProfile(getContext());
-                    if (deviceProfile.isTablet) {
+                    if (true) {
diff --git a/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java b/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java 
index 867fd99..f5926ec 100644
--- a/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java
+++ b/QSSI12/packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java
@@ -91,7 +91,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
 
     private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) {
         // On large devices we do not handle auto-rotate differently.
-        mIgnoreAutoRotateSettings = ignoreAutoRotateSettings;
+        mIgnoreAutoRotateSettings = true;
         if (!mIgnoreAutoRotateSettings) {
             if (mSharedPrefs == null) {
                 mSharedPrefs = Utilities.getPrefs(mActivity);

3、最后展示RecentView与屏幕方向保持一致。转载请注明出处高通Android 12/13 Launcher3修改RecentView与屏幕方向保持一致-CSDN博客,谢谢!

注意事项:

1、修改完之后记得make clean全编,不然可能没生效哈!

2、app应用强制设置竖屏这里暂时不考虑哈!需要可以自行修改app方向(通过配置横竖屏二套布局文件或者在清单文件中默认配置。)

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是 IconShapeOverride.java 的源代码: ```java package com.android.launcher3.graphics; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Path; import android.graphics.Rect; import android.os.Build; import android.util.Log; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.Utilities; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.IconProvider; import com.android.launcher3.icons.ShapeData; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.ResourceBasedOverride; /** * Provides custom icon shapes based on user preferences. */ public class IconShapeOverride extends ResourceBasedOverride { public static final String KEY_PREFERENCE = "pref_override_icon_shape"; private static final String TAG = "IconShapeOverride"; private final IconProvider mIconProvider; public IconShapeOverride(Context context) { this(context, IconProvider.INSTANCE); } @VisibleForTesting public IconShapeOverride(Context context, IconProvider iconProvider) { super(context, KEY_PREFERENCE); mIconProvider = iconProvider; } /** * @return the current shape path, or null if not defined. */ @Nullable public ShapeData getShape() { String pathString = getStringValue(); if (pathString == null) { return null; } try { return ShapeData.parse(pathString); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to parse shape", e); return null; } } /** * @return the current shape path as a {@link Path} instance, or null if not defined. */ @Nullable public Path getShapePath() { ShapeData data = getShape(); return data != null ? data.getPath() : null; } /** * @return the current shape path bounds, or null if not defined. */ @Nullable public Rect getShapeBounds() { ShapeData data = getShape(); return data != null ? data.getBounds() : null; } /** * Returns the shape path for the given context, or null if none is specified. */ public static Path getShapePath(Resources res, SharedPreferences prefs) { IconShapeOverride override = new IconShapeOverride(res); override.setSharedPreferences(prefs); return override.getShapePath(); } /** * Tests whether the current shape is a circle, by checking if all corners of the shape are at * the same distance from the center. */ public boolean isShapeCircle() { Path shape = getShapePath(); if (shape == null) { return false; } Rect bounds = getShapeBounds(); if (bounds == null) { return false; } Rect outBounds = new Rect(); shape.computeBounds(outBounds, true); float centerX = bounds.exactCenterX(); float centerY = bounds.exactCenterY(); float radius = Math.max(centerX - bounds.left, centerY - bounds.top); float maxDeviation = 0; float[] radii = new float[9]; shape.approximate(1f, radii); for (int i = 0; i < radii.length; i += 2) { float deviation = Math.abs(radii[i] - radius); if (deviation > maxDeviation) { maxDeviation = deviation; } } return maxDeviation < GraphicsUtils.EPSILON; } /** * Updates the default icon shape, if the user has not overridden it. */ public static void updateDefaultShape(Context context) { SharedPreferences prefs = Utilities.getPrefs(context); if (prefs.contains(KEY_PREFERENCE)) { return; } IconShapeOverride override = new IconShapeOverride(context); Path path = override.getDefaultShape(); if (path != null) { prefs.edit().putString(KEY_PREFERENCE, ShapeData.toString(path)).apply(); } } /** * @return the default shape path for the current device. */ @Nullable public Path getDefaultShape() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return IconShape.applyMaskIfNeeded(mIconProvider.getDeviceProfile(), mIconProvider.getIconMask()); } return null; } @Override protected void onValueChanged() { super.onValueChanged(); mIconProvider.clearCaches(); } } ``` 该类提供了自定义应用图标的形状的功能,它会根据用户的偏好设置提供自定义图标形状。其中包含了获取、设置、更新默认图标形状等方法。此外,还包含一些辅助方法,如测试当前形状是否为圆形。在 Android Oreo 及以上版本中,会调用 IconShape 类提供的方法来获取默认图标形状。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值