import java.io.ByteArrayOutputStream;
public class CreateHomeScreenShortcutDialog extends DialogFragment {
import java.io.ByteArrayOutputStream;
public class CreateHomeScreenShortcutDialog extends DialogFragment {
- // Create the class variables.
- private String initialShortcutName;
- private String initialUrlString;
- private Bitmap favoriteIconBitmap;
+ // Define the class variables.
private EditText shortcutNameEditText;
private EditText urlEditText;
private RadioButton openWithPrivacyBrowserRadioButton;
private EditText shortcutNameEditText;
private EditText urlEditText;
private RadioButton openWithPrivacyBrowserRadioButton;
public static CreateHomeScreenShortcutDialog createDialog(String shortcutName, String urlString, Bitmap favoriteIconBitmap) {
// Create a favorite icon byte array output stream.
public static CreateHomeScreenShortcutDialog createDialog(String shortcutName, String urlString, Bitmap favoriteIconBitmap) {
// Create a favorite icon byte array output stream.
// Get the arguments.
Bundle arguments = getArguments();
// Remove the incorrect lint warning below that the arguments might be null.
assert arguments != null;
// Get the arguments.
Bundle arguments = getArguments();
// Remove the incorrect lint warning below that the arguments might be null.
assert arguments != null;
- // Store the strings in class variables.
- initialShortcutName = arguments.getString("shortcut_name");
- initialUrlString = arguments.getString("url_string");
+ // Get the strings from the arguments.
+ String initialShortcutName = arguments.getString("shortcut_name");
+ String initialUrlString = arguments.getString("url_string");
// Get the favorite icon byte array.
byte[] favoriteIconByteArray = arguments.getByteArray("favorite_icon_byte_array");
// Get the favorite icon byte array.
byte[] favoriteIconByteArray = arguments.getByteArray("favorite_icon_byte_array");
assert favoriteIconByteArray != null;
// Convert the favorite icon byte array to a bitmap and store it in a class variable.
assert favoriteIconByteArray != null;
// Convert the favorite icon byte array to a bitmap and store it in a class variable.
- favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
- }
+ Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
// Get a handle for the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
// Get a handle for the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
// Set an `onClick` listener on the create button.
dialogBuilder.setPositiveButton(R.string.create, (DialogInterface dialog, int which) -> {
// Create the home screen shortcut.
// Set an `onClick` listener on the create button.
dialogBuilder.setPositiveButton(R.string.create, (DialogInterface dialog, int which) -> {
// Create the home screen shortcut.
shortcutNameEditText = alertDialog.findViewById(R.id.shortcut_name_edittext);
urlEditText = alertDialog.findViewById(R.id.url_edittext);
openWithPrivacyBrowserRadioButton = alertDialog.findViewById(R.id.open_with_privacy_browser_radiobutton);
shortcutNameEditText = alertDialog.findViewById(R.id.shortcut_name_edittext);
urlEditText = alertDialog.findViewById(R.id.url_edittext);
openWithPrivacyBrowserRadioButton = alertDialog.findViewById(R.id.open_with_privacy_browser_radiobutton);
// Check the status of the create button.
if (createButton.isEnabled()) { // The create button is enabled.
// Create the home screen shortcut.
// Check the status of the create button.
if (createButton.isEnabled()) { // The create button is enabled.
// Create the home screen shortcut.
// Check the status of the create button.
if (createButton.isEnabled()) { // The create button is enabled.
// Create the home screen shortcut.
// Check the status of the create button.
if (createButton.isEnabled()) { // The create button is enabled.
// Create the home screen shortcut.
// Get the contents of the edit texts.
String shortcutName = shortcutNameEditText.getText().toString();
String urlString = urlEditText.getText().toString();
// Get the contents of the edit texts.
String shortcutName = shortcutNameEditText.getText().toString();
String urlString = urlEditText.getText().toString();