[3.3.0] 优化帧动画工具类
This commit is contained in:
@@ -264,9 +264,7 @@ public class BusPresenter extends Presenter<BusFragment>
|
||||
* 测试使用
|
||||
*/
|
||||
public void debugAutoPilotStatus(int status) {
|
||||
AutopilotStatusInfo info = new AutopilotStatusInfo();
|
||||
info.setState(status);
|
||||
onAutopilotStatusResponse(info);
|
||||
onAutopilotStatusResponse(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,8 @@ public class AnimatorDrawableUtil {
|
||||
private ImageView mImageView = null;
|
||||
//图片资源的ID列表
|
||||
private List<Integer> mResourceIdList = null;
|
||||
//图片bitmap列表
|
||||
private List<Bitmap> mBitmapList = null;
|
||||
//定时任务器
|
||||
private final Timer mTimer = new Timer();
|
||||
//定时任务
|
||||
@@ -54,10 +56,17 @@ public class AnimatorDrawableUtil {
|
||||
mImageView = imageview;
|
||||
if(mResourceIdList==null){
|
||||
mResourceIdList = new ArrayList<Integer>();
|
||||
mBitmapList = new ArrayList<>();
|
||||
}else{
|
||||
mResourceIdList.clear();
|
||||
mBitmapList.clear();
|
||||
}
|
||||
mResourceIdList.addAll(resourceIdList);
|
||||
|
||||
//在初始化时候就将资源文件decode
|
||||
for (int i = 0; i <= resourceIdList.size(); i++){
|
||||
mBitmapList.add(readBitMap(mImageView.getContext(),resourceIdList.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,14 +76,19 @@ public class AnimatorDrawableUtil {
|
||||
this.mImageView = imageview;
|
||||
if(mResourceIdList==null){
|
||||
mResourceIdList = new ArrayList<Integer>();
|
||||
mBitmapList = new ArrayList<>();
|
||||
}else{
|
||||
mResourceIdList.clear();
|
||||
mBitmapList.clear();
|
||||
}
|
||||
|
||||
loadFromXml(context, resourceId, new OnParseListener() {
|
||||
@Override
|
||||
public void onParse(List<Integer> res) {
|
||||
mResourceIdList.addAll(res);
|
||||
for (int i = 0; i <= res.size(); i++){
|
||||
mBitmapList.add(readBitMap(mImageView.getContext(),res.get(i)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -219,8 +233,13 @@ public class AnimatorDrawableUtil {
|
||||
case MSG_START: {
|
||||
if (mFrameIndex >= 0 && mFrameIndex < mResourceIdList.size() && mState == STATE_RUNNING) {
|
||||
//这里不能使用image.setImageResource 因为源码中也是创建了bitmap 所以这里我们自己创建
|
||||
Bitmap bitmap=readBitMap(mImageView.getContext(),mResourceIdList.get(mFrameIndex));
|
||||
mImageView.setImageBitmap(bitmap);
|
||||
if (mBitmapList != null && mBitmapList.size()-1 >= mFrameIndex){
|
||||
Bitmap bitmap= mBitmapList.get(mFrameIndex);
|
||||
mImageView.setImageBitmap(bitmap);
|
||||
}else {
|
||||
Bitmap bitmap=readBitMap(mImageView.getContext(),mResourceIdList.get(mFrameIndex));
|
||||
mImageView.setImageBitmap(bitmap);
|
||||
}
|
||||
mFrameIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user