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 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.AnimatorSet; |
| 22 | import android.animation.ObjectAnimator; |
| 23 | import android.animation.PropertyValuesHolder; |
| 24 | import android.animation.TimeInterpolator; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 25 | import android.annotation.SuppressLint; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 26 | import android.content.res.Resources; |
| 27 | import android.util.Log; |
| 28 | import android.view.View; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 29 | import android.view.animation.AccelerateInterpolator; |
| 30 | import android.view.animation.DecelerateInterpolator; |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 31 | |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 32 | import com.android.launcher3.allapps.AllAppsContainerView; |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 33 | import com.android.launcher3.util.UiThreadCircularReveal; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 34 | import com.android.launcher3.util.Thunk; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 35 | import com.android.launcher3.widget.WidgetsContainerView; |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 36 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 37 | import java.util.HashMap; |
| 38 | |
| 39 | /** |
| 40 | * TODO: figure out what kind of tests we can write for this |
| 41 | * |
| 42 | * Things to test when changing the following class. |
| 43 | * - Home from workspace |
| 44 | * - from center screen |
| 45 | * - from other screens |
| 46 | * - Home from all apps |
| 47 | * - from center screen |
| 48 | * - from other screens |
| 49 | * - Back from all apps |
| 50 | * - from center screen |
| 51 | * - from other screens |
| 52 | * - Launch app from workspace and quit |
| 53 | * - with back |
| 54 | * - with home |
| 55 | * - Launch app from all apps and quit |
| 56 | * - with back |
| 57 | * - with home |
| 58 | * - Go to a screen that's not the default, then all |
| 59 | * apps, and launch and app, and go back |
| 60 | * - with back |
| 61 | * -with home |
| 62 | * - On workspace, long press power and go back |
| 63 | * - with back |
| 64 | * - with home |
| 65 | * - On all apps, long press power and go back |
| 66 | * - with back |
| 67 | * - with home |
| 68 | * - On workspace, power off |
| 69 | * - On all apps, power off |
| 70 | * - Launch an app and turn off the screen while in that app |
| 71 | * - Go back with home key |
| 72 | * - Go back with back key TODO: make this not go to workspace |
| 73 | * - From all apps |
| 74 | * - From workspace |
| 75 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 76 | * - From all apps |
| 77 | * - From the center workspace |
| 78 | * - From another workspace |
| 79 | */ |
| 80 | public class LauncherStateTransitionAnimation { |
| 81 | |
| 82 | /** |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 83 | * Private callbacks made during transition setup. |
| 84 | */ |
| 85 | static abstract class PrivateTransitionCallbacks { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 86 | float getMaterialRevealViewFinalAlpha(View revealView) { |
| 87 | return 0; |
| 88 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 89 | float getMaterialRevealViewStartFinalRadius() { |
| 90 | return 0; |
| 91 | } |
| 92 | AnimatorListenerAdapter getMaterialRevealViewAnimatorListener(View revealView, |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 93 | View buttonView) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 94 | return null; |
| 95 | } |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 96 | void onTransitionComplete() {} |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | public static final String TAG = "LauncherStateTransitionAnimation"; |
| 100 | |
| 101 | // Flags to determine how to set the layers on views before the transition animation |
| 102 | public static final int BUILD_LAYER = 0; |
| 103 | public static final int BUILD_AND_SET_LAYER = 1; |
| 104 | public static final int SINGLE_FRAME_DELAY = 16; |
| 105 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 106 | @Thunk Launcher mLauncher; |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 107 | @Thunk AnimatorSet mCurrentAnimation; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 108 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 109 | public LauncherStateTransitionAnimation(Launcher l) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 110 | mLauncher = l; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Starts an animation to the apps view. |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 115 | * |
| 116 | * @param startSearchAfterTransition Immediately starts app search after the transition to |
| 117 | * All Apps is completed. |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 118 | */ |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 119 | public void startAnimationToAllApps(final Workspace.State fromWorkspaceState, |
| 120 | final boolean animated, final boolean startSearchAfterTransition) { |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 121 | final AllAppsContainerView toView = mLauncher.getAppsView(); |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 122 | final View buttonView = mLauncher.getAllAppsButton(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 123 | PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 124 | @Override |
| 125 | public float getMaterialRevealViewFinalAlpha(View revealView) { |
| 126 | return 1f; |
| 127 | } |
| 128 | @Override |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 129 | public float getMaterialRevealViewStartFinalRadius() { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 130 | int allAppsButtonSize = mLauncher.getDeviceProfile().allAppsButtonVisualSize; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 131 | return allAppsButtonSize / 2; |
| 132 | } |
| 133 | @Override |
| 134 | public AnimatorListenerAdapter getMaterialRevealViewAnimatorListener( |
| 135 | final View revealView, final View allAppsButtonView) { |
| 136 | return new AnimatorListenerAdapter() { |
| 137 | public void onAnimationStart(Animator animation) { |
| 138 | allAppsButtonView.setVisibility(View.INVISIBLE); |
| 139 | } |
| 140 | public void onAnimationEnd(Animator animation) { |
| 141 | allAppsButtonView.setVisibility(View.VISIBLE); |
| 142 | } |
| 143 | }; |
| 144 | } |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 145 | @Override |
| 146 | void onTransitionComplete() { |
| 147 | if (startSearchAfterTransition) { |
| 148 | toView.startAppsSearch(); |
| 149 | } |
| 150 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 151 | }; |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 152 | // Only animate the search bar if animating from spring loaded mode back to all apps |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 153 | mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState, |
| 154 | Workspace.State.NORMAL_HIDDEN, buttonView, toView, toView.getContentView(), |
| 155 | toView.getRevealView(), toView.getSearchBarView(), animated, cb); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Starts an animation to the widgets view. |
| 160 | */ |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 161 | public void startAnimationToWidgets(final Workspace.State fromWorkspaceState, |
| 162 | final boolean animated) { |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 163 | final WidgetsContainerView toView = mLauncher.getWidgetsView(); |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 164 | final View buttonView = mLauncher.getWidgetsButton(); |
| 165 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 166 | PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() { |
| 167 | @Override |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 168 | public float getMaterialRevealViewFinalAlpha(View revealView) { |
| 169 | return 0.3f; |
| 170 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 171 | }; |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 172 | mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState, |
| 173 | Workspace.State.OVERVIEW_HIDDEN, buttonView, toView, toView.getContentView(), |
| 174 | toView.getRevealView(), null, animated, cb); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Starts and animation to the workspace from the current overlay view. |
| 179 | */ |
| 180 | public void startAnimationToWorkspace(final Launcher.State fromState, |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 181 | final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState, |
| 182 | final int toWorkspacePage, final boolean animated, final Runnable onCompleteRunnable) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 183 | if (toWorkspaceState != Workspace.State.NORMAL && |
| 184 | toWorkspaceState != Workspace.State.SPRING_LOADED && |
| 185 | toWorkspaceState != Workspace.State.OVERVIEW) { |
| 186 | Log.e(TAG, "Unexpected call to startAnimationToWorkspace"); |
| 187 | } |
| 188 | |
| 189 | if (fromState == Launcher.State.APPS || fromState == Launcher.State.APPS_SPRING_LOADED) { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 190 | startAnimationToWorkspaceFromAllApps(fromWorkspaceState, toWorkspaceState, toWorkspacePage, |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 191 | animated, onCompleteRunnable); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 192 | } else { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 193 | startAnimationToWorkspaceFromWidgets(fromWorkspaceState, toWorkspaceState, toWorkspacePage, |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 194 | animated, onCompleteRunnable); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Creates and starts a new animation to a particular overlay view. |
| 200 | */ |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 201 | @SuppressLint("NewApi") |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 202 | private AnimatorSet startAnimationToOverlay(final Workspace.State fromWorkspaceState, |
| 203 | final Workspace.State toWorkspaceState, final View buttonView, final View toView, |
| 204 | final View contentView, final View revealView, final View overlaySearchBarView, |
| 205 | final boolean animated, final PrivateTransitionCallbacks pCb) { |
| 206 | final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 207 | final Resources res = mLauncher.getResources(); |
| 208 | final boolean material = Utilities.isLmpOrAbove(); |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 209 | final int revealDuration = res.getInteger(R.integer.config_overlayRevealTime); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 210 | final int itemsAlphaStagger = |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 211 | res.getInteger(R.integer.config_overlayItemsAlphaStagger); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 212 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 213 | final View fromView = mLauncher.getWorkspace(); |
| 214 | |
| 215 | final HashMap<View, Integer> layerViews = new HashMap<>(); |
| 216 | |
| 217 | // If for some reason our views aren't initialized, don't animate |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 218 | boolean initialized = buttonView != null; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 219 | |
| 220 | // Cancel the current animation |
| 221 | cancelAnimation(); |
| 222 | |
| 223 | // Create the workspace animation. |
| 224 | // NOTE: this call apparently also sets the state for the workspace if !animated |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 225 | Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState, -1, |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 226 | animated, layerViews); |
| 227 | |
| 228 | // Animate the search bar |
| 229 | startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState, |
| 230 | animated ? revealDuration : 0, overlaySearchBarView); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 231 | |
| 232 | if (animated && initialized) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 233 | // Setup the reveal view animation |
| 234 | int width = revealView.getMeasuredWidth(); |
| 235 | int height = revealView.getMeasuredHeight(); |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 236 | float revealRadius = (float) Math.hypot(width / 2, height / 2); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 237 | revealView.setVisibility(View.VISIBLE); |
| 238 | revealView.setAlpha(0f); |
| 239 | revealView.setTranslationY(0f); |
| 240 | revealView.setTranslationX(0f); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 241 | |
| 242 | // Calculate the final animation values |
| 243 | final float revealViewToAlpha; |
| 244 | final float revealViewToXDrift; |
| 245 | final float revealViewToYDrift; |
| 246 | if (material) { |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 247 | int[] buttonViewToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 248 | buttonView, null); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 249 | revealViewToAlpha = pCb.getMaterialRevealViewFinalAlpha(revealView); |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 250 | revealViewToYDrift = buttonViewToPanelDelta[1]; |
| 251 | revealViewToXDrift = buttonViewToPanelDelta[0]; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 252 | } else { |
| 253 | revealViewToAlpha = 0f; |
| 254 | revealViewToYDrift = 2 * height / 3; |
| 255 | revealViewToXDrift = 0; |
| 256 | } |
| 257 | |
| 258 | // Create the animators |
| 259 | PropertyValuesHolder panelAlpha = |
| 260 | PropertyValuesHolder.ofFloat("alpha", revealViewToAlpha, 1f); |
| 261 | PropertyValuesHolder panelDriftY = |
| 262 | PropertyValuesHolder.ofFloat("translationY", revealViewToYDrift, 0); |
| 263 | PropertyValuesHolder panelDriftX = |
| 264 | PropertyValuesHolder.ofFloat("translationX", revealViewToXDrift, 0); |
| 265 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 266 | panelAlpha, panelDriftY, panelDriftX); |
| 267 | panelAlphaAndDrift.setDuration(revealDuration); |
| 268 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 269 | |
| 270 | // Play the animation |
| 271 | layerViews.put(revealView, BUILD_AND_SET_LAYER); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 272 | animation.play(panelAlphaAndDrift); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 273 | |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 274 | if (overlaySearchBarView != null) { |
| 275 | overlaySearchBarView.setAlpha(0f); |
| 276 | ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(overlaySearchBarView, "alpha", 0f, 1f); |
| 277 | searchBarAlpha.setDuration(100); |
| 278 | searchBarAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 279 | layerViews.put(overlaySearchBarView, BUILD_AND_SET_LAYER); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 280 | animation.play(searchBarAlpha); |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 283 | // Setup the animation for the content view |
| 284 | contentView.setVisibility(View.VISIBLE); |
| 285 | contentView.setAlpha(0f); |
| 286 | contentView.setTranslationY(revealViewToYDrift); |
| 287 | layerViews.put(contentView, BUILD_AND_SET_LAYER); |
| 288 | |
| 289 | // Create the individual animators |
| 290 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(contentView, "translationY", |
| 291 | revealViewToYDrift, 0); |
| 292 | pageDrift.setDuration(revealDuration); |
| 293 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 294 | pageDrift.setStartDelay(itemsAlphaStagger); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 295 | animation.play(pageDrift); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 296 | |
| 297 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(contentView, "alpha", 0f, 1f); |
| 298 | itemsAlpha.setDuration(revealDuration); |
| 299 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 300 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 301 | animation.play(itemsAlpha); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 302 | |
| 303 | if (material) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 304 | float startRadius = pCb.getMaterialRevealViewStartFinalRadius(); |
| 305 | AnimatorListenerAdapter listener = pCb.getMaterialRevealViewAnimatorListener( |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 306 | revealView, buttonView); |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 307 | Animator reveal = UiThreadCircularReveal.createCircularReveal(revealView, width / 2, |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 308 | height / 2, startRadius, revealRadius); |
| 309 | reveal.setDuration(revealDuration); |
| 310 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 311 | if (listener != null) { |
| 312 | reveal.addListener(listener); |
| 313 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 314 | animation.play(reveal); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 317 | animation.addListener(new AnimatorListenerAdapter() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 318 | @Override |
| 319 | public void onAnimationEnd(Animator animation) { |
| 320 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 321 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 322 | |
| 323 | // Hide the reveal view |
| 324 | revealView.setVisibility(View.INVISIBLE); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 325 | |
| 326 | // Disable all necessary layers |
| 327 | for (View v : layerViews.keySet()) { |
| 328 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 329 | v.setLayerType(View.LAYER_TYPE_NONE, null); |
| 330 | } |
| 331 | } |
| 332 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 333 | // This can hold unnecessary references to views. |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 334 | cleanupAnimation(); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 335 | pCb.onTransitionComplete(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | }); |
| 339 | |
| 340 | // Play the workspace animation |
| 341 | if (workspaceAnim != null) { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 342 | animation.play(workspaceAnim); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | // Dispatch the prepare transition signal |
| 346 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 347 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
| 348 | |
| 349 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 350 | final AnimatorSet stateAnimation = animation; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 351 | final Runnable startAnimRunnable = new Runnable() { |
| 352 | public void run() { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 353 | // Check that mCurrentAnimation hasn't changed while |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 354 | // we waited for a layout/draw pass |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 355 | if (mCurrentAnimation != stateAnimation) |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 356 | return; |
| 357 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 358 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 359 | |
| 360 | // Enable all necessary layers |
Winson Chung | 11509ad | 2015-05-12 18:55:26 -0700 | [diff] [blame] | 361 | boolean isLmpOrAbove = Utilities.isLmpOrAbove(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 362 | for (View v : layerViews.keySet()) { |
| 363 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 364 | v.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 365 | } |
Winson Chung | 11509ad | 2015-05-12 18:55:26 -0700 | [diff] [blame] | 366 | if (isLmpOrAbove && Utilities.isViewAttachedToWindow(v)) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 367 | v.buildLayer(); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // Focus the new view |
| 372 | toView.requestFocus(); |
| 373 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 374 | stateAnimation.start(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 375 | } |
| 376 | }; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 377 | toView.bringToFront(); |
| 378 | toView.setVisibility(View.VISIBLE); |
| 379 | toView.post(startAnimRunnable); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 380 | |
| 381 | return animation; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 382 | } else { |
| 383 | toView.setTranslationX(0.0f); |
| 384 | toView.setTranslationY(0.0f); |
| 385 | toView.setScaleX(1.0f); |
| 386 | toView.setScaleY(1.0f); |
| 387 | toView.setVisibility(View.VISIBLE); |
| 388 | toView.bringToFront(); |
| 389 | |
| 390 | // Show the content view |
| 391 | contentView.setVisibility(View.VISIBLE); |
| 392 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 393 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 394 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 395 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 396 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
| 397 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 398 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 399 | pCb.onTransitionComplete(); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 400 | |
| 401 | return null; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Starts and animation to the workspace from the apps view. |
| 407 | */ |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 408 | private void startAnimationToWorkspaceFromAllApps(final Workspace.State fromWorkspaceState, |
| 409 | final Workspace.State toWorkspaceState, final int toWorkspacePage, |
| 410 | final boolean animated, final Runnable onCompleteRunnable) { |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 411 | AllAppsContainerView appsView = mLauncher.getAppsView(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 412 | PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 413 | @Override |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 414 | float getMaterialRevealViewFinalAlpha(View revealView) { |
| 415 | // No alpha anim from all apps |
| 416 | return 1f; |
| 417 | } |
| 418 | @Override |
| 419 | float getMaterialRevealViewStartFinalRadius() { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 420 | int allAppsButtonSize = mLauncher.getDeviceProfile().allAppsButtonVisualSize; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 421 | return allAppsButtonSize / 2; |
| 422 | } |
| 423 | @Override |
| 424 | public AnimatorListenerAdapter getMaterialRevealViewAnimatorListener( |
| 425 | final View revealView, final View allAppsButtonView) { |
| 426 | return new AnimatorListenerAdapter() { |
| 427 | public void onAnimationStart(Animator animation) { |
| 428 | // We set the alpha instead of visibility to ensure that the focus does not |
| 429 | // get taken from the all apps view |
| 430 | allAppsButtonView.setVisibility(View.VISIBLE); |
| 431 | allAppsButtonView.setAlpha(0f); |
| 432 | } |
| 433 | public void onAnimationEnd(Animator animation) { |
| 434 | // Hide the reveal view |
| 435 | revealView.setVisibility(View.INVISIBLE); |
| 436 | |
| 437 | // Show the all apps button, and focus it |
| 438 | allAppsButtonView.setAlpha(1f); |
| 439 | } |
| 440 | }; |
| 441 | } |
| 442 | }; |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 443 | // Only animate the search bar if animating to spring loaded mode from all apps |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 444 | mCurrentAnimation = startAnimationToWorkspaceFromOverlay(fromWorkspaceState, toWorkspaceState, |
| 445 | toWorkspacePage, mLauncher.getAllAppsButton(), appsView, appsView.getContentView(), |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 446 | appsView.getRevealView(), appsView.getSearchBarView(), animated, |
| 447 | onCompleteRunnable, cb); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Starts and animation to the workspace from the widgets view. |
| 452 | */ |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 453 | private void startAnimationToWorkspaceFromWidgets(final Workspace.State fromWorkspaceState, |
| 454 | final Workspace.State toWorkspaceState, final int toWorkspacePage, |
| 455 | final boolean animated, final Runnable onCompleteRunnable) { |
Hyunyoung Song | 4cea4c8 | 2015-04-17 19:02:30 -0700 | [diff] [blame] | 456 | final WidgetsContainerView widgetsView = mLauncher.getWidgetsView(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 457 | PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() { |
| 458 | @Override |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 459 | float getMaterialRevealViewFinalAlpha(View revealView) { |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 460 | return 0.3f; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 461 | } |
| 462 | @Override |
| 463 | public AnimatorListenerAdapter getMaterialRevealViewAnimatorListener( |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 464 | final View revealView, final View widgetsButtonView) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 465 | return new AnimatorListenerAdapter() { |
| 466 | public void onAnimationEnd(Animator animation) { |
| 467 | // Hide the reveal view |
| 468 | revealView.setVisibility(View.INVISIBLE); |
| 469 | } |
| 470 | }; |
| 471 | } |
| 472 | }; |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 473 | mCurrentAnimation = startAnimationToWorkspaceFromOverlay(fromWorkspaceState, |
| 474 | toWorkspaceState, toWorkspacePage, mLauncher.getWidgetsButton(), widgetsView, |
| 475 | widgetsView.getContentView(), widgetsView.getRevealView(), null, animated, |
| 476 | onCompleteRunnable, cb); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Creates and starts a new animation to the workspace. |
| 481 | */ |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 482 | private AnimatorSet startAnimationToWorkspaceFromOverlay(final Workspace.State fromWorkspaceState, |
| 483 | final Workspace.State toWorkspaceState, final int toWorkspacePage, final View buttonView, |
| 484 | final View fromView, final View contentView, final View revealView, |
| 485 | final View overlaySearchBarView, final boolean animated, final Runnable onCompleteRunnable, |
| 486 | final PrivateTransitionCallbacks pCb) { |
| 487 | final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 488 | final Resources res = mLauncher.getResources(); |
| 489 | final boolean material = Utilities.isLmpOrAbove(); |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 490 | final int revealDuration = res.getInteger(R.integer.config_overlayRevealTime); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 491 | final int itemsAlphaStagger = |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 492 | res.getInteger(R.integer.config_overlayItemsAlphaStagger); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 493 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 494 | final View toView = mLauncher.getWorkspace(); |
| 495 | |
| 496 | final HashMap<View, Integer> layerViews = new HashMap<>(); |
| 497 | |
| 498 | // If for some reason our views aren't initialized, don't animate |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 499 | boolean initialized = buttonView != null; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 500 | |
| 501 | // Cancel the current animation |
| 502 | cancelAnimation(); |
| 503 | |
| 504 | // Create the workspace animation. |
| 505 | // NOTE: this call apparently also sets the state for the workspace if !animated |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 506 | Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState, |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 507 | toWorkspacePage, animated, layerViews); |
| 508 | |
| 509 | // Animate the search bar |
| 510 | startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState, |
| 511 | animated ? revealDuration : 0, overlaySearchBarView); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 512 | |
| 513 | if (animated && initialized) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 514 | // Play the workspace animation |
| 515 | if (workspaceAnim != null) { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 516 | animation.play(workspaceAnim); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 520 | // don't perform all these no-op animations. In particularly, this was causing |
| 521 | // the all-apps button to pop in and out. |
| 522 | if (fromView.getVisibility() == View.VISIBLE) { |
| 523 | int width = revealView.getMeasuredWidth(); |
| 524 | int height = revealView.getMeasuredHeight(); |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 525 | float revealRadius = (float) Math.hypot(width / 2, height / 2); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 526 | revealView.setVisibility(View.VISIBLE); |
| 527 | revealView.setAlpha(1f); |
| 528 | revealView.setTranslationY(0); |
| 529 | layerViews.put(revealView, BUILD_AND_SET_LAYER); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 530 | |
| 531 | // Calculate the final animation values |
| 532 | final float revealViewToXDrift; |
| 533 | final float revealViewToYDrift; |
| 534 | if (material) { |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 535 | int[] buttonViewToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 536 | buttonView, null); |
| 537 | revealViewToYDrift = buttonViewToPanelDelta[1]; |
| 538 | revealViewToXDrift = buttonViewToPanelDelta[0]; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 539 | } else { |
| 540 | revealViewToYDrift = 2 * height / 3; |
| 541 | revealViewToXDrift = 0; |
| 542 | } |
| 543 | |
| 544 | // The vertical motion of the apps panel should be delayed by one frame |
| 545 | // from the conceal animation in order to give the right feel. We correspondingly |
| 546 | // shorten the duration so that the slide and conceal end at the same time. |
| 547 | TimeInterpolator decelerateInterpolator = material ? |
| 548 | new LogDecelerateInterpolator(100, 0) : |
| 549 | new DecelerateInterpolator(1f); |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 550 | ObjectAnimator panelDriftY = ObjectAnimator.ofFloat(revealView, "translationY", |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 551 | 0, revealViewToYDrift); |
| 552 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 553 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 554 | panelDriftY.setInterpolator(decelerateInterpolator); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 555 | animation.play(panelDriftY); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 556 | |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 557 | ObjectAnimator panelDriftX = ObjectAnimator.ofFloat(revealView, "translationX", |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 558 | 0, revealViewToXDrift); |
| 559 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 560 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 561 | panelDriftX.setInterpolator(decelerateInterpolator); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 562 | animation.play(panelDriftX); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 563 | |
| 564 | // Setup animation for the reveal panel alpha |
| 565 | final float revealViewToAlpha = !material ? 0f : |
| 566 | pCb.getMaterialRevealViewFinalAlpha(revealView); |
| 567 | if (revealViewToAlpha != 1f) { |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 568 | ObjectAnimator panelAlpha = ObjectAnimator.ofFloat(revealView, "alpha", |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 569 | 1f, revealViewToAlpha); |
| 570 | panelAlpha.setDuration(material ? revealDuration : 150); |
| 571 | panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 572 | panelAlpha.setInterpolator(decelerateInterpolator); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 573 | animation.play(panelAlpha); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | // Setup the animation for the content view |
| 577 | layerViews.put(contentView, BUILD_AND_SET_LAYER); |
| 578 | |
| 579 | // Create the individual animators |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 580 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(contentView, "translationY", |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 581 | 0, revealViewToYDrift); |
| 582 | contentView.setTranslationY(0); |
| 583 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 584 | pageDrift.setInterpolator(decelerateInterpolator); |
| 585 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 586 | animation.play(pageDrift); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 587 | |
| 588 | contentView.setAlpha(1f); |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 589 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(contentView, "alpha", 1f, 0f); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 590 | itemsAlpha.setDuration(100); |
| 591 | itemsAlpha.setInterpolator(decelerateInterpolator); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 592 | animation.play(itemsAlpha); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 593 | |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 594 | if (overlaySearchBarView != null) { |
| 595 | overlaySearchBarView.setAlpha(1f); |
| 596 | ObjectAnimator searchAlpha = ObjectAnimator.ofFloat(overlaySearchBarView, "alpha", 1f, 0f); |
| 597 | searchAlpha.setDuration(material ? 100 : 150); |
| 598 | searchAlpha.setInterpolator(decelerateInterpolator); |
| 599 | searchAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 600 | layerViews.put(overlaySearchBarView, BUILD_AND_SET_LAYER); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 601 | animation.play(searchAlpha); |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 604 | if (material) { |
| 605 | // Animate the all apps button |
| 606 | float finalRadius = pCb.getMaterialRevealViewStartFinalRadius(); |
| 607 | AnimatorListenerAdapter listener = |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 608 | pCb.getMaterialRevealViewAnimatorListener(revealView, buttonView); |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 609 | Animator reveal = UiThreadCircularReveal.createCircularReveal(revealView, width / 2, |
| 610 | height / 2, revealRadius, finalRadius); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 611 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 612 | reveal.setDuration(revealDuration); |
| 613 | reveal.setStartDelay(itemsAlphaStagger); |
| 614 | if (listener != null) { |
| 615 | reveal.addListener(listener); |
| 616 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 617 | animation.play(reveal); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 621 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 622 | } |
| 623 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 624 | animation.addListener(new AnimatorListenerAdapter() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 625 | @Override |
| 626 | public void onAnimationEnd(Animator animation) { |
| 627 | fromView.setVisibility(View.GONE); |
| 628 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 629 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
| 630 | |
| 631 | // Run any queued runnables |
| 632 | if (onCompleteRunnable != null) { |
| 633 | onCompleteRunnable.run(); |
| 634 | } |
| 635 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 636 | // Disable all necessary layers |
| 637 | for (View v : layerViews.keySet()) { |
| 638 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 639 | v.setLayerType(View.LAYER_TYPE_NONE, null); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | // Reset page transforms |
| 644 | if (contentView != null) { |
| 645 | contentView.setTranslationX(0); |
| 646 | contentView.setTranslationY(0); |
| 647 | contentView.setAlpha(1); |
| 648 | } |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 649 | if (overlaySearchBarView != null) { |
| 650 | overlaySearchBarView.setAlpha(1f); |
| 651 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 652 | |
| 653 | // This can hold unnecessary references to views. |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 654 | cleanupAnimation(); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 655 | pCb.onTransitionComplete(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 656 | } |
| 657 | }); |
| 658 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 659 | final AnimatorSet stateAnimation = animation; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 660 | final Runnable startAnimRunnable = new Runnable() { |
| 661 | public void run() { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 662 | // Check that mCurrentAnimation hasn't changed while |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 663 | // we waited for a layout/draw pass |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 664 | if (mCurrentAnimation != stateAnimation) |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 665 | return; |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 666 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 667 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 668 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 669 | |
| 670 | // Enable all necessary layers |
Winson Chung | 11509ad | 2015-05-12 18:55:26 -0700 | [diff] [blame] | 671 | boolean isLmpOrAbove = Utilities.isLmpOrAbove(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 672 | for (View v : layerViews.keySet()) { |
| 673 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 674 | v.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 675 | } |
Winson Chung | 11509ad | 2015-05-12 18:55:26 -0700 | [diff] [blame] | 676 | if (isLmpOrAbove && Utilities.isViewAttachedToWindow(v)) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 677 | v.buildLayer(); |
| 678 | } |
| 679 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 680 | stateAnimation.start(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 681 | } |
| 682 | }; |
| 683 | fromView.post(startAnimRunnable); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 684 | |
| 685 | return animation; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 686 | } else { |
| 687 | fromView.setVisibility(View.GONE); |
| 688 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 689 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 690 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 691 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 692 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 693 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 694 | pCb.onTransitionComplete(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 695 | |
| 696 | // Run any queued runnables |
| 697 | if (onCompleteRunnable != null) { |
| 698 | onCompleteRunnable.run(); |
| 699 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 700 | |
| 701 | return null; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 705 | /** |
| 706 | * Coordinates the workspace search bar animation along with the launcher state animation. |
| 707 | */ |
| 708 | private void startWorkspaceSearchBarAnimation(AnimatorSet animation, |
| 709 | final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState, int duration, |
| 710 | View overlaySearchBar) { |
| 711 | final SearchDropTargetBar.State toSearchBarState = |
| 712 | toWorkspaceState.getSearchDropTargetBarState(); |
| 713 | |
| 714 | if (overlaySearchBar != null) { |
| 715 | if ((toWorkspaceState == Workspace.State.NORMAL) && |
| 716 | (fromWorkspaceState == Workspace.State.NORMAL_HIDDEN)) { |
| 717 | // If we are transitioning from the overlay to the workspace, then show the |
| 718 | // workspace search bar immediately and let the overlay search bar fade out on top |
| 719 | mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, 0); |
| 720 | } else if (fromWorkspaceState == Workspace.State.NORMAL) { |
| 721 | // If we are transitioning from the workspace to the overlay, then keep the |
| 722 | // workspace search bar visible until the overlay search bar fades in on top |
| 723 | animation.addListener(new AnimatorListenerAdapter() { |
| 724 | @Override |
| 725 | public void onAnimationEnd(Animator animation) { |
| 726 | mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, 0); |
| 727 | } |
| 728 | }); |
| 729 | } else { |
| 730 | // Otherwise, then just animate the workspace search bar normally |
| 731 | mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, duration); |
| 732 | } |
| 733 | } else { |
| 734 | // If there is no overlay search bar, then just animate the workspace search bar |
| 735 | mLauncher.getSearchDropTargetBar().animateToState(toSearchBarState, duration); |
| 736 | } |
| 737 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 738 | |
| 739 | /** |
| 740 | * Dispatches the prepare-transition event to suitable views. |
| 741 | */ |
| 742 | void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 743 | if (v instanceof LauncherTransitionable) { |
| 744 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(mLauncher, animated, |
| 745 | toWorkspace); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Dispatches the start-transition event to suitable views. |
| 751 | */ |
| 752 | void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 753 | if (v instanceof LauncherTransitionable) { |
| 754 | ((LauncherTransitionable) v).onLauncherTransitionStart(mLauncher, animated, |
| 755 | toWorkspace); |
| 756 | } |
| 757 | |
| 758 | // Update the workspace transition step as well |
| 759 | dispatchOnLauncherTransitionStep(v, 0f); |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Dispatches the step-transition event to suitable views. |
| 764 | */ |
| 765 | void dispatchOnLauncherTransitionStep(View v, float t) { |
| 766 | if (v instanceof LauncherTransitionable) { |
| 767 | ((LauncherTransitionable) v).onLauncherTransitionStep(mLauncher, t); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Dispatches the end-transition event to suitable views. |
| 773 | */ |
| 774 | void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 775 | if (v instanceof LauncherTransitionable) { |
| 776 | ((LauncherTransitionable) v).onLauncherTransitionEnd(mLauncher, animated, |
| 777 | toWorkspace); |
| 778 | } |
| 779 | |
| 780 | // Update the workspace transition step as well |
| 781 | dispatchOnLauncherTransitionStep(v, 1f); |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * Cancels the current animation. |
| 786 | */ |
| 787 | private void cancelAnimation() { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 788 | if (mCurrentAnimation != null) { |
| 789 | mCurrentAnimation.setDuration(0); |
| 790 | mCurrentAnimation.cancel(); |
| 791 | mCurrentAnimation = null; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 792 | } |
| 793 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 794 | |
Sunny Goyal | d1ea63f | 2015-08-05 12:32:47 -0700 | [diff] [blame] | 795 | @Thunk void cleanupAnimation() { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 796 | mCurrentAnimation = null; |
| 797 | } |
Adam Cohen | 1558893 | 2015-05-26 23:03:31 -0700 | [diff] [blame] | 798 | } |