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
This commit is contained in:
Winson
2016-04-12 17:02:26 -07:00
parent f824e58d49
commit 670ea71f1b
5 changed files with 52 additions and 25 deletions

View File

@@ -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);

View File

@@ -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);
}
/**

View File

@@ -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

View File

@@ -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());
}
/**

View File

@@ -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,