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

Commit 9d2ca4cb authored by mpodolian's avatar mpodolian
Browse files

Extract foldable device detection

Refactored DeviceConfig class to extract foldable detection.

Bug: 397459664
Flag: com.android.wm.shell.enable_create_any_bubble
Test: N/A
Change-Id: I6eef11084029f1ce3f7563e9dc7a241e45cc1d89
parent c65f2dde
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -49,19 +49,29 @@ data class DeviceConfig(
                    or WindowInsets.Type.displayCutout())
            val windowBounds = windowMetrics.bounds
            val config: Configuration = context.resources.configuration
            val isLargeScreen = config.smallestScreenWidthDp >= LARGE_SCREEN_MIN_EDGE_DP
            val largestEdgeDp = max(config.screenWidthDp, config.screenHeightDp)
            val isSmallTablet = isLargeScreen && largestEdgeDp < SMALL_TABLET_MAX_EDGE_DP
            val isLandscape = context.resources.configuration.orientation == ORIENTATION_LANDSCAPE
            val isRtl = context.resources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
            return DeviceConfig(
                    isLargeScreen = isLargeScreen,
                    isSmallTablet = isSmallTablet,
                    isLargeScreen = isLargeScreen(config),
                    isSmallTablet = isSmallTablet(context),
                    isLandscape = isLandscape,
                    isRtl = isRtl,
                    windowBounds = windowBounds,
                    insets = insets
            )
        }

        @JvmStatic
        fun isSmallTablet(context: Context): Boolean {
            val config: Configuration = context.resources.configuration
            if (!isLargeScreen(config)) {
                return false
            }
            val largestEdgeDp = max(config.screenWidthDp, config.screenHeightDp)
            return largestEdgeDp < SMALL_TABLET_MAX_EDGE_DP
        }

        private fun isLargeScreen(config: Configuration) =
            config.smallestScreenWidthDp >= LARGE_SCREEN_MIN_EDGE_DP
    }
}