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

Commit 670ea71f authored by Winson's avatar Winson
Browse files

Reducing work on configuration change (Part 1)

- Don’t reinflate the header bar and dummy stack view
- Only update the header bar layout params when values change

Change-Id: I47bb699e35b10caea2ab8640be8d3f9a3d445c58
parent f824e58d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.systemui.recents.events.ui.ShowIncompatibleAppOverlayEvent;
import com.android.systemui.recents.events.ui.StackViewScrolledEvent;
import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent;
import com.android.systemui.recents.events.ui.UserInteractionEvent;
import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent;
import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent;
import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent;
@@ -752,6 +753,13 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        mIgnoreAltTabRelease = true;
    }

    public final void onBusEvent(final DragEndEvent event) {
        // Handle the case where we drop onto a dock region
        if (event.dropTarget instanceof TaskStack.DockState) {
            mScrimViews.animateScrimToCurrentNavBarState(false /* hasStackTasks */);
        }
    }

    @Override
    public boolean onPreDraw() {
        mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
+10 −8
Original line number Diff line number Diff line
@@ -175,7 +175,11 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        ssp.registerTaskStackListener(mTaskStackListener);

        // Initialize the static configuration resources
        reloadHeaderBarLayout();
        LayoutInflater inflater = LayoutInflater.from(mContext);
        mDummyStackView = new TaskStackView(mContext);
        mHeaderBar = (TaskViewHeader) inflater.inflate(R.layout.recents_task_view_header,
                null, false);
        reloadResources();

        // When we start, preload the data associated with the previous recent tasks.
        // We can use a new plan since the caches will be the same.
@@ -194,7 +198,9 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    }

    public void onConfigurationChanged() {
        reloadHeaderBarLayout();
        reloadResources();
        mDummyStackView.reloadOnConfigurationChange();
        mHeaderBar.onConfigurationChanged();
    }

    /**
@@ -542,11 +548,10 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    }

    /**
     * Reloads all the layouts for the header bar transition.
     * Reloads all the resources for the current configuration.
     */
    private void reloadHeaderBarLayout() {
    private void reloadResources() {
        Resources res = mContext.getResources();
        LayoutInflater inflater = LayoutInflater.from(mContext);

        mStatusBarHeight = res.getDimensionPixelSize(
                com.android.internal.R.dimen.status_bar_height);
@@ -561,9 +566,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
                R.dimen.recents_task_view_header_height_tablet_land,
                R.dimen.recents_task_view_header_height,
                R.dimen.recents_task_view_header_height_tablet_land);
        mDummyStackView = new TaskStackView(mContext);
        mHeaderBar = (TaskViewHeader) inflater.inflate(R.layout.recents_task_view_header,
                null, false);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class SystemBarScrimViews {
    /**
     * Animates the scrim to match the state of the current nav bar.
     */
    private void animateScrimToCurrentNavBarState(boolean hasStackTasks) {
    public void animateScrimToCurrentNavBarState(boolean hasStackTasks) {
        boolean hasNavBarScrim = isNavBarScrimRequired(hasStackTasks);
        if (mHasNavBarScrim != hasNavBarScrim) {
            AnimationProps animation = hasNavBarScrim
+23 −9
Original line number Diff line number Diff line
@@ -353,9 +353,9 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    public void updateToInitialState(boolean scrollToInitialState) {
        if (scrollToInitialState) {
            mStackScroller.setStackScrollToInitialState();
        }
            mLayoutAlgorithm.updateToInitialState(mStack.getStackTasks());
        }
    }

    /** Updates the list of task views */
    void updateTaskViewsList() {
@@ -1221,8 +1221,10 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        // TaskViews with the stack so that we can lay them out
        if (mAwaitingFirstLayout || mInitialState != INITIAL_STATE_UPDATE_NONE) {
            updateToInitialState(mInitialState != INITIAL_STATE_UPDATE_LAYOUT_ONLY);
            if (!mAwaitingFirstLayout) {
                mInitialState = INITIAL_STATE_UPDATE_NONE;
            }
        }

        // Rebind all the views, including the ignore ones
        bindVisibleTaskViews(mStackScroller.getStackScroll(), mIgnoreTasks,
@@ -1281,6 +1283,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal

        if (mAwaitingFirstLayout || !mEnterAnimationComplete) {
            mAwaitingFirstLayout = false;
            mInitialState = INITIAL_STATE_UPDATE_NONE;
            onFirstLayout();
        }
    }
@@ -1836,9 +1839,17 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            // Calculate the new task stack bounds that matches the window size that Recents will
            // have after the drop
            final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
            Rect systemInsets = new Rect(mStableLayoutAlgorithm.mSystemInsets);
            // When docked, the nav bar insets are consumed and the activity is measured without
            // insets.  However, the window bounds include the insets, so we need to subtract them
            // here to make them identical.
            int height = getMeasuredHeight();
            height -= systemInsets.bottom;
            systemInsets.bottom = 0;
            mStackBounds.set(dockState.getDockedTaskStackBounds(getMeasuredWidth(),
                    getMeasuredHeight(), mDividerSize, mLayoutAlgorithm.mSystemInsets,
                    height, mDividerSize, mLayoutAlgorithm.mSystemInsets,
                    mLayoutAlgorithm, getResources(), mWindowRect));
            mLayoutAlgorithm.setSystemInsets(systemInsets);
            mLayoutAlgorithm.initialize(mWindowRect, mStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack));
            updateLayoutAlgorithm(true /* boundScroll */);
@@ -1849,6 +1860,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            mWindowRect.set(mStableWindowRect);
            mStackBounds.set(mStableStackBounds);
            removeIgnoreTask(event.task);
            mLayoutAlgorithm.setSystemInsets(mStableLayoutAlgorithm.mSystemInsets);
            mLayoutAlgorithm.initialize(mWindowRect, mStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack));
            updateLayoutAlgorithm(true /* boundScroll */);
@@ -1987,8 +1999,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    }

    public final void onBusEvent(ConfigurationChangedEvent event) {
        mStableLayoutAlgorithm.reloadOnConfigurationChange(getContext());
        mLayoutAlgorithm.reloadOnConfigurationChange(getContext());
        reloadOnConfigurationChange();

        // Notify the task views of the configuration change so they can reload their resources
        if (!event.fromMultiWindow) {
@@ -2002,13 +2013,16 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        }

        // Trigger a new layout and update to the initial state if necessary
        if (event.fromMultiWindow) {
            mInitialState = INITIAL_STATE_UPDATE_ALL;
        } else if (event.fromOrientationChange) {
        if (event.fromMultiWindow || event.fromOrientationChange) {
            mInitialState = INITIAL_STATE_UPDATE_LAYOUT_ONLY;
        }
            requestLayout();
        }
    }

    public void reloadOnConfigurationChange() {
        mStableLayoutAlgorithm.reloadOnConfigurationChange(getContext());
        mLayoutAlgorithm.reloadOnConfigurationChange(getContext());
    }

    /**
     * Starts an alpha animation on the freeform workspace background.
+10 −7
Original line number Diff line number Diff line
@@ -280,29 +280,33 @@ public class TaskViewHeader extends FrameLayout
    /**
     * Update the header view when the configuration changes.
     */
    void onConfigurationChanged() {
    public void onConfigurationChanged() {
        // Update the dimensions of everything in the header. We do this because we need to use
        // resources for the display, and not the current configuration.
        Resources res = getResources();
        mHeaderBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(res,
        int headerBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(res,
                R.dimen.recents_task_view_header_height,
                R.dimen.recents_task_view_header_height,
                R.dimen.recents_task_view_header_height,
                R.dimen.recents_task_view_header_height_tablet_land,
                R.dimen.recents_task_view_header_height,
                R.dimen.recents_task_view_header_height_tablet_land);
        mHeaderButtonPadding = TaskStackLayoutAlgorithm.getDimensionForDevice(res,
        int headerButtonPadding = TaskStackLayoutAlgorithm.getDimensionForDevice(res,
                R.dimen.recents_task_view_header_button_padding,
                R.dimen.recents_task_view_header_button_padding,
                R.dimen.recents_task_view_header_button_padding,
                R.dimen.recents_task_view_header_button_padding_tablet_land,
                R.dimen.recents_task_view_header_button_padding,
                R.dimen.recents_task_view_header_button_padding_tablet_land);
        if (headerBarHeight != mHeaderBarHeight || headerButtonPadding != mHeaderButtonPadding) {
            mHeaderBarHeight = headerBarHeight;
            mHeaderButtonPadding = headerButtonPadding;
            updateLayoutParams(mIconView, mTitleView, mMoveTaskButton, mDismissButton);
            if (mAppOverlayView != null) {
                updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView);
            }
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
@@ -434,7 +438,6 @@ public class TaskViewHeader extends FrameLayout

    /** Binds the bar view to the task */
    public void rebindToTask(Task t, boolean touchExplorationEnabled, boolean disabledInSafeMode) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        mTask = t;

        // If an activity icon is defined, then we use that as the primary icon to show in the bar,