diff --git a/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java b/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java index f2c9455f6a..d0c255c855 100644 --- a/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java +++ b/go/quickstep/src/com/android/launcher3/uioverrides/RecentsUiFactory.java @@ -23,9 +23,7 @@ import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY; import android.view.View; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherStateManager; import com.android.launcher3.LauncherStateManager.StateHandler; -import com.android.launcher3.uioverrides.RecentsViewStateController; import com.android.launcher3.util.TouchController; /** @@ -56,7 +54,6 @@ public final class RecentsUiFactory { * @return state handler for recents */ public static StateHandler createRecentsViewStateController(Launcher launcher) { - //TODO Override RecentsViewStateController on low RAM. return new RecentsViewStateController(launcher); } diff --git a/go/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/go/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java new file mode 100644 index 0000000000..f1cb75b9d1 --- /dev/null +++ b/go/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2019 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.uioverrides; + +import static com.android.quickstep.views.IconRecentsView.CONTENT_ALPHA; +import static com.android.quickstep.views.IconRecentsView.TRANSLATION_Y_FACTOR; + +import android.util.FloatProperty; + +import androidx.annotation.NonNull; + +import com.android.launcher3.Launcher; +import com.android.quickstep.views.IconRecentsView; + +/** + * State handler for Go's {@link IconRecentsView}. + */ +public final class RecentsViewStateController extends + BaseRecentsViewStateController { + + public RecentsViewStateController(@NonNull Launcher launcher) { + super(launcher); + } + + @Override + FloatProperty getTranslationYFactorProperty() { + return TRANSLATION_Y_FACTOR; + } + + @Override + FloatProperty getContentAlphaProperty() { + return CONTENT_ALPHA; + } +} diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsViewStateController.java similarity index 53% rename from quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java rename to quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsViewStateController.java index abd2846618..7d7946d987 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsViewStateController.java @@ -15,13 +15,8 @@ */ package com.android.launcher3.uioverrides; -import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY; import static com.android.launcher3.LauncherState.FAST_OVERVIEW; import static com.android.launcher3.LauncherState.OVERVIEW; -import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_OVERVIEW_FADE; -import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_OVERVIEW_SCALE; -import static com.android.launcher3.anim.Interpolators.AGGRESSIVE_EASE_IN_OUT; -import static com.android.launcher3.anim.Interpolators.LINEAR; import static com.android.quickstep.QuickScrubController.QUICK_SCRUB_START_INTERPOLATOR; import static com.android.quickstep.QuickScrubController.QUICK_SCRUB_TRANSLATION_Y_FACTOR; import static com.android.quickstep.views.LauncherRecentsView.TRANSLATION_Y_FACTOR; @@ -30,34 +25,34 @@ import static com.android.quickstep.views.RecentsView.CONTENT_ALPHA; import android.animation.ValueAnimator; import android.annotation.TargetApi; import android.os.Build; +import android.util.FloatProperty; import android.view.animation.Interpolator; +import androidx.annotation.NonNull; + import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherStateManager.AnimationConfig; -import com.android.launcher3.LauncherStateManager.StateHandler; import com.android.launcher3.anim.AnimatorSetBuilder; import com.android.launcher3.anim.Interpolators; -import com.android.launcher3.anim.PropertySetter; import com.android.quickstep.views.LauncherRecentsView; +import com.android.quickstep.views.RecentsView; +/** + * State handler for handling UI changes for {@link LauncherRecentsView}. In addition to managing + * the basic view properties, this class also manages changes in the task visuals. + */ @TargetApi(Build.VERSION_CODES.O) -public class RecentsViewStateController implements StateHandler { - - private final Launcher mLauncher; - private final LauncherRecentsView mRecentsView; +public final class RecentsViewStateController extends + BaseRecentsViewStateController { public RecentsViewStateController(Launcher launcher) { - mLauncher = launcher; - mRecentsView = launcher.getOverviewPanel(); + super(launcher); } @Override - public void setState(LauncherState state) { - mRecentsView.setContentAlpha(state.overviewUi ? 1 : 0); - float[] scaleTranslationYFactor = state.getOverviewScaleAndTranslationYFactor(mLauncher); - SCALE_PROPERTY.set(mRecentsView, scaleTranslationYFactor[0]); - mRecentsView.setTranslationYFactor(scaleTranslationYFactor[1]); + public void setState(@NonNull LauncherState state) { + super.setState(state); if (state.overviewUi) { mRecentsView.updateEmptyMessage(); mRecentsView.resetTaskVisuals(); @@ -65,26 +60,9 @@ public class RecentsViewStateController implements StateHandler { } @Override - public void setStateWithAnimation(final LauncherState toState, - AnimatorSetBuilder builder, AnimationConfig config) { - if (!config.playAtomicComponent()) { - // The entire recents animation is played atomically. - return; - } - PropertySetter setter = config.getPropertySetter(builder); - float[] scaleTranslationYFactor = toState.getOverviewScaleAndTranslationYFactor(mLauncher); - Interpolator scaleAndTransYInterpolator = builder.getInterpolator( - ANIM_OVERVIEW_SCALE, LINEAR); - if (mLauncher.getStateManager().getState() == OVERVIEW && toState == FAST_OVERVIEW) { - scaleAndTransYInterpolator = Interpolators.clampToProgress( - QUICK_SCRUB_START_INTERPOLATOR, 0, QUICK_SCRUB_TRANSLATION_Y_FACTOR); - } - setter.setFloat(mRecentsView, SCALE_PROPERTY, scaleTranslationYFactor[0], - scaleAndTransYInterpolator); - setter.setFloat(mRecentsView, TRANSLATION_Y_FACTOR, scaleTranslationYFactor[1], - scaleAndTransYInterpolator); - setter.setFloat(mRecentsView, CONTENT_ALPHA, toState.overviewUi ? 1 : 0, - builder.getInterpolator(ANIM_OVERVIEW_FADE, AGGRESSIVE_EASE_IN_OUT)); + void setStateWithAnimationInternal(@NonNull final LauncherState toState, + @NonNull AnimatorSetBuilder builder, @NonNull AnimationConfig config) { + super.setStateWithAnimationInternal(toState, builder, config); if (!toState.overviewUi) { builder.addOnFinishRunnable(mRecentsView::resetTaskVisuals); @@ -101,4 +79,24 @@ public class RecentsViewStateController implements StateHandler { mRecentsView.updateEmptyMessage(); } } + + @Override + Interpolator getScaleAndTransYInterpolator(@NonNull LauncherState toState, + @NonNull AnimatorSetBuilder builder) { + if (mLauncher.getStateManager().getState() == OVERVIEW && toState == FAST_OVERVIEW) { + return Interpolators.clampToProgress(QUICK_SCRUB_START_INTERPOLATOR, 0, + QUICK_SCRUB_TRANSLATION_Y_FACTOR); + } + return super.getScaleAndTransYInterpolator(toState, builder); + } + + @Override + FloatProperty getTranslationYFactorProperty() { + return TRANSLATION_Y_FACTOR; + } + + @Override + FloatProperty getContentAlphaProperty() { + return CONTENT_ALPHA; + } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java new file mode 100644 index 0000000000..df9dbe4119 --- /dev/null +++ b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2019 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.uioverrides; + +import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY; +import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_OVERVIEW_FADE; +import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_OVERVIEW_SCALE; +import static com.android.launcher3.anim.Interpolators.AGGRESSIVE_EASE_IN_OUT; +import static com.android.launcher3.anim.Interpolators.LINEAR; + +import android.util.FloatProperty; +import android.view.View; +import android.view.animation.Interpolator; + +import androidx.annotation.NonNull; + +import com.android.launcher3.Launcher; +import com.android.launcher3.LauncherState; +import com.android.launcher3.LauncherStateManager.AnimationConfig; +import com.android.launcher3.LauncherStateManager.StateHandler; +import com.android.launcher3.anim.AnimatorSetBuilder; +import com.android.launcher3.anim.PropertySetter; + +/** + * State handler for recents view. Manages UI changes and animations for recents view based off the + * current {@link LauncherState}. + * + * @param the recents view + */ +public abstract class BaseRecentsViewStateController + implements StateHandler { + protected final T mRecentsView; + protected final Launcher mLauncher; + + public BaseRecentsViewStateController(@NonNull Launcher launcher) { + mLauncher = launcher; + mRecentsView = launcher.getOverviewPanel(); + } + + @Override + public void setState(@NonNull LauncherState state) { + float[] scaleTranslationYFactor = state.getOverviewScaleAndTranslationYFactor(mLauncher); + SCALE_PROPERTY.set(mRecentsView, scaleTranslationYFactor[0]); + getTranslationYFactorProperty().set(mRecentsView, scaleTranslationYFactor[1]); + getContentAlphaProperty().set(mRecentsView, state.overviewUi ? 1f : 0); + } + + @Override + public final void setStateWithAnimation(@NonNull final LauncherState toState, + @NonNull AnimatorSetBuilder builder, @NonNull AnimationConfig config) { + if (!config.playAtomicComponent()) { + // The entire recents animation is played atomically. + return; + } + setStateWithAnimationInternal(toState, builder, config); + } + + /** + * Core logic for animating the recents view UI. + * + * @param toState state to animate to + * @param builder animator set builder + * @param config current animation config + */ + void setStateWithAnimationInternal(@NonNull final LauncherState toState, + @NonNull AnimatorSetBuilder builder, @NonNull AnimationConfig config) { + PropertySetter setter = config.getPropertySetter(builder); + float[] scaleTranslationYFactor = toState.getOverviewScaleAndTranslationYFactor(mLauncher); + Interpolator scaleAndTransYInterpolator = getScaleAndTransYInterpolator(toState, builder); + setter.setFloat(mRecentsView, SCALE_PROPERTY, scaleTranslationYFactor[0], + scaleAndTransYInterpolator); + setter.setFloat(mRecentsView, getTranslationYFactorProperty(), scaleTranslationYFactor[1], + scaleAndTransYInterpolator); + setter.setFloat(mRecentsView, getContentAlphaProperty(), toState.overviewUi ? 1 : 0, + builder.getInterpolator(ANIM_OVERVIEW_FADE, AGGRESSIVE_EASE_IN_OUT)); + } + + /** + * Get the interpolator to use for the scale and translation Y animation for the view. + * + * @param toState state to animate to + * @param builder animator set builder + * @return interpolator for scale and trans Y recents view animation + */ + Interpolator getScaleAndTransYInterpolator(@NonNull final LauncherState toState, + @NonNull AnimatorSetBuilder builder) { + return builder.getInterpolator(ANIM_OVERVIEW_SCALE, LINEAR); + } + + /** + * Get property for translation Y factor for the recents view. + * + * @return the float property for the recents view + */ + abstract FloatProperty getTranslationYFactorProperty(); + + /** + * Get property for content alpha for the recents view. + * + * @return the float property for the view's content alpha + */ + abstract FloatProperty getContentAlphaProperty(); +}