12ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase/*
22ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * Copyright (C) 2013 The Android Open Source Project
32ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase *
42ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * Licensed under the Apache License, Version 2.0 (the "License");
52ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * you may not use this file except in compliance with the License.
62ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * You may obtain a copy of the License at
72ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase *
82ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase *      http://www.apache.org/licenses/LICENSE-2.0
92ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase *
102ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * Unless required by applicable law or agreed to in writing, software
112ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * distributed under the License is distributed on an "AS IS" BASIS,
122ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * See the License for the specific language governing permissions and
142ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase * limitations under the License.
152ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase */
162ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haasepackage com.android.transitiontests;
172ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
182ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haaseimport android.app.Activity;
192ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haaseimport android.os.Bundle;
20d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport android.transition.ChangeBounds;
212ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haaseimport android.view.View;
222ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haaseimport android.view.ViewGroup;
23d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport android.transition.Transition;
24d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport android.transition.TransitionSet;
25d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport android.transition.TransitionManager;
262ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haaseimport android.widget.Button;
272ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
282ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haaseimport static android.widget.LinearLayout.LayoutParams;
292ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
302ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haasepublic class HierarchicalMove extends Activity {
312ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
322ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    Button[] buttons = new Button[6];
332ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    ViewGroup mSceneRoot;
342ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    boolean wide = false;
352ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    Transition mTransition;
362ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
372ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    @Override
382ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    public void onCreate(Bundle savedInstanceState) {
392ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        super.onCreate(savedInstanceState);
402ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        setContentView(R.layout.hierarchical_move);
412ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
422ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        View container = (View) findViewById(R.id.container);
432ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        mSceneRoot = (ViewGroup) container.getParent();
442ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
452ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        buttons[0] = (Button) findViewById(R.id.button0);
462ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        buttons[1] = (Button) findViewById(R.id.button1);
472ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        buttons[2] = (Button) findViewById(R.id.button2);
482ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        buttons[3] = (Button) findViewById(R.id.button3);
492ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        buttons[4] = (Button) findViewById(R.id.button4);
502ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        buttons[5] = (Button) findViewById(R.id.button5);
512ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
522ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        // Move button0, then buttons 1/2 together, then buttons 3/4/5 sequentially:
532ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        // group (seq)
542ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //    Move 0
552ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //    group (seq)
562ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //       group (together)
572ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //          Move 1
582ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //          Move 2
592ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //       group (sequentially)
602ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //          Move 3
612ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        //          Move 4/5
62d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        TransitionSet rootTransition = new TransitionSet().
63d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
642ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
652ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        // button0
66d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        Transition move0 = new ChangeBounds();
67d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        move0.addTarget(buttons[0]);
682ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
692ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        // buttons 1/2/3/4/5
70d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        TransitionSet group12345 = new TransitionSet().
71d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
722ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
732ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        // buttons 1/2
74d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        TransitionSet group12 = new TransitionSet().
75d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                setOrdering(TransitionSet.ORDERING_TOGETHER);
76d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        ChangeBounds changeBounds1 = new ChangeBounds();
77d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        changeBounds1.addTarget(buttons[1]);
78d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        ChangeBounds changeBounds2 = new ChangeBounds();
79d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        changeBounds2.addTarget(buttons[2]);
80d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        group12.addTransition(changeBounds1).addTransition(changeBounds2);
81d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase
82d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        TransitionSet group345 = new TransitionSet().
83d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
84d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        ChangeBounds changeBounds3 = new ChangeBounds();
85d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        changeBounds3.addTarget(buttons[3]);
86d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        ChangeBounds changeBounds45 = new ChangeBounds();
87d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        changeBounds45.addTarget(buttons[4]).addTarget(buttons[5]);
88d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        group345.addTransition(changeBounds3).addTransition(changeBounds45);
89d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase
90d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        group12345.addTransition(move0).addTransition(group12).addTransition(group345);
91d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase
92d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        rootTransition.addTransition(group12345);
932ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        rootTransition.setDuration(1000);
942ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        mTransition = rootTransition;
952ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
962ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    }
972ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
982ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    public void sendMessage(View view) {
992ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        TransitionManager.beginDelayedTransition(mSceneRoot, mTransition);
1002ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        int widthSpec = wide ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
1012ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        LayoutParams params = new LayoutParams(widthSpec, LayoutParams.WRAP_CONTENT);
1022ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        for (int i = 0; i < buttons.length; ++i) {
1032ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase            buttons[i].setLayoutParams(params);
1042ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        }
1052ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        wide = !wide;
1062ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase    }
1072ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase
1082ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase}
109