2121import android .content .res .Resources ;
2222import android .os .Build ;
2323import android .os .Bundle ;
24- import android .view .View ;
25- import android .view .ViewGroup ;
2624import android .view .WindowManager ;
2725
2826import androidx .annotation .NonNull ;
2927import androidx .annotation .Nullable ;
3028import androidx .annotation .StyleRes ;
3129import androidx .appcompat .app .AppCompatActivity ;
32- import androidx .core .graphics .Insets ;
33- import androidx .core .view .ViewCompat ;
34- import androidx .core .view .WindowInsetsCompat ;
35-
36- import com .hippo .android .resource .AttrResources ;
37- import com .hippo .ehviewer .R ;
3830import com .google .firebase .analytics .FirebaseAnalytics ;
3931import com .hippo .content .ContextLocalWrapper ;
4032import com .hippo .ehviewer .Analytics ;
@@ -54,13 +46,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5446 setTheme (getThemeResId (Settings .getTheme ()));
5547 super .onCreate (savedInstanceState );
5648
57- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
58- applyEdgeToEdgeSystemBars ();
59- }
60- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
61- getWindow ().setNavigationBarContrastEnforced (false );
62- }
63-
6449 ((EhApplication ) getApplication ()).registerActivity (this );
6550
6651 if (Analytics .isEnabled ()) {
@@ -75,72 +60,9 @@ protected void onDestroy() {
7560 ((EhApplication ) getApplication ()).unregisterActivity (this );
7661 }
7762
78- @ Override
79- public void onContentChanged () {
80- super .onContentChanged ();
81- applyNavigationBarPaddingIfNeeded ();
82- }
83-
84- /**
85- * MainActivity uses {@link com.hippo.ehviewer.widget.EhStageLayout} for window insets.
86- * GalleryActivity is fullscreen and handles bottom controls separately.
87- */
88- protected boolean shouldApplyNavigationBarPadding () {
89- return !(this instanceof MainActivity ) && !(this instanceof GalleryActivity );
90- }
91-
92- private void applyNavigationBarPaddingIfNeeded () {
93- if (!shouldApplyNavigationBarPadding ()) {
94- return ;
95- }
96- View target = findViewById (R .id .content_panel );
97- if (target == null ) {
98- View content = findViewById (android .R .id .content );
99- if (content instanceof ViewGroup ) {
100- ViewGroup group = (ViewGroup ) content ;
101- if (group .getChildCount () > 0 ) {
102- target = group .getChildAt (0 );
103- }
104- }
105- }
106- if (target == null || target .getTag (R .id .navigation_bar_padding_applied ) != null ) {
107- return ;
108- }
109- target .setTag (R .id .navigation_bar_padding_applied , Boolean .TRUE );
110- target .setTag (R .id .navigation_bar_padding_origin_bottom , target .getPaddingBottom ());
111- ViewCompat .setOnApplyWindowInsetsListener (target , (v , windowInsets ) -> {
112- Insets nav = windowInsets .getInsets (WindowInsetsCompat .Type .navigationBars ());
113- Object origin = v .getTag (R .id .navigation_bar_padding_origin_bottom );
114- int originBottom = origin instanceof Integer ? (Integer ) origin : 0 ;
115- v .setPadding (v .getPaddingLeft (), v .getPaddingTop (), v .getPaddingRight (),
116- originBottom + nav .bottom );
117- return windowInsets ;
118- });
119- ViewCompat .requestApplyInsets (target );
120- }
121-
122- private void applyEdgeToEdgeSystemBars () {
123- int flags = android .view .View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
124- | android .view .View .SYSTEM_UI_FLAG_LAYOUT_STABLE ;
125- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O_MR1
126- && AttrResources .getAttrBoolean (this , android .R .attr .windowLightNavigationBar )) {
127- flags |= android .view .View .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR ;
128- }
129- getWindow ().getDecorView ().setSystemUiVisibility (flags );
130- syncNavigationBarWithTheme ();
131- }
132-
133- private void syncNavigationBarWithTheme () {
134- getWindow ().setNavigationBarColor (
135- AttrResources .getAttrColor (this , android .R .attr .windowBackground ));
136- }
137-
13863 @ Override
13964 protected void onResume () {
14065 super .onResume ();
141- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
142- syncNavigationBarWithTheme ();
143- }
14466 if (Settings .getEnabledSecurity ()){
14567 getWindow ().setFlags (WindowManager .LayoutParams .FLAG_SECURE ,
14668 WindowManager .LayoutParams .FLAG_SECURE );
0 commit comments