summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alan Viverette <alanv@google.com> 2015-12-16 16:06:23 -0500
committer Alan Viverette <alanv@google.com> 2015-12-16 16:06:23 -0500
commit189d4f5b770eb45ea23e8c529cabc1ccdff6e83a (patch)
treee84371c5c3bbe7dba73d74ad854ab4b14e92b87c
parenteb2094ce24a329dee438870782a8940fbbdba4c4 (diff)
Propagate TextView drawable state after resolving RTL drawables
Bug: 24502082 Change-Id: Iec9c44041622d19401fc074947e15b4843f79d86
-rw-r--r--core/java/android/util/StateSet.java6
-rw-r--r--core/java/android/widget/TextView.java48
2 files changed, 44 insertions, 10 deletions
diff --git a/core/java/android/util/StateSet.java b/core/java/android/util/StateSet.java
index c2a6a7ad4349..051de8a190e1 100644
--- a/core/java/android/util/StateSet.java
+++ b/core/java/android/util/StateSet.java
@@ -260,6 +260,12 @@ public class StateSet {
case R.attr.state_enabled:
sb.append("E ");
break;
+ case R.attr.state_checked:
+ sb.append("C ");
+ break;
+ case R.attr.state_activated:
+ sb.append("A ");
+ break;
}
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 17c803f76cbb..1dc050b145e2 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -393,7 +393,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mOverride = false;
}
- public void resolveWithLayoutDirection(int layoutDirection) {
+ /**
+ * Updates the list of displayed drawables to account for the current
+ * layout direction.
+ *
+ * @param layoutDirection the current layout direction
+ * @return {@code true} if the displayed drawables changed
+ */
+ public boolean resolveWithLayoutDirection(int layoutDirection) {
+ final Drawable previousLeft = mShowing[Drawables.LEFT];
+ final Drawable previousRight = mShowing[Drawables.RIGHT];
+
// First reset "left" and "right" drawables to their initial values
mShowing[Drawables.LEFT] = mDrawableLeftInitial;
mShowing[Drawables.RIGHT] = mDrawableRightInitial;
@@ -441,16 +451,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
break;
}
}
+
applyErrorDrawableIfNeeded(layoutDirection);
- updateDrawablesLayoutDirection(layoutDirection);
- }
- private void updateDrawablesLayoutDirection(int layoutDirection) {
- for (Drawable dr : mShowing) {
- if (dr != null) {
- dr.setLayoutDirection(layoutDirection);
- }
- }
+ return mShowing[Drawables.LEFT] != previousLeft
+ || mShowing[Drawables.RIGHT] != previousRight;
}
public void setErrorDrawable(Drawable dr, TextView tv) {
@@ -9809,7 +9814,30 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Resolve drawables
if (mDrawables != null) {
- mDrawables.resolveWithLayoutDirection(layoutDirection);
+ if (mDrawables.resolveWithLayoutDirection(layoutDirection)) {
+ prepareDrawableForDisplay(mDrawables.mShowing[Drawables.LEFT]);
+ prepareDrawableForDisplay(mDrawables.mShowing[Drawables.RIGHT]);
+ applyCompoundDrawableTint();
+ }
+ }
+ }
+
+ /**
+ * Prepares a drawable for display by propagating layout direction and
+ * drawable state.
+ *
+ * @param dr the drawable to prepare
+ */
+ private void prepareDrawableForDisplay(@Nullable Drawable dr) {
+ if (dr == null) {
+ return;
+ }
+
+ dr.setLayoutDirection(getLayoutDirection());
+
+ if (dr.isStateful()) {
+ dr.setState(getDrawableState());
+ dr.jumpToCurrentState();
}
}