2019-01-15 13:19:06 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 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;
|
|
|
|
|
|
|
|
|
|
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.AGGRESSIVE_EASE_IN_OUT;
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
2019-07-24 17:32:08 -07:00
|
|
|
import static com.android.launcher3.graphics.Scrim.SCRIM_PROGRESS;
|
2020-03-13 13:01:33 -07:00
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCRIM_FADE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.PLAY_ATOMIC_OVERVIEW_PEEK;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.PLAY_ATOMIC_OVERVIEW_SCALE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW;
|
2020-04-01 20:13:12 -07:00
|
|
|
import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_OFFSET;
|
2019-01-15 13:19:06 -08:00
|
|
|
|
|
|
|
|
import android.util.FloatProperty;
|
|
|
|
|
|
2019-07-24 17:32:08 -07:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
2020-03-26 15:28:36 -07:00
|
|
|
import com.android.launcher3.BaseQuickstepLauncher;
|
2019-01-15 13:19:06 -08:00
|
|
|
import com.android.launcher3.LauncherState;
|
|
|
|
|
import com.android.launcher3.LauncherStateManager.StateHandler;
|
2020-03-13 13:01:33 -07:00
|
|
|
import com.android.launcher3.anim.PendingAnimation;
|
2019-07-24 17:32:08 -07:00
|
|
|
import com.android.launcher3.graphics.OverviewScrim;
|
2020-03-13 13:01:33 -07:00
|
|
|
import com.android.launcher3.states.StateAnimationConfig;
|
2020-04-01 20:13:12 -07:00
|
|
|
import com.android.quickstep.views.RecentsView;
|
2019-03-15 16:55:53 -05:00
|
|
|
|
2019-01-15 13:19:06 -08:00
|
|
|
/**
|
|
|
|
|
* State handler for recents view. Manages UI changes and animations for recents view based off the
|
|
|
|
|
* current {@link LauncherState}.
|
|
|
|
|
*
|
|
|
|
|
* @param <T> the recents view
|
|
|
|
|
*/
|
2020-04-01 20:13:12 -07:00
|
|
|
public abstract class BaseRecentsViewStateController<T extends RecentsView>
|
2019-01-15 13:19:06 -08:00
|
|
|
implements StateHandler {
|
|
|
|
|
protected final T mRecentsView;
|
2020-03-26 15:28:36 -07:00
|
|
|
protected final BaseQuickstepLauncher mLauncher;
|
2019-01-15 13:19:06 -08:00
|
|
|
|
2020-03-26 15:28:36 -07:00
|
|
|
public BaseRecentsViewStateController(@NonNull BaseQuickstepLauncher launcher) {
|
2019-01-15 13:19:06 -08:00
|
|
|
mLauncher = launcher;
|
|
|
|
|
mRecentsView = launcher.getOverviewPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setState(@NonNull LauncherState state) {
|
2020-04-01 20:13:12 -07:00
|
|
|
float[] scaleAndOffset = state.getOverviewScaleAndOffset(mLauncher);
|
|
|
|
|
SCALE_PROPERTY.set(mRecentsView, scaleAndOffset[0]);
|
|
|
|
|
ADJACENT_PAGE_OFFSET.set(mRecentsView, scaleAndOffset[1]);
|
2020-03-26 15:28:36 -07:00
|
|
|
|
2019-01-15 13:19:06 -08:00
|
|
|
getContentAlphaProperty().set(mRecentsView, state.overviewUi ? 1f : 0);
|
2019-07-24 17:32:08 -07:00
|
|
|
OverviewScrim scrim = mLauncher.getDragLayer().getOverviewScrim();
|
|
|
|
|
SCRIM_PROGRESS.set(scrim, state.getOverviewScrimAlpha(mLauncher));
|
2019-01-15 13:19:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-03-13 13:01:33 -07:00
|
|
|
public void setStateWithAnimation(LauncherState toState, StateAnimationConfig config,
|
|
|
|
|
PendingAnimation builder) {
|
2020-03-06 15:56:46 -08:00
|
|
|
if (!config.hasAnimationFlag(PLAY_ATOMIC_OVERVIEW_PEEK | PLAY_ATOMIC_OVERVIEW_SCALE)) {
|
2019-01-15 13:19:06 -08:00
|
|
|
// The entire recents animation is played atomically.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-06 15:56:46 -08:00
|
|
|
if (config.hasAnimationFlag(SKIP_OVERVIEW)) {
|
2019-03-19 14:55:22 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2020-03-13 13:01:33 -07:00
|
|
|
setStateWithAnimationInternal(toState, config, builder);
|
2019-01-15 13:19:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Core logic for animating the recents view UI.
|
|
|
|
|
*
|
|
|
|
|
* @param toState state to animate to
|
|
|
|
|
* @param config current animation config
|
2020-03-13 13:01:33 -07:00
|
|
|
* @param setter animator set builder
|
2019-01-15 13:19:06 -08:00
|
|
|
*/
|
|
|
|
|
void setStateWithAnimationInternal(@NonNull final LauncherState toState,
|
2020-03-13 13:01:33 -07:00
|
|
|
@NonNull StateAnimationConfig config, @NonNull PendingAnimation setter) {
|
2020-04-01 20:13:12 -07:00
|
|
|
float[] scaleAndOffset = toState.getOverviewScaleAndOffset(mLauncher);
|
|
|
|
|
setter.setFloat(mRecentsView, SCALE_PROPERTY, scaleAndOffset[0],
|
2020-03-26 15:28:36 -07:00
|
|
|
config.getInterpolator(ANIM_OVERVIEW_SCALE, LINEAR));
|
2020-04-01 20:13:12 -07:00
|
|
|
setter.setFloat(mRecentsView, ADJACENT_PAGE_OFFSET, scaleAndOffset[1],
|
2020-03-26 15:28:36 -07:00
|
|
|
config.getInterpolator(ANIM_OVERVIEW_TRANSLATE_X, LINEAR));
|
|
|
|
|
|
2019-01-15 13:19:06 -08:00
|
|
|
setter.setFloat(mRecentsView, getContentAlphaProperty(), toState.overviewUi ? 1 : 0,
|
2020-03-13 13:01:33 -07:00
|
|
|
config.getInterpolator(ANIM_OVERVIEW_FADE, AGGRESSIVE_EASE_IN_OUT));
|
2019-07-24 17:32:08 -07:00
|
|
|
OverviewScrim scrim = mLauncher.getDragLayer().getOverviewScrim();
|
|
|
|
|
setter.setFloat(scrim, SCRIM_PROGRESS, toState.getOverviewScrimAlpha(mLauncher),
|
2020-03-13 13:01:33 -07:00
|
|
|
config.getInterpolator(ANIM_OVERVIEW_SCRIM_FADE, LINEAR));
|
2019-01-15 13:19:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get property for content alpha for the recents view.
|
|
|
|
|
*
|
|
|
|
|
* @return the float property for the view's content alpha
|
|
|
|
|
*/
|
|
|
|
|
abstract FloatProperty getContentAlphaProperty();
|
|
|
|
|
}
|