From 670ea71f1b4ae59a0cd6608ae44b0fb78a1144c4 Mon Sep 17 00:00:00 2001 From: Winson Date: Tue, 12 Apr 2016 17:02:26 -0700 Subject: [PATCH] Reducing work on configuration change (Part 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Don’t reinflate the header bar and dummy stack view - Only update the header bar layout params when values change Change-Id: I47bb699e35b10caea2ab8640be8d3f9a3d445c58 --- .../systemui/recents/RecentsActivity.java | 8 +++++ .../android/systemui/recents/RecentsImpl.java | 18 ++++++----- .../recents/views/SystemBarScrimViews.java | 2 +- .../systemui/recents/views/TaskStackView.java | 32 +++++++++++++------ .../recents/views/TaskViewHeader.java | 17 ++++++---- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index 6b476eeb43c05..df7966927a57a 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -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); diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index fda340d48ab3d..6d32293d7aaad 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -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); } /** diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java b/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java index 07a1d4edaeaf5..dce2353187338 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index 0fc45ed8951c0..63018c548640f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -353,8 +353,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal public void updateToInitialState(boolean scrollToInitialState) { if (scrollToInitialState) { mStackScroller.setStackScrollToInitialState(); + mLayoutAlgorithm.updateToInitialState(mStack.getStackTasks()); } - mLayoutAlgorithm.updateToInitialState(mStack.getStackTasks()); } /** Updates the list of task views */ @@ -1221,7 +1221,9 @@ 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); - mInitialState = INITIAL_STATE_UPDATE_NONE; + if (!mAwaitingFirstLayout) { + mInitialState = INITIAL_STATE_UPDATE_NONE; + } } // Rebind all the views, including the ignore ones @@ -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,12 +2013,15 @@ 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(); } - requestLayout(); + } + + public void reloadOnConfigurationChange() { + mStableLayoutAlgorithm.reloadOnConfigurationChange(getContext()); + mLayoutAlgorithm.reloadOnConfigurationChange(getContext()); } /** diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java index 16d8e53401ebc..f98d3d5d23be3 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java @@ -280,27 +280,31 @@ 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); - updateLayoutParams(mIconView, mTitleView, mMoveTaskButton, mDismissButton); - if (mAppOverlayView != null) { - updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView); + if (headerBarHeight != mHeaderBarHeight || headerButtonPadding != mHeaderButtonPadding) { + mHeaderBarHeight = headerBarHeight; + mHeaderButtonPadding = headerButtonPadding; + updateLayoutParams(mIconView, mTitleView, mMoveTaskButton, mDismissButton); + if (mAppOverlayView != null) { + updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView); + } } } @@ -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,