package org.android.mygdttst.douban;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.Log;
import android.view.ViewPropertyAnimator;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;
import org.android.mygdttst.R;
public class CardAnimHelper {
public static final int DIFFUSION = 1;
public static final int FOLD = 2;
public static final int VERTICAL = 3;
private final float ROTATION_DOWN_BACK = 5.0f;
private int animDuration = 300;
private CardBanEndListener banEndListener;
private CardPositionHelper cardPositionHelper;
private CardScrollBackListener cardScrollBackListener;
private Context context;
private int currentMode = 1;
private DefaultTouchHelper defaultTouchHelper;
private boolean isDownAnim = true;
private boolean isLoadingChannel = false;
private final float linkRotation = 4.0f;
private CardSwitchEndListener switchEndListener;
private final float targetRotation = 6.0f;
private boolean topFirstAnimEnd = false;
private void downBackListener() {
}
public CardAnimHelper(Context context, CardPositionHelper cardPositionHelper) {
this.context = context;
this.cardPositionHelper = cardPositionHelper;
}
public void doSwitch(DefaultTouchHelper defaultTouchHelper) {
this.defaultTouchHelper = defaultTouchHelper;
ImageUtils.pauseTag(this.context);
if (defaultTouchHelper.getCurrentStatus() != 1) {
final CardItem targetCardItem = getTargetCardItem(4);
final CardItem targetCardItem2 = getTargetCardItem(3);
final CardItem targetCardItem3 = getTargetCardItem(2);
final CardItem targetCardItem4 = getTargetCardItem(0);
final CardItem targetCardItem5 = getTargetCardItem(1);
if (!(targetCardItem == null || targetCardItem2 == null || targetCardItem3 == null || targetCardItem4 == null || targetCardItem4 == null)) {
if (targetCardItem5 != null) {
defaultTouchHelper.setCurrentStatus(1);
targetCardItem.getView().setOnTouchListener(null);
float po = targetCardItem2.getView().getY() - this.cardPositionHelper.getCardWidth();
targetCardItem2.getView().animate().x(targetCardItem2.getView().getX() + (Math.abs(Math.abs(targetCardItem.getView().getX()) - Math.abs(targetCardItem2.getView().getX())) / 2.0f)).rotation(4.0f).setDuration((long) this.animDuration).setListener(null);
targetCardItem.getView().animate().y(po).rotation(6.0f).setDuration((long) this.animDuration).setListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
CardAnimHelper.this.switchingAnim(targetCardItem, targetCardItem2, targetCardItem3, targetCardItem4, targetCardItem5);
}
});
}
}
}
}
private void switchingAnim(CardItem cardItem, final CardItem cardItem2, CardItem cardItem3, CardItem cardItem4, CardItem cardItem5) {
moveAndUpdateData(cardItem, 1);
moveAndUpdateData(cardItem3, 3);
moveAndUpdateData(cardItem5, 0);
topFirstCardMove(cardItem4);
moveAndUpdateData(cardItem2, 4, new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
Log.d("CardAnimHelper", "CardAnimHelper===> setOnTouchListener");
cardItem2.getView().setOnTouchListener(CardAnimHelper.this.defaultTouchHelper.generateListener(cardItem2.getView()));
cardItem2.updateCardLayoutParams(CardAnimHelper.this.getTargetParams(4));
CardAnimHelper.this.defaultTouchHelper.setCurrentStatus(3);
ImageUtils.resumeTag(CardAnimHelper.this.context);
CardAnimHelper.this.switchEnd();
cardItem2.getView().animate().setListener(null);
//Log.e("xxxxxx",)
}
});
}
public void doDownBack(final DefaultTouchHelper defaultTouchHelper) {
this.defaultTouchHelper = defaultTouchHelper;
if (defaultTouchHelper.getCurrentStatus() != 2) {
this.isDownAnim = true;
defaultTouchHelper.setCurrentStatus(2);
final CardItem targetCardItem = getTargetCardItem(4);
downBackListener();
final float y = targetCardItem.getView().getY();
targetCardItem.getView().animate().y((this.cardPositionHelper.getCardWidth() / 5.0f) + y).rotation(5.0f).setDuration((long) this.animDuration).setListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
if (isDownAnim) {
defaultTouchHelper.setCurrentStatus(3);
targetCardItem.getView().animate().y(y).rotation(0.0f).setDuration((long) CardAnimHelper.this.animDuration).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animation.cancel();
}
});
// animator.cancel();
//return;
}else{
targetCardItem.getView().animate().y(y).rotation(0.0f).setDuration((long) CardAnimHelper.this.animDuration);
CardAnimHelper.this.isDownAnim = false;
if(null != cardScrollBackListener) {
CardAnimHelper.this.cardScrollBackListener.backEnd();
}
}
}
});
}
}
public void doBan(DefaultTouchHelper defaultTouchHelper) {
if (defaultTouchHelper.getCurrentStatus() != 1) {
defaultTouchHelper.setCurrentStatus(1);
setDefaultTouchHelper(defaultTouchHelper);
middleCardBanMove(getTargetCardItem(4));
}
}
private void doBanEndAnim() {
CardItem targetCardItem = getTargetCardItem(4);
final CardItem targetCardItem2 = getTargetCardItem(3);
CardItem targetCardItem3 = getTargetCardItem(2);
getTargetCardItem(0);
getTargetCardItem(1);
moveAndUpdateData(targetCardItem3, 3);
moveAndUpdateData(targetCardItem, 2);
moveAndUpdateData(targetCardItem2, 4, new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
targetCardItem2.updateCardLayoutParams(CardAnimHelper.this.getTargetParams(4));
CardAnimHelper.this.defaultTouchHelper.setCurrentStatus(3);
targetCardItem2.getView().setOnTouchListener(CardAnimHelper.this.defaultTouchHelper.generateListener(targetCardItem2.getView()));
CardAnimHelper.this.banEnd();
}
});
}
private void banEnd() {
CardBanEndListener cardBanEndListener = this.banEndListener;
if (cardBanEndListener != null && !this.isLoadingChannel) {
this.isLoadingChannel = true;
cardBanEndListener.banEnd();
}
}
private void middleCardBanMove(final CardItem cardItem) {
cardItem.getView().setOnTouchListener(null);
final CardLayoutParams futureParams = this.cardPositionHelper.getFutureParams();
ObjectAnimator ofFloat = ObjectAnimator.ofFloat(cardItem.getView(), "translationX", new float[]{0.0f, -this.cardPositionHelper.getCardWidth()});
ofFloat.setInterpolator(new AccelerateDecelerateInterpolator());
ofFloat.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
cardItem.getView().setX(fu
Android仿豆瓣FM卡片滑动
53 浏览量
2024-05-16
11:50:49
上传
评论
收藏 16KB ZIP 举报
LuckTigger
- 粉丝: 17
- 资源: 5
最新资源
- 单家独院式农房户型设计水电图.dwg
- STC12C5A60S2单片机+LCD12864俄罗斯方块源码程序实例源码KEIL C51工程文件.zip
- 编程IDE等宽字体,不错的
- FlowGeek FlowGeek是基于MVP架构的、遵循Material Design设计规范的开源中国社区客户端
- 单家独院式图纸农房户型设计90平09.20-t3.dwg
- 使用HttpURLConnect实现的文件下载器
- STM32驱动OLED1.54寸OLED驱动代码
- STC12C5A60S2单片机开发LCD12864液晶显示正弦函数实例源码KEIL C51工程文件.zip
- SI9933BDY-T1-E3-VB一款SOP8封装2个P-Channel场效应MOS管
- C++开发基于ROS实现多差速无人车编队控制源码+使用说明+详细注释 (期末大作业)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