From 9cc023dd96ae4fdcd908153ebb7200ae0971cd75 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Thu, 16 Apr 2020 20:07:47 -0600 Subject: [PATCH] Set statusbar and app switcher header color on Android (close #41) --- config.xml | 1 + license-credits.md | 2 +- package.json | 6 +++++- www/assets/js/main.js | 26 ++++++++++++++++++++------ www/assets/js/platform.js | 4 ++++ www/pages/credits.html | 2 +- www/routes.js | 4 ++-- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/config.xml b/config.xml index bafc836..2155fb7 100644 --- a/config.xml +++ b/config.xml @@ -19,6 +19,7 @@ + diff --git a/license-credits.md b/license-credits.md index 1d0013d..f5be64e 100644 --- a/license-credits.md +++ b/license-credits.md @@ -2997,7 +2997,7 @@ The Apache Software Foundation (http://www.apache.org/). ----- -The following software may be included in this product: cordova-plugin-battery-status, cordova-plugin-device, cordova-plugin-inappbrowser, cordova-plugin-whitelist. A copy of the source code may be downloaded from https://github.com/apache/cordova-plugin-battery-status (cordova-plugin-battery-status), https://github.com/apache/cordova-plugin-device (cordova-plugin-device), https://github.com/apache/cordova-plugin-inappbrowser (cordova-plugin-inappbrowser), https://github.com/apache/cordova-plugin-whitelist (cordova-plugin-whitelist). This software contains the following license and notice below: +The following software may be included in this product: cordova-plugin-battery-status, cordova-plugin-device, cordova-plugin-inappbrowser, cordova-plugin-statusbar, cordova-plugin-whitelist. A copy of the source code may be downloaded from https://github.com/apache/cordova-plugin-battery-status (cordova-plugin-battery-status), https://github.com/apache/cordova-plugin-device (cordova-plugin-device), https://github.com/apache/cordova-plugin-inappbrowser (cordova-plugin-inappbrowser), https://github.com/apache/cordova-plugin-statusbar (cordova-plugin-statusbar), https://github.com/apache/cordova-plugin-whitelist (cordova-plugin-whitelist). This software contains the following license and notice below: Apache License Version 2.0, January 2004 diff --git a/package.json b/package.json index 33cad60..a996e96 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "cordova-plugin-whitelist": {}, "phonegap-plugin-barcodescanner": {}, "cordova-plugin-device": {}, - "cordova-plugin-battery-status": {} + "cordova-plugin-battery-status": {}, + "cordova-plugin-statusbar": {}, + "cordova-plugin-headercolor": {} }, "platforms": [ "android", @@ -39,8 +41,10 @@ "cordova-browser": "^6.0.0", "cordova-plugin-battery-status": "^2.0.3", "cordova-plugin-device": "^2.0.3", + "cordova-plugin-headercolor": "^1.0.0", "cordova-plugin-inappbrowser": "^3.1.0", "cordova-plugin-powermanagement-netsyms": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement", + "cordova-plugin-statusbar": "^2.4.3", "cordova-plugin-whitelist": "^1.3.4" }, "devDependencies": {} diff --git a/www/assets/js/main.js b/www/assets/js/main.js index 3f4881e..8cda0d6 100644 --- a/www/assets/js/main.js +++ b/www/assets/js/main.js @@ -101,19 +101,33 @@ if (getStorage("alertvolume") == null) { setStorage("alertvolume", 100); } +function setAppTheme(theme) { + if (theme == "light") { + $("#app").removeClass("theme-dark"); + if (platform_type == "cordova" && cordova.platformId == 'android' && typeof StatusBar !== 'undefined') { + StatusBar.styleDefault(); + StatusBar.backgroundColorByHexString("#E0E0E0"); + } + } else if (theme == "dark") { + $("#app").addClass("theme-dark"); + if (platform_type == "cordova" && cordova.platformId == 'android' && typeof StatusBar !== 'undefined') { + StatusBar.styleLightContent(); + StatusBar.backgroundColorByHexString("#000000"); + } + } +} + function applyColorTheme() { if (getStorage("apptheme") == "dark") { - // dark theme - $("#app").addClass("theme-dark"); + setAppTheme("dark"); } else if (getStorage("apptheme") == "light") { - // light theme - $("#app").removeClass("theme-dark"); + setAppTheme("light"); } else { // automatic theme, default light if (typeof Framework7.device.prefersColorScheme() !== 'undefined' && Framework7.device.prefersColorScheme() == "dark") { - $("#app").addClass("theme-dark"); + setAppTheme("dark"); } else { - $("#app").removeClass("theme-dark"); + setAppTheme("light"); } } } diff --git a/www/assets/js/platform.js b/www/assets/js/platform.js index 29a1856..64ccee0 100644 --- a/www/assets/js/platform.js +++ b/www/assets/js/platform.js @@ -122,6 +122,7 @@ function setupHTML5BarcodeScanner() { function initCordova() { platform_type = "cordova"; + // Handle back button to close things document.addEventListener("backbutton", handleBackButton, false); document.addEventListener("deviceready", function () { @@ -138,6 +139,9 @@ function initCordova() { console.log("Warn", 'Failed to release wakelock'); }); } + + // Make sure the status bar color is set properly + applyColorTheme(); }, false); openBrowser = function (url) { cordova.InAppBrowser.open(url, '_blank', 'location=yes'); diff --git a/www/pages/credits.html b/www/pages/credits.html index 5685829..0d34162 100644 --- a/www/pages/credits.html +++ b/www/pages/credits.html @@ -3102,7 +3102,7 @@ The Apache Software Foundation (http://www.apache.org/). ----- -The following software may be included in this product: cordova-plugin-battery-status, cordova-plugin-device, cordova-plugin-inappbrowser, cordova-plugin-whitelist. A copy of the source code may be downloaded from https://github.com/apache/cordova-plugin-battery-status (cordova-plugin-battery-status), https://github.com/apache/cordova-plugin-device (cordova-plugin-device), https://github.com/apache/cordova-plugin-inappbrowser (cordova-plugin-inappbrowser), https://github.com/apache/cordova-plugin-whitelist (cordova-plugin-whitelist). This software contains the following license and notice below: +The following software may be included in this product: cordova-plugin-battery-status, cordova-plugin-device, cordova-plugin-inappbrowser, cordova-plugin-statusbar, cordova-plugin-whitelist. A copy of the source code may be downloaded from https://github.com/apache/cordova-plugin-battery-status (cordova-plugin-battery-status), https://github.com/apache/cordova-plugin-device (cordova-plugin-device), https://github.com/apache/cordova-plugin-inappbrowser (cordova-plugin-inappbrowser), https://github.com/apache/cordova-plugin-statusbar (cordova-plugin-statusbar), https://github.com/apache/cordova-plugin-whitelist (cordova-plugin-whitelist). This software contains the following license and notice below: Apache License Version 2.0, January 2004 diff --git a/www/routes.js b/www/routes.js index ce15c27..a68dff8 100644 --- a/www/routes.js +++ b/www/routes.js @@ -485,8 +485,8 @@ var routes = [ text: "Log out", link: true, onclick: "logout()" - }, - ); + } + ); } else { settings.push( {