Revert "Revert "Clean up layout direction APIs for Drawable""
This reverts commit c96132ff53e5c26f5b0170edd85072006fb2bc70
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 61b2352..f74f969 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -660,7 +660,7 @@
*
* @see android.view.ViewGroup
*/
-public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback,
+public class View implements Drawable.Callback, KeyEvent.Callback,
AccessibilityEventSource {
private static final boolean DBG = false;
@@ -3838,6 +3838,15 @@
scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true);
}
+ // Apply layout direction to the new Drawables if needed
+ final int layoutDirection = getResolvedLayoutDirection();
+ if (track != null) {
+ track.setLayoutDirection(layoutDirection);
+ }
+ if (thumb != null) {
+ thumb.setLayoutDirection(layoutDirection);
+ }
+
// Re-apply user/background padding so that scrollbar(s) get added
resolvePadding();
}
@@ -13866,12 +13875,29 @@
}
/**
- * Return the layout direction of a given Drawable.
- *
- * @param who the Drawable to query
- */
- public int getResolvedLayoutDirection(Drawable who) {
- return (who == mBackground) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT;
+ * Resolve the Drawables depending on the layout direction. This is implicitly supposing
+ * that the View directionality can and will be resolved before its Drawables.
+ *
+ * Will call {@link View#onResolveDrawables} when resolution is done.
+ */
+ public void resolveDrawables() {
+ if (mBackground != null) {
+ mBackground.setLayoutDirection(getResolvedLayoutDirection());
+ }
+ onResolveDrawables(getResolvedLayoutDirection());
+ }
+
+ /**
+ * Called when layout direction has been resolved.
+ *
+ * The default implementation does nothing.
+ *
+ * @param layoutDirection The resolved layout direction.
+ *
+ * @see {@link #LAYOUT_DIRECTION_LTR}
+ * @see {@link #LAYOUT_DIRECTION_RTL}
+ */
+ public void onResolveDrawables(int layoutDirection) {
}
/**
@@ -14140,8 +14166,9 @@
padding = new Rect();
sThreadLocal.set(padding);
}
+ background.setLayoutDirection(getResolvedLayoutDirection());
if (background.getPadding(padding)) {
- switch (background.getResolvedLayoutDirectionSelf()) {
+ switch (background.getLayoutDirection()) {
case LAYOUT_DIRECTION_RTL:
setPadding(padding.right, padding.top, padding.left, padding.bottom);
break;