} 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));
@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));
// 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();
// 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));
// 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));
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);
// 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());
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)
/*
- * Copyright © 2019-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2019-2022 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
*
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
// 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 = ""
// 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.
}
}
- 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() {
// Dispatch a nested fling with the specified velocity.
return nestedScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed)
}
-}
\ No newline at end of file
+}
<string name="form_data_deleted">Données de formulaires supprimées</string>
<string name="open_navigation_drawer">Ouvrir le panneau de navigation</string>
<string name="close_navigation_drawer">Fermer le panneau de navigation</string>
- <string name="unrecognized_url">URL inconnue:</string>
+ <string name="pin_drawer">Épingler le panneau</string>
+ <string name="unrecognized_url">URL inconnue :</string>
<string name="add_tab">Ajouter un onglet</string>
<string name="close_tab">Fermer l\'onglet</string>
<string name="new_tab">Nouvel onglet</string>
<string name="close">Fermer</string>
<string name="domain">Domaine</string>
<string name="domain_label">Domaine :</string>
- <string name="ip_addresses">Addresse(s) IP:</string>
+ <string name="ip_addresses">Addresse(s) IP :</string>
<string name="issued_to">Delivré à</string>
<string name="issued_by">Délivré par</string>
- <string name="common_name">Nom courant (CN):</string>
- <string name="organization">Organisation (O):</string>
- <string name="organizational_unit">Unité Organisationelle (OU):</string>
+ <string name="common_name">Nom courant (CN) :</string>
+ <string name="organization">Organisation (O) :</string>
+ <string name="organizational_unit">Unité Organisationelle (OU) :</string>
<string name="valid_dates">Dates de validités</string>
- <string name="start_date">Début:</string>
- <string name="end_date">Fin:</string>
+ <string name="start_date">Début :</string>
+ <string name="end_date">Fin :</string>
<!-- SSL Certificate Error. -->
<string name="ssl_certificate_error">Erreur de certificat SSL</string>
<string name="file_is_mht">Le fichier est une archive web MHT.</string>
<string name="mht_checkbox_explanation">Parfois, les archives web MHT (MIME Encapsulated HTML) doivent être spécifiées manuellement pour être ouvertes correctement.</string>
- <!-- Save Dialog. Android removes double spaces, but extra spaces can be manually specified with the Unicode `\u0020` formatting.
- The `%*$s` code inserts variables into the displayed text and should be preserved in translation. <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
+ <!-- Save Dialog. The `%*$s` code inserts variables into the displayed text and should be preserved in translation. <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
<string name="save_url">Enregistrer l\'URL</string>
<string name="save_archive">Enregistrer l\'archive</string>
<string name="save_text">Sauvegarder le texte</string>
<string name="unknown_size">taille inconnue</string>
<string name="invalid_url">URL invalide</string>
<string name="saving_file">Enregistrement du fichier :</string>
- <string name="processing_image">Traitement de l\'image: \u0020 %1$s</string>
- <string name="error_saving_file">Erreur lors de l\'enregistrement de %1$s: \u0020 %2$s</string>
+ <string name="processing_image">Traitement de l\'image : %1$s</string>
+ <string name="error_saving_file">Erreur lors de l\'enregistrement de %1$s : %2$s</string>
<string name="unknown_error">Erreur inconnue</string>
<!-- View Source. -->
<string name="saved_ip_addresses">Adresse(s) IP sauvegardée(s)</string>
<string name="current_ip_addresses">Adresse(s) IP courante(s)</string>
- <!-- Import/Export. Android removes double spaces, but extra spaces can be manually specified with the Unicode `\u0020` formatting.
- The `%1$s` code inserts variables into the displayed text and should be preserved in translation. <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
+ <!-- Import/Export. The `%1$s` code inserts variables into the displayed text and should be preserved in translation. <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
<string name="encryption">Chiffrement</string>
<string-array name="encryption_type">
<item>Aucun</item>
<string name="export_failed">L\'export a échoué : %1$s</string>
<string name="import_failed">L\'import a échoué : %1$s</string>
- <!-- Logcat. Android removes double spaces, but extra spaces can be manually specified with the Unicode `\u0020` formatting.
- The `%1$s` code inserts variables into the displayed text and should be preserved in translation. <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
+ <!-- Logcat. The `%1$s` code inserts variables into the displayed text and should be preserved in translation. <https://developer.android.com/reference/kotlin/java/util/Formatter> -->
<string name="copy_string">Copie</string>
<string name="clear">Vider</string>
<string name="logcat_copied">Journal système copié.</string>
<string name="privacy_browser_logcat_txt">Privacy Browser %1$s Logcat.txt</string>
<string name="saved">%1$s sauvegardé.</string>
- <string name="error_saving_logcat">Erreur de sauvegarde du logcat: \u0020 %1$s</string>
+ <string name="error_saving_logcat">Erreur de sauvegarde du logcat : %1$s</string>
<!-- Guide. -->
<string name="overview">Présentation</string>