Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1dc5b71 authored by Tracy Zhou's avatar Tracy Zhou Committed by Automerger Merge Worker
Browse files

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

Merge "Consolidate isTablet logic across launcher and SysUI" into sc-v2-dev am: cbc62e20 am: d3ac4486

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15898544

Change-Id: I07ec443fc33205a3ea6ec1c0ffd3386844805178
parents d203dc27 d3ac4486
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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()) {
+5 −2
Original line number Diff line number Diff line
@@ -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);