package com.stoutner.privacybrowser.activities;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.WindowManager;
import androidx.appcompat.app.ActionBar;
public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.Menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the activity theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
}
private void updateMoveIcons() {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Get a long array of the selected bookmarks.
long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
moveBookmarkUpMenuItem.setEnabled(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_dark);
} else {
moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_light);
moveBookmarkDownMenuItem.setEnabled(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_dark);
} else {
moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_light);
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.Menu;
@Override
public void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the activity theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
bookmarkParentFolderTextView.setText(bookmarkParentFolder);
// Set the text color according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.gray_300));
} else {
bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Get the ID of the menu item that was selected.
int menuItemId = menuItem.getItemId();
+ // Run the command that corresponds to the selected menu item.
switch (menuItemId) {
case android.R.id.home: // The home arrow is identified as `android.R.id.home`, not just `R.id.home`.
// Exit the activity.
// Update the icon and display a snackbar.
if (sortByDisplayOrder) { // Sort by display order.
// Update the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
menuItem.setIcon(R.drawable.sort_selected_dark);
} else {
menuItem.setIcon(R.drawable.sort_selected_light);
Snackbar.make(bookmarksListView, R.string.sorted_by_display_order, Snackbar.LENGTH_SHORT).show();
} else { // Sort by database id.
// Update the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
menuItem.setIcon(R.drawable.sort_dark);
} else {
menuItem.setIcon(R.drawable.sort_light);
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.http.SslCertificate;
import android.os.Bundle;
import android.os.Handler;
+import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the activity theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
Runnable enableDeleteMenuItemRunnable = () -> {
// Enable `deleteMenuItem` according to the display mode.
if (twoPanedMode) { // Two-paned mode.
- // Enable `deleteMenuItem`.
+ // Enable the delete menu item.
deleteMenuItem.setEnabled(true);
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+
+ // Get the theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the delete icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
deleteMenuItem.setIcon(R.drawable.delete_dark);
} else {
deleteMenuItem.setIcon(R.drawable.delete_light);
// Enable the delete options menu items.
deleteMenuItem.setEnabled(true);
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the delete icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
deleteMenuItem.setIcon(R.drawable.delete_dark);
} else {
deleteMenuItem.setIcon(R.drawable.delete_light);
package com.stoutner.privacybrowser.activities;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.WindowManager;
import androidx.appcompat.app.ActionBar;
public class GuideActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.preference.PreferenceManager;
import android.provider.DocumentsContract;
import android.text.Editable;
import android.text.TextWatcher;
@Override
public void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the activity theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
+import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
@Override
public void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the activity theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
} else {
setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
});
// Set the swipe to refresh color according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeRefreshLayout.setColorSchemeResources(R.color.blue_600);
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.gray_800);
} else {
// TODO. Store up reloads for tabs that are not visible.
// TODO. New tabs are white in dark mode.
+// TODO. Hide the tabs in full screen mode.
// AppCompatActivity from android.support.v7.app.AppCompatActivity must be used to have access to the SupportActionBar until the minimum API is >= 21.
public class MainWebViewActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener,
EditBookmarkFolderDialog.EditBookmarkFolderListener, HttpAuthenticationDialog.HttpAuthenticationListener, NavigationView.OnNavigationItemSelectedListener, WebViewTabFragment.NewTabListener,
PinnedMismatchDialog.PinnedMismatchListener, SslCertificateErrorDialog.SslCertificateErrorListener, UrlHistoryDialog.UrlHistoryListener {
- // `darkTheme` is public static so it can be accessed from everywhere.
- public static boolean darkTheme;
-
- // `allowScreenshots` is public static so it can be accessed from everywhere. It is also used in `onCreate()`.
- public static boolean allowScreenshots;
-
// `orbotStatus` is public static so it can be accessed from `OrbotProxyHelper`. It is also used in `onCreate()`, `onResume()`, and `applyProxyThroughOrbot()`.
public static String orbotStatus;
// `restartFromBookmarksActivity` is public static so it can be accessed from `BookmarksActivity`. It is also used in `onRestart()`.
public static boolean restartFromBookmarksActivity;
- // The blocklist versions are public static so they can be accessed from `AboutTabFragment`. They are also used in `onCreate()`.
+ // The blocklist versions are public static so they can be accessed from `AboutTabFragment`. They are also used in `onCreate()`. // TODO.
public static String easyListVersion;
public static String easyPrivacyVersion;
public static String fanboysAnnoyanceVersion;
// `customHeader` is used in `onCreate()`, `onOptionsItemSelected()`, `onCreateContextMenu()`, and `loadUrl()`.
private final Map<String, String> customHeaders = new HashMap<>();
- // `firstPartyCookiesEnabled` is used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, `onDownloadImage()`, `onDownloadFile()`, and `applyDomainSettings()`.
- private boolean firstPartyCookiesEnabled;
-
- // 'homepage' is used in `onCreate()`, `onNavigationItemSelected()`, and `applyProxyThroughOrbot()`.
- private String homepage; // TODO ?
-
- // `searchURL` is used in `loadURLFromTextBox()` and `applyProxyThroughOrbot()`.
- private String searchURL; // TODO ?
+ // The search URL is set in `applyProxyThroughOrbot()` and used in `onCreate()`, `onNewIntent()`, `loadURLFromTextBox()`, and `initializeWebView()`.
+ private String searchURL;
// The options menu is set in `onCreateOptionsMenu()` and used in `onOptionsItemSelected()`, `updatePrivacyIcons()`, and `initializeWebView()`.
private Menu optionsMenu;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Get the theme and screenshot preferences.
- darkTheme = sharedPreferences.getBoolean("dark_theme", false);
- allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
// Disable screenshots if not allowed.
if (!allowScreenshots) {
// Load the URL from the intent.
loadUrl(launchingIntentUriData.toString());
} else { // The is no URL in the intent.
- // Load the homepage.
- loadUrl(homepage);
+ // Select the homepage based on the proxy through Orbot status.
+ if (proxyThroughOrbot) {
+ // Load the Tor homepage.
+ loadUrl(sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value)));
+ } else {
+ // Load the normal homepage.
+ loadUrl(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
+ }
}
}
}
// Initialize `inFullScreenBrowsingMode`, which is always false at this point because Privacy Browser never starts in full screen browsing mode.
inFullScreenBrowsingMode = false;
- // Initialize the privacy settings variables.
- firstPartyCookiesEnabled = false;
-
// Inflate a bare WebView to get the default user agent. It is not used to render content on the screen.
@SuppressLint("InflateParams") View webViewLayout = getLayoutInflater().inflate(R.layout.bare_webview, null, false);
// Get the shared preference values.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- // Get the status of the additional AppBar icons.
+ // Get the dark theme and app bar preferences..
boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean("display_additional_app_bar_icons", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
// Set the status of the additional app bar icons. Setting the refresh menu item to `SHOW_AS_ACTION_ALWAYS` makes it appear even on small devices like phones.
if (displayAdditionalAppBarIcons) {
thirdPartyCookiesMenuItem.setChecked(cookieManager.acceptThirdPartyCookies(currentWebView));
// Enable third-party cookies if first-party cookies are enabled.
- thirdPartyCookiesMenuItem.setEnabled(firstPartyCookiesEnabled);
+ thirdPartyCookiesMenuItem.setEnabled(cookieManager.acceptCookie());
}
// Enable DOM Storage if JavaScript is enabled.
}
// Set the status of the menu item checkboxes.
- firstPartyCookiesMenuItem.setChecked(firstPartyCookiesEnabled);
+ firstPartyCookiesMenuItem.setChecked(cookieManager.acceptCookie());
proxyThroughOrbotMenuItem.setChecked(proxyThroughOrbot);
// Enable Clear Cookies if there are any.
@Override
// Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.
@SuppressLint("SetJavaScriptEnabled")
- // removeAllCookies is deprecated, but it is required for API < 21.
- @SuppressWarnings("deprecation")
public boolean onOptionsItemSelected(MenuItem menuItem) {
// Reenter full screen browsing mode if it was interrupted by the options menu. <https://redmine.stoutner.com/issues/389>
if (inFullScreenBrowsingMode) {
// Display a `Snackbar`.
if (currentWebView.getSettings().getJavaScriptEnabled()) { // JavaScrip is enabled.
Snackbar.make(findViewById(R.id.webviewpager), R.string.javascript_enabled, Snackbar.LENGTH_SHORT).show();
- } else if (firstPartyCookiesEnabled) { // JavaScript is disabled, but first-party cookies are enabled.
+ } else if (cookieManager.acceptCookie()) { // JavaScript is disabled, but first-party cookies are enabled.
Snackbar.make(findViewById(R.id.webviewpager), R.string.javascript_disabled, Snackbar.LENGTH_SHORT).show();
} else { // Privacy mode.
Snackbar.make(findViewById(R.id.webviewpager), R.string.privacy_mode, Snackbar.LENGTH_SHORT).show();
return true;
case R.id.toggle_first_party_cookies:
- // Switch the status of firstPartyCookiesEnabled.
- firstPartyCookiesEnabled = !firstPartyCookiesEnabled;
+ // Switch the first-party cookie status.
+ cookieManager.setAcceptCookie(!cookieManager.acceptCookie());
- // Update the menu checkbox.
- menuItem.setChecked(firstPartyCookiesEnabled);
+ // Store the first-party cookie status.
+ currentWebView.setAcceptFirstPartyCookies(cookieManager.acceptCookie());
- // Apply the new cookie status.
- cookieManager.setAcceptCookie(firstPartyCookiesEnabled);
+ // Update the menu checkbox.
+ menuItem.setChecked(cookieManager.acceptCookie());
// Update the privacy icon. `true` runs `invalidateOptionsMenu` as the last step.
updatePrivacyIcons(true);
- // Display a `Snackbar`.
- if (firstPartyCookiesEnabled) { // First-party cookies are enabled.
+ // Display a snackbar.
+ if (cookieManager.acceptCookie()) { // First-party cookies are enabled.
Snackbar.make(findViewById(R.id.webviewpager), R.string.first_party_cookies_enabled, Snackbar.LENGTH_SHORT).show();
} else if (currentWebView.getSettings().getJavaScriptEnabled()) { // JavaScript is still enabled.
Snackbar.make(findViewById(R.id.webviewpager), R.string.first_party_cookies_disabled, Snackbar.LENGTH_SHORT).show();
return true;
case R.id.print:
- // Get a `PrintManager` instance.
+ // Get a print manager instance.
PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
- // Create a print document adapter form the current WebView.
- PrintDocumentAdapter printDocumentAdapter = currentWebView.createPrintDocumentAdapter();
-
- // Remove the lint error below that `printManager` might be `null`.
+ // Remove the lint error below that print manager might be null.
assert printManager != null;
- // Print the document. The print attributes are `null`.
+ // Create a print document adapter from the current WebView.
+ PrintDocumentAdapter printDocumentAdapter = currentWebView.createPrintDocumentAdapter();
+
+ // Print the document.
printManager.print(getString(R.string.privacy_browser_web_page), printDocumentAdapter, null);
return true;
// Get the menu item ID.
int menuItemId = menuItem.getItemId();
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
// Run the commands that correspond to the selected menu item.
switch (menuItemId) {
case R.id.close_tab:
bookmarksCursor.close();
bookmarksDatabaseHelper.close();
- // Get a handle for the shared preferences.
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-
// Get the status of the clear everything preference.
boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true);
break;
case R.id.home:
- loadUrl(homepage);
+ // Select the homepage based on the proxy through Orbot status.
+ if (proxyThroughOrbot) {
+ // Load the Tor homepage.
+ loadUrl(sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value)));
+ } else {
+ // Load the normal homepage.
+ loadUrl(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
+ }
break;
case R.id.back:
// Parse `imageUrl`.
DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(imageUrl));
+ // Get a handle for the cookie manager.
+ CookieManager cookieManager = CookieManager.getInstance();
+
// Pass cookies to download manager if cookies are enabled. This is required to download images from websites that require a login.
// Code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner <soren@stoutner.com>.
- if (firstPartyCookiesEnabled) {
+ if (cookieManager.acceptCookie()) {
// Get the cookies for `imageUrl`.
- String cookies = CookieManager.getInstance().getCookie(imageUrl);
+ String cookies = cookieManager.getCookie(imageUrl);
// Add the cookies to `downloadRequest`. In the HTTP request header, cookies are named `Cookie`.
downloadRequest.addRequestHeader("Cookie", cookies);
// Parse `downloadUrl`.
DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(downloadUrl));
+ // Get a handle for the cookie manager.
+ CookieManager cookieManager = CookieManager.getInstance();
+
// Pass cookies to download manager if cookies are enabled. This is required to download files from websites that require a login.
// Code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner <soren@stoutner.com>.
- if (firstPartyCookiesEnabled) {
+ if (cookieManager.acceptCookie()) {
// Get the cookies for `downloadUrl`.
- String cookies = CookieManager.getInstance().getCookie(downloadUrl);
+ String cookies = cookieManager.getCookie(downloadUrl);
// Add the cookies to `downloadRequest`. In the HTTP request header, cookies are named `Cookie`.
downloadRequest.addRequestHeader("Cookie", cookies);
String defaultUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
boolean defaultSwipeToRefresh = sharedPreferences.getBoolean("swipe_to_refresh", true);
boolean displayWebpageImages = sharedPreferences.getBoolean("display_webpage_images", true);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
// Get a handle for the cookie manager.
CookieManager cookieManager = CookieManager.getInstance();
// Get the settings from the cursor.
nestedScrollWebView.setDomainSettingsDatabaseId(currentDomainSettingsCursor.getInt(currentDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper._ID)));
boolean domainJavaScriptEnabled = (currentDomainSettingsCursor.getInt(currentDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)) == 1);
- firstPartyCookiesEnabled = (currentDomainSettingsCursor.getInt(currentDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)) == 1); // TODO.
+ nestedScrollWebView.setAcceptFirstPartyCookies(currentDomainSettingsCursor.getInt(currentDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)) == 1);
boolean domainThirdPartyCookiesEnabled = (currentDomainSettingsCursor.getInt(currentDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)) == 1);
nestedScrollWebView.getSettings().setDomStorageEnabled(currentDomainSettingsCursor.getInt(currentDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)) == 1);
// Form data can be removed once the minimum API >= 26.
nestedScrollWebView.getSettings().setJavaScriptEnabled(domainJavaScriptEnabled);
}
- // Close `currentHostDomainSettingsCursor`.
+ // Close the current host domain settings cursor.
currentDomainSettingsCursor.close();
// Apply the domain settings.
- cookieManager.setAcceptCookie(firstPartyCookiesEnabled); //TODO This could be bad.
+ cookieManager.setAcceptCookie(nestedScrollWebView.getAcceptFirstPartyCookies());
+
+ // Set third-party cookies status if API >= 21.
+ if (Build.VERSION.SDK_INT >= 21) {
+ cookieManager.setAcceptThirdPartyCookies(nestedScrollWebView, domainThirdPartyCookiesEnabled);
+ }
// Apply the form data setting if the API < 26.
if (Build.VERSION.SDK_INT < 26) {
nestedScrollWebView.getSettings().setTextZoom(fontSize);
}
- // Set third-party cookies status if API >= 21.
- if (Build.VERSION.SDK_INT >= 21) {
- cookieManager.setAcceptThirdPartyCookies(nestedScrollWebView, domainThirdPartyCookiesEnabled);
- }
-
// 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 (nestedScrollWebView.getProgress() == 100) { // A URL is not loading.
} else { // The new URL does not have custom domain settings. Load the defaults.
// Store the values from the shared preferences.
boolean defaultJavaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
- firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies", false); // TODO.
+ nestedScrollWebView.setAcceptFirstPartyCookies(sharedPreferences.getBoolean("first_party_cookies", false));
boolean defaultThirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies", false);
nestedScrollWebView.getSettings().setDomStorageEnabled(sharedPreferences.getBoolean("dom_storage", false));
boolean saveFormData = sharedPreferences.getBoolean("save_form_data", false); // Form data can be removed once the minimum API >= 26.
}
// Apply the default settings.
- cookieManager.setAcceptCookie(firstPartyCookiesEnabled); // TODO.
+ cookieManager.setAcceptCookie(nestedScrollWebView.getAcceptFirstPartyCookies());
nestedScrollWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString));
+ // Apply the form data setting if the API < 26.
+ if (Build.VERSION.SDK_INT < 26) {
+ nestedScrollWebView.getSettings().setSaveFormData(saveFormData);
+ }
+
// Store the swipe to refresh status in the nested scroll WebView.
nestedScrollWebView.setSwipeToRefresh(defaultSwipeToRefresh);
// Apply swipe to refresh according to the default.
swipeRefreshLayout.setEnabled(defaultSwipeToRefresh);
- // Apply the form data setting if the API < 26.
- if (Build.VERSION.SDK_INT < 26) {
- nestedScrollWebView.getSettings().setSaveFormData(saveFormData);
- }
-
// Reset the pinned variables.
nestedScrollWebView.setDomainSettingsDatabaseId(-1);
// Get a handle for the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- // Get the search preferences.
- String homepageString = sharedPreferences.getString("homepage", getString(R.string.homepage_default_value));
- String torHomepageString = sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value));
+ // Get the search and theme preferences.
String torSearchString = sharedPreferences.getString("tor_search", getString(R.string.tor_search_default_value));
String torSearchCustomUrlString = sharedPreferences.getString("tor_search_custom_url", getString(R.string.tor_search_custom_url_default_value));
String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
String searchCustomUrlString = sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value));
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
// Get a handle for the action bar. `getSupportActionBar()` must be used until the minimum API >= 21.
ActionBar actionBar = getSupportActionBar();
// Set the homepage, search, and proxy options.
if (proxyThroughOrbot) { // Set the Tor options.
- // Set `torHomepageString` as `homepage`.
- homepage = torHomepageString;
-
// Set the search URL.
if (torSearchString.equals("Custom URL")) { // Get the custom URL string.
searchURL = torSearchCustomUrlString;
currentWebView.reload();
}
} else { // Set the non-Tor options.
- // Set `homepageString` as `homepage`.
- homepage = homepageString;
-
// Set the search URL.
if (searchString.equals("Custom URL")) { // Get the custom URL string.
searchURL = searchCustomUrlString;
private void updatePrivacyIcons(boolean runInvalidateOptionsMenu) {
// Only update the privacy icons if the options menu and the current WebView have already been populated.
if ((optionsMenu != null) && (currentWebView != null)) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme and screenshot preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Get handles for the menu items.
MenuItem privacyMenuItem = optionsMenu.findItem(R.id.toggle_javascript);
MenuItem firstPartyCookiesMenuItem = optionsMenu.findItem(R.id.toggle_first_party_cookies);
// Update the privacy icon.
if (currentWebView.getSettings().getJavaScriptEnabled()) { // JavaScript is enabled.
privacyMenuItem.setIcon(R.drawable.javascript_enabled);
- } else if (firstPartyCookiesEnabled) { // JavaScript is disabled but cookies are enabled.
+ } else if (currentWebView.getAcceptFirstPartyCookies()) { // JavaScript is disabled but cookies are enabled.
privacyMenuItem.setIcon(R.drawable.warning);
} else { // All the dangerous features are disabled.
privacyMenuItem.setIcon(R.drawable.privacy_mode);
}
// Update the first-party cookies icon.
- if (firstPartyCookiesEnabled) { // First-party cookies are enabled.
+ if (currentWebView.getAcceptFirstPartyCookies()) { // First-party cookies are enabled.
firstPartyCookiesMenuItem.setIcon(R.drawable.cookies_enabled);
} else { // First-party cookies are disabled.
if (darkTheme) {
}
private void setCurrentWebView(int pageNumber) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the theme preference.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Get handles for the URL views.
RelativeLayout urlRelativeLayout = findViewById(R.id.url_relativelayout);
EditText urlEditText = findViewById(R.id.url_edittext);
swipeRefreshLayout.setEnabled(false);
}
+ // Get a handle for the cookie manager.
+ CookieManager cookieManager = CookieManager.getInstance();
+
+ // Set the first-party cookie status.
+ cookieManager.setAcceptCookie(currentWebView.getAcceptFirstPartyCookies());
+
// Update the privacy icons. `true` redraws the icons in the app bar.
updatePrivacyIcons(true);
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ // Get the theme preference.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Reset the list of resource requests.
nestedScrollWebView.clearResourceRequests();
// Set the title.
refreshMenuItem.setTitle(R.string.stop);
- // Get the status of the additional AppBar icons.
+ // Get the app bar and theme preferences.
boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean("display_additional_app_bar_icons", false);
// If the icon is displayed in the AppBar, set it according to the theme.
nestedScrollWebView.getSettings().setUseWideViewPort(url.startsWith("http"));
}
- // Flush any cookies to persistent storage. `CookieManager` has become very lazy about flushing cookies in recent versions.
- if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) {
+ // Flush any cookies to persistent storage. The cookie manager has become very lazy about flushing cookies in recent versions.
+ if (nestedScrollWebView.getAcceptFirstPartyCookies() && Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().flush();
}
// Reset the Refresh title.
refreshMenuItem.setTitle(R.string.refresh);
- // Get the status of the additional AppBar icons.
+ // Get the app bar and theme preferences.
boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean("display_additional_app_bar_icons", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
// If the icon is displayed in the AppBar, reset it according to the theme.
if (displayAdditionalAppBarIcons) {
}
}
-
// Clear the cache and history if Incognito Mode is enabled.
if (incognitoModeEnabled) {
// Clear the cache. `true` includes disk files.
// Load the URL from the intent.
loadUrl(launchingIntentUriData.toString());
} else { // The is no URL in the intent.
- // Load the homepage.
- loadUrl(homepage);
+ // Select the homepage based on the proxy through Orbot status.
+ if (proxyThroughOrbot) {
+ // Load the Tor homepage.
+ loadUrl(sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value)));
+ } else {
+ // Load the normal homepage.
+ loadUrl(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
+ }
}
}
}
package com.stoutner.privacybrowser.activities;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the activity theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserSettingsDark);
} else {
setTheme(R.style.PrivacyBrowserSettingsLight);
// Display the settings fragment.
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
}
-}
+}
\ No newline at end of file
package com.stoutner.privacybrowser.activities;
import android.app.Activity;
-import android.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; // The AndroidX toolbar must be used until the minimum API is >= 21.
import androidx.core.app.NavUtils;
+import androidx.fragment.app.DialogFragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.stoutner.privacybrowser.R;
@Override
protected void onCreate(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Set the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
setTheme(R.style.PrivacyBrowserDark);
} else {
setTheme(R.style.PrivacyBrowserLight);
});
// Set the swipe to refresh color according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeRefreshLayout.setColorSchemeResources(R.color.blue_600);
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.gray_800);
} else {
DialogFragment aboutDialogFragment = new AboutViewSourceDialog();
// Show the about alert dialog.
- aboutDialogFragment.show(getFragmentManager(), getString(R.string.about));
+ aboutDialogFragment.show(getSupportFragmentManager(), getString(R.string.about));
// Consume the event.
return true;
/*
- * Copyright © 2018 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2018-2019 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.DialogFragment;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.WindowManager;
+import androidx.annotation.NonNull;
+import androidx.fragment.app.DialogFragment;
+
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
public class AboutViewSourceDialog extends DialogFragment {
@Override
+ @NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Use a builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
// Set the style and the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
dialogBuilder.setIcon(R.drawable.about_dark);
} else {
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper;
public class AddDomainDialog extends DialogFragment {
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import java.io.ByteArrayOutputStream;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import java.util.Locale;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
public class DownloadImageDialog extends DialogFragment {
// `downloadImageListener` is used in `onAttach()` and `onCreateDialog()`.
// Use and alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.WindowManager;
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
// Use a builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style and the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
dialogBuilder.setIcon(R.drawable.downloads_dark);
} else {
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.widget.TextView;
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import java.io.ByteArrayOutputStream;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import java.io.ByteArrayOutputStream;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.MatrixCursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import java.io.ByteArrayOutputStream;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import java.io.ByteArrayOutputStream;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.widget.EditText;
import android.widget.TextView;
-import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
-
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
+import com.stoutner.privacybrowser.R;
+
public class HttpAuthenticationDialog extends DialogFragment{
// `httpAuthenticationListener` is used in `onAttach()` and `onCreateDialog()`
private HttpAuthenticationListener httpAuthenticationListener;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Set the dialog theme.
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
realmTextView.setText(httpAuthRealm);
// Set the realm text color according to the theme. The deprecated `.getColor()` must be used until API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
realmTextView.setTextColor(getResources().getColor(R.color.gray_300));
} else {
ForegroundColorSpan blueColorSpan;
// Set `blueColorSpan` according to the theme. The deprecated `getColor()` must be used until API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
} else {
// `onCreateDialog()` requires the return of an `AlertDialog`.
return alertDialog;
}
-}
+}
\ No newline at end of file
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.MatrixCursor;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.activities.BookmarksActivity;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import java.io.ByteArrayOutputStream;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
foldersCursorAdapter = new CursorAdapter(alertDialog.getContext(), foldersCursor, false) {
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- // Remove the incorrect lint warning that `.getLayoutInflator()` might be false.
+ // Remove the incorrect lint warning that `.getLayoutInflater()` might be false.
assert getActivity() != null;
// Inflate the individual item layout. `false` does not attach it to the root.
foldersCursorAdapter = new CursorAdapter(alertDialog.getContext(), foldersMergeCursor, false) {
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- // Remove the incorrect lint warning that `.getLayoutInflator()` might be false.
+ // Remove the incorrect lint warning that `.getLayoutInflater()` might be false.
assert getActivity() != null;
// Inflate the individual item layout. `false` does not attach it to the root.
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Set the dialog theme.
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
// Set the favorite icon as the dialog icon if it exists.
if (favoriteIconBitmap.sameAs(defaultFavoriteIconBitmap)) { // There is no website favorite icon.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled_dark);
} else {
dialogBuilder.setIcon(R.drawable.ssl_certificate_enabled_light);
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
}
}
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Create a red foreground color span. The deprecated `getResources().getColor` must be used until the minimum API >= 23.
@SuppressWarnings("deprecation") ForegroundColorSpan redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700));
ForegroundColorSpan blueColorSpan;
// Set the blue color span according to the theme. The deprecated `getResources().getColor` must be used until the minimum API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
} else {
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.preference.PreferenceManager;
import android.provider.DocumentsContract;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;
-import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
-
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment is required or an error is produced on API <=22. It is also required for the browse button to work correctly.
+import com.stoutner.privacybrowser.R;
+
public class SaveLogcatDialog extends DialogFragment {
// Instantiate the class variables.
private SaveLogcatListener saveLogcatListener;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.save_logcat_dialog, null));
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder.setIcon(R.drawable.save_dialog_dark);
} else {
dialogBuilder.setIcon(R.drawable.save_dialog_light);
assert alertDialog.getWindow() != null;
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// Return the alert dialog.
return alertDialog;
}
-}
+}
\ No newline at end of file
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import java.lang.ref.WeakReference;
import java.net.InetAddress;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style and icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Set the style.
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
ForegroundColorSpan blueColorSpan;
// Set a blue color span according to the theme. The deprecated `getResources().getColor` must be used until the minimum API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
} else {
// Create a spannable string builder.
SpannableStringBuilder ipAddressesStringBuilder = new SpannableStringBuilder(ipAddressesLabel + ipAddresses);
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Create a blue foreground color span.
ForegroundColorSpan blueColorSpan;
// Set the blue color span according to the theme. The deprecated `getColor()` must be used until the minimum API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(activity.getResources().getColor(R.color.blue_400));
} else {
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
public class StoragePermissionDialog extends DialogFragment {
// The listener is used in `onAttach()` and `onCreateDialog()`.
// Use a builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style and the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
dialogBuilder.setIcon(R.drawable.import_export_dark);
} else {
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
// `onCreateDialog()` requires the return of an `AlertDialog`.
return alertDialog;
}
-}
+}
\ No newline at end of file
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22.
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.adapters.HistoryArrayAdapter;
import com.stoutner.privacybrowser.definitions.History;
// Use an alert dialog builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
+import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import com.stoutner.privacybrowser.fragments.WebViewTabFragment;
import com.stoutner.privacybrowser.views.NestedScrollWebView;
-import java.io.ByteArrayOutputStream;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
// Use a builder to create the alert dialog.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot and theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
final AlertDialog alertDialog = dialogBuilder.create();
// Disable screenshots if not allowed.
- if (!MainWebViewActivity.allowScreenshots) {
+ if (!allowScreenshots) {
// Remove the warning below that `getWindow()` might be null.
assert alertDialog.getWindow() != null;
ForegroundColorSpan blueColorSpan;
// Set the blue color span according to the theme. The deprecated `getColor()` must be used until the minimum API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
} else {
import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Build;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
Context context = getContext();
assert context != null;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+
+ // Get the theme preference.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Load the tabs. Tab numbers start at 0.
if (tabNumber == 0) { // Load the about tab.
// Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. The fragment will take care of attaching the root automatically.
ForegroundColorSpan blueColorSpan;
// Set `blueColorSpan` according to the theme. We have to use the deprecated `getColor()` until API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400));
} else {
WebView tabWebView = (WebView) tabLayout;
// Load the tabs according to the theme.
- if (MainWebViewActivity.darkTheme) { // The dark theme is applied.
+ if (darkTheme) { // The dark theme is applied.
// Set the background color. The deprecated `.getColor()` must be used until the minimum API >= 23.
//noinspection deprecation
tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
boolean defaultSwipeToRefresh = sharedPreferences.getBoolean("swipe_to_refresh", true);
final boolean defaultNightMode = sharedPreferences.getBoolean("night_mode", false);
final boolean defaultDisplayWebpageImages = sharedPreferences.getBoolean("display_webpage_images", true);
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
// Get handles for the views in the fragment.
final EditText domainNameEditText = domainSettingsView.findViewById(R.id.domain_settings_name_edittext);
final ForegroundColorSpan blueColorSpan;
// Set the blue color span according to the theme. The deprecated `resources.getColor` must be used until the minimum API >= 23.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
//noinspection deprecation
blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.blue_400));
} else {
firstPartyCookiesEnabledSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
} else {
firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
thirdPartyCookiesEnabledSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
} else {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
thirdPartyCookiesEnabledSwitch.setEnabled(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark));
} else {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light));
domStorageEnabledSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
}
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light));
formDataEnabledSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark));
} else {
formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light));
easyListSwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_dark));
} else {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_light));
easyListSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_dark));
} else {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_light));
easyPrivacySwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark));
} else {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light));
easyPrivacySwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark));
} else {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light));
fanboysAnnoyanceListSwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
} else {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
fanboysAnnoyanceListSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
} else {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
fanboysSocialBlockingListSwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
fanboysSocialBlockingListSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
}
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_light));
ultraPrivacySwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark));
} else {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light));
ultraPrivacySwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark));
} else {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light));
blockAllThirdPartyRequestsSwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_dark));
} else {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_light));
blockAllThirdPartyRequestsSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_dark));
} else {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_light));
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_SYSTEM_DEFAULT:
if (defaultSwipeToRefresh) { // Swipe to refresh is enabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light));
}
} else { // Swipe to refresh is disabled by default
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light));
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_ENABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light));
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_DISABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light));
case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT:
if (defaultNightMode) { // Night mode enabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light));
}
} else { // Night mode disabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light));
case DomainsDatabaseHelper.NIGHT_MODE_ENABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light));
case DomainsDatabaseHelper.NIGHT_MODE_DISABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light));
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
if (defaultDisplayWebpageImages) { // Display webpage images enabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light));
}
} else { // Display webpage images disabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light));
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light));
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light));
pinnedSslCertificateSwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark));
} else {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light));
pinnedSslCertificateSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark));
} else {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light));
currentWebsiteCertificateRadioButton.setChecked(false);
// Darken the background of the current website SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
pinnedIpAddressesSwitch.setChecked(true);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark));
} else {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light));
pinnedIpAddressesSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark));
} else {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light));
currentIpAddressesRadioButton.setChecked(false);
// Darken the background of the current IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled));
} else { // DOM storage is disabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
domStorageEnabledSwitch.setEnabled(false);
// Set the DOM storage icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light));
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning));
} else { // Third-party cookies are disabled.
// Set the third-party cookies icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
} else {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
}
} else { // First-party cookies are disabled.
// Update the first-party cookies icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
} else {
firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
thirdPartyCookiesEnabledSwitch.setEnabled(false);
// Set the third-party cookies icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark));
} else {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light));
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning));
} else {
// Update the third-party cookies icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
} else {
thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled));
} else {
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled));
} else {
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark));
} else {
formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light));
// Update the icon.
if (isChecked) { // EasyList is on.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_dark));
} else {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_light));
}
} else { // EasyList is off.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_dark));
} else {
easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_light));
// Update the icon.
if (isChecked) { // EasyPrivacy is on.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark));
} else {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light));
}
} else { // EasyPrivacy is off.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark));
} else {
easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light));
// Update the icon and Fanboy's Social Blocking List.
if (isChecked) { // Fanboy's Annoyance List is on.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
} else {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
fanboysSocialBlockingListSwitch.setEnabled(false);
// Update the Fanboy's Social Blocking List icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_light));
}
} else { // Fanboy's Annoyance List is off.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
} else {
fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
// Update the Fanboy's Social Blocking List icon.
if (fanboysSocialBlockingListSwitch.isChecked()) { // Fanboy's Social Blocking List is on.
// Update the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
}
} else { // Fanboy's Social Blocking List is off.
// Update the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
// Update the icon.
if (isChecked) { // Fanboy's Social Blocking List is on.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
}
} else { // Fanboy's Social Blocking List is off.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
} else {
fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
// Update the icon.
if (isChecked) { // UltraPrivacy is on.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark));
} else {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light));
}
} else { // UltraPrivacy is off.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark));
} else {
ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light));
// Update the icon.
if (isChecked) { // Blocking all third-party requests is on.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_dark));
} else {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_light));
}
} else { // Blocking all third-party requests is off.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_dark));
} else {
blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_light));
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_SYSTEM_DEFAULT:
if (defaultSwipeToRefresh) { // Swipe to refresh enabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light));
}
} else { // Swipe to refresh disabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light));
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_ENABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light));
case DomainsDatabaseHelper.SWIPE_TO_REFRESH_DISABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark));
} else {
swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light));
case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT:
if (defaultNightMode) { // Night mode enabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light));
}
} else { // Night mode disabled by default.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light));
case DomainsDatabaseHelper.NIGHT_MODE_ENABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light));
case DomainsDatabaseHelper.NIGHT_MODE_DISABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark));
} else {
nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light));
domStorageEnabledSwitch.setChecked(false);
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
}
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark));
} else {
domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light));
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
if (defaultDisplayWebpageImages) {
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light));
}
} else {
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light));
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light));
case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark));
} else {
displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light));
// Update the icon.
if (isChecked) { // SSL certificate pinning is enabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark));
} else {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light));
savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the current website SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the saved SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
}
} else { // SSL certificate pinning is disabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark));
} else {
pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light));
savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the current website SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the current website SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the saved SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the saved SSL certificate linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
// Update the icon.
if (isChecked) { // IP addresses pinning is enabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark));
} else {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light));
savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the current IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the saved IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentIpAddressesCardView.getParent().requestChildFocus(currentIpAddressesCardView, currentIpAddressesCardView);
} else { // IP addresses pinning is disabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark));
} else {
pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light));
savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the current IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the current IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the saved IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
// Darken the background of the saved IP addresses linear layout according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
} else {
savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
return domainNamesMatch;
}
-}
+}
\ No newline at end of file
package com.stoutner.privacybrowser.fragments;
import android.content.Context;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.activities.DomainsActivity;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
public class DomainsListFragment extends Fragment {
// Instantiate the dismiss snackbar interface handle.
// Enable the delete menu item.
DomainsActivity.deleteMenuItem.setEnabled(true);
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the theme preferences.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the delete icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_dark);
} else {
DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_light);
return domainsListFragmentView;
}
-}
+}
\ No newline at end of file
package com.stoutner.privacybrowser.fragments;
import android.annotation.SuppressLint;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
public class GuideTabFragment extends Fragment {
// `tabNumber` is used in `onCreate()` and `onCreateView()`.
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the theme preference.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. The fragment will take care of attaching the root automatically.
View tabLayout = inflater.inflate(R.layout.bare_webview, container, false);
WebView tabWebView = (WebView) tabLayout;
// Load the tabs according to the theme.
- if (MainWebViewActivity.darkTheme) { // The dark theme is applied.
+ if (darkTheme) { // The dark theme is applied.
// Set the background color. The deprecated `.getColor()` must be used until API >= 23.
//noinspection deprecation
tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
boolean proxyThroughOrbot = savedPreferences.getBoolean("proxy_through_orbot", false);
boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
+ boolean darkTheme = savedPreferences.getBoolean("dark_theme", false);
final boolean nightMode = savedPreferences.getBoolean("night_mode", false);
// Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
if (firstPartyCookiesEnabled) {
firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
} else {
firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
if (thirdPartyCookiesEnabled) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
} else {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
}
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
} else {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
if (savedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
} else { // DOM storage is disabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
}
}
} else { // The preference is disabled. The icon should be ghosted.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
if (savedPreferences.getBoolean("save_form_data", false)) {
saveFormDataPreference.setIcon(R.drawable.form_data_enabled);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark);
} else {
saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light);
// Set the custom user agent icon.
if (customUserAgentPreference.isEnabled()) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_dark);
} else {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
} else {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
// Set the incognito mode icon.
if (savedPreferences.getBoolean("incognito_mode", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_dark);
} else {
incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_dark);
} else {
incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_light);
// Set the Do Not Track icon.
if (savedPreferences.getBoolean("do_not_track", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_dark);
} else {
doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_dark);
} else {
doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_light);
// Set the allow screenshots icon.
if (savedPreferences.getBoolean("allow_screenshots", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_dark);
} else {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_dark);
} else {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_light);
// Set the EasyList icon.
if (savedPreferences.getBoolean("easylist", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListPreference.setIcon(R.drawable.block_ads_enabled_dark);
} else {
easyListPreference.setIcon(R.drawable.block_ads_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListPreference.setIcon(R.drawable.block_ads_disabled_dark);
} else {
easyListPreference.setIcon(R.drawable.block_ads_disabled_light);
// Set the EasyPrivacy icon.
if (savedPreferences.getBoolean("easyprivacy", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
} else {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
} else {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
// Set the Fanboy lists icons.
if (fanboyAnnoyanceListEnabled) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Set the Fanboy annoyance list icon.
fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark);
fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Set the Fanboy annoyance list icon.
fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark);
// Set the UltraPrivacy icon.
if (savedPreferences.getBoolean("ultraprivacy", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
} else {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
} else {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
// Set the block all third-party requests icon.
if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
} else {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
} else {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
// Set the Tor icons according to the theme.
if (proxyThroughOrbot) { // Proxying is enabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_dark);
torHomepagePreference.setIcon(R.drawable.home_enabled_dark);
torSearchPreference.setIcon(R.drawable.search_enabled_dark);
}
}
} else { // Proxying is disabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_dark);
torHomepagePreference.setIcon(R.drawable.home_ghosted_dark);
torSearchPreference.setIcon(R.drawable.search_ghosted_dark);
// Set the search custom URL icon.
if (searchCustomURLPreference.isEnabled()) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
} else {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
} else {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
// Set the full screen browsing mode icons.
if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled.
// Set the `fullScreenBrowsingModePreference` icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_dark);
} else {
fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_light);
// Set the hide app bar icon.
if (savedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
} else {
hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
}
} else { // Hide app bar is disabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
} else {
hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
}
} else { // Full screen browsing mode is disabled.
// Set the icons according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_dark);
hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_dark);
} else {
// Set the clear everything preference icon.
if (clearEverything) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_dark);
} else {
clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_light);
// Set the clear cookies preference icon.
if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
} else {
clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
// Set the clear DOM storage preference icon.
if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
} else {
clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
// Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
if (Build.VERSION.SDK_INT < 26) {
if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
} else {
clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
// Set the clear cache preference icon.
if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
} else {
clearCachePreference.setIcon(R.drawable.cache_cleared_light);
// Set the swipe to refresh preference icon.
if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
} else {
swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
} else {
swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
// Set the scroll app bar preference icon.
if (savedPreferences.getBoolean("scroll_app_bar", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
} else {
scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
} else {
scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
// Set the display additional app bar icons preference icon.
if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
} else {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
} else {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
// Set the download with external app preference icon.
if (savedPreferences.getBoolean("download_with_external_app", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
} else {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
} else {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
// Set the night mode preference icon.
if (nightMode) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
} else {
nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
} else {
nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
// Set the display webpage images preference icon.
if (savedPreferences.getBoolean("display_webpage_images", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_dark);
} else {
displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_dark);
} else {
displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
if (sharedPreferences.getBoolean("dom_storage", false)) {
domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
domStoragePreference.setEnabled(false);
// Set the icon for DOM storage preference to be ghosted.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
if (sharedPreferences.getBoolean("third_party_cookies", false)) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
} else {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
}
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
} else {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
}
} else { // `first_party_cookies` is `false`.
// Update the icon for `first_party_cookies`.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
} else {
firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
}
// Set the icon for `third_party_cookies` to be ghosted.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
} else {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
if (sharedPreferences.getBoolean("third_party_cookies", false)) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
} else {
thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
if (sharedPreferences.getBoolean("dom_storage", false)) {
domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
if (sharedPreferences.getBoolean("save_form_data", false)) {
saveFormDataPreference.setIcon(R.drawable.form_data_enabled);
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark);
} else {
saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light);
customUserAgentPreference.setEnabled(false);
// Set the custom user agent preference icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
} else {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
customUserAgentPreference.setEnabled(true);
// Set the custom user agent preference icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_dark);
} else {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_light);
customUserAgentPreference.setEnabled(false);
// Set the custom user agent preference icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
} else {
customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
case "incognito_mode":
// Update the icon.
if (sharedPreferences.getBoolean("incognito_mode", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_dark);
} else {
incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_dark);
} else {
incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_light);
case "do_not_track":
// Update the icon.
if (sharedPreferences.getBoolean("do_not_track", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_dark);
} else {
doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_dark);
} else {
doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_light);
case "allow_screenshots":
// Update the icon.
if (sharedPreferences.getBoolean("allow_screenshots", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_dark);
} else {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_dark);
} else {
allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_light);
case "easylist":
// Update the icon.
if (sharedPreferences.getBoolean("easylist", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListPreference.setIcon(R.drawable.block_ads_enabled_dark);
} else {
easyListPreference.setIcon(R.drawable.block_ads_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyListPreference.setIcon(R.drawable.block_ads_disabled_dark);
} else {
easyListPreference.setIcon(R.drawable.block_ads_disabled_light);
case "easyprivacy":
// Update the icon.
if (sharedPreferences.getBoolean("easyprivacy", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
} else {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
} else {
easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
// Update the Fanboy icons.
if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Update the Fanboy's annoyance list icon.
fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark);
fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light);
}
} else { // Fanboy's annoyance list is disabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
// Update the Fanboy's annoyance list icon.
fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark);
case "fanboys_social_blocking_list":
// Update the icon.
if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_dark);
} else {
fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_dark);
} else {
fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_light);
case "ultraprivacy":
// Update the icon.
if (sharedPreferences.getBoolean("ultraprivacy", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
} else {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
} else {
ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
case "block_all_third_party_requests":
// Update the icon.
if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
} else {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
} else {
blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
// Update the icons.
if (currentProxyThroughOrbot) {
// Set the Tor icons according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_dark);
torHomepagePreference.setIcon(R.drawable.home_enabled_dark);
torSearchPreference.setIcon(R.drawable.search_enabled_dark);
}
}
} else { // Proxy through Orbot is disabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_dark);
torHomepagePreference.setIcon(R.drawable.home_ghosted_dark);
torSearchPreference.setIcon(R.drawable.search_ghosted_dark);
torSearchCustomURLPreference.setEnabled(true);
// Update the `torSearchCustomURLPreference` icon.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
} else {
torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
torSearchCustomURLPreference.setEnabled(false);
// Update the `torSearchCustomURLPreference` icon.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
} else {
torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
searchCustomURLPreference.setEnabled(true);
// Set the `searchCustomURLPreference` according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
} else {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
searchCustomURLPreference.setEnabled(false);
// Set the `searchCustomURLPreference` according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
} else {
searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
case "full_screen_browsing_mode":
if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled.
// Set the full screen browsing mode preference icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_dark);
} else {
fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_light);
// Set the hide app bar preference icon.
if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
} else {
hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
}
} else { // Hide app bar is disabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
} else {
hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
}
} else { // Full screen browsing is disabled.
// Update the icons according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_dark);
hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_dark);
} else {
// Update the icon.
if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
} else {
hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
}
} else { // Hide app bar is disabled.
// Set the icon according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
} else {
hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
// Update the `clearEverythingPreference` icon.
if (newClearEverythingBoolean) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_dark);
} else {
clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_light);
// Update the `clearCookiesPreference` icon.
if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
} else {
clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
// Update the `clearDomStoragePreference` icon.
if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
} else {
clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
// Update the clear form data preference icon if the API < 26.
if (Build.VERSION.SDK_INT < 26) {
if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
} else {
clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
// Update the `clearCachePreference` icon.
if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
} else {
clearCachePreference.setIcon(R.drawable.cache_cleared_light);
case "clear_cookies":
// Update the icon.
if (sharedPreferences.getBoolean("clear_cookies", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
} else {
clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
case "clear_dom_storage":
// Update the icon.
if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
} else {
clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
case "clear_form_data":
// Update the icon.
if (sharedPreferences.getBoolean("clear_form_data", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
} else {
clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
case "clear_cache":
// Update the icon.
if (sharedPreferences.getBoolean("clear_cache", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
} else {
clearCachePreference.setIcon(R.drawable.cache_cleared_light);
case "swipe_to_refresh":
// Update the icon.
if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
} else {
swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
} else {
swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
case "scroll_app_bar":
// Update the icon.
if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
} else {
scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
} else {
scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
case "display_additional_app_bar_icons":
// Update the icon.
if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
} else {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
} else {
displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
case "download_with_external_app":
// Update the icon.
if (sharedPreferences.getBoolean("download_with_external_app", false)) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
} else {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
} else {
downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
// Update the icon.
if (currentNightModeBoolean) {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
} else {
nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
}
} else {
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
} else {
nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
} else { // DOM storage is disabled.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
}
}
} else { // The preference is disabled. The icon should be ghosted.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
} else {
domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
case "display_webpage_images":
if (sharedPreferences.getBoolean("display_webpage_images", true)) {
// Update the icon.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_dark);
} else {
displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
MainWebViewActivity.reloadOnRestart = false;
} else {
// Update the icon.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_dark);
} else {
displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Proxy;
+import android.preference.PreferenceManager;
import android.util.ArrayMap;
import android.util.Log;
// Use `AlertDialog.Builder` to create the `AlertDialog`.
AlertDialog.Builder dialogBuilder;
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(privacyBrowserContext);
+
+ // Get the theme preference.
+ boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
// Set the style according to the theme.
- if (MainWebViewActivity.darkTheme) {
+ if (darkTheme) {
dialogBuilder = new AlertDialog.Builder(parentActivity, R.style.PrivacyBrowserAlertDialogDark);
} else {
dialogBuilder = new AlertDialog.Builder(parentActivity, R.style.PrivacyBrowserAlertDialogLight);
// Keep track of when the domain name changes so that domain settings can be reapplied. This should never be null.
private String currentDomainName = "";
+ // Track the status of first-party cookies.
+ private boolean acceptFirstPartyCookies;
+
// Track the resource requests.
private ArrayList<String[]> resourceRequests = new ArrayList<>();
private boolean easyListEnabled;
}
+ // First-party cookies.
+ public void setAcceptFirstPartyCookies(boolean status) {
+ // Store the accept first-party cookies status.
+ acceptFirstPartyCookies = status;
+ }
+
+ public boolean getAcceptFirstPartyCookies() {
+ // Return the accept first-party cookies status.
+ return acceptFirstPartyCookies;
+ }
+
+
// Resource requests.
public void addResourceRequest(String[] resourceRequest) {
// Add the resource request to the list.
<string name="javascript_preference">JavaScript standardmäßig aktivieren</string>
<string name="javascript_preference_summary">JavaScript ermöglicht es Websites, Programme (Scripts) auf Ihrem Gerät auszuführen.</string>
<string name="first_party_cookies_preference">Erstanbieter-Cookies standardmäßig aktivieren</string>
- <string name="first_party_cookies_preference_summary">Auf Geräten mit älterer Android-Version als Lollipop (Version 5.0)
- wird zusammen mit dieser auch die Option für Drittanbieter-Cookies aktiviert.</string>
<string name="third_party_cookies_preference">Drittanbieter-Cookies standardmäßig aktivieren</string>
<string name="third_party_cookies_summary">Diese Option benötigt Android Lollipop (Version 5.0) oder höher. Sie hat keine Auswirkungen, wenn Erstanbieter-Cookies deaktiviert sind.</string>
<string name="dom_storage_preference">DOM-Speicher standardmäßig aktivieren</string>
<string name="no_title">Sin título</string>
<string name="unrecognized_url">URL no reconocida:</string>
<string name="open_with">Abrir con</string>
+ <string name="new_tab">Nueva pestaña</string>
+ <string name="add_tab">Añadir pestaña</string>
<!-- Save As. -->
<string name="save_as">Guardar como</string>
<!-- MainWebViewActivity Navigation Menu. -->
<string name="navigation_drawer">Caja de navegación</string>
<string name="navigation">Navegación</string>
+ <string name="close_tab">Cerrar pestaña</string>
<string name="clear_and_exit">Borrar y salir</string>
<string name="home">Inicio</string>
<string name="back">Atrás</string>
<string name="stop">Parar</string>
<!-- Context Menus. -->
+ <string name="open_in_new_tab">Abrir en nueva pestaña</string>
<string name="copy_url">Copiar URL</string>
<string name="download_url">Descargar URL</string>
<string name="email_address">Correo electrónico</string>
<string name="javascript_preference">Habilitar Javascript por defecto</string>
<string name="javascript_preference_summary">Javascript permite a las webs ejecutar programas (scripts) en el dispositivo.</string>
<string name="first_party_cookies_preference">Habilitar cookies de primera parte por defecto</string>
- <string name="first_party_cookies_preference_summary">Dispositivos con versiones de Android más antiguas que Lollipop (versión 5.0)
- también habilitarán las cookies de terceras partes con este ajuste.</string>
+ <string name="first_party_cookies_preference_summary">Ya que las cookies de primera parte son una configuración de nivel de aplicación, cuando la pestaña activa tiene habilitadas las cookies,
+ cualquier solicitud de red realizada en segundo plano por otras pestañas también incluirá las cookies almacenadas para sus dominios.
+ Android KitKat (versión 4.4.x) no distingue entre cookies de primera y de terceras partes y las habilitará ambas con esta configuración.</string>
<string name="third_party_cookies_preference">Habilar cookies de terceras partes por defecto</string>
<string name="third_party_cookies_summary">Este ajuste requiere Android Lollipop (versión 5.0) o mayor. No tiene efecto si las cookies de primera parte están deshabilitadas.</string>
<string name="dom_storage_preference">Habilitar almacenamiento DOM por defecto</string>
<string name="javascript_preference">Abilita JavaScript</string>
<string name="javascript_preference_summary">Permetti a JavaScript di eseguire programmi (script) sul dispositivo.</string>
<string name="first_party_cookies_preference">Abilita cookies proprietari</string>
- <string name="first_party_cookies_preference_summary">Questa impostazione abilita anche cookies di terze parti con dispositivi con versioni di Android precedenti a Lollipop (versione 5.0).</string>
<string name="third_party_cookies_preference">Abilita cookies di terze parti</string>
<string name="third_party_cookies_summary">Questa impostazione richiede Android Lollipop (version 5.0) o successivo. Non ha effetti se i cookies proprietari sono disabilitati.</string>
<string name="dom_storage_preference">Abilita DOM Storage</string>
<string name="no_title">Без названия</string>
<string name="unrecognized_url">Нераспознанный URL:</string>
<string name="open_with">Открыть в</string>
+ <string name="new_tab">Новая вкладка</string>
+ <string name="add_tab">Добавить вкладку</string>
<!-- Save As. -->
<string name="save_as">Сохранить как</string>
<!-- MainWebViewActivity Navigation Menu. -->
<string name="navigation_drawer">Навигационная панель</string>
<string name="navigation">Навигация</string>
+ <string name="close_tab">Закрыть вкладку</string>
<string name="clear_and_exit">Очистить и выйти</string>
<string name="home">Домой</string>
<string name="back">Назад</string>
<string name="stop">Остановить</string>
<!-- Context Menus. -->
+ <string name="open_in_new_tab">Открыть в новой вкладке</string>
<string name="copy_url">Копировать URL</string>
<string name="download_url">Загрузить URL</string>
<string name="email_address">Адрес email</string>
<string name="javascript_preference">Включить JavaScript по умолчанию</string>
<string name="javascript_preference_summary">JavaScript позволяет веб-сайтам запускать программы (скрипты) на устройстве.</string>
<string name="first_party_cookies_preference">Включить первичные файлы cookie по умолчанию</string>
- <string name="first_party_cookies_preference_summary">На устройствах с версией Android старше Lollipop (версия 5.0) этим параметром также активируются сторонние файлы cookie.</string>
+ <string name="first_party_cookies_preference_summary">Поскольку первичные файлы cookie являются настройкой уровня приложения, при включении файлов cookie на активной вкладке, любые сетевые запросы,
+ сделанные в фоновом режиме другими вкладками, также будут содержать любые сохраненные файлы cookie для их доменов.
+ Android KitKat (версия 4.4.x) не различает первичные и сторонние файлы cookie и включает их одновременно этой настройкой.</string>
<string name="third_party_cookies_preference">Включить сторонние файлы cookie по умолчанию</string>
<string name="third_party_cookies_summary">Этот параметр требует Android Lollipop (версия 5.0) или выше. Он не действует, если первичные файлы cookie отключены.</string>
<string name="dom_storage_preference">Включить DOM-хранилище по умолчанию</string>
<string name="javascript_preference">JavaScript\'i varsayılan olarak etkinleştir</string>
<string name="javascript_preference_summary">JavaScript web sitelerin cihazdaki programları(scriptler) çalıştırmasına izin verir.</string>
<string name="first_party_cookies_preference">Birinci taraf çerezleri varsayılan olarak etkinleştir</string>
- <string name="first_party_cookies_preference_summary">Bu ayar, Android Lollipop sürümünden(5.0) eski sürümlere sahip cihazlarda üçüncü taraf çerezleri de etkinleştirir.</string>
<string name="third_party_cookies_preference">Üçüncü taraf çerezleri varsayılan olarak etkinleştir</string>
<string name="third_party_cookies_summary">Bu ayarı etkinleştirmek için Android Lollipop sürümüne(5.0) ya da daha üst sürümlere sahip olmak gerekir.
Birinci taraf çerezler devre dışı olduğu takdirde etkisi yoktur.</string>
<string name="javascript_preference">Enable JavaScript by default</string>
<string name="javascript_preference_summary">JavaScript allows websites to run programs (scripts) on the device.</string>
<string name="first_party_cookies_preference">Enable first-party cookies by default</string>
- <string name="first_party_cookies_preference_summary">Devices with versions of Android older than Lollipop (version 5.0) will also enable third-party cookies with this setting.</string>
+ <string name="first_party_cookies_preference_summary">Because first-party cookies are an app level setting, when the active tab has cookies enabled,
+ any network requests made in the background by other tabs will also include any stored cookies for their domains.
+ Android KitKat (version 4.4.x) does not differentiate between first and third-party cookies and will enable them both with this setting.</string>
<string name="third_party_cookies_preference">Enable third-party cookies by default</string>
<string name="third_party_cookies_summary">This setting requires Android Lollipop (version 5.0) or higher. It has no effect if first-party cookies are disabled.</string>
<string name="dom_storage_preference">Enable DOM storage by default</string>