mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Merge "Using the WindowMetrics API instead of display.getRealSize" into tm-dev
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.android.launcher3.util.window;
|
||||
|
||||
import static android.view.Display.DEFAULT_DISPLAY;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
|
||||
|
||||
import static com.android.launcher3.ResourceUtils.INVALID_RESOURCE_HANDLE;
|
||||
import static com.android.launcher3.ResourceUtils.NAVBAR_HEIGHT;
|
||||
import static com.android.launcher3.ResourceUtils.NAVBAR_HEIGHT_LANDSCAPE;
|
||||
@@ -47,7 +50,6 @@ import android.view.WindowMetrics;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.util.DisplayController;
|
||||
import com.android.launcher3.util.MainThreadInitializedObject;
|
||||
import com.android.launcher3.util.ResourceBasedOverride;
|
||||
import com.android.launcher3.util.WindowBounds;
|
||||
@@ -90,7 +92,10 @@ public class WindowManagerProxy implements ResourceBasedOverride {
|
||||
ArrayMap<String, Pair<CachedDisplayInfo, WindowBounds[]>> result = new ArrayMap<>();
|
||||
for (Display display : displays) {
|
||||
if (isInternalDisplay(display)) {
|
||||
CachedDisplayInfo info = getDisplayInfo(display).normalize();
|
||||
Context displayContext = Utilities.ATLEAST_S
|
||||
? context.createWindowContext(display, TYPE_APPLICATION, null)
|
||||
: context.createDisplayContext(display);
|
||||
CachedDisplayInfo info = getDisplayInfo(displayContext, display).normalize();
|
||||
WindowBounds[] bounds = estimateWindowBounds(context, info);
|
||||
result.put(info.id, Pair.create(info, bounds));
|
||||
}
|
||||
@@ -121,7 +126,7 @@ public class WindowManagerProxy implements ResourceBasedOverride {
|
||||
}
|
||||
|
||||
WindowMetrics wm = windowContext.getSystemService(WindowManager.class)
|
||||
.getCurrentWindowMetrics();
|
||||
.getMaximumWindowMetrics();
|
||||
|
||||
Rect insets = new Rect();
|
||||
normalizeWindowInsets(windowContext, wm.getWindowInsets(), insets);
|
||||
@@ -267,21 +272,23 @@ public class WindowManagerProxy implements ResourceBasedOverride {
|
||||
* Returns a CachedDisplayInfo initialized for the current display
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.S)
|
||||
public CachedDisplayInfo getDisplayInfo(Display display) {
|
||||
int rotation = display.getRotation();
|
||||
|
||||
Point size = new Point();
|
||||
display.getRealSize(size);
|
||||
|
||||
public CachedDisplayInfo getDisplayInfo(Context displayContext, Display display) {
|
||||
int rotation = getRotation(displayContext);
|
||||
Rect cutoutRect = new Rect();
|
||||
Point size = new Point();
|
||||
if (Utilities.ATLEAST_S) {
|
||||
DisplayCutout cutout = display.getCutout();
|
||||
WindowMetrics wm = displayContext.getSystemService(WindowManager.class)
|
||||
.getMaximumWindowMetrics();
|
||||
DisplayCutout cutout = wm.getWindowInsets().getDisplayCutout();
|
||||
if (cutout != null) {
|
||||
cutoutRect.set(cutout.getSafeInsetLeft(), cutout.getSafeInsetTop(),
|
||||
cutout.getSafeInsetRight(), cutout.getSafeInsetBottom());
|
||||
}
|
||||
}
|
||||
|
||||
size.set(wm.getBounds().right, wm.getBounds().bottom);
|
||||
} else {
|
||||
display.getRealSize(size);
|
||||
}
|
||||
return new CachedDisplayInfo(getDisplayId(display), size, rotation, cutoutRect);
|
||||
}
|
||||
|
||||
@@ -304,7 +311,9 @@ public class WindowManagerProxy implements ResourceBasedOverride {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
return d == null ? DisplayController.INSTANCE.get(context).getInfo().rotation
|
||||
: d.getRotation();
|
||||
if (d == null) {
|
||||
d = context.getSystemService(DisplayManager.class).getDisplay(DEFAULT_DISPLAY);
|
||||
}
|
||||
return d.getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user