2016-06-06 14:19:02 -07:00
|
|
|
package com.android.launcher3.allapps;
|
|
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
|
|
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;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
2016-06-08 16:29:32 -07:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
2016-07-13 14:04:13 -07:00
|
|
|
import android.view.animation.AnimationUtils;
|
2016-06-15 16:45:48 -07:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.view.animation.Interpolator;
|
|
|
|
|
|
2016-07-13 14:04:13 -07:00
|
|
|
import com.android.launcher3.pageindicators.CaretDrawable;
|
2016-06-15 16:45:48 -07:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
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-08 16:29:32 -07:00
|
|
|
import com.android.launcher3.PagedView;
|
2016-06-21 16:37:13 -07:00
|
|
|
import com.android.launcher3.R;
|
2016-06-09 12:08:22 -07:00
|
|
|
import com.android.launcher3.Workspace;
|
2016-06-20 10:53:52 -07:00
|
|
|
import com.android.launcher3.Workspace.Direction;
|
2016-07-21 11:48:37 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
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,
|
|
|
|
|
View.OnLayoutChangeListener {
|
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);
|
|
|
|
|
private final Interpolator mDecelInterpolator = new DecelerateInterpolator(1f);
|
2016-06-08 16:29:32 -07:00
|
|
|
|
2016-06-21 16:37:13 -07:00
|
|
|
private static final float ANIMATION_DURATION = 1200;
|
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-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-13 14:04:13 -07:00
|
|
|
private ObjectAnimator mCaretAnimator;
|
|
|
|
|
private final long mCaretAnimationDuration;
|
|
|
|
|
private final Interpolator mCaretInterpolator;
|
|
|
|
|
|
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-06-21 16:37:13 -07:00
|
|
|
// Animation in this class is controlled by a single variable {@link mShiftCurrent}.
|
2016-06-06 14:19:02 -07:00
|
|
|
// Visually, it represents top y coordinate of the all apps container. Using the
|
2016-06-21 16:37:13 -07:00
|
|
|
// {@link mShiftRange} as the denominator, this fraction value ranges in [0, 1].
|
|
|
|
|
//
|
|
|
|
|
// When {@link mShiftCurrent} is 0, all apps container is pulled up.
|
|
|
|
|
// When {@link mShiftCurrent} is {@link mShirtRange}, all apps container is pulled down.
|
|
|
|
|
private float mShiftStart; // [0, mShiftRange]
|
|
|
|
|
private float mShiftCurrent; // [0, mShiftRange]
|
|
|
|
|
private float mShiftRange; // changes depending on the orientation
|
2016-06-06 14:19:02 -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-21 16:37:13 -07:00
|
|
|
private int mBezelSwipeUpHeight;
|
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-06-15 16:45:48 -07:00
|
|
|
private boolean mLightStatusBar;
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
public AllAppsTransitionController(Launcher launcher) {
|
|
|
|
|
mLauncher = launcher;
|
|
|
|
|
mDetector = new VerticalPullDetector(launcher);
|
|
|
|
|
mDetector.setListener(this);
|
2016-07-07 15:57:42 -07:00
|
|
|
mShiftCurrent = mShiftRange = DEFAULT_SHIFT_RANGE;
|
2016-06-21 16:37:13 -07:00
|
|
|
mBezelSwipeUpHeight = launcher.getResources().getDimensionPixelSize(
|
|
|
|
|
R.dimen.all_apps_bezel_swipe_height);
|
2016-07-13 14:04:13 -07:00
|
|
|
|
|
|
|
|
mCaretAnimationDuration = launcher.getResources().getInteger(
|
|
|
|
|
R.integer.config_caretAnimationDuration);
|
|
|
|
|
mCaretInterpolator = AnimationUtils.loadInterpolator(launcher,
|
|
|
|
|
R.interpolator.caret_animation_interpolator);
|
2016-07-18 16:35:10 -07:00
|
|
|
mEvaluator = new ArgbEvaluator();
|
|
|
|
|
mAllAppsBackgroundColor = launcher.getColor(R.color.all_apps_container_color);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
2016-06-10 12:00:02 -07:00
|
|
|
mNoIntercept = false;
|
|
|
|
|
if (mLauncher.getWorkspace().isInOverviewMode() || mLauncher.isWidgetsViewVisible()) {
|
|
|
|
|
mNoIntercept = true;
|
2016-06-13 12:38:32 -07:00
|
|
|
} else if (mLauncher.isAllAppsVisible() &&
|
2016-06-10 12:00:02 -07:00
|
|
|
!mAppsView.shouldContainerScroll(ev.getX(), ev.getY())) {
|
|
|
|
|
mNoIntercept = true;
|
2016-06-15 16:45:48 -07:00
|
|
|
} else if (!mLauncher.isAllAppsVisible() && !shouldPossiblyIntercept(ev)) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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-06-13 12:38:32 -07:00
|
|
|
return mDetector.shouldIntercept();
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-15 16:45:48 -07:00
|
|
|
private boolean shouldPossiblyIntercept(MotionEvent ev) {
|
|
|
|
|
DeviceProfile grid = mLauncher.getDeviceProfile();
|
2016-06-30 17:22:26 -07:00
|
|
|
if (mDetector.isIdleState()) {
|
2016-06-21 16:37:13 -07:00
|
|
|
if (grid.isVerticalBarLayout()) {
|
|
|
|
|
if (ev.getY() > mLauncher.getDeviceProfile().heightPx - mBezelSwipeUpHeight) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-06-27 22:00:48 -07:00
|
|
|
if ((mLauncher.getDragLayer().isEventOverHotseat(ev)
|
|
|
|
|
|| mLauncher.getDragLayer().isEventOverPageIndicator(ev))
|
|
|
|
|
&& !grid.isVerticalBarLayout()) {
|
2016-06-21 16:37:13 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2016-06-15 16:45:48 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
|
|
|
return mDetector.onTouchEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 12:38:32 -07:00
|
|
|
private boolean isInDisallowRecatchTopZone() {
|
2016-06-21 16:37:13 -07:00
|
|
|
return mShiftCurrent / mShiftRange < RECATCH_REJECTION_FRACTION;
|
2016-06-13 12:38:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isInDisallowRecatchBottomZone() {
|
2016-06-21 16:37:13 -07:00
|
|
|
return mShiftCurrent / mShiftRange > 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-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-06-29 16:40:06 -07:00
|
|
|
float progress = Math.min(Math.max(0, mShiftStart + displacement), mShiftRange);
|
|
|
|
|
setProgress(progress);
|
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(
|
|
|
|
|
LauncherLogProto.Action.FLING,
|
|
|
|
|
LauncherLogProto.Action.UP,
|
|
|
|
|
LauncherLogProto.HOTSEAT);
|
2016-06-21 16:37:13 -07:00
|
|
|
mLauncher.showAppsView(true, true, false, false);
|
|
|
|
|
} else {
|
|
|
|
|
animateToAllApps(mCurrentAnimation, mAnimationDuration, true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
|
|
|
|
|
if (mLauncher.isAllAppsVisible()) {
|
|
|
|
|
mLauncher.showWorkspace(true);
|
|
|
|
|
} else {
|
|
|
|
|
animateToWorkspace(mCurrentAnimation, mAnimationDuration, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// snap to top or bottom using the release velocity
|
|
|
|
|
} else {
|
|
|
|
|
if (mAppsView.getTranslationY() > mShiftRange / 2) {
|
|
|
|
|
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
|
|
|
|
|
if (mLauncher.isAllAppsVisible()) {
|
|
|
|
|
mLauncher.showWorkspace(true);
|
|
|
|
|
} else {
|
|
|
|
|
animateToWorkspace(mCurrentAnimation, mAnimationDuration, true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
calculateDuration(velocity, Math.abs(mAppsView.getTranslationY()));
|
|
|
|
|
if (!mLauncher.isAllAppsVisible()) {
|
2016-07-21 11:48:37 -07:00
|
|
|
mLauncher.getUserEventDispatcher().logActionOnContainer(
|
|
|
|
|
LauncherLogProto.Action.SWIPE,
|
|
|
|
|
LauncherLogProto.Action.UP,
|
|
|
|
|
LauncherLogProto.HOTSEAT);
|
2016-06-21 16:37:13 -07:00
|
|
|
mLauncher.showAppsView(true, true, false, false);
|
|
|
|
|
} else {
|
|
|
|
|
animateToAllApps(mCurrentAnimation, mAnimationDuration, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-14 15:09:11 -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);
|
|
|
|
|
mHotseat.bringToFront();
|
2016-06-06 14:19:02 -07:00
|
|
|
if (!mLauncher.isAllAppsVisible()) {
|
2016-06-15 16:45:48 -07:00
|
|
|
mLauncher.tryAndUpdatePredictedApps();
|
2016-07-18 16:35:10 -07:00
|
|
|
mHotseatBackgroundColor = mHotseat.getBackgroundDrawableColor();
|
2016-06-20 13:54:42 -07:00
|
|
|
mHotseat.setBackgroundTransparent(true /* transparent */);
|
2016-06-06 14:19:02 -07:00
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
|
|
|
|
mAppsView.getContentView().setVisibility(View.VISIBLE);
|
2016-06-08 16:29:32 -07:00
|
|
|
mAppsView.getContentView().setBackground(null);
|
|
|
|
|
mAppsView.getRevealView().setVisibility(View.VISIBLE);
|
2016-07-18 16:35:10 -07:00
|
|
|
mAppsView.setRevealDrawableColor(mHotseatBackgroundColor);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
|
|
|
|
setProgress(mShiftCurrent);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 16:45:48 -07:00
|
|
|
private void updateLightStatusBar(float progress) {
|
2016-07-12 11:14:41 -07:00
|
|
|
boolean enable = progress <= mStatusBarHeight / 2;
|
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-06-15 16:45:48 -07:00
|
|
|
// Already set correctly
|
|
|
|
|
if (mLightStatusBar == enable) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
int systemUiFlags = mLauncher.getWindow().getDecorView().getSystemUiVisibility();
|
|
|
|
|
if (enable) {
|
|
|
|
|
mLauncher.getWindow().getDecorView().setSystemUiVisibility(systemUiFlags
|
2016-06-29 14:03:20 -07:00
|
|
|
| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
mLauncher.getWindow().getDecorView().setSystemUiVisibility(systemUiFlags
|
2016-06-29 14:03:20 -07:00
|
|
|
& ~(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR));
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
}
|
2016-06-15 16:45:48 -07:00
|
|
|
mLightStatusBar = enable;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param progress y value of the border between hotseat and all apps
|
|
|
|
|
*/
|
|
|
|
|
public void setProgress(float progress) {
|
2016-06-15 16:45:48 -07:00
|
|
|
updateLightStatusBar(progress);
|
2016-06-21 16:37:13 -07:00
|
|
|
mShiftCurrent = progress;
|
2016-06-06 14:19:02 -07:00
|
|
|
float alpha = calcAlphaAllApps(progress);
|
2016-06-08 16:29:32 -07:00
|
|
|
float workspaceHotseatAlpha = 1 - alpha;
|
2016-07-18 17:18:02 -07:00
|
|
|
float interpolation = mAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
|
2016-06-08 16:29:32 -07:00
|
|
|
|
2016-07-18 16:35:10 -07:00
|
|
|
int color = (Integer) mEvaluator.evaluate(mDecelInterpolator.getInterpolation(alpha),
|
|
|
|
|
mHotseatBackgroundColor, mAllAppsBackgroundColor);
|
|
|
|
|
mAppsView.setRevealDrawableColor(color);
|
2016-06-08 16:29:32 -07:00
|
|
|
mAppsView.getContentView().setAlpha(alpha);
|
|
|
|
|
mAppsView.setTranslationY(progress);
|
2016-07-11 17:30:03 -07:00
|
|
|
mWorkspace.setWorkspaceYTranslationAndAlpha(
|
2016-06-21 16:37:13 -07:00
|
|
|
PARALLAX_COEFFICIENT * (-mShiftRange + progress),
|
2016-07-18 17:18:02 -07:00
|
|
|
interpolation);
|
|
|
|
|
if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
|
|
|
|
|
mWorkspace.setHotseatTranslationAndAlpha(Direction.Y,
|
|
|
|
|
PARALLAX_COEFFICIENT * (-mShiftRange + progress), interpolation);
|
2016-06-21 16:37:13 -07:00
|
|
|
} else {
|
2016-07-06 15:03:59 -07:00
|
|
|
mWorkspace.setHotseatTranslationAndAlpha(Direction.Y,
|
2016-07-18 17:18:02 -07:00
|
|
|
-mShiftRange + progress, interpolation);
|
2016-06-21 16:37:13 -07:00
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getProgress() {
|
2016-06-21 16:37:13 -07:00
|
|
|
return mShiftCurrent;
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float calcAlphaAllApps(float progress) {
|
2016-07-14 15:09:11 -07:00
|
|
|
return ((mShiftRange - progress) / mShiftRange);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void calculateDuration(float velocity, float disp) {
|
|
|
|
|
// TODO: make these values constants after tuning.
|
2016-06-15 16:45:48 -07:00
|
|
|
float velocityDivisor = Math.max(1.5f, Math.abs(0.5f * velocity));
|
2016-06-21 16:37:13 -07:00
|
|
|
float travelDistance = Math.max(0.2f, disp / mShiftRange);
|
2016-06-08 16:29:32 -07:00
|
|
|
mAnimationDuration = (long) Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
|
|
|
|
|
if (DBG) {
|
|
|
|
|
Log.d(TAG, String.format("calculateDuration=%d, v=%f, d=%f", mAnimationDuration, velocity, disp));
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 16:37:13 -07:00
|
|
|
public void animateToAllApps(AnimatorSet animationOut, long duration, boolean start) {
|
2016-07-14 15:09:11 -07:00
|
|
|
if (animationOut == null) {
|
2016-06-06 14:19:02 -07:00
|
|
|
return;
|
|
|
|
|
}
|
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-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
final float fromAllAppsTop = mAppsView.getTranslationY();
|
|
|
|
|
final float toAllAppsTop = 0;
|
|
|
|
|
|
|
|
|
|
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
|
|
|
|
|
fromAllAppsTop, toAllAppsTop);
|
2016-06-08 16:29:32 -07:00
|
|
|
driftAndAlpha.setDuration(mAnimationDuration);
|
|
|
|
|
driftAndAlpha.setInterpolator(new PagedView.ScrollInterpolator());
|
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-06-21 16:37:13 -07:00
|
|
|
if (start) {
|
|
|
|
|
mCurrentAnimation.start();
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-21 16:37:13 -07:00
|
|
|
public void animateToWorkspace(AnimatorSet animationOut, long duration, boolean start) {
|
2016-07-14 15:09:11 -07:00
|
|
|
if (animationOut == null) {
|
2016-06-06 14:19:02 -07:00
|
|
|
return;
|
|
|
|
|
}
|
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-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
final float fromAllAppsTop = mAppsView.getTranslationY();
|
2016-06-21 16:37:13 -07:00
|
|
|
final float toAllAppsTop = mShiftRange;
|
2016-06-06 14:19:02 -07:00
|
|
|
|
|
|
|
|
ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
|
|
|
|
|
fromAllAppsTop, toAllAppsTop);
|
2016-06-08 16:29:32 -07:00
|
|
|
driftAndAlpha.setDuration(mAnimationDuration);
|
|
|
|
|
driftAndAlpha.setInterpolator(new PagedView.ScrollInterpolator());
|
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;
|
|
|
|
|
setProgress(mShiftCurrent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (canceled) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2016-07-13 14:04:13 -07:00
|
|
|
finishPullDown(true);
|
2016-07-14 15:09:11 -07:00
|
|
|
cleanUpAnimation();
|
|
|
|
|
mDetector.finishedScrolling();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-06-06 14:19:02 -07:00
|
|
|
mCurrentAnimation = animationOut;
|
2016-06-21 16:37:13 -07:00
|
|
|
if (start) {
|
|
|
|
|
mCurrentAnimation.start();
|
|
|
|
|
}
|
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-13 14:04:13 -07:00
|
|
|
animateCaret();
|
2016-06-15 16:45:48 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-13 14:04:13 -07:00
|
|
|
public void finishPullDown(boolean animated) {
|
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-06-21 16:37:13 -07:00
|
|
|
setProgress(mShiftRange);
|
2016-07-13 14:04:13 -07:00
|
|
|
if (animated) {
|
|
|
|
|
animateCaret();
|
|
|
|
|
} else {
|
|
|
|
|
mWorkspace.getPageIndicator().getCaretDrawable()
|
|
|
|
|
.setLevel(CaretDrawable.LEVEL_CARET_POINTING_UP);
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelAnimation() {
|
|
|
|
|
if (mCurrentAnimation != null) {
|
2016-06-21 16:37:13 -07:00
|
|
|
mCurrentAnimation.setDuration(0);
|
2016-06-06 14:19:02 -07:00
|
|
|
mCurrentAnimation.cancel();
|
|
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cleanUpAnimation() {
|
|
|
|
|
mCurrentAnimation = null;
|
|
|
|
|
}
|
2016-06-20 13:54:42 -07:00
|
|
|
|
2016-07-13 14:04:13 -07:00
|
|
|
private void animateCaret() {
|
|
|
|
|
if (mCaretAnimator.isRunning()) {
|
|
|
|
|
mCaretAnimator.cancel(); // stop the animator in its tracks
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mLauncher.isAllAppsVisible()) {
|
|
|
|
|
mCaretAnimator.setIntValues(CaretDrawable.LEVEL_CARET_POINTING_DOWN);
|
|
|
|
|
} else {
|
|
|
|
|
mCaretAnimator.setIntValues(CaretDrawable.LEVEL_CARET_POINTING_UP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mCaretAnimator.start();
|
|
|
|
|
}
|
|
|
|
|
|
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-13 14:04:13 -07:00
|
|
|
mCaretAnimator = ObjectAnimator.ofInt(mWorkspace.getPageIndicator().getCaretDrawable(),
|
|
|
|
|
"level", CaretDrawable.LEVEL_CARET_POINTING_UP); // we will set values later
|
|
|
|
|
mCaretAnimator.setDuration(mCaretAnimationDuration);
|
|
|
|
|
mCaretAnimator.setInterpolator(mCaretInterpolator);
|
2016-06-29 21:25:33 -07:00
|
|
|
mHotseat.addOnLayoutChangeListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
2016-07-14 15:09:11 -07:00
|
|
|
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
2016-07-07 15:57:42 -07:00
|
|
|
float prevShiftRatio = mShiftCurrent / mShiftRange;
|
2016-06-29 21:25:33 -07:00
|
|
|
if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
|
|
|
|
|
mShiftRange = top;
|
|
|
|
|
} else {
|
|
|
|
|
mShiftRange = bottom;
|
|
|
|
|
}
|
2016-07-07 15:57:42 -07:00
|
|
|
setProgress(mShiftRange * prevShiftRatio);
|
2016-06-20 13:54:42 -07:00
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|