Closed lozn00 closed 7 years ago
delte attr autoplay =true solute
loadJsonAnimFromUrl showDialog
public static void loadJsonAnimFromUrl(Activity activity, GiftModel giftModel, final LottieAnimationView lottieAnimationView) {
final ProgressDialog dialog = DialogUtils.getProgressDialog(activity);
dialog.show();
HttpUtil.queryData(AppContext.getInstance(), giftModel.getMurl(), new NetQuestTask.SimpleRequestDataListener() {
@Override
public void onSuccess(String str) {
ActionEngine.loadJsonAnim(str, lottieAnimationView, new INotify<Boolean>() {
@Override
public void onNotify(Boolean param) {
if (param) {
dialog.dismiss();
} else {
DialogUtils.delaydismissDialog(dialog, "悲剧了,加载出错");
}
}
});
}
@Override
public void onFail(String str) {
DialogUtils.delaydismissDialog(dialog, Constants.IS_TRAGEDY_NET_ERR);
}
});
}
public static void loadJsonAnim(String jsonString, final LottieAnimationView animationView, final INotify<Boolean> iNotify) {
animationView.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
animationView.setVisibility(View.VISIBLE);
Log.w(TAG, "onAnimationStart");
}
@Override
public void onAnimationEnd(Animator animation) {
Log.w(TAG_JSON_ANIM, "onAnimationEnd");
animationView.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {
animationView.setVisibility(View.GONE);
Log.w(TAG_JSON_ANIM, "onAnimationCancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.w(TAG_JSON_ANIM, "onAnimationRepeat");
}
});
try {
org.json.JSONObject json = new org.json.JSONObject(jsonString);
LottieComposition.Factory
.fromJson(AppContext.getInstance().getResources(), json, new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(@Nullable LottieComposition composition) {
if (iNotify != null) {
iNotify.onNotify(composition == null ? false : true);
}
if (composition == null) {
Log.w(TAG_JSON_ANIM, "composition is Empty");
return;
}
setComposition(composition, animationView);
}
});
} catch (JSONException e) {
Log.w(TAG_JSON_ANIM, "" + e.toString());
if (iNotify != null) {
iNotify.onNotify(false);
}
}
}
public static void setComposition(LottieComposition composition, LottieAnimationView animationView) {
if (composition.hasImages() && TextUtils.isEmpty(animationView.getImageAssetsFolder())) {
ToastUtils.showToast("包含图片的暂时不支持哦!");
//noinspection ConstantConditions
/* Snackbar.make(
getView(),
"This animation has images and no image folder was set",
Snackbar.LENGTH_LONG).show();*/
return;
}
animationView.setComposition(composition);
if (animationView.getProgress() == 1f) {
animationView.setProgress(0f);
Log.w(TAG_JSON_ANIM, "调整进度为0");
}
boolean restart = animationView.isAnimating();
animationView.cancelAnimation();
animationView.setProgress(0f);
animationView.playAnimation();
/* if (restart) {
} else {
animationView.resumeAnimation();
}*/
Log.w(TAG_JSON_ANIM + " setComposition", "waring:" + composition.getWarnings() + ",duration:" + composition.getDuration()
+ ",hasImage:" + composition.hasImages() + ",top:" + composition.getBounds().top + ",left:" + composition.getBounds().left + ",right:" + composition.getBounds().right
+ ",bottom:" + composition.getBounds().bottom + ",isAnimating:" + animationView.isAnimating());
}
@qssq Can you attach a small sample app that repros this?
CompositionLoaded has been called, but the animation did not immediately come out, even if I switch to a number of different animation, wait a few seconds after the animation can be displayed, after switching animation is normal, how is this going? onCompositionLoaded 已经被回调了, 但是动画效果并没有马上出来,哪怕我切换多个不同的动画, 等了几秒之后动画才能显示出来,之后切换动画各种都是正常的,这是怎么回事?这不是网络问题因为都很快的回调了onCompositionLoaded 只是我感觉这时候又一个预加载过程,而这个过程我应该如何监听?