Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| 17 | package com.android.launcher3; |
| 18 | |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.LauncherState.NORMAL; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER; |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 21 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 22 | import android.animation.Animator; |
| 23 | import android.animation.AnimatorListenerAdapter; |
| 24 | import android.animation.AnimatorSet; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.Looper; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 27 | |
| 28 | import androidx.annotation.IntDef; |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 29 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 30 | import com.android.launcher3.anim.AnimationSuccessListener; |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 31 | import com.android.launcher3.anim.AnimatorPlaybackController; |
Sunny Goyal | e3c6d58 | 2017-12-07 12:45:49 -0800 | [diff] [blame] | 32 | import com.android.launcher3.anim.AnimatorSetBuilder; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 33 | import com.android.launcher3.anim.PropertySetter; |
| 34 | import com.android.launcher3.anim.PropertySetter.AnimatedPropertySetter; |
vadimt | 8f9cf2f | 2019-06-10 18:01:58 -0700 | [diff] [blame] | 35 | import com.android.launcher3.compat.AccessibilityManagerCompat; |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 36 | |
Hyunyoung Song | a310a80 | 2019-04-25 13:57:16 -0700 | [diff] [blame] | 37 | import java.io.PrintWriter; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 38 | import java.lang.annotation.Retention; |
| 39 | import java.lang.annotation.RetentionPolicy; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 40 | import java.util.ArrayList; |
| 41 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 42 | /** |
| 43 | * TODO: figure out what kind of tests we can write for this |
| 44 | * |
| 45 | * Things to test when changing the following class. |
| 46 | * - Home from workspace |
| 47 | * - from center screen |
| 48 | * - from other screens |
| 49 | * - Home from all apps |
| 50 | * - from center screen |
| 51 | * - from other screens |
| 52 | * - Back from all apps |
| 53 | * - from center screen |
| 54 | * - from other screens |
| 55 | * - Launch app from workspace and quit |
| 56 | * - with back |
| 57 | * - with home |
| 58 | * - Launch app from all apps and quit |
| 59 | * - with back |
| 60 | * - with home |
| 61 | * - Go to a screen that's not the default, then all |
| 62 | * apps, and launch and app, and go back |
| 63 | * - with back |
| 64 | * -with home |
| 65 | * - On workspace, long press power and go back |
| 66 | * - with back |
| 67 | * - with home |
| 68 | * - On all apps, long press power and go back |
| 69 | * - with back |
| 70 | * - with home |
| 71 | * - On workspace, power off |
| 72 | * - On all apps, power off |
| 73 | * - Launch an app and turn off the screen while in that app |
| 74 | * - Go back with home key |
| 75 | * - Go back with back key TODO: make this not go to workspace |
| 76 | * - From all apps |
| 77 | * - From workspace |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 78 | * - Enter and exit car mode (becase it causes an extra configuration changed) |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 79 | * - From all apps |
| 80 | * - From the center workspace |
| 81 | * - From another workspace |
| 82 | */ |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 83 | public class LauncherStateManager { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 84 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 85 | public static final String TAG = "StateManager"; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 86 | |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 87 | // We separate the state animations into "atomic" and "non-atomic" components. The atomic |
| 88 | // components may be run atomically - that is, all at once, instead of user-controlled. However, |
| 89 | // atomic components are not restricted to this purpose; they can be user-controlled alongside |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 90 | // non atomic components as well. Note that each gesture model has exactly one atomic component, |
| 91 | // ATOMIC_OVERVIEW_SCALE_COMPONENT *or* ATOMIC_OVERVIEW_PEEK_COMPONENT. |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 92 | @IntDef(flag = true, value = { |
| 93 | NON_ATOMIC_COMPONENT, |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 94 | ATOMIC_OVERVIEW_SCALE_COMPONENT, |
| 95 | ATOMIC_OVERVIEW_PEEK_COMPONENT, |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 96 | }) |
| 97 | @Retention(RetentionPolicy.SOURCE) |
| 98 | public @interface AnimationComponents {} |
| 99 | public static final int NON_ATOMIC_COMPONENT = 1 << 0; |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 100 | public static final int ATOMIC_OVERVIEW_SCALE_COMPONENT = 1 << 1; |
| 101 | public static final int ATOMIC_OVERVIEW_PEEK_COMPONENT = 1 << 2; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 102 | |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 103 | public static final int ANIM_ALL = NON_ATOMIC_COMPONENT | ATOMIC_OVERVIEW_SCALE_COMPONENT |
| 104 | | ATOMIC_OVERVIEW_PEEK_COMPONENT; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 105 | |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 106 | private final AnimationConfig mConfig = new AnimationConfig(); |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 107 | private final Handler mUiHandler; |
| 108 | private final Launcher mLauncher; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 109 | private final ArrayList<StateListener> mListeners = new ArrayList<>(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 110 | |
Sunny Goyal | c4bb373 | 2019-06-20 11:34:14 -0700 | [diff] [blame] | 111 | // Animators which are run on properties also controlled by state animations. |
| 112 | private Animator[] mStateElementAnimators; |
| 113 | |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 114 | private StateHandler[] mStateHandlers; |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 115 | private LauncherState mState = NORMAL; |
| 116 | |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 117 | private LauncherState mLastStableState = NORMAL; |
| 118 | private LauncherState mCurrentStableState = NORMAL; |
| 119 | |
Sunny Goyal | af161fd | 2018-02-05 16:34:57 -0800 | [diff] [blame] | 120 | private LauncherState mRestState; |
| 121 | |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 122 | public LauncherStateManager(Launcher l) { |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 123 | mUiHandler = new Handler(Looper.getMainLooper()); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 124 | mLauncher = l; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 127 | public LauncherState getState() { |
| 128 | return mState; |
| 129 | } |
| 130 | |
vadimt | a42dc53 | 2019-04-15 16:50:12 -0700 | [diff] [blame] | 131 | public LauncherState getCurrentStableState() { |
| 132 | return mCurrentStableState; |
| 133 | } |
| 134 | |
Hyunyoung Song | a310a80 | 2019-04-25 13:57:16 -0700 | [diff] [blame] | 135 | public void dump(String prefix, PrintWriter writer) { |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 136 | writer.println(prefix + "LauncherState:"); |
Hyunyoung Song | a310a80 | 2019-04-25 13:57:16 -0700 | [diff] [blame] | 137 | writer.println(prefix + "\tmLastStableState:" + mLastStableState); |
| 138 | writer.println(prefix + "\tmCurrentStableState:" + mCurrentStableState); |
| 139 | writer.println(prefix + "\tmState:" + mState); |
| 140 | writer.println(prefix + "\tmRestState:" + mRestState); |
| 141 | writer.println(prefix + "\tisInTransition:" + (mConfig.mCurrentAnimation != null)); |
| 142 | } |
| 143 | |
Sunny Goyal | de5535a | 2017-12-08 13:39:39 -0800 | [diff] [blame] | 144 | public StateHandler[] getStateHandlers() { |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 145 | if (mStateHandlers == null) { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 146 | mStateHandlers = mLauncher.createStateHandlers(); |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 147 | } |
| 148 | return mStateHandlers; |
| 149 | } |
| 150 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 151 | public void addStateListener(StateListener listener) { |
| 152 | mListeners.add(listener); |
| 153 | } |
| 154 | |
| 155 | public void removeStateListener(StateListener listener) { |
| 156 | mListeners.remove(listener); |
Jon Miranda | 758d504 | 2017-11-08 14:38:23 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 159 | /** |
Sunny Goyal | b52ff22 | 2019-02-14 13:49:36 -0800 | [diff] [blame] | 160 | * Returns true if the state changes should be animated. |
| 161 | */ |
| 162 | public boolean shouldAnimateStateChange() { |
| 163 | return !mLauncher.isForceInvisible() && mLauncher.isStarted(); |
| 164 | } |
| 165 | |
| 166 | /** |
Riddle Hsu | 7a7468f | 2019-11-21 01:32:58 +0800 | [diff] [blame^] | 167 | * @return {@code true} if the state matches the current state and there is no active |
| 168 | * transition to different state. |
| 169 | */ |
| 170 | public boolean isInStableState(LauncherState state) { |
| 171 | return mState == state && mCurrentStableState == state |
| 172 | && (mConfig.mTargetState == null || mConfig.mTargetState == state); |
| 173 | } |
| 174 | |
| 175 | /** |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 176 | * @see #goToState(LauncherState, boolean, Runnable) |
| 177 | */ |
| 178 | public void goToState(LauncherState state) { |
Sunny Goyal | b52ff22 | 2019-02-14 13:49:36 -0800 | [diff] [blame] | 179 | goToState(state, shouldAnimateStateChange()); |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @see #goToState(LauncherState, boolean, Runnable) |
| 184 | */ |
| 185 | public void goToState(LauncherState state, boolean animated) { |
| 186 | goToState(state, animated, 0, null); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Changes the Launcher state to the provided state. |
| 191 | * |
| 192 | * @param animated false if the state should change immediately without any animation, |
| 193 | * true otherwise |
| 194 | * @paras onCompleteRunnable any action to perform at the end of the transition, of null. |
| 195 | */ |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 196 | public void goToState(LauncherState state, boolean animated, Runnable onCompleteRunnable) { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 197 | goToState(state, animated, 0, onCompleteRunnable); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Changes the Launcher state to the provided state after the given delay. |
| 202 | */ |
| 203 | public void goToState(LauncherState state, long delay, Runnable onCompleteRunnable) { |
| 204 | goToState(state, true, delay, onCompleteRunnable); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Changes the Launcher state to the provided state after the given delay. |
| 209 | */ |
| 210 | public void goToState(LauncherState state, long delay) { |
| 211 | goToState(state, true, delay, null); |
| 212 | } |
| 213 | |
Sunny Goyal | ce8809a | 2018-01-18 14:02:47 -0800 | [diff] [blame] | 214 | public void reapplyState() { |
Sunny Goyal | ed2d2bc | 2018-04-19 12:34:43 -0700 | [diff] [blame] | 215 | reapplyState(false); |
| 216 | } |
| 217 | |
| 218 | public void reapplyState(boolean cancelCurrentAnimation) { |
Sunny Goyal | 8be5040 | 2019-06-18 12:02:42 -0700 | [diff] [blame] | 219 | boolean wasInAnimation = mConfig.mCurrentAnimation != null; |
Sunny Goyal | ed2d2bc | 2018-04-19 12:34:43 -0700 | [diff] [blame] | 220 | if (cancelCurrentAnimation) { |
Sunny Goyal | c4bb373 | 2019-06-20 11:34:14 -0700 | [diff] [blame] | 221 | cancelAllStateElementAnimation(); |
Sunny Goyal | ed2d2bc | 2018-04-19 12:34:43 -0700 | [diff] [blame] | 222 | cancelAnimation(); |
| 223 | } |
Sunny Goyal | ce8809a | 2018-01-18 14:02:47 -0800 | [diff] [blame] | 224 | if (mConfig.mCurrentAnimation == null) { |
| 225 | for (StateHandler handler : getStateHandlers()) { |
| 226 | handler.setState(mState); |
| 227 | } |
Sunny Goyal | 8be5040 | 2019-06-18 12:02:42 -0700 | [diff] [blame] | 228 | if (wasInAnimation) { |
| 229 | onStateTransitionEnd(mState); |
| 230 | } |
Sunny Goyal | ce8809a | 2018-01-18 14:02:47 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 234 | private void goToState(LauncherState state, boolean animated, long delay, |
Sunny Goyal | f58e0df | 2018-03-01 10:24:20 -0800 | [diff] [blame] | 235 | final Runnable onCompleteRunnable) { |
Sunny Goyal | 7368fa4 | 2019-04-22 09:58:14 -0700 | [diff] [blame] | 236 | animated &= Utilities.areAnimationsEnabled(mLauncher); |
Sunny Goyal | f58e0df | 2018-03-01 10:24:20 -0800 | [diff] [blame] | 237 | if (mLauncher.isInState(state)) { |
| 238 | if (mConfig.mCurrentAnimation == null) { |
| 239 | // Run any queued runnable |
| 240 | if (onCompleteRunnable != null) { |
| 241 | onCompleteRunnable.run(); |
| 242 | } |
| 243 | return; |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 244 | } else if (!mConfig.userControlled && animated && mConfig.mTargetState == state) { |
Sunny Goyal | f58e0df | 2018-03-01 10:24:20 -0800 | [diff] [blame] | 245 | // We are running the same animation as requested |
| 246 | if (onCompleteRunnable != null) { |
| 247 | mConfig.mCurrentAnimation.addListener(new AnimationSuccessListener() { |
| 248 | @Override |
| 249 | public void onAnimationSuccess(Animator animator) { |
| 250 | onCompleteRunnable.run(); |
| 251 | } |
| 252 | }); |
| 253 | } |
| 254 | return; |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 255 | } |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Tony | 67f9cad | 2018-05-29 17:33:16 -0700 | [diff] [blame] | 258 | // Cancel the current animation. This will reset mState to mCurrentStableState, so store it. |
| 259 | LauncherState fromState = mState; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 260 | mConfig.reset(); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 261 | |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 262 | if (!animated) { |
Sunny Goyal | c4bb373 | 2019-06-20 11:34:14 -0700 | [diff] [blame] | 263 | cancelAllStateElementAnimation(); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 264 | onStateTransitionStart(state); |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 265 | for (StateHandler handler : getStateHandlers()) { |
| 266 | handler.setState(state); |
| 267 | } |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 268 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 269 | onStateTransitionEnd(state); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 270 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 271 | // Run any queued runnable |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 272 | if (onCompleteRunnable != null) { |
| 273 | onCompleteRunnable.run(); |
| 274 | } |
| 275 | return; |
| 276 | } |
| 277 | |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 278 | if (delay > 0) { |
| 279 | // Create the animation after the delay as some properties can change between preparing |
| 280 | // the animation and running the animation. |
| 281 | int startChangeId = mConfig.mChangeId; |
| 282 | mUiHandler.postDelayed(() -> { |
| 283 | if (mConfig.mChangeId == startChangeId) { |
| 284 | goToStateAnimated(state, fromState, onCompleteRunnable); |
| 285 | } |
| 286 | }, delay); |
| 287 | } else { |
| 288 | goToStateAnimated(state, fromState, onCompleteRunnable); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | private void goToStateAnimated(LauncherState state, LauncherState fromState, |
| 293 | Runnable onCompleteRunnable) { |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 294 | // Since state NORMAL can be reached from multiple states, just assume that the |
| 295 | // transition plays in reverse and use the same duration as previous state. |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 296 | mConfig.duration = state == NORMAL |
| 297 | ? fromState.getTransitionDuration(mLauncher) |
| 298 | : state.getTransitionDuration(mLauncher); |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 299 | |
Tony Wickham | b2ddf10 | 2018-05-16 12:23:12 -0700 | [diff] [blame] | 300 | AnimatorSetBuilder builder = new AnimatorSetBuilder(); |
Tony | 67f9cad | 2018-05-29 17:33:16 -0700 | [diff] [blame] | 301 | prepareForAtomicAnimation(fromState, state, builder); |
Sunny Goyal | e3c6d58 | 2017-12-07 12:45:49 -0800 | [diff] [blame] | 302 | AnimatorSet animation = createAnimationToNewWorkspaceInternal( |
Tony Wickham | b2ddf10 | 2018-05-16 12:23:12 -0700 | [diff] [blame] | 303 | state, builder, onCompleteRunnable); |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 304 | mUiHandler.post(new StartAnimRunnable(animation)); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 307 | /** |
Tony Wickham | b2ddf10 | 2018-05-16 12:23:12 -0700 | [diff] [blame] | 308 | * Prepares for a non-user controlled animation from fromState to toState. Preparations include: |
| 309 | * - Setting interpolators for various animations included in the state transition. |
| 310 | * - Setting some start values (e.g. scale) for views that are hidden but about to be shown. |
| 311 | */ |
| 312 | public void prepareForAtomicAnimation(LauncherState fromState, LauncherState toState, |
| 313 | AnimatorSetBuilder builder) { |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 314 | toState.prepareForAtomicAnimation(mLauncher, fromState, builder); |
Tony Wickham | b2ddf10 | 2018-05-16 12:23:12 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 317 | public AnimatorSet createAtomicAnimation(LauncherState fromState, LauncherState toState, |
| 318 | AnimatorSetBuilder builder, @AnimationComponents int atomicComponent, long duration) { |
| 319 | prepareForAtomicAnimation(fromState, toState, builder); |
| 320 | AnimationConfig config = new AnimationConfig(); |
| 321 | config.animComponents = atomicComponent; |
| 322 | config.duration = duration; |
| 323 | for (StateHandler handler : mLauncher.getStateManager().getStateHandlers()) { |
| 324 | handler.setStateWithAnimation(toState, builder, config); |
| 325 | } |
| 326 | return builder.build(); |
| 327 | } |
| 328 | |
Tony Wickham | b2ddf10 | 2018-05-16 12:23:12 -0700 | [diff] [blame] | 329 | /** |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 330 | * Creates a {@link AnimatorPlaybackController} that can be used for a controlled |
Sunny Goyal | d936f6a | 2018-06-01 12:18:19 -0700 | [diff] [blame] | 331 | * state transition. The UI is force-set to fromState before creating the controller. |
| 332 | * @param fromState the initial state for the transition. |
| 333 | * @param state the final state for the transition. |
| 334 | * @param duration intended duration for normal playback. Use higher duration for better |
| 335 | * accuracy. |
| 336 | */ |
| 337 | public AnimatorPlaybackController createAnimationToNewWorkspace( |
| 338 | LauncherState fromState, LauncherState state, long duration) { |
Sunny Goyal | 379e8e0 | 2018-07-12 14:59:09 -0700 | [diff] [blame] | 339 | // Since we are creating a state animation to a different state, temporarily prevent state |
| 340 | // change as part of config reset. |
| 341 | LauncherState originalRestState = mRestState; |
| 342 | mRestState = state; |
Sunny Goyal | d936f6a | 2018-06-01 12:18:19 -0700 | [diff] [blame] | 343 | mConfig.reset(); |
Sunny Goyal | 379e8e0 | 2018-07-12 14:59:09 -0700 | [diff] [blame] | 344 | mRestState = originalRestState; |
| 345 | |
Sunny Goyal | d936f6a | 2018-06-01 12:18:19 -0700 | [diff] [blame] | 346 | for (StateHandler handler : getStateHandlers()) { |
| 347 | handler.setState(fromState); |
| 348 | } |
| 349 | |
| 350 | return createAnimationToNewWorkspace(state, duration); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Creates a {@link AnimatorPlaybackController} that can be used for a controlled |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 355 | * state transition. |
| 356 | * @param state the final state for the transition. |
| 357 | * @param duration intended duration for normal playback. Use higher duration for better |
| 358 | * accuracy. |
| 359 | */ |
Sunny Goyal | 8552517 | 2017-11-06 13:00:42 -0800 | [diff] [blame] | 360 | public AnimatorPlaybackController createAnimationToNewWorkspace( |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 361 | LauncherState state, long duration) { |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 362 | return createAnimationToNewWorkspace(state, duration, LauncherStateManager.ANIM_ALL); |
| 363 | } |
| 364 | |
| 365 | public AnimatorPlaybackController createAnimationToNewWorkspace( |
| 366 | LauncherState state, long duration, @AnimationComponents int animComponents) { |
| 367 | return createAnimationToNewWorkspace(state, new AnimatorSetBuilder(), duration, null, |
| 368 | animComponents); |
Sunny Goyal | e3c6d58 | 2017-12-07 12:45:49 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 371 | public AnimatorPlaybackController createAnimationToNewWorkspace(LauncherState state, |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 372 | AnimatorSetBuilder builder, long duration, Runnable onCancelRunnable, |
| 373 | @AnimationComponents int animComponents) { |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 374 | mConfig.reset(); |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 375 | mConfig.userControlled = true; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 376 | mConfig.animComponents = animComponents; |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 377 | mConfig.duration = duration; |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 378 | mConfig.playbackController = AnimatorPlaybackController.wrap( |
| 379 | createAnimationToNewWorkspaceInternal(state, builder, null), duration, |
| 380 | onCancelRunnable); |
| 381 | return mConfig.playbackController; |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | protected AnimatorSet createAnimationToNewWorkspaceInternal(final LauncherState state, |
Sunny Goyal | e3c6d58 | 2017-12-07 12:45:49 -0800 | [diff] [blame] | 385 | AnimatorSetBuilder builder, final Runnable onCompleteRunnable) { |
Jon Miranda | 8b08a1f | 2018-02-15 11:32:25 -0800 | [diff] [blame] | 386 | |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 387 | for (StateHandler handler : getStateHandlers()) { |
Sunny Goyal | 3c585dd | 2017-12-07 11:42:33 -0800 | [diff] [blame] | 388 | handler.setStateWithAnimation(state, builder, mConfig); |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 389 | } |
Sunny Goyal | e3c6d58 | 2017-12-07 12:45:49 -0800 | [diff] [blame] | 390 | |
| 391 | final AnimatorSet animation = builder.build(); |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 392 | animation.addListener(new AnimationSuccessListener() { |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 393 | |
| 394 | @Override |
| 395 | public void onAnimationStart(Animator animation) { |
| 396 | // Change the internal state only when the transition actually starts |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 397 | onStateTransitionStart(state); |
Jon Miranda | 758d504 | 2017-11-08 14:38:23 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | @Override |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 401 | public void onAnimationSuccess(Animator animator) { |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 402 | // Run any queued runnables |
| 403 | if (onCompleteRunnable != null) { |
| 404 | onCompleteRunnable.run(); |
| 405 | } |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 406 | onStateTransitionEnd(state); |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 407 | } |
| 408 | }); |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 409 | mConfig.setAnimation(animation, state); |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 410 | return mConfig.mCurrentAnimation; |
Tony Wickham | 6d1bbe3 | 2015-09-16 12:06:38 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 413 | private void onStateTransitionStart(LauncherState state) { |
Matthew Ng | f8fafa2 | 2018-06-13 16:36:29 -0700 | [diff] [blame] | 414 | if (mState != state) { |
| 415 | mState.onStateDisabled(mLauncher); |
| 416 | } |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 417 | mState = state; |
| 418 | mState.onStateEnabled(mLauncher); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 419 | mLauncher.onStateSetStart(mState); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 420 | |
| 421 | if (state.disablePageClipping) { |
| 422 | // Only disable clipping if needed, otherwise leave it as previous value. |
| 423 | mLauncher.getWorkspace().setClipChildren(false); |
| 424 | } |
Sunny Goyal | 7f45514 | 2019-01-28 11:56:13 -0800 | [diff] [blame] | 425 | |
| 426 | for (int i = mListeners.size() - 1; i >= 0; i--) { |
| 427 | mListeners.get(i).onStateTransitionStart(state); |
| 428 | } |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | private void onStateTransitionEnd(LauncherState state) { |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 432 | // Only change the stable states after the transitions have finished |
| 433 | if (state != mCurrentStableState) { |
| 434 | mLastStableState = state.getHistoryForState(mCurrentStableState); |
| 435 | mCurrentStableState = state; |
| 436 | } |
| 437 | |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 438 | state.onStateTransitionEnd(mLauncher); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 439 | mLauncher.onStateSetEnd(state); |
Sunny Goyal | af161fd | 2018-02-05 16:34:57 -0800 | [diff] [blame] | 440 | |
| 441 | if (state == NORMAL) { |
| 442 | setRestState(null); |
| 443 | } |
Winson Chung | d782394 | 2018-02-16 03:23:47 +0000 | [diff] [blame] | 444 | |
Sunny Goyal | 7f45514 | 2019-01-28 11:56:13 -0800 | [diff] [blame] | 445 | for (int i = mListeners.size() - 1; i >= 0; i--) { |
| 446 | mListeners.get(i).onStateTransitionComplete(state); |
| 447 | } |
vadimt | 8f9cf2f | 2019-06-10 18:01:58 -0700 | [diff] [blame] | 448 | |
| 449 | AccessibilityManagerCompat.sendStateEventToTest(mLauncher, state.ordinal); |
Winson Chung | d782394 | 2018-02-16 03:23:47 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 452 | public LauncherState getLastState() { |
| 453 | return mLastStableState; |
| 454 | } |
| 455 | |
Sunny Goyal | af161fd | 2018-02-05 16:34:57 -0800 | [diff] [blame] | 456 | public void moveToRestState() { |
Sunny Goyal | 6586062 | 2018-03-12 13:40:58 -0700 | [diff] [blame] | 457 | if (mConfig.mCurrentAnimation != null && mConfig.userControlled) { |
| 458 | // The user is doing something. Lets not mess it up |
| 459 | return; |
| 460 | } |
Sunny Goyal | af161fd | 2018-02-05 16:34:57 -0800 | [diff] [blame] | 461 | if (mState.disableRestore) { |
| 462 | goToState(getRestState()); |
| 463 | // Reset history |
| 464 | mLastStableState = NORMAL; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | public LauncherState getRestState() { |
| 469 | return mRestState == null ? NORMAL : mRestState; |
| 470 | } |
| 471 | |
| 472 | public void setRestState(LauncherState restState) { |
| 473 | mRestState = restState; |
| 474 | } |
| 475 | |
Tony Wickham | 6d1bbe3 | 2015-09-16 12:06:38 -0700 | [diff] [blame] | 476 | /** |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 477 | * Cancels the current animation. |
| 478 | */ |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 479 | public void cancelAnimation() { |
| 480 | mConfig.reset(); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 481 | } |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 482 | |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 483 | public void setCurrentUserControlledAnimation(AnimatorPlaybackController controller) { |
Sunny Goyal | d6692ce | 2018-06-06 18:41:32 +0000 | [diff] [blame] | 484 | clearCurrentAnimation(); |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 485 | setCurrentAnimation(controller.getTarget()); |
| 486 | mConfig.userControlled = true; |
| 487 | mConfig.playbackController = controller; |
| 488 | } |
| 489 | |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 490 | /** |
| 491 | * Sets the animation as the current state animation, i.e., canceled when |
| 492 | * starting another animation and may block some launcher interactions while running. |
Sunny Goyal | b35f50c | 2018-04-09 16:30:51 -0700 | [diff] [blame] | 493 | * |
| 494 | * @param childAnimations Set of animations with the new target is controlling. |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 495 | */ |
Sunny Goyal | b35f50c | 2018-04-09 16:30:51 -0700 | [diff] [blame] | 496 | public void setCurrentAnimation(AnimatorSet anim, Animator... childAnimations) { |
| 497 | for (Animator childAnim : childAnimations) { |
Sunny Goyal | a6616de | 2018-05-04 10:09:41 -0700 | [diff] [blame] | 498 | if (childAnim == null) { |
| 499 | continue; |
| 500 | } |
| 501 | if (mConfig.playbackController != null |
| 502 | && mConfig.playbackController.getTarget() == childAnim) { |
Tony Wickham | d4ece9a | 2018-05-10 09:55:07 -0700 | [diff] [blame] | 503 | clearCurrentAnimation(); |
Sunny Goyal | a6616de | 2018-05-04 10:09:41 -0700 | [diff] [blame] | 504 | break; |
| 505 | } else if (mConfig.mCurrentAnimation == childAnim) { |
Tony Wickham | d4ece9a | 2018-05-10 09:55:07 -0700 | [diff] [blame] | 506 | clearCurrentAnimation(); |
Sunny Goyal | b35f50c | 2018-04-09 16:30:51 -0700 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | } |
Sunny Goyal | 1c6d566 | 2018-04-02 15:27:28 -0700 | [diff] [blame] | 510 | boolean reapplyNeeded = mConfig.mCurrentAnimation != null; |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 511 | cancelAnimation(); |
Sunny Goyal | 1c6d566 | 2018-04-02 15:27:28 -0700 | [diff] [blame] | 512 | if (reapplyNeeded) { |
| 513 | reapplyState(); |
Sunny Goyal | 9cc1b2f | 2019-05-03 11:53:12 -0700 | [diff] [blame] | 514 | // Dispatch on transition end, so that any transient property is cleared. |
| 515 | onStateTransitionEnd(mState); |
Sunny Goyal | 1c6d566 | 2018-04-02 15:27:28 -0700 | [diff] [blame] | 516 | } |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 517 | mConfig.setAnimation(anim, null); |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Sunny Goyal | c4bb373 | 2019-06-20 11:34:14 -0700 | [diff] [blame] | 520 | private void cancelAllStateElementAnimation() { |
| 521 | if (mStateElementAnimators == null) { |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | for (Animator animator : mStateElementAnimators) { |
| 526 | if (animator != null) { |
| 527 | animator.cancel(); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * Cancels a currently running gesture animation |
| 534 | */ |
| 535 | public void cancelStateElementAnimation(int index) { |
| 536 | if (mStateElementAnimators == null) { |
| 537 | return; |
| 538 | } |
| 539 | if (mStateElementAnimators[index] != null) { |
| 540 | mStateElementAnimators[index].cancel(); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | public Animator createStateElementAnimation(int index, float... values) { |
| 545 | cancelStateElementAnimation(index); |
| 546 | LauncherAppTransitionManager latm = mLauncher.getAppTransitionManager(); |
| 547 | if (mStateElementAnimators == null) { |
| 548 | mStateElementAnimators = new Animator[latm.getStateElementAnimationsCount()]; |
| 549 | } |
| 550 | Animator anim = latm.createStateElementAnimation(index, values); |
| 551 | mStateElementAnimators[index] = anim; |
| 552 | anim.addListener(new AnimatorListenerAdapter() { |
| 553 | @Override |
| 554 | public void onAnimationEnd(Animator animation) { |
| 555 | mStateElementAnimators[index] = null; |
| 556 | } |
| 557 | }); |
| 558 | return anim; |
| 559 | } |
| 560 | |
Tony Wickham | d4ece9a | 2018-05-10 09:55:07 -0700 | [diff] [blame] | 561 | private void clearCurrentAnimation() { |
| 562 | if (mConfig.mCurrentAnimation != null) { |
| 563 | mConfig.mCurrentAnimation.removeListener(mConfig); |
| 564 | mConfig.mCurrentAnimation = null; |
| 565 | } |
| 566 | mConfig.playbackController = null; |
| 567 | } |
| 568 | |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 569 | private class StartAnimRunnable implements Runnable { |
| 570 | |
| 571 | private final AnimatorSet mAnim; |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 572 | |
Vadim Tryshev | 1b0c503 | 2018-05-23 12:54:27 -0700 | [diff] [blame] | 573 | public StartAnimRunnable(AnimatorSet anim) { |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 574 | mAnim = anim; |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Override |
| 578 | public void run() { |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 579 | if (mConfig.mCurrentAnimation != mAnim) { |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 580 | return; |
| 581 | } |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 582 | mAnim.start(); |
| 583 | } |
| 584 | } |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 585 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 586 | public static class AnimationConfig extends AnimatorListenerAdapter { |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 587 | public long duration; |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 588 | public boolean userControlled; |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 589 | public AnimatorPlaybackController playbackController; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 590 | public @AnimationComponents int animComponents = ANIM_ALL; |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 591 | private PropertySetter mPropertySetter; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 592 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 593 | private AnimatorSet mCurrentAnimation; |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 594 | private LauncherState mTargetState; |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 595 | // Id to keep track of config changes, to tie an animation with the corresponding request |
| 596 | private int mChangeId = 0; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 597 | |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 598 | /** |
| 599 | * Cancels the current animation and resets config variables. |
| 600 | */ |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 601 | public void reset() { |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 602 | duration = 0; |
Sunny Goyal | 0310220 | 2017-10-27 11:05:26 -0700 | [diff] [blame] | 603 | userControlled = false; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 604 | animComponents = ANIM_ALL; |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 605 | mPropertySetter = null; |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 606 | mTargetState = null; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 607 | |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 608 | if (playbackController != null) { |
| 609 | playbackController.getAnimationPlayer().cancel(); |
| 610 | playbackController.dispatchOnCancel(); |
| 611 | } else if (mCurrentAnimation != null) { |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 612 | mCurrentAnimation.setDuration(0); |
| 613 | mCurrentAnimation.cancel(); |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 614 | } |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 615 | |
| 616 | mCurrentAnimation = null; |
| 617 | playbackController = null; |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 618 | mChangeId ++; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 621 | public PropertySetter getPropertySetter(AnimatorSetBuilder builder) { |
| 622 | if (mPropertySetter == null) { |
| 623 | mPropertySetter = duration == 0 ? NO_ANIM_PROPERTY_SETTER |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 624 | : new AnimatedPropertySetter(duration, builder); |
| 625 | } |
Tony | 31fbd4c | 2018-04-27 12:33:24 -0500 | [diff] [blame] | 626 | return mPropertySetter; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 629 | @Override |
| 630 | public void onAnimationEnd(Animator animation) { |
Sunny Goyal | 87a6ad1 | 2018-06-05 11:56:08 -0700 | [diff] [blame] | 631 | if (playbackController != null && playbackController.getTarget() == animation) { |
| 632 | playbackController = null; |
| 633 | } |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 634 | if (mCurrentAnimation == animation) { |
| 635 | mCurrentAnimation = null; |
| 636 | } |
| 637 | } |
| 638 | |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 639 | public void setAnimation(AnimatorSet animation, LauncherState targetState) { |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 640 | mCurrentAnimation = animation; |
Sunny Goyal | d754dcd | 2018-04-12 14:16:42 -0700 | [diff] [blame] | 641 | mTargetState = targetState; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 642 | mCurrentAnimation.addListener(this); |
| 643 | } |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 644 | |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 645 | public boolean playAtomicOverviewScaleComponent() { |
| 646 | return (animComponents & ATOMIC_OVERVIEW_SCALE_COMPONENT) != 0; |
| 647 | } |
| 648 | |
| 649 | public boolean playAtomicOverviewPeekComponent() { |
| 650 | return (animComponents & ATOMIC_OVERVIEW_PEEK_COMPONENT) != 0; |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | public boolean playNonAtomicComponent() { |
| 654 | return (animComponents & NON_ATOMIC_COMPONENT) != 0; |
| 655 | } |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 656 | } |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 657 | |
| 658 | public interface StateHandler { |
| 659 | |
| 660 | /** |
| 661 | * Updates the UI to {@param state} without any animations |
| 662 | */ |
| 663 | void setState(LauncherState state); |
| 664 | |
| 665 | /** |
| 666 | * Sets the UI to {@param state} by animating any changes. |
| 667 | */ |
Sunny Goyal | 3c585dd | 2017-12-07 11:42:33 -0800 | [diff] [blame] | 668 | void setStateWithAnimation(LauncherState toState, |
Sunny Goyal | e3c6d58 | 2017-12-07 12:45:49 -0800 | [diff] [blame] | 669 | AnimatorSetBuilder builder, AnimationConfig config); |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 670 | } |
Jon Miranda | 758d504 | 2017-11-08 14:38:23 -0800 | [diff] [blame] | 671 | |
| 672 | public interface StateListener { |
| 673 | |
Jon Miranda | 758d504 | 2017-11-08 14:38:23 -0800 | [diff] [blame] | 674 | void onStateTransitionStart(LauncherState toState); |
| 675 | void onStateTransitionComplete(LauncherState finalState); |
| 676 | } |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 677 | } |