}
- // 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);
// 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);
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);
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);
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() {
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;
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"
- android:orderInCategory="90"
+ android:orderInCategory="100"
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"
- android:orderInCategory="110"
+ android:orderInCategory="120"
app:showAsAction="never" />
</menu>
<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="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="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="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>
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"