version:1.5
fix:迁移到奥乐云平台 add:
This commit is contained in:
156
src/com/aoleyun/os/WorkspaceStateTransitionAnimation.java
Normal file
156
src/com/aoleyun/os/WorkspaceStateTransitionAnimation.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.aoleyun.os;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.aoleyun.os.anim.AnimatorSetBuilder;
|
||||
import com.aoleyun.os.anim.PropertySetter;
|
||||
import com.aoleyun.os.dragndrop.DragLayer;
|
||||
import com.aoleyun.os.graphics.WorkspaceAndHotseatScrim;
|
||||
import com.aoleyun.os.anim.Interpolators;
|
||||
|
||||
/**
|
||||
* Manages the animations between each of the workspace states.
|
||||
*/
|
||||
public class WorkspaceStateTransitionAnimation {
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final Workspace mWorkspace;
|
||||
|
||||
private float mNewScale;
|
||||
|
||||
public WorkspaceStateTransitionAnimation(Launcher launcher, Workspace workspace) {
|
||||
mLauncher = launcher;
|
||||
mWorkspace = workspace;
|
||||
}
|
||||
|
||||
public void setState(LauncherState toState) {
|
||||
setWorkspaceProperty(toState, PropertySetter.NO_ANIM_PROPERTY_SETTER, new AnimatorSetBuilder(),
|
||||
new LauncherStateManager.AnimationConfig());
|
||||
}
|
||||
|
||||
public void setStateWithAnimation(LauncherState toState, AnimatorSetBuilder builder,
|
||||
LauncherStateManager.AnimationConfig config) {
|
||||
setWorkspaceProperty(toState, config.getPropertySetter(builder), builder, config);
|
||||
}
|
||||
|
||||
public float getFinalScale() {
|
||||
return mNewScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a transition animation for the workspace.
|
||||
*/
|
||||
private void setWorkspaceProperty(LauncherState state, PropertySetter propertySetter,
|
||||
AnimatorSetBuilder builder, LauncherStateManager.AnimationConfig config) {
|
||||
LauncherState.ScaleAndTranslation scaleAndTranslation = state.getWorkspaceScaleAndTranslation(mLauncher);
|
||||
LauncherState.ScaleAndTranslation hotseatScaleAndTranslation = state.getHotseatScaleAndTranslation(
|
||||
mLauncher);
|
||||
mNewScale = scaleAndTranslation.scale;
|
||||
LauncherState.PageAlphaProvider pageAlphaProvider = state.getWorkspacePageAlphaProvider(mLauncher);
|
||||
final int childCount = mWorkspace.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
applyChildState(state, (CellLayout) mWorkspace.getChildAt(i), i, pageAlphaProvider,
|
||||
propertySetter, builder, config);
|
||||
}
|
||||
|
||||
int elements = state.getVisibleElements(mLauncher);
|
||||
Interpolator fadeInterpolator = builder.getInterpolator(AnimatorSetBuilder.ANIM_WORKSPACE_FADE,
|
||||
pageAlphaProvider.interpolator);
|
||||
boolean playAtomicComponent = config.playAtomicOverviewScaleComponent();
|
||||
Hotseat hotseat = mWorkspace.getHotseat();
|
||||
if (playAtomicComponent) {
|
||||
Interpolator scaleInterpolator = builder.getInterpolator(AnimatorSetBuilder.ANIM_WORKSPACE_SCALE, Interpolators.ZOOM_OUT);
|
||||
propertySetter.setFloat(mWorkspace, LauncherAnimUtils.SCALE_PROPERTY, mNewScale, scaleInterpolator);
|
||||
|
||||
if (!hotseat.getRotationMode().isTransposed) {
|
||||
// Set the hotseat's pivot point to match the workspace's, so that it scales together.
|
||||
DragLayer dragLayer = mLauncher.getDragLayer();
|
||||
float[] workspacePivot =
|
||||
new float[]{ mWorkspace.getPivotX(), mWorkspace.getPivotY() };
|
||||
dragLayer.getDescendantCoordRelativeToSelf(mWorkspace, workspacePivot);
|
||||
dragLayer.mapCoordInSelfToDescendant(hotseat, workspacePivot);
|
||||
hotseat.setPivotX(workspacePivot[0]);
|
||||
hotseat.setPivotY(workspacePivot[1]);
|
||||
}
|
||||
float hotseatScale = hotseatScaleAndTranslation.scale;
|
||||
Interpolator hotseatScaleInterpolator = builder.getInterpolator(AnimatorSetBuilder.ANIM_HOTSEAT_SCALE,
|
||||
scaleInterpolator);
|
||||
propertySetter.setFloat(hotseat, LauncherAnimUtils.SCALE_PROPERTY, hotseatScale,
|
||||
hotseatScaleInterpolator);
|
||||
|
||||
float hotseatIconsAlpha = (elements & LauncherState.HOTSEAT_ICONS) != 0 ? 1 : 0;
|
||||
propertySetter.setViewAlpha(hotseat, hotseatIconsAlpha, fadeInterpolator);
|
||||
propertySetter.setViewAlpha(mLauncher.getWorkspace().getPageIndicator(),
|
||||
hotseatIconsAlpha, fadeInterpolator);
|
||||
}
|
||||
|
||||
if (!config.playNonAtomicComponent()) {
|
||||
// Only the alpha and scale, handled above, are included in the atomic animation.
|
||||
return;
|
||||
}
|
||||
|
||||
Interpolator translationInterpolator = !playAtomicComponent
|
||||
? Interpolators.LINEAR
|
||||
: builder.getInterpolator(AnimatorSetBuilder.ANIM_WORKSPACE_TRANSLATE, Interpolators.ZOOM_OUT);
|
||||
propertySetter.setFloat(mWorkspace, View.TRANSLATION_X,
|
||||
scaleAndTranslation.translationX, translationInterpolator);
|
||||
propertySetter.setFloat(mWorkspace, View.TRANSLATION_Y,
|
||||
scaleAndTranslation.translationY, translationInterpolator);
|
||||
|
||||
Interpolator hotseatTranslationInterpolator = builder.getInterpolator(
|
||||
AnimatorSetBuilder.ANIM_HOTSEAT_TRANSLATE, translationInterpolator);
|
||||
propertySetter.setFloat(hotseat, View.TRANSLATION_Y,
|
||||
hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
|
||||
propertySetter.setFloat(mWorkspace.getPageIndicator(), View.TRANSLATION_Y,
|
||||
hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
|
||||
|
||||
setScrim(propertySetter, state);
|
||||
}
|
||||
|
||||
public void setScrim(PropertySetter propertySetter, LauncherState state) {
|
||||
WorkspaceAndHotseatScrim scrim = mLauncher.getDragLayer().getScrim();
|
||||
propertySetter.setFloat(scrim, WorkspaceAndHotseatScrim.SCRIM_PROGRESS, state.getWorkspaceScrimAlpha(mLauncher),
|
||||
Interpolators.LINEAR);
|
||||
propertySetter.setFloat(scrim, WorkspaceAndHotseatScrim.SYSUI_PROGRESS, state.hasSysUiScrim ? 1 : 0, Interpolators.LINEAR);
|
||||
}
|
||||
|
||||
public void applyChildState(LauncherState state, CellLayout cl, int childIndex) {
|
||||
applyChildState(state, cl, childIndex, state.getWorkspacePageAlphaProvider(mLauncher),
|
||||
PropertySetter.NO_ANIM_PROPERTY_SETTER, new AnimatorSetBuilder(), new LauncherStateManager.AnimationConfig());
|
||||
}
|
||||
|
||||
private void applyChildState(LauncherState state, CellLayout cl, int childIndex,
|
||||
LauncherState.PageAlphaProvider pageAlphaProvider, PropertySetter propertySetter,
|
||||
AnimatorSetBuilder builder, LauncherStateManager.AnimationConfig config) {
|
||||
float pageAlpha = pageAlphaProvider.getPageAlpha(childIndex);
|
||||
int drawableAlpha = Math.round(pageAlpha * (state.hasWorkspacePageBackground ? 255 : 0));
|
||||
|
||||
if (config.playNonAtomicComponent()) {
|
||||
propertySetter.setInt(cl.getScrimBackground(),
|
||||
LauncherAnimUtils.DRAWABLE_ALPHA, drawableAlpha, Interpolators.ZOOM_OUT);
|
||||
}
|
||||
if (config.playAtomicOverviewScaleComponent()) {
|
||||
Interpolator fadeInterpolator = builder.getInterpolator(AnimatorSetBuilder.ANIM_WORKSPACE_FADE,
|
||||
pageAlphaProvider.interpolator);
|
||||
propertySetter.setFloat(cl.getShortcutsAndWidgets(), View.ALPHA,
|
||||
pageAlpha, fadeInterpolator);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user