Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09F96179DB for ; Wed, 4 Mar 2015 01:29:26 +0000 (UTC) Received: (qmail 54026 invoked by uid 500); 4 Mar 2015 01:29:10 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 53995 invoked by uid 500); 4 Mar 2015 01:29:10 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 53986 invoked by uid 99); 4 Mar 2015 01:29:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Mar 2015 01:29:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 00136E03B9; Wed, 4 Mar 2015 01:29:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: purplecabbage@apache.org To: commits@cordova.apache.org Date: Wed, 04 Mar 2015 01:29:09 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/4] cordova-plugin-statusbar git commit: Allow setting the statusbar backgroundcolor on Android Repository: cordova-plugin-statusbar Updated Branches: refs/heads/master 29b42dd93 -> bf17f4397 Allow setting the statusbar backgroundcolor on Android Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/43c8c15b Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/43c8c15b Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/43c8c15b Branch: refs/heads/master Commit: 43c8c15bf48d058fec9e91a6d2bcad17880b2b78 Parents: dff669e Author: EddyVerbruggen Authored: Fri Feb 27 10:29:39 2015 +0100 Committer: EddyVerbruggen Committed: Fri Feb 27 10:29:39 2015 +0100 ---------------------------------------------------------------------- doc/index.md | 4 ++++ src/android/StatusBar.java | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/43c8c15b/doc/index.md ---------------------------------------------------------------------- diff --git a/doc/index.md b/doc/index.md index 9955857..bd5bd1e 100644 --- a/doc/index.md +++ b/doc/index.md @@ -41,6 +41,10 @@ Preferences +- __AndroidStatusBarBackgroundColor__ (color hex string, defaults to the Android theme default). On Android 5 and up, the background color can be set by a hex string (#RRGGBB) at startup. We don't use the same property as for iOS because on iOS you typically want the statusbar to have the same color as the app background, but the Android 5+ guidelines specify using a different color than you apps main color, so the value of this property is typically different than the one specified by StatusBarBackgroundColor. + + + - __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque. http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/43c8c15b/src/android/StatusBar.java ---------------------------------------------------------------------- diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java index e4f748f..2cbb19e 100644 --- a/src/android/StatusBar.java +++ b/src/android/StatusBar.java @@ -20,6 +20,8 @@ package org.apache.cordova.statusbar; import android.app.Activity; +import android.graphics.Color; +import android.os.Build; import android.util.Log; import android.view.Window; import android.view.WindowManager; @@ -54,6 +56,7 @@ public class StatusBar extends CordovaPlugin { // by the Cordova. Window window = cordova.getActivity().getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); + setStatusBarBackgroundColor(); } }); } @@ -98,4 +101,26 @@ public class StatusBar extends CordovaPlugin { return false; } + + /** + * Read 'AndroidStatusBarBackgroundColor' from config.xml. We expect a hex #RRGGBB string. + */ + private void setStatusBarBackgroundColor() { + if (Build.VERSION.SDK_INT >= 21) { + final String colorPref = preferences.getString("AndroidStatusBarBackgroundColor", null); + if (colorPref != null) { + final Window window = cordova.getActivity().getWindow(); + // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK + window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(0x80000000); // SDK 21: 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 + window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref)); + } catch (Exception ignore) { + // this should not happen, only in case Android removes this method in a version > 21 + Log.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT); + } + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org