|
1 | 1 | package com.saulmm.material; |
2 | 2 |
|
| 3 | +import android.animation.Animator; |
| 4 | +import android.animation.LayoutTransition; |
3 | 5 | import android.app.Activity; |
4 | 6 | import android.app.Fragment; |
5 | 7 | import android.graphics.Outline; |
|
9 | 11 | import android.transition.Explode; |
10 | 12 | import android.transition.Scene; |
11 | 13 | import android.transition.Slide; |
| 14 | +import android.transition.Transition; |
12 | 15 | import android.transition.TransitionManager; |
13 | 16 | import android.view.Menu; |
14 | 17 | import android.view.MenuItem; |
| 18 | +import android.view.View; |
| 19 | +import android.view.ViewGroup; |
| 20 | +import android.view.ViewPropertyAnimator; |
15 | 21 | import android.widget.FrameLayout; |
| 22 | +import android.widget.LinearLayout; |
16 | 23 |
|
17 | 24 | import com.saulmm.material.R; |
18 | 25 |
|
19 | 26 | public class MyActivity2 extends Activity { |
20 | 27 |
|
21 | | - private FrameLayout frameContainer; |
| 28 | + private static final int NUM_VIEWS = 5; |
| 29 | + private static final int SCALE_ITEM_ANIMATION_DELAY = 30; |
| 30 | + private LinearLayout rowContainer; |
22 | 31 |
|
23 | 32 | @Override |
24 | 33 | protected void onCreate(Bundle savedInstanceState) { |
25 | 34 | super.onCreate(savedInstanceState); |
| 35 | + |
26 | 36 | setContentView(R.layout.activity_my2); |
27 | 37 |
|
28 | | - // Fab Button |
29 | | - int fabSize = getResources().getDimensionPixelSize(R.dimen.fab_size); |
30 | | - Outline fabOutLine = new Outline(); |
| 38 | + rowContainer = (LinearLayout) findViewById(R.id.row_container2); |
31 | 39 |
|
32 | 40 | Utils.configureWindowEnterExitTransition(getWindow()); |
33 | 41 |
|
34 | | - fabOutLine.setOval(0, 0, fabSize, fabSize); |
| 42 | + getWindow().getEnterTransition().addListener(new Transition.TransitionListener() { |
| 43 | + @Override |
| 44 | + public void onTransitionStart(Transition transition) {} |
| 45 | + |
| 46 | + @Override |
| 47 | + public void onTransitionCancel(Transition transition) {} |
| 48 | + |
| 49 | + @Override |
| 50 | + public void onTransitionPause(Transition transition) {} |
| 51 | + |
| 52 | + @Override |
| 53 | + public void onTransitionResume(Transition transition) {} |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onTransitionEnd(Transition transition) { |
| 57 | + getWindow().getEnterTransition().removeListener(this); |
| 58 | + |
| 59 | + for (int i = 0; i < rowContainer.getChildCount(); i++) { |
| 60 | + |
| 61 | + View rowView = rowContainer.getChildAt(i); |
| 62 | + rowView.animate().setStartDelay(i * SCALE_ITEM_ANIMATION_DELAY) |
| 63 | + .scaleX(1).scaleY(1); |
| 64 | + } |
| 65 | + } |
| 66 | + }); |
35 | 67 | } |
36 | 68 |
|
37 | 69 | @Override |
38 | | - protected void onResume() { |
| 70 | + public void onBackPressed() { |
| 71 | + |
| 72 | + for (int i = 0; i < rowContainer.getChildCount(); i++) { |
| 73 | + |
| 74 | + View rowView = rowContainer.getChildAt(i); |
| 75 | + ViewPropertyAnimator propertyAnimator = rowView.animate().setStartDelay(i * SCALE_ITEM_ANIMATION_DELAY) |
| 76 | + .scaleX(0).scaleY(0); |
| 77 | + |
| 78 | + propertyAnimator.setListener(new Animator.AnimatorListener() { |
| 79 | + @Override |
| 80 | + public void onAnimationStart(Animator animator) {} |
| 81 | + |
| 82 | + @Override |
| 83 | + public void onAnimationEnd(Animator animator) { |
39 | 84 |
|
40 | | - super.onResume(); |
| 85 | + finishAfterTransition(); |
| 86 | + } |
41 | 87 |
|
42 | | - frameContainer = (FrameLayout) findViewById(R.id.container); |
| 88 | + @Override |
| 89 | + public void onAnimationCancel(Animator animator) {} |
43 | 90 |
|
44 | | - Scene scene1 = Scene.getSceneForLayout(frameContainer, R.layout.activity_my_activity2, this); |
45 | | - TransitionManager.go(scene1, new Explode()); |
| 91 | + @Override |
| 92 | + public void onAnimationRepeat(Animator animator) {} |
| 93 | + }); |
| 94 | + } |
46 | 95 | } |
47 | 96 | } |
0 commit comments