Skip to content

Commit fde3f83

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #6140391 Make RTL awareness as an opt-in into the AndroidManifest"
2 parents 991c873 + 59dfce8 commit fde3f83

File tree

7 files changed

+112
-63
lines changed

7 files changed

+112
-63
lines changed

api/current.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ package android {
596596
field public static final int layerType = 16843604; // 0x1010354
597597
field public static final int layout = 16842994; // 0x10100f2
598598
field public static final int layoutAnimation = 16842988; // 0x10100ec
599-
field public static final int layoutDirection = 16843689; // 0x10103a9
599+
field public static final int layoutDirection = 16843690; // 0x10103aa
600600
field public static final int layout_above = 16843140; // 0x1010184
601601
field public static final int layout_alignBaseline = 16843142; // 0x1010186
602602
field public static final int layout_alignBottom = 16843146; // 0x101018a
@@ -618,10 +618,10 @@ package android {
618618
field public static final int layout_height = 16842997; // 0x10100f5
619619
field public static final int layout_margin = 16842998; // 0x10100f6
620620
field public static final int layout_marginBottom = 16843002; // 0x10100fa
621-
field public static final int layout_marginEnd = 16843693; // 0x10103ad
621+
field public static final int layout_marginEnd = 16843694; // 0x10103ae
622622
field public static final int layout_marginLeft = 16842999; // 0x10100f7
623623
field public static final int layout_marginRight = 16843001; // 0x10100f9
624-
field public static final int layout_marginStart = 16843692; // 0x10103ac
624+
field public static final int layout_marginStart = 16843693; // 0x10103ad
625625
field public static final int layout_marginTop = 16843000; // 0x10100f8
626626
field public static final int layout_row = 16843643; // 0x101037b
627627
field public static final int layout_rowSpan = 16843644; // 0x101037c
@@ -717,10 +717,10 @@ package android {
717717
field public static final int packageNames = 16843649; // 0x1010381
718718
field public static final int padding = 16842965; // 0x10100d5
719719
field public static final int paddingBottom = 16842969; // 0x10100d9
720-
field public static final int paddingEnd = 16843691; // 0x10103ab
720+
field public static final int paddingEnd = 16843692; // 0x10103ac
721721
field public static final int paddingLeft = 16842966; // 0x10100d6
722722
field public static final int paddingRight = 16842968; // 0x10100d8
723-
field public static final int paddingStart = 16843690; // 0x10103aa
723+
field public static final int paddingStart = 16843691; // 0x10103ab
724724
field public static final int paddingTop = 16842967; // 0x10100d7
725725
field public static final int panelBackground = 16842846; // 0x101005e
726726
field public static final int panelColorBackground = 16842849; // 0x1010061
@@ -931,6 +931,7 @@ package android {
931931
field public static final int summaryColumn = 16843426; // 0x10102a2
932932
field public static final int summaryOff = 16843248; // 0x10101f0
933933
field public static final int summaryOn = 16843247; // 0x10101ef
934+
field public static final int supportsRtl = 16843688; // 0x10103a8
934935
field public static final int supportsUploading = 16843419; // 0x101029b
935936
field public static final int switchMinWidth = 16843632; // 0x1010370
936937
field public static final int switchPadding = 16843633; // 0x1010371
@@ -1000,7 +1001,7 @@ package android {
10001001
field public static final int textColorTertiary = 16843282; // 0x1010212
10011002
field public static final int textColorTertiaryInverse = 16843283; // 0x1010213
10021003
field public static final int textCursorDrawable = 16843618; // 0x1010362
1003-
field public static final int textDirection = 16843688; // 0x10103a8
1004+
field public static final int textDirection = 16843689; // 0x10103a9
10041005
field public static final int textEditNoPasteWindowLayout = 16843541; // 0x1010315
10051006
field public static final int textEditPasteWindowLayout = 16843540; // 0x1010314
10061007
field public static final int textEditSideNoPasteWindowLayout = 16843615; // 0x101035f
@@ -6131,6 +6132,7 @@ package android.content.pm {
61316132
field public static final int FLAG_STOPPED = 2097152; // 0x200000
61326133
field public static final int FLAG_SUPPORTS_LARGE_SCREENS = 2048; // 0x800
61336134
field public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1024; // 0x400
6135+
field public static final int FLAG_SUPPORTS_RTL = 1073741824; // 0x40000000
61346136
field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
61356137
field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
61366138
field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000

core/java/android/content/pm/ApplicationInfo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
290290
*/
291291
public static final int FLAG_STOPPED = 1<<21;
292292

293+
/**
294+
* Value for {@link #flags}: true when the application is willing to support
295+
* RTL (right to left). All activities will inherit this value.
296+
*
297+
* Set from the {@link android.R.attr#supportsRtl} attribute in the
298+
* activity's manifest.
299+
*
300+
* Default value is false (no support for RTL).
301+
*/
302+
public static final int FLAG_SUPPORTS_RTL = 1<<22;
303+
293304
/**
294305
* Value for {@link #flags}: Set to true if the application has been
295306
* installed using the forward lock option.
@@ -466,8 +477,17 @@ public void dump(Printer pw, String prefix) {
466477
if (uiOptions != 0) {
467478
pw.println(prefix + "uiOptions=0x" + Integer.toHexString(uiOptions));
468479
}
480+
pw.println(prefix + "supportsRtl=" + (hasRtlSupport() ? "true" : "false"));
469481
super.dumpBack(pw, prefix);
470482
}
483+
484+
/**
485+
* @return true if "supportsRtl" has been set to true in the AndroidManifest
486+
* @hide
487+
*/
488+
public boolean hasRtlSupport() {
489+
return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
490+
}
471491

472492
public static class DisplayNameComparator
473493
implements Comparator<ApplicationInfo> {

core/java/android/content/pm/PackageParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,12 @@ private boolean parseApplication(Package owner, Resources res,
17611761
ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
17621762
}
17631763

1764+
if (sa.getBoolean(
1765+
com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1766+
false /* default is no RTL support*/)) {
1767+
ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1768+
}
1769+
17641770
String str;
17651771
str = sa.getNonConfigurationString(
17661772
com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);

core/java/android/view/View.java

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9997,6 +9997,13 @@ void dispatchScreenStateChanged(int screenState) {
99979997
public void onScreenStateChanged(int screenState) {
99989998
}
99999999

10000+
/**
10001+
* Return true if the application tag in the AndroidManifest has set "supportRtl" to true
10002+
*/
10003+
private boolean hasRtlSupport() {
10004+
return mContext.getApplicationInfo().hasRtlSupport();
10005+
}
10006+
1000010007
/**
1000110008
* Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing
1000210009
* that the parent directionality can and will be resolved before its children.
@@ -10006,30 +10013,32 @@ public void resolveLayoutDirection() {
1000610013
// Clear any previous layout direction resolution
1000710014
mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK;
1000810015

10009-
// Set resolved depending on layout direction
10010-
switch (getLayoutDirection()) {
10011-
case LAYOUT_DIRECTION_INHERIT:
10012-
// If this is root view, no need to look at parent's layout dir.
10013-
if (canResolveLayoutDirection()) {
10014-
ViewGroup viewGroup = ((ViewGroup) mParent);
10016+
if (hasRtlSupport()) {
10017+
// Set resolved depending on layout direction
10018+
switch (getLayoutDirection()) {
10019+
case LAYOUT_DIRECTION_INHERIT:
10020+
// If this is root view, no need to look at parent's layout dir.
10021+
if (canResolveLayoutDirection()) {
10022+
ViewGroup viewGroup = ((ViewGroup) mParent);
1001510023

10016-
if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
10024+
if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
10025+
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
10026+
}
10027+
} else {
10028+
// Nothing to do, LTR by default
10029+
}
10030+
break;
10031+
case LAYOUT_DIRECTION_RTL:
10032+
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
10033+
break;
10034+
case LAYOUT_DIRECTION_LOCALE:
10035+
if(isLayoutDirectionRtl(Locale.getDefault())) {
1001710036
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
1001810037
}
10019-
} else {
10038+
break;
10039+
default:
1002010040
// Nothing to do, LTR by default
10021-
}
10022-
break;
10023-
case LAYOUT_DIRECTION_RTL:
10024-
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
10025-
break;
10026-
case LAYOUT_DIRECTION_LOCALE:
10027-
if(isLayoutDirectionRtl(Locale.getDefault())) {
10028-
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
10029-
}
10030-
break;
10031-
default:
10032-
// Nothing to do, LTR by default
10041+
}
1003310042
}
1003410043

1003510044
// Set to resolved
@@ -14809,44 +14818,49 @@ public void resolveTextDirection() {
1480914818
// Reset any previous text direction resolution
1481014819
mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK);
1481114820

14812-
// Set resolved text direction flag depending on text direction flag
14813-
final int textDirection = getTextDirection();
14814-
switch(textDirection) {
14815-
case TEXT_DIRECTION_INHERIT:
14816-
if (canResolveTextDirection()) {
14817-
ViewGroup viewGroup = ((ViewGroup) mParent);
14818-
14819-
// Set current resolved direction to the same value as the parent's one
14820-
final int parentResolvedDirection = viewGroup.getResolvedTextDirection();
14821-
switch (parentResolvedDirection) {
14822-
case TEXT_DIRECTION_FIRST_STRONG:
14823-
case TEXT_DIRECTION_ANY_RTL:
14824-
case TEXT_DIRECTION_LTR:
14825-
case TEXT_DIRECTION_RTL:
14826-
case TEXT_DIRECTION_LOCALE:
14827-
mPrivateFlags2 |=
14828-
(parentResolvedDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT);
14829-
break;
14830-
default:
14831-
// Default resolved direction is "first strong" heuristic
14832-
mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT;
14821+
if (hasRtlSupport()) {
14822+
// Set resolved text direction flag depending on text direction flag
14823+
final int textDirection = getTextDirection();
14824+
switch(textDirection) {
14825+
case TEXT_DIRECTION_INHERIT:
14826+
if (canResolveTextDirection()) {
14827+
ViewGroup viewGroup = ((ViewGroup) mParent);
14828+
14829+
// Set current resolved direction to the same value as the parent's one
14830+
final int parentResolvedDirection = viewGroup.getResolvedTextDirection();
14831+
switch (parentResolvedDirection) {
14832+
case TEXT_DIRECTION_FIRST_STRONG:
14833+
case TEXT_DIRECTION_ANY_RTL:
14834+
case TEXT_DIRECTION_LTR:
14835+
case TEXT_DIRECTION_RTL:
14836+
case TEXT_DIRECTION_LOCALE:
14837+
mPrivateFlags2 |=
14838+
(parentResolvedDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT);
14839+
break;
14840+
default:
14841+
// Default resolved direction is "first strong" heuristic
14842+
mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT;
14843+
}
14844+
} else {
14845+
// We cannot do the resolution if there is no parent, so use the default one
14846+
mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT;
1483314847
}
14834-
} else {
14835-
// We cannot do the resolution if there is no parent, so use the default one
14848+
break;
14849+
case TEXT_DIRECTION_FIRST_STRONG:
14850+
case TEXT_DIRECTION_ANY_RTL:
14851+
case TEXT_DIRECTION_LTR:
14852+
case TEXT_DIRECTION_RTL:
14853+
case TEXT_DIRECTION_LOCALE:
14854+
// Resolved direction is the same as text direction
14855+
mPrivateFlags2 |= (textDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT);
14856+
break;
14857+
default:
14858+
// Default resolved direction is "first strong" heuristic
1483614859
mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT;
14837-
}
14838-
break;
14839-
case TEXT_DIRECTION_FIRST_STRONG:
14840-
case TEXT_DIRECTION_ANY_RTL:
14841-
case TEXT_DIRECTION_LTR:
14842-
case TEXT_DIRECTION_RTL:
14843-
case TEXT_DIRECTION_LOCALE:
14844-
// Resolved direction is the same as text direction
14845-
mPrivateFlags2 |= (textDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT);
14846-
break;
14847-
default:
14848-
// Default resolved direction is "first strong" heuristic
14849-
mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT;
14860+
}
14861+
} else {
14862+
// Default resolved direction is "first strong" heuristic
14863+
mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT;
1485014864
}
1485114865

1485214866
// Set to resolved

core/res/res/values/attrs_manifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@
843843
@hide -->
844844
<attr name="cantSaveState" format="boolean" />
845845
<attr name="uiOptions" />
846+
<!-- Declare that your application will be able to deal with RTL (right to left) layouts.
847+
If set to false (default value), your application will not care about RTL layouts. -->
848+
<attr name="supportsRtl" format="boolean" />
846849
</declare-styleable>
847850

848851
<!-- The <code>permission</code> tag declares a security permission that can be

core/res/res/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,8 @@
35513551
=============================================================== -->
35523552
<public type="attr" name="isolatedProcess" id="0x010103a7" />
35533553

3554+
<public type="attr" name="supportsRtl" id="0x010103a8" />
3555+
35543556
<public type="attr" name="textDirection"/>
35553557

35563558
<public type="attr" name="layoutDirection" />

tests/BiDiTests/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
android:versionCode="1"
2020
android:versionName="1.0">
2121

22-
<application android:label="BiDiTests" android:hardwareAccelerated="true">
22+
<application android:label="BiDiTests"
23+
android:hardwareAccelerated="true"
24+
android:supportsRtl="true" >
2325

2426
<activity android:name=".BiDiTestActivity"
2527
android:windowSoftInputMode="stateAlwaysHidden">

0 commit comments

Comments
 (0)