Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Avoid creating futures for drawables with no constant state
Browse files Browse the repository at this point in the history
We don't need to create futures for drawables without constant state,
since we only copy on mutate and we don't need to do any work on mutate()
for drawables without shared constant state. Also we would crash in that
case, so avoiding the NPE is nice too.

Rider: Also fixes elevations again.

BUG: 18696100
Change-Id: I4d7737f39ce3efc5830704e5ce412c540603e6ac
  • Loading branch information
alanv committed Dec 10, 2014
1 parent c780187 commit 62b780e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions core/res/res/values/dimens_material.xml
Expand Up @@ -56,6 +56,7 @@
<dimen name="action_bar_overflow_padding_start_material">6dp</dimen>
<!-- Padding to add to the end of the overflow action button. -->
<dimen name="action_bar_overflow_padding_end_material">10dp</dimen>
<dimen name="action_bar_elevation_material">4dp</dimen>

<dimen name="action_button_min_width_overflow_material">36dp</dimen>
<dimen name="action_button_min_width_material">48dp</dimen>
Expand Down Expand Up @@ -87,9 +88,9 @@
<dimen name="floating_window_margin_bottom">32dp</dimen>

<!-- Elevation when button is pressed -->
<dimen name="button_elevation_material">4dp</dimen>
<dimen name="button_elevation_material">2dp</dimen>
<!-- Z translation to apply when button is pressed -->
<dimen name="button_pressed_z_material">2dp</dimen>
<dimen name="button_pressed_z_material">4dp</dimen>
<!-- Default insets (outer padding) around buttons -->
<dimen name="button_inset_vertical_material">6dp</dimen>
<dimen name="button_inset_horizontal_material">@dimen/control_inset_material</dimen>
Expand Down
2 changes: 1 addition & 1 deletion core/res/res/values/styles_material.xml
Expand Up @@ -917,7 +917,7 @@ please see styles_device_defaults.xml.
<item name="gravity">center_vertical</item>
<item name="contentInsetStart">@dimen/action_bar_content_inset_material</item>
<item name="contentInsetEnd">@dimen/action_bar_content_inset_material</item>
<item name="elevation">8dp</item>
<item name="elevation">@dimen/action_bar_elevation_material</item>
<item name="popupTheme">?attr/actionBarPopupTheme</item>
</style>

Expand Down
Expand Up @@ -714,10 +714,17 @@ public abstract static class DrawableContainerState extends ConstantState {
mDrawableFutures = new SparseArray<ConstantStateFuture>(mNumChildren);
}

// Create futures for drawables with constant states. If a
// drawable doesn't have a constant state, then we can't clone
// it and we'll have to reference the original.
final int N = mNumChildren;
for (int i = 0; i < N; i++) {
if (origDr[i] != null) {
mDrawableFutures.put(i, new ConstantStateFuture(origDr[i]));
if (origDr[i].getConstantState() != null) {
mDrawableFutures.put(i, new ConstantStateFuture(origDr[i]));
} else {
mDrawables[i] = origDr[i];
}
}
}
} else {
Expand Down

0 comments on commit 62b780e

Please sign in to comment.