SequenceTest.java revision d82c8ac4db7091d2e976af4c89a1734465d20cd2
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 */
16package com.android.transitiontests;
17
18import android.app.Activity;
19import android.os.Bundle;
20import android.view.View;
21import android.view.ViewGroup;
22import android.transition.Scene;
23import android.transition.Transition;
24import android.transition.TransitionSet;
25import android.widget.Button;
26import android.transition.Fade;
27import android.transition.ChangeBounds;
28import android.transition.TransitionManager;
29
30
31public class SequenceTest extends Activity {
32
33    Button mRemovingButton, mInvisibleButton, mGoneButton;
34    Scene mScene1, mScene2;
35    ViewGroup mSceneRoot;
36    TransitionSet sequencedFade, reverseSequencedFade;
37    Scene mCurrentScene;
38
39    @Override
40    public void onCreate(Bundle savedInstanceState) {
41        super.onCreate(savedInstanceState);
42        setContentView(R.layout.fading_test);
43
44        View container = (View) findViewById(R.id.container);
45        mSceneRoot = (ViewGroup) container.getParent();
46
47        mRemovingButton = (Button) findViewById(R.id.removingButton);
48        mInvisibleButton = (Button) findViewById(R.id.invisibleButton);
49        mGoneButton = (Button) findViewById(R.id.goneButton);
50
51        mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.fading_test, this);
52        mScene2 = Scene.getSceneForLayout(mSceneRoot, R.layout.fading_test_scene_2, this);
53
54        Transition fade1 = new Fade().addTargetId(R.id.removingButton);
55        Transition fade2 = new Fade().addTargetId(R.id.invisibleButton);
56        Transition fade3 = new Fade().addTargetId(R.id.goneButton);
57        TransitionSet fader = new TransitionSet().
58                setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
59        fader.addTransition(fade1).addTransition(fade2).addTransition(fade3).
60                addTransition(new ChangeBounds());
61        sequencedFade = fader;
62
63        reverseSequencedFade = new TransitionSet().
64                setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
65        reverseSequencedFade.addTransition(new ChangeBounds()).addTransition(fade3).addTransition(fade2).
66                addTransition(fade1);
67
68        mCurrentScene = mScene1;
69    }
70
71    public void sendMessage(View view) {
72        if (mCurrentScene == mScene1) {
73            TransitionManager.go(mScene2, sequencedFade);
74            mCurrentScene = mScene2;
75        } else {
76            TransitionManager.go(mScene1, reverseSequencedFade);
77            mCurrentScene = mScene1;
78        }
79    }
80}
81