diff options
Diffstat (limited to 'android/app/src/twa/java')
| -rw-r--r-- | android/app/src/twa/java/io/coinos/app/LauncherActivity.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/android/app/src/twa/java/io/coinos/app/LauncherActivity.java b/android/app/src/twa/java/io/coinos/app/LauncherActivity.java index 654265b..bf960e2 100644 --- a/android/app/src/twa/java/io/coinos/app/LauncherActivity.java +++ b/android/app/src/twa/java/io/coinos/app/LauncherActivity.java @@ -1,10 +1,13 @@ package io.coinos.app; import android.Manifest; +import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Parcelable; +import android.util.SparseArray; import java.net.URLEncoder; @@ -36,6 +39,47 @@ public class LauncherActivity } } + // The navigation bar is left to the browser and the system. The helper + // library always names a colour for it (white when the manifest names + // none), and on Android 17 / Chrome 154 the Custom Tab window paints that + // bar white whatever colour it's given while the buttons follow the colour + // asked for — white buttons on white. So the colour is taken off the + // launch intent on its way to the browser, light and dark scheme alike. + private static final String NAV = "androidx.browser.customtabs.extra.NAVIGATION_BAR_COLOR"; + private static final String NAV_DIVIDER = "androidx.browser.customtabs.extra.NAVIGATION_BAR_DIVIDER_COLOR"; + private static final String SCHEMES = "androidx.browser.customtabs.extra.COLOR_SCHEME_PARAMS"; + + private static void dropNavColors(Intent intent) { + if (intent == null || !intent.hasExtra("android.support.customtabs.extra.SESSION")) return; + try { + intent.removeExtra(NAV); + intent.removeExtra(NAV_DIVIDER); + Bundle extras = intent.getExtras(); + SparseArray<Parcelable> schemes = extras == null ? null : extras.getSparseParcelableArray(SCHEMES); + if (schemes == null) return; + for (int i = 0; i < schemes.size(); i++) { + if (schemes.valueAt(i) instanceof Bundle) { + ((Bundle) schemes.valueAt(i)).remove(NAV); + ((Bundle) schemes.valueAt(i)).remove(NAV_DIVIDER); + } + } + extras.putSparseParcelableArray(SCHEMES, schemes); + intent.replaceExtras(extras); + } catch (Exception ignored) {} + } + + @Override + public void startActivity(Intent intent) { + dropNavColors(intent); + super.startActivity(intent); + } + + @Override + public void startActivity(Intent intent, Bundle options) { + dropNavColors(intent); + super.startActivity(intent, options); + } + @Override protected Uri getLaunchingUrl() { Uri data = getIntent().getData(); |
