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;
|
|
|
|
|
import static com.android.launcher3.LauncherState.ALL_APPS_HEADER;
|
2018-03-21 08:16:33 -07:00
|
|
|
import static com.android.launcher3.LauncherState.ALL_APPS_HEADER_EXTRA;
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
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;
|
2018-02-01 14:46:13 -08:00
|
|
|
import com.android.launcher3.allapps.SearchUiManager.OnScrollRangeChangeListener;
|
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;
|
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
|
2018-02-01 14:46:13 -08:00
|
|
|
implements OnScrollRangeChangeListener, StateHandler, OnDeviceProfileChangeListener {
|
2016-06-06 14:19:02 -07:00
|
|
|
|
2018-01-23 11:13:05 -08:00
|
|
|
public static final Property<AllAppsTransitionController, Float> ALL_APPS_PROGRESS =
|
|
|
|
|
new Property<AllAppsTransitionController, Float>(Float.class, "allAppsProgress") {
|
2017-10-20 17:05:27 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Float get(AllAppsTransitionController controller) {
|
|
|
|
|
return controller.mProgress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void set(AllAppsTransitionController controller, Float progress) {
|
|
|
|
|
controller.setProgress(progress);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-06 14:19:02 -07:00
|
|
|
private AllAppsContainerView mAppsView;
|
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
|
|
|
|
2016-07-07 15:57:42 -07:00
|
|
|
private static final float DEFAULT_SHIFT_RANGE = 10;
|
|
|
|
|
|
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);
|
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
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
private void onProgressAnimationStart() {
|
|
|
|
|
// Initialize values that should not change until #onDragEnd
|
|
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
|
|
|
|
|
2018-02-01 14:46:13 -08:00
|
|
|
@Override
|
|
|
|
|
public void onDeviceProfileChanged(DeviceProfile dp) {
|
|
|
|
|
mIsVerticalLayout = dp.isVerticalBarLayout();
|
|
|
|
|
|
|
|
|
|
if (mIsVerticalLayout) {
|
|
|
|
|
mAppsView.setAlpha(1);
|
|
|
|
|
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;
|
|
|
|
|
float shiftCurrent = progress * mShiftRange;
|
|
|
|
|
|
|
|
|
|
mAppsView.setTranslationY(shiftCurrent);
|
2017-12-13 17:16:54 -08:00
|
|
|
float hotseatTranslation = -mShiftRange + shiftCurrent;
|
|
|
|
|
|
2018-01-04 15:35:22 -08:00
|
|
|
if (!mIsVerticalLayout) {
|
2018-01-19 14:26:18 -08:00
|
|
|
mLauncher.getHotseat().setTranslationY(hotseatTranslation);
|
|
|
|
|
mLauncher.getWorkspace().getPageIndicator().setTranslationY(hotseatTranslation);
|
2018-03-26 12:10:31 -07:00
|
|
|
mLauncher.getDragHandleIndicator().setTranslationY(hotseatTranslation);
|
2018-02-28 15:09:36 -08:00
|
|
|
}
|
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.
|
|
|
|
|
boolean forceChange = shiftCurrent <= mShiftRange / 4;
|
|
|
|
|
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-03-14 17:51:49 -07:00
|
|
|
setAlphas(state, NO_ANIM_PROPERTY_SETTER);
|
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-03-14 17:51:49 -07:00
|
|
|
setAlphas(toState, config.getProperSetter(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
|
|
|
|
2017-11-07 12:23:58 -08:00
|
|
|
Interpolator interpolator = config.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
|
2018-01-23 11:13:05 -08:00
|
|
|
ObjectAnimator anim =
|
|
|
|
|
ObjectAnimator.ofFloat(this, ALL_APPS_PROGRESS, 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
|
|
|
|
|
|
|
|
setAlphas(toState, config.getProperSetter(builder));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setAlphas(LauncherState toState, PropertySetter setter) {
|
|
|
|
|
int visibleElements = toState.getVisibleElements(mLauncher);
|
|
|
|
|
boolean hasHeader = (visibleElements & ALL_APPS_HEADER) != 0;
|
2018-03-21 08:16:33 -07:00
|
|
|
boolean hasHeaderExtra = (visibleElements & ALL_APPS_HEADER_EXTRA) != 0;
|
2018-03-14 17:51:49 -07:00
|
|
|
boolean hasContent = (visibleElements & ALL_APPS_CONTENT) != 0;
|
|
|
|
|
|
|
|
|
|
setter.setViewAlpha(mAppsView.getSearchView(), hasHeader ? 1 : 0, LINEAR);
|
|
|
|
|
setter.setViewAlpha(mAppsView.getContentView(), hasContent ? 1 : 0, LINEAR);
|
|
|
|
|
setter.setViewAlpha(mAppsView.getScrollBar(), hasContent ? 1 : 0, LINEAR);
|
2018-03-21 08:16:33 -07:00
|
|
|
mAppsView.getFloatingHeaderView().setContentVisibility(hasHeaderExtra, hasContent, setter);
|
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
|
|
|
}
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
public void setupViews(AllAppsContainerView appsView) {
|
2016-06-20 13:54:42 -07:00
|
|
|
mAppsView = appsView;
|
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);
|
2018-03-14 17:51:49 -07:00
|
|
|
mAppsView.reset(false /* animate */);
|
2017-10-20 17:05:27 -07:00
|
|
|
} else if (Float.compare(mProgress, 0f) == 0) {
|
|
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
2018-01-10 16:55:49 +00:00
|
|
|
mAppsView.onScrollUpEnd();
|
2018-01-04 15:35:22 -08:00
|
|
|
} else {
|
|
|
|
|
mAppsView.setVisibility(View.VISIBLE);
|
2017-10-20 17:05:27 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|