Skip to content

Commit 11fed59

Browse files
committed
Transparent navigation bar on Android 11-14
1 parent ca8e5b7 commit 11fed59

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

app/src/main/java/org/thunderdog/challegram/BaseActivity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ public float windowRefreshRate () {
461461
return 60.0f;
462462
}
463463

464+
private boolean isGestureNavigationEnabled;
465+
464466
@Override
465467
public void onCreate (Bundle savedInstanceState) {
466468
UI.setContext(this);
@@ -483,6 +485,7 @@ public void onCreate (Bundle savedInstanceState) {
483485
if (Config.USE_CUSTOM_NAVIGATION_COLOR) {
484486
this.isWindowLight = !Theme.isDark();
485487
}
488+
this.isGestureNavigationEnabled = Screen.isGesturalNavigationEnabled(getResources());
486489
// UI.resetSizes();
487490
setActivityState(UI.State.RESUMED);
488491
TdlibManager.instance().watchDog().onActivityCreate(this);
@@ -1137,6 +1140,7 @@ public void onResume () {
11371140
throw t;
11381141
}
11391142
checkAutoNightMode();
1143+
setGestureNavigationEnabled(Screen.isGesturalNavigationEnabled(getResources()));
11401144
Intents.revokeFileReadPermissions();
11411145
enableFocus();
11421146
if (timeFilter == null) {
@@ -1309,6 +1313,13 @@ configMode, systemNightModeToString(configMode),
13091313
}
13101314
}
13111315

1316+
private void setGestureNavigationEnabled (boolean isEnabled) {
1317+
if (this.isGestureNavigationEnabled != isEnabled) {
1318+
this.isGestureNavigationEnabled = isEnabled;
1319+
updateNavigationBarColor();
1320+
}
1321+
}
1322+
13121323
@Override
13131324
public void onConfigurationChanged (@NonNull Configuration newConfig) {
13141325
super.onConfigurationChanged(newConfig);
@@ -1320,6 +1331,7 @@ public void onConfigurationChanged (@NonNull Configuration newConfig) {
13201331
if (camera != null) {
13211332
camera.onConfigurationChanged(newConfig);
13221333
}
1334+
setGestureNavigationEnabled(Screen.isGesturalNavigationEnabled(getResources()));
13231335
currentOrientation = newConfig.orientation;
13241336
Lang.checkLanguageCode();
13251337
setSystemNightMode(newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK);
@@ -3352,7 +3364,7 @@ private void updateNavigationBarColor () {
33523364
color = ColorUtils.fromToArgb(color, Theme.getColor(ColorId.passcode), passcodeFactor);
33533365
isLight = isLight && passcodeFactor < .5f;
33543366
}
3355-
UI.setNavigationBarColor(getWindow(), color);
3367+
UI.setNavigationBarColor(getWindow(), color, isGestureNavigationEnabled);
33563368
if (this.isWindowLight != isLight) {
33573369
this.isWindowLight = isLight;
33583370
UI.setLightSystemBars(getWindow(), isLight, Theme.needLightStatusBar(), lastWindowVisibility, true);

app/src/main/java/org/thunderdog/challegram/tool/Screen.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.thunderdog.challegram.tool;
1616

1717
import android.content.Context;
18+
import android.content.res.Resources;
1819
import android.graphics.Point;
1920
import android.graphics.Rect;
2021
import android.os.Build;
@@ -273,18 +274,18 @@ public static int getNavigationBarFrameDifference () {
273274

274275
@Deprecated
275276
public static boolean needsKeyboardPadding (BaseActivity context) {
276-
return context.isKeyboardVisible() && isGesturalNavigationEnabled() && getNavigationBarHeight() > 0;
277+
return context.isKeyboardVisible() && isGesturalNavigationEnabled(UI.getResources()) && getNavigationBarHeight() > 0;
277278
}
278279

279-
private static boolean isGesturalNavigationEnabled () {
280+
public static boolean isGesturalNavigationEnabled (Resources resources) {
280281
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
281282
return false;
282283
}
283284

284285
try {
285-
int resourceId = UI.getResources().getIdentifier("config_navBarInteractionMode", "integer", "android");
286+
int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
286287
if (resourceId > 0) {
287-
return UI.getResources().getInteger(resourceId) == 2; // 2 is gestural by AOSP docs, SO says some Samsung devices can have values like 17694897, needs further investigation
288+
return resources.getInteger(resourceId) == 2; // 2 is gestural by AOSP docs, SO says some Samsung devices can have values like 17694897, needs further investigation
288289
}
289290
} catch (android.content.res.Resources.NotFoundException ignored) {}
290291

app/src/main/java/org/thunderdog/challegram/tool/UI.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,15 @@ public static void setLightSystemBars (Window w, boolean lightNavigationBar, boo
611611
w.getDecorView().setSystemUiVisibility(visibility);
612612
}
613613

614-
public static void setNavigationBarColor (Window w, int color) {
614+
public static void setNavigationBarColor (Window w, int color, boolean isGestureNavigationEnabled) {
615615
if (Config.USE_CUSTOM_NAVIGATION_COLOR) {
616616
if (Settings.instance().useEdgeToEdge()) {
617-
int transparentColor = Color.alpha(color) == 255 ? ColorUtils.alphaColor(.75f , color) : color;
618-
w.setNavigationBarColor(transparentColor);
617+
if (isGestureNavigationEnabled) {
618+
w.setNavigationBarColor(Color.TRANSPARENT);
619+
} else {
620+
int transparentColor = Color.alpha(color) == 255 ? ColorUtils.alphaColor(.75f, color) : color;
621+
w.setNavigationBarColor(transparentColor);
622+
}
619623
} else {
620624
w.setNavigationBarColor(color);
621625
}
@@ -640,7 +644,7 @@ public static void clearActivity (BaseActivity a) {
640644
w.setBackgroundDrawableResource(R.drawable.transparent);
641645
} else {
642646
if (Config.USE_CUSTOM_NAVIGATION_COLOR) {
643-
setNavigationBarColor(w, Theme.backgroundColor());
647+
setNavigationBarColor(w, Theme.backgroundColor(), Screen.isGesturalNavigationEnabled(getResources()));
644648
} else {
645649
w.setNavigationBarColor(NAVIGATION_BAR_COLOR);
646650
}

0 commit comments

Comments
 (0)