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

Commit 1c846140 authored by Winson's avatar Winson
Browse files

Fix issue with stack not invalidating when only focus state changes.

- Adding callback to invalidate when focus state changes.
- Fixing issue where we were posting the invalidate, causing everything
  to lag by 1 frame
- Fixing issue where we weren’t passing the cancel-enter animation flag
  down when setting focused tasks

Change-Id: I218ec78dc0e4e22e59ffcef03a1bc91d08b7c18b
parent 31f97bc4
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -110,6 +110,10 @@ public class TaskStackLayoutAlgorithm {
    public static final float STATE_FOCUSED = 1f;
    public static final float STATE_FOCUSED = 1f;
    public static final float STATE_UNFOCUSED = 0f;
    public static final float STATE_UNFOCUSED = 0f;


    public interface TaskStackLayoutAlgorithmCallbacks {
        void onFocusStateChanged(float prevFocusState, float curFocusState);
    }

    /**
    /**
     * The various stack/freeform states.
     * The various stack/freeform states.
     */
     */
@@ -210,6 +214,7 @@ public class TaskStackLayoutAlgorithm {
    Context mContext;
    Context mContext;
    private Interpolator mLinearOutSlowInInterpolator;
    private Interpolator mLinearOutSlowInInterpolator;
    private StackState mState = StackState.SPLIT;
    private StackState mState = StackState.SPLIT;
    private TaskStackLayoutAlgorithmCallbacks mCb;


    // The task bounds (untransformed) for layout.  This rect is anchored at mTaskRoot.
    // The task bounds (untransformed) for layout.  This rect is anchored at mTaskRoot.
    public Rect mTaskRect = new Rect();
    public Rect mTaskRect = new Rect();
@@ -279,8 +284,10 @@ public class TaskStackLayoutAlgorithm {
    TaskViewTransform mBackOfStackTransform = new TaskViewTransform();
    TaskViewTransform mBackOfStackTransform = new TaskViewTransform();
    TaskViewTransform mFrontOfStackTransform = new TaskViewTransform();
    TaskViewTransform mFrontOfStackTransform = new TaskViewTransform();


    public TaskStackLayoutAlgorithm(Context context) {
    public TaskStackLayoutAlgorithm(Context context, TaskStackLayoutAlgorithmCallbacks cb) {
        Resources res = context.getResources();
        Resources res = context.getResources();
        mContext = context;
        mCb = cb;


        mFocusedRange = new Range(res.getFloat(R.integer.recents_layout_focused_range_min),
        mFocusedRange = new Range(res.getFloat(R.integer.recents_layout_focused_range_min),
                res.getFloat(R.integer.recents_layout_focused_range_max));
                res.getFloat(R.integer.recents_layout_focused_range_max));
@@ -291,7 +298,6 @@ public class TaskStackLayoutAlgorithm {


        mMinTranslationZ = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min);
        mMinTranslationZ = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min);
        mMaxTranslationZ = res.getDimensionPixelSize(R.dimen.recents_task_view_z_max);
        mMaxTranslationZ = res.getDimensionPixelSize(R.dimen.recents_task_view_z_max);
        mContext = context;
        mFreeformLayoutAlgorithm = new FreeformWorkspaceLayoutAlgorithm(context);
        mFreeformLayoutAlgorithm = new FreeformWorkspaceLayoutAlgorithm(context);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                com.android.internal.R.interpolator.linear_out_slow_in);
                com.android.internal.R.interpolator.linear_out_slow_in);
@@ -315,8 +321,12 @@ public class TaskStackLayoutAlgorithm {
     * Sets the focused state.
     * Sets the focused state.
     */
     */
    public void setFocusState(float focusState) {
    public void setFocusState(float focusState) {
        float prevFocusState = mFocusState;
        mFocusState = focusState;
        mFocusState = focusState;
        updateFrontBackTransforms();
        updateFrontBackTransforms();
        if (mCb != null) {
            mCb.onFocusStateChanged(prevFocusState, focusState);
        }
    }
    }


    /**
    /**
+20 −10
Original line number Original line Diff line number Diff line
@@ -88,6 +88,7 @@ import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
/* The visual representation of a task stack view */
/* The visual representation of a task stack view */
public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCallbacks,
public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCallbacks,
        TaskView.TaskViewCallbacks, TaskStackViewScroller.TaskStackViewScrollerCallbacks,
        TaskView.TaskViewCallbacks, TaskStackViewScroller.TaskStackViewScrollerCallbacks,
        TaskStackLayoutAlgorithm.TaskStackLayoutAlgorithmCallbacks,
        ViewPool.ViewPoolConsumer<TaskView, Task> {
        ViewPool.ViewPoolConsumer<TaskView, Task> {


    private final static String KEY_SAVED_STATE_SUPER = "saved_instance_state_super";
    private final static String KEY_SAVED_STATE_SUPER = "saved_instance_state_super";
@@ -192,9 +193,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        setStack(stack);
        setStack(stack);
        mViewPool = new ViewPool<>(context, this);
        mViewPool = new ViewPool<>(context, this);
        mInflater = LayoutInflater.from(context);
        mInflater = LayoutInflater.from(context);
        mLayoutAlgorithm = new TaskStackLayoutAlgorithm(context);
        mLayoutAlgorithm = new TaskStackLayoutAlgorithm(context, this);
        mStackScroller = new TaskStackViewScroller(context, mLayoutAlgorithm);
        mStackScroller = new TaskStackViewScroller(context, this, mLayoutAlgorithm);
        mStackScroller.setCallbacks(this);
        mTouchHandler = new TaskStackViewTouchHandler(context, this, mStackScroller);
        mTouchHandler = new TaskStackViewTouchHandler(context, this, mStackScroller);
        mAnimationHelper = new TaskStackAnimationHelper(context, this);
        mAnimationHelper = new TaskStackAnimationHelper(context, this);
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
@@ -623,7 +623,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
     */
     */
    void relayoutTaskViewsOnNextFrame(TaskViewAnimation animation) {
    void relayoutTaskViewsOnNextFrame(TaskViewAnimation animation) {
        mDeferredTaskViewLayoutAnimation = animation;
        mDeferredTaskViewLayoutAnimation = animation;
        postInvalidateOnAnimation();
        invalidate();
    }
    }


    /**
    /**
@@ -852,17 +852,17 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            };
            };


            if (scrollToTask) {
            if (scrollToTask) {
                // Cancel any running enter animations at this point when we scroll or change focus
                if (!mEnterAnimationComplete) {
                    cancelAllTaskViewAnimations();
                }

                // TODO: Center the newly focused task view, only if not freeform
                // TODO: Center the newly focused task view, only if not freeform
                float newScroll = mLayoutAlgorithm.getStackScrollForTask(newFocusedTask);
                float newScroll = mLayoutAlgorithm.getStackScrollForTask(newFocusedTask);
                if (Float.compare(newScroll, mStackScroller.getStackScroll()) != 0) {
                if (Float.compare(newScroll, mStackScroller.getStackScroll()) != 0) {
                    mStackScroller.animateScroll(mStackScroller.getStackScroll(), newScroll,
                    mStackScroller.animateScroll(mStackScroller.getStackScroll(), newScroll,
                            focusTaskRunnable);
                            focusTaskRunnable);
                    willScroll = true;
                    willScroll = true;

                    // Cancel any running enter animations at this point when we scroll as well
                    if (!mEnterAnimationComplete) {
                        cancelAllTaskViewAnimations();
                    }
                } else {
                } else {
                    focusTaskRunnable.run();
                    focusTaskRunnable.run();
                }
                }
@@ -902,7 +902,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
     */
     */
    public void setRelativeFocusedTask(boolean forward, boolean stackTasksOnly, boolean animated,
    public void setRelativeFocusedTask(boolean forward, boolean stackTasksOnly, boolean animated,
                                       boolean cancelWindowAnimations) {
                                       boolean cancelWindowAnimations) {
        setRelativeFocusedTask(forward, stackTasksOnly, animated, false, false);
        setRelativeFocusedTask(forward, stackTasksOnly, animated, cancelWindowAnimations, false);
    }
    }


    /**
    /**
@@ -1448,6 +1448,16 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        }
        }
    }
    }


    /**** TaskStackLayoutAlgorithm.TaskStackLayoutAlgorithmCallbacks ****/

    @Override
    public void onFocusStateChanged(float prevFocusState, float curFocusState) {
        if (mDeferredTaskViewLayoutAnimation == null) {
            mUIDozeTrigger.poke();
            relayoutTaskViewsOnNextFrame(TaskViewAnimation.IMMEDIATE);
        }
    }

    /**** TaskStackViewScroller.TaskStackViewScrollerCallbacks ****/
    /**** TaskStackViewScroller.TaskStackViewScrollerCallbacks ****/


    @Override
    @Override
+24 −7
Original line number Original line Diff line number Diff line
@@ -20,7 +20,9 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Context;
import android.util.FloatProperty;
import android.util.Log;
import android.util.Log;
import android.util.Property;
import android.view.animation.AnimationUtils;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.Interpolator;
import android.widget.OverScroller;
import android.widget.OverScroller;
@@ -37,6 +39,24 @@ public class TaskStackViewScroller {
        void onScrollChanged(float prevScroll, float curScroll, TaskViewAnimation animation);
        void onScrollChanged(float prevScroll, float curScroll, TaskViewAnimation animation);
    }
    }


    /**
     * A Property wrapper around the <code>stackScroll</code> functionality handled by the
     * {@link #setStackScroll(float)} and
     * {@link #getStackScroll()} methods.
     */
    private static final Property<TaskStackViewScroller, Float> STACK_SCROLL =
            new FloatProperty<TaskStackViewScroller>("stackScroll") {
                @Override
                public void setValue(TaskStackViewScroller object, float value) {
                    object.setStackScroll(value);
                }

                @Override
                public Float get(TaskStackViewScroller object) {
                    return object.getStackScroll();
                }
            };

    Context mContext;
    Context mContext;
    TaskStackLayoutAlgorithm mLayoutAlgorithm;
    TaskStackLayoutAlgorithm mLayoutAlgorithm;
    TaskStackViewScrollerCallbacks mCb;
    TaskStackViewScrollerCallbacks mCb;
@@ -51,8 +71,10 @@ public class TaskStackViewScroller {


    private Interpolator mLinearOutSlowInInterpolator;
    private Interpolator mLinearOutSlowInInterpolator;


    public TaskStackViewScroller(Context context, TaskStackLayoutAlgorithm layoutAlgorithm) {
    public TaskStackViewScroller(Context context, TaskStackViewScrollerCallbacks cb,
            TaskStackLayoutAlgorithm layoutAlgorithm) {
        mContext = context;
        mContext = context;
        mCb = cb;
        mScroller = new OverScroller(context);
        mScroller = new OverScroller(context);
        mLayoutAlgorithm = layoutAlgorithm;
        mLayoutAlgorithm = layoutAlgorithm;
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
@@ -64,11 +86,6 @@ public class TaskStackViewScroller {
        mStackScrollP = 0f;
        mStackScrollP = 0f;
    }
    }


    /** Sets the callbacks */
    void setCallbacks(TaskStackViewScrollerCallbacks cb) {
        mCb = cb;
    }

    /** Gets the current stack scroll */
    /** Gets the current stack scroll */
    public float getStackScroll() {
    public float getStackScroll() {
        return mStackScrollP;
        return mStackScrollP;
@@ -172,7 +189,7 @@ public class TaskStackViewScroller {
        stopBoundScrollAnimation();
        stopBoundScrollAnimation();


        mFinalAnimatedScroll = newScroll;
        mFinalAnimatedScroll = newScroll;
        mScrollAnimator = ObjectAnimator.ofFloat(this, "stackScroll", curScroll, newScroll);
        mScrollAnimator = ObjectAnimator.ofFloat(this, STACK_SCROLL, curScroll, newScroll);
        mScrollAnimator.setDuration(mContext.getResources().getInteger(
        mScrollAnimator.setDuration(mContext.getResources().getInteger(
                R.integer.recents_animate_task_stack_scroll_duration));
                R.integer.recents_animate_task_stack_scroll_duration));
        mScrollAnimator.setInterpolator(mLinearOutSlowInInterpolator);
        mScrollAnimator.setInterpolator(mLinearOutSlowInInterpolator);