|
14 | 14 |
|
15 | 15 | package com.google.maps.android.rx.demo |
16 | 16 |
|
17 | | -import androidx.activity.enableEdgeToEdge |
| 17 | +import android.os.Build |
18 | 18 | import android.os.Bundle |
19 | 19 | import android.util.Log |
| 20 | +import android.view.WindowManager |
20 | 21 | import android.widget.Button |
21 | 22 | import android.widget.Toast |
| 23 | +import androidx.activity.enableEdgeToEdge |
22 | 24 | import androidx.activity.result.contract.ActivityResultContracts |
23 | 25 | import androidx.appcompat.app.AppCompatActivity |
24 | | -import androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener |
| 26 | +import androidx.core.view.ViewCompat |
| 27 | +import androidx.core.view.WindowCompat |
| 28 | +import androidx.core.view.WindowInsetsCompat |
| 29 | +import androidx.core.view.WindowInsetsControllerCompat |
25 | 30 | import androidx.lifecycle.* |
26 | 31 | import com.google.android.gms.maps.MapView |
27 | 32 | import com.google.android.libraries.places.api.Places |
@@ -57,27 +62,25 @@ class MainActivity : AppCompatActivity() { |
57 | 62 | setContentView(R.layout.activity_main) |
58 | 63 |
|
59 | 64 | // 1. Inset Handling: Decor fits system windows = false |
60 | | - androidx.core.view.WindowCompat.setDecorFitsSystemWindows(window, false) |
| 65 | + WindowCompat.setDecorFitsSystemWindows(window, false) |
61 | 66 |
|
62 | 67 | // 2 & 3. Visibility & Behavior: Hide bars, transient swipe behavior |
63 | | - val controller = androidx.core.view.WindowCompat.getInsetsController(window, window.decorView) |
64 | | - controller.systemBarsBehavior = androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE |
65 | | - controller.hide(androidx.core.view.WindowInsetsCompat.Type.systemBars()) |
| 68 | + val controller = WindowCompat.getInsetsController(window, window.decorView) |
| 69 | + controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE |
| 70 | + controller.hide(WindowInsetsCompat.Type.systemBars()) |
66 | 71 |
|
67 | 72 | // 3. Cutout Support: Short edges |
68 | | - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { |
69 | | - window.attributes.layoutInDisplayCutoutMode = android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES |
| 73 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
| 74 | + window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES |
70 | 75 | } |
71 | 76 |
|
72 | 77 | // 4. Inset Handling: Apply insets to controls |
73 | | - androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.controls_container)) { v, insets -> |
74 | | - val bars = insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.systemBars()) |
| 78 | + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.controls_container)) { v, insets -> |
| 79 | + val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) |
75 | 80 | v.setPadding(v.paddingLeft, v.paddingTop, v.paddingRight, bars.bottom + v.paddingBottom) |
76 | 81 | insets |
77 | 82 | } |
78 | 83 |
|
79 | | - |
80 | | - |
81 | 84 | // Initialize Places (provide a valid API key in local.defaults.properties or secrets) |
82 | 85 | // Note: SDK must be initialized. Usually done in Application class, |
83 | 86 | // but here confirming if it's initialized or doing it here if simple. |
@@ -109,8 +112,8 @@ class MainActivity : AppCompatActivity() { |
109 | 112 |
|
110 | 113 | // Set padding on Google Map to account for cutouts/bars |
111 | 114 | // We can use the View's root insets to determine safe area |
112 | | - androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(mapView) { _, insets -> |
113 | | - val bars = insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.displayCutout() or androidx.core.view.WindowInsetsCompat.Type.systemBars()) |
| 115 | + ViewCompat.setOnApplyWindowInsetsListener(mapView) { _, insets -> |
| 116 | + val bars = insets.getInsets(WindowInsetsCompat.Type.displayCutout() or WindowInsetsCompat.Type.systemBars()) |
114 | 117 | googleMap.setPadding(bars.left, bars.top, bars.right, bars.bottom) // Ensure map controls aren't hidden |
115 | 118 | insets |
116 | 119 | } |
|
0 commit comments