]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Create a settings activity.
authorSoren Stoutner <soren@stoutner.com>
Sat, 6 Feb 2016 00:28:37 +0000 (17:28 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 6 Feb 2016 00:28:37 +0000 (17:28 -0700)
14 files changed:
app/src/main/AndroidManifest.xml
app/src/main/java/com/stoutner/privacybrowser/MainWebView.java
app/src/main/java/com/stoutner/privacybrowser/Settings.java [new file with mode: 0644]
app/src/main/res/drawable/javascript_enabled.xml
app/src/main/res/drawable/privacy_mode.xml
app/src/main/res/drawable/warning.xml
app/src/main/res/layout/activity_webview.xml
app/src/main/res/menu/menu_webview.xml
app/src/main/res/values-w820dp/dimens.xml
app/src/main/res/values/colors.xml [new file with mode: 0644]
app/src/main/res/values/dimens.xml
app/src/main/res/values/strings.xml
app/src/main/res/values/styles.xml
app/src/main/res/xml/preferences.xml [new file with mode: 0644]

index 66fc9a55706f27eab2d5047c0c6c598cff380b8a..5c5adf6e5e80b07b89d0b13fa36dd6cf6c7acef0 100644 (file)
                 <data android:scheme="https" />
             </intent-filter>
         </activity>
+
+        <activity
+            android:name=".Settings"
+            android:label="@string/privacy_browser_settings"
+            android:parentActivityName=".MainWebView" >
+
+            <!-- android.support.PARENT_ACTIVITY is necessary for API <= 15. -->
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value=".MainWebView" />
+        </activity>
+
     </application>
 
 </manifest>
index f58f1a2b02313e570de57a202d570b802c962b1f..b0176a3f1506e9a19b8129e96ba35edbb32ee2b5 100644 (file)
@@ -27,10 +27,12 @@ import android.content.ClipData;
 import android.content.ClipboardManager;
 import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.support.v4.app.DialogFragment;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
@@ -68,7 +70,7 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
     // formattedUrlString is used in onCreate(), onOptionsItemSelected(), onCreateHomeScreenShortcutCreate(), and loadUrlFromTextBox().
     private String formattedUrlString;
     // homepage is used in onCreate() and onOptionsItemSelected().
-    private String homepage = "https://www.duckduckgo.com/";
+    private String homepage;
     // javaScriptEnabled is used in onCreate(), onCreateOptionsMenu(), onOptionsItemSelected(), and loadUrlFromTextBox().
     private boolean javaScriptEnabled;
     // domStorageEnabled is used in onCreate(), onCreateOptionsMenu(), and onOptionsItemSelected().
@@ -262,12 +264,18 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
             mainWebView.getSettings().setDisplayZoomControls(false);
         }
 
+        // Initialize the default preference values the first time the program is run.
+        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
+
+        // Get the shared preference values.
+        SharedPreferences savedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
         // Set JavaScript initial status.
-        javaScriptEnabled = false;
+        javaScriptEnabled = savedPreferences.getBoolean("javascript_enabled", false);
         mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled);
 
-        // Set DOM Storage initial status.
-        domStorageEnabled = false;
+        // Set DOM storage initial status.
+        domStorageEnabled = savedPreferences.getBoolean("dom_storage_enabled", false);
         mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled);
 
         /* Save Form Data does nothing until database storage is implemented.
@@ -276,11 +284,14 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
         mainWebView.getSettings().setSaveFormData(saveFormDataEnabled);
         */
 
-        // Set Cookies initial status.
-        cookiesEnabled = false;
+        // Set cookies initial status.
+        cookiesEnabled = savedPreferences.getBoolean("cookies_enabled", false);
         cookieManager = CookieManager.getInstance();
         cookieManager.setAcceptCookie(cookiesEnabled);
 
+        // Set hompage initial status.
+        homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com");
+
         // Get the intent information that started the app.
         final Intent intent = getIntent();
 
@@ -572,6 +583,12 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
                 startActivity(downloadManangerIntent);
                 return true;
 
