Skip to content

Commit 1d3d7da

Browse files
author
Fabrice Di Meglio
committed
Improve ListPopupWindow RTL support
- add Javadoc for new method setLayoutDirection() - fix one issue where the layout direction would not be set when the popup was recreated Change-Id: Ic53a8b0d01dc86e03e9bf5f09195af77404dca39
1 parent d395ea1 commit 1d3d7da

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

core/java/android/widget/ListPopupWindow.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.graphics.drawable.Drawable;
2323
import android.os.Handler;
2424
import android.util.AttributeSet;
25+
import android.util.LocaleUtil;
2526
import android.util.Log;
2627
import android.view.KeyEvent;
2728
import android.view.MotionEvent;
@@ -31,6 +32,8 @@
3132
import android.view.ViewGroup;
3233
import android.view.ViewParent;
3334

35+
import java.util.Locale;
36+
3437
/**
3538
* A ListPopupWindow anchors itself to a host view and displays a
3639
* list of choices.
@@ -92,6 +95,8 @@ public class ListPopupWindow {
9295

9396
private boolean mModal;
9497

98+
private int mLayoutDirection;
99+
95100
/**
96101
* The provided prompt view should appear above list content.
97102
*
@@ -193,6 +198,9 @@ public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, in
193198
mContext = context;
194199
mPopup = new PopupWindow(context, attrs, defStyleAttr, defStyleRes);
195200
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
201+
// Set the default layout direction to match the default locale one
202+
final Locale locale = mContext.getResources().getConfiguration().locale;
203+
mLayoutDirection = LocaleUtil.getLayoutDirectionFromLocale(locale);
196204
}
197205

198206
/**
@@ -1013,6 +1021,8 @@ public void onNothingSelected(AdapterView<?> parent) {
10131021
mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
10141022
}
10151023

1024+
mDropDownList.setLayoutDirection(mLayoutDirection);
1025+
10161026
dropDownView = mDropDownList;
10171027

10181028
View hintView = mPromptView;
@@ -1121,9 +1131,18 @@ public void onNothingSelected(AdapterView<?> parent) {
11211131
return listContent + otherHeights;
11221132
}
11231133

1124-
public void setLayoutDirection(int resolvedLayoutDirection) {
1134+
/**
1135+
* Set the layout direction for this popup. Should be a resolved direction as the
1136+
* popup as no capacity to do the resolution on his own.
1137+
*
1138+
* @param layoutDirection One of {@link View#LAYOUT_DIRECTION_LTR},
1139+
* {@link View#LAYOUT_DIRECTION_RTL},
1140+
*
1141+
*/
1142+
public void setLayoutDirection(int layoutDirection) {
1143+
mLayoutDirection = layoutDirection;
11251144
if (mDropDownList != null) {
1126-
mDropDownList.setLayoutDirection(resolvedLayoutDirection);
1145+
mDropDownList.setLayoutDirection(mLayoutDirection);
11271146
}
11281147
}
11291148

0 commit comments

Comments
 (0)