2015-04-20 18:26:57 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 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;
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
|
|
|
|
|
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
2020-03-06 15:35:55 -08:00
|
|
|
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
|
|
|
|
|
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
|
|
|
|
|
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
|
2020-04-23 19:00:36 -07:00
|
|
|
import static com.android.launcher3.LauncherState.FLAG_HAS_SYS_UI_SCRIM;
|
|
|
|
|
import static com.android.launcher3.LauncherState.FLAG_WORKSPACE_HAS_BACKGROUNDS;
|
2018-03-21 08:16:33 -07:00
|
|
|
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
|
2018-05-16 12:23:12 -07:00
|
|
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.ZOOM_OUT;
|
2018-03-14 17:51:49 -07:00
|
|
|
import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
|
2018-05-08 11:10:44 -07:00
|
|
|
import static com.android.launcher3.graphics.WorkspaceAndHotseatScrim.SCRIM_PROGRESS;
|
|
|
|
|
import static com.android.launcher3.graphics.WorkspaceAndHotseatScrim.SYSUI_PROGRESS;
|
2020-03-13 13:01:33 -07:00
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_SCALE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_TRANSLATE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_SCALE;
|
|
|
|
|
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_TRANSLATE;
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2015-04-20 18:26:57 -07:00
|
|
|
import android.view.View;
|
2018-04-19 11:39:34 -07:00
|
|
|
import android.view.animation.Interpolator;
|
2015-05-04 15:50:25 -07:00
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
import com.android.launcher3.LauncherState.PageAlphaProvider;
|
2019-03-19 13:30:25 -05:00
|
|
|
import com.android.launcher3.LauncherState.ScaleAndTranslation;
|
2019-11-04 16:23:51 -08:00
|
|
|
import com.android.launcher3.allapps.AllAppsContainerView;
|
2020-03-13 13:01:33 -07:00
|
|
|
import com.android.launcher3.anim.PendingAnimation;
|
2018-03-14 17:51:49 -07:00
|
|
|
import com.android.launcher3.anim.PropertySetter;
|
2018-05-08 11:10:44 -07:00
|
|
|
import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
|
2020-03-13 13:01:33 -07:00
|
|
|
import com.android.launcher3.states.StateAnimationConfig;
|
2015-04-20 18:26:57 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Manages the animations between each of the workspace states.
|
|
|
|
|
*/
|
|
|
|
|
public class WorkspaceStateTransitionAnimation {
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
private final Workspace mWorkspace;
|
2015-04-20 18:26:57 -07:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
private float mNewScale;
|
2015-04-20 18:26:57 -07:00
|
|
|
|
|
|
|
|
public WorkspaceStateTransitionAnimation(Launcher launcher, Workspace workspace) {
|
|
|
|
|
mLauncher = launcher;
|
|
|
|
|
mWorkspace = workspace;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 17:17:16 -07:00
|
|
|
public void setState(LauncherState toState) {
|
2020-03-13 13:01:33 -07:00
|
|
|
setWorkspaceProperty(toState, NO_ANIM_PROPERTY_SETTER, new StateAnimationConfig());
|
2015-07-08 15:44:27 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-13 13:01:33 -07:00
|
|
|
/**
|
2020-05-08 13:37:58 -07:00
|
|
|
* @see com.android.launcher3.statemanager.StateManager.StateHandler#setStateWithAnimation
|
2020-03-13 13:01:33 -07:00
|
|
|
*/
|
|
|
|
|
public void setStateWithAnimation(
|
|
|
|
|
LauncherState toState, StateAnimationConfig config, PendingAnimation animation) {
|
|
|
|
|
setWorkspaceProperty(toState, animation, config);
|
2015-04-20 18:26:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getFinalScale() {
|
|
|
|
|
return mNewScale;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 17:18:17 -07:00
|
|
|
/**
|
|
|
|
|
* Starts a transition animation for the workspace.
|
|
|
|
|
*/
|
2018-04-19 11:39:34 -07:00
|
|
|
private void setWorkspaceProperty(LauncherState state, PropertySetter propertySetter,
|
2020-03-13 13:01:33 -07:00
|
|
|
StateAnimationConfig config) {
|
2019-03-19 13:30:25 -05:00
|
|
|
ScaleAndTranslation scaleAndTranslation = state.getWorkspaceScaleAndTranslation(mLauncher);
|
|
|
|
|
ScaleAndTranslation hotseatScaleAndTranslation = state.getHotseatScaleAndTranslation(
|
|
|
|
|
mLauncher);
|
2019-11-04 16:23:51 -08:00
|
|
|
ScaleAndTranslation qsbScaleAndTranslation = state.getQsbScaleAndTranslation(mLauncher);
|
2019-03-19 13:30:25 -05:00
|
|
|
mNewScale = scaleAndTranslation.scale;
|
2017-12-06 10:25:07 -08:00
|
|
|
PageAlphaProvider pageAlphaProvider = state.getWorkspacePageAlphaProvider(mLauncher);
|
2017-10-16 11:46:41 -07:00
|
|
|
final int childCount = mWorkspace.getChildCount();
|
2015-04-20 18:26:57 -07:00
|
|
|
for (int i = 0; i < childCount; i++) {
|
2017-12-06 10:25:07 -08:00
|
|
|
applyChildState(state, (CellLayout) mWorkspace.getChildAt(i), i, pageAlphaProvider,
|
2020-03-13 13:01:33 -07:00
|
|
|
propertySetter, config);
|
2017-10-16 11:46:41 -07:00
|
|
|
}
|
2015-04-20 18:26:57 -07:00
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
int elements = state.getVisibleElements(mLauncher);
|
2020-03-13 13:01:33 -07:00
|
|
|
Interpolator fadeInterpolator = config.getInterpolator(ANIM_WORKSPACE_FADE,
|
2018-05-16 12:23:12 -07:00
|
|
|
pageAlphaProvider.interpolator);
|
2019-03-20 12:38:35 -05:00
|
|
|
boolean playAtomicComponent = config.playAtomicOverviewScaleComponent();
|
2019-03-03 15:32:12 -08:00
|
|
|
Hotseat hotseat = mWorkspace.getHotseat();
|
2019-11-04 16:23:51 -08:00
|
|
|
// Since we set the pivot relative to mWorkspace, we need to scale a sibling of Workspace.
|
|
|
|
|
AllAppsContainerView qsbScaleView = mLauncher.getAppsView();
|
|
|
|
|
View qsbView = qsbScaleView.getSearchView();
|
2018-04-19 11:39:34 -07:00
|
|
|
if (playAtomicComponent) {
|
2020-03-13 13:01:33 -07:00
|
|
|
Interpolator scaleInterpolator = config.getInterpolator(ANIM_WORKSPACE_SCALE, ZOOM_OUT);
|
2018-05-16 12:23:12 -07:00
|
|
|
propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, scaleInterpolator);
|
2019-03-03 15:32:12 -08:00
|
|
|
|
2020-04-03 17:10:11 -07:00
|
|
|
setPivotToScaleWithWorkspace(hotseat);
|
|
|
|
|
setPivotToScaleWithWorkspace(qsbScaleView);
|
2019-03-19 13:30:25 -05:00
|
|
|
float hotseatScale = hotseatScaleAndTranslation.scale;
|
2020-03-13 13:01:33 -07:00
|
|
|
Interpolator hotseatScaleInterpolator = config.getInterpolator(ANIM_HOTSEAT_SCALE,
|
2019-06-18 16:34:37 -07:00
|
|
|
scaleInterpolator);
|
|
|
|
|
propertySetter.setFloat(hotseat, SCALE_PROPERTY, hotseatScale,
|
|
|
|
|
hotseatScaleInterpolator);
|
2019-11-04 16:23:51 -08:00
|
|
|
propertySetter.setFloat(qsbScaleView, SCALE_PROPERTY, qsbScaleAndTranslation.scale,
|
|
|
|
|
hotseatScaleInterpolator);
|
2019-03-03 15:32:12 -08:00
|
|
|
|
2018-04-19 11:39:34 -07:00
|
|
|
float hotseatIconsAlpha = (elements & HOTSEAT_ICONS) != 0 ? 1 : 0;
|
2019-03-03 15:32:12 -08:00
|
|
|
propertySetter.setViewAlpha(hotseat, hotseatIconsAlpha, fadeInterpolator);
|
2018-04-19 11:39:34 -07:00
|
|
|
propertySetter.setViewAlpha(mLauncher.getWorkspace().getPageIndicator(),
|
2018-05-16 12:23:12 -07:00
|
|
|
hotseatIconsAlpha, fadeInterpolator);
|
2018-04-19 11:39:34 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 15:56:46 -08:00
|
|
|
if (config.onlyPlayAtomicComponent()) {
|
2018-04-19 11:39:34 -07:00
|
|
|
// Only the alpha and scale, handled above, are included in the atomic animation.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-25 10:23:39 -05:00
|
|
|
Interpolator translationInterpolator = !playAtomicComponent
|
|
|
|
|
? LINEAR
|
2020-03-13 13:01:33 -07:00
|
|
|
: config.getInterpolator(ANIM_WORKSPACE_TRANSLATE, ZOOM_OUT);
|
2020-03-06 15:35:55 -08:00
|
|
|
propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_X,
|
2019-03-19 13:30:25 -05:00
|
|
|
scaleAndTranslation.translationX, translationInterpolator);
|
2020-03-06 15:35:55 -08:00
|
|
|
propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_Y,
|
2019-03-19 13:30:25 -05:00
|
|
|
scaleAndTranslation.translationY, translationInterpolator);
|
2019-03-04 14:57:07 -08:00
|
|
|
|
2020-03-13 13:01:33 -07:00
|
|
|
Interpolator hotseatTranslationInterpolator = config.getInterpolator(
|
2019-06-18 16:34:37 -07:00
|
|
|
ANIM_HOTSEAT_TRANSLATE, translationInterpolator);
|
2020-03-06 15:35:55 -08:00
|
|
|
propertySetter.setFloat(hotseat, VIEW_TRANSLATE_Y,
|
2019-06-18 16:34:37 -07:00
|
|
|
hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
|
2020-03-06 15:35:55 -08:00
|
|
|
propertySetter.setFloat(mWorkspace.getPageIndicator(), VIEW_TRANSLATE_Y,
|
2019-06-18 16:34:37 -07:00
|
|
|
hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
|
2020-03-06 15:35:55 -08:00
|
|
|
propertySetter.setFloat(qsbView, VIEW_TRANSLATE_Y,
|
2019-11-04 16:23:51 -08:00
|
|
|
qsbScaleAndTranslation.translationY, hotseatTranslationInterpolator);
|
2017-12-05 14:24:37 -08:00
|
|
|
|
2019-06-04 19:25:03 -07:00
|
|
|
setScrim(propertySetter, state);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-04 16:23:51 -08:00
|
|
|
/**
|
|
|
|
|
* Set the given view's pivot point to match the workspace's, so that it scales together. Since
|
|
|
|
|
* both this view and workspace can move, transform the point manually instead of using
|
|
|
|
|
* dragLayer.getDescendantCoordRelativeToSelf and related methods.
|
|
|
|
|
*/
|
|
|
|
|
private void setPivotToScaleWithWorkspace(View sibling) {
|
|
|
|
|
sibling.setPivotY(mWorkspace.getPivotY() + mWorkspace.getTop()
|
|
|
|
|
- sibling.getTop() - sibling.getTranslationY());
|
|
|
|
|
sibling.setPivotX(mWorkspace.getPivotX() + mWorkspace.getLeft()
|
|
|
|
|
- sibling.getLeft() - sibling.getTranslationX());
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 19:25:03 -07:00
|
|
|
public void setScrim(PropertySetter propertySetter, LauncherState state) {
|
2018-05-08 11:10:44 -07:00
|
|
|
WorkspaceAndHotseatScrim scrim = mLauncher.getDragLayer().getScrim();
|
|
|
|
|
propertySetter.setFloat(scrim, SCRIM_PROGRESS, state.getWorkspaceScrimAlpha(mLauncher),
|
2018-05-16 12:23:12 -07:00
|
|
|
LINEAR);
|
2020-04-23 19:00:36 -07:00
|
|
|
propertySetter.setFloat(scrim, SYSUI_PROGRESS,
|
|
|
|
|
state.hasFlag(FLAG_HAS_SYS_UI_SCRIM) ? 1 : 0, LINEAR);
|
2017-10-16 11:46:41 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 10:32:40 -07:00
|
|
|
public void applyChildState(LauncherState state, CellLayout cl, int childIndex) {
|
2017-12-06 10:25:07 -08:00
|
|
|
applyChildState(state, cl, childIndex, state.getWorkspacePageAlphaProvider(mLauncher),
|
2020-03-13 13:01:33 -07:00
|
|
|
NO_ANIM_PROPERTY_SETTER, new StateAnimationConfig());
|
2017-10-24 10:32:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyChildState(LauncherState state, CellLayout cl, int childIndex,
|
2018-04-19 11:39:34 -07:00
|
|
|
PageAlphaProvider pageAlphaProvider, PropertySetter propertySetter,
|
2020-03-13 13:01:33 -07:00
|
|
|
StateAnimationConfig config) {
|
2018-01-04 15:35:22 -08:00
|
|
|
float pageAlpha = pageAlphaProvider.getPageAlpha(childIndex);
|
2020-04-23 19:00:36 -07:00
|
|
|
int drawableAlpha = state.hasFlag(FLAG_WORKSPACE_HAS_BACKGROUNDS)
|
|
|
|
|
? Math.round(pageAlpha * 255) : 0;
|
2018-01-04 15:35:22 -08:00
|
|
|
|
2020-03-06 15:56:46 -08:00
|
|
|
if (!config.onlyPlayAtomicComponent()) {
|
|
|
|
|
// Don't update the scrim during the atomic animation.
|
2018-04-19 11:39:34 -07:00
|
|
|
propertySetter.setInt(cl.getScrimBackground(),
|
2018-05-16 12:23:12 -07:00
|
|
|
DRAWABLE_ALPHA, drawableAlpha, ZOOM_OUT);
|
2018-04-19 11:39:34 -07:00
|
|
|
}
|
2019-03-20 12:38:35 -05:00
|
|
|
if (config.playAtomicOverviewScaleComponent()) {
|
2020-03-13 13:01:33 -07:00
|
|
|
Interpolator fadeInterpolator = config.getInterpolator(ANIM_WORKSPACE_FADE,
|
2018-05-16 12:23:12 -07:00
|
|
|
pageAlphaProvider.interpolator);
|
2020-03-06 15:35:55 -08:00
|
|
|
propertySetter.setFloat(cl.getShortcutsAndWidgets(), VIEW_ALPHA,
|
2018-05-16 12:23:12 -07:00
|
|
|
pageAlpha, fadeInterpolator);
|
2018-04-19 11:39:34 -07:00
|
|
|
}
|
2017-10-24 10:32:40 -07:00
|
|
|
}
|
2015-04-20 18:26:57 -07:00
|
|
|
}
|