X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fcoroutines%2FSaveWebpageImageCoroutine.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fcoroutines%2FSaveWebpageImageCoroutine.kt;h=d6c984625ccf3233a0d00eea0b6d6820ca7bee7c;hp=1c3a2c0310104f0f1d876f9aa22974bf8bb1fae9;hb=e065315a36c804626a7dba38d3edad05e9fdb473;hpb=7a54e6907e74196a4840a2434dd13e2b68a95db4 diff --git a/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveWebpageImageCoroutine.kt b/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveWebpageImageCoroutine.kt index 1c3a2c03..d6c98462 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveWebpageImageCoroutine.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveWebpageImageCoroutine.kt @@ -1,5 +1,5 @@ /* - * Copyright0 2019-2023 Soren Stoutner . + * Copyright0 2019-2024 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -23,7 +23,6 @@ import android.app.Activity import android.graphics.Bitmap import android.graphics.Canvas import android.net.Uri -import android.os.Build import android.provider.OpenableColumns import com.google.android.material.snackbar.Snackbar @@ -42,26 +41,17 @@ class SaveWebpageImageCoroutine { fun save(activity: Activity, fileUri: Uri, nestedScrollWebView: NestedScrollWebView) { // Use a coroutine to save the webpage image. CoroutineScope(Dispatchers.Main).launch { - // Create a file name string. - val fileNameString: String + // Get a cursor from the content resolver. + val contentResolverCursor = activity.contentResolver.query(fileUri, null, null, null) - // Query the exact file name if the API >= 26. - if (Build.VERSION.SDK_INT >= 26) { - // Get a cursor from the content resolver. - val contentResolverCursor = activity.contentResolver.query(fileUri, null, null, null) + // Move to the first row. + contentResolverCursor!!.moveToFirst() - // Move to the first row. - contentResolverCursor!!.moveToFirst() + // Get the file name from the cursor. + val fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) - // Get the file name from the cursor. - fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) - - // Close the cursor. - contentResolverCursor.close() - } else { - // Use the file URI last path segment as the file name string. - fileNameString = fileUri.lastPathSegment!! - } + // Close the cursor. + contentResolverCursor.close() // Create a saving image snackbar. val savingImageSnackbar = Snackbar.make(nestedScrollWebView, activity.getString(R.string.processing_image, fileNameString), Snackbar.LENGTH_INDEFINITE) @@ -69,7 +59,8 @@ class SaveWebpageImageCoroutine { // Display the saving image snackbar. savingImageSnackbar.show() - // Create a webpage bitmap. Once the Minimum API >= 26 Bitmap.Config.RBGA_F16 can be used instead of ARGB_8888. The nested scroll WebView commands must be run on the UI thread. + // Create a webpage bitmap. Once the Minimum API >= 33 Bitmap.Config.RGBA_1010102 can be used instead of ARGB_8888. + // RGBA_F16 can't be used because it produces black output for the part of page not currently visible on the screen. val webpageBitmap = Bitmap.createBitmap(nestedScrollWebView.getHorizontalScrollRange(), nestedScrollWebView.getVerticalScrollRange(), Bitmap.Config.ARGB_8888) // Create a canvas. @@ -115,8 +106,7 @@ class SaveWebpageImageCoroutine { Snackbar.make(nestedScrollWebView, activity.getString(R.string.error_saving_file, fileNameString, exception), Snackbar.LENGTH_INDEFINITE).show() } } - } } } -} \ No newline at end of file +}