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-26 12:10:31 -07:00
|
|
|
import static com.android.launcher3.LauncherState.DRAG_HANDLE_INDICATOR;
|
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-03-14 17:51:49 -07:00
|
|
|
import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2015-04-20 18:26:57 -07:00
|
|
|
import android.view.View;
|
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;
|
2017-10-26 15:36:10 -07:00
|
|
|
import com.android.launcher3.anim.Interpolators;
|
2018-03-14 17:51:49 -07:00
|
|
|
import com.android.launcher3.anim.PropertySetter;
|
2018-02-28 15:09:36 -08:00
|
|
|
import com.android.launcher3.graphics.ViewScrim;
|
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) {
|
2017-10-16 11:46:41 -07:00
|
|
|
setWorkspaceProperty(toState, NO_ANIM_PROPERTY_SETTER);
|
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-04-27 12:33:24 -05:00
|
|
|
setWorkspaceProperty(toState, config.getPropertySetter(builder));
|
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.
|
|
|
|
|
*/
|
2017-10-17 17:17:16 -07:00
|
|
|
private void setWorkspaceProperty(LauncherState state, PropertySetter propertySetter) {
|
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,
|
2017-10-24 10:32:40 -07:00
|
|
|
propertySetter);
|
2017-10-16 11:46:41 -07:00
|
|
|
}
|
2015-04-20 18:26:57 -07:00
|
|
|
|
2018-04-04 10:23:36 -07:00
|
|
|
propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, Interpolators.ZOOM_OUT);
|
2017-12-21 12:40:38 -08:00
|
|
|
propertySetter.setFloat(mWorkspace, View.TRANSLATION_X,
|
2018-04-04 10:23:36 -07:00
|
|
|
scaleAndTranslation[1], Interpolators.ZOOM_OUT);
|
2017-10-16 11:46:41 -07:00
|
|
|
propertySetter.setFloat(mWorkspace, View.TRANSLATION_Y,
|
2018-04-04 10:23:36 -07:00
|
|
|
scaleAndTranslation[2], Interpolators.ZOOM_OUT);
|
2017-10-16 11:46:41 -07:00
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
int elements = state.getVisibleElements(mLauncher);
|
2018-03-21 08:16:33 -07:00
|
|
|
float hotseatIconsAlpha = (elements & HOTSEAT_ICONS) != 0 ? 1 : 0;
|
|
|
|
|
propertySetter.setViewAlpha(mLauncher.getHotseat().getLayout(), hotseatIconsAlpha,
|
2018-01-19 14:26:18 -08:00
|
|
|
pageAlphaProvider.interpolator);
|
2018-03-06 13:11:43 -08:00
|
|
|
propertySetter.setViewAlpha(mLauncher.getWorkspace().getPageIndicator(),
|
2018-03-21 08:16:33 -07:00
|
|
|
hotseatIconsAlpha, pageAlphaProvider.interpolator);
|
2017-12-05 14:24:37 -08:00
|
|
|
|
2018-03-26 12:10:31 -07:00
|
|
|
propertySetter.setViewAlpha(mLauncher.getHotseatSearchBox(),
|
|
|
|
|
(elements & HOTSEAT_SEARCH_BOX) != 0 ? 1 : 0,
|
|
|
|
|
pageAlphaProvider.interpolator);
|
|
|
|
|
|
|
|
|
|
propertySetter.setViewAlpha(mLauncher.getDragHandleIndicator(),
|
|
|
|
|
(elements & DRAG_HANDLE_INDICATOR) != 0 ? 1 : 0,
|
|
|
|
|
pageAlphaProvider.interpolator);
|
|
|
|
|
|
2017-10-16 11:46:41 -07:00
|
|
|
// Set scrim
|
2018-02-28 15:09:36 -08:00
|
|
|
propertySetter.setFloat(ViewScrim.get(mWorkspace), ViewScrim.PROGRESS,
|
2018-05-04 13:19:29 -07:00
|
|
|
state.getWorkspaceScrimAlpha(mLauncher), Interpolators.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),
|
2017-10-24 10:32:40 -07:00
|
|
|
NO_ANIM_PROPERTY_SETTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyChildState(LauncherState state, CellLayout cl, int childIndex,
|
2017-12-06 10:25:07 -08:00
|
|
|
PageAlphaProvider pageAlphaProvider, PropertySetter propertySetter) {
|
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
|
|
|
|
2017-10-24 10:32:40 -07:00
|
|
|
propertySetter.setInt(cl.getScrimBackground(),
|
2018-04-04 10:23:36 -07:00
|
|
|
DRAWABLE_ALPHA, drawableAlpha, Interpolators.ZOOM_OUT);
|
2017-12-06 10:25:07 -08:00
|
|
|
propertySetter.setFloat(cl.getShortcutsAndWidgets(), View.ALPHA,
|
2018-01-04 15:35:22 -08:00
|
|
|
pageAlpha, pageAlphaProvider.interpolator);
|
2017-10-24 10:32:40 -07:00
|
|
|
}
|
2015-04-20 18:26:57 -07:00
|
|
|
}
|