From: Soren Stoutner Date: Mon, 22 Aug 2016 20:37:21 +0000 (-0700) Subject: Create controls for font size. X-Git-Tag: v1.9~3 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=4a527702ad11865c2a53b01c398b507cd488276c;p=PrivacyBrowserAndroid.git Create controls for font size. --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index f27f9615..4cad1873 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -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"); - // 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); @@ -488,15 +492,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // 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); - // Set the initial status of the privacy icon. - updatePrivacyIcon(); - // 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()); + // 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); @@ -653,6 +707,34 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation 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); diff --git a/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java index cd6a81e1..38463427 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java @@ -109,10 +109,15 @@ public class SettingsFragment extends PreferenceFragment { 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")); + // 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() { @@ -302,11 +307,21 @@ public class SettingsFragment extends PreferenceFragment { 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": - // 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); - // Update swipeRefreshLayout to match the new state. + // Update `swipeRefreshLayout` to match the new state. MainWebViewActivity.swipeToRefresh.setEnabled(MainWebViewActivity.swipeToRefreshEnabled); break; diff --git a/app/src/main/res/menu/webview_options_menu.xml b/app/src/main/res/menu/webview_options_menu.xml index d380a060..9c189886 100644 --- a/app/src/main/res/menu/webview_options_menu.xml +++ b/app/src/main/res/menu/webview_options_menu.xml @@ -76,21 +76,74 @@ android:orderInCategory="80" app:showAsAction="never" /> + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6cb1a4a..977d412d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,7 +38,7 @@ Favorite Icon URL or Search Terms - + Navigation Drawer Navigation Home @@ -51,7 +51,7 @@ About Clear and Exit - + JavaScript First-Party Cookies Third-Party Cookies @@ -60,6 +60,13 @@ Clear Cookies Clear DOM Storage Clear Form Data + Font Size 50% + Font Size 75% + Font Size 100% + Font Size 125% + Font Size 150% + Font Size 175% + Font Size 200% Share Add to Home Screen Refresh @@ -192,6 +199,25 @@ Custom URL General Homepage + Default Font Size + + 50% + 75% + 100% + 125% + 150% + 175% + 200% + + + 50 + 75 + 100 + 125 + 150 + 175 + 200 + Swipe to refresh Some websites don\'t work well if swipe to refresh is enabled. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 702db50e..e9c6405b 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -119,6 +119,13 @@ android:defaultValue="https://www.duckduckgo.com" android:inputType="textUri" /> + +