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;
|
2018-03-21 08:16:33 -07:00
|
|
|
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
|
2018-03-26 12:10:31 -07:00
|
|
|
import static com.android.launcher3.LauncherState.HOTSEAT_SEARCH_BOX;
|
2018-05-16 12:23:12 -07:00
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_WORKSPACE_FADE;
|
|
|
|
|
import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_WORKSPACE_SCALE;
|
|
|
|
|
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;
|
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;
|
2017-10-23 17:14:52 -07:00
|
|
|
import com.android.launcher3.LauncherStateManager.AnimationConfig;
|
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;
|
2018-05-08 11:10:44 -07:00
|
|
|
import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
|
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) {
|
2018-05-16 12:23:12 -07:00
|
|
|
setWorkspaceProperty(toState, NO_ANIM_PROPERTY_SETTER, new AnimatorSetBuilder(),
|
|
|
|
|
new AnimationConfig());
|
2015-07-08 15:44:27 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-07 12:45:49 -08:00
|
|
|
public void setStateWithAnimation(LauncherState toState, AnimatorSetBuilder builder,
|
2017-12-07 11:42:33 -08:00
|
|
|
AnimationConfig config) {
|
2018-05-16 12:23:12 -07:00
|
|
|
setWorkspaceProperty(toState, config.getPropertySetter(builder), builder, 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,
|
2018-05-16 12:23:12 -07:00
|
|
|
AnimatorSetBuilder builder, AnimationConfig config) {
|
2017-12-21 12:40:38 -08:00
|
|
|
float[] scaleAndTranslation = state.getWorkspaceScaleAndTranslation(mLauncher);
|
|
|
|
|
mNewScale = scaleAndTranslation[0];
|
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,
|
2018-05-16 12:23:12 -07:00
|
|
|
propertySetter, builder, 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);
|
2018-05-16 12:23:12 -07:00
|
|
|
Interpolator fadeInterpolator = builder.getInterpolator(ANIM_WORKSPACE_FADE,
|
|
|
|
|
pageAlphaProvider.interpolator);
|
2018-04-19 11:39:34 -07:00
|
|
|
boolean playAtomicComponent = config.playAtomicComponent();
|
|
|
|
|
if (playAtomicComponent) {
|
2018-05-16 12:23:12 -07:00
|
|
|
Interpolator scaleInterpolator = builder.getInterpolator(ANIM_WORKSPACE_SCALE, ZOOM_OUT);
|
|
|
|
|
propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, scaleInterpolator);
|
2018-04-19 11:39:34 -07:00
|
|
|
float hotseatIconsAlpha = (elements & HOTSEAT_ICONS) != 0 ? 1 : 0;
|
|
|
|
|
propertySetter.setViewAlpha(mLauncher.getHotseat().getLayout(), hotseatIconsAlpha,
|
2018-05-16 12:23:12 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.playNonAtomicComponent()) {
|
|
|
|
|
// Only the alpha and scale, handled above, are included in the atomic animation.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:23:12 -07:00
|
|
|
Interpolator translationInterpolator = !playAtomicComponent ? LINEAR : ZOOM_OUT;
|
2018-04-19 11:39:34 -07:00
|
|
|
propertySetter.setFloat(mWorkspace, View.TRANSLATION_X,
|
|
|
|
|
scaleAndTranslation[1], translationInterpolator);
|
|
|
|
|
propertySetter.setFloat(mWorkspace, View.TRANSLATION_Y,
|
|
|
|
|
scaleAndTranslation[2], translationInterpolator);
|
2017-12-05 14:24:37 -08:00
|
|
|
|
2018-03-26 12:10:31 -07:00
|
|
|
propertySetter.setViewAlpha(mLauncher.getHotseatSearchBox(),
|
2018-05-16 12:23:12 -07:00
|
|
|
(elements & HOTSEAT_SEARCH_BOX) != 0 ? 1 : 0, fadeInterpolator);
|
2018-03-26 12:10:31 -07:00
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
// Set scrim
|
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);
|
|
|
|
|
propertySetter.setFloat(scrim, SYSUI_PROGRESS, state.hasSysUiScrim ? 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),
|
2018-05-16 12:23:12 -07:00
|
|
|
NO_ANIM_PROPERTY_SETTER, new AnimatorSetBuilder(), new AnimationConfig());
|
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,
|
2018-05-16 12:23:12 -07:00
|
|
|
AnimatorSetBuilder builder, AnimationConfig config) {
|
2018-01-04 15:35:22 -08:00
|
|
|
float pageAlpha = pageAlphaProvider.getPageAlpha(childIndex);
|
2018-02-28 15:09:36 -08:00
|
|
|
int drawableAlpha = Math.round(pageAlpha * (state.hasWorkspacePageBackground ? 255 : 0));
|
2018-01-04 15:35:22 -08:00
|
|
|
|
2018-04-19 11:39:34 -07:00
|
|
|
if (config.playNonAtomicComponent()) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
if (config.playAtomicComponent()) {
|
2018-05-16 12:23:12 -07:00
|
|
|
Interpolator fadeInterpolator = builder.getInterpolator(ANIM_WORKSPACE_FADE,
|
|
|
|
|
pageAlphaProvider.interpolator);
|
2018-04-19 11:39:34 -07: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
|
|
|
}
|