2017-11-07 12:23:58 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.uioverrides;
|
|
|
|
|
|
2017-12-22 17:33:02 -08:00
|
|
|
import static com.android.launcher3.LauncherState.NORMAL;
|
|
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
|
import android.view.View;
|
2017-11-07 12:23:58 -08:00
|
|
|
|
|
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.LauncherState;
|
|
|
|
|
import com.android.launcher3.LauncherStateManager.AnimationConfig;
|
|
|
|
|
import com.android.launcher3.LauncherStateManager.StateHandler;
|
2018-01-04 17:16:05 -08:00
|
|
|
import com.android.launcher3.PagedView;
|
2017-12-06 10:25:07 -08:00
|
|
|
import com.android.launcher3.anim.AnimationSuccessListener;
|
2017-12-07 12:45:49 -08:00
|
|
|
import com.android.launcher3.anim.AnimatorSetBuilder;
|
2017-12-06 10:25:07 -08:00
|
|
|
import com.android.launcher3.anim.Interpolators;
|
|
|
|
|
import com.android.quickstep.AnimatedFloat;
|
2018-03-13 09:57:05 -07:00
|
|
|
import com.android.quickstep.views.RecentsView;
|
2017-11-07 12:23:58 -08:00
|
|
|
|
|
|
|
|
public class RecentsViewStateController implements StateHandler {
|
|
|
|
|
|
|
|
|
|
private final Launcher mLauncher;
|
2017-12-06 10:25:07 -08:00
|
|
|
private final RecentsView mRecentsView;
|
|
|
|
|
|
2018-01-26 16:45:23 -08:00
|
|
|
private final AnimatedFloat mTransitionProgress = new AnimatedFloat(this::onTransitionProgress);
|
2017-12-06 10:25:07 -08:00
|
|
|
// The fraction representing the visibility of the RecentsView. This allows delaying the
|
|
|
|
|
// overall transition while the RecentsView is being shown or hidden.
|
2018-01-26 16:45:23 -08:00
|
|
|
private final AnimatedFloat mVisibilityMultiplier = new AnimatedFloat(this::onVisibilityProgress);
|
|
|
|
|
|
2017-11-07 12:23:58 -08:00
|
|
|
public RecentsViewStateController(Launcher launcher) {
|
|
|
|
|
mLauncher = launcher;
|
2017-12-06 10:25:07 -08:00
|
|
|
mRecentsView = launcher.getOverviewPanel();
|
2017-11-07 12:23:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setState(LauncherState state) {
|
2018-03-02 14:57:46 -08:00
|
|
|
setVisibility(state.overviewUi);
|
|
|
|
|
setTransitionProgress(state.overviewUi ? 1 : 0);
|
|
|
|
|
if (state.overviewUi) {
|
2018-03-13 16:44:00 -07:00
|
|
|
mRecentsView.resetTaskVisuals();
|
2018-02-13 11:28:12 -08:00
|
|
|
}
|
2018-03-14 12:05:00 +00:00
|
|
|
float overviewTranslationX = state.getOverviewTranslationX(mLauncher);
|
|
|
|
|
int direction = mRecentsView.isRtl() ? -1 : 1;
|
|
|
|
|
mRecentsView.setTranslationX(overviewTranslationX * direction);
|
2017-11-07 12:23:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-12-15 13:05:42 -08:00
|
|
|
public void setStateWithAnimation(final LauncherState toState,
|
2017-12-07 12:45:49 -08:00
|
|
|
AnimatorSetBuilder builder, AnimationConfig config) {
|
2018-01-26 16:45:23 -08:00
|
|
|
|
2018-01-04 17:16:05 -08:00
|
|
|
// Scroll to the workspace card before changing to the NORMAL state.
|
2018-03-14 12:05:00 +00:00
|
|
|
LauncherState fromState = mLauncher.getStateManager().getState();
|
2018-01-04 17:16:05 -08:00
|
|
|
int currPage = mRecentsView.getCurrentPage();
|
2018-03-03 05:36:23 -08:00
|
|
|
if (fromState.overviewUi && toState == NORMAL && currPage != 0 && !config.userControlled) {
|
2018-01-04 17:16:05 -08:00
|
|
|
int maxSnapDuration = PagedView.SLOW_PAGE_SNAP_ANIMATION_DURATION;
|
|
|
|
|
int durationPerPage = maxSnapDuration / 10;
|
|
|
|
|
int snapDuration = Math.min(maxSnapDuration, durationPerPage * currPage);
|
|
|
|
|
mRecentsView.snapToPage(0, snapDuration);
|
2018-03-09 22:01:47 +00:00
|
|
|
// Let the snapping animation play for a bit before we translate off screen.
|
|
|
|
|
builder.setStartDelay(snapDuration / 4);
|
2018-01-04 17:16:05 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
ObjectAnimator progressAnim =
|
2018-03-02 14:57:46 -08:00
|
|
|
mTransitionProgress.animateToValue(toState.overviewUi ? 1 : 0);
|
2017-12-06 10:25:07 -08:00
|
|
|
progressAnim.setDuration(config.duration);
|
|
|
|
|
progressAnim.setInterpolator(Interpolators.LINEAR);
|
2017-12-07 12:45:49 -08:00
|
|
|
builder.play(progressAnim);
|
2017-12-06 10:25:07 -08:00
|
|
|
|
2018-03-02 14:57:46 -08:00
|
|
|
ObjectAnimator visibilityAnim = animateVisibility(toState.overviewUi);
|
2017-12-06 10:25:07 -08:00
|
|
|
visibilityAnim.setDuration(config.duration);
|
|
|
|
|
visibilityAnim.setInterpolator(Interpolators.LINEAR);
|
2017-12-07 12:45:49 -08:00
|
|
|
builder.play(visibilityAnim);
|
2018-03-14 12:05:00 +00:00
|
|
|
|
|
|
|
|
int direction = mRecentsView.isRtl() ? -1 : 1;
|
|
|
|
|
float fromTranslationX = fromState.getOverviewTranslationX(mLauncher) * direction;
|
|
|
|
|
float toTranslationX = toState.getOverviewTranslationX(mLauncher) * direction;
|
|
|
|
|
ObjectAnimator translationXAnim = ObjectAnimator.ofFloat(mRecentsView, View.TRANSLATION_X,
|
|
|
|
|
fromTranslationX, toTranslationX);
|
|
|
|
|
translationXAnim.setDuration(config.duration);
|
|
|
|
|
translationXAnim.setInterpolator(Interpolators.ACCEL);
|
|
|
|
|
if (toState.overviewUi) {
|
|
|
|
|
translationXAnim.addUpdateListener(valueAnimator -> {
|
|
|
|
|
// While animating into recents, update the visible task data as needed
|
|
|
|
|
mRecentsView.loadVisibleTaskData();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
builder.play(translationXAnim);
|
2017-12-06 10:25:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setVisibility(boolean isVisible) {
|
|
|
|
|
mVisibilityMultiplier.cancelAnimation();
|
|
|
|
|
mRecentsView.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
|
|
|
|
mVisibilityMultiplier.updateValue(isVisible ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObjectAnimator animateVisibility(boolean isVisible) {
|
|
|
|
|
ObjectAnimator anim = mVisibilityMultiplier.animateToValue(isVisible ? 1 : 0);
|
|
|
|
|
if (isVisible) {
|
|
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
mRecentsView.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
anim.addListener(new AnimationSuccessListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationSuccess(Animator animator) {
|
|
|
|
|
mRecentsView.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return anim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTransitionProgress(float progress) {
|
|
|
|
|
mTransitionProgress.cancelAnimation();
|
|
|
|
|
mTransitionProgress.updateValue(progress);
|
2017-11-07 12:23:58 -08:00
|
|
|
}
|
|
|
|
|
|
2018-01-26 16:45:23 -08:00
|
|
|
private void onTransitionProgress() {
|
|
|
|
|
applyProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onVisibilityProgress() {
|
|
|
|
|
applyProgress();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
private void applyProgress() {
|
|
|
|
|
mRecentsView.setAlpha(mTransitionProgress.value * mVisibilityMultiplier.value);
|
2017-11-07 12:23:58 -08:00
|
|
|
}
|
|
|
|
|
}
|