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

Commit 9ffda8ac authored by Mykola Podolian's avatar Mykola Podolian Committed by Android (Google) Code Review
Browse files

Merge "Extract foldable device detection" into main

parents dd3a085b 9d2ca4cb
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
    }
}