]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt
Implement selecting bookmark favorite icons from the file system. https://redmine...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / views / NestedScrollWebView.kt
index cd103e7a6952b1cbbd1622fbcafe9befeb93adbf..6076950291c304e74fa75d0326913973da8c1984 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2019-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/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 {