X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fviews%2FNestedScrollWebView.kt;h=6076950291c304e74fa75d0326913973da8c1984;hb=e6befb69eb16e4c633623df508bfb9de370e204f;hp=cd103e7a6952b1cbbd1622fbcafe9befeb93adbf;hpb=2eecbd37661b76d1bcd4020d6218ea6641917527;p=PrivacyBrowserAndroid.git 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 cd103e7a..60769502 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-2023 Soren Stoutner . + * Copyright 2019-2024 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -23,7 +23,7 @@ import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.content.Context import android.graphics.Bitmap -import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable import android.os.Bundle import android.util.AttributeSet import android.view.MotionEvent @@ -31,12 +31,10 @@ import android.webkit.HttpAuthHandler import android.webkit.SslErrorHandler import android.webkit.WebView -import androidx.appcompat.content.res.AppCompatResources.getDrawable import androidx.core.view.NestedScrollingChild2 import androidx.core.view.NestedScrollingChildHelper import androidx.core.view.ViewCompat -import com.stoutner.privacybrowser.R import com.stoutner.privacybrowser.activities.MainWebViewActivity import java.util.Collections @@ -104,6 +102,8 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS var httpAuthHandler: HttpAuthHandler? = null var ignorePinnedDomainInformation = false var pinnedIpAddresses = "" + var previousFavoriteIconDrawable: Drawable? = null + var previousWebpageTitle = "" var sslErrorHandler: SslErrorHandler? = null var swipeToRefresh = false var ultraListEnabled = true @@ -140,19 +140,13 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS nestedScrollingChildHelper.isNestedScrollingEnabled = true // Initialize the favorite icon. - initializeFavoriteIcon() + resetFavoriteIcon() } // Favorite or default icon. - fun initializeFavoriteIcon() { - // 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?)!! - + fun resetFavoriteIcon() { // Store the default icon bitmap. - favoriteIcon = favoriteIconBitmapDrawable.bitmap + favoriteIcon = MainWebViewActivity.defaultFavoriteIconBitmap // Set the favorite icon height to be 0. This way any favorite icons presented by the website will overwrite it. favoriteIconHeight = 0 @@ -162,13 +156,11 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS // 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. - favoriteIcon = if (icon.height > 256 || icon.width > 256) { - Bitmap.createScaledBitmap(icon, 256, 256, true) - } else { - // Store the icon as presented. + // Scale the favorite icon bitmap down if it is larger than 128 in either direction. Filtering uses bilinear interpolation. + favoriteIcon = if (icon.height > 128 || icon.width > 128) // Scale the icon before storing it. + Bitmap.createScaledBitmap(icon, 128, 128, true) + else // Store the icon as presented. icon - } } fun getFavoriteIcon(): Bitmap {