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;
|
2017-10-20 17:05:27 -07:00
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Looper;
|
2015-03-02 11:51:23 -08:00
|
|
|
import android.view.View;
|
2015-05-26 23:03:31 -07:00
|
|
|
|
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-10-20 17:05:27 -07:00
|
|
|
import com.android.launcher3.anim.AnimationSuccessListener;
|
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();
|
2017-10-20 17:05:27 -07:00
|
|
|
private final Handler mUiHandler;
|
|
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
private final AllAppsTransitionController mAllAppsController;
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
public LauncherStateTransitionAnimation(
|
|
|
|
|
Launcher l, AllAppsTransitionController allAppsController) {
|
|
|
|
|
mUiHandler = new Handler(Looper.getMainLooper());
|
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
|
|
|
}
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
public void goToState(LauncherState state, boolean animated, Runnable onCompleteRunnable) {
|
2017-10-10 15:21:15 -07:00
|
|
|
// Cancel the current animation
|
2017-10-16 11:46:41 -07:00
|
|
|
mConfig.reset();
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
if (!animated) {
|
2017-10-20 17:05:27 -07:00
|
|
|
mAllAppsController.setFinalProgress(state.verticalProgress);
|
|
|
|
|
mLauncher.getWorkspace().setState(state);
|
2017-10-10 15:21:15 -07:00
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
2015-10-02 16:22:08 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
// Run any queued runnable
|
2016-06-06 14:19:02 -07:00
|
|
|
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-20 17:05:27 -07:00
|
|
|
AnimatorSet animation = createAnimationToNewWorkspace(state, onCompleteRunnable);
|
|
|
|
|
Runnable runnable = new StartAnimRunnable(animation, state.getFinalFocus(mLauncher));
|
2017-10-16 11:46:41 -07:00
|
|
|
if (mConfig.shouldPost) {
|
2017-10-20 17:05:27 -07:00
|
|
|
mUiHandler.post(runnable);
|
2017-10-10 15:21:15 -07:00
|
|
|
} else {
|
2017-10-20 17:05:27 -07:00
|
|
|
runnable.run();
|
2017-10-10 15:21:15 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2017-10-19 11:22:07 -07:00
|
|
|
protected AnimatorSet createAnimationToNewWorkspace(LauncherState state,
|
|
|
|
|
final Runnable onCompleteRunnable) {
|
2017-10-20 17:05:27 -07:00
|
|
|
mConfig.reset();
|
2017-10-19 11:22:07 -07:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
|
2017-10-20 17:05:27 -07:00
|
|
|
final AnimationLayerSet layerViews = new AnimationLayerSet();
|
|
|
|
|
|
|
|
|
|
mAllAppsController.animateToFinalProgress(state.verticalProgress,
|
|
|
|
|
state.hasVerticalSpring, animation, mConfig);
|
|
|
|
|
mLauncher.getWorkspace().setStateWithAnimation(state,
|
|
|
|
|
layerViews, animation, mConfig);
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
animation.addListener(layerViews);
|
|
|
|
|
animation.addListener(new AnimationSuccessListener() {
|
2017-10-16 11:46:41 -07:00
|
|
|
@Override
|
2017-10-20 17:05:27 -07:00
|
|
|
public void onAnimationSuccess(Animator animator) {
|
2017-10-16 11:46:41 -07:00
|
|
|
// Run any queued runnables
|
|
|
|
|
if (onCompleteRunnable != null) {
|
|
|
|
|
onCompleteRunnable.run();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
|
2017-10-16 11:46:41 -07:00
|
|
|
}
|
|
|
|
|
});
|
2017-10-20 17:05:27 -07:00
|
|
|
mConfig.setAnimation(animation);
|
|
|
|
|
return mConfig.mCurrentAnimation;
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancels the current animation.
|
|
|
|
|
*/
|
2017-10-20 17:05:27 -07:00
|
|
|
public void cancelAnimation() {
|
|
|
|
|
mConfig.reset();
|
2015-08-03 14:40:11 -07:00
|
|
|
}
|
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() {
|
2017-10-20 17:05:27 -07:00
|
|
|
if (mConfig.mCurrentAnimation != mAnim) {
|
2016-10-26 19:12:47 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mViewToFocus != null) {
|
|
|
|
|
mViewToFocus.requestFocus();
|
|
|
|
|
}
|
|
|
|
|
mAnim.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
public static class AnimationConfig extends AnimatorListenerAdapter {
|
2017-10-16 11:46:41 -07:00
|
|
|
public boolean shouldPost;
|
|
|
|
|
|
|
|
|
|
private long mOverriddenDuration = -1;
|
2017-10-20 17:05:27 -07:00
|
|
|
private AnimatorSet mCurrentAnimation;
|
2017-10-16 11:46:41 -07:00
|
|
|
|
|
|
|
|
public void reset() {
|
|
|
|
|
shouldPost = false;
|
|
|
|
|
mOverriddenDuration = -1;
|
2017-10-20 17:05:27 -07:00
|
|
|
|
|
|
|
|
if (mCurrentAnimation != null) {
|
|
|
|
|
mCurrentAnimation.setDuration(0);
|
|
|
|
|
mCurrentAnimation.cancel();
|
|
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void overrideDuration(long duration) {
|
|
|
|
|
mOverriddenDuration = duration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getDuration(long defaultDuration) {
|
|
|
|
|
return mOverriddenDuration >= 0 ? mOverriddenDuration : defaultDuration;
|
|
|
|
|
}
|
2017-10-20 17:05:27 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (mCurrentAnimation == animation) {
|
|
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAnimation(AnimatorSet animation) {
|
|
|
|
|
mCurrentAnimation = animation;
|
|
|
|
|
mCurrentAnimation.addListener(this);
|
|
|
|
|
}
|
2017-10-16 11:46:41 -07:00
|
|
|
}
|
2015-05-26 23:03:31 -07:00
|
|
|
}
|