20
20
import android .content .Intent ;
21
21
import android .content .res .Configuration ;
22
22
import android .content .res .Resources ;
23
+ import android .graphics .Color ;
23
24
import android .os .Build ;
24
25
import android .os .CancellationSignal ;
25
26
import android .os .Handler ;
28
29
import android .text .format .DateFormat ;
29
30
import android .view .View ;
30
31
import android .view .Window ;
32
+ import android .view .WindowInsetsController ;
31
33
import android .view .WindowManager ;
32
34
import android .view .inputmethod .InputMethodManager ;
33
35
import android .view .inputmethod .InputMethodSubtype ;
34
36
import android .widget .Toast ;
35
37
38
+ import androidx .activity .EdgeToEdge ;
36
39
import androidx .annotation .IntDef ;
37
40
import androidx .annotation .Nullable ;
38
41
import androidx .annotation .StringRes ;
39
42
import androidx .core .content .ContextCompat ;
43
+ import androidx .core .view .WindowCompat ;
44
+ import androidx .core .view .WindowInsetsControllerCompat ;
40
45
41
46
import org .drinkless .tdlib .TdApi ;
42
47
import org .thunderdog .challegram .BaseActivity ;
77
82
import me .vkryl .android .ViewUtils ;
78
83
import me .vkryl .android .util .InvalidateDelegate ;
79
84
import me .vkryl .android .util .LayoutDelegate ;
85
+ import me .vkryl .core .BitwiseUtils ;
86
+ import me .vkryl .core .ColorUtils ;
80
87
import me .vkryl .core .StringUtils ;
81
88
import me .vkryl .core .reference .ReferenceList ;
82
89
@@ -585,6 +592,36 @@ public static ViewController<?> getCurrentStackItem (Context context) {
585
592
586
593
public static final int NAVIGATION_BAR_COLOR = false && Device .NEED_LIGHT_NAVIGATION_COLOR ? 0xfff0f0f0 : 0xff000000 ;
587
594
595
+ public static void setLightSystemBars (Window w , boolean lightNavigationBar , boolean lightStatusBar , int newVisibility , boolean forceNewVisibility ) {
596
+ if (Settings .instance ().useEdgeToEdge () && Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
597
+ android .view .WindowInsetsController insetsController = w .getInsetsController ();
598
+ if (insetsController != null ) {
599
+ int flags =
600
+ android .view .WindowInsetsController .APPEARANCE_LIGHT_NAVIGATION_BARS |
601
+ android .view .WindowInsetsController .APPEARANCE_LIGHT_STATUS_BARS ;
602
+ int setFlags =
603
+ BitwiseUtils .optional (android .view .WindowInsetsController .APPEARANCE_LIGHT_NAVIGATION_BARS , lightNavigationBar ) |
604
+ BitwiseUtils .optional (android .view .WindowInsetsController .APPEARANCE_LIGHT_STATUS_BARS , lightStatusBar );
605
+ insetsController .setSystemBarsAppearance (setFlags , flags );
606
+ }
607
+ }
608
+ int visibility = forceNewVisibility ? newVisibility : w .getDecorView ().getSystemUiVisibility ();
609
+ visibility = BitwiseUtils .setFlag (visibility , View .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR , lightNavigationBar );
610
+ visibility = BitwiseUtils .setFlag (visibility , View .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR , lightStatusBar );
611
+ w .getDecorView ().setSystemUiVisibility (visibility );
612
+ }
613
+
614
+ public static void setNavigationBarColor (Window w , int color ) {
615
+ if (Config .USE_CUSTOM_NAVIGATION_COLOR ) {
616
+ if (Settings .instance ().useEdgeToEdge ()) {
617
+ int transparentColor = Color .alpha (color ) == 255 ? ColorUtils .alphaColor (.75f , color ) : color ;
618
+ w .setNavigationBarColor (transparentColor );
619
+ } else {
620
+ w .setNavigationBarColor (color );
621
+ }
622
+ }
623
+ }
624
+
588
625
public static void clearActivity (BaseActivity a ) {
589
626
a .requestWindowFeature (Window .FEATURE_NO_TITLE );
590
627
Window w = a .getWindow ();
@@ -593,27 +630,21 @@ public static void clearActivity (BaseActivity a) {
593
630
} else {
594
631
w .setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_HIDDEN | WindowManager .LayoutParams .SOFT_INPUT_ADJUST_RESIZE );
595
632
}
633
+ if (Settings .instance ().useEdgeToEdge ()) {
634
+ EdgeToEdge .enable (a );
635
+ if (Config .EDGE_TO_EDGE_CUSTOMIZABLE ) {
636
+ w .setNavigationBarContrastEnforced (false );
637
+ }
638
+ }
596
639
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .LOLLIPOP ) {
597
640
w .setBackgroundDrawableResource (R .drawable .transparent );
598
641
} else {
599
- int visibility = 0 ;
600
642
if (Config .USE_CUSTOM_NAVIGATION_COLOR ) {
601
- w .setNavigationBarColor (Theme .backgroundColor ());
602
- if (!Theme .isDark ()) {
603
- visibility |= View .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR ;
604
- }
643
+ setNavigationBarColor (w , Theme .backgroundColor ());
605
644
} else {
606
645
w .setNavigationBarColor (NAVIGATION_BAR_COLOR );
607
646
}
608
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
609
- if (Theme .needLightStatusBar ()) {
610
- visibility |= View .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR ;
611
- }
612
- }
613
- if (visibility != 0 ) {
614
- // TODO: rework to WindowInsetsController
615
- w .getDecorView ().setSystemUiVisibility (visibility );
616
- }
647
+ setLightSystemBars (w , !Theme .isDark (), Theme .needLightStatusBar (), 0 , false );
617
648
RootDrawable d = new RootDrawable (a );
618
649
w .setBackgroundDrawable (d );
619
650
a .setRootDrawable (d );
0 commit comments