X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FCreateBookmarkDialog.java;h=6d4e84e65a18d08ad2cbff2e13c5b6cefb7efcc9;hb=84989e138cb593d5a2f70be848db4889aaa8da88;hp=caadd02a34afd00e65184642f2d61d884afc5d1c;hpb=0a5d2eabceeafb49a957598538aa74d4f11dfce0;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java index caadd02a..6d4e84e6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2018 Soren Stoutner . + * Copyright © 2016-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -24,24 +24,25 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.NonNull; -// 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 androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22. + import com.stoutner.privacybrowser.activities.MainWebViewActivity; import com.stoutner.privacybrowser.R; -public class CreateBookmarkDialog extends AppCompatDialogFragment { +public class CreateBookmarkDialog extends DialogFragment { // The public interface is used to send information back to the parent activity. public interface CreateBookmarkListener { - void onCreateBookmark(AppCompatDialogFragment dialogFragment); + void onCreateBookmark(DialogFragment dialogFragment); } // `createBookmarkListener` is used in `onAttach()` and `onCreateDialog()` @@ -51,12 +52,8 @@ public class CreateBookmarkDialog extends AppCompatDialogFragment { public void onAttach(Context context) { super.onAttach(context); - // Get a handle for `CreateBookmarkListener` from `context`. - try { - createBookmarkListener = (CreateBookmarkListener) context; - } catch(ClassCastException exception) { - throw new ClassCastException(context.toString() + " must implement `CreateBookmarkListener`."); - } + // Get a handle for `CreateBookmarkListener` from the launching context. + createBookmarkListener = (CreateBookmarkListener) context; } // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. @@ -64,10 +61,18 @@ public class CreateBookmarkDialog extends AppCompatDialogFragment { @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { + // Get a copy of the favorite icon bitmap. + Bitmap favoriteIconBitmap = MainWebViewActivity.favoriteIconBitmap; + + // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation. + if ((favoriteIconBitmap.getHeight() > 256) || (favoriteIconBitmap.getWidth() > 256)) { + favoriteIconBitmap = Bitmap.createScaledBitmap(favoriteIconBitmap, 256, 256, true); + } + // Create a drawable version of the favorite icon. - Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIconBitmap); + Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), favoriteIconBitmap); - // 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. @@ -112,7 +117,7 @@ public class CreateBookmarkDialog extends AppCompatDialogFragment { // Show the keyboard when the `AlertDialog` is displayed on the screen. alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); - // The `AlertDialog` needs to be shown before `setOnKeyListener()` can be called. + // The alert dialog needs to be shown before `setOnKeyListener()` can be called. alertDialog.show(); // Get a handle for `create_bookmark_name_edittext`. @@ -159,7 +164,7 @@ public class CreateBookmarkDialog extends AppCompatDialogFragment { } }); - // `onCreateDialog()` requires the return of an `AlertDialog`. + // Return the alert dialog. return alertDialog; } } \ No newline at end of file