Skip to content

Commit be4c5dd

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #6427629 Clean up layout direction APIs" into jb-mr1-dev
2 parents 9c7b529 + 97e146c commit be4c5dd

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

api/current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24954,7 +24954,6 @@ package android.view {
2495424954
method public float getPivotX();
2495524955
method public float getPivotY();
2495624956
method public int getResolvedTextAlignment();
24957-
method public int getResolvedTextDirection();
2495824957
method public android.content.res.Resources getResources();
2495924958
method public final int getRight();
2496024959
method protected float getRightFadingEdgeStrength();

core/java/android/view/View.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16500,6 +16500,8 @@ protected float getHorizontalScrollFactor() {
1650016500
* {@link #TEXT_DIRECTION_LTR},
1650116501
* {@link #TEXT_DIRECTION_RTL},
1650216502
* {@link #TEXT_DIRECTION_LOCALE}
16503+
*
16504+
* @hide
1650316505
*/
1650416506
@ViewDebug.ExportedProperty(category = "text", mapping = {
1650516507
@ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"),
@@ -16509,7 +16511,7 @@ protected float getHorizontalScrollFactor() {
1650916511
@ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"),
1651016512
@ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE")
1651116513
})
16512-
public int getTextDirection() {
16514+
public int getRawTextDirection() {
1651316515
return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
1651416516
}
1651516517

@@ -16526,7 +16528,7 @@ public int getTextDirection() {
1652616528
* {@link #TEXT_DIRECTION_LOCALE}
1652716529
*/
1652816530
public void setTextDirection(int textDirection) {
16529-
if (getTextDirection() != textDirection) {
16531+
if (getRawTextDirection() != textDirection) {
1653016532
// Reset the current text direction and the resolved one
1653116533
mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK;
1653216534
resetResolvedTextDirection();
@@ -16543,10 +16545,10 @@ public void setTextDirection(int textDirection) {
1654316545
/**
1654416546
* Return the resolved text direction.
1654516547
*
16546-
* This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches
16547-
* {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds
16548-
* up the parent chain of the view. if there is no parent, then it will return the default
16549-
* {@link #TEXT_DIRECTION_FIRST_STRONG}.
16548+
* This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches what has
16549+
* been set by {@link #setTextDirection(int)} if it is not TEXT_DIRECTION_INHERIT, otherwise the
16550+
* resolution proceeds up the parent chain of the view. If there is no parent, then it will
16551+
* return the default {@link #TEXT_DIRECTION_FIRST_STRONG}.
1655016552
*
1655116553
* @return the resolved text direction. Returns one of:
1655216554
*
@@ -16556,7 +16558,7 @@ public void setTextDirection(int textDirection) {
1655616558
* {@link #TEXT_DIRECTION_RTL},
1655716559
* {@link #TEXT_DIRECTION_LOCALE}
1655816560
*/
16559-
public int getResolvedTextDirection() {
16561+
public int getTextDirection() {
1656016562
// The text direction will be resolved only if needed
1656116563
if ((mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) != PFLAG2_TEXT_DIRECTION_RESOLVED) {
1656216564
resolveTextDirection();
@@ -16575,14 +16577,14 @@ public void resolveTextDirection() {
1657516577

1657616578
if (hasRtlSupport()) {
1657716579
// Set resolved text direction flag depending on text direction flag
16578-
final int textDirection = getTextDirection();
16580+
final int textDirection = getRawTextDirection();
1657916581
switch(textDirection) {
1658016582
case TEXT_DIRECTION_INHERIT:
1658116583
if (canResolveTextDirection()) {
1658216584
ViewGroup viewGroup = ((ViewGroup) mParent);
1658316585

1658416586
// Set current resolved direction to the same value as the parent's one
16585-
final int parentResolvedDirection = viewGroup.getResolvedTextDirection();
16587+
final int parentResolvedDirection = viewGroup.getTextDirection();
1658616588
switch (parentResolvedDirection) {
1658716589
case TEXT_DIRECTION_FIRST_STRONG:
1658816590
case TEXT_DIRECTION_ANY_RTL:
@@ -16628,7 +16630,7 @@ public void resolveTextDirection() {
1662816630
* @return true if text direction resolution can be done otherwise return false.
1662916631
*/
1663016632
private boolean canResolveTextDirection() {
16631-
switch (getTextDirection()) {
16633+
switch (getRawTextDirection()) {
1663216634
case TEXT_DIRECTION_INHERIT:
1663316635
return (mParent != null) && (mParent instanceof ViewGroup);
1663416636
default:
@@ -16638,14 +16640,21 @@ private boolean canResolveTextDirection() {
1663816640

1663916641
/**
1664016642
* Reset resolved text direction. Text direction can be resolved with a call to
16641-
* getResolvedTextDirection().
16643+
* getTextDirection().
1664216644
*
1664316645
* @hide
1664416646
*/
1664516647
public void resetResolvedTextDirection() {
1664616648
mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK);
1664716649
}
1664816650

16651+
/**
16652+
* @hide
16653+
*/
16654+
public boolean isTextDirectionInherited() {
16655+
return (getRawTextDirection() == TEXT_DIRECTION_INHERIT);
16656+
}
16657+
1664916658
/**
1665016659
* Return the value specifying the text alignment or policy that was set with
1665116660
* {@link #setTextAlignment(int)}.

core/java/android/view/ViewGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5271,7 +5271,7 @@ public void resetResolvedLayoutDirection() {
52715271
if (child.isLayoutDirectionInherited()) {
52725272
child.resetResolvedLayoutDirection();
52735273
}
5274-
if (child.getTextDirection() == TEXT_DIRECTION_INHERIT) {
5274+
if (child.isTextDirectionInherited()) {
52755275
child.resetResolvedTextDirection();
52765276
}
52775277
if (child.getTextAlignment() == TEXT_ALIGNMENT_INHERIT) {

core/java/android/widget/TextView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8192,8 +8192,7 @@ TextDirectionHeuristic getTextDirectionHeuristic() {
81928192
final boolean defaultIsRtl = (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
81938193

81948194
// Now, we can select the heuristic
8195-
int textDir = getResolvedTextDirection();
8196-
switch (textDir) {
8195+
switch (getTextDirection()) {
81978196
default:
81988197
case TEXT_DIRECTION_FIRST_STRONG:
81998198
return (defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL :

0 commit comments

Comments
 (0)