import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.activities.MainWebViewActivity;
import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
-public class EditBookmarkFolderDialog extends AppCompatDialogFragment {
+public class EditBookmarkFolderDialog extends DialogFragment {
+ // Instantiate the class variable.
+ private EditBookmarkFolderListener editBookmarkFolderListener;
+
// The public interface is used to send information back to the parent activity.
public interface EditBookmarkFolderListener {
// The public interface is used to send information back to the parent activity.
public interface EditBookmarkFolderListener {
- // Get a handle for `EditFolderListener` from `parentActivity`.
- try {
- editBookmarkFolderListener = (EditBookmarkFolderListener) context;
- } catch(ClassCastException exception) {
- throw new ClassCastException(context.toString() + " must implement EditBookmarkFolderListener.");
- }
+ // Get a handle for `EditFolderListener` from the launching context.
+ editBookmarkFolderListener = (EditBookmarkFolderListener) context;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- // Run the default commands.
- super.onCreate(savedInstanceState);
-
- // Store the folder database ID in the class variable.
- selectedFolderDatabaseId = getArguments().getInt("Database ID");
- }
-
// `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
@SuppressLint("InflateParams")
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
// `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
@SuppressLint("InflateParams")
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Remove the incorrect lint warning that `getInt()` might be null.
+ assert getArguments() != null;
+
+ // Store the folder database ID in the class variable.
+ int selectedFolderDatabaseId = getArguments().getInt("Database ID");
+
// Initialize the database helper. The two `nulls` do not specify the database name or a `CursorFactory`. The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
final BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(getContext(), null, null, 0);
// Get a `Cursor` with the selected folder and move it to the first position.
// Initialize the database helper. The two `nulls` do not specify the database name or a `CursorFactory`. The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
final BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(getContext(), null, null, 0);
// Get a `Cursor` with the selected folder and move it to the first position.
// 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 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));
dialogBuilder.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
// Do nothing. The `AlertDialog` will close automatically.
});
dialogBuilder.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
// Do nothing. The `AlertDialog` will close automatically.
});
dialogBuilder.setPositiveButton(R.string.save, (DialogInterface dialog, int which) -> {
// Return the `DialogFragment` to the parent activity on save.
editBookmarkFolderListener.onSaveBookmarkFolder(EditBookmarkFolderDialog.this, selectedFolderDatabaseId);
});
dialogBuilder.setPositiveButton(R.string.save, (DialogInterface dialog, int which) -> {
// Return the `DialogFragment` to the parent activity on save.
editBookmarkFolderListener.onSaveBookmarkFolder(EditBookmarkFolderDialog.this, selectedFolderDatabaseId);
});
- // 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.
String newFolderName = folderNameEditText.getText().toString();
// Get a cursor for the new folder name if it exists.
String newFolderName = folderNameEditText.getText().toString();
// Get a cursor for the new folder name if it exists.