From 7dba1da1fa527e74cc0c91b1d2cdc827a79c1039 Mon Sep 17 00:00:00 2001 From: Himanshu Jaju Date: Mon, 30 Nov 2020 13:49:40 +0000 Subject: [PATCH] Refactors RotationUtils to be independent from device width. Currently the RotationUtils class checks for the device orientation AND the device width to figure out the current orientation. This CL moves the device width checks to the caller class so that Util class is free of special cases. Test: Manual Bug: 171918213 Change-Id: Ide67ee35394f48f3312e5ece1228e450fbdf30b4 --- .../recents/ScreenPinningRequest.java | 17 ++++++++-- .../systemui/util/leak/RotationUtils.java | 33 ++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java index 6afc75624a9f4..c2ba3440f19f2 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java +++ b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java @@ -17,6 +17,7 @@ package com.android.systemui.recents; import static com.android.systemui.util.leak.RotationUtils.ROTATION_LANDSCAPE; +import static com.android.systemui.util.leak.RotationUtils.ROTATION_NONE; import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE; import android.animation.ArgbEvaluator; @@ -27,6 +28,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Configuration; import android.graphics.PixelFormat; import android.graphics.drawable.ColorDrawable; import android.os.Binder; @@ -186,7 +188,7 @@ public class ScreenPinningRequest implements View.OnClickListener, DisplayMetrics metrics = new DisplayMetrics(); mWindowManager.getDefaultDisplay().getMetrics(metrics); float density = metrics.density; - int rotation = RotationUtils.getRotation(mContext); + int rotation = getRotation(mContext); inflateView(rotation); int bgColor = mContext.getColor( @@ -342,14 +344,23 @@ public class ScreenPinningRequest implements View.OnClickListener, protected void onConfigurationChanged() { removeAllViews(); - inflateView(RotationUtils.getRotation(mContext)); + inflateView(getRotation(mContext)); + } + + private int getRotation(Context context) { + Configuration config = context.getResources().getConfiguration(); + if (config.smallestScreenWidthDp >= 600) { + return ROTATION_NONE; + } + + return RotationUtils.getRotation(context); } private final Runnable mUpdateLayoutRunnable = new Runnable() { @Override public void run() { if (mLayout != null && mLayout.getParent() != null) { - mLayout.setLayoutParams(getRequestLayoutParams(RotationUtils.getRotation(mContext))); + mLayout.setLayoutParams(getRequestLayoutParams(getRotation(mContext))); } } }; diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java b/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java index 11c72c4c0cb9d..e44981e249064 100644 --- a/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java +++ b/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java @@ -15,7 +15,6 @@ package com.android.systemui.util.leak; import android.content.Context; -import android.content.res.Configuration; import android.view.Surface; public class RotationUtils { @@ -26,30 +25,26 @@ public class RotationUtils { public static final int ROTATION_UPSIDE_DOWN = 3; public static int getRotation(Context context) { - Configuration config = context.getResources().getConfiguration(); int rot = context.getDisplay().getRotation(); - if (config.smallestScreenWidthDp < 600) { - if (rot == Surface.ROTATION_90) { - return ROTATION_LANDSCAPE; - } else if (rot == Surface.ROTATION_270) { - return ROTATION_SEASCAPE; - } + if (rot == Surface.ROTATION_90) { + return ROTATION_LANDSCAPE; + } else if (rot == Surface.ROTATION_270) { + return ROTATION_SEASCAPE; + } else { + return ROTATION_NONE; } - return ROTATION_NONE; } public static int getExactRotation(Context context) { - Configuration config = context.getResources().getConfiguration(); int rot = context.getDisplay().getRotation(); - if (config.smallestScreenWidthDp < 600) { - if (rot == Surface.ROTATION_90) { - return ROTATION_LANDSCAPE; - } else if (rot == Surface.ROTATION_270) { - return ROTATION_SEASCAPE; - } else if (rot == Surface.ROTATION_180) { - return ROTATION_UPSIDE_DOWN; - } + if (rot == Surface.ROTATION_90) { + return ROTATION_LANDSCAPE; + } else if (rot == Surface.ROTATION_270) { + return ROTATION_SEASCAPE; + } else if (rot == Surface.ROTATION_180) { + return ROTATION_UPSIDE_DOWN; + } else { + return ROTATION_NONE; } - return ROTATION_NONE; } }