Improve textDirection APIs
Change-Id: I8bff30f5adb0ab4077145d83ac4a716e04f289ac
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 642663e..dac451e 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -9540,10 +9540,6 @@
// 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 @@
* @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 @@
mCurrentAnimation = null;
resetResolvedLayoutDirection();
- resetResolvedTextDirection();
}
/**
@@ -14085,7 +14082,6 @@
* {@link #TEXT_DIRECTION_LTR},
* {@link #TEXT_DIRECTION_RTL},
* {@link #TEXT_DIRECTION_LOCALE},
- *
*/
public int getTextDirection() {
return mTextDirection;
@@ -14102,7 +14098,6 @@
* {@link #TEXT_DIRECTION_LTR},
* {@link #TEXT_DIRECTION_RTL},
* {@link #TEXT_DIRECTION_LOCALE},
- *
*/
public void setTextDirection(int textDirection) {
if (textDirection != mTextDirection) {
@@ -14122,7 +14117,6 @@
* {@link #TEXT_DIRECTION_LTR},
* {@link #TEXT_DIRECTION_RTL},
* {@link #TEXT_DIRECTION_LOCALE},
- *
*/
public int getResolvedTextDirection() {
if (mResolvedTextDirection == TEXT_DIRECTION_INHERIT) {
@@ -14132,27 +14126,47 @@
}
/**
- * Resolve the text direction.
- *
+ * Resolve the text direction. Will call {@link View#onResolveTextDirection()} when resolution
+ * is done.
*/
- protected void resolveTextDirection() {
+ public void resolveTextDirection() {
+ if (mResolvedTextDirection != TEXT_DIRECTION_INHERIT) {
+ // Resolution has already been done.
+ return;
+ }
if (mTextDirection != TEXT_DIRECTION_INHERIT) {
mResolvedTextDirection = mTextDirection;
- return;
- }
- if (mParent != null && mParent instanceof ViewGroup) {
+ } 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 e6a8334..4860f5f 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -4857,9 +4857,7 @@
}
@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 13798ef..688b37f 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -11407,7 +11407,7 @@
}
@Override
- protected void resolveTextDirection() {
+ public void onResolveTextDirection() {
if (hasPasswordTransformationMethod()) {
mTextDir = TextDirectionHeuristics.LOCALE;
return;
@@ -11416,9 +11416,6 @@
// 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 @@
* 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