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

Commit afa16744 authored by Coco Duan's avatar Coco Duan Committed by Android (Google) Code Review
Browse files

Merge "Add a window size enum in WindowSizeUtil" into main

parents 16485c16 096c0150
Loading
Loading
Loading
Loading
+34 −15
Original line number Diff line number Diff line
@@ -35,24 +35,43 @@ object WindowSizeUtils {
    /** Expanded screen height breakpoint. */
    val EXPANDED_HEIGHT = 900.dp

    /** Whether the window size is compact, which reflects most mobile sizes in portrait. */
    /** Returns the window size category based on the current window metrics. */
    @JvmStatic
    fun isCompactWindowSize(context: Context): Boolean {
        val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
        val width = metrics.bounds.width()
        return width / metrics.density < COMPACT_WIDTH.value
    }

    /** Whether the window size reflects most tablet sizes. */
    @JvmStatic
    fun isTabletWindowSize(context: Context): Boolean {
    fun getWindowSizeCategory(context: Context): WindowSizeCategory {
        val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
        val width = metrics.bounds.width() / metrics.density
        val height = metrics.bounds.height() / metrics.density
        return height >= EXPANDED_HEIGHT.value ||

        if (width < COMPACT_WIDTH.value) {
            return WindowSizeCategory.MOBILE_PORTRAIT
        }
        if (height < COMPACT_HEIGHT.value) {
            return WindowSizeCategory.MOBILE_LANDSCAPE
        }
        if (
            height >= EXPANDED_HEIGHT.value ||
                (width >= MEDIUM_WIDTH.value &&
                    height in COMPACT_HEIGHT.value..EXPANDED_HEIGHT.value &&
                    // aspect ratio to exclude unfolded screen size
                    width / height >= 1.5f)
        ) {
            return WindowSizeCategory.TABLET
        }
        return WindowSizeCategory.UNFOLDED
    }

    /**
     * Represent custom breakpoints for responsive hub mode UI, which reflects device type and its
     * orientation.
     */
    enum class WindowSizeCategory {
        /** Mobile in portrait */
        MOBILE_PORTRAIT,
        /** Mobile in landscape */
        MOBILE_LANDSCAPE,
        /** Unfolded inner displays */
        UNFOLDED,
        /** Tablet */
        TABLET,
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;

import com.android.internal.util.Preconditions;
import com.android.systemui.communal.util.WindowSizeUtils;
import com.android.systemui.communal.util.WindowSizeUtils.WindowSizeCategory;
import com.android.systemui.complication.ComplicationLayoutEngine;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.res.R;
@@ -71,10 +72,11 @@ public abstract class ComplicationHostViewModule {
            return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin);
        }
        final int padding;
        if (WindowSizeUtils.isCompactWindowSize(context)) {
        final WindowSizeCategory windowSize = WindowSizeUtils.getWindowSizeCategory(context);
        if (windowSize == WindowSizeCategory.MOBILE_PORTRAIT) {
            padding = resources.getDimensionPixelSize(
                    R.dimen.dream_overlay_complication_small_margin);
        } else if (WindowSizeUtils.isTabletWindowSize(context)) {
        } else if (windowSize == WindowSizeCategory.TABLET) {
            padding = resources.getDimensionPixelSize(
                    R.dimen.dream_overlay_complication_medium_margin);
        } else {
@@ -92,7 +94,7 @@ public abstract class ComplicationHostViewModule {
    @Named(COMPLICATION_MARGINS)
    static ComplicationLayoutEngine.Margins providesComplicationMargins(@Main Resources resources,
            Context context) {
        return WindowSizeUtils.isCompactWindowSize(context)
        return WindowSizeUtils.getWindowSizeCategory(context) == WindowSizeCategory.MOBILE_PORTRAIT
                ? new ComplicationLayoutEngine.Margins(resources.getDimensionPixelSize(
                        R.dimen.dream_overlay_container_small_padding_start),
                resources.getDimensionPixelSize(
+3 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.res.Resources;
import android.view.ViewGroup;

import com.android.systemui.communal.util.WindowSizeUtils;
import com.android.systemui.communal.util.WindowSizeUtils.WindowSizeCategory;
import com.android.systemui.complication.ComplicationLayoutParams;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.flags.FeatureFlags;
@@ -66,7 +67,8 @@ public interface RegisteredComplicationsModule {
    static ComplicationLayoutParams provideClockTimeLayoutParams(FeatureFlags featureFlags,
            Context context) {
        if (featureFlags.isEnabled(Flags.HIDE_SMARTSPACE_ON_DREAM_OVERLAY)
                && (!dreamsV2() || !WindowSizeUtils.isCompactWindowSize(context))) {
                && (!dreamsV2() || WindowSizeUtils.getWindowSizeCategory(context)
                != WindowSizeCategory.MOBILE_PORTRAIT)) {
            return new ComplicationLayoutParams(0,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ComplicationLayoutParams.POSITION_BOTTOM