night mode,
[wl-mobile.git] / src / pl / org / nowoczesnapolska / wlmobi / MenuInterface.java
1 /*
2  * This file is part of WolneLektury-Mobile, licensed under GNU Affero GPLv3 or later.
3  * Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4  */
5
6 package pl.org.nowoczesnapolska.wlmobi;
7
8 import org.json.JSONArray;
9 import org.json.JSONException;
10
11 import android.graphics.Color;
12 import android.webkit.WebView;
13
14 import com.phonegap.api.Plugin;
15 import com.phonegap.api.PluginResult;
16
17 public class MenuInterface extends Plugin{
18
19         public static String infoLabel = "Proszę czekać...";
20         public static Boolean infoEnabled = false;
21         public static Boolean nightEnabled = false;
22         public static WebView view;
23
24         @Override
25         public PluginResult execute(String action, JSONArray args, String callbackId) {
26                 if (action.equals("setInfoButton")) {
27                         try {
28                                 return this.setInfoButton(args.getString(0), args.getString(1));
29                         } catch (JSONException e) {
30                                 return new PluginResult(PluginResult.Status.ERROR, "Param errrors");
31                         }
32                 }
33                 else if (action.equals("setNightMode")) {
34                         try {
35                                 return this.setNightMode(args.getString(0));
36                         } catch (JSONException e) {
37                                 return new PluginResult(PluginResult.Status.ERROR, "Param errrors");
38                         }
39                 }
40                 else {
41                         return new PluginResult(PluginResult.Status.INVALID_ACTION);
42                 }
43         }
44
45         private PluginResult setInfoButton(String label, String enabled) {
46         infoLabel = label;
47         infoEnabled = enabled.equals("true");
48
49                 return new PluginResult(PluginResult.Status.OK);
50         }
51
52         private PluginResult setNightMode(String enabled) {
53         nightEnabled = enabled.equals("true");
54         if (nightEnabled) {
55                 view.setBackgroundColor(0x222222ff);
56         }
57         else {
58                 view.setBackgroundColor(Color.WHITE);
59         }
60
61                 return new PluginResult(PluginResult.Status.OK);
62         }
63 }