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.
/*
- * 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>.
*
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]
//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")) {
Snackbar.make(swipeRefreshLayout, errorString, Snackbar.LENGTH_LONG).show()
}
}
- })
+ }
// Implement swipe to refresh.
swipeRefreshLayout.setOnRefreshListener {
responseBodyTitleTextView.setText(R.string.response_body)
}
}
-}
\ No newline at end of file
+}
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;
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
/*
- * 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>.
*
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
// 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()
}
}
}
-}
\ No newline at end of file
+}