Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5eb1045c authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Add taskbar stashing feedforward, i.e. hint at upcoming stash/unstash" into sc-v2-dev

parents 1dad82a1 8a2c1cbc
Loading
Loading
Loading
Loading
+0 −5
Original line number Original line Diff line number Diff line
@@ -233,11 +233,6 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
        }
        }
    }
    }


    @Override
    public boolean onLongPressToUnstashTaskbar() {
        return mControllers.taskbarStashController.onLongPressToUnstashTaskbar();
    }

    /**
    /**
     * @param ev MotionEvent in screen coordinates.
     * @param ev MotionEvent in screen coordinates.
     * @return Whether any Taskbar item could handle the given MotionEvent if given the chance.
     * @return Whether any Taskbar item could handle the given MotionEvent if given the chance.
+20 −0
Original line number Original line Diff line number Diff line
@@ -40,6 +40,8 @@ public class StashedHandleViewController {
    private final int mStashedHandleHeight;
    private final int mStashedHandleHeight;
    private final AnimatedFloat mTaskbarStashedHandleAlpha = new AnimatedFloat(
    private final AnimatedFloat mTaskbarStashedHandleAlpha = new AnimatedFloat(
            this::updateStashedHandleAlpha);
            this::updateStashedHandleAlpha);
    private final AnimatedFloat mTaskbarStashedHandleHintScale = new AnimatedFloat(
            this::updateStashedHandleHintScale);


    // Initialized in init.
    // Initialized in init.
    private TaskbarControllers mControllers;
    private TaskbarControllers mControllers;
@@ -64,6 +66,7 @@ public class StashedHandleViewController {
        mStashedHandleView.getLayoutParams().height = mActivity.getDeviceProfile().taskbarSize;
        mStashedHandleView.getLayoutParams().height = mActivity.getDeviceProfile().taskbarSize;


        updateStashedHandleAlpha();
        updateStashedHandleAlpha();
        mTaskbarStashedHandleHintScale.updateValue(1f);


        final int stashedTaskbarHeight = mControllers.taskbarStashController.getStashedHeight();
        final int stashedTaskbarHeight = mControllers.taskbarStashController.getStashedHeight();
        mStashedHandleView.setOutlineProvider(new ViewOutlineProvider() {
        mStashedHandleView.setOutlineProvider(new ViewOutlineProvider() {
@@ -80,12 +83,24 @@ public class StashedHandleViewController {
                outline.setRoundRect(mStashedHandleBounds, mStashedHandleRadius);
                outline.setRoundRect(mStashedHandleBounds, mStashedHandleRadius);
            }
            }
        });
        });

        mStashedHandleView.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> {
            final int stashedCenterX = view.getWidth() / 2;
            final int stashedCenterY = view.getHeight() - stashedTaskbarHeight / 2;

            view.setPivotX(stashedCenterX);
            view.setPivotY(stashedCenterY);
        });
    }
    }


    public AnimatedFloat getStashedHandleAlpha() {
    public AnimatedFloat getStashedHandleAlpha() {
        return mTaskbarStashedHandleAlpha;
        return mTaskbarStashedHandleAlpha;
    }
    }


    public AnimatedFloat getStashedHandleHintScale() {
        return mTaskbarStashedHandleHintScale;
    }

    /**
    /**
     * Creates and returns a {@link RevealOutlineAnimation} Animator that updates the stashed handle
     * Creates and returns a {@link RevealOutlineAnimation} Animator that updates the stashed handle
     * shape and size. When stashed, the shape is a thin rounded pill. When unstashed, the shape
     * shape and size. When stashed, the shape is a thin rounded pill. When unstashed, the shape
@@ -105,4 +120,9 @@ public class StashedHandleViewController {
    protected void updateStashedHandleAlpha() {
    protected void updateStashedHandleAlpha() {
        mStashedHandleView.setAlpha(mTaskbarStashedHandleAlpha.value);
        mStashedHandleView.setAlpha(mTaskbarStashedHandleAlpha.value);
    }
    }

    protected void updateStashedHandleHintScale() {
        mStashedHandleView.setScaleX(mTaskbarStashedHandleHintScale.value);
        mStashedHandleView.setScaleY(mTaskbarStashedHandleHintScale.value);
    }
}
}
+16 −0
Original line number Original line Diff line number Diff line
@@ -332,4 +332,20 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ


        AbstractFloatingView.closeAllOpenViews(this);
        AbstractFloatingView.closeAllOpenViews(this);
    }
    }

    /**
     * Called when we detect a long press in the nav region before passing the gesture slop.
     * @return Whether taskbar handled the long press, and thus should cancel the gesture.
     */
    public boolean onLongPressToUnstashTaskbar() {
        return mControllers.taskbarStashController.onLongPressToUnstashTaskbar();
    }

    /**
     * Called when we detect a motion down or up/cancel in the nav region while stashed.
     * @param animateForward Whether to animate towards the unstashed hint state or back to stashed.
     */
    public void startTaskbarUnstashHint(boolean animateForward) {
        mControllers.taskbarStashController.startUnstashHint(animateForward);
    }
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.hardware.display.DisplayManager;
import android.view.Display;
import android.view.Display;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile;
@@ -188,4 +189,8 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
        mDisplayController.removeChangeListener(this);
        mDisplayController.removeChangeListener(this);
        mSysUINavigationMode.removeModeChangeListener(this);
        mSysUINavigationMode.removeModeChangeListener(this);
    }
    }

    public @Nullable TaskbarActivityContext getCurrentActivityContext() {
        return mTaskbarActivityContext;
    }
}
}
+54 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.animation.AnimatorSet;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.Resources;
import android.view.ViewConfiguration;


