Avoid creating futures for drawables with no constant state

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
This commit is contained in:
Alan Viverette
2014-12-10 13:52:28 -08:00
parent c780187745
commit 62b780e85f
3 changed files with 12 additions and 4 deletions

View File

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

View File

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

View File

@@ -714,10 +714,17 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
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 {