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.ChangeScroll;
19 import android.transition.TransitionManager;
20 import android.view.View;
21 
22 public class ChangeScrollTest extends BaseTransitionTest {
23     ChangeScroll mChangeScroll;
24 
ChangeScrollTest()25     public ChangeScrollTest() {
26     }
27 
28     @Override
setUp()29     protected void setUp() throws Exception {
30         super.setUp();
31         mChangeScroll = new ChangeScroll();
32         mTransition = mChangeScroll;
33         resetListener();
34     }
35 
testChangeScroll()36     public void testChangeScroll() throws Throwable {
37         enterScene(R.layout.scene5);
38         runTestOnUiThread(new Runnable() {
39             @Override
40             public void run() {
41                 final View view = mActivity.findViewById(R.id.text);
42                 assertEquals(0, view.getScrollX());
43                 assertEquals(0, view.getScrollY());
44                 TransitionManager.beginDelayedTransition(mSceneRoot, mChangeScroll);
45                 view.scrollTo(150, 300);
46             }
47         });
48         waitForStart();
49         Thread.sleep(150);
50         runTestOnUiThread(new Runnable() {
51             @Override
52             public void run() {
53                 final View view = mActivity.findViewById(R.id.text);
54                 final int scrollX = view.getScrollX();
55                 final int scrollY = view.getScrollY();
56                 assertTrue(scrollX > 0);
57                 assertTrue(scrollX < 150);
58                 assertTrue(scrollY > 0);
59                 assertTrue(scrollY < 300);
60             }
61         });
62         waitForEnd(400);
63         runTestOnUiThread(new Runnable() {
64             @Override
65             public void run() {
66                 final View view = mActivity.findViewById(R.id.text);
67                 assertEquals(150, view.getScrollX());
68                 assertEquals(300, view.getScrollY());
69             }
70         });
71     }
72 }
73 
74