cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cordova-plugin-splashscreen] SchnWalter commented on a change in pull request #206: Enable colors Android for status bar and navigation bar
Date Thu, 23 Apr 2020 01:34:06 GMT

SchnWalter commented on a change in pull request #206:
URL: https://github.com/apache/cordova-plugin-splashscreen/pull/206#discussion_r413440919



##########
File path: src/android/SplashScreen.java
##########
@@ -307,12 +311,45 @@ public void run() {
 
                 // Create and show the dialog
                 splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
+                splashWindow = splashDialog.getWindow();
                 // check to see if the splash screen should be full screen
                 if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
                         == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
                     splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                             WindowManager.LayoutParams.FLAG_FULLSCREEN);
                 }
+
+                // Inspirated in https://github.com/apache/cordova-plugin-splashscreen/pull/124/files
+                String statusBarColor = preferences.getString("SplashStatusBarBackgroundColor",
"#000000");
+
+                if (statusBarColor != null && !statusBarColor.isEmpty() &&
Build.VERSION.SDK_INT >= 19) {
+
+                    splashWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+                    splashWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+                    try {
+                        // Using reflection makes sure any 5.0+ device will work without
having to compile with SDK level 21
+                        splashWindow.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(splashWindow,
Color.parseColor(statusBarColor));
+                    } catch (Exception ignore) {
+                        // this should not happen, only in case Android removes this method
in a version > 21
+                        LOG.w("SplashScreen StatusBarColor", "Method window.setStatusBarColor
not found for SDK level " + Build.VERSION.SDK_INT);

Review comment:
       I've tested this inside a Android emulators and it works fine on API 27, 28 and 29.
   
   But it doesn't work on devices with EMUI 10 and API v29:
   ```
   SplashScreen StatusBarColor: »»» USING COLOR #ffd51e2b
   SplashScreen StatusBarColor: Method window.setStatusBarColor not found for SDK level 29
   SplashScreen StatusBarColor: »»» java.lang.NoSuchMethodException: com.android.internal.policy.HwPhoneWindow.setStatusBarColor
   ```
   
   L.E. This is a known issue and it has a simple fix replace the `getDeclaredMethod` call
with `getMethod`, see:
   
   * FIX: https://github.com/apache/cordova-plugin-statusbar/commit/916cccc2c00a1b7c77e2e738c83e74a22bdd55e7
   * https://issues.apache.org/jira/browse/CB-12164
   * https://issues.apache.org/jira/browse/CB-12188




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message