Update Scene
This commit is contained in:
1 parent
e8d1d92bfb
commit
0ce081512d
10 files changed
+141
-44
No files matched your search
@@ -24,15 +24,20 @@ import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.hippo.animation.ArgbEvaluator;
|
||||
import com.hippo.animation.SimpleAnimatorListener;
|
||||
import com.hippo.util.ViewUtils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class TransitionCurtain extends Curtain {
|
||||
|
||||
private static long ANIMATE_DELAY = 500L;
|
||||
private static long ANIMATE_TIME = 800L;
|
||||
|
||||
private ViewPair[] mViewPairArray;
|
||||
|
||||
private List<ObjectAnimator> mAnimList = new LinkedList<>();
|
||||
|
||||
public TransitionCurtain(ViewPair[] viewPairArray) {
|
||||
mViewPairArray = viewPairArray;
|
||||
}
|
||||
@@ -51,8 +56,17 @@ public class TransitionCurtain extends Curtain {
|
||||
colorAnim.setEvaluator(ArgbEvaluator.getInstance());
|
||||
colorAnim.setDuration(ANIMATE_TIME);
|
||||
|
||||
colorAnim.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAnimList.clear();
|
||||
}
|
||||
});
|
||||
|
||||
colorAnim.start();
|
||||
|
||||
mAnimList.add(colorAnim);
|
||||
|
||||
// Handle transit part
|
||||
for (ViewPair pair : mViewPairArray) {
|
||||
final View enterView = pair.getToView(enter);
|
||||
@@ -98,11 +112,7 @@ public class TransitionCurtain extends Curtain {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
ViewUtils.setVisibility(exitView, View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
ViewUtils.setVisibility(exitView, View.VISIBLE);
|
||||
ViewUtils.setVisibility(exit.getSceneView(), View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -111,6 +121,11 @@ public class TransitionCurtain extends Curtain {
|
||||
xAnim.start();
|
||||
yAnim.start();
|
||||
|
||||
mAnimList.add(scaleXAnim);
|
||||
mAnimList.add(scaleYAnim);
|
||||
mAnimList.add(xAnim);
|
||||
mAnimList.add(yAnim);
|
||||
|
||||
// TODO show other part progressively
|
||||
}
|
||||
});
|
||||
@@ -120,6 +135,8 @@ public class TransitionCurtain extends Curtain {
|
||||
@Override
|
||||
public void close(@NonNull Scene enter, final @NonNull Scene exit) {
|
||||
|
||||
ViewUtils.setVisibility(enter.getSceneView(), View.VISIBLE);
|
||||
|
||||
// Handle background
|
||||
ObjectAnimator colorAnim = ObjectAnimator.ofInt(exit, "backgroundColor", Color.TRANSPARENT);
|
||||
colorAnim.setEvaluator(ArgbEvaluator.getInstance());
|
||||
@@ -183,6 +200,18 @@ public class TransitionCurtain extends Curtain {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endAnimation() {
|
||||
for (ObjectAnimator oa : mAnimList) {
|
||||
oa.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInAnimation() {
|
||||
return !mAnimList.isEmpty();
|
||||
}
|
||||
|
||||
public static class ViewPair {
|
||||
|
||||
private int[] mIds;
|
||||
@@ -196,26 +225,23 @@ public class TransitionCurtain extends Curtain {
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
private @Nullable View getFromView(Scene scene) {
|
||||
View sceneView = scene.getSceneView();
|
||||
|
||||
if (mIds != null && sceneView != null) {
|
||||
return sceneView.findViewById(mIds[0]);
|
||||
private @Nullable View getFromView(@NonNull Scene scene) {
|
||||
if (mIds != null) {
|
||||
return scene.findViewById(mIds[0]);
|
||||
}
|
||||
if (mHelper != null) {
|
||||
return mHelper.getFromView(sceneView);
|
||||
return mHelper.getFromView(scene.getSceneView());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private @Nullable View getToView(Scene scene) {
|
||||
View sceneView = scene.getSceneView();
|
||||
private @Nullable View getToView(@NonNull Scene scene) {
|
||||
|
||||
if (mIds != null && sceneView != null) {
|
||||
return sceneView.findViewById(mIds[1]);
|
||||
if (mIds != null) {
|
||||
return scene.findViewById(mIds[1]);
|
||||
}
|
||||
if (mHelper != null) {
|
||||
return mHelper.getToView(sceneView);
|
||||
return mHelper.getToView(scene.getSceneView());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -227,23 +253,4 @@ public class TransitionCurtain extends Curtain {
|
||||
|
||||
public abstract View getToView(@Nullable View sceneView);
|
||||
}
|
||||
|
||||
public class SimpleAnimatorListener implements Animator.AnimatorListener {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user