night mode,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 8 Sep 2011 12:49:31 +0000 (14:49 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 8 Sep 2011 12:49:31 +0000 (14:49 +0200)
new spinner

assets/www/css/style.css
assets/www/img/spinner.gif [deleted file]
assets/www/img/spinner.png [new file with mode: 0644]
assets/www/js/main.js
assets/www/js/menu.js
assets/www/js/menuinterface.js
assets/www/js/view.js
src/pl/org/nowoczesnapolska/wlmobi/Catalogue.java
src/pl/org/nowoczesnapolska/wlmobi/MenuInterface.java

index 8b17fb2..83271f0 100644 (file)
@@ -6,13 +6,38 @@
 body {
        padding: 0;
        margin: 0;
 body {
        padding: 0;
        margin: 0;
+       background: white;
        font-family: verdana, arial, helvetica, sans-serif;
 }
 
        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;
 }
 .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;
 #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 (file)
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 (file)
index 0000000..bad5a12
Binary files /dev/null and b/assets/www/img/spinner.png differ
index b4022d2..f3a1eee 100644 (file)
@@ -26,8 +26,10 @@ function onDeviceReady() {
                        History.init(function() {
                                console.log('after history.init');
                                View.init(function() {
                        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);
                                        }, error);
                                }, error);
                        }, error);
index 2f9400b..9fea371 100644 (file)
@@ -7,6 +7,10 @@ var Menu = new function() {
        var self = this;
        var infoView = "ProjectInfo";
 
        var self = this;
        var infoView = "ProjectInfo";
 
+       self.init = function() {
+               window.MenuInterface.setNightMode(View.getNightMode());
+       };
+
        self.start = function() {
                History.visit('');
        };
        self.start = function() {
                History.visit('');
        };
@@ -21,6 +25,11 @@ var Menu = new function() {
                        History.addBookmark(name);
        };
 
                        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);
        self.setInfoButton = function(view, label, enabled) {
                self.infoView = view;
                window.MenuInterface.setInfoButton(label, enabled);
index 6510424..596f859 100644 (file)
@@ -26,5 +26,16 @@ var MenuInterface = {
                        [label, enabled]
                );
        },
                        [label, enabled]
                );
        },
+       setNightMode: function(enabled, win, fail) {
+               if (enabled == false) enabled = "false";
+               else enabled = "true";
+               return PhoneGap.exec(
+                       win, 
+                       fail, 
+                       "MenuInterface", 
+                       "setNightMode", 
+                       [enabled]
+               );
+       },
 };
 
 };
 
index fe02c9e..f9a1576 100644 (file)
@@ -33,6 +33,9 @@ var View = new function() {
                self.currentTitle = '';
 
                document.getElementById("cover").style.display = 'none';
                self.currentTitle = '';
 
                document.getElementById("cover").style.display = 'none';
+
+               self.checkNightMode();
+
                self.enter('');
 
                success && success();
                self.enter('');
 
                success && success();
@@ -54,7 +57,8 @@ var View = new function() {
        this.spinner = function(text) {
                if (!text)
                        text = "Ładowanie";
        this.spinner = function(text) {
                if (!text)
                        text = "Ładowanie";
-               self._content.innerHTML = "<div class='spinner'><img src='img/spinner.gif' /><div id='spinnertext'>" + text +"</div></div>";
+               self._content.innerHTML = "";
+               self._content.innerHTML = "<div class='spinner'><img src='img/spinner.png' /><div id='spinnertext'>" + text +"</div></div>";
                setOffset(0);
        };
 
                setOffset(0);
        };
 
@@ -444,6 +448,32 @@ var View = new function() {
                return false;
        }
        
                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());
+       };
 }
 }
index 2cf726e..d296270 100644 (file)
@@ -5,6 +5,7 @@
 
 package pl.org.nowoczesnapolska.wlmobi;
 
 
 package pl.org.nowoczesnapolska.wlmobi;
 
+import android.graphics.Color;
 import android.os.Bundle;
 import android.view.KeyEvent;
 import android.view.Menu;
 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);
 
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+
         super.loadUrl("file:///android_asset/www/index.html");
 
         super.loadUrl("file:///android_asset/www/index.html");
 
+        MenuInterface.view = appView;
+
         WebSettings settings = this.appView.getSettings();
         settings.setSupportZoom(true);
         settings.setBuiltInZoomControls(true);
     }
 
         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");
     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);
         //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 3:
                this.appView.loadUrl("javascript:Menu.bookmark();");
                break;
+       case 4:
+               this.appView.loadUrl("javascript:Menu.toggleNightMode();");
+               break;
        default:
                return super.onOptionsItemSelected(item);
        }
        default:
                return super.onOptionsItemSelected(item);
        }
index 28f3f2e..064d4de 100644 (file)
@@ -8,6 +8,9 @@ package pl.org.nowoczesnapolska.wlmobi;
 import org.json.JSONArray;
 import org.json.JSONException;
 
 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;
 
 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 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) {
 
        @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");
                        }
                }
                                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);
                }
                else {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                }
@@ -36,4 +48,16 @@ public class MenuInterface extends Plugin{
 
                return new PluginResult(PluginResult.Status.OK);
        }
 
                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);
+       }
 }
 }