[630] optimize: 优化帧动画时decode bitmap;
This commit is contained in:
@@ -7,7 +7,8 @@ import android.os.Handler
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import com.mogo.commons.AbsMogoApplication
|
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
|
import java.lang.ref.SoftReference
|
||||||
|
|
||||||
class FrameAnimatorContainer (resId: Int,
|
class FrameAnimatorContainer (resId: Int,
|
||||||
@@ -115,6 +116,7 @@ class FrameAnimatorContainer (resId: Int,
|
|||||||
mHandler?.removeCallbacksAndMessages(null)
|
mHandler?.removeCallbacksAndMessages(null)
|
||||||
val runnable: Runnable = object : Runnable {
|
val runnable: Runnable = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
Logger.d(TAG, "runnable: isMainThread:${ThreadUtils.isMainThread()}, threadName=${Thread.currentThread().name}")
|
||||||
val imageView = mSoftReferenceImageView!!.get()
|
val imageView = mSoftReferenceImageView!!.get()
|
||||||
if (!mShouldRun || imageView == null) {
|
if (!mShouldRun || imageView == null) {
|
||||||
mIsRunning = false
|
mIsRunning = false
|
||||||
@@ -136,22 +138,28 @@ class FrameAnimatorContainer (resId: Int,
|
|||||||
}
|
}
|
||||||
mHandler?.postDelayed(this, mDelayMillis.toLong())
|
mHandler?.postDelayed(this, mDelayMillis.toLong())
|
||||||
if (mBitmap != null) { // so Build.VERSION.SDK_INT >= 11
|
if (mBitmap != null) { // so Build.VERSION.SDK_INT >= 11
|
||||||
var bitmap: Bitmap? = null
|
ThreadUtils.getFixedPool(1).submit {
|
||||||
try {
|
Logger.d(TAG, "decodeResource Runnable: isMainThread:${ThreadUtils.isMainThread()}, threadName=${Thread.currentThread().name}")
|
||||||
bitmap = BitmapFactory.decodeResource(
|
var bitmap: Bitmap? = null
|
||||||
imageView.resources,
|
try {
|
||||||
imageRes,
|
bitmap = BitmapFactory.decodeResource(
|
||||||
mBitmapOptions
|
imageView.resources,
|
||||||
)
|
imageRes,
|
||||||
} catch (e: Exception) {
|
mBitmapOptions
|
||||||
e.printStackTrace()
|
)
|
||||||
}
|
} catch (e: Exception) {
|
||||||
if (bitmap != null) {
|
e.printStackTrace()
|
||||||
imageView.setImageBitmap(bitmap)
|
}
|
||||||
} else {
|
ThreadUtils.runOnUiThread({
|
||||||
imageView.setImageResource(imageRes)
|
Logger.d(TAG, "setImageBitmap Runnable: isMainThread:${ThreadUtils.isMainThread()}, threadName=${Thread.currentThread().name}")
|
||||||
mBitmap!!.recycle()
|
if (bitmap != null) {
|
||||||
mBitmap = null
|
imageView.setImageBitmap(bitmap)
|
||||||
|
} else {
|
||||||
|
imageView.setImageResource(imageRes)
|
||||||
|
mBitmap!!.recycle()
|
||||||
|
mBitmap = null
|
||||||
|
}
|
||||||
|
}, ThreadUtils.MODE.QUEUE)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
imageView.setImageResource(imageRes)
|
imageView.setImageResource(imageRes)
|
||||||
|
|||||||
Reference in New Issue
Block a user