• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.communal.util
18 
19 import android.content.Context
20 import androidx.compose.ui.unit.dp
21 import androidx.window.layout.WindowMetricsCalculator
22 
23 /**
24  * [WindowSizeUtils] defines viewport breakpoints that helps create responsive mobile layout.
25  *
26  * @see https://developer.android.com/develop/ui/views/layout/use-window-size-classes
27  */
28 object WindowSizeUtils {
29     /** Compact screen width breakpoint. */
30     val COMPACT_WIDTH = 600.dp
31     /** Medium screen width breakpoint. */
32     val MEDIUM_WIDTH = 840.dp
33     /** Compact screen height breakpoint. */
34     val COMPACT_HEIGHT = 480.dp
35     /** Expanded screen height breakpoint. */
36     val EXPANDED_HEIGHT = 900.dp
37 
38     /** Whether the window size is compact, which reflects most mobile sizes in portrait. */
39     @JvmStatic
isCompactWindowSizenull40     fun isCompactWindowSize(context: Context): Boolean {
41         val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
42         val width = metrics.bounds.width()
43         return width / metrics.density < COMPACT_WIDTH.value
44     }
45 }
46