]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Create controls for font size.
authorSoren Stoutner <soren@stoutner.com>
Mon, 22 Aug 2016 20:37:21 +0000 (13:37 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 22 Aug 2016 20:37:21 +0000 (13:37 -0700)
app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java
app/src/main/res/menu/webview_options_menu.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index f27f961580a772867b7cbb0f1fe750cc52ee23b6..4cad1873faf00f8c275ee0c1c8bf31d09214b406 100644 (file)
@@ -415,10 +415,14 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         }
 
 
         }
 
 
-        // Set homepage initial status.  The default value is "https://www.duckduckgo.com".
+        // Set the homepage initial status.  The default value is `https://www.duckduckgo.com`.
         homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com");
 
         homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com");
 
-        // Set swipe to refresh initial status.  The default is true.
+        // Set the font size initial status.  the default value is `100`.
+        String defaultFontSizeString = savedPreferences.getString("default_font_size", "100");
+        mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString));
+
+        // Set the swipe to refresh initial status.  The default is `true`.
         swipeToRefreshEnabled = savedPreferences.getBoolean("swipe_to_refresh_enabled", true);
         swipeToRefresh.setEnabled(swipeToRefreshEnabled);
 
         swipeToRefreshEnabled = savedPreferences.getBoolean("swipe_to_refresh_enabled", true);
         swipeToRefresh.setEnabled(swipeToRefreshEnabled);
 
@@ -488,15 +492,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Initialize privacyIcon
         privacyIcon = menu.findItem(R.id.toggleJavaScript);
 
         // Initialize privacyIcon
         privacyIcon = menu.findItem(R.id.toggleJavaScript);
 
+        // Set the initial status of the privacy icon.
+        updatePrivacyIcon();
+
         // Get MenuItems for checkable menu items.
         MenuItem toggleFirstPartyCookies = menu.findItem(R.id.toggleFirstPartyCookies);
         MenuItem toggleThirdPartyCookies = menu.findItem(R.id.toggleThirdPartyCookies);
         MenuItem toggleDomStorage = menu.findItem(R.id.toggleDomStorage);
         MenuItem toggleSaveFormData = menu.findItem(R.id.toggleSaveFormData);
 
         // Get MenuItems for checkable menu items.
         MenuItem toggleFirstPartyCookies = menu.findItem(R.id.toggleFirstPartyCookies);
         MenuItem toggleThirdPartyCookies = menu.findItem(R.id.toggleThirdPartyCookies);
         MenuItem toggleDomStorage = menu.findItem(R.id.toggleDomStorage);
         MenuItem toggleSaveFormData = menu.findItem(R.id.toggleSaveFormData);
 
-        // Set the initial status of the privacy icon.
-        updatePrivacyIcon();
-
         // Set the initial status of the menu item checkboxes.
         toggleFirstPartyCookies.setChecked(firstPartyCookiesEnabled);
         toggleThirdPartyCookies.setChecked(thirdPartyCookiesEnabled);
         // Set the initial status of the menu item checkboxes.
         toggleFirstPartyCookies.setChecked(firstPartyCookiesEnabled);
         toggleThirdPartyCookies.setChecked(thirdPartyCookiesEnabled);
@@ -529,6 +533,56 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this);
         clearFormData.setEnabled(mainWebViewDatabase.hasFormData());
 
         WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this);
         clearFormData.setEnabled(mainWebViewDatabase.hasFormData());
 
+        // Select the current font size.
+        int fontSize = mainWebView.getSettings().getTextZoom();
+        MenuItem fontSizeMenuItem = menu.findItem(R.id.fontSize);
+        MenuItem selectedFontSizeMenuItem;
+        switch (fontSize) {
+            case 50:
+                fontSizeMenuItem.setTitle(R.string.font_size_fifty_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeFiftyPercent);
+                break;
+
+            case 75:
+                fontSizeMenuItem.setTitle(R.string.font_size_seventy_five_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeSeventyFivePercent);
+                break;
+
+            case 100:
+                fontSizeMenuItem.setTitle(R.string.font_size_one_hundred_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeOneHundredPercent);
+                break;
+
+            case 125:
+                fontSizeMenuItem.setTitle(R.string.font_size_one_hundred_twenty_five_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeOneHundredTwentyFivePercent);
+                break;
+
+            case 150:
+                fontSizeMenuItem.setTitle(R.string.font_size_one_hundred_fifty_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeOneHundredFiftyPercent);
+                break;
+
+            case 175:
+                fontSizeMenuItem.setTitle(R.string.font_size_one_hundred_seventy_five_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeOneHundredSeventyFivePercent);
+                break;
+
+            case 200:
+                fontSizeMenuItem.setTitle(R.string.font_size_two_hundred_percent);
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeTwoHundredPercent);
+                break;
+
+            default:
+                selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeOneHundredPercent);
+                break;
+        }
+        selectedFontSizeMenuItem.setChecked(true);
+
+        // Only show `Refresh` if `swipeToRefresh` is disabled.
+        MenuItem refreshMenuItem = menu.findItem(R.id.refresh);
+        refreshMenuItem.setVisible(!swipeToRefreshEnabled);
+
         // Run all the other default commands.
         super.onPrepareOptionsMenu(menu);
 
         // Run all the other default commands.
         super.onPrepareOptionsMenu(menu);
 
