From: Soren Stoutner Date: Sat, 6 Feb 2016 00:28:37 +0000 (-0700) Subject: Create a settings activity. X-Git-Tag: v1.0~8 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=218e03269d47ababa71ae0dcec7b6ea8fef20454;p=PrivacyBrowserAndroid.git Create a settings activity. --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 66fc9a55..5c5adf6e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,6 +56,18 @@ + + + + + + + diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java index f58f1a2b..b0176a3f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java @@ -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 index 00000000..a1044a68 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/Settings.java @@ -0,0 +1,33 @@ +/** + * Copyright 2016 Soren Stoutner . + * + * 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 . + */ + +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); + } +} diff --git a/app/src/main/res/drawable/javascript_enabled.xml b/app/src/main/res/drawable/javascript_enabled.xml index 5dc5dfc7..b58a5614 100644 --- a/app/src/main/res/drawable/javascript_enabled.xml +++ b/app/src/main/res/drawable/javascript_enabled.xml @@ -8,6 +8,8 @@ android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> + + diff --git a/app/src/main/res/drawable/privacy_mode.xml b/app/src/main/res/drawable/privacy_mode.xml index 58101898..5b25cc9d 100644 --- a/app/src/main/res/drawable/privacy_mode.xml +++ b/app/src/main/res/drawable/privacy_mode.xml @@ -8,6 +8,8 @@ android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> + + diff --git a/app/src/main/res/drawable/warning.xml b/app/src/main/res/drawable/warning.xml index 9415215f..dbd18296 100644 --- a/app/src/main/res/drawable/warning.xml +++ b/app/src/main/res/drawable/warning.xml @@ -8,6 +8,8 @@ android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> + + diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml index df5cedb5..7b091e5d 100644 --- a/app/src/main/res/layout/activity_webview.xml +++ b/app/src/main/res/layout/activity_webview.xml @@ -1,3 +1,5 @@ + + + + + + #FF64DD17 + #FFD50000 + #FFFFD600 + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 47c82246..2512a380 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,3 +1,5 @@ + + 16dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49b5e94a..e6d9c2fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ + + Privacy Browser + Privacy Browser Settings Favorite Icon @@ -39,6 +42,7 @@ Share URL Add to Home Screen Downloads + Settings About Clear and Exit @@ -47,6 +51,18 @@ Cancel Create + + Privacy Settings + JavaScript + Enable JavaScript by default + DOM Storage + Enable DOM storage by default + Cookies + Enable cookies by default + General Settings + Homepage + Set the homepage + About Privacy Browser Dismiss diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9216c30a..f46fa1c3 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,5 +1,7 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file