TP-75758 | Pixelcopy no backing surface fixe (#225)

This commit is contained in:
Sayed Owais Ali
2024-08-23 16:23:24 +05:30
committed by GitHub
parent 8c21eed94e
commit ad2f94df9b
2 changed files with 22 additions and 17 deletions

View File

@@ -33,7 +33,7 @@ fun getScreenShotUsingPixelCopy(
bitmapForBackground: Bitmap? = null,
canvas: Canvas
) {
if (isViewCaptureNotReady(activity, view)) return
if (!isViewCaptureReady(activity, view)) return
val captureWindow =
if (isBottomSheet == false) {
@@ -42,7 +42,7 @@ fun getScreenShotUsingPixelCopy(
AlfredManager.dialog?.window
}
if (isWindowCaptureNotReady(captureWindow)) return
if (!isWindowCaptureReady(captureWindow)) return
val handlerThread = HandlerThread("PixelCopyThread")
handlerThread.start()
@@ -96,8 +96,10 @@ fun getScreenShotUsingPixelCopy(
)
}
}
} catch (e: IllegalArgumentException) {
e.log()
} catch (e: Exception) {
if (e.message?.contains("Window doesn't have a backing surface!") != true) {
e.log()
}
}
}
}

View File

@@ -17,6 +17,7 @@ import android.os.Build
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import com.navi.alfred.AlfredManager
import com.navi.alfred.db.AlfredDatabaseHelper
@@ -342,19 +343,21 @@ internal fun isResolutionEven(width: Int, height: Int): Boolean {
return width.mod(2) == 0 && height.mod(2) == 0
}
internal fun isViewCaptureNotReady(activity: Activity?, view: View): Boolean {
return activity == null ||
!view.isVisible ||
!view.isAttachedToWindow ||
view.width == 0 ||
view.height == 0 ||
activity.isFinishing ||
activity.isDestroyed
internal fun isViewCaptureReady(activity: Activity?, view: View): Boolean {
return activity != null &&
view.isVisible &&
view.isAttachedToWindow &&
view.width != 0 &&
view.height != 0 &&
!activity.isFinishing &&
!activity.isDestroyed
}
internal fun isWindowCaptureNotReady(window: Window?): Boolean {
return window == null ||
window.decorView.width == 0 ||
window.decorView.height == 0 ||
window.peekDecorView() == null
internal fun isWindowCaptureReady(window: Window?): Boolean {
return window != null &&
window.decorView.width != 0 &&
window.decorView.height != 0 &&
window.peekDecorView() != null &&
window.isActive &&
ViewCompat.isLaidOut(window.decorView)
}