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 package com.android.compatibility.common.util.transition;
17 
18 import android.animation.Animator;
19 import android.graphics.Rect;
20 import android.transition.TransitionValues;
21 import android.transition.Visibility;
22 import android.view.View;
23 import android.view.ViewGroup;
24 
25 import java.util.ArrayList;
26 
27 /**
28  * Visibility transition that tracks which targets are applied to it.
29  * This transition does no animation.
30  */
31 public class TrackingVisibility extends Visibility implements TargetTracking {
32     public final ArrayList<View> targets = new ArrayList<>();
33     private final Rect[] mEpicenter = new Rect[1];
34 
35     @Override
onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues)36     public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues,
37             TransitionValues endValues) {
38         targets.add(endValues.view);
39         Rect epicenter = getEpicenter();
40         if (epicenter != null) {
41             mEpicenter[0] = new Rect(epicenter);
42         } else {
43             mEpicenter[0] = null;
44         }
45         return null;
46     }
47 
48     @Override
onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues)49     public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues,
50             TransitionValues endValues) {
51         targets.add(startValues.view);
52         Rect epicenter = getEpicenter();
53         if (epicenter != null) {
54             mEpicenter[0] = new Rect(epicenter);
55         } else {
56             mEpicenter[0] = null;
57         }
58         return null;
59     }
60 
61     @Override
getTrackedTargets()62     public ArrayList<View> getTrackedTargets() {
63         return targets;
64     }
65 
66     @Override
clearTargets()67     public void clearTargets() {
68         targets.clear();
69     }
70 
71     @Override
getCapturedEpicenter()72     public Rect getCapturedEpicenter() {
73         return mEpicenter[0];
74     }
75 }
76