package com.stoutner.privacybrowser;
import android.app.Activity;
-import android.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
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;
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:
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;
@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));
}
});
}
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:
}
@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();
}
@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();
}
@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];
}
@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();
}
@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();
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()`
// `@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);
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`.
// `@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);
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()`.
// `@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();
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;
import java.util.Locale;
-public class DownloadFile extends DialogFragment {
+public class DownloadFile extends AppCompatDialogFragment {
private String downloadUrl;
private String downloadFileName;
// 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()`.
// `@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();
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.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()`
// `@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;
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`.
// `@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;
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;
@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));
}
});
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;
}
@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);
}
@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));
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();
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.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;
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`.
// `@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);