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

Commit 67533eea authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge changes I2586b90d,I67111528,I9aeb191a into nyc-dev

* changes:
  Fix config change layout. (Part 2)
  Fixing issue with tasks being laid out with the wrong bounds.
  Launch state/config change audit. (Part 1)
parents 6885598b 619e40cd
Loading
Loading
Loading
Loading
+90 −54
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import com.android.systemui.recents.model.RecentsTaskLoadPlan;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.Task;
import com.android.systemui.recents.model.TaskStack;
import com.android.systemui.recents.views.AnimationProps;
import com.android.systemui.recents.views.RecentsView;
import com.android.systemui.recents.views.SystemBarScrimViews;
import com.android.systemui.statusbar.BaseStatusBar;
@@ -285,6 +286,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        registerReceiver(mSystemBroadcastReceiver, filter);

        getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION);

        // Reload the stack view
        reloadStackView();
    }

    @Override
@@ -297,15 +301,17 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
    }

    @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();
        EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
    }
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

    @Override
    protected void onResume() {
        super.onResume();
        // Reload the stack view
        reloadStackView();
    }

    /**
     * Reloads the stack views upon launching Recents.
     */
    private void reloadStackView() {
        // If the Recents component has preloaded a load plan, then use that to prevent
        // reconstructing the task stack
        RecentsTaskLoader loader = Recents.getTaskLoader();
@@ -328,38 +334,21 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
        loader.loadTasks(this, loadPlan, loadOpts);
        TaskStack stack = loadPlan.getTaskStack();
        mRecentsView.onResume(mIsVisible, false /* multiWindowChange */, stack);
        mRecentsView.onReload(mIsVisible, stack.getTaskCount() == 0);
        mRecentsView.updateStack(stack);

        // Animate the SystemUI scrims into view
        Task launchTarget = stack.getLaunchTarget();
        int taskCount = stack.getTaskCount();
        int launchTaskIndexInStack = launchTarget != null
                ? stack.indexOfStackTask(launchTarget)
                : 0;
        boolean hasNavBarScrim = (taskCount > 0) && !config.hasTransposedNavBar;
        // Update the nav bar scrim, but defer the animation until the enter-window event
        boolean animateNavBarScrim = !launchState.launchedWhileDocking;
        mScrimViews.prepareEnterRecentsAnimation(hasNavBarScrim, animateNavBarScrim);
        updateNavBarScrim(animateNavBarScrim, null);

        // If this is a new instance from a configuration change, then we have to manually trigger
        // the enter animation state, or if recents was relaunched by AM, without going through
        // the normal mechanisms
        // 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
        boolean wasLaunchedByAm = !launchState.launchedFromHome &&
                !launchState.launchedFromApp;
        if (launchState.launchedHasConfigurationChanged || wasLaunchedByAm) {
        if (wasLaunchedByAm) {
            EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
        }

        mRecentsView.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {

                    @Override
                    public boolean onPreDraw() {
                        mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
                        EventBus.getDefault().post(new RecentsDrawnEvent());
                        return true;
                    }
                });

        // Keep track of whether we launched from the nav bar button or via alt-tab
        if (launchState.launchedWithAltTab) {
            MetricsLogger.count(this, "overview_trigger_alttab", 1);
@@ -369,6 +358,10 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD

        // Keep track of whether we launched from an app or from home
        if (launchState.launchedFromApp) {
            Task launchTarget = stack.getLaunchTarget();
            int launchTaskIndexInStack = launchTarget != null
                    ? stack.indexOfStackTask(launchTarget)
                    : 0;
            MetricsLogger.count(this, "overview_source_app", 1);
            // If from an app, track the stack index of the app in the stack (for affiliated tasks)
            MetricsLogger.histogram(this, "overview_source_app_index", launchTaskIndexInStack);
@@ -377,12 +370,36 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        }

        // Keep track of the total stack task count
        int taskCount = mRecentsView.getStack().getTaskCount();
        MetricsLogger.histogram(this, "overview_task_count", taskCount);

        // After we have resumed, set the visible state until the next onStop() call
        mIsVisible = true;
    }

    @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();
        EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Notify of the next draw
        mRecentsView.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {

                    @Override
                    public boolean onPreDraw() {
                        mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
                        EventBus.getDefault().post(new RecentsDrawnEvent());
                        return true;
                    }
                });
    }

    @Override
    protected void onPause() {
        super.onPause();
@@ -395,7 +412,34 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        EventBus.getDefault().send(new ConfigurationChangedEvent());
        // Update the nav bar for the current orientation
        updateNavBarScrim(false /* animateNavBarScrim */, AnimationProps.IMMEDIATE);

        EventBus.getDefault().send(new ConfigurationChangedEvent(false /* fromMultiWindow */));
    }

    @Override
    public void onMultiWindowChanged(boolean inMultiWindow) {
        super.onMultiWindowChanged(inMultiWindow);
        EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */));

        if (mRecentsView != null) {
            // Reload the task stack completely
            RecentsConfiguration config = Recents.getConfiguration();
            RecentsActivityLaunchState launchState = config.getLaunchState();
            RecentsTaskLoader loader = Recents.getTaskLoader();
            RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this);
            loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */);

            RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
            loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
            loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
            loader.loadTasks(this, loadPlan, loadOpts);

            mRecentsView.updateStack(loadPlan.getTaskStack());
        }

        EventBus.getDefault().send(new MultiWindowStateChangedEvent(inMultiWindow));
    }

    @Override
