From: Radek Czajka Date: Thu, 8 Sep 2011 12:49:31 +0000 (+0200) Subject: night mode, X-Git-Url: https://git.mdrn.pl/wl-mobile.git/commitdiff_plain/6e087a91530a9731db6dd4b41bf69eda3409c0e9 night mode, new spinner --- diff --git a/assets/www/css/style.css b/assets/www/css/style.css index 8b17fb2..83271f0 100644 --- a/assets/www/css/style.css +++ b/assets/www/css/style.css @@ -6,13 +6,38 @@ body { padding: 0; margin: 0; + background: white; font-family: verdana, arial, helvetica, sans-serif; } +.night-mode { + color: #ddd; + background: #222; +} +.night-mode #search { + color: #ddd; + background: #222; +} + .spinner { margin-top: 4em; text-align: center; } +@-webkit-keyframes rotate { + from { + -webkit-transform: rotate(0deg); + } + to { + -webkit-transform: rotate(360deg); + } +} +.spinner img { + -webkit-animation-name: rotate; + -webkit-animation-duration: 4s; + -webkit-animation-iteration-count: 10; + -webkit-animation-direction: right; + -webkit-animation-timing-function:linear; +} #spinnertext { margin-top: 2em; font-size: .7em; diff --git a/assets/www/img/spinner.gif b/assets/www/img/spinner.gif deleted file mode 100644 index c69e937..0000000 Binary files a/assets/www/img/spinner.gif and /dev/null differ diff --git a/assets/www/img/spinner.png b/assets/www/img/spinner.png new file mode 100644 index 0000000..bad5a12 Binary files /dev/null and b/assets/www/img/spinner.png differ diff --git a/assets/www/js/main.js b/assets/www/js/main.js index b4022d2..f3a1eee 100644 --- a/assets/www/js/main.js +++ b/assets/www/js/main.js @@ -26,8 +26,10 @@ function onDeviceReady() { History.init(function() { console.log('after history.init'); View.init(function() { - Catalogue.sync(function() { - Catalogue.updateLocal(); + Menu.init(function() { + Catalogue.sync(function() { + Catalogue.updateLocal(); + }, error); }, error); }, error); }, error); diff --git a/assets/www/js/menu.js b/assets/www/js/menu.js index 2f9400b..9fea371 100644 --- a/assets/www/js/menu.js +++ b/assets/www/js/menu.js @@ -7,6 +7,10 @@ var Menu = new function() { var self = this; var infoView = "ProjectInfo"; + self.init = function() { + window.MenuInterface.setNightMode(View.getNightMode()); + }; + self.start = function() { History.visit(''); }; @@ -21,6 +25,11 @@ var Menu = new function() { History.addBookmark(name); }; + self.toggleNightMode = function() { + View.toggleNightMode(); + window.MenuInterface.setNightMode(View.getNightMode()); + }; + self.setInfoButton = function(view, label, enabled) { self.infoView = view; window.MenuInterface.setInfoButton(label, enabled); diff --git a/assets/www/js/menuinterface.js b/assets/www/js/menuinterface.js index 6510424..596f859 100644 --- a/assets/www/js/menuinterface.js +++ b/assets/www/js/menuinterface.js @@ -26,5 +26,16 @@ var MenuInterface = { [label, enabled] ); }, + setNightMode: function(enabled, win, fail) { + if (enabled == false) enabled = "false"; + else enabled = "true"; + return PhoneGap.exec( + win, + fail, + "MenuInterface", + "setNightMode", + [enabled] + ); + }, }; diff --git a/assets/www/js/view.js b/assets/www/js/view.js index fe02c9e..f9a1576 100644 --- a/assets/www/js/view.js +++ b/assets/www/js/view.js @@ -33,6 +33,9 @@ var View = new function() { self.currentTitle = ''; document.getElementById("cover").style.display = 'none'; + + self.checkNightMode(); + self.enter(''); success && success(); @@ -54,7 +57,8 @@ var View = new function() { this.spinner = function(text) { if (!text) text = "Ładowanie"; - self._content.innerHTML = "
" + text +"
"; + self._content.innerHTML = ""; + self._content.innerHTML = "
" + text +"
"; setOffset(0); }; @@ -444,6 +448,32 @@ var View = new function() { return false; } - + self.getNightMode = function() { + night_mode = window.localStorage.getItem('View.night_mode'); + if (night_mode === undefined) + return false; + else + return !!night_mode; + }; + + self.checkNightMode = function() { + night_mode = self.getNightMode(); + if (night_mode) { + document.body.setAttribute("class", "night-mode"); + } + else { + document.body.setAttribute("class", ""); + } + }; + + self.setNightMode = function(night_mode) { + night_mode = night_mode ? "1" : ""; + window.localStorage.setItem('View.night_mode', night_mode); + self.checkNightMode(); + }; + + self.toggleNightMode = function(night_mode) { + self.setNightMode(!self.getNightMode()); + }; } diff --git a/src/pl/org/nowoczesnapolska/wlmobi/Catalogue.java b/src/pl/org/nowoczesnapolska/wlmobi/Catalogue.java index 2cf726e..d296270 100644 --- a/src/pl/org/nowoczesnapolska/wlmobi/Catalogue.java +++ b/src/pl/org/nowoczesnapolska/wlmobi/Catalogue.java @@ -5,6 +5,7 @@ package pl.org.nowoczesnapolska.wlmobi; +import android.graphics.Color; import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; @@ -23,18 +24,22 @@ public class Catalogue extends DroidGap { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + super.loadUrl("file:///android_asset/www/index.html"); + MenuInterface.view = appView; + WebSettings settings = this.appView.getSettings(); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); } - @Override + @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(Menu.NONE, 1, 1, "Początek"); - menu.add(Menu.NONE, 2, 2, MenuInterface.infoLabel); - menu.add(Menu.NONE, 3, 3, "Dodaj zakładkę"); + menu.add(Menu.NONE, 3, 2, "Dodaj zakładkę"); + menu.add(Menu.NONE, 2, 3, MenuInterface.infoLabel); + menu.add(Menu.NONE, 4, 4, "Tryb nocny"); //MenuInflater inflater = getMenuInflater(); //inflater.inflate(R.menu.game_menu, menu); return super.onCreateOptionsMenu(menu); @@ -69,6 +74,9 @@ public class Catalogue extends DroidGap { case 3: this.appView.loadUrl("javascript:Menu.bookmark();"); break; + case 4: + this.appView.loadUrl("javascript:Menu.toggleNightMode();"); + break; default: return super.onOptionsItemSelected(item); } diff --git a/src/pl/org/nowoczesnapolska/wlmobi/MenuInterface.java b/src/pl/org/nowoczesnapolska/wlmobi/MenuInterface.java index 28f3f2e..064d4de 100644 --- a/src/pl/org/nowoczesnapolska/wlmobi/MenuInterface.java +++ b/src/pl/org/nowoczesnapolska/wlmobi/MenuInterface.java @@ -8,6 +8,9 @@ package pl.org.nowoczesnapolska.wlmobi; import org.json.JSONArray; import org.json.JSONException; +import android.graphics.Color; +import android.webkit.WebView; + import com.phonegap.api.Plugin; import com.phonegap.api.PluginResult; @@ -15,6 +18,8 @@ public class MenuInterface extends Plugin{ public static String infoLabel = "Proszę czekać..."; public static Boolean infoEnabled = false; + public static Boolean nightEnabled = false; + public static WebView view; @Override public PluginResult execute(String action, JSONArray args, String callbackId) { @@ -25,6 +30,13 @@ public class MenuInterface extends Plugin{ return new PluginResult(PluginResult.Status.ERROR, "Param errrors"); } } + else if (action.equals("setNightMode")) { + try { + return this.setNightMode(args.getString(0)); + } catch (JSONException e) { + return new PluginResult(PluginResult.Status.ERROR, "Param errrors"); + } + } else { return new PluginResult(PluginResult.Status.INVALID_ACTION); } @@ -36,4 +48,16 @@ public class MenuInterface extends Plugin{ return new PluginResult(PluginResult.Status.OK); } + + private PluginResult setNightMode(String enabled) { + nightEnabled = enabled.equals("true"); + if (nightEnabled) { + view.setBackgroundColor(0x222222ff); + } + else { + view.setBackgroundColor(Color.WHITE); + } + + return new PluginResult(PluginResult.Status.OK); + } }