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