Skip to content

Commit e56ffdc

Browse files
author
Fabrice Di Meglio
committed
Fix bug #6427629 Clean up layout direction APIs
- rename getResolvedLayoutDirection() to getLayoutDirection() Change-Id: I3afe56c0db0751952f5056c23893cb7455531d29
1 parent 4457e85 commit e56ffdc

20 files changed

+61
-59
lines changed

api/current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24898,7 +24898,6 @@ package android.view {
2489824898
method public android.view.ViewParent getParentForAccessibility();
2489924899
method public float getPivotX();
2490024900
method public float getPivotY();
24901-
method public int getResolvedLayoutDirection();
2490224901
method public int getResolvedTextAlignment();
2490324902
method public int getResolvedTextDirection();
2490424903
method public android.content.res.Resources getResources();

core/java/android/view/View.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,7 +3926,7 @@ protected void initializeScrollbars(TypedArray a) {
39263926
}
39273927

39283928
// Apply layout direction to the new Drawables if needed
3929-
final int layoutDirection = getResolvedLayoutDirection();
3929+
final int layoutDirection = getLayoutDirection();
39303930
if (track != null) {
39313931
track.setLayoutDirection(layoutDirection);
39323932
}
@@ -5778,7 +5778,7 @@ public boolean isHapticFeedbackEnabled() {
57785778
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"),
57795779
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE")
57805780
})
5781-
public int getLayoutDirection() {
5781+
private int getRawLayoutDirection() {
57825782
return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
57835783
}
57845784

@@ -5795,7 +5795,7 @@ public int getLayoutDirection() {
57955795
*/
57965796
@RemotableViewMethod
57975797
public void setLayoutDirection(int layoutDirection) {
5798-
if (getLayoutDirection() != layoutDirection) {
5798+
if (getRawLayoutDirection() != layoutDirection) {
57995799
// Reset the current layout direction and the resolved one
58005800
mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK;
58015801
resetRtlProperties();
@@ -5820,7 +5820,7 @@ public void setLayoutDirection(int layoutDirection) {
58205820
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"),
58215821
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
58225822
})
5823-
public int getResolvedLayoutDirection() {
5823+
public int getLayoutDirection() {
58245824
final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
58255825
if (targetSdkVersion < JELLY_BEAN_MR1) {
58265826
mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED;
@@ -5842,7 +5842,7 @@ public int getResolvedLayoutDirection() {
58425842
*/
58435843
@ViewDebug.ExportedProperty(category = "layout")
58445844
public boolean isLayoutRtl() {
5845-
return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL);
5845+
return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
58465846
}
58475847

58485848
/**
@@ -9935,7 +9935,7 @@ public void setLayoutParams(ViewGroup.LayoutParams params) {
99359935
*/
99369936
private void resolveLayoutParams() {
99379937
if (mLayoutParams != null) {
9938-
mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection());
9938+
mLayoutParams.onResolveLayoutDirection(getLayoutDirection());
99399939
}
99409940
}
99419941

@@ -11560,7 +11560,8 @@ public void resolveLayoutDirection() {
1156011560

1156111561
if (hasRtlSupport()) {
1156211562
// Set resolved depending on layout direction
11563-
switch (getLayoutDirection()) {
11563+
switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >>
11564+
PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) {
1156411565
case LAYOUT_DIRECTION_INHERIT:
1156511566
// We cannot resolve yet. LTR is by default and let the resolution happen again
1156611567
// later to get the correct resolved value
@@ -11572,7 +11573,7 @@ public void resolveLayoutDirection() {
1157211573
// resolution happen again later
1157311574
if (!viewGroup.canResolveLayoutDirection()) return;
1157411575

11575-
if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
11576+
if (viewGroup.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
1157611577
mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL;
1157711578
}
1157811579
break;
@@ -11602,7 +11603,8 @@ public void resolveLayoutDirection() {
1160211603
* @hide
1160311604
*/
1160411605
public boolean canResolveLayoutDirection() {
11605-
switch (getLayoutDirection()) {
11606+
switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >>
11607+
PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) {
1160611608
case LAYOUT_DIRECTION_INHERIT:
1160711609
return (mParent != null) && (mParent instanceof ViewGroup);
1160811610
default:
@@ -11620,6 +11622,13 @@ public void resetResolvedLayoutDirection() {
1162011622
mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK;
1162111623
}
1162211624

11625+
/**
11626+
* @hide
11627+
*/
11628+
public boolean isLayoutDirectionInherited() {
11629+
return (getRawLayoutDirection() == LAYOUT_DIRECTION_INHERIT);
11630+
}
11631+
1162311632
/**
1162411633
* Return if padding has been resolved
1162511634
*
@@ -11659,7 +11668,7 @@ public void resolvePadding() {
1165911668
// If start / end padding are defined, they will be resolved (hence overriding) to
1166011669
// left / right or right / left depending on the resolved layout direction.
1166111670
// If start / end padding are not defined, use the left / right ones.
11662-
int resolvedLayoutDirection = getResolvedLayoutDirection();
11671+
int resolvedLayoutDirection = getLayoutDirection();
1166311672
// Set user padding to initial values ...
1166411673
mUserPaddingLeft = (mUserPaddingLeftInitial == UNDEFINED_PADDING) ?
1166511674
0 : mUserPaddingLeftInitial;
@@ -14101,9 +14110,9 @@ public void unscheduleDrawable(Drawable who) {
1410114110
*/
1410214111
public void resolveDrawables() {
1410314112
if (mBackground != null) {
14104-
mBackground.setLayoutDirection(getResolvedLayoutDirection());
14113+
mBackground.setLayoutDirection(getLayoutDirection());
1410514114
}
14106-
onResolveDrawables(getResolvedLayoutDirection());
14115+
onResolveDrawables(getLayoutDirection());
1410714116
}
1410814117

1410914118
/**
@@ -14390,7 +14399,7 @@ public void setBackgroundDrawable(Drawable background) {
1439014399
padding = new Rect();
1439114400
sThreadLocal.set(padding);
1439214401
}
14393-
background.setLayoutDirection(getResolvedLayoutDirection());
14402+
background.setLayoutDirection(getLayoutDirection());
1439414403
if (background.getPadding(padding)) {
1439514404
resetResolvedPadding();
1439614405
switch (background.getLayoutDirection()) {
@@ -14587,7 +14596,7 @@ public void setPaddingRelative(int start, int top, int end, int bottom) {
1458714596
mUserPaddingStart = start;
1458814597
mUserPaddingEnd = end;
1458914598

14590-
switch(getResolvedLayoutDirection()) {
14599+
switch(getLayoutDirection()) {
1459114600
case LAYOUT_DIRECTION_RTL:
1459214601
mUserPaddingLeftInitial = end;
1459314602
mUserPaddingRightInitial = start;
@@ -14646,7 +14655,7 @@ public int getPaddingStart() {
1464614655
if (!isPaddingResolved()) {
1464714656
resolvePadding();
1464814657
}
14649-
return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
14658+
return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
1465014659
mPaddingRight : mPaddingLeft;
1465114660
}
1465214661

@@ -14675,7 +14684,7 @@ public int getPaddingEnd() {
1467514684
if (!isPaddingResolved()) {
1467614685
resolvePadding();
1467714686
}
14678-
return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
14687+
return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
1467914688
mPaddingLeft : mPaddingRight;
1468014689
}
1468114690

core/java/android/view/ViewGroup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,7 @@ private void addViewInner(View child, int index, LayoutParams params,
33923392
childHasTransientStateChanged(child, true);
33933393
}
33943394

3395-
if (child.getLayoutDirection() == View.LAYOUT_DIRECTION_INHERIT) {
3395+
if (child.isLayoutDirectionInherited()) {
33963396
child.resetResolvedLayoutDirection();
33973397
child.resolveRtlProperties();
33983398
}
@@ -5268,7 +5268,7 @@ public void resetResolvedLayoutDirection() {
52685268
int count = getChildCount();
52695269
for (int i = 0; i < count; i++) {
52705270
final View child = getChildAt(i);
5271-
if (child.getLayoutDirection() == LAYOUT_DIRECTION_INHERIT) {
5271+
if (child.isLayoutDirectionInherited()) {
52725272
child.resetResolvedLayoutDirection();
52735273
}
52745274
if (child.getTextDirection() == TEXT_DIRECTION_INHERIT) {
@@ -6155,7 +6155,7 @@ private void init(ViewGroup root, View view) {
61556155
view.getDrawingRect(viewLocation);
61566156
root.offsetDescendantRectToMyCoords(view, viewLocation);
61576157
mView = view;
6158-
mLayoutDirection = root.getResolvedLayoutDirection();
6158+
mLayoutDirection = root.getLayoutDirection();
61596159
}
61606160

61616161
private void clear() {

core/java/android/widget/AbsSeekBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void setThumb(Drawable thumb) {
108108
if (thumb != null) {
109109
thumb.setCallback(this);
110110
if (canResolveLayoutDirection()) {
111-
thumb.setLayoutDirection(getResolvedLayoutDirection());
111+
thumb.setLayoutDirection(getLayoutDirection());
112112
}
113113

114114
// Assuming the thumb drawable is symmetric, set the thumb offset

core/java/android/widget/AutoCompleteTextView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package android.widget;
1818

19-
import android.app.SearchManager.OnDismissListener;
2019
import android.content.Context;
2120
import android.content.res.TypedArray;
2221
import android.database.DataSetObserver;
@@ -1094,7 +1093,7 @@ public void showDropDown() {
10941093
mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
10951094
mPopup.setListItemExpandMax(EXPAND_MAX);
10961095
}
1097-
mPopup.setLayoutDirection(getResolvedLayoutDirection());
1096+
mPopup.setLayoutDirection(getLayoutDirection());
10981097
mPopup.show();
10991098
mPopup.getListView().setOverScrollMode(View.OVER_SCROLL_ALWAYS);
11001099
}

core/java/android/widget/Editor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@
8888
import android.view.inputmethod.InputConnection;
8989
import android.view.inputmethod.InputMethodManager;
9090
import android.widget.AdapterView.OnItemClickListener;
91-
import android.widget.Editor.InputContentType;
92-
import android.widget.Editor.InputMethodState;
93-
import android.widget.Editor.SelectionModifierCursorController;
9491
import android.widget.TextView.Drawables;
9592
import android.widget.TextView.OnEditorActionListener;
9693

@@ -292,7 +289,7 @@ public void setError(CharSequence error, Drawable icon) {
292289
mErrorWasChanged = true;
293290
final Drawables dr = mTextView.mDrawables;
294291
if (dr != null) {
295-
switch (mTextView.getResolvedLayoutDirection()) {
292+
switch (mTextView.getLayoutDirection()) {
296293
default:
297294
case View.LAYOUT_DIRECTION_LTR:
298295
mTextView.setCompoundDrawables(dr.mDrawableLeft, dr.mDrawableTop, icon,

core/java/android/widget/FrameLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
411411
gravity = DEFAULT_CHILD_GRAVITY;
412412
}
413413

414-
final int layoutDirection = getResolvedLayoutDirection();
414+
final int layoutDirection = getLayoutDirection();
415415
final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
416416
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
417417

@@ -483,7 +483,7 @@ public void draw(Canvas canvas) {
483483
selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom);
484484
}
485485

486-
final int layoutDirection = getResolvedLayoutDirection();
486+
final int layoutDirection = getLayoutDirection();
487487
Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
488488
foreground.getIntrinsicHeight(), selfBounds, overlayBounds,
489489
layoutDirection);

core/java/android/widget/GridView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ private void setupChild(View child, int position, int y, boolean flow, int child
14251425
int childLeft;
14261426
final int childTop = flow ? y : y - h;
14271427

1428-
final int layoutDirection = getResolvedLayoutDirection();
1428+
final int layoutDirection = getLayoutDirection();
14291429
final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
14301430
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
14311431
case Gravity.LEFT:

core/java/android/widget/ImageView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ private void updateDrawable(Drawable d) {
680680
d.setState(getDrawableState());
681681
}
682682
d.setLevel(mLevel);
683-
d.setLayoutDirection(getResolvedLayoutDirection());
683+
d.setLayoutDirection(getLayoutDirection());
684684
mDrawableWidth = d.getIntrinsicWidth();
685685
mDrawableHeight = d.getIntrinsicHeight();
686686
applyColorMod();

core/java/android/widget/LinearLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ void layoutVertical() {
14951495
if (gravity < 0) {
14961496
gravity = minorGravity;
14971497
}
1498-
final int layoutDirection = getResolvedLayoutDirection();
1498+
final int layoutDirection = getLayoutDirection();
14991499
final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
15001500
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
15011501
case Gravity.CENTER_HORIZONTAL:
@@ -1559,7 +1559,7 @@ void layoutHorizontal() {
15591559
final int[] maxAscent = mMaxAscent;
15601560
final int[] maxDescent = mMaxDescent;
15611561

1562-
final int layoutDirection = getResolvedLayoutDirection();
1562+
final int layoutDirection = getLayoutDirection();
15631563
switch (Gravity.getAbsoluteGravity(majorGravity, layoutDirection)) {
15641564
case Gravity.RIGHT:
15651565
// mTotalLength contains the padding already

0 commit comments

Comments
 (0)