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;
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.
}
@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;
// 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