From 1bd5ba3b9f91e69517fa8a39665256f0badc408b Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Sat, 22 Oct 2016 20:09:18 -0700 Subject: [PATCH] Switch to AppCompatDialogFragment for dialogs that return values due to crashes in API <= 23 after switching to target API 24. Fix downloading of files crash on API <= 23. --- .../privacybrowser/BookmarksActivity.java | 32 +++++++++---------- .../privacybrowser/CreateBookmark.java | 9 ++++-- .../privacybrowser/CreateBookmarkFolder.java | 9 ++++-- .../CreateHomeScreenShortcut.java | 9 ++++-- .../stoutner/privacybrowser/DownloadFile.java | 9 ++++-- .../stoutner/privacybrowser/EditBookmark.java | 9 ++++-- .../privacybrowser/EditBookmarkFolder.java | 9 ++++-- .../privacybrowser/MainWebViewActivity.java | 20 +++++++----- .../stoutner/privacybrowser/MoveToFolder.java | 9 ++++-- 9 files changed, 70 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java index 65d1cfdd..3941e634 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java @@ -20,7 +20,6 @@ package com.stoutner.privacybrowser; import android.app.Activity; -import android.app.DialogFragment; import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -35,6 +34,7 @@ import android.support.design.widget.Snackbar; import android.support.v4.app.NavUtils; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.AppCompatDialogFragment; import android.support.v7.widget.Toolbar; import android.util.SparseBooleanArray; import android.view.ActionMode; @@ -345,8 +345,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma checkedItemIds = bookmarksListView.getCheckedItemIds(); // Show the `MoveToFolder` `AlertDialog` and name the instance `@string/move_to_folder - DialogFragment moveToFolderDialog = new MoveToFolder(); - moveToFolderDialog.show(getFragmentManager(), getResources().getString(R.string.move_to_folder)); + AppCompatDialogFragment moveToFolderDialog = new MoveToFolder(); + moveToFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.move_to_folder)); break; case R.id.edit_bookmark: @@ -370,12 +370,12 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME)); // Show the `EditBookmarkFolder` `AlertDialog` and name the instance `@string/edit_folder`. - DialogFragment editFolderDialog = new EditBookmarkFolder(); - editFolderDialog.show(getFragmentManager(), getResources().getString(R.string.edit_folder)); + AppCompatDialogFragment editFolderDialog = new EditBookmarkFolder(); + editFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_folder)); } else { // Show the `EditBookmark` `AlertDialog` and name the instance `@string/edit_bookmark`. - DialogFragment editBookmarkDialog = new EditBookmark(); - editBookmarkDialog.show(getFragmentManager(), getResources().getString(R.string.edit_bookmark)); + AppCompatDialogFragment editBookmarkDialog = new EditBookmark(); + editBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_bookmark)); } break; @@ -488,8 +488,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma @Override public void onClick(View view) { // Show the `CreateBookmark` `AlertDialog` and name the instance `@string/create_bookmark`. - DialogFragment createBookmarkDialog = new CreateBookmark(); - createBookmarkDialog.show(getFragmentManager(), getResources().getString(R.string.create_bookmark)); + AppCompatDialogFragment createBookmarkDialog = new CreateBookmark(); + createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark)); } }); } @@ -528,8 +528,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma case R.id.create_folder: // Show the `CreateBookmarkFolder` `AlertDialog` and name the instance `@string/create_folder`. - DialogFragment createBookmarkFolderDialog = new CreateBookmarkFolder(); - createBookmarkFolderDialog.show(getFragmentManager(), getResources().getString(R.string.create_folder)); + AppCompatDialogFragment createBookmarkFolderDialog = new CreateBookmarkFolder(); + createBookmarkFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_folder)); break; case R.id.options_menu_select_all_bookmarks: @@ -550,7 +550,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } @Override - public void onCreateBookmark(DialogFragment dialogFragment) { + public void onCreateBookmark(AppCompatDialogFragment dialogFragment) { // Get the `EditText`s from the `createBookmarkDialogFragment` and extract the strings. EditText createBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext); String bookmarkNameString = createBookmarkNameEditText.getText().toString(); @@ -575,7 +575,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } @Override - public void onCreateBookmarkFolder(DialogFragment dialogFragment) { + public void onCreateBookmarkFolder(AppCompatDialogFragment dialogFragment) { // Get `create_folder_name_edit_text` and extract the string. EditText createFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext); String folderNameString = createFolderNameEditText.getText().toString(); @@ -621,7 +621,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } @Override - public void onSaveEditBookmark(DialogFragment dialogFragment) { + public void onSaveEditBookmark(AppCompatDialogFragment dialogFragment) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds(); int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0]; @@ -655,7 +655,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } @Override - public void onSaveEditBookmarkFolder(DialogFragment dialogFragment) { + public void onSaveEditBookmarkFolder(AppCompatDialogFragment dialogFragment) { // Get the new folder name. EditText editFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext); String newFolderNameString = editFolderNameEditText.getText().toString(); @@ -717,7 +717,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } @Override - public void onMoveToFolder(DialogFragment dialogFragment) { + public void onMoveToFolder(AppCompatDialogFragment dialogFragment) { // Get the new folder database id. ListView folderListView = (ListView) dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview); long[] newFolderLongArray = folderListView.getCheckedItemIds(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java index 8aa5dbce..8bd0930a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java @@ -21,23 +21,25 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.support.annotation.NonNull; // If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.widget.EditText; -public class CreateBookmark extends DialogFragment { +public class CreateBookmark extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateBookmarkListener { - void onCreateBookmark(DialogFragment dialogFragment); + void onCreateBookmark(AppCompatDialogFragment dialogFragment); } // `createBookmarkListener` is used in `onAttach()` and `onCreateDialog()` @@ -58,6 +60,7 @@ public class CreateBookmark extends DialogFragment { // `@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) { // Create a drawable version of the favorite icon. Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java index 73741047..46d2ed96 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java @@ -21,22 +21,24 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.NonNull; // If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; -public class CreateBookmarkFolder extends DialogFragment { +public class CreateBookmarkFolder extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateBookmarkFolderListener { - void onCreateBookmarkFolder(DialogFragment dialogFragment); + void onCreateBookmarkFolder(AppCompatDialogFragment dialogFragment); } // `createBookmarkFolderListener` is used in `onAttach()` and `onCreateDialog`. @@ -56,6 +58,7 @@ public class CreateBookmarkFolder extends DialogFragment { // `@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) { // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java index 9f47d465..6159f8da 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java @@ -21,24 +21,26 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.support.annotation.NonNull; // If we don't use android.support.v7.app.AlertDialog instead of android.app.AlertDialog then the dialog will be covered by the keyboard. import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.EditText; -public class CreateHomeScreenShortcut extends DialogFragment { +public class CreateHomeScreenShortcut extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateHomeScreenSchortcutListener { - void onCreateHomeScreenShortcut(DialogFragment dialogFragment); + void onCreateHomeScreenShortcut(AppCompatDialogFragment dialogFragment); } //`createHomeScreenShortcutListener` is used in `onAttach()` and `onCreateDialog()`. @@ -57,6 +59,7 @@ public class CreateHomeScreenShortcut extends DialogFragment { // `@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) { // Get the activity's layout inflater. LayoutInflater layoutInflater = getActivity().getLayoutInflater(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java index 0a1d1dca..1a3b76da 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java +++ b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java @@ -21,13 +21,15 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; // `android.support.v7.app.AlertDialog` uses more of the horizontal screen real estate versus `android.app.AlertDialog's` smaller width. import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -37,7 +39,7 @@ import android.widget.TextView; import java.util.Locale; -public class DownloadFile extends DialogFragment { +public class DownloadFile extends AppCompatDialogFragment { private String downloadUrl; private String downloadFileName; @@ -87,7 +89,7 @@ public class DownloadFile extends DialogFragment { // The public interface is used to send information back to the parent activity. public interface DownloadFileListener { - void onDownloadFile(DialogFragment dialogFragment, String downloadUrl); + void onDownloadFile(AppCompatDialogFragment dialogFragment, String downloadUrl); } // `downloadFileListener` is used in `onAttach()` and `onCreateDialog()`. @@ -107,6 +109,7 @@ public class DownloadFile extends DialogFragment { // `@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) { // Get the activity's layout inflater. LayoutInflater layoutInflater = getActivity().getLayoutInflater(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java index e42fc0e3..3ce8204d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java @@ -21,7 +21,6 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.database.Cursor; @@ -29,17 +28,20 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; // If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. +import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; -public class EditBookmark extends DialogFragment { +public class EditBookmark extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface EditBookmarkListener { - void onSaveEditBookmark(DialogFragment dialogFragment); + void onSaveEditBookmark(AppCompatDialogFragment dialogFragment); } // `editBookmarkListener` is used in `onAttach()` and `onCreateDialog()` @@ -59,6 +61,7 @@ public class EditBookmark extends DialogFragment { // `@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) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. long[] selectedBookmarkLongArray = BookmarksActivity.checkedItemIds; diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java index 218023fd..c04012b9 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java +++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java @@ -21,25 +21,27 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; +import android.support.annotation.NonNull; // If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. import android.support.v7.app.AlertDialog; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; -public class EditBookmarkFolder extends DialogFragment { +public class EditBookmarkFolder extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface EditBookmarkFolderListener { - void onSaveEditBookmarkFolder(DialogFragment dialogFragment); + void onSaveEditBookmarkFolder(AppCompatDialogFragment dialogFragment); } // `editFolderListener` is used in `onAttach()` and `onCreateDialog`. @@ -59,6 +61,7 @@ public class EditBookmarkFolder extends DialogFragment { // `@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) { // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`. long[] selectedBookmarkLongArray = BookmarksActivity.checkedItemIds; diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index 7872677d..2a2e14f0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -49,6 +49,7 @@ import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.AppCompatDialogFragment; import android.support.v7.widget.Toolbar; import android.util.Patterns; import android.view.KeyEvent; @@ -354,8 +355,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { // Show the `DownloadFile` `AlertDialog` and name this instance `@string/download`. - DialogFragment downloadFileDialogFragment = DownloadFile.fromUrl(url, contentDisposition, contentLength); - downloadFileDialogFragment.show(getFragmentManager(), getResources().getString(R.string.download)); + AppCompatDialogFragment downloadFileDialogFragment = DownloadFile.fromUrl(url, contentDisposition, contentLength); + downloadFileDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.download)); } }); @@ -751,8 +752,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation case R.id.addToHomescreen: // Show the `CreateHomeScreenShortcut` `AlertDialog` and name this instance `@string/create_shortcut`. - DialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcut(); - createHomeScreenShortcutDialogFragment.show(getFragmentManager(), getResources().getString(R.string.create_shortcut)); + AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcut(); + createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.create_shortcut)); //Everything else will be handled by `CreateHomeScreenShortcut` and the associated listener below. return true; @@ -909,7 +910,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } @Override - public void onCreateHomeScreenShortcut(DialogFragment dialogFragment) { + public void onCreateHomeScreenShortcut(AppCompatDialogFragment dialogFragment) { // Get shortcutNameEditText from the alert dialog. EditText shortcutNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.shortcut_name_edittext); @@ -928,7 +929,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } @Override - public void onDownloadFile(DialogFragment dialogFragment, String downloadUrl) { + public void onDownloadFile(AppCompatDialogFragment dialogFragment, String downloadUrl) { DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(downloadUrl)); @@ -936,9 +937,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation EditText downloadFileNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.download_file_name); String fileName = downloadFileNameEditText.getText().toString(); - // Set the download save in the the `DIRECTORY_DOWNLOADS`using `fileName`. // Once we have `WRITE_EXTERNAL_STORAGE` permissions we can use `setDestinationInExternalPublicDir`. - downloadRequest.setDestinationInExternalFilesDir(this, "/", fileName); + if (Build.VERSION.SDK_INT >= 23) { // If API >= 23, set the download save in the the `DIRECTORY_DOWNLOADS` using `fileName`. + downloadRequest.setDestinationInExternalFilesDir(this, "/", fileName); + } else { // Only set the title using `fileName`. + downloadRequest.setTitle(fileName); + } // Allow `MediaScanner` to index the download if it is a media file. downloadRequest.allowScanningByMediaScanner(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java b/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java index 66e81253..60f7707f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MoveToFolder.java @@ -21,7 +21,6 @@ package com.stoutner.privacybrowser; import android.annotation.SuppressLint; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.database.Cursor; @@ -33,9 +32,12 @@ import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.support.annotation.NonNull; // If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. import android.support.v4.content.ContextCompat; +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatDialogFragment; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; @@ -45,10 +47,10 @@ import android.widget.TextView; import java.io.ByteArrayOutputStream; -public class MoveToFolder extends DialogFragment { +public class MoveToFolder extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface MoveToFolderListener { - void onMoveToFolder(DialogFragment dialogFragment); + void onMoveToFolder(AppCompatDialogFragment dialogFragment); } // `moveToFolderListener` is used in `onAttach()` and `onCreateDialog`. @@ -71,6 +73,7 @@ public class MoveToFolder extends DialogFragment { // `@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) { // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); -- 2.45.2