+            case R.id.settings:
+                // Start the Settings activity.
+                Intent intent = new Intent(this, Settings.class);
+                startActivity(intent);
+                return true;
+
             case R.id.about:
                 // Show the AboutDialog AlertDialog and name this instance aboutDialog.
                 AppCompatDialogFragment aboutDialog = new AboutDialog();
diff --git a/app/src/main/java/com/stoutner/privacybrowser/Settings.java b/app/src/main/java/com/stoutner/privacybrowser/Settings.java
new file mode 100644 (file)
index 0000000..a1044a6
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2016 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser.
+ *
+ * Privacy Browser is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.stoutner.privacybrowser;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class Settings extends PreferenceActivity {
+    @Override
+    // Once the minimum API is >= 11 we can switch from the deprecated PreferenceActivity to using a PreferenceFragment.
+    @SuppressWarnings("deprecation")
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.preferences);
+    }
+}
index 5dc5dfc758cfa94e642bb389a3f5f854f4a9784a..b58a56140a40e48d740b92eabe5752ee5ef121c6 100644 (file)
@@ -8,6 +8,8 @@
         android:height="24dp"
         android:viewportWidth="24.0"
         android:viewportHeight="24.0">
+
+    <!-- The fillColor must be hardcoded in this file unitl the minimum API is >= 22.  Then the resources in colors.xml may be used instead. -->
     <path
         android:fillColor="#FFD50000"
         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"/>
index 58101898870ff9b2850c3ec0cb072991288faccc..5b25cc9d04c159be5d4b53eb03e475f74263a385 100644 (file)
@@ -8,6 +8,8 @@
         android:height="24dp"
         android:viewportWidth="24.0"
         android:viewportHeight="24.0">
+
+    <!-- The fillColor must be hardcoded in this file unitl the minimum API is >= 22.  Then the resources in colors.xml may be used instead. -->
     <path
         android:fillColor="#FF64DD17"
         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"/>
index 9415215fde12ecc7d8baeb827a3c3f94117a614d..dbd18296ad5c8214e12c95641722d557a9920ed1 100644 (file)
@@ -8,6 +8,8 @@
         android:height="24dp"
         android:viewportWidth="24.0"
         android:viewportHeight="24.0">
+
+    <!-- The fillColor must be hardcoded in this file unitl the minimum API is >= 22.  Then the resources in colors.xml may be used instead. -->
     <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"/>
index df5cedb5c17ef2440e2c915bab09e1c7af8f0a2a..7b091e5d7a815751ddddedc088c9f61ad1f82e40 100644 (file)
@@ -1,3 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+
 <!--
   Copyright 2015 Soren Stoutner <soren@stoutner.com>.
 
index fe01a0bdac9a725687c90de6b8a34c33c32e2da5..29a57e557401a62d506be2cf9d8b9ab14828c853 100644 (file)
@@ -1,3 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+
 <!--
   Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
 
         android:orderInCategory="90"
         app:showAsAction="never" />
 
+    <item
+        android:id="@+id/settings"
+        android:title="@string/settings"
+        android:orderInCategory="100"
+        app:showAsAction="never" />
+
     <item
         android:id="@+id/about"
         android:title="@string/about"
-        android:orderInCategory="100"
+        android:orderInCategory="110"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clearAndExit"
         android:title="@string/clear_and_exit"
-        android:orderInCategory="110"
+        android:orderInCategory="120"
         app:showAsAction="never" />
 </menu>
index 63fc816444614bd64f68a372d1f93211628ee51d..55ebf55455dc5856b62fd395bf56246b39f096b3 100644 (file)
@@ -1,3 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+
 <resources>
     <!-- Example customization of dimensions originally defined in res/values/dimens.xml
          (such as screen margins) for screens with more than 820dp of available width. This
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644 (file)
index 0000000..e33adcc
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Copyright 2016 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser <https://privacybrowser.stoutner.com/>.
+
+  Privacy Browser is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Privacy Browser is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
+
+<!-- These color resources are hardcoded for vector drawables.  Once the minimum API is >= 22 we can remove the hardcoded colors and reference these entries. -->
+<resources>
+    <color name="green">#FF64DD17</color>
+    <color name="red">#FFD50000</color>
+    <color name="yellow">#FFFFD600</color>
+</resources>
\ No newline at end of file
index 47c82246738c4d056e8030d3a259206f42e8e15d..2512a380e81aa395acca03def59e183f140d9fa3 100644 (file)
@@ -1,3 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+
 <resources>
     <!-- Default screen margins, per the Android Design guidelines. -->
     <dimen name="activity_horizontal_margin">16dp</dimen>
