Skip to content

Commit 5b5a657

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Make SearchView RTL aware" into jb-mr1-dev
2 parents 706708d + 3a69bea commit 5b5a657

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

core/java/android/widget/AutoCompleteTextView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ public void showDropDown() {
10781078
mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
10791079
mPopup.setListItemExpandMax(EXPAND_MAX);
10801080
}
1081+
mPopup.setLayoutDirection(getResolvedLayoutDirection());
10811082
mPopup.show();
10821083
mPopup.getListView().setOverScrollMode(View.OVER_SCROLL_ALWAYS);
10831084
}

core/java/android/widget/ListPopupWindow.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,12 @@ public void onNothingSelected(AdapterView<?> parent) {
11211121
return listContent + otherHeights;
11221122
}
11231123

1124+
public void setLayoutDirection(int resolvedLayoutDirection) {
1125+
if (mDropDownList != null) {
1126+
mDropDownList.setLayoutDirection(resolvedLayoutDirection);
1127+
}
1128+
}
1129+
11241130
/**
11251131
* <p>Wrapper class for a ListView. This wrapper can hijack the focus to
11261132
* make sure the list uses the appropriate drawables and states when

core/java/android/widget/SearchView.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
326326
int oldLeft, int oldTop, int oldRight, int oldBottom) {
327327
adjustDropDownSizeAndPosition();
328328
}
329-
330329
});
331330
}
332331

@@ -1285,15 +1284,22 @@ private void adjustDropDownSizeAndPosition() {
12851284
Resources res = getContext().getResources();
12861285
int anchorPadding = mSearchPlate.getPaddingLeft();
12871286
Rect dropDownPadding = new Rect();
1287+
final boolean isLayoutRtl = isLayoutRtl();
12881288
int iconOffset = mIconifiedByDefault
12891289
? res.getDimensionPixelSize(R.dimen.dropdownitem_icon_width)
12901290
+ res.getDimensionPixelSize(R.dimen.dropdownitem_text_padding_left)
12911291
: 0;
12921292
mQueryTextView.getDropDownBackground().getPadding(dropDownPadding);
1293-
mQueryTextView.setDropDownHorizontalOffset(-(dropDownPadding.left + iconOffset)
1294-
+ anchorPadding);
1295-
mQueryTextView.setDropDownWidth(mDropDownAnchor.getWidth() + dropDownPadding.left
1296-
+ dropDownPadding.right + iconOffset - (anchorPadding));
1293+
int offset;
1294+
if (isLayoutRtl) {
1295+
offset = - dropDownPadding.left;
1296+
} else {
1297+
offset = anchorPadding - (dropDownPadding.left + iconOffset);
1298+
}
1299+
mQueryTextView.setDropDownHorizontalOffset(offset);
1300+
final int width = mDropDownAnchor.getWidth() + dropDownPadding.left
1301+
+ dropDownPadding.right + iconOffset - anchorPadding;
1302+
mQueryTextView.setDropDownWidth(width);
12971303
}
12981304
}
12991305

@@ -1347,6 +1353,11 @@ public void onNothingSelected(AdapterView<?> parent) {
13471353
}
13481354
};
13491355

1356+
@Override
1357+
public void onResolvedLayoutDirectionChanged() {
1358+
mQueryTextView.setLayoutDirection(getResolvedLayoutDirection());
1359+
}
1360+
13501361
/**
13511362
* Query rewriting.
13521363
*/

0 commit comments

Comments
 (0)