• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.transitiontests;
17 
18 import android.app.Activity;
19 import android.os.Bundle;
20 import android.transition.ChangeBounds;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.transition.Transition;
24 import android.transition.TransitionSet;
25 import android.transition.TransitionManager;
26 import android.widget.Button;
27 
28 import static android.widget.LinearLayout.LayoutParams;
29 
30 public class HierarchicalMove extends Activity {
31 
32     Button[] buttons = new Button[6];
33     ViewGroup mSceneRoot;
34     boolean wide = false;
35     Transition mTransition;
36 
37     @Override
onCreate(Bundle savedInstanceState)38     public void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40         setContentView(R.layout.hierarchical_move);
41 
42         View container = (View) findViewById(R.id.container);
43         mSceneRoot = (ViewGroup) container.getParent();
44 
45         buttons[0] = (Button) findViewById(R.id.button0);
46         buttons[1] = (Button) findViewById(R.id.button1);
47         buttons[2] = (Button) findViewById(R.id.button2);
48         buttons[3] = (Button) findViewById(R.id.button3);
49         buttons[4] = (Button) findViewById(R.id.button4);
50         buttons[5] = (Button) findViewById(R.id.button5);
51 
52         // Move button0, then buttons 1/2 together, then buttons 3/4/5 sequentially:
53         // group (seq)
54         //    Move 0
55         //    group (seq)
56         //       group (together)
57         //          Move 1
58         //          Move 2
59         //       group (sequentially)
60         //          Move 3
61         //          Move 4/5
62         TransitionSet rootTransition = new TransitionSet().
63                 setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
64 
65         // button0
66         Transition move0 = new ChangeBounds();
67         move0.addTarget(buttons[0]);
68 
69         // buttons 1/2/3/4/5
70         TransitionSet group12345 = new TransitionSet().
71                 setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
72 
73         // buttons 1/2
74         TransitionSet group12 = new TransitionSet().
75                 setOrdering(TransitionSet.ORDERING_TOGETHER);
76         ChangeBounds changeBounds1 = new ChangeBounds();
77         changeBounds1.addTarget(buttons[1]);
78         ChangeBounds changeBounds2 = new ChangeBounds();
79         changeBounds2.addTarget(buttons[2]);
80         group12.addTransition(changeBounds1).addTransition(changeBounds2);
81 
82         TransitionSet group345 = new TransitionSet().
83                 setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
84         ChangeBounds changeBounds3 = new ChangeBounds();
85         changeBounds3.addTarget(buttons[3]);
86         ChangeBounds changeBounds45 = new ChangeBounds();
87         changeBounds45.addTarget(buttons[4]).addTarget(buttons[5]);
88         group345.addTransition(changeBounds3).addTransition(changeBounds45);
89 
90         group12345.addTransition(move0).addTransition(group12).addTransition(group345);
91 
92         rootTransition.addTransition(group12345);
93         rootTransition.setDuration(1000);
94         mTransition = rootTransition;
95 
96     }
97 
sendMessage(View view)98     public void sendMessage(View view) {
99         TransitionManager.beginDelayedTransition(mSceneRoot, mTransition);
100         int widthSpec = wide ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
101         LayoutParams params = new LayoutParams(widthSpec, LayoutParams.WRAP_CONTENT);
102         for (int i = 0; i < buttons.length; ++i) {
103             buttons[i].setLayoutParams(params);
104         }
105         wide = !wide;
106     }
107 
108 }
109