index 49b5e94ac9466f86538984c5370145da2630addc..e6d9c2fdfdf2a097d7d27f43c2db2541c731652d 100644 (file)
@@ -1,3 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+
 <!--
   Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
 
@@ -19,6 +21,7 @@
 <resources>
     <!-- Activities. -->
     <string name="privacy_browser">Privacy Browser</string>
+    <string name="privacy_browser_settings">Privacy Browser Settings</string>
 
     <!-- Custom App Bar. -->
     <string name="favorite_icon">Favorite Icon</string>
@@ -39,6 +42,7 @@
     <string name="share_url">Share URL</string>
     <string name="add_to_home_screen">Add to Home Screen</string>
     <string name="downloads">Downloads</string>
+    <string name="settings">Settings</string>
     <string name="about">About</string>
     <string name="clear_and_exit">Clear and Exit</string>
 
     <string name="cancel">Cancel</string>
     <string name="create">Create</string>
 
+    <!-- Preferences. -->
+    <string name="privacy_settings">Privacy Settings</string>
+    <string name="javascript_preference">JavaScript</string>
+    <string name="javascript_preference_summary">Enable JavaScript by default</string>
+    <string name="dom_storage_preference">DOM Storage</string>
+    <string name="dom_storage_preference_summary">Enable DOM storage by default</string>
+    <string name="cookies_preference">Cookies</string>
+    <string name="cookies_preference_summary">Enable cookies by default</string>
+    <string name="general_settings">General Settings</string>
+    <string name="homepage_preference">Homepage</string>
+    <string name="homepage_preference_summary">Set the homepage</string>
+
     <!-- About Dialog. -->
     <string name="about_privacy_browser">About Privacy Browser</string>
     <string name="dismiss">Dismiss</string>
index 9216c30a6322513afa1312d4e3018de28aecca72..f46fa1c35de154c280392192b3066968d8904cd2 100644 (file)
@@ -1,5 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+
 <!--
-  Copyright 2015 Soren Stoutner <soren@stoutner.com>.
+  Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
 
   This file is part of Privacy Browser <https://privacybrowser.stoutner.com/>.
 
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
new file mode 100644 (file)
index 0000000..97965a5
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Copyright 2016 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser <https://privacybrowser.stoutner.com/>.
+
+  Privacy Browser is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Privacy Browser is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+    <PreferenceCategory
+        android:key="privacy_settings"
+        android:title="@string/privacy_settings" >
+
+        <CheckBoxPreference
+            android:key="javascript_enabled"
+            android:title="@string/javascript_preference"
+            android:summary="@string/javascript_preference_summary"
+            android:defaultValue="false" />
+
+        <CheckBoxPreference
+            android:key="dom_storage_enabled"
+            android:title="@string/dom_storage_preference"
+            android:summary="@string/dom_storage_preference_summary"
+            android:defaultValue="false" />
+
+        <CheckBoxPreference
+            android:key="cookies_enabled"
+            android:title="@string/cookies_preference"
+            android:summary="@string/cookies_preference_summary"
+            android:defaultValue="false" />
+    </PreferenceCategory>
+
+    <PreferenceCategory
+        android:key="general_settings"
+        android:title="@string/general_settings" >
+
+        <EditTextPreference
+            android:key="homepage"
+            android:title="@string/homepage_preference"
+            android:summary="@string/homepage_preference_summary"
+            android:defaultValue="https://www.duckduckgo.com" />
+    </PreferenceCategory>
+</PreferenceScreen>
\ No newline at end of file