From 943421c57418f6500b9d8683076ea6734e0ac56c Mon Sep 17 00:00:00 2001 From: liujing Date: Thu, 17 Sep 2020 10:03:10 +0800 Subject: [PATCH] [fix]crash --- .../utils/animation/V2XAnimationManager.java | 65 ++++++++++--------- .../v2x/view/V2XNetworkLoadingView.java | 2 +- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/animation/V2XAnimationManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/animation/V2XAnimationManager.java index 76e6008160..94a760dd65 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/animation/V2XAnimationManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/animation/V2XAnimationManager.java @@ -1,64 +1,71 @@ package com.mogo.module.v2x.utils.animation; -import android.graphics.drawable.AnimationDrawable; -import android.util.Log; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; -import com.mogo.utils.ThreadPoolService; -import com.mogo.utils.UiThreadHandler; - public class V2XAnimationManager implements Animation { private static final String TAG = "V2XAnimationManager"; private ProgressBar targetImageView; - private Animation delegate; private boolean isStarted = false; + private int mStartIndex = 0; + + private final static int MSG_LOOP = 3004; + private long INTERVAL = 100L; + + private Handler mHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch (msg.what) { + case MSG_LOOP: + if (isStarted) { +// targetImageView.setImageResource( AnimationResources.loadingRes[mStartIndex++ % AnimationResources.loadingRes.length] ); + mHandler.sendEmptyMessageDelayed(MSG_LOOP, INTERVAL); + } + break; + } + } + }; + public void animationWithTarget(ProgressBar imageView, int[] resources, int duration) { targetImageView = imageView; - ThreadPoolService.execute(() -> { - final AnimationDrawable drawable = new AnimationDrawable(); - for (int i = 0; i < resources.length; i++) { - drawable.setOneShot(false); - drawable.addFrame(targetImageView.getResources().getDrawable(resources[i]), duration); - } - UiThreadHandler.post(() -> { - targetImageView.setBackground(drawable); - delegate = new DelegateDrawable(drawable); - start(); - }); - }); + INTERVAL = duration; + start(); } @Override synchronized public void start() { - if (delegate != null && !isStarted) { + isStarted = true; + mHandler.sendEmptyMessage(MSG_LOOP); + if (targetImageView != null) { targetImageView.setVisibility(View.VISIBLE); - isStarted = true; - delegate.start(); } } @Override synchronized public void stop() { - if (delegate != null && isStarted) { - isStarted = false; - delegate.stop(); + isStarted = false; + mHandler.removeMessages(MSG_LOOP); + if (targetImageView != null) { targetImageView.setVisibility(View.INVISIBLE); } } - public void soptWithError(){ - if (delegate != null && isStarted) { - isStarted = false; - delegate.stop(); + public void soptWithError() { + stop(); + if (targetImageView != null) { + targetImageView.setVisibility(View.VISIBLE); } } public void release() { - delegate = null; + stop(); } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/V2XNetworkLoadingView.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/V2XNetworkLoadingView.java index 0f2a51fd87..99a6cbbad7 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/V2XNetworkLoadingView.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/V2XNetworkLoadingView.java @@ -36,7 +36,7 @@ public class V2XNetworkLoadingView extends RelativeLayout { /* 添加动画图片资源 * */ -// setLoadingImage(AnimationResources.loadingRes); + setLoadingImage(AnimationResources.loadingRes); } public V2XNetworkLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {