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

Commit 500ba75c authored by Winson's avatar Winson
Browse files

Disabling the nav bar scrim when Recents is docked.

Bug: 27869246

Change-Id: I554b299c7e577f40811fc02d6ff4a46313ff1622
parent cf9b8326
Loading
Loading
Loading
Loading
+23 −33
Original line number Diff line number Diff line
@@ -344,7 +344,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD

        // Update the nav bar scrim, but defer the animation until the enter-window event
        boolean animateNavBarScrim = !launchState.launchedViaDockGesture;
        updateNavBarScrim(animateNavBarScrim, null);
        mScrimViews.updateNavBarScrim(animateNavBarScrim, stack.getTaskCount() > 0, null);

        // If this is a new instance relaunched by AM, without going through the normal mechanisms,
        // then we have to manually trigger the enter animation state
@@ -417,23 +417,19 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Update the nav bar for the current orientation
        updateNavBarScrim(false /* animateNavBarScrim */, AnimationProps.IMMEDIATE);

        // Notify of the config change
        int newOrientation = getResources().getConfiguration().orientation;
        int numStackTasks = mRecentsView.getStack().getStackTaskCount();
        EventBus.getDefault().send(new ConfigurationChangedEvent(false /* fromMultiWindow */,
                (mLastOrientation != newOrientation)));
                (mLastOrientation != newOrientation), numStackTasks > 0));
        mLastOrientation = newOrientation;
    }

    @Override
    public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
        super.onMultiWindowModeChanged(isInMultiWindowMode);
        EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */,
                false /* fromOrientationChange */));

        if (mRecentsView != null) {
        // Reload the task stack completely
        RecentsConfiguration config = Recents.getConfiguration();
        RecentsActivityLaunchState launchState = config.getLaunchState();
@@ -446,10 +442,18 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
        loader.loadTasks(this, loadPlan, loadOpts);

            mRecentsView.updateStack(loadPlan.getTaskStack());
        TaskStack stack = loadPlan.getTaskStack();
        int numStackTasks = stack.getStackTaskCount();

        EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */,
                false /* fromOrientationChange */, numStackTasks > 0));

        if (mRecentsView != null) {
            mRecentsView.updateStack(stack);
        }

        EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode));
        EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode,
                numStackTasks > 0));
    }

    @Override
