Merge "Consolidate isTablet logic across launcher and SysUI" into sc-v2-dev

This commit is contained in:
Tracy Zhou
2021-09-24 17:16:41 +00:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 18 deletions

View File

@@ -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_IME_SHOWN;
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.view.WindowManager;
/* Common code */
public class Utilities {
@@ -117,21 +120,20 @@ public class Utilities {
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) {
Configuration newConfig = context.getResources().getConfiguration();
return isTablet(newConfig, context);
final WindowManager windowManager = context.getSystemService(WindowManager.class);
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;
}
/**
* @return whether or not {@param newConfig} represents that of a large screen device or not
*/
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;
public static float dpiFromPx(float size, int densityDpi) {
float densityRatio = (float) densityDpi / DisplayMetrics.DENSITY_DEFAULT;
return (size / densityRatio);
}
}

View File

@@ -205,7 +205,7 @@ public class NavigationBarController implements
@Override
public void onConfigChanged(Configuration newConfig) {
boolean isOldConfigTablet = mIsTablet;
mIsTablet = isTablet(newConfig, mContext);
mIsTablet = isTablet(mContext);
boolean largeScreenChanged = mIsTablet != isOldConfigTablet;
// If we folded/unfolded while in 3 button, show navbar in folded state, hide in unfolded
if (largeScreenChanged && updateNavbarForTaskbar()) {

View File

@@ -168,9 +168,12 @@ public class NavigationBarTest extends SysuiTestCase {
Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
when(windowManager.getDefaultDisplay()).thenReturn(
defaultDisplay);
WindowMetrics metrics = mContext.getSystemService(WindowManager.class)
WindowMetrics maximumWindowMetrics = mContext.getSystemService(WindowManager.class)
.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());
mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager);
mSysuiTestableContextExternal.addMockSystemService(Context.WINDOW_SERVICE, windowManager);