• 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.Crossfade;
24 import android.transition.ChangeText;
25 import android.transition.Transition;
26 import android.transition.TransitionSet;
27 import android.transition.TransitionManager;
28 import android.widget.Button;
29 import android.widget.ImageView;
30 import android.widget.TextView;
31 
32 import static android.widget.LinearLayout.LayoutParams;
33 
34 public 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, mTextChangeGroup3;
45     TransitionSet mInOutGroup;
46 
47     @Override
onCreate(Bundle savedInstanceState)48     public void onCreate(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50         setContentView(R.layout.crossfade_multiple);
51 
52         ViewGroup container = findViewById(R.id.container);
53         mSceneRoot = container;
54 
55         mButton = findViewById(R.id.button);
56         mImageView = findViewById(R.id.imageview);
57         mTextView = findViewById(R.id.textview);
58 
59         mCrossfade = new Crossfade();
60         mCrossfade.addTarget(R.id.button).addTarget(R.id.textview).addTarget(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         ChangeText changeTextInOut = new ChangeText();
78         changeTextInOut.setChangeBehavior(ChangeText.CHANGE_BEHAVIOR_OUT_IN);
79         mTextChangeGroup1.addTransition(changeTextInOut).addTransition(new ChangeBounds());
80 
81         mTextChangeGroup2 = new TransitionSet();
82         mTextChangeGroup2.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
83         ChangeText changeTextOut = new ChangeText();
84         changeTextOut.setChangeBehavior(ChangeText.CHANGE_BEHAVIOR_OUT);
85         mTextChangeGroup2.addTransition(changeTextOut).addTransition(new ChangeBounds());
86 
87         mTextChangeGroup3 = new TransitionSet();
88         mTextChangeGroup3.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
89         ChangeText changeTextIn = new ChangeText();
90         changeTextIn.setChangeBehavior(ChangeText.CHANGE_BEHAVIOR_IN);
91         mTextChangeGroup3.addTransition(changeTextIn).addTransition(new ChangeBounds());
92     }
93 
sendMessage(View view)94     public void sendMessage(View view) {
95         TransitionManager.beginDelayedTransition(mSceneRoot, mTransition);
96         int id = view.getId();
97         LayoutParams params = null;
98         switch (id) {
99             case R.id.button1:
100                 params = new LayoutParams(200, 200);
101                 mButton.setText("A");
102                 mTextView.setText("1111111");
103                 mImageView.setImageResource(R.drawable.self_portrait_square_100);
104                 break;
105             case R.id.button2:
106                 params = new LayoutParams(400, 200);
107                 mButton.setText("B");
108                 mTextView.setText("2222222");
109                 mImageView.setImageResource(R.drawable.self_portrait_square_200);
110                 break;
111             case R.id.button3:
112                 params = new LayoutParams(200, 400);
113                 mButton.setText("C");
114                 mTextView.setText("3333333");
115                 mImageView.setImageResource(R.drawable.self_portrait_square_400);
116                 break;
117         }
118         mButton.setLayoutParams(params);
119     }
120 
changeTransitionType(View view)121     public void changeTransitionType(View view) {
122         int id = view.getId();
123         switch (id) {
124             case R.id.reveal:
125                 mCrossfade.setFadeBehavior(Crossfade.FADE_BEHAVIOR_REVEAL);
126                 mTransition = mCrossfadeGroup;
127                 break;
128             case R.id.crossfade:
129                 mCrossfade.setFadeBehavior(Crossfade.FADE_BEHAVIOR_CROSSFADE);
130                 mTransition = mCrossfadeGroup;
131                 break;
132             case R.id.inout:
133                 mTransition = mInOutGroup;
134                 break;
135             case R.id.textfade1:
136                 mTransition = mTextChangeGroup1;
137                 break;
138             case R.id.textfade2:
139                 mTransition = mTextChangeGroup2;
140                 break;
141             case R.id.textfade3:
142                 mTransition = mTextChangeGroup3;
143                 break;
144         }
145     }
146 }
147