@@ -653,6 +707,34 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 mainWebView.reload();
                 return true;
 
                 mainWebView.reload();
                 return true;
 
+            case R.id.fontSizeFiftyPercent:
+                mainWebView.getSettings().setTextZoom(50);
+                return true;
+
+            case R.id.fontSizeSeventyFivePercent:
+                mainWebView.getSettings().setTextZoom(75);
+                return true;
+
+            case R.id.fontSizeOneHundredPercent:
+                mainWebView.getSettings().setTextZoom(100);
+                return true;
+
+            case R.id.fontSizeOneHundredTwentyFivePercent:
+                mainWebView.getSettings().setTextZoom(125);
+                return true;
+
+            case R.id.fontSizeOneHundredFiftyPercent:
+                mainWebView.getSettings().setTextZoom(150);
+                return true;
+
+            case R.id.fontSizeOneHundredSeventyFivePercent:
+                mainWebView.getSettings().setTextZoom(175);
+                return true;
+
+            case R.id.fontSizeTwoHundredPercent:
+                mainWebView.getSettings().setTextZoom(200);
+                return true;
+
             case R.id.share:
                 Intent shareIntent = new Intent();
                 shareIntent.setAction(Intent.ACTION_SEND);
             case R.id.share:
                 Intent shareIntent = new Intent();
                 shareIntent.setAction(Intent.ACTION_SEND);
