diff options
| author | 2012-02-15 20:22:56 -0800 | |
|---|---|---|
| committer | 2012-02-16 16:42:20 -0800 | |
| commit | 6d3d5057b445069e73fd06adbc11fa412e7c48c3 (patch) | |
| tree | ed57e591ab52911b368cf340574109df4d976dc0 | |
| parent | e800892c4b4e05914f0d08a7928113193b39d037 (diff) | |
Improve textDirection APIs
Change-Id: I8bff30f5adb0ab4077145d83ac4a716e04f289ac
| -rw-r--r-- | api/current.txt | 6 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 54 | ||||
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 4 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 6 |
4 files changed, 40 insertions, 30 deletions
diff --git a/api/current.txt b/api/current.txt index 6c7833b40e35..d034b89c9d5c 100644 --- a/api/current.txt +++ b/api/current.txt @@ -23310,7 +23310,9 @@ package android.view { method protected void onMeasure(int, int); method protected void onOverScrolled(int, int, boolean, boolean); method public void onPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent); + method public void onResetResolvedTextDirection(); method public void onResolvePadding(int); + method public void onResolveTextDirection(); method protected void onRestoreInstanceState(android.os.Parcelable); method protected android.os.Parcelable onSaveInstanceState(); method protected void onScrollChanged(int, int, int, int); @@ -23345,11 +23347,11 @@ package android.view { method public void requestLayout(); method public boolean requestRectangleOnScreen(android.graphics.Rect); method public boolean requestRectangleOnScreen(android.graphics.Rect, boolean); - method protected void resetResolvedTextDirection(); + method public void resetResolvedTextDirection(); method public void resolvePadding(); method public static int resolveSize(int, int); method public static int resolveSizeAndState(int, int, int); - method protected void resolveTextDirection(); + method public void resolveTextDirection(); method public void restoreHierarchyState(android.util.SparseArray<android.os.Parcelable>); method public void saveHierarchyState(android.util.SparseArray<android.os.Parcelable>); method public void scheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable, long); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 642663ee7911..dac451eab226 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -9540,10 +9540,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal // Clear any previous layout direction resolution mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; - // Reset also TextDirection as a change into LayoutDirection may impact the selected - // TextDirectionHeuristic - resetResolvedTextDirection(); - // Set resolved depending on layout direction switch (getLayoutDirection()) { case LAYOUT_DIRECTION_INHERIT: @@ -9664,8 +9660,10 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * @hide */ protected void resetResolvedLayoutDirection() { - // Reset the current View resolution + // Reset the layout direction resolution mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED; + // Reset also the text direction + resetResolvedTextDirection(); } /** @@ -9710,7 +9708,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal mCurrentAnimation = null; resetResolvedLayoutDirection(); - resetResolvedTextDirection(); } /** @@ -14085,7 +14082,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, * {@link #TEXT_DIRECTION_LOCALE}, - * */ public int getTextDirection() { return mTextDirection; @@ -14102,7 +14098,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, * {@link #TEXT_DIRECTION_LOCALE}, - * */ public void setTextDirection(int textDirection) { if (textDirection != mTextDirection) { @@ -14122,7 +14117,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, * {@link #TEXT_DIRECTION_LOCALE}, - * */ public int getResolvedTextDirection() { if (mResolvedTextDirection == TEXT_DIRECTION_INHERIT) { @@ -14132,27 +14126,47 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal } /** - * Resolve the text direction. - * + * Resolve the text direction. Will call {@link View#onResolveTextDirection()} when resolution + * is done. */ - protected void resolveTextDirection() { - if (mTextDirection != TEXT_DIRECTION_INHERIT) { - mResolvedTextDirection = mTextDirection; + public void resolveTextDirection() { + if (mResolvedTextDirection != TEXT_DIRECTION_INHERIT) { + // Resolution has already been done. return; } - if (mParent != null && mParent instanceof ViewGroup) { + if (mTextDirection != TEXT_DIRECTION_INHERIT) { + mResolvedTextDirection = mTextDirection; + } else if (mParent != null && mParent instanceof ViewGroup) { mResolvedTextDirection = ((ViewGroup) mParent).getResolvedTextDirection(); - return; + } else { + mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG; } - mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG; + onResolveTextDirection(); } /** - * Reset resolved text direction. Will be resolved during a call to getResolvedTextDirection(). - * + * Called when text direction has been resolved. Subclasses that care about text direction + * resolution should override this method. The default implementation does nothing. */ - protected void resetResolvedTextDirection() { + public void onResolveTextDirection() { + } + + /** + * Reset resolved text direction. Text direction can be resolved with a call to + * getResolvedTextDirection(). Will call {@link View#onResetResolvedTextDirection()} when + * reset is done. + */ + public void resetResolvedTextDirection() { mResolvedTextDirection = TEXT_DIRECTION_INHERIT; + onResetResolvedTextDirection(); + } + + /** + * Called when text direction is reset. Subclasses that care about text direction reset should + * override this method and do a reset of the text direction of their children. The default + * implementation does nothing. + */ + public void onResetResolvedTextDirection() { } // diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index e6a833494284..4860f5fa23b5 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -4857,9 +4857,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } @Override - protected void resetResolvedTextDirection() { - super.resetResolvedTextDirection(); - + public void onResetResolvedTextDirection() { // Take care of resetting the children resolution too final int count = getChildCount(); for (int i = 0; i < count; i++) { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 13798ef1da38..688b37f3b241 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -11407,7 +11407,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } @Override - protected void resolveTextDirection() { + public void onResolveTextDirection() { if (hasPasswordTransformationMethod()) { mTextDir = TextDirectionHeuristics.LOCALE; return; @@ -11416,9 +11416,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // Always need to resolve layout direction first final boolean defaultIsRtl = (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); - // Then resolve text direction on the parent - super.resolveTextDirection(); - // Now, we can select the heuristic int textDir = getResolvedTextDirection(); switch (textDir) { @@ -11447,7 +11444,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * drawables depending on the layout direction. * * A call to the super method will be required from the subclasses implementation. - * */ protected void resolveDrawables() { // No need to resolve twice |