package com.mikadev.test;
import android.animation.ValueAnimator;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList;
import java.util.List;
public class CustomAnimator extends ValueAnimator implements ValueAnimator.AnimatorUpdateListener {
private final Rect mTmpRect;
private boolean mIsRevert;
private ViewGroup mMainContainer;
private View mFocusedView;
private View mFocusedViewContainer;
private List<View> mFadedOutToBottomViews, mSlideToTop;
private View mStickyTo;
private ViewGroup mEditModeViewGroup;
private int mEditModeHalfHeight;
private final int ANIMATION_DURATION = 300;
public CustomAnimator() {
super();
mTmpRect = new Rect();
mIsRevert = false;
mFadedOutToBottomViews = new ArrayList<View>();
mSlideToTop = new ArrayList<View>();
setInterpolator(new DecelerateInterpolator());
setDuration(ANIMATION_DURATION);
addUpdateListener(this);
}
public void setAnimatorViews(ViewGroup mainContainer, View focusedView, View focusedViewContainer, List<View> fadedOutToBottomViews, View stickyTo, ViewGroup editModeView, List<View> slideToTop) {
if (mainContainer == null) throw new NullPointerException();
if (focusedView == null) throw new NullPointerException();
if (focusedViewContainer == null) throw new NullPointerException();
if (editModeView == null) throw new NullPointerException();
mMainContainer = mainContainer;
mFocusedView = focusedView;
mFocusedViewContainer = focusedViewContainer;
mFadedOutToBottomViews.clear();
if (fadedOutToBottomViews != null)
mFadedOutToBottomViews.addAll(fadedOutToBottomViews);
mStickyTo = stickyTo;
mEditModeViewGroup = editModeView;
mSlideToTop.clear();
if (slideToTop != null)
mSlideToTop.addAll(slideToTop);
removeAllListeners();
addListener(new LayerEnablingAnimatorListener(focusedView));
for (View v : mFadedOutToBottomViews)
addListener(new LayerEnablingAnimatorListener(v));
for (View v : mSlideToTop)
addListener(new LayerEnablingAnimatorListener(v));
addListener(new LayerEnablingAnimatorListener(editModeView));
}
public void setEditModeHalfHeight(int editModeHalfHeight) {
mEditModeHalfHeight = editModeHalfHeight;
}
private Positions getPositionsStart() {
// focusOn
float focusY = mFocusedViewContainer.getY();
// slideToTop
float[] slideToTopY = new float[mSlideToTop.size()];
for (int i = 0; i < mSlideToTop.size(); i++) {
slideToTopY[i] = mSlideToTop.get(i).getY();
}
// fadeToBottom
float[] nextContainersY = new float[mFadedOutToBottomViews.size()];
for (int i = 0; i < mFadedOutToBottomViews.size(); i++) {
nextContainersY[i] = mFadedOutToBottomViews.get(i).getY();
}
float nextContainersAlpha = 1;
// stickyTo
float stickToY = mStickyTo == null ? 0 : mStickyTo.getY();
// fadeInToTop
float editY = mEditModeViewGroup.getY();
float editAlpha = 0f;
return new Positions(focusY, nextContainersY, nextContainersAlpha, stickToY, editY, editAlpha, slideToTopY);
}
private Positions getPositionsEnd() {
// focusOn
mFocusedView.getDrawingRect(mTmpRect);
mMainContainer.offsetDescendantRectToMyCoords(mFocusedView, mTmpRect);
float focusY = mFocusedViewContainer.getY() - mTmpRect.top;
// slideToTop
float[] slideToTopY = new float[mSlideToTop.size()];
for (int i = 0; i < mSlideToTop.size(); i++) {
slideToTopY[i] = mSlideToTop.get(i).getY() - mTmpRect.top;
}
// fadeToBottom
float[] nextContainersY = new float[mFadedOutToBottomViews.size()];
for (int i = 0; i < mFadedOutToBottomViews.size(); i++) {
nextContainersY[i] = mFadedOutToBottomViews.get(i).getY() + mEditModeHalfHeight;
}
float nextContainersAlpha = 0;
// stickyTo
float stickToY = 0;
if (mStickyTo != null) {
mStickyTo.getDrawingRect(mTmpRect);
mMainContainer.offsetDescendantRectToMyCoords(mStickyTo, mTmpRect);
stickToY = mStickyTo.getY() + (mStickyTo.getHeight() - mTmpRect.top);
}
// fadeInToTop
float editY = 0;
float editAlpha = 1f;
return new Positions(focusY, nextContainersY, nextContainersAlpha, stickToY, editY, editAlpha, slideToTopY);
}
public void prepareAnimation() {
mIsRevert = false;
setObjectValues(getPositionsStart(), getPositionsEnd());
setEvaluator(new PositionTypeEvaluator());
}
private Positions getRevertPositionsStart() {
// focusOn
float focusY = mFocusedViewContainer.getY();
// slideToTop
float[] slideToTopY = new float[mSlideToTop.size()];
for (int i = 0; i < mSlideToTop.size(); i++) {
slideToTopY[i] = mSlideToTop.get(i).getY();
}
// fadeToBottom
float[] nextContainersY = new float[mFadedOutToBottomViews.size()];
for (int i = 0; i < mFadedOutToBottomViews.size(); i++) {
nextContainersY[i] = mFadedOutToBottomViews.get(i).getY();
}
float nextContainersAlpha = 0;
// stickyTo
float stickToY = mStickyTo == null ? 0 : mStickyTo.getY();
// fadeInToTop
float editY = mEditModeViewGroup.getY();
float editAlpha = 1f;
return new Positions(focusY, nextContainersY, nextContainersAlpha, stickToY, editY, editAlpha, slideToTopY);
}
private Positions getRevertPositionsEnd() {
// focusOn
mFocusedView.getDrawingRect(mTmpRect);
mMainContainer.offsetDescendantRectToMyCoords(mFocusedView, mTmpRect);
float focusY = mFocusedViewContainer.getY() + mTmpRect.top;
// slideToTop
float[] slideToTopY = new float[mSlideToTop.size()];
for (int i = 0; i < mSlideToTop.size(); i++) {
slideToTopY[i] = mSlideToTop.get(i).getY() + mTmpRect.top;
}
// fadeToBottom
float[] nextContainersY = new float[mFadedOutToBottomViews.size()];
for (int i = 0; i < mFadedOutToBottomViews.size(); i++) {
nextContainersY[i] = mFadedOutToBottomViews.get(i).getY() - mEditModeHalfHeight;
}
float nextContainersAlpha = 1;
// stickyTo
float stickToY = 0;
if (mStickyTo != null) {
mStickyTo.getDrawingRect(mTmpRect);
mMainContainer.offsetDescendantRectToMyCoords(mStickyTo, mTmpRect);
stickToY = mStickyTo.getY() - (mStickyTo.getHeight() - mTmpRect.top);
}
// fadeInToTop
float editY = mEditModeHalfHeight;
float editAlpha = 0f;
return new Positions(focusY, nextContainersY, nextContainersAlpha, stickToY, editY, editAlpha, slideToTopY);
}
public void prepareRevert() {
mIsRevert = true;
setObjectValues(getRevertPositionsStart(), getRevertPositionsEnd());
setEvaluator(new PositionTypeEvaluator());
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Positions currentPos = (Positions) animation.getAnimatedValue();
if (!mIsRevert) {
for (int i = 0; i < mSlideToTop.size(); i++) {
mSlideToTop.get(i).setY(currentPos.getSlideToTop()[i]);
}
mFocusedViewContainer.setY(currentPos.getFocusY());
for (int i = 0; i < mFadedOutToBottomViews.size(); i++) {
mFadedOutToBottomViews.get(i).setY(currentPos.getNextContainersY()[i]);
mFadedOutToBottomViews.get(i).setAlpha(currentPos.getNextContainersAlpha());
}
if (mStickyTo != null)
mStickyTo.setY(currentPos.getStickToY());
mEditModeViewGroup.setY(currentPos.getEditY());
mEditModeViewGroup.setAlpha(currentPos.getEditAlpha());
mEditModeViewGroup.setVisibility(View.VISIBLE);
}
else {
mEditModeViewGroup.setY(currentPos.getEditY());
mEditModeViewGroup.setAlpha(currentPos.getEditAlpha());
if (mStickyTo != null)
mStickyTo.setY(currentPos.getStickToY());
for (int i = 0; i < mFadedOutToBottomViews.size(); i++) {
mFadedOutToBottomViews.get(i).setY(currentPos.getNextContainersY()[i]);
mFadedOutToBottomViews.get(i).setAlpha(currentPos.getNextContainersAlpha());
}
mFocusedViewContainer.setY(currentPos.getFocusY());
for (int i = 0; i < mSlideToTop.size(); i++) {
mSlideToTop.get(i).setY(currentPos.getSlideToTop()[i]);
}
}
}
}
jianghejie123
- 粉丝: 115
- 资源: 8
最新资源
- 同步发电机离网并网无缝切 同步发电机预同步控制 在0.5秒的时候开始预同步跟踪,当满足离网并网无缝切条件的时候自动产生并网信号,由离网切并网 有参考文献如下图 默认2018b版本
- Screenshot_20250105_092244.jpg
- COMSOL裂缝条数对岩层声波测井响应规律的影响,地层参数可以自己修改 参考:煤层发育状况的单极子声波测井响应数值模拟-裂缝性煤层声波测井响应的有限元模拟研究 地层中裂缝条数对声波测井响应规律的影响
- GooglePinyin
- 华为初级实验手册(PDF).rar
- 基于PyTorch和Transformers的本地法律大模型搭建用于合同审查与法律咨询-含可实现方案及代码
- H3CIE-LAB资料.zip
- 颗粒流动本案例首先基于图像处理方法将SEM二维扫描图像的孔隙模型进行了提取,如图1所示 将提取的孔隙网络模型导入有限元软件中进行渗流模拟,模拟结果如图2所示 2.5x.
- CPU与简单模型机设计实验
- Generative Agent Simulations of 1,000 People
- 分布式驱动 直接横摆力矩控制MPC 自己写的,效果如图
- 20250103211238097-2-1029623.jpg
- 塑料颗粒筛分机sw18全套技术资料100%好用.zip
- PEN-200.pdf
- Comsol相场法压裂案例及相关参考文献 裂纹相场法模拟包括 1. 单边裂纹受剪切载荷作用 2. 单边裂纹受拉伸载荷作用 3. 初始地应力场作用下多孔介质水力压裂
- 水下维修作业工程双体船sw21可编辑全套技术资料100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页