2016-06-06 14:19:02 -07:00
|
|
|
package com.android.launcher3.allapps;
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
import static com.android.launcher3.LauncherState.ALL_APPS_CONTENT;
|
2018-03-21 08:16:33 -07:00
|
|
|
import static com.android.launcher3.LauncherState.ALL_APPS_HEADER_EXTRA;
|
2020-02-25 14:29:37 -08:00
|
|
|
import static com.android.launcher3.LauncherState.APPS_VIEW_ITEM_MASK;
|
2018-05-16 12:23:12 -07:00
|
|
|
import static com.android.launcher3.LauncherState.OVERVIEW;
|
2018-05-22 13:22:25 -07:00
|
|
|
import static com.android.launcher3.LauncherState.VERTICAL_SWIPE_INDICATOR;
|
2018-06-19 17:23:11 -07:00
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_ALL_APPS_FADE;
|
2019-06-18 17:04:49 -07:00
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_ALL_APPS_HEADER_FADE;
|
2018-05-16 12:23:12 -07:00
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_OVERVIEW_SCALE;
|
2018-03-21 09:32:27 -07:00
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_VERTICAL_PROGRESS;
|
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;
|
2018-03-14 17:51:49 -07:00
|
|
|
import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
|
2018-01-31 15:18:11 -08:00
|
|
|
import static com.android.launcher3.util.SystemUiController.UI_STATE_ALL_APPS;
|
2017-10-23 17:14:52 -07:00
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2020-01-07 11:22:51 -08:00
|
|
|
import android.animation.ObjectAnimator;
|
2019-06-19 21:30:40 -07:00
|
|
|
import android.util.FloatProperty;
|
2016-06-06 14:19:02 -07:00
|
|
|
import android.view.animation.Interpolator;
|
|
|
|
|
|
2018-01-31 15:18:11 -08:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2018-02-01 14:46:13 -08:00
|
|
|
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
|
2016-06-06 14:19:02 -07:00
|
|
|
import com.android.launcher3.Launcher;
|
2017-10-18 10:55:56 -07:00
|
|
|
import com.android.launcher3.LauncherState;
|
2017-10-23 17:14:52 -07:00
|
|
|
import com.android.launcher3.LauncherStateManager.AnimationConfig;
|
2018-02-01 14:46:13 -08:00
|
|
|
import com.android.launcher3.LauncherStateManager.StateHandler;
|
2016-06-21 16:37:13 -07:00
|
|
|
import com.android.launcher3.R;
|
2017-10-20 17:05:27 -07:00
|
|
|
import com.android.launcher3.anim.AnimationSuccessListener;
|
2017-12-07 12:45:49 -08:00
|
|
|
import com.android.launcher3.anim.AnimatorSetBuilder;
|
2018-03-14 17:51:49 -07:00
|
|
|
import com.android.launcher3.anim.PropertySetter;
|
2017-02-10 16:52:16 -08:00
|
|
|
import com.android.launcher3.util.Themes;
|
2018-05-04 13:19:29 -07:00
|
|
|
import com.android.launcher3.views.ScrimView;
|
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
|
|
|
*/
|
2019-06-19 21:30:40 -07:00
|
|
|
public class AllAppsTransitionController implements StateHandler, OnDeviceProfileChangeListener {
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2019-06-19 21:30:40 -07:00
|
|
|
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS =
|
|
|
|
|
new FloatProperty<AllAppsTransitionController>("allAppsProgress") {
|
2017-10-20 17:05:27 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Float get(AllAppsTransitionController controller) {
|
|
|
|
|
return controller.mProgress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-06-19 21:30:40 -07:00
|
|
|
public void setValue(AllAppsTransitionController controller, float progress) {
|
2017-10-20 17:05:27 -07:00
|
|
|
controller.setProgress(progress);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-09 09:56:53 -04:00
|
|
|
private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 0;
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
private AllAppsContainerView mAppsView;
|
2018-05-04 13:19:29 -07:00
|
|
|
private ScrimView mScrimView;
|
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;
|
2018-01-31 15:18:11 -08:00
|
|
|
private boolean mIsVerticalLayout;
|
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
|
|
|
|
2018-03-28 13:17:32 -07:00
|
|
|
private float mScrollRangeDelta = 0;
|
2016-07-07 15:57:42 -07:00
|
|
|
|
2016-07-21 17:32:43 -07:00
|
|
|
public AllAppsTransitionController(Launcher l) {
|
|
|
|
|
mLauncher = l;
|
2018-03-28 13:17:32 -07:00
|
|
|
mShiftRange = mLauncher.getDeviceProfile().heightPx;
|
2016-07-21 17:32:43 -07:00
|
|
|
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);
|
2018-02-01 14:46:13 -08:00
|
|
|
mIsVerticalLayout = mLauncher.getDeviceProfile().isVerticalBarLayout();
|
|
|
|
|
mLauncher.addOnDeviceProfileChangeListener(this);
|
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
|
|
|
|
2018-02-01 14:46:13 -08:00
|
|
|
@Override
|
|
|
|
|
public void onDeviceProfileChanged(DeviceProfile dp) {
|
|
|
|
|
mIsVerticalLayout = dp.isVerticalBarLayout();
|
2018-03-28 13:17:32 -07:00
|
|
|
setScrollRangeDelta(mScrollRangeDelta);
|
2018-02-01 14:46:13 -08:00
|
|
|
|
|
|
|
|
if (mIsVerticalLayout) {
|
2019-04-09 09:56:53 -04:00
|
|
|
mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(1);
|
2018-02-01 14:46:13 -08:00
|
|
|
mLauncher.getHotseat().setTranslationY(0);
|
|
|
|
|
mLauncher.getWorkspace().getPageIndicator().setTranslationY(0);
|
|
|
|
|
}
|
2018-01-31 15:18:11 -08:00
|
|
|
}
|
|
|
|
|
|
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)
|
2017-12-07 11:42:33 -08:00
|
|
|
* @see #setStateWithAnimation(LauncherState, AnimatorSetBuilder, AnimationConfig)
|
2016-06-06 14:19:02 -07:00
|
|
|
*/
|
|
|
|
|
public void setProgress(float progress) {
|
2016-07-21 17:32:43 -07:00
|
|
|
mProgress = progress;
|
2018-05-04 13:19:29 -07:00
|
|
|
mScrimView.setProgress(progress);
|
2016-07-21 17:32:43 -07:00
|
|
|
float shiftCurrent = progress * mShiftRange;
|
|
|
|
|
|
|
|
|
|
mAppsView.setTranslationY(shiftCurrent);
|
2016-08-02 13:31:22 -07:00
|
|
|
|
2018-02-28 15:09:36 -08:00
|
|
|
// Use a light system UI (dark icons) if all apps is behind at least half of the
|
|
|
|
|
// status bar.
|
2018-05-16 14:26:40 -07:00
|
|
|
boolean forceChange = shiftCurrent - mScrimView.getDragHandleSize()
|
|
|
|
|
<= mLauncher.getDeviceProfile().getInsets().top / 2;
|
2018-02-28 15:09:36 -08:00
|
|
|
if (forceChange) {
|
|
|
|
|
mLauncher.getSystemUiController().updateUiState(UI_STATE_ALL_APPS, !mIsDarkTheme);
|
|
|
|
|
} else {
|
|
|
|
|
mLauncher.getSystemUiController().updateUiState(UI_STATE_ALL_APPS, 0);
|
2018-01-04 15:35:22 -08:00
|
|
|
}
|
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) {
|
2018-01-04 15:35:22 -08:00
|
|
|
setProgress(state.getVerticalProgress(mLauncher));
|
2018-06-19 17:23:11 -07:00
|
|
|
setAlphas(state, null, new AnimatorSetBuilder());
|
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
|
2017-12-07 11:42:33 -08:00
|
|
|
public void setStateWithAnimation(LauncherState toState,
|
2017-12-07 12:45:49 -08:00
|
|
|
AnimatorSetBuilder builder, AnimationConfig config) {
|
2018-01-04 15:35:22 -08:00
|
|
|
float targetProgress = toState.getVerticalProgress(mLauncher);
|
|
|
|
|
if (Float.compare(mProgress, targetProgress) == 0) {
|
2018-06-19 17:23:11 -07:00
|
|
|
setAlphas(toState, config, builder);
|
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
|
|
|
|
2018-04-19 11:39:34 -07:00
|
|
|
if (!config.playNonAtomicComponent()) {
|
|
|
|
|
// There is no atomic component for the all apps transition, so just return early.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:23:12 -07:00
|
|
|
Interpolator interpolator = config.userControlled ? LINEAR : toState == OVERVIEW
|
|
|
|
|
? builder.getInterpolator(ANIM_OVERVIEW_SCALE, FAST_OUT_SLOW_IN)
|
|
|
|
|
: FAST_OUT_SLOW_IN;
|
2019-06-20 11:34:14 -07:00
|
|
|
Animator anim = createSpringAnimation(mProgress, targetProgress);
|
2017-11-07 12:23:58 -08:00
|
|
|
anim.setDuration(config.duration);
|
2018-03-21 09:32:27 -07:00
|
|
|
anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator));
|
2017-12-05 15:11:21 -08:00
|
|
|
anim.addListener(getProgressAnimatorListener());
|
2017-09-05 11:32:13 -07:00
|
|
|
|
2017-12-07 12:45:49 -08:00
|
|
|
builder.play(anim);
|
2018-03-14 17:51:49 -07:00
|
|
|
|
2018-06-19 17:23:11 -07:00
|
|
|
setAlphas(toState, config, builder);
|
2018-03-14 17:51:49 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-20 11:34:14 -07:00
|
|
|
public Animator createSpringAnimation(float... progressValues) {
|
2020-01-07 11:22:51 -08:00
|
|
|
return ObjectAnimator.ofFloat(this, ALL_APPS_PROGRESS, progressValues);
|
2019-06-20 11:34:14 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-19 17:23:11 -07:00
|
|
|
private void setAlphas(LauncherState toState, AnimationConfig config,
|
|
|
|
|
AnimatorSetBuilder builder) {
|
2019-02-11 15:03:47 -08:00
|
|
|
setAlphas(toState.getVisibleElements(mLauncher), config, builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAlphas(int visibleElements, AnimationConfig config, AnimatorSetBuilder builder) {
|
2018-06-19 17:23:11 -07:00
|
|
|
PropertySetter setter = config == null ? NO_ANIM_PROPERTY_SETTER
|
|
|
|
|
: config.getPropertySetter(builder);
|
2018-03-21 08:16:33 -07:00
|
|
|
boolean hasHeaderExtra = (visibleElements & ALL_APPS_HEADER_EXTRA) != 0;
|
2019-06-18 17:04:49 -07:00
|
|
|
boolean hasAllAppsContent = (visibleElements & ALL_APPS_CONTENT) != 0;
|
2018-03-14 17:51:49 -07:00
|
|
|
|
2020-02-25 14:29:37 -08:00
|
|
|
boolean hasAnyVisibleItem = (visibleElements & APPS_VIEW_ITEM_MASK) != 0;
|
|
|
|
|
|
2018-06-19 17:23:11 -07:00
|
|
|
Interpolator allAppsFade = builder.getInterpolator(ANIM_ALL_APPS_FADE, LINEAR);
|
2019-06-18 17:04:49 -07:00
|
|
|
Interpolator headerFade = builder.getInterpolator(ANIM_ALL_APPS_HEADER_FADE, allAppsFade);
|
2019-09-03 16:16:54 -07:00
|
|
|
setter.setViewAlpha(mAppsView.getContentView(), hasAllAppsContent ? 1 : 0, allAppsFade);
|
2019-06-18 17:04:49 -07:00
|
|
|
setter.setViewAlpha(mAppsView.getScrollBar(), hasAllAppsContent ? 1 : 0, allAppsFade);
|
|
|
|
|
mAppsView.getFloatingHeaderView().setContentVisibility(hasHeaderExtra, hasAllAppsContent,
|
|
|
|
|
setter, headerFade, allAppsFade);
|
2018-11-02 13:50:40 -07:00
|
|
|
mAppsView.getSearchUiManager().setContentVisibility(visibleElements, setter, allAppsFade);
|
2018-05-22 13:22:25 -07:00
|
|
|
|
|
|
|
|
setter.setInt(mScrimView, ScrimView.DRAG_HANDLE_ALPHA,
|
2019-03-25 10:23:39 -05:00
|
|
|
(visibleElements & VERTICAL_SWIPE_INDICATOR) != 0 ? 255 : 0, allAppsFade);
|
2020-02-25 14:29:37 -08:00
|
|
|
|
|
|
|
|
setter.setViewAlpha(mAppsView, hasAnyVisibleItem ? 1 : 0, allAppsFade);
|
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-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
public void setupViews(AllAppsContainerView appsView) {
|
2016-06-20 13:54:42 -07:00
|
|
|
mAppsView = appsView;
|
2018-05-04 13:19:29 -07:00
|
|
|
mScrimView = mLauncher.findViewById(R.id.scrim_view);
|
2016-06-29 21:25:33 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-28 13:17:32 -07:00
|
|
|
/**
|
|
|
|
|
* Updates the total scroll range but does not update the UI.
|
|
|
|
|
*/
|
2018-11-20 13:52:55 -08:00
|
|
|
void setScrollRangeDelta(float delta) {
|
2018-03-28 13:17:32 -07:00
|
|
|
mScrollRangeDelta = delta;
|
|
|
|
|
mShiftRange = mLauncher.getDeviceProfile().heightPx - mScrollRangeDelta;
|
2018-04-26 13:51:18 -07:00
|
|
|
|
2018-05-04 13:19:29 -07:00
|
|
|
if (mScrimView != null) {
|
|
|
|
|
mScrimView.reInitUi();
|
2018-04-26 13:51:18 -07:00
|
|
|
}
|
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) {
|
2018-03-14 17:51:49 -07:00
|
|
|
mAppsView.reset(false /* animate */);
|
2018-08-17 14:46:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|