blob: 3b0dbb1a58da77c9a1a68fef89cba11fb2f0ad1f [file] [log] [blame]
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -08001/*
2 * Copyright 2018 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 */
16package androidx.fragment.app;
17
18import android.animation.Animator;
19import android.graphics.Rect;
20import android.transition.TransitionValues;
21import android.transition.Visibility;
22import android.view.View;
23import android.view.ViewGroup;
24
25import java.util.ArrayList;
26
27/**
28 * Visibility transition that tracks which targets are applied to it.
29 * This transition does no animation.
30 */
31class TrackingVisibility extends Visibility implements TargetTracking {
32 public final ArrayList<View> targets = new ArrayList<>();
33 private final Rect[] mEpicenter = new Rect[1];
34
35 @Override
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
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
62 public ArrayList<View> getTrackedTargets() {
63 return targets;
64 }
65
66 @Override
67 public void clearTargets() {
68 targets.clear();
69 }
70
71 @Override
72 public Rect getCapturedEpicenter() {
73 return mEpicenter[0];
74 }
75}