X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FEditBookmarkDatabaseViewDialog.java;h=272e471956633e0a4b0605daf07e4b369e6c8f83;hp=d75cf6c0c7a7376d8202c8b8dc22db5401fb6585;hb=b4fc354bee486a2df17b3aae6760a3c61eba1e97;hpb=9f551f25b53a30cca7b19b6e6bfc2d2520d9aa1b diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java index d75cf6c0..272e4719 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 Soren Stoutner . + * Copyright © 2016-2018 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -58,7 +58,6 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Instantiate the class variables. private EditBookmarkDatabaseViewListener editBookmarkDatabaseViewListener; - private int bookmarkDatabaseId; private String currentBookmarkName; private String currentUrl; private int currentFolderDatabaseId; @@ -75,16 +74,14 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { void onSaveBookmark(AppCompatDialogFragment dialogFragment, int selectedBookmarkDatabaseId); } + @Override public void onAttach(Context context) { // Run the default commands. super.onAttach(context); - // Get a handle for `EditBookmarkDatabaseViewListener` from `context`. - try { - editBookmarkDatabaseViewListener = (EditBookmarkDatabaseViewListener) context; - } catch(ClassCastException exception) { - throw new ClassCastException(context.toString() + " must implement EditBookmarkDatabaseViewListener."); - } + // Get a handle for `EditBookmarkDatabaseViewListener` from the launching context. + + editBookmarkDatabaseViewListener = (EditBookmarkDatabaseViewListener) context; } // Store the database ID in the arguments bundle. @@ -103,28 +100,25 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { return editBookmarkDatabaseViewDialog; } - @Override - public void onCreate(Bundle savedInstanceState) { - // Run the default commands. - super.onCreate(savedInstanceState); - - // Store the bookmark database ID in the class variable. - bookmarkDatabaseId = getArguments().getInt("Database ID"); - } - - // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. + // `@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) { - // 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`. + // Remove the incorrect lint warning below that `getInt()` might be null. + assert getArguments() != null; + + // Get the bookmark database ID from the bundle. + int bookmarkDatabaseId = getArguments().getInt("Database ID"); + + // Initialize the database helper. The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`. BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(getContext(), null, null, 0); - // Get a `Cursor` with the selected bookmark and move it to the first position. + // Get a cursor with the selected bookmark and move it to the first position. Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(bookmarkDatabaseId); bookmarkCursor.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. @@ -137,30 +131,38 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Set the title. dialogBuilder.setTitle(R.string.edit_bookmark); + // Remove the incorrect lint warning below that `getLayoutInflater()` 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_databaseview_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. editBookmarkDatabaseViewListener.onSaveBookmark(EditBookmarkDatabaseViewDialog.this, bookmarkDatabaseId); }); - // 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; + // Disable screenshots if not allowed. + if (!MainWebViewActivity.allowScreenshots) { + alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + // Set the keyboard to be hidden when the `AlertDialog` is first shown. If this is not set, the `AlertDialog` will not shrink when the keyboard is displayed. alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - // 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 the layout items. @@ -210,8 +212,11 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Combine `matrixCursor` and `foldersCursor`. MergeCursor foldersMergeCursor = new MergeCursor(new Cursor[]{matrixCursor, foldersCursor}); + // Remove the incorrect lint warning below that `getContext()` might be null. + assert getContext() != null; + // Create a `ResourceCursorAdapter` for the `Spinner`. `0` specifies no flags.; - ResourceCursorAdapter foldersCursorAdapter = new ResourceCursorAdapter(getContext(), R.layout.edit_bookmark_databaseview_spinner_item, foldersMergeCursor, 0) { + ResourceCursorAdapter foldersCursorAdapter = new ResourceCursorAdapter(getContext(), R.layout.spinner_item, foldersMergeCursor, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { // Get a handle for the `Spinner` item `TextView`. @@ -223,7 +228,7 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { }; // Set the `ResourceCursorAdapter` drop drown view resource. - foldersCursorAdapter.setDropDownViewResource(R.layout.edit_bookmark_databaseview_spinner_dropdown_item); + foldersCursorAdapter.setDropDownViewResource(R.layout.spinner_dropdown_items); // Set the adapter for the folder `Spinner`. folderSpinner.setAdapter(foldersCursorAdapter);