@@ -453,28 +497,6 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        }
    }

    @Override
    public void onMultiWindowChanged(boolean inMultiWindow) {
        super.onMultiWindowChanged(inMultiWindow);
        EventBus.getDefault().send(new ConfigurationChangedEvent());

        // Reload the task stack completely
        RecentsConfiguration config = Recents.getConfiguration();
        RecentsActivityLaunchState launchState = config.getLaunchState();
        RecentsTaskLoader loader = Recents.getTaskLoader();
        RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this);
        loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */);

        RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
        loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
        loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
        loader.loadTasks(this, loadPlan, loadOpts);

        mRecentsView.onResume(mIsVisible, true /* multiWindowChange */, loadPlan.getTaskStack());

        EventBus.getDefault().send(new MultiWindowStateChangedEvent(inMultiWindow));
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
@@ -697,4 +719,18 @@ 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);
        }
    }
}
+0 −7
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ public class RecentsActivityLaunchState {
    public boolean launchedFromApp;
    public boolean launchedFromAppDocked;
    public boolean launchedFromHome;
    public boolean launchedReuseTaskStackViews;
    public boolean launchedHasConfigurationChanged;
    public boolean launchedViaDragGesture;
    public boolean launchedWhileDocking;
    public int launchedToTaskId;
@@ -45,7 +43,6 @@ public class RecentsActivityLaunchState {
        launchedFromAppDocked = false;
        launchedToTaskId = -1;
        launchedWithAltTab = false;
        launchedHasConfigurationChanged = false;
        launchedViaDragGesture = false;
        launchedWhileDocking = false;
    }
@@ -53,10 +50,6 @@ public class RecentsActivityLaunchState {
    /** Called when the configuration has changed, and we want to reset any configuration specific
     * members. */
    public void updateOnConfigurationChange() {
        // Reset this flag on configuration change to ensure that we recreate new task views
        launchedReuseTaskStackViews = false;
        // Set this flag to indicate that the configuration has changed since Recents last launched
        launchedHasConfigurationChanged = true;
        launchedViaDragGesture = false;
        launchedWhileDocking = false;
    }
+0 −12
Original line number Diff line number Diff line
@@ -47,11 +47,6 @@ public class RecentsConfiguration {
    // Launch states
    public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState();

    // TODO: Values determined by the current context, needs to be refactored into something that is
    //       agnostic of the activity context, but still calculable from the Recents component for
    //       the transition into recents
    public boolean hasTransposedNavBar;

    // Since the positions in Recents has to be calculated globally (before the RecentsActivity
    // starts), we need to calculate some resource values ourselves, instead of relying on framework
    // resources.
@@ -78,13 +73,6 @@ public class RecentsConfiguration {
        isXLargeScreen = smallestWidth >= (int) (screenDensity * XLARGE_SCREEN_MIN_DP);
    }

    /**
     * Updates the configuration based on the current state of the system
     */
    void update(Rect systemInsets) {
        hasTransposedNavBar = systemInsets.right > 0;
    }

    /**
     * Returns the activity launch state.
     * TODO: This will be refactored out of RecentsConfiguration.
+3 −13
Original line number Diff line number Diff line
@@ -140,7 +140,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    protected Context mContext;
    protected Handler mHandler;
    TaskStackListenerImpl mTaskStackListener;
    protected boolean mCanReuseTaskStackViews = true;
    boolean mDraggingInRecents;
    boolean mLaunchedWhileDocking;

@@ -209,8 +208,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    public void onConfigurationChanged() {
        reloadHeaderBarLayout();
        updateHeaderBarLayout(null /* stack */);
        // Don't reuse task stack views if the configuration changes
        mCanReuseTaskStackViews = false;
        Recents.getConfiguration().updateOnConfigurationChange();
    }

@@ -592,9 +589,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        calculateWindowStableInsets(systemInsets, windowRect);
        windowRect.offsetTo(0, 0);

        // Update the configuration for the current state
        Recents.getConfiguration().update(systemInsets);

        TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm();
        stackLayout.getTaskStackBounds(windowRect, systemInsets.top, systemInsets.right,
                mTaskStackBounds);
@@ -605,8 +599,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        if (stack != null) {
            stackLayout.initialize(windowRect, taskStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(stack));
            mDummyStackView.setTasks(stack, false /* notifyStackChanges */,
                    false /* relayoutTaskStack */, false /* multiWindowChange */);
            mDummyStackView.setTasks(stack, false /* allowNotifyStackChanges */);
        }
        Rect taskViewBounds = stackLayout.getUntransformedTaskViewBounds();
        if (!taskViewBounds.equals(mLastTaskViewBounds)) {
@@ -715,7 +708,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
            TaskStackViewScroller stackScroller = stackView.getScroller();

            stackView.updateLayoutAlgorithm(true /* boundScroll */);
            stackView.updateToInitialState();
            stackView.updateToInitialState(true /* scrollToInitialState */);

            for (int i = tasks.size() - 1; i >= 0; i--) {
                Task task = tasks.get(i);
@@ -782,7 +775,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

        // Get the transform for the running task
        stackView.updateLayoutAlgorithm(true /* boundScroll */);
        stackView.updateToInitialState();
        stackView.updateToInitialState(true /* scrollToInitialState */);
        mTmpTransform = stackView.getStackAlgorithm().getStackTransformScreenCoordinates(launchTask,
                stackView.getScroller().getStackScroll(), mTmpTransform, null);
        return mTmpTransform;
@@ -862,10 +855,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        launchState.launchedToTaskId = (topTask != null) ? topTask.id : -1;
        launchState.launchedFromAppDocked = mLaunchedWhileDocking;
        launchState.launchedWithAltTab = mTriggeredFromAltTab;
        launchState.launchedReuseTaskStackViews = mCanReuseTaskStackViews;
        launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks;
        launchState.launchedNumVisibleThumbnails = stackVr.numVisibleThumbnails;
        launchState.launchedHasConfigurationChanged = false;
        launchState.launchedViaDragGesture = mDraggingInRecents;
        launchState.launchedWhileDocking = mLaunchedWhileDocking;

@@ -915,7 +906,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        } else {
            mContext.startActivityAsUser(intent, UserHandle.CURRENT);
        }
        mCanReuseTaskStackViews = true;
        EventBus.getDefault().send(new RecentsActivityStartingEvent());
    }

+6 −1
Original line number Diff line number Diff line
@@ -22,5 +22,10 @@ import com.android.systemui.recents.events.EventBus;
 * This is sent when the Recents activity configuration has changed.
 */
public class ConfigurationChangedEvent extends EventBus.AnimatedEvent {
    // Simple event

    public final boolean fromMultiWindow;

    public ConfigurationChangedEvent(boolean fromMultiWindow) {
        this.fromMultiWindow = fromMultiWindow;
    }
}
Loading