Merge "Add workspace page translations for edit state." into tm-dev

This commit is contained in:
Pat Manning
2022-03-23 11:35:20 +00:00
committed by Android (Google) Code Review
3 changed files with 66 additions and 1 deletions
@@ -16,6 +16,7 @@
package com.android.launcher3; package com.android.launcher3;
import static com.android.launcher3.anim.Interpolators.ACCEL_2; import static com.android.launcher3.anim.Interpolators.ACCEL_2;
import static com.android.launcher3.anim.Interpolators.DEACCEL_2;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL; import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL;
@@ -91,6 +92,14 @@ public abstract class LauncherState implements BaseState<LauncherState> {
} }
}; };
protected static final PageTranslationProvider DEFAULT_PAGE_TRANSLATION_PROVIDER =
new PageTranslationProvider(DEACCEL_2) {
@Override
public float getPageTranslation(int pageIndex) {
return 0;
}
};
private static final LauncherState[] sAllStates = new LauncherState[10]; private static final LauncherState[] sAllStates = new LauncherState[10];
/** /**
@@ -288,6 +297,25 @@ public abstract class LauncherState implements BaseState<LauncherState> {
}; };
} }
/**
* Gets the translation provider for workspace pages.
*/
public PageTranslationProvider getWorkspacePageTranslationProvider(Launcher launcher) {
if (this != SPRING_LOADED || !launcher.getDeviceProfile().isTwoPanels) {
return DEFAULT_PAGE_TRANSLATION_PROVIDER;
}
final float quarterPageSpacing = launcher.getWorkspace().getPageSpacing() / 4f;
return new PageTranslationProvider(DEACCEL_2) {
@Override
public float getPageTranslation(int pageIndex) {
boolean isRtl = launcher.getWorkspace().mIsRtl;
boolean isFirstPage = pageIndex % 2 == 0;
return ((isFirstPage && !isRtl) || (!isFirstPage && isRtl)) ? -quarterPageSpacing
: quarterPageSpacing;
}
};
}
@Override @Override
public LauncherState getHistoryForState(LauncherState previousState) { public LauncherState getHistoryForState(LauncherState previousState) {
// No history is supported // No history is supported
@@ -318,6 +346,23 @@ public abstract class LauncherState implements BaseState<LauncherState> {
public abstract float getPageAlpha(int pageIndex); public abstract float getPageAlpha(int pageIndex);
} }
/**
* Provider for the translation and animation interpolation of workspace pages.
*/
public abstract static class PageTranslationProvider {
public final Interpolator interpolator;
public PageTranslationProvider(Interpolator interpolator) {
this.interpolator = interpolator;
}
/**
* Gets the translation of the workspace page at the provided page index.
*/
public abstract float getPageTranslation(int pageIndex);
}
public static class ScaleAndTranslation { public static class ScaleAndTranslation {
public float scale; public float scale;
public float translationX; public float translationX;
@@ -39,6 +39,7 @@ import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_SCA
import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_TRANSLATE; import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_TRANSLATE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_SCRIM_FADE; import static com.android.launcher3.states.StateAnimationConfig.ANIM_SCRIM_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE; import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_PAGE_TRANSLATE_X;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_SCALE; import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_SCALE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_TRANSLATE; import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_TRANSLATE;
import static com.android.launcher3.states.StateAnimationConfig.SKIP_SCRIM; import static com.android.launcher3.states.StateAnimationConfig.SKIP_SCRIM;
@@ -49,6 +50,7 @@ import android.view.View;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import com.android.launcher3.LauncherState.PageAlphaProvider; import com.android.launcher3.LauncherState.PageAlphaProvider;
import com.android.launcher3.LauncherState.PageTranslationProvider;
import com.android.launcher3.LauncherState.ScaleAndTranslation; import com.android.launcher3.LauncherState.ScaleAndTranslation;
import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.anim.PropertySetter;
@@ -155,6 +157,12 @@ public class WorkspaceStateTransitionAnimation {
scaleAndTranslation.translationX, translationInterpolator); scaleAndTranslation.translationX, translationInterpolator);
propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_Y, propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_Y,
scaleAndTranslation.translationY, translationInterpolator); scaleAndTranslation.translationY, translationInterpolator);
PageTranslationProvider pageTranslationProvider = state.getWorkspacePageTranslationProvider(
mLauncher);
for (int i = 0; i < childCount; i++) {
applyPageTranslation((CellLayout) mWorkspace.getChildAt(i), i, pageTranslationProvider,
propertySetter, config);
}
Interpolator hotseatTranslationInterpolator = config.getInterpolator( Interpolator hotseatTranslationInterpolator = config.getInterpolator(
ANIM_HOTSEAT_TRANSLATE, translationInterpolator); ANIM_HOTSEAT_TRANSLATE, translationInterpolator);
@@ -202,6 +210,16 @@ public class WorkspaceStateTransitionAnimation {
pageAlpha, fadeInterpolator); pageAlpha, fadeInterpolator);
} }
private void applyPageTranslation(CellLayout cellLayout, int childIndex,
PageTranslationProvider pageTranslationProvider, PropertySetter propertySetter,
StateAnimationConfig config) {
float pageTranslation = pageTranslationProvider.getPageTranslation(childIndex);
Interpolator translationInterpolator = config.getInterpolator(
ANIM_WORKSPACE_PAGE_TRANSLATE_X, pageTranslationProvider.interpolator);
propertySetter.setFloat(cellLayout, VIEW_TRANSLATE_X, pageTranslation,
translationInterpolator);
}
/** /**
* Returns a spring based animator for the scale property of {@param workspace}. * Returns a spring based animator for the scale property of {@param workspace}.
*/ */
@@ -62,6 +62,7 @@ public class StateAnimationConfig {
ANIM_OVERVIEW_MODAL, ANIM_OVERVIEW_MODAL,
ANIM_DEPTH, ANIM_DEPTH,
ANIM_OVERVIEW_ACTIONS_FADE, ANIM_OVERVIEW_ACTIONS_FADE,
ANIM_WORKSPACE_PAGE_TRANSLATE_X,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface AnimType {} public @interface AnimType {}
@@ -80,8 +81,9 @@ public class StateAnimationConfig {
public static final int ANIM_OVERVIEW_MODAL = 12; public static final int ANIM_OVERVIEW_MODAL = 12;
public static final int ANIM_DEPTH = 13; public static final int ANIM_DEPTH = 13;
public static final int ANIM_OVERVIEW_ACTIONS_FADE = 14; public static final int ANIM_OVERVIEW_ACTIONS_FADE = 14;
public static final int ANIM_WORKSPACE_PAGE_TRANSLATE_X = 15;
private static final int ANIM_TYPES_COUNT = 15; private static final int ANIM_TYPES_COUNT = 16;
protected final Interpolator[] mInterpolators = new Interpolator[ANIM_TYPES_COUNT]; protected final Interpolator[] mInterpolators = new Interpolator[ANIM_TYPES_COUNT];