2015-03-02 11:51:23 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
2015-05-26 23:03:31 -07:00
|
|
|
|
2015-05-22 11:12:27 -07:00
|
|
|
import com.android.launcher3.allapps.AllAppsContainerView;
|
2016-06-06 14:19:02 -07:00
|
|
|
import com.android.launcher3.allapps.AllAppsTransitionController;
|
2016-10-26 18:32:38 -07:00
|
|
|
import com.android.launcher3.anim.AnimationLayerSet;
|
2017-03-28 12:23:22 -07:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2015-03-18 14:16:05 -07:00
|
|
|
import com.android.launcher3.util.Thunk;
|
2015-05-26 23:03:31 -07:00
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
/**
|
|
|
|
|
* TODO: figure out what kind of tests we can write for this
|
|
|
|
|
*
|
|
|
|
|
* Things to test when changing the following class.
|
|
|
|
|
* - Home from workspace
|
|
|
|
|
* - from center screen
|
|
|
|
|
* - from other screens
|
|
|
|
|
* - Home from all apps
|
|
|
|
|
* - from center screen
|
|
|
|
|
* - from other screens
|
|
|
|
|
* - Back from all apps
|
|
|
|
|
* - from center screen
|
|
|
|
|
* - from other screens
|
|
|
|
|
* - Launch app from workspace and quit
|
|
|
|
|
* - with back
|
|
|
|
|
* - with home
|
|
|
|
|
* - Launch app from all apps and quit
|
|
|
|
|
* - with back
|
|
|
|
|
* - with home
|
|
|
|
|
* - Go to a screen that's not the default, then all
|
|
|
|
|
* apps, and launch and app, and go back
|
|
|
|
|
* - with back
|
|
|
|
|
* -with home
|
|
|
|
|
* - On workspace, long press power and go back
|
|
|
|
|
* - with back
|
|
|
|
|
* - with home
|
|
|
|
|
* - On all apps, long press power and go back
|
|
|
|
|
* - with back
|
|
|
|
|
* - with home
|
|
|
|
|
* - On workspace, power off
|
|
|
|
|
* - On all apps, power off
|
|
|
|
|
* - Launch an app and turn off the screen while in that app
|
|
|
|
|
* - Go back with home key
|
|
|
|
|
* - Go back with back key TODO: make this not go to workspace
|
|
|
|
|
* - From all apps
|
|
|
|
|
* - From workspace
|
|
|
|
|
* - Enter and exit car mode (becuase it causes an extra configuration changed)
|
|
|
|
|
* - From all apps
|
|
|
|
|
* - From the center workspace
|
|
|
|
|
* - From another workspace
|
|
|
|
|
*/
|
|
|
|
|
public class LauncherStateTransitionAnimation {
|
|
|
|
|
|
2016-01-29 13:14:14 -08:00
|
|
|
public static final String TAG = "LSTAnimation";
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
private final AnimationConfig mConfig = new AnimationConfig();
|
2015-03-18 14:16:05 -07:00
|
|
|
@Thunk Launcher mLauncher;
|
2015-08-03 14:40:11 -07:00
|
|
|
@Thunk AnimatorSet mCurrentAnimation;
|
2016-06-06 14:19:02 -07:00
|
|
|
AllAppsTransitionController mAllAppsController;
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
public LauncherStateTransitionAnimation(Launcher l, AllAppsTransitionController allAppsController) {
|
2015-03-02 11:51:23 -08:00
|
|
|
mLauncher = l;
|
2016-06-06 14:19:02 -07:00
|
|
|
mAllAppsController = allAppsController;
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starts an animation to the apps view.
|
|
|
|
|
*/
|
2017-10-16 11:46:41 -07:00
|
|
|
public void startAnimationToAllApps(boolean animated) {
|
2015-05-22 11:12:27 -07:00
|
|
|
final AllAppsContainerView toView = mLauncher.getAppsView();
|
2017-10-10 15:21:15 -07:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
// If for some reason our views aren't initialized, don't animate
|
|
|
|
|
animated = animated && (toView != null);
|
|
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
|
|
|
|
|
|
|
|
|
|
final AnimationLayerSet layerViews = new AnimationLayerSet();
|
|
|
|
|
|
|
|
|
|
// Cancel the current animation
|
|
|
|
|
cancelAnimation();
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
if (!animated) {
|
2017-10-17 17:17:16 -07:00
|
|
|
mLauncher.getWorkspace().setState(LauncherState.ALL_APPS);
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
mAllAppsController.finishPullUp();
|
|
|
|
|
toView.setTranslationX(0.0f);
|
|
|
|
|
toView.setTranslationY(0.0f);
|
|
|
|
|
toView.setScaleX(1.0f);
|
|
|
|
|
toView.setScaleY(1.0f);
|
|
|
|
|
toView.setAlpha(1.0f);
|
|
|
|
|
toView.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
if (!FeatureFlags.LAUNCHER3_PHYSICS) {
|
|
|
|
|
// We are animating the content view alpha, so ensure we have a layer for it.
|
|
|
|
|
layerViews.addView(toView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animation.addListener(new AnimatorListenerAdapter() {
|
2015-07-10 14:33:23 -07:00
|
|
|
@Override
|
2017-10-10 15:21:15 -07:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
cleanupAnimation();
|
2016-04-19 18:30:24 -07:00
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
2015-07-10 14:33:23 -07:00
|
|
|
}
|
2017-10-10 15:21:15 -07:00
|
|
|
});
|
2017-10-16 11:46:41 -07:00
|
|
|
|
|
|
|
|
mConfig.reset();
|
|
|
|
|
mAllAppsController.animateToAllApps(animation, mConfig);
|
2017-10-17 17:17:16 -07:00
|
|
|
mLauncher.getWorkspace().setStateWithAnimation(LauncherState.ALL_APPS,
|
2017-10-16 11:46:41 -07:00
|
|
|
layerViews, animation, mConfig);
|
2017-10-10 15:21:15 -07:00
|
|
|
|
|
|
|
|
Runnable startAnimRunnable = new StartAnimRunnable(animation, toView);
|
|
|
|
|
mCurrentAnimation = animation;
|
|
|
|
|
mCurrentAnimation.addListener(layerViews);
|
2017-10-16 11:46:41 -07:00
|
|
|
if (mConfig.shouldPost) {
|
2017-10-10 15:21:15 -07:00
|
|
|
toView.post(startAnimRunnable);
|
|
|
|
|
} else {
|
|
|
|
|
startAnimRunnable.run();
|
|
|
|
|
}
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-09-16 12:06:38 -07:00
|
|
|
* Starts an animation to the workspace from the current overlay view.
|
2015-03-02 11:51:23 -08:00
|
|
|
*/
|
2017-10-18 10:55:56 -07:00
|
|
|
public void startAnimationToWorkspace(final LauncherState toWorkspaceState,
|
2015-08-07 10:37:21 -07:00
|
|
|
final boolean animated, final Runnable onCompleteRunnable) {
|
2017-10-17 17:17:16 -07:00
|
|
|
if (toWorkspaceState != LauncherState.NORMAL &&
|
|
|
|
|
toWorkspaceState != LauncherState.SPRING_LOADED &&
|
|
|
|
|
toWorkspaceState != LauncherState.OVERVIEW) {
|
2015-03-02 11:51:23 -08:00
|
|
|
Log.e(TAG, "Unexpected call to startAnimationToWorkspace");
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 10:55:56 -07:00
|
|
|
if (mLauncher.isInState(LauncherState.ALL_APPS) || mAllAppsController.isTransitioning()) {
|
|
|
|
|
startAnimationToWorkspaceFromAllApps(mLauncher.getWorkspace().getState(),
|
|
|
|
|
toWorkspaceState, animated, onCompleteRunnable);
|
2015-09-16 12:06:38 -07:00
|
|
|
} else {
|
2017-10-18 10:55:56 -07:00
|
|
|
startAnimationToNewWorkspaceState(toWorkspaceState, animated, onCompleteRunnable);
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-09-16 12:06:38 -07:00
|
|
|
* Starts an animation to the workspace from the apps view.
|
2015-03-02 11:51:23 -08:00
|
|
|
*/
|
2017-10-17 17:17:16 -07:00
|
|
|
private void startAnimationToWorkspaceFromAllApps(final LauncherState fromWorkspaceState,
|
|
|
|
|
final LauncherState toWorkspaceState, boolean animated,
|
2015-08-07 10:37:21 -07:00
|
|
|
final Runnable onCompleteRunnable) {
|
2017-10-10 15:21:15 -07:00
|
|
|
final AllAppsContainerView fromView = mLauncher.getAppsView();
|
2017-10-16 11:46:41 -07:00
|
|
|
// If for some reason our views aren't initialized, don't animate
|
|
|
|
|
animated = animated & (fromView != null);
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
|
2016-10-26 18:32:38 -07:00
|
|
|
final AnimationLayerSet layerViews = new AnimationLayerSet();
|
2015-03-02 11:51:23 -08:00
|
|
|
|
|
|
|
|
// Cancel the current animation
|
|
|
|
|
cancelAnimation();
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
if (!animated) {
|
2017-10-17 17:17:16 -07:00
|
|
|
if (fromWorkspaceState == LauncherState.ALL_APPS) {
|
2016-07-27 12:48:09 -07:00
|
|
|
mAllAppsController.finishPullDown();
|
2016-06-06 21:04:36 -07:00
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
fromView.setVisibility(View.GONE);
|
2017-10-16 11:46:41 -07:00
|
|
|
mLauncher.getWorkspace().setState(toWorkspaceState);
|
2017-10-10 15:21:15 -07:00
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
2015-10-02 16:22:08 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
// Run any queued runnables
|
|
|
|
|
if (onCompleteRunnable != null) {
|
|
|
|
|
onCompleteRunnable.run();
|
|
|
|
|
}
|
2016-08-03 15:14:43 -07:00
|
|
|
return;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
animation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
boolean canceled = false;
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
|
canceled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (canceled) return;
|
|
|
|
|
// Run any queued runnables
|
|
|
|
|
if (onCompleteRunnable != null) {
|
|
|
|
|
onCompleteRunnable.run();
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
2017-10-10 15:21:15 -07:00
|
|
|
|
|
|
|
|
cleanupAnimation();
|
|
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
});
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
mConfig.reset();
|
|
|
|
|
mAllAppsController.animateToWorkspace(animation, mConfig);
|
|
|
|
|
mLauncher.getWorkspace().setStateWithAnimation(toWorkspaceState, layerViews, animation,
|
|
|
|
|
mConfig);
|
|
|
|
|
|
|
|
|
|
Runnable startAnimRunnable = new StartAnimRunnable(animation, mLauncher.getWorkspace());
|
2017-10-10 15:21:15 -07:00
|
|
|
mCurrentAnimation = animation;
|
|
|
|
|
mCurrentAnimation.addListener(layerViews);
|
2017-10-16 11:46:41 -07:00
|
|
|
if (mConfig.shouldPost) {
|
2017-10-10 15:21:15 -07:00
|
|
|
fromView.post(startAnimRunnable);
|
|
|
|
|
} else {
|
|
|
|
|
startAnimRunnable.run();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
/**
|
|
|
|
|
* Starts an animation to the workspace from another workspace state, e.g. normal to overview.
|
|
|
|
|
*/
|
2017-10-18 10:55:56 -07:00
|
|
|
private void startAnimationToNewWorkspaceState(
|
2017-10-17 17:17:16 -07:00
|
|
|
final LauncherState toWorkspaceState, final boolean animated,
|
2017-10-10 15:21:15 -07:00
|
|
|
final Runnable onCompleteRunnable) {
|
|
|
|
|
// Cancel the current animation
|
|
|
|
|
cancelAnimation();
|
|
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
if (!animated) {
|
|
|
|
|
mLauncher.getWorkspace().setState(toWorkspaceState);
|
2017-10-10 15:21:15 -07:00
|
|
|
// Run any queued runnables
|
|
|
|
|
if (onCompleteRunnable != null) {
|
|
|
|
|
onCompleteRunnable.run();
|
2016-08-03 15:14:43 -07:00
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
return;
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2017-10-19 11:22:07 -07:00
|
|
|
final AnimatorSet animation =
|
|
|
|
|
createAnimationToNewWorkspace(toWorkspaceState, onCompleteRunnable);
|
|
|
|
|
mLauncher.getWorkspace().post(new StartAnimRunnable(animation, null));
|
|
|
|
|
mCurrentAnimation = animation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected AnimatorSet createAnimationToNewWorkspace(LauncherState state,
|
|
|
|
|
final Runnable onCompleteRunnable) {
|
|
|
|
|
cancelAnimation();
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
final AnimationLayerSet layerViews = new AnimationLayerSet();
|
|
|
|
|
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
|
|
|
|
|
mConfig.reset();
|
2017-10-19 11:22:07 -07:00
|
|
|
mLauncher.getWorkspace().setStateWithAnimation(state, layerViews, animation, mConfig);
|
2017-10-16 11:46:41 -07:00
|
|
|
|
|
|
|
|
animation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
// Run any queued runnables
|
|
|
|
|
if (onCompleteRunnable != null) {
|
|
|
|
|
onCompleteRunnable.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This can hold unnecessary references to views.
|
|
|
|
|
cleanupAnimation();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
animation.addListener(layerViews);
|
2017-10-19 11:22:07 -07:00
|
|
|
return animation;
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancels the current animation.
|
|
|
|
|
*/
|
|
|
|
|
private void cancelAnimation() {
|
2015-08-03 14:40:11 -07:00
|
|
|
if (mCurrentAnimation != null) {
|
|
|
|
|
mCurrentAnimation.setDuration(0);
|
|
|
|
|
mCurrentAnimation.cancel();
|
|
|
|
|
mCurrentAnimation = null;
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
}
|
2015-08-03 14:40:11 -07:00
|
|
|
|
2015-08-05 12:32:47 -07:00
|
|
|
@Thunk void cleanupAnimation() {
|
2015-08-03 14:40:11 -07:00
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
2016-10-26 19:12:47 -07:00
|
|
|
|
|
|
|
|
private class StartAnimRunnable implements Runnable {
|
|
|
|
|
|
|
|
|
|
private final AnimatorSet mAnim;
|
|
|
|
|
private final View mViewToFocus;
|
|
|
|
|
|
|
|
|
|
public StartAnimRunnable(AnimatorSet anim, View viewToFocus) {
|
|
|
|
|
mAnim = anim;
|
|
|
|
|
mViewToFocus = viewToFocus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (mCurrentAnimation != mAnim) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mViewToFocus != null) {
|
|
|
|
|
mViewToFocus.requestFocus();
|
|
|
|
|
}
|
|
|
|
|
mAnim.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
|
|
|
|
|
public static class AnimationConfig {
|
|
|
|
|
public boolean shouldPost;
|
|
|
|
|
|
|
|
|
|
private long mOverriddenDuration = -1;
|
|
|
|
|
|
|
|
|
|
public void reset() {
|
|
|
|
|
shouldPost = false;
|
|
|
|
|
mOverriddenDuration = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void overrideDuration(long duration) {
|
|
|
|
|
mOverriddenDuration = duration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getDuration(long defaultDuration) {
|
|
|
|
|
return mOverriddenDuration >= 0 ? mOverriddenDuration : defaultDuration;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-26 23:03:31 -07:00
|
|
|
}
|