]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkFolderDialog.java
Add setting to disable screenshots. https://redmine.stoutner.com/issues/266
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / EditBookmarkFolderDialog.java
index ab3e690d01346f929743be59cc50c348686da59a..8f41bfc7cb4eb60db318fd395e918b1cf74e3b61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2018 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -89,6 +89,9 @@ public class EditBookmarkFolderDialog extends AppCompatDialogFragment {
         // Run the default commands.
         super.onCreate(savedInstanceState);
 
+        // Remove the incorrect lint warning that `getInt()` might be null.
+        assert getArguments() != null;
+
         // Store the folder database ID in the class variable.
         selectedFolderDatabaseId = getArguments().getInt("Database ID");
     }
@@ -105,7 +108,7 @@ public class EditBookmarkFolderDialog extends AppCompatDialogFragment {
         Cursor folderCursor = bookmarksDatabaseHelper.getBookmarkCursor(selectedFolderDatabaseId);
         folderCursor.moveToFirst();
 
-        // Use `AlertDialog.Builder` to create the `AlertDialog`.
+        // Use an alert dialog builder to create the alert dialog.
         AlertDialog.Builder dialogBuilder;
 
         // Set the style according to the theme.
@@ -118,30 +121,38 @@ public class EditBookmarkFolderDialog extends AppCompatDialogFragment {
         // Set the title.
         dialogBuilder.setTitle(R.string.edit_folder);
 
+        // Remove the incorrect lint warning that `getActivity()` might be null.
+        assert getActivity() != null;
+
         // Set the view.  The parent view is `null` because it will be assigned by `AlertDialog`.
         dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.edit_bookmark_folder_dialog, null));
 
-        // Set an `onClick()` listener for the negative button.
+        // Set the listener for the negative button.
         dialogBuilder.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
             // Do nothing.  The `AlertDialog` will close automatically.
         });
 
-        // Set the `onClick()` listener fo the positive button.
+        // Set the listener fo the positive button.
         dialogBuilder.setPositiveButton(R.string.save, (DialogInterface dialog, int which) -> {
             // Return the `DialogFragment` to the parent activity on save.
             editBookmarkFolderListener.onSaveBookmarkFolder(EditBookmarkFolderDialog.this, selectedFolderDatabaseId);
         });
 
-        // Create an `AlertDialog` from the `AlertDialog.Builder`.
+        // Create an alert dialog from the alert dialog builder.
         final AlertDialog alertDialog = dialogBuilder.create();
 
-        // Remove the warning below that `setSoftInputMode` might produce `java.lang.NullPointerException`.
+        // Remove the warning below that `getWindow()` might be null.
         assert alertDialog.getWindow() != null;
 
-        // Show the keyboard when the `Dialog` is displayed on the screen.
+        // Disable screenshots if not allowed.
+        if (!MainWebViewActivity.allowScreenshots) {
+            alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
+        }
+
+        // Show the keyboard when the dialog is displayed on the screen.
         alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
 
-        // The `AlertDialog` must be shown before items in the layout can be modified.
+        // The alert dialog must be shown before items in the layout can be modified.
         alertDialog.show();
 
         // Get handles for layout items in the `AlertDialog`.