Skip to content

Commit 97e146c

Browse files
author
Fabrice Di Meglio
committed
Fix bug #6427629 Clean up layout direction APIs
- rename getResolvedTextDirection() to getTextDirection() Change-Id: Id2a6025daf5521dcd676e454fc6bb9955fdccf2d
1 parent e56ffdc commit 97e146c

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
@@ -24899,7 +24899,6 @@ package android.view {
2489924899
method public float getPivotX();
2490024900
method public float getPivotY();
2490124901
method public int getResolvedTextAlignment();
24902-
method public int getResolvedTextDirection();
2490324902
method public android.content.res.Resources getResources();
2490424903
method public final int getRight();
2490524904
method protected float getRightFadingEdgeStrength();

core/java/android/view/View.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16496,6 +16496,8 @@ protected float getHorizontalScrollFactor() {
1649616496
* {@link #TEXT_DIRECTION_LTR},
1649716497
* {@link #TEXT_DIRECTION_RTL},
1649816498
* {@link #TEXT_DIRECTION_LOCALE}
16499+
*
16500+
* @hide
1649916501
*/
1650016502
@ViewDebug.ExportedProperty(category = "text", mapping = {
1650116503
@ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"),
@@ -16505,7 +16507,7 @@ protected float getHorizontalScrollFactor() {
1650516507
@ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"),
1650616508
@ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE")
1650716509
})
16508-
public int getTextDirection() {
16510+
public int getRawTextDirection() {
1650916511
return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
1651016512
}
1651116513

@@ -16522,7 +16524,7 @@ public int getTextDirection() {
1652216524
* {@link #TEXT_DIRECTION_LOCALE}
1652316525
*/
1652416526
public void setTextDirection(int textDirection) {
16525-
if (getTextDirection() != textDirection) {
16527+
if (getRawTextDirection() != textDirection) {
1652616528
// Reset the current text direction and the resolved one
1652716529
mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK;
1652816530
resetResolvedTextDirection();
@@ -16539,10 +16541,10 @@ public void setTextDirection(int textDirection) {
1653916541
/**
1654016542
* Return the resolved text direction.
1654116543
*
16542-
* This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches
16543-
* {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds
16544-
* up the parent chain of the view. if there is no parent, then it will return the default
16545-
* {@link #TEXT_DIRECTION_FIRST_STRONG}.
16544+
* This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches what has
16545+
* been set by {@link #setTextDirection(int)} if it is not TEXT_DIRECTION_INHERIT, otherwise the
16546+
* resolution proceeds up the parent chain of the view. If there is no parent, then it will
16547+
* return the default {@link #TEXT_DIRECTION_FIRST_STRONG}.
1654616548
*
1654716549
* @return the resolved text direction. Returns one of:
1654816550
*
@@ -16552,7 +16554,7 @@ public void setTextDirection(int textDirection) {
1655216554
* {@link #TEXT_DIRECTION_RTL},
1655316555
* {@link #TEXT_DIRECTION_LOCALE}
1655416556
*/
16555-
public int getResolvedTextDirection() {
16557+
public int getTextDirection() {
1655616558
// The text direction will be resolved only if needed
1655716559
if ((mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) != PFLAG2_TEXT_DIRECTION_RESOLVED) {
1655816560
resolveTextDirection();
@@ -16571,14 +16573,14 @@ public void resolveTextDirection() {
1657116573

1657216574
if (hasRtlSupport()) {
1657316575
// Set resolved text direction flag depending on text direction flag
16574-
final int textDirection = getTextDirection();
16576+
final int textDirection = getRawTextDirection();
1657516577
switch(textDirection) {
1657616578
case TEXT_DIRECTION_INHERIT:
1657716579
if (canResolveTextDirection()) {
1657816580
ViewGroup viewGroup = ((ViewGroup) mParent);
1657916581

1658016582
// Set current resolved direction to the same value as the parent's one
16581-
final int parentResolvedDirection = viewGroup.getResolvedTextDirection();
16583+
final int parentResolvedDirection = viewGroup.getTextDirection();
1658216584
switch (parentResolvedDirection) {
1658316585
case TEXT_DIRECTION_FIRST_STRONG:
1658416586
case TEXT_DIRECTION_ANY_RTL:
@@ -16624,7 +16626,7 @@ public void resolveTextDirection() {
1662416626
* @return true if text direction resolution can be done otherwise return false.
1662516627
*/
1662616628
private boolean canResolveTextDirection() {
16627-
switch (getTextDirection()) {
16629+
switch (getRawTextDirection()) {
1662816630
case TEXT_DIRECTION_INHERIT:
1662916631
return (mParent != null) && (mParent instanceof ViewGroup);
1663016632
default:
@@ -16634,14 +16636,21 @@ private boolean canResolveTextDirection() {
1663416636

1663516637
/**
1663616638
* Reset resolved text direction. Text direction can be resolved with a call to
16637-
* getResolvedTextDirection().
16639+
* getTextDirection().
1663816640
*
1663916641
* @hide
1664016642
*/
1664116643
public void resetResolvedTextDirection() {
1664216644
mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK);
1664316645
}
1664416646

16647+
/**
16648+
* @hide
16649+
*/
16650+
public boolean isTextDirectionInherited() {
16651+
return (getRawTextDirection() == TEXT_DIRECTION_INHERIT);
16652+
}
16653+
1664516654
/**
1664616655
* Return the value specifying the text alignment or policy that was set with
1664716656
* {@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)