Merge "Consolidate isTablet logic across launcher and SysUI" into sc-v2-dev am: cbc62e2056
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15898544 Change-Id: I908d5fbdeb681f52dc6ae2b8637a72b717242f81
This commit is contained in:
@@ -18,16 +18,19 @@ package com.android.systemui.shared.recents.utilities;
|
|||||||
|
|
||||||
import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT;
|
import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT;
|
||||||
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN;
|
import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN;
|
||||||
|
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
/* Common code */
|
/* Common code */
|
||||||
public class Utilities {
|
public class Utilities {
|
||||||
@@ -117,21 +120,20 @@ public class Utilities {
|
|||||||
return hints;
|
return hints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** See {@link #isTablet(Configuration, Context)} */
|
/** @return whether or not {@param context} represents that of a large screen device or not */
|
||||||
|
@TargetApi(Build.VERSION_CODES.R)
|
||||||
public static boolean isTablet(Context context) {
|
public static boolean isTablet(Context context) {
|
||||||
Configuration newConfig = context.getResources().getConfiguration();
|
final WindowManager windowManager = context.getSystemService(WindowManager.class);
|
||||||
return isTablet(newConfig, context);
|
final Rect bounds = windowManager.getCurrentWindowMetrics().getBounds();
|
||||||
|
|
||||||
|
float originalSmallestWidth = dpiFromPx(Math.min(bounds.width(), bounds.height()),
|
||||||
|
context.getResources().getConfiguration().densityDpi);
|
||||||
|
return dpiFromPx(Math.min(bounds.width(), bounds.height()), DENSITY_DEVICE_STABLE)
|
||||||
|
>= TABLET_MIN_DPS && originalSmallestWidth >= TABLET_MIN_DPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static float dpiFromPx(float size, int densityDpi) {
|
||||||
* @return whether or not {@param newConfig} represents that of a large screen device or not
|
float densityRatio = (float) densityDpi / DisplayMetrics.DENSITY_DEFAULT;
|
||||||
*/
|
return (size / densityRatio);
|
||||||
public static boolean isTablet(Configuration newConfig, Context context) {
|
|
||||||
float density = Resources.getSystem().getDisplayMetrics().density;
|
|
||||||
int size = Math.min((int) (density * newConfig.screenWidthDp),
|
|
||||||
(int) (density* newConfig.screenHeightDp));
|
|
||||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
|
||||||
float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;
|
|
||||||
return (size / densityRatio) >= TABLET_MIN_DPS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ public class NavigationBarController implements
|
|||||||
@Override
|
@Override
|
||||||
public void onConfigChanged(Configuration newConfig) {
|
public void onConfigChanged(Configuration newConfig) {
|
||||||
boolean isOldConfigTablet = mIsTablet;
|
boolean isOldConfigTablet = mIsTablet;
|
||||||
mIsTablet = isTablet(newConfig, mContext);
|
mIsTablet = isTablet(mContext);
|
||||||
boolean largeScreenChanged = mIsTablet != isOldConfigTablet;
|
boolean largeScreenChanged = mIsTablet != isOldConfigTablet;
|
||||||
// If we folded/unfolded while in 3 button, show navbar in folded state, hide in unfolded
|
// If we folded/unfolded while in 3 button, show navbar in folded state, hide in unfolded
|
||||||
if (largeScreenChanged && updateNavbarForTaskbar()) {
|
if (largeScreenChanged && updateNavbarForTaskbar()) {
|
||||||
|
|||||||
@@ -168,9 +168,12 @@ public class NavigationBarTest extends SysuiTestCase {
|
|||||||
Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
|
Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
|
||||||
when(windowManager.getDefaultDisplay()).thenReturn(
|
when(windowManager.getDefaultDisplay()).thenReturn(
|
||||||
defaultDisplay);
|
defaultDisplay);
|
||||||
WindowMetrics metrics = mContext.getSystemService(WindowManager.class)
|
WindowMetrics maximumWindowMetrics = mContext.getSystemService(WindowManager.class)
|
||||||
.getMaximumWindowMetrics();
|
.getMaximumWindowMetrics();
|
||||||
when(windowManager.getMaximumWindowMetrics()).thenReturn(metrics);
|
when(windowManager.getMaximumWindowMetrics()).thenReturn(maximumWindowMetrics);
|
||||||
|
WindowMetrics currentWindowMetrics = mContext.getSystemService(WindowManager.class)
|
||||||
|
.getCurrentWindowMetrics();
|
||||||
|
when(windowManager.getCurrentWindowMetrics()).thenReturn(currentWindowMetrics);
|
||||||
doNothing().when(windowManager).addView(any(), any());
|
doNothing().when(windowManager).addView(any(), any());
|
||||||
mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager);
|
mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager);
|
||||||
mSysuiTestableContextExternal.addMockSystemService(Context.WINDOW_SERVICE, windowManager);
|
mSysuiTestableContextExternal.addMockSystemService(Context.WINDOW_SERVICE, windowManager);
|
||||||
|
|||||||
Reference in New Issue
Block a user