Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Android: fix display of external links from Bitrefill
- fix language sometimes not persistent across app restarts
- Android: make the UI work with responsive font sizes and adhere to OS font size settings
- Android: fix layout issues with status and navigation bars.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" ... on Android 15+"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were issues also in previous versions


## v4.49.0
- Bundle BitBox02 Nova firmware version v9.24.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

Expand Down Expand Up @@ -50,37 +51,46 @@ public void onServiceDisconnected(ComponentName arg0) {
}
};

@Override
public void onConfigurationChanged(Configuration newConfig) {
int currentNightMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
// Night mode is not active, we're using the light theme
setDarkTheme(false);
break;
case Configuration.UI_MODE_NIGHT_YES:
// Night mode is active, we're using dark theme
setDarkTheme(true);
break;
}
super.onConfigurationChanged(newConfig);
}

public void setDarkTheme(boolean isDark) {
int flags = getWindow().getDecorView().getSystemUiVisibility(); // get current flag
int statusBarColor = ContextCompat.getColor(
getApplicationContext(),
isDark ? R.color.colorPrimaryDark : R.color.colorPrimary
);
// Pre-Oreo devices cannot render light nav bar icons, so fall back to dark bar to keep icons visible.
boolean supportsLightNavIcons = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
int navBarColor = supportsLightNavIcons
? statusBarColor
: ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark);

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(statusBarColor);
window.setNavigationBarColor(navBarColor);

View decorView = window.getDecorView();
int flags = decorView.getSystemUiVisibility(); // get current flag
if (isDark) {
Util.log("Dark theme");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; // remove LIGHT_STATUS_BAR to flag
getWindow().getDecorView().setSystemUiVisibility(flags);
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; // remove LIGHT_STATUS_BAR flag
if (supportsLightNavIcons) {
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
} else {
Util.log("Light theme");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; // add LIGHT_STATUS_BAR to flag
getWindow().getDecorView().setSystemUiVisibility(flags);
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; // add LIGHT_STATUS_BAR flag
if (supportsLightNavIcons) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
}
decorView.setSystemUiVisibility(flags);

View root = findViewById(R.id.root_layout);
WebView vw = findViewById(R.id.vw);
if (root != null) {
root.setBackgroundColor(statusBarColor);
}
if (vw != null) {
vw.setBackgroundColor(statusBarColor);
}
}

Expand All @@ -93,7 +103,6 @@ protected void onCreate(Bundle savedInstanceState) {
if (actionBar != null) {
actionBar.hide(); // hide title bar with app name.
}
onConfigurationChanged(getResources().getConfiguration());
setContentView(R.layout.activity_main);
final WebView vw = findViewById(R.id.vw);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/root_layout"
android:keepScreenOn="true"
android:fitsSystemWindows="true"
tools:context="ch.shiftcrypto.bitboxapp.MainActivity">

<WebView
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why in the v23 folder (we support v24+ only anyway)? Couldn't it simply be in res/values/styles.xml?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's v23 because some of the attributes are supported from v23+. But yeah, since our minSdk is 24 we could also collapse everything inside values/values-night folders.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>
<style name="AppTheme" parent="BaseAppTheme">
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar">false</item>
</style>
</resources>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
</style>

<!-- declare the theme name that's actually applied in the manifest file -->
<style name="AppTheme" parent="BaseAppTheme" />
<style name="AppTheme" parent="BaseAppTheme" >
<item name="android:statusBarColor">@color/colorPrimary</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar">true</item>
</style>
</resources>