2121package com .amaze .filemanager .ui .activities .superclasses ;
2222
2323import static android .os .Build .VERSION .SDK_INT ;
24+ import static android .os .Build .VERSION_CODES .KITKAT ;
25+ import static android .os .Build .VERSION_CODES .KITKAT_WATCH ;
2426import static android .os .Build .VERSION_CODES .LOLLIPOP ;
27+ import static android .os .Build .VERSION_CODES .M ;
28+ import static android .os .Build .VERSION_CODES .O ;
2529import static com .amaze .filemanager .ui .fragments .preferencefragments .PreferencesConstants .PREFERENCE_COLORED_NAVIGATION ;
2630
2731import com .amaze .filemanager .R ;
5862import androidx .annotation .Nullable ;
5963import androidx .appcompat .widget .Toolbar ;
6064import androidx .core .content .ContextCompat ;
65+ import androidx .core .graphics .Insets ;
66+ import androidx .core .view .ViewCompat ;
67+ import androidx .core .view .WindowCompat ;
68+ import androidx .core .view .WindowInsetsCompat ;
69+ import androidx .core .view .WindowInsetsControllerCompat ;
6170import androidx .preference .PreferenceManager ;
6271
6372/** Created by arpitkh996 on 03-03-2016. */
@@ -86,6 +95,38 @@ public void onReceive(Context context, Intent i) {
8695 }
8796 };
8897
98+ @ Override
99+ public void setContentView (int layoutResID ) {
100+ super .setContentView (layoutResID );
101+ setupEdgeToEdgeInsets ();
102+ }
103+
104+ @ Override
105+ public void setContentView (View view ) {
106+ super .setContentView (view );
107+ setupEdgeToEdgeInsets ();
108+ }
109+
110+ /**
111+ * Apply system bar insets as padding on the content view to handle Android 15+ edge-to-edge
112+ * enforcement. This ensures content is laid out below the status bar and above the navigation
113+ * bar.
114+ */
115+ private void setupEdgeToEdgeInsets () {
116+ if (SDK_INT >= 35 ) {
117+ View contentView = findViewById (android .R .id .content );
118+ if (contentView != null ) {
119+ ViewCompat .setOnApplyWindowInsetsListener (
120+ contentView ,
121+ (v , windowInsets ) -> {
122+ Insets insets = windowInsets .getInsets (WindowInsetsCompat .Type .systemBars ());
123+ v .setPadding (insets .left , insets .top , insets .right , insets .bottom );
124+ return WindowInsetsCompat .CONSUMED ;
125+ });
126+ }
127+ }
128+ }
129+
89130 @ Override
90131 public void onCreate (Bundle savedInstanceState ) {
91132 super .onCreate (savedInstanceState );
@@ -108,7 +149,7 @@ public void onCreate(Bundle savedInstanceState) {
108149 getColorPreference ().saveColorPreferences (getPrefs (), ColorPreferenceHelper .randomize (this ));
109150 }
110151
111- if (SDK_INT >= 21 ) {
152+ if (SDK_INT >= LOLLIPOP ) {
112153 ActivityManager .TaskDescription taskDescription =
113154 new ActivityManager .TaskDescription (
114155 getString (R .string .appbar_name ),
@@ -132,8 +173,13 @@ public void initStatusBarResources(View parentView) {
132173 }
133174
134175 Window window = getWindow ();
135- if (SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
136- if (findViewById (R .id .tab_frame ) != null || findViewById (R .id .drawer_layout ) == null ) {
176+ if (SDK_INT >= LOLLIPOP ) {
177+ boolean useSolidStatusBar =
178+ findViewById (R .id .tab_frame ) != null
179+ || findViewById (R .id .drawer_layout ) == null
180+ || getAppTheme ().equals (AppTheme .LIGHT );
181+
182+ if (useSolidStatusBar ) {
137183 window .setStatusBarColor (PreferenceUtils .getStatusColor (getPrimary ()));
138184 window .clearFlags (WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS );
139185 } else {
@@ -150,8 +196,19 @@ public void initStatusBarResources(View parentView) {
150196 window .setNavigationBarColor (Utils .getColor (this , R .color .holo_dark_background ));
151197 }
152198 }
153- } else if (SDK_INT == Build .VERSION_CODES .KITKAT_WATCH
154- || SDK_INT == Build .VERSION_CODES .KITKAT ) {
199+
200+ // Set light/dark icon appearance for system bars based on theme
201+ if (SDK_INT >= M ) {
202+ WindowInsetsControllerCompat insetsController =
203+ WindowCompat .getInsetsController (window , window .getDecorView ());
204+ boolean isLightTheme = getAppTheme ().equals (AppTheme .LIGHT );
205+ insetsController .setAppearanceLightStatusBars (isLightTheme );
206+ if (SDK_INT >= O ) {
207+ insetsController .setAppearanceLightNavigationBars (isLightTheme );
208+ }
209+ }
210+ } else if (SDK_INT == KITKAT_WATCH
211+ || SDK_INT == KITKAT ) {
155212 setKitkatStatusBarMargin (parentView );
156213 setKitkatStatusBarTint ();
157214 }
@@ -212,7 +269,7 @@ private Toolbar getToolbar() {
212269
213270 void setTheme () {
214271 AppTheme theme = getAppTheme ();
215- if (Build . VERSION . SDK_INT >= 21 ) {
272+ if (SDK_INT >= LOLLIPOP ) {
216273
217274 String stringRepresentation = String .format ("#%06X" , (0xFFFFFF & getAccent ()));
218275
0 commit comments