2016-06-06 14:19:02 -07:00
|
|
|
package com.android.launcher3.allapps;
|
|
|
|
|
|
2017-10-27 11:05:26 -07:00
|
|
|
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
2017-10-23 17:14:52 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
2017-10-20 17:05:27 -07:00
|
|
|
import android.util.Property;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.animation.Interpolator;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.Hotseat;
|
|
|
|
|
import com.android.launcher3.Launcher;
|
2017-10-18 10:55:56 -07:00
|
|
|
import com.android.launcher3.LauncherState;
|
2017-11-07 12:23:58 -08:00
|
|
|
import com.android.launcher3.LauncherStateManager;
|
2017-10-23 17:14:52 -07:00
|
|
|
import com.android.launcher3.LauncherStateManager.AnimationConfig;
|
2016-06-21 16:37:13 -07:00
|
|
|
import com.android.launcher3.R;
|
2016-07-21 17:32:43 -07:00
|
|
|
import com.android.launcher3.Utilities;
|
2016-06-09 12:08:22 -07:00
|
|
|
import com.android.launcher3.Workspace;
|
2017-11-07 12:23:58 -08:00
|
|
|
import com.android.launcher3.anim.AnimationLayerSet;
|
2017-10-20 17:05:27 -07:00
|
|
|
import com.android.launcher3.anim.AnimationSuccessListener;
|
2017-10-26 15:36:10 -07:00
|
|
|
import com.android.launcher3.anim.Interpolators;
|
2017-05-11 10:45:20 -07:00
|
|
|
import com.android.launcher3.graphics.GradientView;
|
2017-06-20 10:03:56 -07:00
|
|
|
import com.android.launcher3.util.SystemUiController;
|
2017-02-10 16:52:16 -08:00
|
|
|
import com.android.launcher3.util.Themes;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles AllApps view transition.
|
|
|
|
|
* 1) Slides all apps view using direct manipulation
|
|
|
|
|
* 2) When finger is released, animate to either top or bottom accordingly.
|
2016-07-14 15:09:11 -07:00
|
|
|
* <p/>
|
2016-06-06 14:19:02 -07:00
|
|
|
* Algorithm:
|
|
|
|
|
* If release velocity > THRES1, snap according to the direction of movement.
|
|
|
|
|
* If release velocity < THRES1, snap according to either top or bottom depending on whether it's
|
2016-07-14 15:09:11 -07:00
|
|
|
* closer to top or closer to the page indicator.
|
2016-06-06 14:19:02 -07:00
|
|
|
*/
|
2017-11-07 12:23:58 -08:00
|
|
|
public class AllAppsTransitionController
|
|
|
|
|
implements SearchUiManager.OnScrollRangeChangeListener, LauncherStateManager.StateHandler {
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
private static final Property<AllAppsTransitionController, Float> PROGRESS =
|
|
|
|
|
new Property<AllAppsTransitionController, Float>(Float.class, "progress") {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Float get(AllAppsTransitionController controller) {
|
|
|
|
|
return controller.mProgress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void set(AllAppsTransitionController controller, Float progress) {
|
|
|
|
|
controller.setProgress(progress);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-26 15:36:10 -07:00
|
|
|
private final Interpolator mWorkspaceAccelnterpolator = Interpolators.ACCEL_2;
|
|
|
|
|
private final Interpolator mHotseatAccelInterpolator = Interpolators.ACCEL_1_5;
|
2016-06-08 16:29:32 -07:00
|
|
|
|
2016-06-15 16:45:48 -07:00
|
|
|
private static final float PARALLAX_COEFFICIENT = .125f;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
private AllAppsContainerView mAppsView;
|
2016-06-09 12:08:22 -07:00
|
|
|
private Workspace mWorkspace;
|
2016-06-06 14:19:02 -07:00
|
|
|
private Hotseat mHotseat;
|
2016-06-20 13:54:42 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
private final Launcher mLauncher;
|
2017-05-24 13:19:15 -07:00
|
|
|
private final boolean mIsDarkTheme;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
// Animation in this class is controlled by a single variable {@link mProgress}.
|
|
|
|
|
// Visually, it represents top y coordinate of the all apps container if multiplied with
|
|
|
|
|
// {@link mShiftRange}.
|
|
|
|
|
|
|
|
|
|
// When {@link mProgress} is 0, all apps container is pulled up.
|
|
|
|
|
// When {@link mProgress} is 1, all apps container is pulled down.
|
2016-06-21 16:37:13 -07:00
|
|
|
private float mShiftRange; // changes depending on the orientation
|
2016-07-21 17:32:43 -07:00
|
|
|
private float mProgress; // [0, 1], mShiftRange * mProgress = shiftCurrent
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2016-07-07 15:57:42 -07:00
|
|
|
private static final float DEFAULT_SHIFT_RANGE = 10;
|
|
|
|
|
|
2017-05-11 10:45:20 -07:00
|
|
|
private GradientView mGradientView;
|
2016-07-21 17:32:43 -07:00
|
|
|
|
|
|
|
|
public AllAppsTransitionController(Launcher l) {
|
|
|
|
|
mLauncher = l;
|
|
|
|
|
mShiftRange = DEFAULT_SHIFT_RANGE;
|
|
|
|
|
mProgress = 1f;
|
2016-07-13 14:04:13 -07:00
|
|
|
|
2017-05-31 14:48:19 -07:00
|
|
|
mIsDarkTheme = Themes.getAttrBoolean(mLauncher, R.attr.isMainColorDark);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-27 11:05:26 -07:00
|
|
|
public float getShiftRange() {
|
|
|
|
|
return mShiftRange;
|
2016-07-27 10:55:51 -07:00
|
|
|
}
|
2016-07-27 11:54:02 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
private void onProgressAnimationStart() {
|
|
|
|
|
// Initialize values that should not change until #onDragEnd
|
|
|
|
|
mHotseat.setVisibility(View.VISIBLE);
|
|
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
private void updateLightStatusBar(float shift) {
|
2017-06-20 10:03:56 -07:00
|
|
|
// Use a light system UI (dark icons) if all apps is behind at least half of the status bar.
|
2017-09-28 11:31:39 -07:00
|
|
|
boolean forceChange = shift <= mShiftRange / 4;
|
2017-06-20 10:03:56 -07:00
|
|
|
if (forceChange) {
|
|
|
|
|
mLauncher.getSystemUiController().updateUiState(
|
|
|
|
|
SystemUiController.UI_STATE_ALL_APPS, !mIsDarkTheme);
|
|
|
|
|
} else {
|
|
|
|
|
mLauncher.getSystemUiController().updateUiState(
|
|
|
|
|
SystemUiController.UI_STATE_ALL_APPS, 0);
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-30 17:05:24 -08:00
|
|
|
private void updateAllAppsBg(float progress) {
|
|
|
|
|
// gradient
|
|
|
|
|
if (mGradientView == null) {
|
2017-10-02 15:26:42 -07:00
|
|
|
mGradientView = mLauncher.findViewById(R.id.gradient_bg);
|
2017-01-30 17:05:24 -08:00
|
|
|
}
|
|
|
|
|
mGradientView.setProgress(progress);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
/**
|
2017-10-20 17:05:27 -07:00
|
|
|
* Note this method should not be called outside this class. This is public because it is used
|
|
|
|
|
* in xml-based animations which also handle updating the appropriate UI.
|
|
|
|
|
*
|
|
|
|
|
* @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
|
|
|
|
|
*
|
2017-11-07 12:23:58 -08:00
|
|
|
* @see #setState(LauncherState)
|
|
|
|
|
* @see #setStateWithAnimation(LauncherState, AnimationLayerSet, AnimatorSet, AnimationConfig)
|
2016-06-06 14:19:02 -07:00
|
|
|
*/
|
|
|
|
|
public void setProgress(float progress) {
|
2016-07-21 17:32:43 -07:00
|
|
|
mProgress = progress;
|
|
|
|
|
float shiftCurrent = progress * mShiftRange;
|
|
|
|
|
|
|
|
|
|
float workspaceHotseatAlpha = Utilities.boundToRange(progress, 0f, 1f);
|
|
|
|
|
float alpha = 1 - workspaceHotseatAlpha;
|
2017-05-11 10:45:20 -07:00
|
|
|
float workspaceAlpha = mWorkspaceAccelnterpolator.getInterpolation(workspaceHotseatAlpha);
|
|
|
|
|
float hotseatAlpha = mHotseatAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
|
2016-06-08 16:29:32 -07:00
|
|
|
|
2017-09-28 11:31:39 -07:00
|
|
|
updateAllAppsBg(alpha);
|
2017-10-10 15:21:15 -07:00
|
|
|
mAppsView.setAlpha(alpha);
|
2016-07-21 17:32:43 -07:00
|
|
|
mAppsView.setTranslationY(shiftCurrent);
|
|
|
|
|
|
|
|
|
|
if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
|
|
|
|
|
mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y, -mShiftRange + shiftCurrent,
|
2017-05-11 10:45:20 -07:00
|
|
|
hotseatAlpha);
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
2016-07-21 17:32:43 -07:00
|
|
|
mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y,
|
|
|
|
|
PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent),
|
2017-05-11 10:45:20 -07:00
|
|
|
hotseatAlpha);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
2016-07-21 17:32:43 -07:00
|
|
|
mWorkspace.setWorkspaceYTranslationAndAlpha(
|
2017-05-11 10:45:20 -07:00
|
|
|
PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent), workspaceAlpha);
|
2016-08-02 13:31:22 -07:00
|
|
|
|
2016-07-29 17:05:30 -07:00
|
|
|
updateLightStatusBar(shiftCurrent);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
public float getProgress() {
|
|
|
|
|
return mProgress;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
/**
|
2017-11-07 12:23:58 -08:00
|
|
|
* Sets the vertical transition progress to {@param state} and updates all the dependent UI
|
2017-10-20 17:05:27 -07:00
|
|
|
* accordingly.
|
|
|
|
|
*/
|
2017-11-07 12:23:58 -08:00
|
|
|
@Override
|
|
|
|
|
public void setState(LauncherState state) {
|
|
|
|
|
setProgress(state.verticalProgress);
|
2017-10-20 17:05:27 -07:00
|
|
|
onProgressAnimationEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an animation which updates the vertical transition progress and updates all the
|
|
|
|
|
* dependent UI using various animation events
|
|
|
|
|
*/
|
2017-11-07 12:23:58 -08:00
|
|
|
@Override
|
|
|
|
|
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
|
|
|
|
|
AnimatorSet animationOut, AnimationConfig config) {
|
|
|
|
|
if (Float.compare(mProgress, toState.verticalProgress) == 0) {
|
2017-10-20 17:05:27 -07:00
|
|
|
// Fail fast
|
|
|
|
|
onProgressAnimationEnd();
|
2017-10-16 11:46:41 -07:00
|
|
|
return;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2017-10-20 17:05:27 -07:00
|
|
|
|
2017-11-07 12:23:58 -08:00
|
|
|
Interpolator interpolator = config.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
|
|
|
|
|
ObjectAnimator anim = ObjectAnimator.ofFloat(
|
|
|
|
|
this, PROGRESS, mProgress, toState.verticalProgress);
|
|
|
|
|
anim.setDuration(config.duration);
|
2017-10-20 17:05:27 -07:00
|
|
|
anim.setInterpolator(interpolator);
|
2017-12-05 15:11:21 -08:00
|
|
|
anim.addListener(getProgressAnimatorListener());
|
2017-09-05 11:32:13 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
animationOut.play(anim);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 15:11:21 -08:00
|
|
|
public AnimatorListenerAdapter getProgressAnimatorListener() {
|
|
|
|
|
return new AnimationSuccessListener() {
|
2016-07-21 17:32:43 -07:00
|
|
|
@Override
|
2017-12-05 15:11:21 -08:00
|
|
|
public void onAnimationSuccess(Animator animator) {
|
2017-10-20 17:05:27 -07:00
|
|
|
onProgressAnimationEnd();
|
2016-07-21 17:32:43 -07:00
|
|
|
}
|
2017-12-05 15:11:21 -08:00
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
@Override
|
2017-12-05 15:11:21 -08:00
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
onProgressAnimationStart();
|
2016-07-21 17:32:43 -07:00
|
|
|
}
|
2017-12-05 15:11:21 -08:00
|
|
|
};
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-20 13:54:42 -07:00
|
|
|
public void setupViews(AllAppsContainerView appsView, Hotseat hotseat, Workspace workspace) {
|
|
|
|
|
mAppsView = appsView;
|
|
|
|
|
mHotseat = hotseat;
|
|
|
|
|
mWorkspace = workspace;
|
2016-07-27 17:08:38 -07:00
|
|
|
mHotseat.bringToFront();
|
2017-05-12 08:17:35 -07:00
|
|
|
mAppsView.getSearchUiManager().addOnScrollRangeChangeListener(this);
|
2016-06-29 21:25:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-05-12 08:17:35 -07:00
|
|
|
public void onScrollRangeChanged(int scrollRange) {
|
|
|
|
|
mShiftRange = scrollRange;
|
2016-07-21 17:32:43 -07:00
|
|
|
setProgress(mProgress);
|
2016-06-20 13:54:42 -07:00
|
|
|
}
|
2017-10-20 17:05:27 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the final view states based on the progress.
|
|
|
|
|
* TODO: This logic should go in {@link LauncherState}
|
|
|
|
|
*/
|
|
|
|
|
private void onProgressAnimationEnd() {
|
|
|
|
|
if (Float.compare(mProgress, 1f) == 0) {
|
|
|
|
|
mAppsView.setVisibility(View.INVISIBLE);
|
|
|
|
|
mHotseat.setVisibility(View.VISIBLE);
|
|
|
|
|
mAppsView.reset();
|
|
|
|
|
} else if (Float.compare(mProgress, 0f) == 0) {
|
|
|
|
|
mHotseat.setVisibility(View.INVISIBLE);
|
|
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|