Skip to content

Commit 9e403da

Browse files
committed
update for edge-to-edge
1 parent 4b69e8b commit 9e403da

5 files changed

Lines changed: 90 additions & 20 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
android:exported="true"
156156
android:label="@string/title_activity_detail"
157157
android:parentActivityName="eu.faircode.netguard.ActivityMain"
158-
android:theme="@style/AppTheme.NoActionBar">
158+
android:theme="@style/AppTheme.EdgeToEdge">
159159
<meta-data
160160
android:name="android.support.PARENT_ACTIVITY"
161161
android:value="eu.faircode.netguard.ActivityMain" />

app/src/main/java/eu/faircode/netguard/ApplicationEx.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
import android.content.Context;
3232
import android.content.SharedPreferences;
3333
import android.graphics.Color;
34+
import android.graphics.drawable.ColorDrawable;
3435
import android.os.Build;
3536
import android.os.Bundle;
3637
import android.os.StrictMode;
3738
import android.util.Log;
38-
import android.util.TypedValue;
3939
import android.view.View;
4040

4141
import androidx.annotation.NonNull;
4242
import androidx.annotation.Nullable;
43+
import androidx.core.content.ContextCompat;
4344
import androidx.core.graphics.Insets;
4445
import androidx.core.view.OnApplyWindowInsetsListener;
4546
import androidx.core.view.ViewCompat;
@@ -48,6 +49,7 @@
4849
import androidx.preference.PreferenceManager;
4950

5051
import net.kollnig.missioncontrol.BuildConfig;
52+
import net.kollnig.missioncontrol.DetailsActivity;
5153
import net.kollnig.missioncontrol.R;
5254

