From 2edf7052d2faee9047ed74d36fb79ccceba4731e Mon Sep 17 00:00:00 2001 From: aibingbing Date: Fri, 8 Mar 2024 10:34:42 +0800 Subject: [PATCH] =?UTF-8?q?[630]=20optimize:=20=E4=BC=98=E5=8C=96=E5=B8=A7?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E6=97=B6decode=20bitmap=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/utils/FrameAnimatorContainer.kt | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/FrameAnimatorContainer.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/FrameAnimatorContainer.kt index eed566129f..82c809d15d 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/FrameAnimatorContainer.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/FrameAnimatorContainer.kt @@ -7,7 +7,8 @@ import android.os.Handler import android.os.Looper import android.widget.ImageView import com.mogo.commons.AbsMogoApplication -import java.lang.RuntimeException +import com.mogo.eagle.core.utilcode.mogo.logger.Logger +import com.mogo.eagle.core.utilcode.util.ThreadUtils import java.lang.ref.SoftReference class FrameAnimatorContainer (resId: Int, @@ -115,6 +116,7 @@ class FrameAnimatorContainer (resId: Int, mHandler?.removeCallbacksAndMessages(null) val runnable: Runnable = object : Runnable { override fun run() { + Logger.d(TAG, "runnable: isMainThread:${ThreadUtils.isMainThread()}, threadName=${Thread.currentThread().name}") val imageView = mSoftReferenceImageView!!.get() if (!mShouldRun || imageView == null) { mIsRunning = false @@ -136,22 +138,28 @@ class FrameAnimatorContainer (resId: Int, } mHandler?.postDelayed(this, mDelayMillis.toLong()) if (mBitmap != null) { // so Build.VERSION.SDK_INT >= 11 - var bitmap: Bitmap? = null - try { - bitmap = BitmapFactory.decodeResource( - imageView.resources, - imageRes, - mBitmapOptions - ) - } catch (e: Exception) { - e.printStackTrace() - } - if (bitmap != null) { - imageView.setImageBitmap(bitmap) - } else { - imageView.setImageResource(imageRes) - mBitmap!!.recycle() - mBitmap = null + ThreadUtils.getFixedPool(1).submit { + Logger.d(TAG, "decodeResource Runnable: isMainThread:${ThreadUtils.isMainThread()}, threadName=${Thread.currentThread().name}") + var bitmap: Bitmap? = null + try { + bitmap = BitmapFactory.decodeResource( + imageView.resources, + imageRes, + mBitmapOptions + ) + } catch (e: Exception) { + e.printStackTrace() + } + ThreadUtils.runOnUiThread({ + Logger.d(TAG, "setImageBitmap Runnable: isMainThread:${ThreadUtils.isMainThread()}, threadName=${Thread.currentThread().name}") + if (bitmap != null) { + imageView.setImageBitmap(bitmap) + } else { + imageView.setImageResource(imageRes) + mBitmap!!.recycle() + mBitmap = null + } + }, ThreadUtils.MODE.QUEUE) } } else { imageView.setImageResource(imageRes)