From: Soren Stoutner Date: Wed, 14 Dec 2022 19:36:26 +0000 (-0700) Subject: Don't replace a high resolution favorite icon with a lower resolution one. https... X-Git-Tag: v3.13~6 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=851453e788404e4275809f34f199d0c3023ca4ea;p=PrivacyBrowserAndroid.git Don't replace a high resolution favorite icon with a lower resolution one. https://redmine.stoutner.com/issues/947 --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 649cf644..0f412f01 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -1870,7 +1870,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } else if (menuItemId == R.id.add_to_homescreen) { // Add to homescreen. // Instantiate the create home screen shortcut dialog. DialogFragment createHomeScreenShortcutDialogFragment = CreateHomeScreenShortcutDialog.createDialog(currentWebView.getTitle(), currentWebView.getUrl(), - currentWebView.getFavoriteOrDefaultIcon()); + currentWebView.getFavoriteIcon()); // Show the create home screen shortcut dialog. createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getString(R.string.create_shortcut)); @@ -3124,7 +3124,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook @Override public void onTabReselected(TabLayout.Tab tab) { // Instantiate the View SSL Certificate dialog. - DialogFragment viewSslCertificateDialogFragment = ViewSslCertificateDialog.displayDialog(currentWebView.getWebViewFragmentId(), currentWebView.getFavoriteOrDefaultIcon()); + DialogFragment viewSslCertificateDialogFragment = ViewSslCertificateDialog.displayDialog(currentWebView.getWebViewFragmentId(), currentWebView.getFavoriteIcon()); // Display the View SSL Certificate dialog. viewSslCertificateDialogFragment.show(getSupportFragmentManager(), getString(R.string.view_ssl_certificate)); @@ -3140,7 +3140,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Set the launch bookmarks activity FAB to launch the bookmarks activity. launchBookmarksActivityFab.setOnClickListener(v -> { // Get a copy of the favorite icon bitmap. - Bitmap favoriteIconBitmap = currentWebView.getFavoriteOrDefaultIcon(); + Bitmap favoriteIconBitmap = currentWebView.getFavoriteIcon(); // Create a favorite icon byte array output stream. ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); @@ -3167,7 +3167,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Set the create new bookmark folder FAB to display an alert dialog. createBookmarkFolderFab.setOnClickListener(v -> { // Create a create bookmark folder dialog. - DialogFragment createBookmarkFolderDialog = CreateBookmarkFolderDialog.createBookmarkFolder(currentWebView.getFavoriteOrDefaultIcon()); + DialogFragment createBookmarkFolderDialog = CreateBookmarkFolderDialog.createBookmarkFolder(currentWebView.getFavoriteIcon()); // Show the create bookmark folder dialog. createBookmarkFolderDialog.show(getSupportFragmentManager(), getString(R.string.create_folder)); @@ -3176,7 +3176,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Set the create new bookmark FAB to display an alert dialog. createBookmarkFab.setOnClickListener(view -> { // Instantiate the create bookmark dialog. - DialogFragment createBookmarkDialog = CreateBookmarkDialog.createBookmark(currentWebView.getUrl(), currentWebView.getTitle(), currentWebView.getFavoriteOrDefaultIcon()); + DialogFragment createBookmarkDialog = CreateBookmarkDialog.createBookmark(currentWebView.getUrl(), currentWebView.getTitle(), currentWebView.getFavoriteIcon()); // Display the create bookmark dialog. createBookmarkDialog.show(getSupportFragmentManager(), getString(R.string.create_bookmark)); @@ -3599,7 +3599,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook TextView tabTitleTextView = tabCustomView.findViewById(R.id.title_textview); // Set the default favorite icon as the favorite icon for this tab. - tabFavoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(nestedScrollWebView.getFavoriteOrDefaultIcon(), 64, 64, true)); + tabFavoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(nestedScrollWebView.getFavoriteIcon(), 64, 64, true)); // Set the loading title text. tabTitleTextView.setText(R.string.loading); @@ -5232,10 +5232,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Set the favorite icon when it changes. @Override public void onReceivedIcon(WebView view, Bitmap icon) { - // Only update the favorite icon if the website has finished loading. - if (progressBar.getVisibility() == View.GONE) { + // Only update the favorite icon if the website has finished loading and the new favorite icon height is greater than the current favorite icon height. This prevents low resolution icons from replacing high resolution one. + if ((progressBar.getVisibility() == View.GONE) && (icon.getHeight() > nestedScrollWebView.getFavoriteIconHeight())) { // Store the new favorite icon. - nestedScrollWebView.setFavoriteOrDefaultIcon(icon); + nestedScrollWebView.setFavoriteIcon(icon); // Get the current page position. int currentPosition = webViewPagerAdapter.getPositionForId(nestedScrollWebView.getWebViewFragmentId()); diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/PinnedMismatchDialog.kt b/app/src/main/java/com/stoutner/privacybrowser/dialogs/PinnedMismatchDialog.kt index b3f6de21..97cd63d0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/PinnedMismatchDialog.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/PinnedMismatchDialog.kt @@ -102,7 +102,7 @@ class PinnedMismatchDialog : DialogFragment() { val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog) // Get the favorite icon. - val favoriteIconBitmap = nestedScrollWebView.getFavoriteOrDefaultIcon() + val favoriteIconBitmap = nestedScrollWebView.getFavoriteIcon() // Get the default favorite icon drawable. `ContextCompat` must be used until API >= 21. val defaultFavoriteIconDrawable = ContextCompat.getDrawable(requireContext(), R.drawable.world) diff --git a/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt b/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt index ad34be83..eafe10fe 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2019-2022 Soren Stoutner . + * Copyright 2019-2022 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -31,7 +31,7 @@ import android.webkit.HttpAuthHandler import android.webkit.SslErrorHandler import android.webkit.WebView -import androidx.core.content.ContextCompat +import androidx.appcompat.content.res.AppCompatResources.getDrawable import androidx.core.view.NestedScrollingChild2 import androidx.core.view.NestedScrollingChildHelper import androidx.core.view.ViewCompat @@ -117,7 +117,8 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS // Define the private variables. private val nestedScrollingChildHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this) - private lateinit var favoriteOrDefaultIcon: Bitmap + private lateinit var favoriteIcon: Bitmap + private var favoriteIconHeight = 0 private var previousYPosition = 0 // The previous Y position needs to be tracked between motion events. private var hasPinnedSslCertificate = false private var pinnedSslIssuedToCName = "" @@ -149,19 +150,25 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS // Favorite or default icon. fun initializeFavoriteIcon() { - // Get the default favorite icon drawable. `ContextCompat` must be used until API >= 21. - val favoriteIconDrawable = ContextCompat.getDrawable(context, R.drawable.world) + // Get the default favorite icon drawable. + val favoriteIconDrawable = getDrawable(context, R.drawable.world) // Cast the favorite icon drawable to a bitmap drawable. val favoriteIconBitmapDrawable = (favoriteIconDrawable as BitmapDrawable?)!! // Store the default icon bitmap. - favoriteOrDefaultIcon = favoriteIconBitmapDrawable.bitmap + favoriteIcon = favoriteIconBitmapDrawable.bitmap + + // Set the favorite icon height to be 0. This way any favorite icons presented by the website will overwrite it. + favoriteIconHeight = 0 } - fun setFavoriteOrDefaultIcon(icon: Bitmap) { + fun setFavoriteIcon(icon: Bitmap) { + // Store the current favorite icon height. + favoriteIconHeight = icon.height + // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation. - favoriteOrDefaultIcon = if (icon.height > 256 || icon.width > 256) { + favoriteIcon = if (icon.height > 256 || icon.width > 256) { Bitmap.createScaledBitmap(icon, 256, 256, true) } else { // Store the icon as presented. @@ -169,11 +176,15 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS } } - fun getFavoriteOrDefaultIcon(): Bitmap { - // Return the favorite or default icon. This is the only way to return a non-nullable variable while retaining the custom initialization and setter functions above. - return favoriteOrDefaultIcon + fun getFavoriteIcon(): Bitmap { + // Return the favorite icon. This is the only way to return a non-nullable variable while retaining the custom initialization and setter functions above. + return favoriteIcon } + fun getFavoriteIconHeight(): Int { + // Return the favorite icon height. + return favoriteIconHeight + } // Reset the handlers. fun resetSslErrorHandler() { @@ -540,4 +551,4 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS // Dispatch a nested fling with the specified velocity. return nestedScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed) } -} \ No newline at end of file +} diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 476012b1..b7aba539 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -43,7 +43,8 @@ Données de formulaires supprimées Ouvrir le panneau de navigation Fermer le panneau de navigation - URL inconnue: + Épingler le panneau + URL inconnue : Ajouter un onglet Fermer l\'onglet Nouvel onglet @@ -72,15 +73,15 @@ Fermer Domaine Domaine : - Addresse(s) IP: + Addresse(s) IP : Delivré à Délivré par - Nom courant (CN): - Organisation (O): - Unité Organisationelle (OU): + Nom courant (CN) : + Organisation (O) : + Unité Organisationelle (OU) : Dates de validités - Début: - Fin: + Début : + Fin : Erreur de certificat SSL @@ -190,8 +191,7 @@ Le fichier est une archive web MHT. Parfois, les archives web MHT (MIME Encapsulated HTML) doivent être spécifiées manuellement pour être ouvertes correctement. - + Enregistrer l\'URL Enregistrer l\'archive Sauvegarder le texte @@ -202,8 +202,8 @@ taille inconnue URL invalide Enregistrement du fichier : - Traitement de l\'image: \u0020 %1$s - Erreur lors de l\'enregistrement de %1$s: \u0020 %2$s + Traitement de l\'image : %1$s + Erreur lors de l\'enregistrement de %1$s : %2$s Erreur inconnue @@ -350,8 +350,7 @@ Adresse(s) IP sauvegardée(s) Adresse(s) IP courante(s) - + Chiffrement Aucun @@ -369,14 +368,13 @@ L\'export a échoué : %1$s L\'import a échoué : %1$s - + Copie Vider Journal système copié. Privacy Browser %1$s Logcat.txt %1$s sauvegardé. - Erreur de sauvegarde du logcat: \u0020 %1$s + Erreur de sauvegarde du logcat : %1$s Présentation