summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2015-04-28 10:44:50 -0700
committerAlan Viverette <alanv@google.com>2015-04-28 10:45:26 -0700
commita54cd38ba552a924c481c01cf9eae31b7bb63e86 (patch)
tree38d2bb3832d56b3f5d53d4e267461995d83cc237 /graphics
parente658285baf86a223ad369851d1fc5ebacad7b408 (diff)
downloadframeworks_base-a54cd38ba552a924c481c01cf9eae31b7bb63e86.zip
frameworks_base-a54cd38ba552a924c481c01cf9eae31b7bb63e86.tar.gz
frameworks_base-a54cd38ba552a924c481c01cf9eae31b7bb63e86.tar.bz2
Layout layers without intrinsic dimensions using FILL gravity
Addresses a regression in Calendar where a custom drawable that doesn't implement intrinsic bounds is laid out incorrectly. Also fixes an issue where ColorDrawable would be laid out incorrectly. Bug: 20643614 Change-Id: I796f0d3e189e482cf6fa169a5dd13f654d72653c
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/LayerDrawable.java17
1 files changed, 15 insertions, 2 deletions
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index 3bbbc71..c3d8cfa 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -1464,7 +1464,8 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
bounds.right - insetR - padR, bounds.bottom - r.mInsetB - padB);
// Apply resolved gravity to drawable based on resolved size.
- final int gravity = resolveGravity(r.mGravity, r.mWidth, r.mHeight);
+ final int gravity = resolveGravity(r.mGravity, r.mWidth, r.mHeight,
+ d.getIntrinsicWidth(), d.getIntrinsicHeight());
final int w = r.mWidth < 0 ? d.getIntrinsicWidth() : r.mWidth;
final int h = r.mHeight < 0 ? d.getIntrinsicHeight() : r.mHeight;
Gravity.apply(gravity, w, h, container, outRect, layoutDirection);
@@ -1491,7 +1492,8 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
* @param height height of the layer if set, -1 otherwise
* @return the default gravity for the layer
*/
- private static int resolveGravity(int gravity, int width, int height) {
+ private static int resolveGravity(int gravity, int width, int height,
+ int intrinsicWidth, int intrinsicHeight) {
if (!Gravity.isHorizontal(gravity)) {
if (width < 0) {
gravity |= Gravity.FILL_HORIZONTAL;
@@ -1508,6 +1510,17 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
}
}
+ // If a dimension if not specified, either implicitly or explicitly,
+ // force FILL for that dimension's gravity. This ensures that colors
+ // are handled correctly and ensures backward compatibility.
+ if (width < 0 && intrinsicWidth < 0) {
+ gravity |= Gravity.FILL_HORIZONTAL;
+ }
+
+ if (height < 0 && intrinsicHeight < 0) {
+ gravity |= Gravity.FILL_VERTICAL;
+ }
+
return gravity;
}