]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Use a coroutine to compress the bitmap in MoveToFolderDialog. https://redmine.stoutne...
authorSoren Stoutner <soren@stoutner.com>
Fri, 4 Nov 2022 00:13:41 +0000 (17:13 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 4 Nov 2022 00:13:41 +0000 (17:13 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/activities/ViewSourceActivity.kt
app/src/main/java/com/stoutner/privacybrowser/backgroundtasks/GetSourceBackgroundTask.java
app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolderDialog.kt

index fd1904422b87d0e596f699af200f1f3d7e6400c0..a21848a5ed5530e135fdfd2ca2206a89aec71a18 100644 (file)
@@ -190,9 +190,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         WebViewTabFragment.NewTabListener {
 
     // Define the public static variables.
-    public static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    public static final ExecutorService executorService = Executors.newFixedThreadPool(4);
     public static String orbotStatus = "unknown";
-    public static ArrayList<PendingDialog> pendingDialogsArrayList =  new ArrayList<>();
+    public static final ArrayList<PendingDialog> pendingDialogsArrayList =  new ArrayList<>();
     public static String proxyMode = ProxyHelper.NONE;
 
     // Declare the public static variables.
index 691ff17fc1f7f75d97c5a252c45a3445877ccfa0..3769a6820448a37053a785aa307e6396eb6b8722 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2017-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2017-2022 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -274,10 +274,10 @@ class ViewSourceActivity: AppCompatActivity(), UntrustedSslCertificateListener {
         val webViewSourceFactory: ViewModelProvider.Factory = WebViewSourceFactory(currentUrl, userAgent, localeString, proxy, contentResolver, MainWebViewActivity.executorService)
 
         // Instantiate the WebView source view model class.
-        webViewSource = ViewModelProvider(this, webViewSourceFactory).get(WebViewSource::class.java)
+        webViewSource = ViewModelProvider(this, webViewSourceFactory)[WebViewSource::class.java]
 
         // Create a source observer.
-        webViewSource.observeSource().observe(this, { sourceStringArray: Array<SpannableStringBuilder> ->
+        webViewSource.observeSource().observe(this) { sourceStringArray: Array<SpannableStringBuilder> ->
             // Populate the text views.  This can take a long time, and freezes the user interface, if the response body is particularly large.
             requestHeadersTextView.text = sourceStringArray[0]
             responseMessageTextView.text = sourceStringArray[1]
@@ -290,10 +290,10 @@ class ViewSourceActivity: AppCompatActivity(), UntrustedSslCertificateListener {
 
             //Stop the swipe to refresh indicator if it is running
             swipeRefreshLayout.isRefreshing = false
-        })
+        }
 
         // Create an error observer.
-        webViewSource.observeErrors().observe(this, { errorString: String ->
+        webViewSource.observeErrors().observe(this) { errorString: String ->
             // Display an error snackbar if the string is not `""`.
             if (errorString != "") {
                 if (errorString.startsWith("javax.net.ssl.SSLHandshakeException")) {
@@ -307,7 +307,7 @@ class ViewSourceActivity: AppCompatActivity(), UntrustedSslCertificateListener {
                     Snackbar.make(swipeRefreshLayout, errorString, Snackbar.LENGTH_LONG).show()
                 }
             }
-        })
+        }
 
         // Implement swipe to refresh.
         swipeRefreshLayout.setOnRefreshListener {
@@ -472,4 +472,4 @@ class ViewSourceActivity: AppCompatActivity(), UntrustedSslCertificateListener {
             responseBodyTitleTextView.setText(R.string.response_body)
         }
     }
-}
\ No newline at end of file
+}
index d9da8bcc407623e50c8b3e11ff9a3fc3cda097cc..a50f3dfc1287dd9fa14a17195b6bb17a2ed7f4a3 100644 (file)
@@ -24,7 +24,6 @@ import android.content.ContentResolver;
 import android.database.Cursor;
 import android.graphics.Typeface;
 import android.net.Uri;
-import android.os.Build;
 import android.text.SpannableStringBuilder;
 import android.text.Spanned;
 import android.text.style.StyleSpan;
@@ -233,8 +232,9 @@ public class GetSourceBackgroundTask {
                         return true;
                     };
 
-                    // Create a new trust manager.
-                    TrustManager[] trustManager = new TrustManager[] {
+                    // Create a new trust manager.  Lint wants to warn us that it is hard to securely implement an X509 trust manager.
+                    // But the point of this trust manager is that it should accept all certificates no matter what, so that isn't an issue in our case.
+                    @SuppressLint("CustomX509TrustManager") TrustManager[] trustManager = new TrustManager[] {
                             new X509TrustManager() {
                                 @SuppressLint("TrustAllX509TrustManager")
                                 @Override
index 101e6b3256585fb1344bf703e3130d241a28779d..0b8891f5d83f4493b7ee12a4409485dee4dbdb52 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2016-2022 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -48,6 +48,11 @@ import androidx.preference.PreferenceManager
 import com.stoutner.privacybrowser.R
 import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper
 
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+
 import java.io.ByteArrayOutputStream
 import java.lang.StringBuilder
 
@@ -188,8 +193,13 @@ class MoveToFolderDialog : DialogFragment() {
             // Create a home folder icon byte array output stream.
             val homeFolderIconByteArrayOutputStream = ByteArrayOutputStream()
 
-            // Convert the home folder bitmap to a byte array.  `0` is for lossless compression (the only option for a PNG).
-            homeFolderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, homeFolderIconByteArrayOutputStream)
+            // Compress the bitmap using a coroutine with Dispatchers.Default.
+            CoroutineScope(Dispatchers.Main).launch {
+                withContext(Dispatchers.Default) {
+                    // Convert the home folder bitmap to a byte array.  `0` is for lossless compression (the only option for a PNG).
+                    homeFolderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, homeFolderIconByteArrayOutputStream)
+                }
+            }
 
             // Convert the home folder icon byte array output stream to a byte array.
             val homeFolderIconByteArray = homeFolderIconByteArrayOutputStream.toByteArray()
@@ -311,4 +321,4 @@ class MoveToFolderDialog : DialogFragment() {
             }
         }
     }
-}
\ No newline at end of file
+}