• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.quickstep.util;
17 
18 import android.annotation.CallSuper;
19 import android.view.Surface.Rotation;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.view.WindowManager;
23 
24 import com.android.systemui.shared.animation.UnfoldMoveFromCenterAnimator;
25 import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener;
26 import com.android.systemui.unfold.updates.RotationChangeProvider;
27 
28 import java.util.HashMap;
29 import java.util.Map;
30 
31 /**
32  * Animation that moves launcher icons and widgets from center to the sides (final position)
33  */
34 public abstract class BaseUnfoldMoveFromCenterAnimator implements TransitionProgressListener {
35 
36     private final UnfoldMoveFromCenterAnimator mMoveFromCenterAnimation;
37     private final RotationChangeProvider mRotationChangeProvider;
38 
39     private final Map<ViewGroup, Boolean> mOriginalClipToPadding = new HashMap<>();
40     private final Map<ViewGroup, Boolean> mOriginalClipChildren = new HashMap<>();
41 
42     private final UnfoldMoveFromCenterRotationListener mRotationListener =
43             new UnfoldMoveFromCenterRotationListener();
44     private boolean mAnimationInProgress = false;
45 
BaseUnfoldMoveFromCenterAnimator(WindowManager windowManager, RotationChangeProvider rotationChangeProvider)46     public BaseUnfoldMoveFromCenterAnimator(WindowManager windowManager,
47             RotationChangeProvider rotationChangeProvider) {
48         mMoveFromCenterAnimation = new UnfoldMoveFromCenterAnimator(windowManager,
49                 new LauncherViewsMoveFromCenterTranslationApplier());
50         mRotationChangeProvider = rotationChangeProvider;
51     }
52 
53     @CallSuper
54     @Override
onTransitionStarted()55     public void onTransitionStarted() {
56         mAnimationInProgress = true;
57         mMoveFromCenterAnimation.updateDisplayProperties();
58         onPrepareViewsForAnimation();
59         mRotationChangeProvider.addCallback(mRotationListener);
60     }
61 
62     @CallSuper
63     @Override
onTransitionProgress(float progress)64     public void onTransitionProgress(float progress) {
65         mMoveFromCenterAnimation.onTransitionProgress(progress);
66     }
67 
68     @CallSuper
69     @Override
onTransitionFinished()70     public void onTransitionFinished() {
71         mAnimationInProgress = false;
72         mRotationChangeProvider.removeCallback(mRotationListener);
73         mMoveFromCenterAnimation.onTransitionFinished();
74         clearRegisteredViews();
75     }
76 
77     /**
78      * Re-prepares views for animation. This is useful in case views are re-bound while the
79      * animation is in progress.
80      */
updateRegisteredViewsIfNeeded()81     public void updateRegisteredViewsIfNeeded() {
82         if (mAnimationInProgress) {
83             clearRegisteredViews();
84             onPrepareViewsForAnimation();
85         }
86     }
87 
clearRegisteredViews()88     private void clearRegisteredViews() {
89         restoreClippings();
90         mMoveFromCenterAnimation.clearRegisteredViews();
91 
92         mOriginalClipChildren.clear();
93         mOriginalClipToPadding.clear();
94     }
95 
onPrepareViewsForAnimation()96     protected void onPrepareViewsForAnimation() {
97 
98     }
99 
registerViewForAnimation(View view)100     protected void registerViewForAnimation(View view) {
101         mMoveFromCenterAnimation.registerViewForAnimation(view);
102     }
103 
104     /**
105      * Sets clipToPadding for the view which then could be restored to the original value
106      * using {@link BaseUnfoldMoveFromCenterAnimator#restoreClippings} method call
107      * @param view view to set the property
108      * @param clipToPadding value of the property
109      */
setClipToPadding(ViewGroup view, boolean clipToPadding)110     protected void setClipToPadding(ViewGroup view, boolean clipToPadding) {
111         mOriginalClipToPadding.put(view, view.getClipToPadding());
112         view.setClipToPadding(clipToPadding);
113     }
114 
115     /**
116      * Sets clipChildren for the view which then could be restored to the original value
117      * using {@link BaseUnfoldMoveFromCenterAnimator#restoreClippings} method call
118      * @param view view to set the property
119      * @param clipChildren value of the property
120      */
setClipChildren(ViewGroup view, boolean clipChildren)121     protected void setClipChildren(ViewGroup view, boolean clipChildren) {
122         mOriginalClipChildren.put(view, view.getClipChildren());
123         view.setClipChildren(clipChildren);
124     }
125 
126     /**
127      * Restores original clip properties after their modifications
128      */
restoreClippings()129     protected void restoreClippings() {
130         mOriginalClipToPadding.forEach(ViewGroup::setClipToPadding);
131         mOriginalClipChildren.forEach(ViewGroup::setClipChildren);
132     }
133 
134     private class UnfoldMoveFromCenterRotationListener implements
135             RotationChangeProvider.RotationListener {
136 
137         @Override
onRotationChanged(@otation int newRotation)138         public void onRotationChanged(@Rotation int newRotation) {
139             mMoveFromCenterAnimation.updateDisplayProperties(newRotation);
140             updateRegisteredViewsIfNeeded();
141         }
142     }
143 }
144