import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
-import com.stoutner.privacybrowser.BuildConfig;
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.adapters.WebViewPagerAdapter;
import com.stoutner.privacybrowser.asynctasks.GetHostIpAddresses;
import com.stoutner.privacybrowser.asynctasks.SaveUrl;
import com.stoutner.privacybrowser.asynctasks.SaveWebpageImage;
import com.stoutner.privacybrowser.dataclasses.PendingDialog;
-import com.stoutner.privacybrowser.dialogs.AdConsentDialog;
import com.stoutner.privacybrowser.dialogs.CreateBookmarkDialog;
import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolderDialog;
import com.stoutner.privacybrowser.dialogs.CreateHomeScreenShortcutDialog;
import com.stoutner.privacybrowser.dialogs.ViewSslCertificateDialog;
import com.stoutner.privacybrowser.dialogs.WaitingForProxyDialog;
import com.stoutner.privacybrowser.fragments.WebViewTabFragment;
-import com.stoutner.privacybrowser.helpers.AdHelper;
import com.stoutner.privacybrowser.helpers.BlocklistHelper;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper;
// Declare the class views.
private FrameLayout rootFrameLayout;
private DrawerLayout drawerLayout;
- private RelativeLayout mainContentRelativeLayout;
+ private CoordinatorLayout coordinatorLayout;
private AppBarLayout appBarLayout;
private Toolbar toolbar;
private RelativeLayout urlRelativeLayout;
// Get handles for the views.
rootFrameLayout = findViewById(R.id.root_framelayout);
drawerLayout = findViewById(R.id.drawerlayout);
- mainContentRelativeLayout = findViewById(R.id.main_content_relativelayout);
+ coordinatorLayout = findViewById(R.id.coordinatorlayout);
appBarLayout = findViewById(R.id.appbar_layout);
toolbar = findViewById(R.id.toolbar);
findOnPageLinearLayout = findViewById(R.id.find_on_page_linearlayout);
applyProxy(false);
}
- // Reapply any system UI flags and the ad in the free flavor.
+ // Reapply any system UI flags.
if (displayingFullScreenVideo || inFullScreenBrowsingMode) { // The system is displaying a website or a video in full screen mode.
/* Hide the system bars.
* SYSTEM_UI_FLAG_FULLSCREEN hides the status bar at the top of the screen.
*/
rootFrameLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
- } else if (BuildConfig.FLAVOR.contentEquals("free")) { // The system in not in full screen mode.
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Resume the ad.
- AdHelper.resumeAd(adView);
}
// Show any pending dialogs.
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")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Pause the ad.
- AdHelper.pauseAd(adView);
- }
}
@Override
// Store a handle for the options menu so it can be used by `onOptionsItemSelected()` and `updatePrivacyIcons()`.
optionsMenu = menu;
- // Get handles for the class menu items.
+ // Get handles for the menu items.
optionsPrivacyMenuItem = menu.findItem(R.id.javascript);
optionsRefreshMenuItem = menu.findItem(R.id.refresh);
+ MenuItem bookmarksMenuItem = menu.findItem(R.id.bookmarks);
optionsCookiesMenuItem = menu.findItem(R.id.cookies);
optionsDomStorageMenuItem = menu.findItem(R.id.dom_storage);
optionsSaveFormDataMenuItem = menu.findItem(R.id.save_form_data); // Form data can be removed once the minimum API >= 26.
optionsFontSizeMenuItem = menu.findItem(R.id.font_size);
optionsAddOrEditDomainMenuItem = menu.findItem(R.id.add_or_edit_domain);
- // Get handles for the method menu items.
- MenuItem bookmarksMenuItem = menu.findItem(R.id.bookmarks);
- MenuItem adConsentMenuItem = menu.findItem(R.id.ad_consent);
-
// Set the initial status of the privacy icons. `false` does not call `invalidateOptionsMenu` as the last step.
updatePrivacyIcons(false);
// Only display the dark WebView menu item if API >= 21.
optionsDarkWebViewMenuItem.setVisible(Build.VERSION.SDK_INT >= 21);
- // Only show Ad Consent if this is the free flavor.
- adConsentMenuItem.setVisible(BuildConfig.FLAVOR.contentEquals("free"));
-
// Get the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
startActivity(domainsIntent);
}
- // Consume the event.
- return true;
- } else if (menuItemId == R.id.ad_consent) { // Ad consent.
- // Instantiate the ad consent dialog.
- DialogFragment adConsentDialogFragment = new AdConsentDialog();
-
- // Display the ad consent dialog.
- adConsentDialogFragment.show(getSupportFragmentManager(), getString(R.string.ad_consent));
-
// Consume the event.
return true;
} else { // There is no match with the options menu. Pass the event up to the parent method.
actionBarDrawerToggle.syncState();
}
- @Override
- public void onConfigurationChanged(@NonNull Configuration newConfig) {
- // Run the default commands.
- super.onConfigurationChanged(newConfig);
-
- // Reload the ad for the free flavor if not in full screen mode.
- if (BuildConfig.FLAVOR.contentEquals("free") && !inFullScreenBrowsingMode) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Reload the ad. The AdView is destroyed and recreated, which changes the ID, every time it is reloaded to handle possible rotations.
- // `getContext()` can be used instead of `getActivity.getApplicationContext()` once the minimum API >= 23.
- AdHelper.loadAd(adView, getApplicationContext(), this, getString(R.string.ad_unit_id));
- }
-
- // `invalidateOptionsMenu` should recalculate the number of action buttons from the menu to display on the app bar, but it doesn't because of the this bug:
- // https://code.google.com/p/android/issues/detail?id=20493#c8
- // ActivityCompat.invalidateOptionsMenu(this);
- }
-
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
// Get the hit test result.
actionBar.show();
}
- // Hide the banner ad in the free flavor.
- if (BuildConfig.FLAVOR.contentEquals("free")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Hide the banner ad.
- AdHelper.hideAd(adView);
- }
-
/* Hide the system bars.
* SYSTEM_UI_FLAG_FULLSCREEN hides the status bar at the top of the screen.
* SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN makes the root frame layout fill the area that is normally reserved for the status bar.
// Show the action bar.
actionBar.show();
- // Show the banner ad in the free flavor.
- if (BuildConfig.FLAVOR.contentEquals("free")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Initialize the ads. If this isn't the first run, `loadAd()` will be automatically called instead.
- // `getContext()` can be used instead of `getActivity.getApplicationContext()` once the minimum API >= 23.
- AdHelper.initializeAds(adView, getApplicationContext(), this, getSupportFragmentManager(), getString(R.string.ad_unit_id));
- }
-
// Remove the `SYSTEM_UI` flags from the root frame layout.
rootFrameLayout.setSystemUiVisibility(0);
}
// Enable the sliding drawers.
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
- // Show the main content relative layout.
- mainContentRelativeLayout.setVisibility(View.VISIBLE);
+ // Show the coordinator layout.
+ coordinatorLayout.setVisibility(View.VISIBLE);
// Apply the appropriate full screen mode flags.
if (fullScreenBrowsingModeEnabled && inFullScreenBrowsingMode) { // Privacy Browser is currently in full screen browsing mode.
actionBar.hide();
}
- // Hide the banner ad in the free flavor.
- if (BuildConfig.FLAVOR.contentEquals("free")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Hide the banner ad.
- AdHelper.hideAd(adView);
- }
-
/* Hide the system bars.
* SYSTEM_UI_FLAG_FULLSCREEN hides the status bar at the top of the screen.
* SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN makes the root frame layout fill the area that is normally reserved for the status bar.
// Remove the `SYSTEM_UI` flags from the root frame layout.
rootFrameLayout.setSystemUiVisibility(0);
}
-
- // Reload the ad for the free flavor if not in full screen mode.
- if (BuildConfig.FLAVOR.contentEquals("free") && !inFullScreenBrowsingMode) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Reload the ad.
- AdHelper.loadAd(adView, this, this, getString(R.string.ad_unit_id));
- }
}
private void clearAndExit() {
}
}
- // Hide the banner ad in the free flavor.
- if (BuildConfig.FLAVOR.contentEquals("free")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Hide the banner ad.
- AdHelper.hideAd(adView);
- }
-
/* Hide the system bars.
* SYSTEM_UI_FLAG_FULLSCREEN hides the status bar at the top of the screen.
* SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN makes the root frame layout fill the area that is normally reserved for the status bar.
}
}
- // Show the banner ad in the free flavor.
- if (BuildConfig.FLAVOR.contentEquals("free")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // Reload the ad. `getContext()` can be used instead of `getActivity.getApplicationContext()` once the minimum API >= 23.
- AdHelper.loadAd(adView, getApplicationContext(), activity, getString(R.string.ad_unit_id));
- }
-
// Remove the `SYSTEM_UI` flags from the root frame layout.
rootFrameLayout.setSystemUiVisibility(0);
}
// Set the full screen video flag.
displayingFullScreenVideo = true;
- // Pause the ad if this is the free flavor.
- if (BuildConfig.FLAVOR.contentEquals("free")) {
- // Get a handle for the ad view. This cannot be a class variable because it changes with each ad load.
- View adView = findViewById(R.id.adview);
-
- // The AdView is destroyed and recreated, which changes the ID, every time it is reloaded to handle possible rotations.
- AdHelper.pauseAd(adView);
- }
-
// Hide the keyboard.
inputMethodManager.hideSoftInputFromWindow(nestedScrollWebView.getWindowToken(), 0);
- // Hide the main content relative layout.
- mainContentRelativeLayout.setVisibility(View.GONE);
+ // Hide the coordinator layout.
+ coordinatorLayout.setVisibility(View.GONE);
/* Hide the system bars.
* SYSTEM_UI_FLAG_FULLSCREEN hides the status bar at the top of the screen.