1 /* 2 * Copyright (C) 2016 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 17 package android.transition; 18 19 import android.animation.AnimatorSetActivity; 20 import android.app.Activity; 21 import android.graphics.Rect; 22 import android.test.ActivityInstrumentationTestCase2; 23 import android.transition.Transition.EpicenterCallback; 24 import android.util.ArrayMap; 25 import android.view.View; 26 import android.view.animation.AccelerateInterpolator; 27 import android.widget.TextView; 28 29 import androidx.test.filters.LargeTest; 30 31 import com.android.frameworks.coretests.R; 32 33 import java.lang.reflect.Field; 34 35 @LargeTest 36 public class TransitionTest extends ActivityInstrumentationTestCase2<AnimatorSetActivity> { 37 Activity mActivity; TransitionTest()38 public TransitionTest() { 39 super(AnimatorSetActivity.class); 40 } 41 42 @Override setUp()43 protected void setUp() throws Exception { 44 mActivity = getActivity(); 45 } 46 testClone()47 public void testClone() throws Throwable { 48 View square1 = mActivity.findViewById(R.id.square1); 49 View square2 = mActivity.findViewById(R.id.square2); 50 View square3 = mActivity.findViewById(R.id.square3); 51 Fade fade = new Fade(); 52 fade.setStartDelay(1000); 53 fade.setDuration(1001); 54 55 fade.addTarget(square1); 56 fade.excludeTarget(square2, true); 57 fade.excludeChildren(square3, true); 58 59 fade.addTarget(R.id.square4); 60 fade.excludeTarget(R.id.square3, true); 61 fade.excludeChildren(R.id.square2, true); 62 63 fade.addTarget("hello"); 64 fade.excludeTarget("world", true); 65 66 fade.addTarget(View.class); 67 fade.excludeTarget(TextView.class, true); 68 69 fade.setMatchOrder(Transition.MATCH_ID); 70 fade.setPropagation(new CircularPropagation()); 71 fade.setPathMotion(new ArcMotion()); 72 fade.setInterpolator(new AccelerateInterpolator()); 73 fade.setNameOverrides(new ArrayMap<>()); 74 75 EpicenterCallback epicenterCallback = new EpicenterCallback() { 76 @Override 77 public Rect onGetEpicenter(Transition transition) { 78 return null; 79 } 80 }; 81 82 fade.setEpicenterCallback(epicenterCallback); 83 84 Fade clone = (Fade) fade.clone(); 85 assertFieldEquals(fade, clone, "mStartDelay"); 86 assertFieldEquals(fade, clone, "mDuration"); 87 assertFieldEquals(fade, clone, "mInterpolator"); 88 assertFieldEquals(fade, clone, "mPropagation"); 89 assertEquals(fade.getPathMotion(), clone.getPathMotion()); 90 assertEquals(fade.getEpicenterCallback(), clone.getEpicenterCallback()); 91 assertFieldEquals(fade, clone, "mNameOverrides"); 92 assertFieldEquals(fade, clone, "mMatchOrder"); 93 94 assertFieldEquals(fade, clone, "mTargets"); 95 assertFieldEquals(fade, clone, "mTargetExcludes"); 96 assertFieldEquals(fade, clone, "mTargetChildExcludes"); 97 98 assertFieldEquals(fade, clone, "mTargetIds"); 99 assertFieldEquals(fade, clone, "mTargetIdExcludes"); 100 assertFieldEquals(fade, clone, "mTargetIdChildExcludes"); 101 102 assertFieldEquals(fade, clone, "mTargetNames"); 103 assertFieldEquals(fade, clone, "mTargetNameExcludes"); 104 105 assertFieldEquals(fade, clone, "mTargetTypes"); 106 assertFieldEquals(fade, clone, "mTargetTypeExcludes"); 107 } 108 assertFieldEquals(Fade fade1, Fade fade2, String fieldName)109 private static void assertFieldEquals(Fade fade1, Fade fade2, String fieldName) 110 throws NoSuchFieldException, IllegalAccessException { 111 Field field = findField(Fade.class, fieldName); 112 field.setAccessible(true); 113 assertEquals("Field '" + fieldName + "' value mismatch", field.get(fade1), 114 field.get(fade2)); 115 } 116 findField(Class<?> type, String fieldName)117 private static Field findField(Class<?> type, String fieldName) throws NoSuchFieldException { 118 while (type != null) { 119 try { 120 return type.getDeclaredField(fieldName); 121 } catch (NoSuchFieldException e) { 122 // try the parent 123 type = type.getSuperclass(); 124 } 125 } 126 throw new NoSuchFieldException(fieldName); 127 } 128 } 129