5355
import org.acra.ACRA;
@@ -121,28 +123,43 @@ public void onCreate() {
121123
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
122124
@Override
123125
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
126+
if (activity.getClass() == DetailsActivity.class)
127+
return;
128+
124129
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
125-
View content = activity.findViewById(android.R.id.content);
130+
android.widget.FrameLayout content = activity.findViewById(android.R.id.content);
131+
132+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
133+
boolean dark = prefs.getBoolean("dark_theme", false);
134+
135+
// On Android 15+, setStatusBarColor is ignored
136+
// Set window background to primary color - this shows behind the status bar
137+
int primaryColor = ContextCompat.getColor(activity, R.color.colorPrimary);
138+
activity.getWindow().setBackgroundDrawable(new ColorDrawable(primaryColor));
139+
140+
// Set status bar icons to light (white) since our background is dark
141+
View decor = activity.getWindow().getDecorView();
142+
WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightStatusBars(false);
143+
WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightNavigationBars(!dark);
144+
126145
ViewCompat.setOnApplyWindowInsetsListener(content, new OnApplyWindowInsetsListener() {
127146
@NonNull
128147
@Override
129148
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
130149
Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.ime());
131150

132-
TypedValue tv = new TypedValue();
133-
activity.getTheme().resolveAttribute(R.attr.colorPrimaryDark, tv, true);
134-
135151
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
136152
boolean dark = prefs.getBoolean("dark_theme", false);
137153

138-
activity.getWindow().getDecorView().setBackgroundColor(tv.data);
139-
content.setBackgroundColor(dark ? Color.parseColor("#ff121212") : Color.WHITE);
154+
// Apply padding to android.R.id.content for system bars
155+
v.setPadding(bars.left, bars.top, bars.right, bars.bottom);
140156

141-
int actionBarHeight = Util.dips2pixels(56, activity);
142-
View decor = activity.getWindow().getDecorView();
143-
WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightStatusBars(false);
144-
WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightNavigationBars(!dark);
145-
v.setPadding(bars.left, bars.top + actionBarHeight, bars.right, bars.bottom);
157+
// Set background on the actual layout (first child), not on the content frame
158+
// This way the padding area shows the window background (primary color)
159+
if (content.getChildCount() > 0) {
160+
View child = content.getChildAt(0);
161+
child.setBackgroundColor(dark ? Color.parseColor("#ff121212") : Color.WHITE);
162+
}
146163

147164
return insets;
148165
}

app/src/main/java/net/kollnig/missioncontrol/DetailsActivity.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@
3838
import androidx.appcompat.app.AppCompatActivity;
3939
import androidx.appcompat.widget.Toolbar;
4040
import androidx.core.app.NavUtils;
41+
import androidx.core.content.ContextCompat;
42+
import androidx.core.graphics.Insets;
43+
import androidx.core.view.ViewCompat;
44+
import androidx.core.view.WindowCompat;
45+
import androidx.core.view.WindowInsetsCompat;
46+
import androidx.core.view.WindowInsetsControllerCompat;
4147
import androidx.viewpager2.widget.ViewPager2;
4248

4349
import com.google.android.material.snackbar.Snackbar;
50+
import com.google.android.material.appbar.AppBarLayout;
4451
import com.google.android.material.tabs.TabLayout;
4552
import com.google.android.material.tabs.TabLayoutMediator;
4653
import com.opencsv.CSVWriter;
@@ -120,8 +127,17 @@ protected void onActivityResult(int requestCode, int resultCode, final Intent da
120127
@Override
121128
protected void onCreate(Bundle savedInstanceState) {
122129
super.onCreate(savedInstanceState);
130+
// Enable edge-to-edge content
131+
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
123132
setContentView(R.layout.activity_details);
124133

134+
// Status bar appearance
135+
WindowInsetsControllerCompat insetsController = new WindowInsetsControllerCompat(getWindow(), getWindow().getDecorView());
136+
insetsController.setAppearanceLightStatusBars(false);
137+
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM) {
138+
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
139+
}
140+
125141
running = true;
126142

127143
// Receive about details
@@ -153,6 +169,28 @@ protected void onCreate(Bundle savedInstanceState) {
153169
getSupportActionBar().setDisplayShowTitleEnabled(false);
154170
toolbar.setTitle(getString(R.string.app_info));
155171
toolbar.setSubtitle(appName);
172+
173+
// Apply window insets so content avoids status/navigation bars
174+
AppBarLayout appBar = findViewById(R.id.appbar);
175+
final int appBarInitialLeft = appBar.getPaddingLeft();
176+
final int appBarInitialTop = appBar.getPaddingTop();
177+
final int appBarInitialRight = appBar.getPaddingRight();
178+
final int appBarInitialBottom = appBar.getPaddingBottom();
179+
ViewCompat.setOnApplyWindowInsetsListener(appBar, (v, insets) -> {
180+
Insets sysBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
181+
v.setPadding(appBarInitialLeft, appBarInitialTop + sysBars.top, appBarInitialRight, appBarInitialBottom);
182+
return insets;
183+
});
184+
185+
final int pagerInitialLeft = viewPager.getPaddingLeft();
186+
final int pagerInitialTop = viewPager.getPaddingTop();
187+
final int pagerInitialRight = viewPager.getPaddingRight();
188+
final int pagerInitialBottom = viewPager.getPaddingBottom();
189+
ViewCompat.setOnApplyWindowInsetsListener(viewPager, (v, insets) -> {
190+
Insets sysBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
191+
v.setPadding(pagerInitialLeft + sysBars.left, pagerInitialTop, pagerInitialRight + sysBars.right, pagerInitialBottom + sysBars.bottom);
192+
return insets;
193+
});
156194
}
157195

158196
@Override

app/src/main/res/layout/activity_details.xml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
tools:mContext="net.kollnig.missioncontrol.DetailsActivity">
7+
tools:context="net.kollnig.missioncontrol.DetailsActivity">
88

99
<com.google.android.material.appbar.AppBarLayout
10+
android:id="@+id/appbar"
1011
android:layout_width="match_parent"
1112
android:layout_height="wrap_content"
12-
android:theme="@style/AppTheme.AppBarOverlay">
13+
android:background="?attr/colorPrimary">
1314

14-
<androidx.appcompat.widget.Toolbar
15+
<com.google.android.material.appbar.MaterialToolbar
1516
android:id="@+id/toolbar"
1617
android:layout_width="match_parent"
1718
android:layout_height="?attr/actionBarSize"
18-
app:title="@string/app_info"/>
19+
android:background="@android:color/transparent"
20+
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
21+
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
22+
app:title="@string/app_info"
23+
app:titleTextColor="@android:color/white"
24+
app:subtitleTextColor="@android:color/white" />
1925

2026
<com.google.android.material.tabs.TabLayout
2127
android:id="@+id/tabs"
2228
android:layout_width="match_parent"
2329
android:layout_height="wrap_content"
24-
android:background="?attr/colorPrimary"
25-
/>
30+
app:tabTextColor="@android:color/white"
31+
app:tabSelectedTextColor="@android:color/white"
32+
app:tabIndicatorColor="@android:color/white" />
2633
</com.google.android.material.appbar.AppBarLayout>
2734

2835
<androidx.viewpager2.widget.ViewPager2
@@ -31,4 +38,4 @@
3138
android:layout_height="match_parent"
3239
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
3340

34-
</androidx.coordinatorlayout.widget.CoordinatorLayout>
41+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

app/src/main/res/values/styles.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
</style>
2323
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
2424

25+
<!-- Edge-to-edge variant for DetailsActivity -->
26+
<style name="AppTheme.EdgeToEdge" parent="AppTheme.NoActionBar">
27+
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
28+
<item name="android:navigationBarColor">@android:color/transparent</item>
29+
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
30+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
31+
</style>
32+
2533
<style name="PrimaryFlatButton" parent="Theme.AppCompat.Light">
2634
<item name="android:buttonStyle">
2735
@style/Widget.AppCompat.Button.Borderless.Colored

0 commit comments

Comments
 (0)