From eb39135adf5f24064c451ad4a7cdda505092ce07 Mon Sep 17 00:00:00 2001 From: xiaojie Date: Fri, 22 Nov 2024 14:36:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E5=A5=94=E6=BA=83=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hippo/app/EditTextDialogBuilder.kt | 4 +- .../hippo/drawable/PreciselyClipDrawable.kt | 5 ++- .../ehviewer/download/DownloadService.kt | 6 ++- .../main/java/com/hippo/lib/image/Image.kt | 43 ++++++++++++------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/hippo/app/EditTextDialogBuilder.kt b/app/src/main/java/com/hippo/app/EditTextDialogBuilder.kt index 25227d586..1b619596b 100644 --- a/app/src/main/java/com/hippo/app/EditTextDialogBuilder.kt +++ b/app/src/main/java/com/hippo/app/EditTextDialogBuilder.kt @@ -61,8 +61,8 @@ class EditTextDialogBuilder @SuppressLint("InflateParams") constructor( return mDialog!! } - override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent): Boolean { - if (mDialog != null) { + override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent?): Boolean { + if (event != null && mDialog != null) { val button = mDialog!!.getButton(DialogInterface.BUTTON_POSITIVE) button?.performClick() return true diff --git a/app/src/main/java/com/hippo/drawable/PreciselyClipDrawable.kt b/app/src/main/java/com/hippo/drawable/PreciselyClipDrawable.kt index 39a547f53..65ba2b865 100644 --- a/app/src/main/java/com/hippo/drawable/PreciselyClipDrawable.kt +++ b/app/src/main/java/com/hippo/drawable/PreciselyClipDrawable.kt @@ -92,9 +92,10 @@ class PreciselyClipDrawable( override fun draw(canvas: Canvas) { if (mClip) { if (!mScale.isEmpty) { - val rect = bounds - canvas.clipRect(rect) + val saveCount = canvas.save() + canvas.clipRect(bounds) super.draw(canvas) + canvas.restoreToCount(saveCount) } } else { super.draw(canvas) diff --git a/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt b/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt index 390ad5917..a6a49333f 100644 --- a/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt +++ b/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt @@ -97,7 +97,11 @@ class DownloadService : Service(), DownloadManager.DownloadListener { } } - override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + if (intent == null) { + // Handle the case where the intent is null + return START_STICKY + } handleIntent(intent) return START_STICKY } diff --git a/app/src/main/java/com/hippo/lib/image/Image.kt b/app/src/main/java/com/hippo/lib/image/Image.kt index 05938e43a..b5802522c 100644 --- a/app/src/main/java/com/hippo/lib/image/Image.kt +++ b/app/src/main/java/com/hippo/lib/image/Image.kt @@ -193,23 +193,36 @@ class Image private constructor( fun texImage(init: Boolean, offsetX: Int, offsetY: Int, width: Int, height: Int) { check(!hardware) { "Hardware buffer cannot be used in glgallery" } - val bitmap: Bitmap = if (animated) { - updateBitmap() - mBitmap!! - } else { - if (mObtainedDrawable == null) { - return + try { + val bitmap: Bitmap = if (animated) { + updateBitmap() + mBitmap!! + } else { + if (mObtainedDrawable == null) { + return + } + if (mObtainedDrawable is BitmapDrawable){ + (mObtainedDrawable as BitmapDrawable).bitmap + }else{ + val stickerBitmap = Bitmap.createBitmap(mObtainedDrawable!!.intrinsicWidth, mObtainedDrawable!!.intrinsicHeight, Bitmap.Config.ARGB_8888) + val canvas = Canvas(stickerBitmap) + mObtainedDrawable!!.setBounds(0, 0, stickerBitmap.width, stickerBitmap.height) + mObtainedDrawable!!.draw(canvas) + stickerBitmap + } } - (mObtainedDrawable as BitmapDrawable).bitmap + nativeTexImage( + bitmap, + init, + offsetX, + offsetY, + width, + height + ) + }catch (e:ClassCastException){ + FirebaseCrashlytics.getInstance().recordException(e) + return } - nativeTexImage( - bitmap, - init, - offsetX, - offsetY, - width, - height - ) } fun start() {