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;
|
2018-03-21 09:32:27 -07:00
|
|
|
import static com.android.launcher3.anim.AlphaUpdateListener.updateVisibility;
|
|
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_OVERVIEW_TRANSLATION;
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
|
|
|
|
import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled;
|
2018-03-15 12:48:51 +00:00
|
|
|
import static com.android.quickstep.views.LauncherRecentsView.TRANSLATION_X_FACTOR;
|
|
|
|
|
import static com.android.quickstep.views.LauncherRecentsView.TRANSLATION_Y_FACTOR;
|
2017-12-22 17:33:02 -08:00
|
|
|
|
2018-03-21 09:32:27 -07:00
|
|
|
import android.animation.ValueAnimator;
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.os.Build;
|
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-07 12:45:49 -08:00
|
|
|
import com.android.launcher3.anim.AnimatorSetBuilder;
|
2018-03-21 09:32:27 -07:00
|
|
|
import com.android.launcher3.anim.PropertySetter;
|
|
|
|
|
import com.android.quickstep.views.LauncherRecentsView;
|
2017-11-07 12:23:58 -08:00
|
|
|
|
2018-03-21 09:32:27 -07:00
|
|
|
@TargetApi(Build.VERSION_CODES.O)
|
2017-11-07 12:23:58 -08:00
|
|
|
public class RecentsViewStateController implements StateHandler {
|
|
|
|
|
|
|
|
|
|
private final Launcher mLauncher;
|
2018-03-21 09:32:27 -07:00
|
|
|
private final LauncherRecentsView mRecentsView;
|
2018-01-26 16:45:23 -08:00
|
|
|
|
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-21 09:32:27 -07:00
|
|
|
mRecentsView.setAlpha(state.overviewUi ? 1 : 0);
|
|
|
|
|
updateVisibility(mRecentsView, isAccessibilityEnabled(mLauncher));
|
2018-03-15 12:48:51 +00:00
|
|
|
float[] translationFactor = state.getOverviewTranslationFactor(mLauncher);
|
|
|
|
|
mRecentsView.setTranslationXFactor(translationFactor[0]);
|
|
|
|
|
mRecentsView.setTranslationYFactor(translationFactor[1]);
|
2018-03-02 14:57:46 -08:00
|
|
|
if (state.overviewUi) {
|
2018-03-13 16:44:00 -07:00
|
|
|
mRecentsView.resetTaskVisuals();
|
2018-02-13 11:28:12 -08:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2018-03-21 09:32:27 -07:00
|
|
|
PropertySetter setter = config.getProperSetter(builder);
|
2018-03-15 12:48:51 +00:00
|
|
|
float[] translationFactor = toState.getOverviewTranslationFactor(mLauncher);
|
|
|
|
|
setter.setFloat(mRecentsView, TRANSLATION_X_FACTOR,
|
|
|
|
|
translationFactor[0],
|
|
|
|
|
builder.getInterpolator(ANIM_OVERVIEW_TRANSLATION, LINEAR));
|
|
|
|
|
setter.setFloat(mRecentsView, TRANSLATION_Y_FACTOR,
|
|
|
|
|
translationFactor[1],
|
2018-03-21 09:32:27 -07:00
|
|
|
builder.getInterpolator(ANIM_OVERVIEW_TRANSLATION, LINEAR));
|
|
|
|
|
setter.setViewAlpha(mRecentsView, toState.overviewUi ? 1 : 0, LINEAR);
|
2018-03-14 12:05:00 +00:00
|
|
|
|
|
|
|
|
if (toState.overviewUi) {
|
2018-03-21 09:32:27 -07:00
|
|
|
ValueAnimator updateAnim = ValueAnimator.ofFloat(0, 1);
|
|
|
|
|
updateAnim.addUpdateListener(valueAnimator -> {
|
2018-03-14 12:05:00 +00:00
|
|
|
// While animating into recents, update the visible task data as needed
|
|
|
|
|
mRecentsView.loadVisibleTaskData();
|
|
|
|
|
});
|
2018-03-21 09:32:27 -07:00
|
|
|
updateAnim.setDuration(config.duration);
|
|
|
|
|
builder.play(updateAnim);
|
2018-03-14 12:05:00 +00:00
|
|
|
}
|
2017-11-07 12:23:58 -08:00
|
|
|
}
|
|
|
|
|
}
|