blob: 093d7c1931a03594947640b510d2add9d0ddc8ab [file] [log] [blame]
Chet Haase2ea7f8b2013-06-21 15:00:05 -07001/*
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 */
16package com.android.transitiontests;
17
18import android.app.Activity;
19import android.os.Bundle;
20import android.view.View;
21import android.view.ViewGroup;
22import android.view.transition.Move;
23import android.view.transition.Transition;
24import android.view.transition.TransitionGroup;
25import android.view.transition.TransitionManager;
26import android.widget.Button;
27
28import static android.widget.LinearLayout.LayoutParams;
29
30public class HierarchicalMove extends Activity {
31
32 Button[] buttons = new Button[6];
33 ViewGroup mSceneRoot;
34 boolean wide = false;
35 Transition mTransition;
36
37 @Override
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 TransitionGroup rootTransition = new TransitionGroup(TransitionGroup.SEQUENTIALLY);
63
64 // button0
65 Transition move0 = new Move();
66 move0.setTargets(buttons[0]);
67
68 // buttons 1/2/3/4/5
69 TransitionGroup group12345 = new TransitionGroup(TransitionGroup.SEQUENTIALLY);
70
71 // buttons 1/2
72 TransitionGroup group12 = new TransitionGroup(TransitionGroup.TOGETHER);
73 Move move1 = new Move();
74 move1.setTargets(buttons[1]);
75 Move move2 = new Move();
76 move2.setTargets(buttons[2]);
77 group12.addTransitions(move1, move2);
78
79 TransitionGroup group345 = new TransitionGroup(TransitionGroup.SEQUENTIALLY);
80 Move move3 = new Move();
81 move3.setTargets(buttons[3]);
82 Move move45 = new Move();
83 move45.setTargets(buttons[4], buttons[5]);
84 group345.addTransitions(move3, move45);
85
86 group12345.addTransitions(move0, group12, group345);
87
88 rootTransition.addTransitions(group12345);
89 rootTransition.setDuration(1000);
90 mTransition = rootTransition;
91
92 }
93
94 public void sendMessage(View view) {
95 TransitionManager.beginDelayedTransition(mSceneRoot, mTransition);
96 int widthSpec = wide ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
97 LayoutParams params = new LayoutParams(widthSpec, LayoutParams.WRAP_CONTENT);
98 for (int i = 0; i < buttons.length; ++i) {
99 buttons[i].setLayoutParams(params);
100 }
101 wide = !wide;
102 }
103
104}