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.test.ActivityInstrumentationTestCase2;
23import android.transition.Transition.EpicenterCallback;
24import android.util.ArrayMap;
25import android.view.View;
26import android.view.animation.AccelerateInterpolator;
27import android.widget.TextView;
28
29import com.android.frameworks.coretests.R;
30
31public class TransitionTest extends ActivityInstrumentationTestCase2<AnimatorSetActivity> {
32    Activity mActivity;
33    public TransitionTest() {
34        super(AnimatorSetActivity.class);
35    }
36
37    @Override
38    protected void setUp() throws Exception {
39        mActivity = getActivity();
40    }
41
42    public void testClone() throws Throwable {
43        View square1 = mActivity.findViewById(R.id.square1);
44        View square2 = mActivity.findViewById(R.id.square2);
45        View square3 = mActivity.findViewById(R.id.square3);
46        Fade fade = new Fade();
47        fade.setStartDelay(1000);
48        fade.setDuration(1001);
49
50        fade.addTarget(square1);
51        fade.excludeTarget(square2, true);
52        fade.excludeChildren(square3, true);
53
54        fade.addTarget(R.id.square4);
55        fade.excludeTarget(R.id.square3, true);
56        fade.excludeChildren(R.id.square2, true);
57
58        fade.addTarget("hello");
59        fade.excludeTarget("world", true);
60
61        fade.addTarget(View.class);
62        fade.excludeTarget(TextView.class, true);
63
64        fade.setMatchOrder(Transition.MATCH_ID);
65        fade.setPropagation(new CircularPropagation());
66        fade.setPathMotion(new ArcMotion());
67        fade.setInterpolator(new AccelerateInterpolator());
68        fade.setNameOverrides(new ArrayMap<>());
69
70        EpicenterCallback epicenterCallback = new EpicenterCallback() {
71            @Override
72            public Rect onGetEpicenter(Transition transition) {
73                return null;
74            }
75        };
76
77        fade.setEpicenterCallback(epicenterCallback);
78
79        Fade clone = (Fade) fade.clone();
80        assertEquals(fade.mStartDelay, clone.mStartDelay);
81        assertEquals(fade.mDuration, clone.mDuration);
82        assertEquals(fade.mInterpolator, clone.mInterpolator);
83        assertEquals(fade.mPropagation, clone.mPropagation);
84        assertEquals(fade.getPathMotion(), clone.getPathMotion());
85        assertEquals(fade.getEpicenterCallback(), clone.getEpicenterCallback());
86        assertEquals(fade.mNameOverrides, clone.mNameOverrides);
87        assertEquals(fade.mMatchOrder, clone.mMatchOrder);
88
89        assertEquals(fade.mTargets, clone.mTargets);
90        assertEquals(fade.mTargetExcludes, clone.mTargetExcludes);
91        assertEquals(fade.mTargetChildExcludes, clone.mTargetChildExcludes);
92
93        assertEquals(fade.mTargetIds, clone.mTargetIds);
94        assertEquals(fade.mTargetIdExcludes, clone.mTargetIdExcludes);
95        assertEquals(fade.mTargetIdChildExcludes, clone.mTargetIdChildExcludes);
96
97        assertEquals(fade.mTargetNames, clone.mTargetNames);
98        assertEquals(fade.mTargetNameExcludes, clone.mTargetNameExcludes);
99
100        assertEquals(fade.mTargetTypes, clone.mTargetTypes);
101        assertEquals(fade.mTargetTypeExcludes, clone.mTargetTypeExcludes);
102    }
103}
104