+import java.io.ByteArrayOutputStream;
+
+public class CreateHomeScreenShortcutDialog extends DialogFragment {
+ // Create the class variables.
+ private String initialShortcutName;
+ private String initialUrlString;
+ private Bitmap favoriteIconBitmap;
+ private EditText shortcutNameEditText;
+ private EditText urlEditText;
+ private Button createButton;
+
+ public static CreateHomeScreenShortcutDialog createDialog(String shortcutName, String urlString, Bitmap favoriteIconBitmap) {
+ // Create a favorite icon byte array output stream.
+ ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the favorite icon to a PNG and place it in the byte array output stream. `0` is for lossless compression (the only option for a PNG).
+ favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+
+ // Convert the byte array output stream to a byte array.
+ byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
+
+ // Create a bundle.
+ Bundle bundle = new Bundle();
+
+ // Store the variables in the bundle.
+ bundle.putString("shortcut_name", shortcutName);
+ bundle.putString("url_string", urlString);
+ bundle.putByteArray("favorite_icon_byte_array", favoriteIconByteArray);
+
+ // Create a new instance of the dialog.
+ CreateHomeScreenShortcutDialog createHomeScreenShortcutDialog = new CreateHomeScreenShortcutDialog();
+
+ // Add the bundle to the dialog.
+ createHomeScreenShortcutDialog.setArguments(bundle);
+
+ // Return the new dialog.
+ return createHomeScreenShortcutDialog;