Use WindowConfiguration to match DeviceProfile in IDP.getDeviceProfile
- Also fix WindowBounds.isLandscape to use full display bounds to determine isLandscape, otherwise both orientation will be treated as isLandscape when using availableSize
Bug: 309801705
Test: manual and presubmit
Flag: NONE
Change-Id: Ic7f4235e620d4760a9af356f23066fe5b23304e6
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 75f4bb2..e5a6b2b 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -27,12 +27,12 @@
import android.annotation.TargetApi;
import android.content.Context;
-import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Point;
import android.graphics.PointF;
+import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
@@ -700,14 +700,11 @@
}
public DeviceProfile getDeviceProfile(Context context) {
- Resources res = context.getResources();
- Configuration config = context.getResources().getConfiguration();
+ WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
+ Rect bounds = windowManagerProxy.getCurrentBounds(context);
+ int rotation = windowManagerProxy.getRotation(context);
- float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
- float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
- int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
-
- return getBestMatch(screenWidth, screenHeight, rotation);
+ return getBestMatch(bounds.width(), bounds.height(), rotation);
}
/**
diff --git a/src/com/android/launcher3/util/WindowBounds.java b/src/com/android/launcher3/util/WindowBounds.java
index ec3b642..84a3e7a 100644
--- a/src/com/android/launcher3/util/WindowBounds.java
+++ b/src/com/android/launcher3/util/WindowBounds.java
@@ -85,7 +85,7 @@
* Returns true if the device is in landscape orientation
*/
public final boolean isLandscape() {
- return availableSize.x > availableSize.y;
+ return bounds.width() > bounds.height();
}
/**
diff --git a/src/com/android/launcher3/util/window/WindowManagerProxy.java b/src/com/android/launcher3/util/window/WindowManagerProxy.java
index 278a37e..51a96c4 100644
--- a/src/com/android/launcher3/util/window/WindowManagerProxy.java
+++ b/src/com/android/launcher3/util/window/WindowManagerProxy.java
@@ -338,6 +338,20 @@
}
/**
+ * Returns bounds of the display associated with the context, or bounds of DEFAULT_DISPLAY
+ * if the context isn't associated with a display.
+ */
+ public Rect getCurrentBounds(Context displayInfoContext) {
+ Resources res = displayInfoContext.getResources();
+ Configuration config = res.getConfiguration();
+
+ float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
+ float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
+
+ return new Rect(0, 0, (int) screenWidth, (int) screenHeight);
+ }
+
+ /**
* Returns rotation of the display associated with the context, or rotation of DEFAULT_DISPLAY
* if the context isn't associated with a display.
*/