Skip to content

Commit dd3ef2c

Browse files
author
Fabrice Di Meglio
committed
Improve RTL APIs
- follow changed / reset pattern Change-Id: I1c5e9b39196029bd78add2ab13b984da124822ca
1 parent f64a6d5 commit dd3ef2c

File tree

5 files changed

+45
-25
lines changed

5 files changed

+45
-25
lines changed

api/current.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23344,10 +23344,12 @@ package android.view {
2334423344
method protected void onLayout(boolean, int, int, int, int);
2334523345
method protected void onMeasure(int, int);
2334623346
method protected void onOverScrolled(int, int, boolean, boolean);
23347+
method public void onPaddingChanged(int);
2334723348
method public void onPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
23348-
method public void onResetResolvedTextDirection();
23349-
method public void onResolvePadding(int);
23350-
method public void onResolveTextDirection();
23349+
method public void onResolvedLayoutDirectionChanged();
23350+
method public void onResolvedLayoutDirectionReset();
23351+
method public void onResolvedTextDirectionChanged();
23352+
method public void onResolvedTextDirectionReset();
2335123353
method protected void onRestoreInstanceState(android.os.Parcelable);
2335223354
method protected android.os.Parcelable onSaveInstanceState();
2335323355
method protected void onScrollChanged(int, int, int, int);

core/java/android/view/View.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9598,10 +9598,19 @@ private void resolveLayoutDirectionIfNeeded() {
95989598

95999599
// Set to resolved
96009600
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED;
9601+
onResolvedLayoutDirectionChanged();
96019602
}
96029603

96039604
/**
9604-
* Force padding depending on layout direction.
9605+
* Called when layout direction has been resolved.
9606+
*
9607+
* The default implementation does nothing.
9608+
*/
9609+
public void onResolvedLayoutDirectionChanged() {
9610+
}
9611+
9612+
/**
9613+
* Resolve padding depending on layout direction.
96059614
*/
96069615
public void resolvePadding() {
96079616
// If the user specified the absolute padding (either with android:padding or
@@ -9645,7 +9654,7 @@ public void resolvePadding() {
96459654
mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom;
96469655

96479656
recomputePadding();
9648-
onResolvePadding(resolvedLayoutDirection);
9657+
onPaddingChanged(resolvedLayoutDirection);
96499658
}
96509659

96519660
/**
@@ -9656,7 +9665,7 @@ public void resolvePadding() {
96569665
* @param layoutDirection the direction of the layout
96579666
*
96589667
*/
9659-
public void onResolvePadding(int layoutDirection) {
9668+
public void onPaddingChanged(int layoutDirection) {
96609669
}
96619670

96629671
/**
@@ -9674,19 +9683,28 @@ public boolean canResolveLayoutDirection() {
96749683
}
96759684

96769685
/**
9677-
* Reset the resolved layout direction.
9678-
*
9679-
* Subclasses need to override this method to clear cached information that depends on the
9680-
* resolved layout direction, or to inform child views that inherit their layout direction.
9681-
* Overrides must also call the superclass implementation at the start of their implementation.
9686+
* Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset}
9687+
* when reset is done.
96829688
*/
96839689
public void resetResolvedLayoutDirection() {
96849690
// Reset the current View resolution
96859691
mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED;
9692+
onResolvedLayoutDirectionReset();
96869693
// Reset also the text direction
96879694
resetResolvedTextDirection();
96889695
}
96899696

9697+
/**
9698+
* Called during reset of resolved layout direction.
9699+
*
9700+
* Subclasses need to override this method to clear cached information that depends on the
9701+
* resolved layout direction, or to inform child views that inherit their layout direction.
9702+
*
9703+
* The default implementation does nothing.
9704+
*/
9705+
public void onResolvedLayoutDirectionReset() {
9706+
}
9707+
96909708
/**
96919709
* Check if a Locale uses an RTL script.
96929710
*
@@ -14137,8 +14155,8 @@ public int getResolvedTextDirection() {
1413714155
}
1413814156

1413914157
/**
14140-
* Resolve the text direction. Will call {@link View#onResolveTextDirection()} when resolution
14141-
* is done.
14158+
* Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when
14159+
* resolution is done.
1414214160
*/
1414314161
public void resolveTextDirection() {
1414414162
if (mResolvedTextDirection != TEXT_DIRECTION_INHERIT) {
@@ -14152,32 +14170,34 @@ public void resolveTextDirection() {
1415214170
} else {
1415314171
mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG;
1415414172
}
14155-
onResolveTextDirection();
14173+
onResolvedTextDirectionChanged();
1415614174
}
1415714175

1415814176
/**
1415914177
* Called when text direction has been resolved. Subclasses that care about text direction
14160-
* resolution should override this method. The default implementation does nothing.
14178+
* resolution should override this method.
14179+
*
14180+
* The default implementation does nothing.
1416114181
*/
14162-
public void onResolveTextDirection() {
14182+
public void onResolvedTextDirectionChanged() {
1416314183
}
1416414184

1416514185
/**
1416614186
* Reset resolved text direction. Text direction can be resolved with a call to
14167-
* getResolvedTextDirection(). Will call {@link View#onResetResolvedTextDirection()} when
14187+
* getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when
1416814188
* reset is done.
1416914189
*/
1417014190
public void resetResolvedTextDirection() {
1417114191
mResolvedTextDirection = TEXT_DIRECTION_INHERIT;
14172-
onResetResolvedTextDirection();
14192+
onResolvedTextDirectionReset();
1417314193
}
1417414194

1417514195
/**
1417614196
* Called when text direction is reset. Subclasses that care about text direction reset should
1417714197
* override this method and do a reset of the text direction of their children. The default
1417814198
* implementation does nothing.
1417914199
*/
14180-
public void onResetResolvedTextDirection() {
14200+
public void onResolvedTextDirectionReset() {
1418114201
}
1418214202

1418314203
//

core/java/android/view/ViewGroup.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,9 +4920,7 @@ public void requestTransitionStart(LayoutTransition transition) {
49204920
}
49214921

49224922
@Override
4923-
public void resetResolvedLayoutDirection() {
4924-
super.resetResolvedLayoutDirection();
4925-
4923+
public void onResolvedLayoutDirectionReset() {
49264924
// Take care of resetting the children resolution too
49274925
final int count = getChildCount();
49284926
for (int i = 0; i < count; i++) {
@@ -4934,7 +4932,7 @@ public void resetResolvedLayoutDirection() {
49344932
}
49354933

49364934
@Override
4937-
public void onResetResolvedTextDirection() {
4935+
public void onResolvedTextDirectionReset() {
49384936
// Take care of resetting the children resolution too
49394937
final int count = getChildCount();
49404938
for (int i = 0; i < count; i++) {

core/java/android/widget/CheckedTextView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void setCheckMarkDrawable(Drawable d) {
143143
}
144144

145145
@Override
146-
public void onResolvePadding(int layoutDirection) {
146+
public void onPaddingChanged(int layoutDirection) {
147147
int newPadding = (mCheckMarkDrawable != null) ?
148148
mCheckMarkWidth + mBasePadding : mBasePadding;
149149
mNeedRequestlayout |= (mPaddingRight != newPadding);

core/java/android/widget/TextView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8715,7 +8715,7 @@ boolean isInBatchEditMode() {
87158715
}
87168716

87178717
@Override
8718-
public void onResolveTextDirection() {
8718+
public void onResolvedTextDirectionChanged() {
87198719
if (hasPasswordTransformationMethod()) {
87208720
// TODO: take care of the content direction to show the password text and dots justified
87218721
// to the left or to the right

0 commit comments

Comments
 (0)