Update Scene

This commit is contained in:
seven332 committed 2015-03-24 16:46:50 +08:00
1 parent e8d1d92bfb
commit 0ce081512d
10 files changed
+141 -44

No files matched your search

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.animation;
import android.animation.Animator;
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) {
}
}
@@ -87,7 +87,8 @@ public class GalleryListScene extends Scene implements SearchLayout.SearhLayoutH
@Override
public void onClick(View v) {
startScene(TestScene.class, null, new TransitionCurtain(new TransitionCurtain.ViewPair[] {
new TransitionCurtain.ViewPair(R.id.haha, R.id.haha)
new TransitionCurtain.ViewPair(R.id.haha, R.id.haha),
new TransitionCurtain.ViewPair(R.id.bbbbbb, R.id.bbbbbb)
}));
}
});
+20 -5
View File
@@ -19,16 +19,31 @@ import android.support.annotation.NonNull;
public abstract class Curtain {
/**
* Called when
*
* @param enter the scene on the top of the scene stack
* @param exit the scene behind the enter scene
*/
public abstract void open(@NonNull Scene enter, @NonNull Scene exit);
public abstract void close(@NonNull Scene enter, @NonNull Scene exit);
/**
* Call it after {@link #close}
*
* @param scene the scene
* End open or close animation
*/
protected void dispatchDetachFromeStage(Scene scene) {
scene.detachFromeStage();
public abstract void endAnimation();
/**
* Is open or close animation running
*/
public abstract boolean isInAnimation();
protected void dispatchOpenFinished(@NonNull Scene enter, @NonNull Scene exit) {
}
protected void dispatchCloseFinished(@NonNull Scene enter, @NonNull Scene exit) {
exit.detachFromeStage();
}
}
+18 -2
View File
@@ -37,10 +37,19 @@ import com.hippo.util.AssertUtils;
*/
public abstract class Scene {
static final int SCENE_STATE_CREATE = 0;
static final int SCENE_STATE_RUN = 1;
static final int SCENE_STATE_DESTROY = 2;
static final int SCENE_STATE_OPEN = 3;
static final int SCENE_STATE_CLOSE = 4;
static final int SCENE_STATE_PAUSE = 5;
private @Nullable FrameLayout mSceneView;
private int mBackgroundColor = 0xffeeeeee; // TODO Need a better to set background color
private int mState = SCENE_STATE_CREATE;
private static SceneManager sSceneManager;
static void setSceneManager(SceneManager sceneManager) {
@@ -76,6 +85,14 @@ public abstract class Scene {
sSceneManager.startScene(sceneClass, announcer, curtain);
}
int getState() {
return mState;
}
void setState(int state) {
mState = state;
}
public final void finish() {
sSceneManager.finishScene(this);
}
@@ -131,8 +148,6 @@ public abstract class Scene {
return mBackgroundColor;
}
protected void setContentView(int resId) {
AssertUtils.assertNull("Only call setContentView once", mSceneView);
@@ -240,6 +255,7 @@ public abstract class Scene {
}
public void onBackPressed() {
// TODO First click to show finish animation, click again to finish the animation at once and it is finished
finish();
}
@@ -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) {
}
}
}