import com.android.launcher3.R;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
@@ -46,6 +47,22 @@ public class TaskbarStashController {
     */
     */
    private static final float STASHED_TASKBAR_SCALE = 0.5f;
    private static final float STASHED_TASKBAR_SCALE = 0.5f;


    /**
     * How long the hint animation plays, starting on motion down.
     */
    private static final long TASKBAR_HINT_STASH_DURATION =
            ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT;

    /**
     * The scale that TaskbarView animates to when hinting towards the stashed state.
     */
    private static final float STASHED_TASKBAR_HINT_SCALE = 0.9f;

    /**
     * The scale that the stashed handle animates to when hinting towards the unstashed state.
     */
    private static final float UNSTASHED_TASKBAR_HANDLE_HINT_SCALE = 1.1f;

    /**
    /**
     * The SharedPreferences key for whether user has manually stashed the taskbar.
     * The SharedPreferences key for whether user has manually stashed the taskbar.
     */
     */
@@ -71,6 +88,7 @@ public class TaskbarStashController {
    private AnimatedFloat mIconTranslationYForStash;
    private AnimatedFloat mIconTranslationYForStash;
    // Stashed handle properties.
    // Stashed handle properties.
    private AnimatedFloat mTaskbarStashedHandleAlpha;
    private AnimatedFloat mTaskbarStashedHandleAlpha;
    private AnimatedFloat mTaskbarStashedHandleHintScale;


    /** Whether the user has manually invoked taskbar stashing, which we persist. */
    /** Whether the user has manually invoked taskbar stashing, which we persist. */
    private boolean mIsStashedInApp;
    private boolean mIsStashedInApp;
@@ -102,6 +120,7 @@ public class TaskbarStashController {
        StashedHandleViewController stashedHandleController =
        StashedHandleViewController stashedHandleController =
                controllers.stashedHandleViewController;
                controllers.stashedHandleViewController;
        mTaskbarStashedHandleAlpha = stashedHandleController.getStashedHandleAlpha();
        mTaskbarStashedHandleAlpha = stashedHandleController.getStashedHandleAlpha();
        mTaskbarStashedHandleHintScale = stashedHandleController.getStashedHandleHintScale();


        mIsStashedInApp = supportsStashing()
        mIsStashedInApp = supportsStashing()
                && mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
                && mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
@@ -246,6 +265,9 @@ public class TaskbarStashController {
        if (stashedHandleRevealAnim != null) {
        if (stashedHandleRevealAnim != null) {
            fullLengthAnimatorSet.play(stashedHandleRevealAnim);
            fullLengthAnimatorSet.play(stashedHandleRevealAnim);
        }
        }
        // Return the stashed handle to its default scale in case it was changed as part of the
        // feedforward hint. Note that the reveal animation above also visually scales it.
        fullLengthAnimatorSet.play(mTaskbarStashedHandleHintScale.animateToValue(1f));


        fullLengthAnimatorSet.setDuration(duration);
        fullLengthAnimatorSet.setDuration(duration);
        firstHalfAnimatorSet.setDuration((long) (duration * firstHalfDurationScale));
        firstHalfAnimatorSet.setDuration((long) (duration * firstHalfDurationScale));
@@ -271,4 +293,36 @@ public class TaskbarStashController {
        });
        });
        return mAnimator;
        return mAnimator;
    }
    }

    /**
     * Creates and starts a partial stash animation, hinting at the new state that will trigger when
     * long press is detected.
     * @param animateForward Whether we are going towards the new stashed state or returning to the
     *                       unstashed state.
     */
    public void startStashHint(boolean animateForward) {
        if (isStashed() || !supportsStashing()) {
            // Already stashed, no need to hint in that direction.
            return;
        }
        mIconScaleForStash.animateToValue(
                animateForward ? STASHED_TASKBAR_HINT_SCALE : 1)
                .setDuration(TASKBAR_HINT_STASH_DURATION).start();
    }

    /**
     * Creates and starts a partial unstash animation, hinting at the new state that will trigger
     * when long press is detected.
     * @param animateForward Whether we are going towards the new unstashed state or returning to
     *                       the stashed state.
     */
    public void startUnstashHint(boolean animateForward) {
        if (!isStashed()) {
            // Already unstashed, no need to hint in that direction.
            return;
        }
        mTaskbarStashedHandleHintScale.animateToValue(
                animateForward ? UNSTASHED_TASKBAR_HANDLE_HINT_SCALE : 1)
                .setDuration(TASKBAR_HINT_STASH_DURATION).start();
    }
}
}
Loading