index cd6a81e1e4dfae4ce34720711df7e350f0b783f4..38463427425875c55dbeb7f8c4c36a62a03d2e99 100644 (file)
@@ -109,10 +109,15 @@ public class SettingsFragment extends PreferenceFragment {
         javaScriptEnabledSearchCustomURLPreference.setEnabled(javaScriptEnabledSearchString.equals("Custom URL"));
 
 
         javaScriptEnabledSearchCustomURLPreference.setEnabled(javaScriptEnabledSearchString.equals("Custom URL"));
 
 
-        // Set the homepage URL as the summary text for the Homepage preference when the preference screen is loaded.  The default is "https://www.duckduckgo.com".
+        // Set the homepage URL as the summary text for the `Homepage` preference when the preference screen is loaded.  The default is `https://www.duckduckgo.com`.
         final Preference homepagePreference = findPreference("homepage");
         homepagePreference.setSummary(savedPreferences.getString("homepage", "https://www.duckduckgo.com"));
 
         final Preference homepagePreference = findPreference("homepage");
         homepagePreference.setSummary(savedPreferences.getString("homepage", "https://www.duckduckgo.com"));
 
+        // Set the default font size as the summary text for the `Default Font Size` preference when the preference screen is loaded.  The default is `100`.
+        final Preference defaultFontSizePreference = findPreference("default_font_size");
+        String defaultFontSizeString = savedPreferences.getString("default_font_size", "100");
+        defaultFontSizePreference.setSummary(defaultFontSizeString + "%%");
+
 
         // Listen for preference changes.
         preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
 
         // Listen for preference changes.
         preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@@ -302,11 +307,21 @@ public class SettingsFragment extends PreferenceFragment {
                         MainWebViewActivity.homepage = sharedPreferences.getString("homepage", "https://www.duckduckgo.com");
                         break;
 
                         MainWebViewActivity.homepage = sharedPreferences.getString("homepage", "https://www.duckduckgo.com");
                         break;
 
+                    case "default_font_size":
+                        // Get the default font size as a string.  The default is `100`.
+                        String newDefaultFontSizeString = sharedPreferences.getString("default_font_size", "100");
+
+                        // Update the font size on `mainWebView`.  The default is `100`.
+                        MainWebViewActivity.mainWebView.getSettings().setTextZoom(Integer.valueOf(newDefaultFontSizeString));
+
+                        // Update the summary text of `default_font_size`.
+                        defaultFontSizePreference.setSummary(newDefaultFontSizeString + "%%");
+
                     case "swipe_to_refresh_enabled":
                     case "swipe_to_refresh_enabled":
-                        // Set swipeToRefreshEnabled to the new state.  The default is true.
+                        // Set `swipeToRefreshEnabled` to the new state.  The default is `true`.
                         MainWebViewActivity.swipeToRefreshEnabled = sharedPreferences.getBoolean("swipe_to_refresh_enabled", true);
 
                         MainWebViewActivity.swipeToRefreshEnabled = sharedPreferences.getBoolean("swipe_to_refresh_enabled", true);
 
-                        // Update swipeRefreshLayout to match the new state.
+                        // Update `swipeRefreshLayout` to match the new state.
                         MainWebViewActivity.swipeToRefresh.setEnabled(MainWebViewActivity.swipeToRefreshEnabled);
                         break;
 
                         MainWebViewActivity.swipeToRefresh.setEnabled(MainWebViewActivity.swipeToRefreshEnabled);
                         break;
 
index d380a060227aa65b0a15f725058c5235da9daf52..9c189886da6205339f01437e020f5453783a5f3a 100644 (file)
         android:orderInCategory="80"
         app:showAsAction="never" />
 
         android:orderInCategory="80"
         app:showAsAction="never" />
 
+    <item
+        android:id="@+id/fontSize"
+        android:title="@string/font_size_one_hundred_percent"
+        android:orderInCategory="90"
+        app:showAsAction="never" >
+
+        <menu>
+            <group android:checkableBehavior="single">
+                <item
+                    android:id="@+id/fontSizeFiftyPercent"
+                    android:title="@string/font_size_fifty_percent"
+                    android:orderInCategory="91"
+                    app:showAsAction="never" />
+
+                <item
+                    android:id="@+id/fontSizeSeventyFivePercent"
+                    android:title="@string/font_size_seventy_five_percent"
+                    android:orderInCategory="92"
+                    app:showAsAction="never" />
+
+                <item
+                    android:id="@+id/fontSizeOneHundredPercent"
+                    android:title="@string/font_size_one_hundred_percent"
+                    android:orderInCategory="93"
+                    app:showAsAction="never" />
+
+                <item
+                    android:id="@+id/fontSizeOneHundredTwentyFivePercent"
+                    android:title="@string/font_size_one_hundred_twenty_five_percent"
+                    android:orderInCategory="94"
+                    app:showAsAction="never" />
+
+                <item
+                    android:id="@+id/fontSizeOneHundredFiftyPercent"
+                    android:title="@string/font_size_one_hundred_fifty_percent"
+                    android:orderInCategory="95"
+                    app:showAsAction="never" />
+
+                <item
+                    android:id="@+id/fontSizeOneHundredSeventyFivePercent"
+                    android:title="@string/font_size_one_hundred_seventy_five_percent"
+                    android:orderInCategory="96"
+                    app:showAsAction="never" />
+
+                <item
+                    android:id="@+id/fontSizeTwoHundredPercent"
+                    android:title="@string/font_size_two_hundred_percent"
+                    android:orderInCategory="97"
+                    app:showAsAction="never" />
+            </group>
+        </menu>
+    </item>
+
     <item
         android:id="@+id/share"
         android:title="@string/share"
     <item
         android:id="@+id/share"
         android:title="@string/share"
-        android:orderInCategory="90"
+        android:orderInCategory="100"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/addToHomescreen"
         android:title="@string/add_to_home_screen"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/addToHomescreen"
         android:title="@string/add_to_home_screen"
-        android:orderInCategory="100"
+        android:orderInCategory="110"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/refresh"
         android:title="@string/refresh"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/refresh"
         android:title="@string/refresh"
-        android:orderInCategory="110"
+        android:orderInCategory="120"
         app:showAsAction="never" />
 </menu>
         app:showAsAction="never" />
 </menu>
index d6cb1a4ab86436b7d34829c0cb445acbbd169314..977d412d92705ca86c3354d4504a3a64e349c94c 100644 (file)
@@ -38,7 +38,7 @@
     <string name="favorite_icon">Favorite Icon</string>
     <string name="url_or_search_terms">URL or Search Terms</string>
 
     <string name="favorite_icon">Favorite Icon</string>
     <string name="url_or_search_terms">URL or Search Terms</string>
 
-    <!-- Main WebView Navigation Drawer. -->
+    <!-- Main `WebView` Navigation Drawer. -->
     <string name="navigation_drawer">Navigation Drawer</string>
     <string name="navigation">Navigation</string>
     <string name="home">Home</string>
     <string name="navigation_drawer">Navigation Drawer</string>
     <string name="navigation">Navigation</string>
     <string name="home">Home</string>
@@ -51,7 +51,7 @@
     <string name="about">About</string>
     <string name="clear_and_exit">Clear and Exit</string>
 
     <string name="about">About</string>
     <string name="clear_and_exit">Clear and Exit</string>
 
-    <!-- Main WebView Options Menu. -->
+    <!-- Main `WebView` Options Menu. -->
     <string name="javascript">JavaScript</string>
     <string name="first_party_cookies">First-Party Cookies</string>
     <string name="third_party_cookies">Third-Party Cookies</string>
     <string name="javascript">JavaScript</string>
     <string name="first_party_cookies">First-Party Cookies</string>
     <string name="third_party_cookies">Third-Party Cookies</string>
     <string name="clear_cookies">Clear Cookies</string>
     <string name="clear_dom_storage">Clear DOM Storage</string>
     <string name="clear_form_data">Clear Form Data</string>
     <string name="clear_cookies">Clear Cookies</string>
     <string name="clear_dom_storage">Clear DOM Storage</string>
     <string name="clear_form_data">Clear Form Data</string>
+        <string name="font_size_fifty_percent">Font Size 50%</string>
+        <string name="font_size_seventy_five_percent">Font Size 75%</string>
+        <string name="font_size_one_hundred_percent">Font Size 100%</string>
+        <string name="font_size_one_hundred_twenty_five_percent">Font Size 125%</string>
+        <string name="font_size_one_hundred_fifty_percent">Font Size 150%</string>
+        <string name="font_size_one_hundred_seventy_five_percent">Font Size 175%</string>
+        <string name="font_size_two_hundred_percent">Font Size 200%</string>
     <string name="share">Share</string>
     <string name="add_to_home_screen">Add to Home Screen</string>
     <string name="refresh">Refresh</string>
     <string name="share">Share</string>
     <string name="add_to_home_screen">Add to Home Screen</string>
     <string name="refresh">Refresh</string>
     <string name="custom_url">Custom URL</string>
     <string name="general">General</string>
     <string name="homepage_preference">Homepage</string>
     <string name="custom_url">Custom URL</string>
     <string name="general">General</string>
     <string name="homepage_preference">Homepage</string>
+    <string name="default_font_size">Default Font Size</string>
+    <string-array name="default_font_size_entries">
+        <item>50%</item>
+        <item>75%</item>
+        <item>100%</item>
+        <item>125%</item>
+        <item>150%</item>
+        <item>175%</item>
+        <item>200%</item>
+    </string-array>
+    <string-array name="default_font_size_entry_values" translatable="false">  <!-- None of the items in this string-array should be translated. -->
+        <item>50</item>
+        <item>75</item>
+        <item>100</item>
+        <item>125</item>
+        <item>150</item>
+        <item>175</item>
+        <item>200</item>
+    </string-array>
     <string name="swipe_to_refresh_enabled">Swipe to refresh</string>
     <string name="swipe_to_refresh_enabled_summary">Some websites don\'t work well if swipe to refresh is enabled.</string>
 
     <string name="swipe_to_refresh_enabled">Swipe to refresh</string>
     <string name="swipe_to_refresh_enabled_summary">Some websites don\'t work well if swipe to refresh is enabled.</string>
 
index 702db50eb3b5ad2b88cb8235f8c796603f4b4046..e9c6405bb748cd4696344877d52b912d6d52a1de 100644 (file)
             android:defaultValue="https://www.duckduckgo.com"
             android:inputType="textUri" />
 
             android:defaultValue="https://www.duckduckgo.com"
             android:inputType="textUri" />
 
+        <ListPreference
+            android:key="default_font_size"
+            android:title="@string/default_font_size"
+            android:entries="@array/default_font_size_entries"
+            android:entryValues="@array/default_font_size_entry_values"
+            android:defaultValue="100" />
+
         <SwitchPreference
             android:key="swipe_to_refresh_enabled"
             android:title="@string/swipe_to_refresh_enabled"
         <SwitchPreference
             android:key="swipe_to_refresh_enabled"
             android:title="@string/swipe_to_refresh_enabled"