X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Ffree%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FAdConsentDialog.java;h=bce865f224443ddd18559ff83f09c90b764a0f31;hp=94f8a91e60019bf40c10be40bb7eef602a8d9d93;hb=fa3b8b382eb5ed86c598e3b126d1ef5dd117c5be;hpb=fa5bfd542337d3aff87271af18272768312e1306 diff --git a/app/src/free/java/com/stoutner/privacybrowser/dialogs/AdConsentDialog.java b/app/src/free/java/com/stoutner/privacybrowser/dialogs/AdConsentDialog.java index 94f8a91e..bce865f2 100644 --- a/app/src/free/java/com/stoutner/privacybrowser/dialogs/AdConsentDialog.java +++ b/app/src/free/java/com/stoutner/privacybrowser/dialogs/AdConsentDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018 Soren Stoutner . + * Copyright © 2018-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -21,24 +21,36 @@ package com.stoutner.privacybrowser.dialogs; import android.app.AlertDialog; import android.app.Dialog; -import android.app.DialogFragment; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.Build; 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; import com.stoutner.privacybrowser.helpers.AdConsentDatabaseHelper; import com.stoutner.privacybrowser.helpers.AdHelper; public class AdConsentDialog extends DialogFragment { + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + // 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); + // 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.block_ads_enabled_dark); } else { @@ -46,8 +58,11 @@ public class AdConsentDialog extends DialogFragment { dialogBuilder.setIcon(R.drawable.block_ads_enabled_light); } + // Remove the incorrect lint warning below that `getApplicationContext()` might be null. + assert getActivity() != null; + // Initialize the bookmarks database helper. The `0` specifies a database version, but that is ignored and set instead using a constant in `AdConsentDatabaseHelper`. - // `getContext()` can be used instead of `getActivity.getApplicationContext()` on the minimum API >= 23. + // `getContext()` can be used instead of `getActivity.getApplicationContext()` when the minimum API >= 23. AdConsentDatabaseHelper adConsentDatabaseHelper = new AdConsentDatabaseHelper(getActivity().getApplicationContext(), null, null, 0); // Set the title. @@ -81,15 +96,30 @@ public class AdConsentDialog extends DialogFragment { AdHelper.loadAd(getActivity().findViewById(R.id.adview), getActivity().getApplicationContext(), getString(R.string.ad_unit_id)); }); + // Create an alert dialog from the alert dialog builder. + AlertDialog alertDialog = dialogBuilder.create(); + + // Disable screenshots if not allowed. + if (!allowScreenshots) { + // Remove the warning below that `getWindow()` might be null. + assert alertDialog.getWindow() != null; + + // Disable screenshots. + alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + // Return the alert dialog. - return dialogBuilder.create(); + return alertDialog; } // Close Privacy Browser Free if the dialog is cancelled without selecting a button (by tapping on the background). @Override public void onCancel(DialogInterface dialogInterface) { + // Remove the incorrect lint warning below that `getApplicationContext()` might be null. + assert getActivity() != null; + // Initialize the bookmarks database helper. The `0` specifies a database version, but that is ignored and set instead using a constant in `AdConsentDatabaseHelper`. - // `getContext()` can be used instead of `getActivity.getApplicationContext()` on the minimum API >= 23. + // `getContext()` can be used instead of `getActivity.getApplicationContext()` when the minimum API >= 23. AdConsentDatabaseHelper adConsentDatabaseHelper = new AdConsentDatabaseHelper(getActivity().getApplicationContext(), null, null, 0); // Update the ad consent database.