CrossfadeMultiple.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.transition.ChangeBounds;
21import android.view.View;
22import android.view.ViewGroup;
23import android.transition.Crossfade;
24import android.transition.TextChange;
25import android.transition.Transition;
26import android.transition.TransitionSet;
27import android.transition.TransitionManager;
28import android.widget.Button;
29import android.widget.ImageView;
30import android.widget.TextView;
31
32import static android.widget.LinearLayout.LayoutParams;
33
34public class CrossfadeMultiple extends Activity {
35    ViewGroup mSceneRoot;
36    static int mCurrentScene;
37    TransitionManager mTransitionManager;
38    Transition mTransition;
39    ImageView mImageView;
40    TextView mTextView;
41    Button mButton;
42    Crossfade mCrossfade;
43    TransitionSet mCrossfadeGroup;
44    TransitionSet mTextChangeGroup1, mTextChangeGroup2;
45    TransitionSet mInOutGroup;
46
47    @Override
48    public void onCreate(Bundle savedInstanceState) {
49        super.onCreate(savedInstanceState);
50        setContentView(R.layout.crossfade_multiple);
51
52        ViewGroup container = (ViewGroup) findViewById(R.id.container);
53        mSceneRoot = container;
54
55        mButton = (Button) findViewById(R.id.button);
56        mImageView = (ImageView) findViewById(R.id.imageview);
57        mTextView = (TextView) findViewById(R.id.textview);
58
59        mCrossfade = new Crossfade();
60        mCrossfade.addTargetId(R.id.button).addTargetId(R.id.textview).addTargetId(R.id.imageview);
61
62        mCrossfadeGroup = new TransitionSet();
63        mCrossfadeGroup.setDuration(300);
64        mCrossfadeGroup.addTransition(mCrossfade).addTransition(new ChangeBounds());
65        mTransition = mCrossfadeGroup;
66
67        mInOutGroup = new TransitionSet();
68        Crossfade inOut = new Crossfade();
69        inOut.setDuration(300);
70        inOut.setFadeBehavior(Crossfade.FADE_BEHAVIOR_OUT_IN);
71        ChangeBounds changeBounds = new ChangeBounds();
72        changeBounds.setStartDelay(150);
73        changeBounds.setDuration(0);
74        mInOutGroup.addTransition(inOut).addTransition(changeBounds);
75
76        mTextChangeGroup1 = new TransitionSet();
77        TextChange textChangeInOut = new TextChange();
78        textChangeInOut.setChangeBehavior(TextChange.CHANGE_BEHAVIOR_OUT_IN);
79        mTextChangeGroup1.addTransition(textChangeInOut).addTransition(new ChangeBounds());
80
81        mTextChangeGroup2 = new TransitionSet();
82        mTextChangeGroup2.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
83        TextChange textChangeOut = new TextChange();
84        textChangeOut.setChangeBehavior(TextChange.CHANGE_BEHAVIOR_OUT);
85        TextChange textChangeIn = new TextChange();
86        textChangeIn.setChangeBehavior(TextChange.CHANGE_BEHAVIOR_IN);
87        mTextChangeGroup2.addTransition(textChangeOut).addTransition(new ChangeBounds()).
88                addTransition(textChangeIn);
89    }
90
91    public void sendMessage(View view) {
92        TransitionManager.beginDelayedTransition(mSceneRoot, mTransition);
93        int id = view.getId();
94        LayoutParams params = null;
95        switch (id) {
96            case R.id.button1:
97                params = new LayoutParams(200, 200);
98                mButton.setText("A");
99                mTextView.setText("1111111");
100                mImageView.setImageResource(R.drawable.self_portrait_square_100);
101                break;
102            case R.id.button2:
103                params = new LayoutParams(400, 200);
104                mButton.setText("B");
105                mTextView.setText("2222222");
106                mImageView.setImageResource(R.drawable.self_portrait_square_200);
107                break;
108            case R.id.button3:
109                params = new LayoutParams(200, 400);
110                mButton.setText("C");
111                mTextView.setText("3333333");
112                mImageView.setImageResource(R.drawable.self_portrait_square_400);
113                break;
114        }
115        mButton.setLayoutParams(params);
116    }
117
118    public void changeTransitionType(View view) {
119        int id = view.getId();
120        switch (id) {
121            case R.id.reveal:
122                mCrossfade.setFadeBehavior(Crossfade.FADE_BEHAVIOR_REVEAL);
123                mTransition = mCrossfadeGroup;
124                break;
125            case R.id.crossfade:
126                mCrossfade.setFadeBehavior(Crossfade.FADE_BEHAVIOR_CROSSFADE);
127                mTransition = mCrossfadeGroup;
128                break;
129            case R.id.inout:
130                mTransition = mInOutGroup;
131                break;
132            case R.id.textfade1:
133                mTransition = mTextChangeGroup1;
134                break;
135            case R.id.textfade2:
136                mTransition = mTextChangeGroup2;
137                break;
138        }
139    }
140}
141