2016-06-06 14:19:02 -07:00
|
|
|
package com.android.launcher3.allapps;
|
|
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
2016-07-21 17:32:43 -07:00
|
|
|
import android.animation.AnimatorInflater;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.AnimatorSet;
|
2016-07-18 16:35:10 -07:00
|
|
|
import android.animation.ArgbEvaluator;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.animation.ObjectAnimator;
|
2016-09-30 12:57:16 -07:00
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.support.v4.graphics.ColorUtils;
|
2016-07-27 11:54:02 -07:00
|
|
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
2016-06-08 16:29:32 -07:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
2016-09-30 12:57:16 -07:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.view.animation.Interpolator;
|
|
|
|
|
|
2016-12-12 22:23:28 -08:00
|
|
|
import com.android.launcher3.AbstractFloatingView;
|
2016-06-06 14:19:02 -07:00
|
|
|
import com.android.launcher3.Hotseat;
|
|
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.LauncherAnimUtils;
|
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-01-30 17:05:24 -08:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
|
|
|
|
import com.android.launcher3.dynamicui.ExtractedColors;
|
|
|
|
|
import com.android.launcher3.graphics.RadialGradientView;
|
|
|
|
|
import com.android.launcher3.graphics.ScrimView;
|
2016-11-23 02:24:32 +05:30
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
|
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
2017-02-10 16:52:16 -08:00
|
|
|
import com.android.launcher3.util.Themes;
|
2016-06-06 14:19:02 -07:00
|
|
|
import com.android.launcher3.util.TouchController;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
*/
|
2016-06-29 21:25:33 -07:00
|
|
|
public class AllAppsTransitionController implements TouchController, VerticalPullDetector.Listener,
|
2017-05-09 12:40:11 -07:00
|
|
|
View.OnLayoutChangeListener, ExtractedColors.OnChangeListener {
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
private static final String TAG = "AllAppsTrans";
|
|
|
|
|
private static final boolean DBG = false;
|
|
|
|
|
|
2016-06-15 16:45:48 -07:00
|
|
|
private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
|
2016-09-30 12:57:16 -07:00
|
|
|
private final Interpolator mDecelInterpolator = new DecelerateInterpolator(3f);
|
2016-07-27 11:54:02 -07:00
|
|
|
private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
|
2017-03-20 16:11:54 -07:00
|
|
|
private final VerticalPullDetector.ScrollInterpolator mScrollInterpolator
|
|
|
|
|
= new VerticalPullDetector.ScrollInterpolator();
|
2016-06-08 16:29:32 -07:00
|
|
|
|
2016-06-15 16:45:48 -07:00
|
|
|
private static final float PARALLAX_COEFFICIENT = .125f;
|
2016-08-03 15:14:43 -07:00
|
|
|
private static final int SINGLE_FRAME_MS = 16;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
private AllAppsContainerView mAppsView;
|
2016-07-18 16:35:10 -07:00
|
|
|
private int mAllAppsBackgroundColor;
|
2016-06-09 12:08:22 -07:00
|
|
|
private Workspace mWorkspace;
|
2016-06-06 14:19:02 -07:00
|
|
|
private Hotseat mHotseat;
|
2016-07-18 16:35:10 -07:00
|
|
|
private int mHotseatBackgroundColor;
|
2016-06-20 13:54:42 -07:00
|
|
|
|
2016-07-29 17:05:30 -07:00
|
|
|
private AllAppsCaretController mCaretController;
|
2016-07-13 14:04:13 -07:00
|
|
|
|
2016-06-15 16:45:48 -07:00
|
|
|
private float mStatusBarHeight;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
private final VerticalPullDetector mDetector;
|
2016-07-18 16:35:10 -07:00
|
|
|
private final ArgbEvaluator mEvaluator;
|
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 mShiftStart; // [0, mShiftRange]
|
|
|
|
|
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-08-03 15:14:43 -07:00
|
|
|
// Velocity of the container. Unit is in px/ms.
|
2016-08-02 13:31:22 -07:00
|
|
|
private float mContainerVelocity;
|
2016-07-27 12:48:09 -07:00
|
|
|
|
2016-07-07 15:57:42 -07:00
|
|
|
private static final float DEFAULT_SHIFT_RANGE = 10;
|
|
|
|
|
|
2016-06-21 16:37:13 -07:00
|
|
|
private static final float RECATCH_REJECTION_FRACTION = .0875f;
|
2016-06-15 16:45:48 -07:00
|
|
|
|
2016-06-08 16:29:32 -07:00
|
|
|
private long mAnimationDuration;
|
2016-06-21 16:37:13 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
private AnimatorSet mCurrentAnimation;
|
2016-06-10 12:00:02 -07:00
|
|
|
private boolean mNoIntercept;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
// Used in discovery bounce animation to provide the transition without workspace changing.
|
|
|
|
|
private boolean mIsTranslateWithoutWorkspace = false;
|
|
|
|
|
private AnimatorSet mDiscoBounceAnimation;
|
2017-01-30 17:05:24 -08:00
|
|
|
private RadialGradientView mGradientView;
|
|
|
|
|
private ScrimView mScrimView;
|
2016-07-21 17:32:43 -07:00
|
|
|
|
|
|
|
|
public AllAppsTransitionController(Launcher l) {
|
|
|
|
|
mLauncher = l;
|
|
|
|
|
mDetector = new VerticalPullDetector(l);
|
2016-06-06 14:19:02 -07:00
|
|
|
mDetector.setListener(this);
|
2016-07-21 17:32:43 -07:00
|
|
|
mShiftRange = DEFAULT_SHIFT_RANGE;
|
|
|
|
|
mProgress = 1f;
|
2016-07-13 14:04:13 -07:00
|
|
|
|
2016-07-18 16:35:10 -07:00
|
|
|
mEvaluator = new ArgbEvaluator();
|
2017-02-10 16:52:16 -08:00
|
|
|
mAllAppsBackgroundColor = Themes.getAttrColor(l, android.R.attr.colorPrimary);
|
2017-05-09 12:40:11 -07:00
|
|
|
mLauncher.getExtractedColors().addOnChangeListener(this);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-09-23 11:01:10 -07:00
|
|
|
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
2016-06-06 14:19:02 -07:00
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
2016-06-10 12:00:02 -07:00
|
|
|
mNoIntercept = false;
|
2016-09-20 22:50:06 -07:00
|
|
|
if (!mLauncher.isAllAppsVisible() && mLauncher.getWorkspace().workspaceInModalState()) {
|
2016-06-10 12:00:02 -07:00
|
|
|
mNoIntercept = true;
|
2016-06-13 12:38:32 -07:00
|
|
|
} else if (mLauncher.isAllAppsVisible() &&
|
2016-08-05 13:57:21 -07:00
|
|
|
!mAppsView.shouldContainerScroll(ev)) {
|
2016-06-10 12:00:02 -07:00
|
|
|
mNoIntercept = true;
|
2016-12-12 22:23:28 -08:00
|
|
|
} else if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
|
|
|
|
|
mNoIntercept = true;
|
2016-06-13 12:38:32 -07:00
|
|
|
} else {
|
2016-06-21 16:37:13 -07:00
|
|
|
// Now figure out which direction scroll events the controller will start
|
|
|
|
|
// calling the callbacks.
|
2016-06-30 17:22:26 -07:00
|
|
|
int directionsToDetectScroll = 0;
|
|
|
|
|
boolean ignoreSlopWhenSettling = false;
|
2016-06-21 16:37:13 -07:00
|
|
|
|
2016-06-30 17:22:26 -07:00
|
|
|
if (mDetector.isIdleState()) {
|
2016-06-21 16:37:13 -07:00
|
|
|
if (mLauncher.isAllAppsVisible()) {
|
2016-06-30 17:22:26 -07:00
|
|
|
directionsToDetectScroll |= VerticalPullDetector.DIRECTION_DOWN;
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
2016-06-30 17:22:26 -07:00
|
|
|
directionsToDetectScroll |= VerticalPullDetector.DIRECTION_UP;
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (isInDisallowRecatchBottomZone()) {
|
2016-06-30 17:22:26 -07:00
|
|
|
directionsToDetectScroll |= VerticalPullDetector.DIRECTION_UP;
|
2016-06-21 16:37:13 -07:00
|
|
|
} else if (isInDisallowRecatchTopZone()) {
|
2016-06-30 17:22:26 -07:00
|
|
|
directionsToDetectScroll |= VerticalPullDetector.DIRECTION_DOWN;
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
2016-06-30 17:22:26 -07:00
|
|
|
directionsToDetectScroll |= VerticalPullDetector.DIRECTION_BOTH;
|
|
|
|
|
ignoreSlopWhenSettling = true;
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-30 17:22:26 -07:00
|
|
|
mDetector.setDetectableScrollConditions(directionsToDetectScroll,
|
|
|
|
|
ignoreSlopWhenSettling);
|
2016-06-10 12:00:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
2017-01-04 16:31:57 -08:00
|
|
|
|
2016-06-10 12:00:02 -07:00
|
|
|
if (mNoIntercept) {
|
|
|
|
|
return false;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
mDetector.onTouchEvent(ev);
|
2016-06-30 17:22:26 -07:00
|
|
|
if (mDetector.isSettlingState() && (isInDisallowRecatchBottomZone() || isInDisallowRecatchTopZone())) {
|
2016-06-21 16:37:13 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-07-27 10:55:51 -07:00
|
|
|
return mDetector.isDraggingOrSettling();
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-09-23 11:01:10 -07:00
|
|
|
public boolean onControllerTouchEvent(MotionEvent ev) {
|
2016-06-06 14:19:02 -07:00
|
|
|
return mDetector.onTouchEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 12:38:32 -07:00
|
|
|
private boolean isInDisallowRecatchTopZone() {
|
2016-07-21 17:32:43 -07:00
|
|
|
return mProgress < RECATCH_REJECTION_FRACTION;
|
2016-06-13 12:38:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isInDisallowRecatchBottomZone() {
|
2016-07-21 17:32:43 -07:00
|
|
|
return mProgress > 1 - RECATCH_REJECTION_FRACTION;
|
2016-06-13 12:38:32 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
@Override
|
2016-06-30 17:22:26 -07:00
|
|
|
public void onDragStart(boolean start) {
|
2016-07-29 17:05:30 -07:00
|
|
|
mCaretController.onDragStart();
|
2016-06-27 20:13:55 +00:00
|
|
|
cancelAnimation();
|
2016-06-06 14:19:02 -07:00
|
|
|
mCurrentAnimation = LauncherAnimUtils.createAnimatorSet();
|
2016-06-21 16:37:13 -07:00
|
|
|
mShiftStart = mAppsView.getTranslationY();
|
2016-06-06 14:19:02 -07:00
|
|
|
preparePull(start);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 16:37:13 -07:00
|
|
|
@Override
|
2016-06-30 17:22:26 -07:00
|
|
|
public boolean onDrag(float displacement, float velocity) {
|
2016-06-21 16:37:13 -07:00
|
|
|
if (mAppsView == null) {
|
|
|
|
|
return false; // early termination.
|
|
|
|
|
}
|
2016-07-27 12:48:09 -07:00
|
|
|
|
2016-08-02 13:31:22 -07:00
|
|
|
mContainerVelocity = velocity;
|
2016-07-27 12:48:09 -07:00
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
float shift = Math.min(Math.max(0, mShiftStart + displacement), mShiftRange);
|
|
|
|
|
setProgress(shift / mShiftRange);
|
2016-07-27 12:48:09 -07:00
|
|
|
|
2016-06-21 16:37:13 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-06-30 17:22:26 -07:00
|
|
|
public void onDragEnd(float velocity, boolean fling) {
|
2016-06-21 16:37:13 -07:00
|
|
|
if (mAppsView == null) {
|
|
|
|
|
return; // early termination.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fling) {
|
|
|
|
|
if (velocity < 0) {
|
|
|
|
|
calculateDuration(velocity, mAppsView.getTranslationY());
|
|
|
|
|
|
|
|
|
|
if (!mLauncher.isAllAppsVisible()) {
|
2016-07-21 11:48:37 -07:00
|
|
|
mLauncher.getUserEventDispatcher().logActionOnContainer(
|
2016-11-23 02:24:32 +05:30
|
|
|
Action.Touch.FLING,
|
|
|
|
|
Action.Direction.UP,
|
|
|
|
|
ContainerType.HOTSEAT);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
2016-07-27 17:08:38 -07:00
|
|
|
mLauncher.showAppsView(true /* animated */,
|
|
|
|
|
false /* updatePredictedApps */,
|
|
|
|
|
false /* focusSearchBar */);
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
|
|
|
|
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
|
2016-07-27 10:55:51 -07:00
|
|
|
mLauncher.showWorkspace(true);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
|
|
|
|
// snap to top or bottom using the release velocity
|
|
|
|
|
} else {
|
|
|
|
|
if (mAppsView.getTranslationY() > mShiftRange / 2) {
|
|
|
|
|
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
|
2016-07-27 10:55:51 -07:00
|
|
|
mLauncher.showWorkspace(true);
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
|
|
|
|
calculateDuration(velocity, Math.abs(mAppsView.getTranslationY()));
|
|
|
|
|
if (!mLauncher.isAllAppsVisible()) {
|
2016-07-21 11:48:37 -07:00
|
|
|
mLauncher.getUserEventDispatcher().logActionOnContainer(
|
2016-11-23 02:24:32 +05:30
|
|
|
Action.Touch.SWIPE,
|
|
|
|
|
Action.Direction.UP,
|
|
|
|
|
ContainerType.HOTSEAT);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
2016-07-27 17:08:38 -07:00
|
|
|
mLauncher.showAppsView(true, /* animated */
|
|
|
|
|
false /* updatePredictedApps */,
|
|
|
|
|
false /* focusSearchBar */);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-14 15:09:11 -07:00
|
|
|
|
2016-07-27 10:55:51 -07:00
|
|
|
public boolean isTransitioning() {
|
|
|
|
|
return mDetector.isDraggingOrSettling();
|
|
|
|
|
}
|
2016-07-27 11:54:02 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
/**
|
|
|
|
|
* @param start {@code true} if start of new drag.
|
|
|
|
|
*/
|
|
|
|
|
public void preparePull(boolean start) {
|
|
|
|
|
if (start) {
|
2016-06-30 17:22:26 -07:00
|
|
|
// Initialize values that should not change until #onDragEnd
|
2016-06-21 16:37:13 -07:00
|
|
|
mStatusBarHeight = mLauncher.getDragLayer().getInsets().top;
|
|
|
|
|
mHotseat.setVisibility(View.VISIBLE);
|
2016-08-04 15:48:42 -07:00
|
|
|
mHotseatBackgroundColor = mHotseat.getBackgroundDrawableColor();
|
|
|
|
|
mHotseat.setBackgroundTransparent(true /* transparent */);
|
2016-06-06 14:19:02 -07:00
|
|
|
if (!mLauncher.isAllAppsVisible()) {
|
2016-06-15 16:45:48 -07:00
|
|
|
mLauncher.tryAndUpdatePredictedApps();
|
2016-06-06 14:19:02 -07:00
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
2017-01-30 17:05:24 -08:00
|
|
|
if (!FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
|
|
|
|
mAppsView.setRevealDrawableColor(mHotseatBackgroundColor);
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
private void updateLightStatusBar(float shift) {
|
2016-06-28 12:16:47 -07:00
|
|
|
// Do not modify status bar on landscape as all apps is not full bleed.
|
|
|
|
|
if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-14 16:46:32 -07:00
|
|
|
// Use a light status bar (dark icons) if all apps is behind at least half of the status
|
|
|
|
|
// bar. If the status bar is already light due to wallpaper extraction, keep it that way.
|
2016-09-28 15:34:51 -07:00
|
|
|
boolean forceLight = shift <= mStatusBarHeight / 2;
|
2017-03-20 16:49:37 -07:00
|
|
|
mLauncher.activateLightSystemBars(forceLight, true /* statusBar */, true /* navBar */);
|
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) {
|
|
|
|
|
mGradientView = (RadialGradientView) mLauncher.findViewById(R.id.gradient_bg);
|
|
|
|
|
mGradientView.setVisibility(View.VISIBLE);
|
|
|
|
|
onExtractedColorsChanged();
|
|
|
|
|
}
|
|
|
|
|
mGradientView.setProgress(progress);
|
|
|
|
|
|
|
|
|
|
// scrim
|
|
|
|
|
if (mScrimView == null) {
|
|
|
|
|
mScrimView = (ScrimView) mLauncher.findViewById(R.id.scrim_bg);
|
|
|
|
|
mScrimView.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
mScrimView.setProgress(progress);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 12:40:11 -07:00
|
|
|
@Override
|
2017-01-30 17:05:24 -08:00
|
|
|
public void onExtractedColorsChanged() {
|
|
|
|
|
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
|
|
|
|
if (mGradientView != null) {
|
|
|
|
|
int color1 = mLauncher.getExtractedColors()
|
|
|
|
|
.getColor(ExtractedColors.ALLAPPS_GRADIENT_MAIN_INDEX);
|
|
|
|
|
int color2 = mLauncher.getExtractedColors()
|
|
|
|
|
.getColor(ExtractedColors.ALLAPPS_GRADIENT_SECONDARY_INDEX);
|
|
|
|
|
mGradientView.onExtractedColorsChanged(color1, color2);
|
|
|
|
|
mGradientView.requestLayout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
/**
|
2016-08-02 13:31:22 -07:00
|
|
|
* @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
|
2016-06-06 14:19:02 -07:00
|
|
|
*/
|
|
|
|
|
public void setProgress(float progress) {
|
2016-08-02 13:31:22 -07:00
|
|
|
float shiftPrevious = mProgress * mShiftRange;
|
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;
|
2016-07-18 17:18:02 -07:00
|
|
|
float interpolation = mAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
|
2016-06-08 16:29:32 -07:00
|
|
|
|
2016-09-30 12:57:16 -07:00
|
|
|
int color = (Integer) mEvaluator.evaluate(mDecelInterpolator.getInterpolation(alpha),
|
2016-07-18 16:35:10 -07:00
|
|
|
mHotseatBackgroundColor, mAllAppsBackgroundColor);
|
2016-09-30 12:57:16 -07:00
|
|
|
int bgAlpha = Color.alpha((int) mEvaluator.evaluate(alpha,
|
|
|
|
|
mHotseatBackgroundColor, mAllAppsBackgroundColor));
|
|
|
|
|
|
2017-01-30 17:05:24 -08:00
|
|
|
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
|
|
|
|
updateAllAppsBg(alpha);
|
|
|
|
|
} else {
|
|
|
|
|
mAppsView.setRevealDrawableColor(ColorUtils.setAlphaComponent(color, bgAlpha));
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 16:29:32 -07:00
|
|
|
mAppsView.getContentView().setAlpha(alpha);
|
2016-07-21 17:32:43 -07:00
|
|
|
mAppsView.setTranslationY(shiftCurrent);
|
|
|
|
|
|
|
|
|
|
if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
|
|
|
|
|
mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y, -mShiftRange + shiftCurrent,
|
|
|
|
|
interpolation);
|
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),
|
|
|
|
|
interpolation);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
if (mIsTranslateWithoutWorkspace) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mWorkspace.setWorkspaceYTranslationAndAlpha(
|
2016-07-29 17:05:30 -07:00
|
|
|
PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent), interpolation);
|
2016-08-02 13:31:22 -07:00
|
|
|
|
|
|
|
|
if (!mDetector.isDraggingState()) {
|
|
|
|
|
mContainerVelocity = mDetector.computeVelocity(shiftCurrent - shiftPrevious,
|
|
|
|
|
System.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 17:05:30 -07:00
|
|
|
mCaretController.updateCaret(progress, mContainerVelocity, mDetector.isDraggingState());
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void calculateDuration(float velocity, float disp) {
|
2017-03-20 16:11:54 -07:00
|
|
|
mAnimationDuration = mDetector.calculateDuration(velocity, disp / mShiftRange);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-03 15:14:43 -07:00
|
|
|
public boolean animateToAllApps(AnimatorSet animationOut, long duration) {
|
|
|
|
|
boolean shouldPost = true;
|
2016-07-14 15:09:11 -07:00
|
|
|
if (animationOut == null) {
|
2016-08-03 15:14:43 -07:00
|
|
|
return shouldPost;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2016-08-03 15:14:43 -07:00
|
|
|
Interpolator interpolator;
|
2016-06-30 17:22:26 -07:00
|
|
|
if (mDetector.isIdleState()) {
|
2016-06-06 14:19:02 -07:00
|
|
|
preparePull(true);
|
2016-06-08 16:29:32 -07:00
|
|
|
mAnimationDuration = duration;
|
2016-06-21 16:37:13 -07:00
|
|
|
mShiftStart = mAppsView.getTranslationY();
|
2016-07-27 11:54:02 -07:00
|
|
|
interpolator = mFastOutSlowInInterpolator;
|
|
|
|
|
} else {
|
2016-08-03 15:14:43 -07:00
|
|
|
mScrollInterpolator.setVelocityAtZero(Math.abs(mContainerVelocity));
|
2016-07-27 11:54:02 -07:00
|
|
|
interpolator = mScrollInterpolator;
|
2016-08-03 15:14:43 -07:00
|
|
|
float nextFrameProgress = mProgress + mContainerVelocity * SINGLE_FRAME_MS / mShiftRange;
|
|
|
|
|
if (nextFrameProgress >= 0f) {
|
|
|
|
|
mProgress = nextFrameProgress;
|
|
|
|
|
}
|
|
|
|
|
shouldPost = false;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2016-08-03 15:14:43 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
|
2016-08-03 15:14:43 -07:00
|
|
|
mProgress, 0f);
|
2016-06-08 16:29:32 -07:00
|
|
|
driftAndAlpha.setDuration(mAnimationDuration);
|
2016-07-27 11:54:02 -07:00
|
|
|
driftAndAlpha.setInterpolator(interpolator);
|
2016-06-06 14:19:02 -07:00
|
|
|
animationOut.play(driftAndAlpha);
|
|
|
|
|
|
|
|
|
|
animationOut.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
boolean canceled = false;
|
2016-07-14 15:09:11 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
@Override
|
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
|
canceled = true;
|
|
|
|
|
}
|
2016-07-14 15:09:11 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (canceled) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
finishPullUp();
|
|
|
|
|
cleanUpAnimation();
|
|
|
|
|
mDetector.finishedScrolling();
|
|
|
|
|
}
|
2016-07-14 15:09:11 -07:00
|
|
|
}
|
|
|
|
|
});
|
2016-06-06 14:19:02 -07:00
|
|
|
mCurrentAnimation = animationOut;
|
2016-08-03 15:14:43 -07:00
|
|
|
return shouldPost;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
public void showDiscoveryBounce() {
|
|
|
|
|
// cancel existing animation in case user locked and unlocked at a super human speed.
|
|
|
|
|
cancelDiscoveryAnimation();
|
|
|
|
|
|
|
|
|
|
// assumption is that this variable is always null
|
|
|
|
|
mDiscoBounceAnimation = (AnimatorSet) AnimatorInflater.loadAnimator(mLauncher,
|
|
|
|
|
R.anim.discovery_bounce);
|
|
|
|
|
mDiscoBounceAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
|
mIsTranslateWithoutWorkspace = true;
|
|
|
|
|
preparePull(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
2016-07-27 12:48:09 -07:00
|
|
|
finishPullDown();
|
2016-07-21 17:32:43 -07:00
|
|
|
mDiscoBounceAnimation = null;
|
|
|
|
|
mIsTranslateWithoutWorkspace = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mDiscoBounceAnimation.setTarget(this);
|
|
|
|
|
mAppsView.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
2016-08-03 10:40:18 -07:00
|
|
|
if (mDiscoBounceAnimation == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-21 17:32:43 -07:00
|
|
|
mDiscoBounceAnimation.start();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 15:14:43 -07:00
|
|
|
public boolean animateToWorkspace(AnimatorSet animationOut, long duration) {
|
|
|
|
|
boolean shouldPost = true;
|
2016-07-14 15:09:11 -07:00
|
|
|
if (animationOut == null) {
|
2016-08-03 15:14:43 -07:00
|
|
|
return shouldPost;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2016-07-27 11:54:02 -07:00
|
|
|
Interpolator interpolator;
|
2016-07-14 15:09:11 -07:00
|
|
|
if (mDetector.isIdleState()) {
|
2016-06-06 14:19:02 -07:00
|
|
|
preparePull(true);
|
2016-06-08 16:29:32 -07:00
|
|
|
mAnimationDuration = duration;
|
2016-06-21 16:37:13 -07:00
|
|
|
mShiftStart = mAppsView.getTranslationY();
|
2016-07-27 11:54:02 -07:00
|
|
|
interpolator = mFastOutSlowInInterpolator;
|
|
|
|
|
} else {
|
2016-08-03 15:14:43 -07:00
|
|
|
mScrollInterpolator.setVelocityAtZero(Math.abs(mContainerVelocity));
|
2016-07-27 11:54:02 -07:00
|
|
|
interpolator = mScrollInterpolator;
|
2016-08-03 15:14:43 -07:00
|
|
|
float nextFrameProgress = mProgress + mContainerVelocity * SINGLE_FRAME_MS / mShiftRange;
|
|
|
|
|
if (nextFrameProgress <= 1f) {
|
|
|
|
|
mProgress = nextFrameProgress;
|
|
|
|
|
}
|
|
|
|
|
shouldPost = false;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
|
2016-08-03 15:14:43 -07:00
|
|
|
mProgress, 1f);
|
2016-06-08 16:29:32 -07:00
|
|
|
driftAndAlpha.setDuration(mAnimationDuration);
|
2016-07-27 11:54:02 -07:00
|
|
|
driftAndAlpha.setInterpolator(interpolator);
|
2016-06-06 14:19:02 -07:00
|
|
|
animationOut.play(driftAndAlpha);
|
|
|
|
|
|
|
|
|
|
animationOut.addListener(new AnimatorListenerAdapter() {
|
2016-07-14 15:09:11 -07:00
|
|
|
boolean canceled = false;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
|
canceled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (canceled) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2016-07-27 12:48:09 -07:00
|
|
|
finishPullDown();
|
2016-07-14 15:09:11 -07:00
|
|
|
cleanUpAnimation();
|
|
|
|
|
mDetector.finishedScrolling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-06-06 14:19:02 -07:00
|
|
|
mCurrentAnimation = animationOut;
|
2016-08-03 15:14:43 -07:00
|
|
|
return shouldPost;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 11:14:41 -07:00
|
|
|
public void finishPullUp() {
|
2016-06-15 16:45:48 -07:00
|
|
|
mHotseat.setVisibility(View.INVISIBLE);
|
|
|
|
|
setProgress(0f);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 12:48:09 -07:00
|
|
|
public void finishPullDown() {
|
2016-06-06 14:19:02 -07:00
|
|
|
mAppsView.setVisibility(View.INVISIBLE);
|
2016-06-20 13:54:42 -07:00
|
|
|
mHotseat.setBackgroundTransparent(false /* transparent */);
|
2016-06-06 14:19:02 -07:00
|
|
|
mHotseat.setVisibility(View.VISIBLE);
|
2016-06-30 13:52:36 -07:00
|
|
|
mAppsView.reset();
|
2016-07-21 17:32:43 -07:00
|
|
|
setProgress(1f);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelAnimation() {
|
|
|
|
|
if (mCurrentAnimation != null) {
|
|
|
|
|
mCurrentAnimation.cancel();
|
|
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
2016-07-21 17:32:43 -07:00
|
|
|
cancelDiscoveryAnimation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void cancelDiscoveryAnimation() {
|
|
|
|
|
if (mDiscoBounceAnimation == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mDiscoBounceAnimation.cancel();
|
|
|
|
|
mDiscoBounceAnimation = null;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cleanUpAnimation() {
|
|
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
2016-06-20 13:54:42 -07:00
|
|
|
|
|
|
|
|
public void setupViews(AllAppsContainerView appsView, Hotseat hotseat, Workspace workspace) {
|
|
|
|
|
mAppsView = appsView;
|
|
|
|
|
mHotseat = hotseat;
|
|
|
|
|
mWorkspace = workspace;
|
2016-06-29 21:25:33 -07:00
|
|
|
mHotseat.addOnLayoutChangeListener(this);
|
2016-07-27 17:08:38 -07:00
|
|
|
mHotseat.bringToFront();
|
2016-07-29 17:05:30 -07:00
|
|
|
mCaretController = new AllAppsCaretController(
|
|
|
|
|
mWorkspace.getPageIndicator().getCaretDrawable(), mLauncher);
|
2016-06-29 21:25:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
2016-07-21 17:32:43 -07:00
|
|
|
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
2016-06-29 21:25:33 -07:00
|
|
|
if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
|
|
|
|
|
mShiftRange = top;
|
|
|
|
|
} else {
|
|
|
|
|
mShiftRange = bottom;
|
|
|
|
|
}
|
2016-07-21 17:32:43 -07:00
|
|
|
setProgress(mProgress);
|
2016-06-20 13:54:42 -07:00
|
|
|
}
|
2016-08-03 15:14:43 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|