Enable warning_on icon for toggleJavaScript.
authorSoren Stoutner <soren@stoutner.com>
Wed, 3 Feb 2016 05:49:28 +0000 (22:49 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 3 Feb 2016 05:49:28 +0000 (22:49 -0700)
app/src/main/assets/about_text.html
app/src/main/java/com/stoutner/privacybrowser/MainWebView.java
app/src/main/res/drawable/javascript_off.xml [deleted file]
app/src/main/res/drawable/privacy_mode.xml [new file with mode: 0644]
app/src/main/res/drawable/warning_on.xml [new file with mode: 0644]

index 482a1f6fb76b6e80c3d79ae3125170cc7e609fc3..89d2ab9bb776dfa37383045759e89c361557d57b 100644 (file)
@@ -9,7 +9,10 @@
 <p>/app/src/main/res/drawable/javascript_on.xml is part of the Android Material icon set, where it is named ic_visibility.
     It is released under the <a href=https://creativecommons.org/licenses/by/4.0/>CC-BY license</a>.  Changes to fill color were made by Soren Stoutner in 2016.</p>
 
-<p>/app/src/main/res/drawable/javascript_off.xml is part of the Android Material icon set, where it is named ic_visibility_off.
+<p>/app/src/main/res/drawable/warning_on.xml is part of the Android Material icon set, where it is named ic_visibility.
+    It is released under the <a href=https://creativecommons.org/licenses/by/4.0/>CC-BY license</a>.  Changes to fill color were made by Soren Stoutner in 2016.</p>
+
+<p>/app/src/main/res/drawable/privacy_mode.xml is part of the Android Material icon set, where it is named ic_visibility_off.
     It is released under the <a href=https://creativecommons.org/licenses/by/4.0/>CC-BY license</a>.  Changes to fill color were made by Soren Stoutner in 2016.</p>
 
 <br/>
index d4b134747642db01fd4958838186fb8ea1aab366..0b9c117a1ca962cacfa02073e9e08c5cbd23c368 100644 (file)
@@ -63,6 +63,8 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
     // mainWebView is public static so it can be accessed from AboutDialog.  It is also used in onCreate(), onOptionsItemSelected(), and loadUrlFromTextBox().
     public static WebView mainWebView;
 
+    // mainMenu is used in onCreateOptionsMenu() and onOptionsItemSelected().
+    private Menu mainMenu;
     // formattedUrlString is used in onCreate(), onOptionsItemSelected(), onCreateHomeScreenShortcutCreate(), and loadUrlFromTextBox().
     private String formattedUrlString;
     // homepage is used in onCreate() and onOptionsItemSelected().
@@ -299,7 +301,7 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
 
     @Override
     protected void onNewIntent(Intent intent) {
-        // Sets the new intent as the activity intent, so that any future getIntent() picks up this one.
+        // Sets the new intent as the activity intent, so that any future getIntent()s pick up this one instead of creating a new activity.
         setIntent(intent);
 
         if (intent.getData() != null) {
@@ -317,6 +319,9 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.menu_webview, menu);
 
+        // Set mainMenu so it can be used by onOptionsItemSelected.
+        mainMenu = menu;
+
         // Get MenuItems for checkable menu items.
         MenuItem toggleJavaScript = menu.findItem(R.id.toggleJavaScript);
         MenuItem toggleDomStorage = menu.findItem(R.id.toggleDomStorage);
@@ -329,7 +334,11 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
         if (javaScriptEnabled) {
             toggleJavaScript.setIcon(R.drawable.javascript_on);
         } else {
-            toggleJavaScript.setIcon(R.drawable.javascript_off);
+            if (domStorageEnabled || cookiesEnabled) {
+                toggleJavaScript.setIcon(R.drawable.warning_on);
+            } else {
+                toggleJavaScript.setIcon(R.drawable.privacy_mode);
+            }
         }
 
         // Set the initial status of the menu item checkboxes.
@@ -372,23 +381,43 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
     @SuppressWarnings("deprecation")
     public boolean onOptionsItemSelected(MenuItem menuItem) {
         int menuItemId = menuItem.getItemId();
+
+        // Some options need to access the clipboard.
         ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
 
+        // Some options need to update the drawable for toggleJavaScript.
+        MenuItem toggleJavaScript = mainMenu.findItem(R.id.toggleJavaScript);
+
         // Sets the commands that relate to the menu entries.
         switch (menuItemId) {
             case R.id.toggleJavaScript:
                 if (javaScriptEnabled) {
                     javaScriptEnabled = false;
-                    menuItem.setIcon(R.drawable.javascript_off);
                     mainWebView.getSettings().setJavaScriptEnabled(false);
                     mainWebView.reload();
-                    Toast.makeText(getApplicationContext(), "JavaScript Disabled", Toast.LENGTH_SHORT).show();
+
+                    // Update the toggleJavaScript icon and display a toast message.
+                    if (domStorageEnabled || cookiesEnabled) {
+                        menuItem.setIcon(R.drawable.warning_on);
+                        if (domStorageEnabled && cookiesEnabled) {
+                            Toast.makeText(getApplicationContext(), "JavaScript disabled, DOM Storage and Cookies still enabled", Toast.LENGTH_SHORT).show();
+                        } else {
+                            if (domStorageEnabled) {
+                                Toast.makeText(getApplicationContext(), "JavaScript disabled, DOM Storage still enabled", Toast.LENGTH_SHORT).show();
+                            } else {
+                                Toast.makeText(getApplicationContext(), "JavaScript disabled, Cookies still enabled", Toast.LENGTH_SHORT).show();
+                            }
+                        }
+                    } else {
+                        menuItem.setIcon(R.drawable.privacy_mode);
+                        Toast.makeText(getApplicationContext(), "Privacy Mode", Toast.LENGTH_SHORT).show();
+                    }
                 } else {
                     javaScriptEnabled = true;
                     menuItem.setIcon(R.drawable.javascript_on);
                     mainWebView.getSettings().setJavaScriptEnabled(true);
                     mainWebView.reload();
-                    Toast.makeText(getApplicationContext(), "JavaScript Enabled", Toast.LENGTH_SHORT).show();
+                    Toast.makeText(getApplicationContext(), "JavaScript enabled", Toast.LENGTH_SHORT).show();
                 }
                 return true;
 
@@ -398,11 +427,29 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
                     menuItem.setChecked(false);
                     mainWebView.getSettings().setDomStorageEnabled(false);
                     mainWebView.reload();
+
+                    // Update the toggleJavaScript icon and display a toast message if appropriate.
+                    if (!javaScriptEnabled && !cookiesEnabled) {
+                        toggleJavaScript.setIcon(R.drawable.privacy_mode);
+                        Toast.makeText(getApplicationContext(), "Privacy Mode", Toast.LENGTH_SHORT).show();
+                    } else {
+                        if (cookiesEnabled) {
+                            toggleJavaScript.setIcon(R.drawable.warning_on);
+                            Toast.makeText(getApplicationContext(), "Cookies still enabled", Toast.LENGTH_SHORT).show();
+                        } // Else Do nothing because JavaScript is enabled.
+                    }
                 } else {
                     domStorageEnabled = true;
                     menuItem.setChecked(true);
                     mainWebView.getSettings().setDomStorageEnabled(true);
                     mainWebView.reload();
+
+                    // Update the toggleJavaScript icon if appropriate.
+                    if (!javaScriptEnabled) {
+                        toggleJavaScript.setIcon(R.drawable.warning_on);
+                    } // Else Do nothing because JavaScript is enabled.
+
+                    Toast.makeText(getApplicationContext(), "DOM Storage enabled", Toast.LENGTH_SHORT).show();
                 }
                 return true;
 
@@ -428,11 +475,29 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
                     menuItem.setChecked(false);
                     cookieManager.setAcceptCookie(false);
                     mainWebView.reload();
+
+                    // Update the toggleJavaScript icon and display a toast message if appropriate.
+                    if (!javaScriptEnabled && !domStorageEnabled) {
+                        toggleJavaScript.setIcon(R.drawable.privacy_mode);
+                        Toast.makeText(getApplicationContext(), "Privacy Mode", Toast.LENGTH_SHORT).show();
+                    } else {
+                        if (domStorageEnabled) {
+                            toggleJavaScript.setIcon(R.drawable.warning_on);
+                            Toast.makeText(getApplicationContext(), "DOM Storage still enabled", Toast.LENGTH_SHORT).show();
+                        } // Else Do nothing because JavaScript is enabled.
+                    }
                 } else {
                     cookiesEnabled = true;
                     menuItem.setChecked(true);
                     cookieManager.setAcceptCookie(true);
                     mainWebView.reload();
+
+                    // Update the toggleJavaScript icon if appropriate.
+                    if (!javaScriptEnabled) {
+                        toggleJavaScript.setIcon(R.drawable.warning_on);
+                    } // Else Do nothing because JavaScript is enabled.
+
+                    Toast.makeText(getApplicationContext(), "Cookies enabled", Toast.LENGTH_SHORT).show();
                 }
                 return true;
 
diff --git a/app/src/main/res/drawable/javascript_off.xml b/app/src/main/res/drawable/javascript_off.xml
deleted file mode 100644 (file)
index 0965c3e..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<!--
-  javascript_off.xml is part of the Android Material icon set, where it is named ic_visibility_off.
-  It is released under the CC-BY license <https://creativecommons.org/licenses/by/4.0/>.
-  Changes to fill color were made by Soren Stoutner in 2016. -->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="24dp"
-        android:height="24dp"
-        android:viewportWidth="24.0"
-        android:viewportHeight="24.0">
-    <path
-        android:fillColor="#88000000"
-        android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zm4.31,-0.78l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
-</vector>
diff --git a/app/src/main/res/drawable/privacy_mode.xml b/app/src/main/res/drawable/privacy_mode.xml
new file mode 100644 (file)
index 0000000..8fb3bee
--- /dev/null
@@ -0,0 +1,14 @@
+<!--
+  privacy_mode.xml is part of the Android Material icon set, where it is named ic_visibility_off.
+  It is released under the CC-BY license <https://creativecommons.org/licenses/by/4.0/>.
+  Changes to fill color were made by Soren Stoutner in 2016. -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#88000000"
+        android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zm4.31,-0.78l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
+</vector>
diff --git a/app/src/main/res/drawable/warning_on.xml b/app/src/main/res/drawable/warning_on.xml
new file mode 100644 (file)
index 0000000..2de8773
--- /dev/null
@@ -0,0 +1,14 @@
+<!--
+  warning_on.xml is part of the Android Material icon set, where it is named ic_visibility.
+  It is released under the CC-BY license <https://creativecommons.org/licenses/by/4.0/>.
+  Changes to fill color were made by Soren Stoutner in 2016. -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFFFD600"
+        android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zm0,-8c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
+</vector>