@@ -20,14 +20,23 @@ package com.bharathvishal.textfilegeneratorbenchmark
20
20
21
21
22
22
import android.content.Context
23
+ import android.content.res.Configuration
24
+ import android.os.Build
23
25
import android.os.Bundle
24
26
import android.os.Handler
25
27
import android.os.Looper
28
+ import android.view.View
29
+ import android.view.WindowInsets
26
30
import android.widget.LinearLayout
27
31
import android.widget.Toast
28
32
import androidx.activity.OnBackPressedCallback
33
+ import androidx.activity.enableEdgeToEdge
29
34
import androidx.appcompat.app.AppCompatActivity
30
35
import androidx.appcompat.widget.Toolbar
36
+ import androidx.core.view.ViewCompat
37
+ import androidx.core.view.WindowInsetsCompat
38
+ import androidx.core.view.updatePadding
39
+ import com.google.android.material.color.DynamicColors
31
40
32
41
class MainActivity : AppCompatActivity () {
33
42
@@ -40,6 +49,14 @@ class MainActivity : AppCompatActivity() {
40
49
41
50
42
51
override fun onCreate (savedInstanceState : Bundle ? ) {
52
+ try {
53
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
54
+ enableEdgeToEdge()
55
+ }
56
+ } catch (e: Exception ) {
57
+ e.printStackTrace()
58
+ }
59
+
43
60
super .onCreate(savedInstanceState)
44
61
setContentView(R .layout.activity_main)
45
62
@@ -52,6 +69,39 @@ class MainActivity : AppCompatActivity() {
52
69
53
70
activityContextMain = this @MainActivity
54
71
72
+ try {
73
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
74
+ val viewTempAppBar = findViewById<View >(R .id.appbarmain)
75
+ viewTempAppBar.setOnApplyWindowInsetsListener { view, insets ->
76
+ val statusBarInsets = insets.getInsets(WindowInsets .Type .statusBars())
77
+
78
+ val nightModeFlags: Int = view.resources
79
+ .configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK
80
+ val isDarkMode = nightModeFlags == Configuration .UI_MODE_NIGHT_YES
81
+ val isDynamicTheme = DynamicColors .isDynamicColorAvailable()
82
+ // Adjust padding to avoid overlap
83
+ view.setPadding(0 , statusBarInsets.top, 0 , 0 )
84
+ insets
85
+ }
86
+
87
+
88
+ val tempL: View = findViewById<View >(R .id.linearlayoutfragmentlayout)
89
+ ViewCompat .setOnApplyWindowInsetsListener(tempL) { view, windowInsets ->
90
+ val insets = windowInsets.getInsets(WindowInsetsCompat .Type .systemGestures())
91
+ // Apply the insets as padding to the view. Here, set all the dimensions
92
+ // as appropriate to your layout. You can also update the view's margin if
93
+ // more appropriate.
94
+ tempL.updatePadding(0 , 0 , 0 , insets.bottom)
95
+
96
+ // Return CONSUMED if you don't want the window insets to keep passing down
97
+ // to descendant views.
98
+ WindowInsetsCompat .CONSUMED
99
+ }
100
+ }
101
+ } catch (e: Exception ) {
102
+ e.printStackTrace()
103
+ }
104
+
55
105
try {
56
106
val mgr = supportFragmentManager
57
107
val trans = mgr.beginTransaction()
0 commit comments