1/* 2 * Copyright (C) 2017 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 17package android.support.transition; 18 19import static org.junit.Assert.assertEquals; 20import static org.junit.Assert.assertNotNull; 21import static org.junit.Assert.assertNull; 22import static org.junit.Assert.assertTrue; 23 24import android.graphics.Rect; 25import android.support.test.filters.MediumTest; 26import android.support.test.filters.SdkSuppress; 27import android.support.transition.test.R; 28import android.support.v4.view.ViewCompat; 29import android.view.View; 30 31import org.junit.Test; 32 33@MediumTest 34public class ChangeClipBoundsTest extends BaseTransitionTest { 35 36 @Override 37 Transition createTransition() { 38 return new ChangeClipBounds(); 39 } 40 41 @SdkSuppress(minSdkVersion = 18) 42 @Test 43 public void testChangeClipBounds() throws Throwable { 44 enterScene(R.layout.scene1); 45 46 final View redSquare = rule.getActivity().findViewById(R.id.redSquare); 47 final Rect newClip = new Rect(redSquare.getLeft() + 10, redSquare.getTop() + 10, 48 redSquare.getRight() - 10, redSquare.getBottom() - 10); 49 50 rule.runOnUiThread(new Runnable() { 51 @Override 52 public void run() { 53 assertNull(ViewCompat.getClipBounds(redSquare)); 54 TransitionManager.beginDelayedTransition(mRoot, mTransition); 55 ViewCompat.setClipBounds(redSquare, newClip); 56 } 57 }); 58 waitForStart(); 59 Thread.sleep(150); 60 rule.runOnUiThread(new Runnable() { 61 @Override 62 public void run() { 63 Rect midClip = ViewCompat.getClipBounds(redSquare); 64 assertNotNull(midClip); 65 assertTrue(midClip.left > 0 && midClip.left < newClip.left); 66 assertTrue(midClip.top > 0 && midClip.top < newClip.top); 67 assertTrue(midClip.right < redSquare.getRight() && midClip.right > newClip.right); 68 assertTrue(midClip.bottom < redSquare.getBottom() 69 && midClip.bottom > newClip.bottom); 70 } 71 }); 72 waitForEnd(); 73 74 rule.runOnUiThread(new Runnable() { 75 @Override 76 public void run() { 77 final Rect endRect = ViewCompat.getClipBounds(redSquare); 78 assertNotNull(endRect); 79 assertEquals(newClip, endRect); 80 } 81 }); 82 83 resetListener(); 84 rule.runOnUiThread(new Runnable() { 85 @Override 86 public void run() { 87 TransitionManager.beginDelayedTransition(mRoot, mTransition); 88 ViewCompat.setClipBounds(redSquare, null); 89 } 90 }); 91 waitForStart(); 92 Thread.sleep(150); 93 rule.runOnUiThread(new Runnable() { 94 @Override 95 public void run() { 96 Rect midClip = ViewCompat.getClipBounds(redSquare); 97 assertNotNull(midClip); 98 assertTrue(midClip.left > 0 && midClip.left < newClip.left); 99 assertTrue(midClip.top > 0 && midClip.top < newClip.top); 100 assertTrue(midClip.right < redSquare.getRight() && midClip.right > newClip.right); 101 assertTrue(midClip.bottom < redSquare.getBottom() 102 && midClip.bottom > newClip.bottom); 103 } 104 }); 105 waitForEnd(); 106 107 rule.runOnUiThread(new Runnable() { 108 @Override 109 public void run() { 110 assertNull(ViewCompat.getClipBounds(redSquare)); 111 } 112 }); 113 114 } 115 116 @Test 117 public void dummy() { 118 // Avoid "No tests found" on older devices 119 } 120 121} 122