@@ -729,18 +733,4 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        });
        return true;
    }

    /**
     * Updates the nav bar scrim.
     */
    private void updateNavBarScrim(boolean animateNavBarScrim, AnimationProps animation) {
        // Animate the SystemUI scrims into view
        SystemServicesProxy ssp = Recents.getSystemServices();
        int taskCount = mRecentsView.getStack().getTaskCount();
        boolean hasNavBarScrim = (taskCount > 0) && !ssp.hasTransposedNavBar();
        mScrimViews.prepareEnterRecentsAnimation(hasNavBarScrim, animateNavBarScrim);
        if (animateNavBarScrim && animation != null) {
            mScrimViews.animateNavBarScrimVisibility(true, animation);
        }
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -25,9 +25,12 @@ public class ConfigurationChangedEvent extends EventBus.AnimatedEvent {

    public final boolean fromMultiWindow;
    public final boolean fromOrientationChange;
    public final boolean hasStackTasks;

    public ConfigurationChangedEvent(boolean fromMultiWindow, boolean fromOrientationChange) {
    public ConfigurationChangedEvent(boolean fromMultiWindow, boolean fromOrientationChange,
            boolean hasStackTasks) {
        this.fromMultiWindow = fromMultiWindow;
        this.fromOrientationChange = fromOrientationChange;
        this.hasStackTasks = hasStackTasks;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ import com.android.systemui.recents.events.EventBus;
public class MultiWindowStateChangedEvent extends EventBus.Event {

    public final boolean inMultiWindow;
    public final boolean hasStackTasks;

    public MultiWindowStateChangedEvent(boolean inMultiWindow) {
    public MultiWindowStateChangedEvent(boolean inMultiWindow, boolean hasStackTasks) {
        this.inMultiWindow = inMultiWindow;
        this.hasStackTasks = hasStackTasks;
    }
}
+70 −17
Original line number Diff line number Diff line
@@ -16,40 +16,58 @@

package com.android.systemui.recents.views;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsActivity;
import com.android.systemui.recents.events.activity.ConfigurationChangedEvent;
import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent;
import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent;
import com.android.systemui.recents.misc.SystemServicesProxy;

/** Manages the scrims for the various system bars. */
public class SystemBarScrimViews {

    Context mContext;
    private static final int DEFAULT_ANIMATION_DURATION = 150;

    View mNavBarScrimView;
    private Context mContext;

    boolean mHasNavBarScrim;
    boolean mShouldAnimateNavBarScrim;
    private View mNavBarScrimView;

    int mNavBarScrimEnterDuration;
    private boolean mHasNavBarScrim;
    private boolean mShouldAnimateNavBarScrim;

    public SystemBarScrimViews(Activity activity) {
    private int mNavBarScrimEnterDuration;

    public SystemBarScrimViews(RecentsActivity activity) {
        mContext = activity;
        mNavBarScrimView = activity.findViewById(R.id.nav_bar_scrim);
        mNavBarScrimView.forceHasOverlappingRendering(false);
        mNavBarScrimEnterDuration = activity.getResources().getInteger(
                R.integer.recents_nav_bar_scrim_enter_duration);
    }

    /**
     * Updates the nav bar scrim.
     */
    public void updateNavBarScrim(boolean animateNavBarScrim, boolean hasStackTasks,
            AnimationProps animation) {
        prepareEnterRecentsAnimation(isNavBarScrimRequired(hasStackTasks), animateNavBarScrim);
        if (animateNavBarScrim && animation != null) {
            animateNavBarScrimVisibility(true, animation);
        }
    }

    /**
     * Prepares the scrim views for animating when entering Recents. This will be called before
     * the first draw, unless we are updating the scrim on configuration change.
     */
    public void prepareEnterRecentsAnimation(boolean hasNavBarScrim, boolean animateNavBarScrim) {
    private void prepareEnterRecentsAnimation(boolean hasNavBarScrim, boolean animateNavBarScrim) {
        mHasNavBarScrim = hasNavBarScrim;
        mShouldAnimateNavBarScrim = animateNavBarScrim;

@@ -60,7 +78,7 @@ public class SystemBarScrimViews {
    /**
     * Animates the nav bar scrim visibility.
     */
    public void animateNavBarScrimVisibility(boolean visible, AnimationProps animation) {
    private void animateNavBarScrimVisibility(boolean visible, AnimationProps animation) {
        int toY = 0;
        if (visible) {
            mNavBarScrimView.setVisibility(View.VISIBLE);
@@ -79,6 +97,14 @@ public class SystemBarScrimViews {
        }
    }

    /**
     * @return Whether to show the nav bar scrim.
     */
    private boolean isNavBarScrimRequired(boolean hasStackTasks) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        return hasStackTasks && !ssp.hasTransposedNavBar() && !ssp.hasDockedTask();
    }

    /**** EventBus events ****/

    /**
@@ -101,21 +127,48 @@ public class SystemBarScrimViews {
     */
    public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) {
        if (mHasNavBarScrim) {
            AnimationProps animation = new AnimationProps()
                    .setDuration(AnimationProps.BOUNDS,
                            TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION)
                    .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN);
            AnimationProps animation = createBoundsAnimation(
                    TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION);
            animateNavBarScrimVisibility(false, animation);
        }
    }

    public final void onBusEvent(DismissAllTaskViewsEvent event) {
        if (mHasNavBarScrim) {
            AnimationProps animation = new AnimationProps()
                    .setDuration(AnimationProps.BOUNDS,
                            TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION)
                    .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN);
            AnimationProps animation = createBoundsAnimation(
                    TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION);
            animateNavBarScrimVisibility(false, animation);
        }
    }

    public final void onBusEvent(ConfigurationChangedEvent event) {
        animateScrimToCurrentNavBarState(event.hasStackTasks);
    }

    public final void onBusEvent(MultiWindowStateChangedEvent event) {
        animateScrimToCurrentNavBarState(event.hasStackTasks);
    }

    /**
     * Animates the scrim to match the state of the current nav bar.
     */
    private void animateScrimToCurrentNavBarState(boolean hasStackTasks) {
        boolean hasNavBarScrim = isNavBarScrimRequired(hasStackTasks);
        if (mHasNavBarScrim != hasNavBarScrim) {
            AnimationProps animation = hasNavBarScrim
                    ? createBoundsAnimation(DEFAULT_ANIMATION_DURATION)
                    : AnimationProps.IMMEDIATE;
            animateNavBarScrimVisibility(hasNavBarScrim, animation);
        }
        mHasNavBarScrim = hasNavBarScrim;
    }

    /**
     * @return a default animation to aniamte the bounds of the scrim.
     */
    private AnimationProps createBoundsAnimation(int duration) {
        return new AnimationProps()
                .setDuration(AnimationProps.BOUNDS, duration)
                .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -537,11 +537,13 @@ public class TaskStackLayoutAlgorithm {
            } else {
                mInitialScrollP = Utilities.clamp(launchTaskIndex - 1, mMinScrollP, mMaxScrollP);
            }
            mInitialNormX = null;
        } else if (!ssp.hasFreeformWorkspaceSupport() && mNumStackTasks == 1) {
            // If there is one stack task, ignore the min/max/initial scroll positions
            mMinScrollP = 0;
            mMaxScrollP = 0;
            mInitialScrollP = 0;
            mInitialNormX = null;
        } else {
            // Set the max scroll to be the point where the front most task is visible with the
            // stack bottom offset