X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FDownloadLocationPermissionDialog.java;h=117f000bef2cfdf9f5d958594d3da4c3d3637cb1;hb=012e5595c82d6e8d0b8a46f1ef18a02a56341182;hp=0ad43d1c7a69d15e5adde01cb5a86c818c671b0b;hpb=d420aa6be32a78b27905074edc3881a6e71d2263;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java index 0ad43d1c..117f000b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java @@ -25,6 +25,7 @@ import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; +import android.view.WindowManager; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.MainWebViewActivity; @@ -33,7 +34,22 @@ public class DownloadLocationPermissionDialog extends DialogFragment { public static final int DOWNLOAD_FILE = 1; public static final int DOWNLOAD_IMAGE = 2; - private int downloadType; + // `downloadLocationPermissionDialogListener` is used in `onAttach()` and `onCreateDialog()`. + private DownloadLocationPermissionDialogListener downloadLocationPermissionDialogListener; + + // The public interface is used to send information back to the parent activity. + public interface DownloadLocationPermissionDialogListener { + void onCloseDownloadLocationPermissionDialog(int downloadType); + } + + @Override + public void onAttach(Context context) { + // Run the default commands. + super.onAttach(context); + + // Get a handle for `DownloadLocationPermissionDialogListener` from the launching context. + downloadLocationPermissionDialogListener = (DownloadLocationPermissionDialogListener) context; + } public static DownloadLocationPermissionDialog downloadType(int type) { // Create an arguments bundle. @@ -49,35 +65,10 @@ public class DownloadLocationPermissionDialog extends DialogFragment { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - + public Dialog onCreateDialog(Bundle savedInstanceState) { // Store the download type in the local class variable. - downloadType = getArguments().getInt("Download_Type"); - } + int downloadType = getArguments().getInt("Download_Type"); - // The public interface is used to send information back to the parent activity. - public interface DownloadLocationPermissionDialogListener { - void onCloseDownloadLocationPermissionDialog(int downloadType); - } - - // `downloadLocationPermissionDialogListener` is used in `onAttach()` and `onCreateDialog()`. - private DownloadLocationPermissionDialogListener downloadLocationPermissionDialogListener; - - @Override - public void onAttach(Context context) { - super.onAttach(context); - - // Check to make sure the parent activity implements the listener. - try { - downloadLocationPermissionDialogListener = (DownloadLocationPermissionDialogListener) context; - } catch (ClassCastException exception) { - throw new ClassCastException(context.toString() + " must implement DownloadLocationPermissionDialogListener."); - } - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { // Use a builder to create the alert dialog. AlertDialog.Builder dialogBuilder; @@ -102,7 +93,19 @@ public class DownloadLocationPermissionDialog extends DialogFragment { // Set the text. dialogBuilder.setMessage(R.string.download_location_message); + // Create an alert dialog from the alert dialog builder. + final AlertDialog alertDialog = dialogBuilder.create(); + + // Disable screenshots if not allowed. + if (!MainWebViewActivity.allowScreenshots) { + // Remove the warning below that `getWindow()` might be null. + assert alertDialog.getWindow() != null; + + // Disable screenshots. + alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + // `onCreateDialog` requires the return of an `AlertDialog`. - return dialogBuilder.create(); + return alertDialog; } } \ No newline at end of file