private TabLayout tabLayout;
private SwipeRefreshLayout swipeRefreshLayout;
private ViewPager webViewPager;
+ private NavigationView navigationView;
+
+ // Declare the class menus.
+ private Menu navigationMenu;
+
+ // Declare the class menu items.
+ private MenuItem navigationRequestsMenuItem;
@Override
// Remove the warning about needing to override `performClick()` when using an `OnTouchListener` with `WebView`.
tabLayout = findViewById(R.id.tablayout);
swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
webViewPager = findViewById(R.id.webviewpager);
+ navigationView = findViewById(R.id.navigationview);
+
+ // Get handles for the class menus.
+ navigationMenu = navigationView.getMenu();
+
+ // Get a handle for the navigation requests menu item.
+ navigationRequestsMenuItem = navigationMenu.findItem(R.id.requests);
// Get a handle for the app compat delegate.
AppCompatDelegate appCompatDelegate = getDelegate();
// Get the nested scroll WebView from the tab fragment.
NestedScrollWebView nestedScrollWebView = fragmentView.findViewById(R.id.nestedscroll_webview);
- // Resume the nested scroll WebView JavaScript timers.
- nestedScrollWebView.resumeTimers();
-
// Resume the nested scroll WebView.
nestedScrollWebView.onResume();
}
}
+ // Resume the nested scroll WebView JavaScript timers. This is a global command that resumes JavaScript timers on all WebViews.
+ if (currentWebView != null) {
+ currentWebView.resumeTimers();
+ }
+
// Reapply the proxy settings if the system is using a proxy. This redisplays the appropriate alert dialog.
if (!proxyMode.equals(ProxyHelper.NONE)) {
applyProxy(false);
// Pause the nested scroll WebView.
nestedScrollWebView.onPause();
-
- // Pause the nested scroll WebView JavaScript timers.
- nestedScrollWebView.pauseTimers();
}
}
+ // Pause the WebView JavaScript timers. This is a global command that pauses JavaScript on all WebViews.
+ if (currentWebView != null) {
+ currentWebView.pauseTimers();
+ }
+
// Pause the ad or it will continue to consume resources in the background on the free flavor.
if (BuildConfig.FLAVOR.contentEquals("free")) {
// Pause the ad.
updatePrivacyIcons(false);
// Get handles for the menu items.
+ MenuItem bookmarksMenuItem = menu.findItem(R.id.bookmarks);
MenuItem toggleFirstPartyCookiesMenuItem = menu.findItem(R.id.toggle_first_party_cookies);
MenuItem toggleThirdPartyCookiesMenuItem = menu.findItem(R.id.toggle_third_party_cookies);
- MenuItem toggleDomStorageMenuItem = menu.findItem(R.id.toggle_dom_storage);
MenuItem toggleSaveFormDataMenuItem = menu.findItem(R.id.toggle_save_form_data); // Form data can be removed once the minimum API >= 26.
MenuItem clearFormDataMenuItem = menu.findItem(R.id.clear_form_data); // Form data can be removed once the minimum API >= 26.
MenuItem refreshMenuItem = menu.findItem(R.id.refresh);
// Get the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- // Get the dark theme and app bar preferences..
- boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean("display_additional_app_bar_icons", false);
+ // Get the dark theme and app bar preferences.
+ boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), 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) {
- toggleFirstPartyCookiesMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
- toggleDomStorageMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
refreshMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+ bookmarksMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ toggleFirstPartyCookiesMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
} else { //Do not display the additional icons.
- toggleFirstPartyCookiesMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- toggleDomStorageMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
refreshMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ bookmarksMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ toggleFirstPartyCookiesMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
}
// Replace Refresh with Stop if a URL is already loading.
// Set the icon according to the current theme status.
if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
- refreshMenuItem.setIcon(R.drawable.close_day);
+ refreshMenuItem.setIcon(R.drawable.close_blue_day);
} else {
- refreshMenuItem.setIcon(R.drawable.close_night);
+ refreshMenuItem.setIcon(R.drawable.close_blue_night);
}
}
}
Intent viewSourceIntent = new Intent(this, ViewSourceActivity.class);
// Add the variables to the intent.
- viewSourceIntent.putExtra("user_agent", currentWebView.getSettings().getUserAgentString());
- viewSourceIntent.putExtra("current_url", currentWebView.getUrl());
+ viewSourceIntent.putExtra(ViewSourceActivityKt.CURRENT_URL, currentWebView.getUrl());
+ viewSourceIntent.putExtra(ViewSourceActivityKt.USER_AGENT, currentWebView.getSettings().getUserAgentString());
// Make it so.
startActivity(viewSourceIntent);
this.registerReceiver(orbotStatusBroadcastReceiver, new IntentFilter("org.torproject.android.intent.action.STATUS"));
// Get handles for views that need to be modified.
- NavigationView navigationView = findViewById(R.id.navigationview);
- SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
ListView bookmarksListView = findViewById(R.id.bookmarks_drawer_listview);
FloatingActionButton launchBookmarksActivityFab = findViewById(R.id.launch_bookmarks_activity_fab);
FloatingActionButton createBookmarkFolderFab = findViewById(R.id.create_bookmark_folder_fab);
// Listen for touches on the navigation menu.
navigationView.setNavigationItemSelectedListener(this);
- // Get handles for the navigation menu and the back and forward menu items.
- Menu navigationMenu = navigationView.getMenu();
+ // Get handles for the navigation menu items.
MenuItem navigationBackMenuItem = navigationMenu.findItem(R.id.back);
MenuItem navigationForwardMenuItem = navigationMenu.findItem(R.id.forward);
MenuItem navigationHistoryMenuItem = navigationMenu.findItem(R.id.history);
- MenuItem navigationRequestsMenuItem = navigationMenu.findItem(R.id.requests);
// Update the web view pager every time a tab is modified.
webViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
// Get handles for the menu items.
MenuItem privacyMenuItem = optionsMenu.findItem(R.id.toggle_javascript);
MenuItem firstPartyCookiesMenuItem = optionsMenu.findItem(R.id.toggle_first_party_cookies);
- MenuItem domStorageMenuItem = optionsMenu.findItem(R.id.toggle_dom_storage);
MenuItem refreshMenuItem = optionsMenu.findItem(R.id.refresh);
// Update the privacy icon.
}
}
- // Update the DOM storage icon.
- if (currentWebView.getSettings().getJavaScriptEnabled() && currentWebView.getSettings().getDomStorageEnabled()) { // Both JavaScript and DOM storage are enabled.
- domStorageMenuItem.setIcon(R.drawable.dom_storage_enabled);
- } else if (currentWebView.getSettings().getJavaScriptEnabled()) { // JavaScript is enabled but DOM storage is disabled.
+ // Update the refresh icon.
+ if (refreshMenuItem.getTitle() == getString(R.string.refresh)) { // The refresh icon is displayed.
+ // Set the icon according to the theme.
if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
- domStorageMenuItem.setIcon(R.drawable.dom_storage_disabled_day);
+ refreshMenuItem.setIcon(R.drawable.refresh_enabled_day);
} else {
- domStorageMenuItem.setIcon(R.drawable.dom_storage_disabled_night);
+ refreshMenuItem.setIcon(R.drawable.refresh_enabled_night);
}
- } else { // JavaScript is disabled, so DOM storage is ghosted.
+ } else { // The stop icon is displayed.
+ // Set the icon according to the theme.
if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
- domStorageMenuItem.setIcon(R.drawable.dom_storage_ghosted_day);
+ refreshMenuItem.setIcon(R.drawable.close_blue_day);
} else {
- domStorageMenuItem.setIcon(R.drawable.dom_storage_ghosted_night);
+ refreshMenuItem.setIcon(R.drawable.close_blue_night);
}
}
- // Update the refresh icon.
- if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
- refreshMenuItem.setIcon(R.drawable.refresh_enabled_day);
- } else {
- refreshMenuItem.setIcon(R.drawable.refresh_enabled_night);
- }
-
// `invalidateOptionsMenu()` calls `onPrepareOptionsMenu()` and redraws the icons in the app bar.
if (runInvalidateOptionsMenu) {
invalidateOptionsMenu();
}
private void closeCurrentTab() {
- // Pause the current WebView.
+ // Pause the current WebView. This prevents buffered audio from playing after the tab is closed.
currentWebView.onPause();
- // Pause the current WebView JavaScript timers.
- currentWebView.pauseTimers();
-
// Get the current tab number.
int currentTabNumber = tabLayout.getSelectedTabPosition();
// Sanitize the URL.
url = sanitizeUrl(url);
- // Get a handle for the navigation view.
- NavigationView navigationView = findViewById(R.id.navigationview);
-
- // Get a handle for the navigation menu.
- Menu navigationMenu = navigationView.getMenu();
-
- // Get a handle for the navigation requests menu item.
- MenuItem navigationRequestsMenuItem = navigationMenu.findItem(R.id.requests);
-
// Create an empty web resource response to be used if the resource request is blocked.
WebResourceResponse emptyWebResourceResponse = new WebResourceResponse("text/plain", "utf8", new ByteArrayInputStream("".getBytes()));
refreshMenuItem.setTitle(R.string.stop);
// Get the app bar and theme preferences.
- boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean("display_additional_app_bar_icons", false);
+ boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false);
// If the icon is displayed in the AppBar, set it according to the theme.
if (displayAdditionalAppBarIcons) {
// Set the stop icon according to the theme.
if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
- refreshMenuItem.setIcon(R.drawable.close_day);
+ refreshMenuItem.setIcon(R.drawable.close_blue_day);
} else {
- refreshMenuItem.setIcon(R.drawable.close_night);
+ refreshMenuItem.setIcon(R.drawable.close_blue_night);
}
}
}
refreshMenuItem.setTitle(R.string.refresh);
// Get the app bar and theme preferences.
- boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean("display_additional_app_bar_icons", false);
+ boolean displayAdditionalAppBarIcons = sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false);
// If the icon is displayed in the app bar, reset it according to the theme.
if (displayAdditionalAppBarIcons) {