summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2012-05-31 15:21:23 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2012-06-01 11:39:10 -0700
commitc1da65187a4b9de8f72bd617ef937030187c0a92 (patch)
tree85af5f439c731625f5f6c442dc50147a23586eb0 /core
parentdb120c4dd21bc53c6f58d0140e3a9a3dc6e79b16 (diff)
downloadframeworks_base-c1da65187a4b9de8f72bd617ef937030187c0a92.zip
frameworks_base-c1da65187a4b9de8f72bd617ef937030187c0a92.tar.gz
frameworks_base-c1da65187a4b9de8f72bd617ef937030187c0a92.tar.bz2
Clean up layout direction APIs for Drawable
- see bug #6427629 Change-Id: I3119db3022bba0ee325b6d0d4471bfebd850ec10
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/View.java43
-rw-r--r--core/java/android/widget/ImageView.java7
-rw-r--r--core/java/android/widget/ProgressBar.java10
-rw-r--r--core/java/android/widget/TextView.java41
4 files changed, 59 insertions, 42 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 706ad59..9f8a21b 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -660,7 +660,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
*
* @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;
@@ -3765,6 +3765,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
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();
}
@@ -13690,12 +13699,29 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
}
/**
- * 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) {
}
/**
@@ -13964,8 +13990,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
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;
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 7593bff..f259597 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -194,12 +194,6 @@ public class ImageView extends View {
}
@Override
- public int getResolvedLayoutDirection(Drawable dr) {
- return (dr == mDrawable) ?
- getResolvedLayoutDirection() : super.getResolvedLayoutDirection(dr);
- }
-
- @Override
public boolean hasOverlappingRendering() {
return (getBackground() != null);
}
@@ -672,6 +666,7 @@ public class ImageView extends View {
d.setState(getDrawableState());
}
d.setLevel(mLevel);
+ d.setLayoutDirection(getLayoutDirection());
mDrawableWidth = d.getIntrinsicWidth();
mDrawableHeight = d.getIntrinsicHeight();
applyColorMod();
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index e26620f..1c6a406 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -478,6 +478,9 @@ public class ProgressBar extends View {
d.setCallback(this);
}
mIndeterminateDrawable = d;
+ if (mIndeterminateDrawable != null) {
+ mIndeterminateDrawable.setLayoutDirection(getLayoutDirection());
+ }
if (mIndeterminate) {
mCurrentDrawable = d;
postInvalidate();
@@ -517,6 +520,7 @@ public class ProgressBar extends View {
if (d != null) {
d.setCallback(this);
+ d.setLayoutDirection(getLayoutDirection());
// Make sure the ProgressBar is always tall enough
int drawableHeight = d.getMinimumHeight();
@@ -976,12 +980,6 @@ public class ProgressBar extends View {
}
@Override
- public int getResolvedLayoutDirection(Drawable who) {
- return (who == mProgressDrawable || who == mIndeterminateDrawable) ?
- getResolvedLayoutDirection() : super.getResolvedLayoutDirection(who);
- }
-
- @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
updateDrawableBounds(w, h);
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 69ece17..230b71d 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -4571,20 +4571,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
@Override
- public int getResolvedLayoutDirection(Drawable who) {
- if (who == null) return View.LAYOUT_DIRECTION_LTR;
- if (mDrawables != null) {
- final Drawables drawables = mDrawables;
- if (who == drawables.mDrawableLeft || who == drawables.mDrawableRight ||
- who == drawables.mDrawableTop || who == drawables.mDrawableBottom ||
- who == drawables.mDrawableStart || who == drawables.mDrawableEnd) {
- return getResolvedLayoutDirection();
- }
- }
- return super.getResolvedLayoutDirection(who);
- }
-
- @Override
public boolean hasOverlappingRendering() {
return (getBackground() != null || mText instanceof Spannable || hasSelection());
}
@@ -8195,13 +8181,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
- /**
- * Subclasses will need to override this method to implement their own way of resolving
- * drawables depending on the layout direction.
- *
- * A call to the super method will be required from the subclasses implementation.
- */
- protected void resolveDrawables() {
+ @Override
+ public void onResolveDrawables(int layoutDirection) {
// No need to resolve twice
if (mResolvedDrawables) {
return;
@@ -8217,7 +8198,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
Drawables dr = mDrawables;
- switch(getResolvedLayoutDirection()) {
+ switch(layoutDirection) {
case LAYOUT_DIRECTION_RTL:
if (dr.mDrawableStart != null) {
dr.mDrawableRight = dr.mDrawableStart;
@@ -8249,9 +8230,25 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
break;
}
+ updateDrawablesLayoutDirection(dr, layoutDirection);
mResolvedDrawables = true;
}
+ private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) {
+ if (dr.mDrawableLeft != null) {
+ dr.mDrawableLeft.setLayoutDirection(layoutDirection);
+ }
+ if (dr.mDrawableRight != null) {
+ dr.mDrawableRight.setLayoutDirection(layoutDirection);
+ }
+ if (dr.mDrawableTop != null) {
+ dr.mDrawableTop.setLayoutDirection(layoutDirection);
+ }
+ if (dr.mDrawableBottom != null) {
+ dr.mDrawableBottom.setLayoutDirection(layoutDirection);
+ }
+ }
+
protected void resetResolvedDrawables() {
mResolvedDrawables = false;
}