import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
-import android.text.style.StyleSpan;
import android.util.Patterns;
import android.view.ContextMenu;
import android.view.GestureDetector;
public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcutDialog.CreateHomeScreenSchortcutListener,
SslCertificateErrorDialog.SslCertificateErrorListener, DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, UrlHistoryDialog.UrlHistoryListener {
- // `darkTheme` is public static so it can be accessed from `AboutActivity`, `GuideActivity`, `AddDomainDialog`, `SettingsActivity`, `DomainsActivity`, `DomainsSettingsActivity`, `BookmarksActivity`, `BookmarksDatabaseViewActivity`,
+ // `darkTheme` is public static so it can be accessed from `AboutActivity`, `GuideActivity`, `AddDomainDialog`, `SettingsActivity`, `DomainsActivity`, `DomainsListFragment`, `BookmarksActivity`, `BookmarksDatabaseViewActivity`,
// `CreateBookmarkDialog`, `CreateBookmarkFolderDialog`, `DownloadFileDialog`, `DownloadImageDialog`, `EditBookmarkDialog`, `EditBookmarkFolderDialog`, `MoveToFolderDialog`, `SslCertificateErrorDialog`, `UrlHistoryDialog`, `ViewSslCertificateDialog`,
// `CreateHomeScreenShortcutDialog`, and `OrbotProxyHelper`. It is also used in `onCreate()`, `applyAppSettings()`, `applyDomainSettings()`, and `updatePrivacyIcons()`.
public static boolean darkTheme;
// `finalGrayColorSpam` is used in `onCreate()` and `highlightUrlText()`.
private ForegroundColorSpan finalGrayColorSpan;
- // `boldStyleSpan` is used in `onCreate()` and `highlightUrlText()`.
- private StyleSpan boldStyleSpan;
-
// `adView` is used in `onCreate()` and `onConfigurationChanged()`.
private View adView;
redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700));
initialGrayColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.gray_500));
finalGrayColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.gray_500));
- boldStyleSpan = new StyleSpan(Typeface.BOLD);
// Get a handle for `urlTextBox`.
urlTextBox = (EditText) appBar.getCustomView().findViewById(R.id.url_edittext);
urlTextBox.getText().removeSpan(redColorSpan);
urlTextBox.getText().removeSpan(initialGrayColorSpan);
urlTextBox.getText().removeSpan(finalGrayColorSpan);
- urlTextBox.getText().removeSpan(boldStyleSpan);
} else { // The user has stopped editing `urlTextBox`.
// Reapply the highlighting.
highlightUrlText();
// Get a handle for the shared preference. `this` references the current context.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ // Store the default font size and user agent information.
+ String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100");
+ String defaultUserAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0");
+ String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0");
+
if (domainSettingsApplied) { // The url we are loading has custom domain settings.
// Get a cursor for the current host and move it to the first position.
Cursor currentHostDomainSettingsCursor = domainsDatabaseHelper.getCursorForDomainName(domainNameInDatabase);
cookieManager.setAcceptCookie(firstPartyCookiesEnabled);
mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled);
mainWebView.getSettings().setSaveFormData(saveFormDataEnabled);
- mainWebView.getSettings().setTextZoom(fontSize);
+
+ // Apply the font size.
+ if (fontSize == 0) { // Apply the default font size.
+ mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString));
+ } else { // Apply the specified font size.
+ mainWebView.getSettings().setTextZoom(fontSize);
+ }
// Set third-party cookies status if API >= 21.
if (Build.VERSION.SDK_INT >= 21) {
// Only set the user agent if the webpage is not currently loading. Otherwise, changing the user agent on redirects can cause the original website to reload. <https://redmine.stoutner.com/issues/160>
if (!urlIsLoading) {
- if (userAgentString.equals("WebView default user agent")) {
- // Set the user agent to `""`, which uses the default value.
- mainWebView.getSettings().setUserAgentString("");
- } else {
- // Use the selected user agent.
- mainWebView.getSettings().setUserAgentString(userAgentString);
+ switch (userAgentString) {
+ case "System default user agent":
+ // Set the user agent according to the system default.
+ switch (defaultUserAgentString) {
+ case "WebView default user agent":
+ // Set the user agent to `""`, which uses the default value.
+ mainWebView.getSettings().setUserAgentString("");
+ break;
+
+ case "Custom user agent":
+ // Set the custom user agent.
+ mainWebView.getSettings().setUserAgentString(defaultCustomUserAgentString);
+ break;
+
+ default:
+ // Use the selected user agent.
+ mainWebView.getSettings().setUserAgentString(defaultUserAgentString);
+ }
+ break;
+
+ case "WebView default user agent":
+ // Set the user agent to `""`, which uses the default value.
+ mainWebView.getSettings().setUserAgentString("");
+ break;
+
+ default:
+ // Use the selected user agent.
+ mainWebView.getSettings().setUserAgentString(userAgentString);
}
}
thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false);
domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false);
saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false);
- String userAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0");
- String customUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0");
- String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100");
// Apply the default settings.
mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled);
// Only set the user agent if the webpage is not currently loading. Otherwise, changing the user agent on redirects can cause the original website to reload. <https://redmine.stoutner.com/issues/160>
if (!urlIsLoading) {
- switch (userAgentString) {
+ switch (defaultUserAgentString) {
case "WebView default user agent":
// Set the user agent to `""`, which uses the default value.
mainWebView.getSettings().setUserAgentString("");
case "Custom user agent":
// Set the custom user agent.
- mainWebView.getSettings().setUserAgentString(customUserAgentString);
+ mainWebView.getSettings().setUserAgentString(defaultCustomUserAgentString);
break;
default:
// Use the selected user agent.
- mainWebView.getSettings().setUserAgentString(userAgentString);
- break;
+ mainWebView.getSettings().setUserAgentString(defaultUserAgentString);
}
}
if (urlString.startsWith("http://")) { // Highlight connections that are not encrypted.
urlTextBox.getText().setSpan(redColorSpan, 0, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
- // urlTextBox.getText().setSpan(boldStyleSpan, 0, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
} else if (urlString.startsWith("https://")) { // Highlight connections that are encrypted.
urlTextBox.getText().setSpan(initialGrayColorSpan, 0, 8, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}