• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 android.transition.cts;
17 
18 import android.transition.cts.R;
19 
20 import android.transition.Scene;
21 import android.transition.TransitionManager;
22 import android.view.View;
23 
24 import java.util.concurrent.CountDownLatch;
25 import java.util.concurrent.TimeUnit;
26 
27 public class TransitionManagerTest extends BaseTransitionTest {
28 
TransitionManagerTest()29     public TransitionManagerTest() {
30     }
31 
testBeginDelayedTransition()32     public void testBeginDelayedTransition() throws Throwable {
33         runTestOnUiThread(new Runnable() {
34             @Override
35             public void run() {
36                 TransitionManager.beginDelayedTransition(mSceneRoot, mTransition);
37                 View view = mActivity.getLayoutInflater().inflate(R.layout.scene1, mSceneRoot,
38                         false);
39                 mSceneRoot.addView(view);
40             }
41         });
42 
43         waitForStart();
44         waitForEnd(300);
45         assertEquals(1, mListener.resumeLatch.getCount());
46         assertEquals(1, mListener.pauseLatch.getCount());
47         assertEquals(1, mListener.cancelLatch.getCount());
48         assertNotNull(mListener.transition);
49         assertEquals(TestTransition.class, mListener.transition.getClass());
50         assertTrue(mTransition != mListener.transition);
51         runTestOnUiThread(new Runnable() {
52             @Override
53             public void run() {
54                 assertNotNull(mActivity.findViewById(R.id.redSquare));
55                 assertNotNull(mActivity.findViewById(R.id.greenSquare));
56             }
57         });
58     }
59 
testGo()60     public void testGo() throws Throwable {
61         startTransition(R.layout.scene1);
62         waitForStart();
63         waitForEnd(300);
64 
65         assertEquals(1, mListener.resumeLatch.getCount());
66         assertEquals(1, mListener.pauseLatch.getCount());
67         assertEquals(1, mListener.cancelLatch.getCount());
68         assertNotNull(mListener.transition);
69         assertEquals(TestTransition.class, mListener.transition.getClass());
70         assertTrue(mTransition != mListener.transition);
71         runTestOnUiThread(new Runnable() {
72             @Override
73             public void run() {
74                 assertNotNull(mActivity.findViewById(R.id.redSquare));
75                 assertNotNull(mActivity.findViewById(R.id.greenSquare));
76             }
77         });
78     }
79 
testSetTransition1()80     public void testSetTransition1() throws Throwable {
81         final TransitionManager transitionManager = new TransitionManager();
82 
83         runTestOnUiThread(new Runnable() {
84             @Override
85             public void run() {
86                 Scene scene = Scene.getSceneForLayout(mSceneRoot, R.layout.scene1, mActivity);
87                 transitionManager.setTransition(scene, mTransition);
88                 transitionManager.transitionTo(scene);
89             }
90         });
91 
92         waitForStart();
93         waitForEnd(300);
94         assertEquals(1, mListener.resumeLatch.getCount());
95         assertEquals(1, mListener.pauseLatch.getCount());
96         assertEquals(1, mListener.cancelLatch.getCount());
97         assertNotNull(mListener.transition);
98         assertEquals(TestTransition.class, mListener.transition.getClass());
99         assertTrue(mTransition != mListener.transition);
100         runTestOnUiThread(new Runnable() {
101             @Override
102             public void run() {
103                 mListener.startLatch = new CountDownLatch(1);
104                 mListener.endLatch = new CountDownLatch(1);
105                 assertNotNull(mActivity.findViewById(R.id.redSquare));
106                 assertNotNull(mActivity.findViewById(R.id.greenSquare));
107                 Scene scene = Scene.getSceneForLayout(mSceneRoot, R.layout.scene2, mActivity);
108                 transitionManager.transitionTo(scene);
109             }
110         });
111         assertFalse(mListener.startLatch.await(50, TimeUnit.MILLISECONDS));
112         endTransition();
113     }
114 
testSetTransition2()115     public void testSetTransition2() throws Throwable {
116         final TransitionManager transitionManager = new TransitionManager();
117         final Scene[] scenes = new Scene[3];
118 
119         runTestOnUiThread(new Runnable() {
120             @Override
121             public void run() {
122                 scenes[0] = Scene.getSceneForLayout(mSceneRoot, R.layout.scene1, mActivity);
123                 scenes[1] = Scene.getSceneForLayout(mSceneRoot, R.layout.scene2, mActivity);
124                 scenes[2] = Scene.getSceneForLayout(mSceneRoot, R.layout.scene3, mActivity);
125                 transitionManager.setTransition(scenes[0], scenes[1], mTransition);
126                 transitionManager.transitionTo(scenes[0]);
127             }
128         });
129         assertFalse(mListener.startLatch.await(100, TimeUnit.MILLISECONDS));
130 
131         runTestOnUiThread(new Runnable() {
132             @Override
133             public void run() {
134                 transitionManager.transitionTo(scenes[1]);
135             }
136         });
137 
138         waitForStart();
139         waitForEnd(300);
140         assertEquals(1, mListener.resumeLatch.getCount());
141         assertEquals(1, mListener.pauseLatch.getCount());
142         assertEquals(1, mListener.cancelLatch.getCount());
143         assertNotNull(mListener.transition);
144         assertEquals(TestTransition.class, mListener.transition.getClass());
145         assertTrue(mTransition != mListener.transition);
146         runTestOnUiThread(new Runnable() {
147             @Override
148             public void run() {
149                 mListener.startLatch = new CountDownLatch(1);
150                 mListener.endLatch = new CountDownLatch(1);
151                 transitionManager.transitionTo(scenes[2]);
152             }
153         });
154         assertFalse(mListener.startLatch.await(50, TimeUnit.MILLISECONDS));
155         endTransition();
156     }
157 
testEndTransitions()158     public void testEndTransitions() throws Throwable {
159         mTransition.setDuration(400);
160 
161         startTransition(R.layout.scene1);
162         waitForStart();
163         endTransition();
164         waitForEnd(100);
165     }
166 
testEndTransitionsBeforeStarted()167     public void testEndTransitionsBeforeStarted() throws Throwable {
168         mTransition.setDuration(400);
169 
170         runTestOnUiThread(new Runnable() {
171             @Override
172             public void run() {
173                 Scene scene = Scene.getSceneForLayout(mSceneRoot, R.layout.scene1, mActivity);
174                 TransitionManager.go(scene, mTransition);
175                 TransitionManager.endTransitions(mSceneRoot);
176             }
177         });
178         assertFalse(mListener.startLatch.await(100, TimeUnit.MILLISECONDS));
179         assertFalse(mListener.endLatch.await(10, TimeUnit.MILLISECONDS));
180     }
181 }
182 
183