]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java
Add a requests activity. https://redmine.stoutner.com/issues/170
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / DownloadLocationPermissionDialog.java
index 0ad43d1c7a69d15e5adde01cb5a86c818c671b0b..117f000bef2cfdf9f5d958594d3da4c3d3637cb1 100644 (file)
@@ -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