|
22 | 22 | import android.graphics.drawable.Drawable; |
23 | 23 | import android.os.Handler; |
24 | 24 | import android.util.AttributeSet; |
| 25 | +import android.util.LocaleUtil; |
25 | 26 | import android.util.Log; |
26 | 27 | import android.view.KeyEvent; |
27 | 28 | import android.view.MotionEvent; |
|
31 | 32 | import android.view.ViewGroup; |
32 | 33 | import android.view.ViewParent; |
33 | 34 |
|
| 35 | +import java.util.Locale; |
| 36 | + |
34 | 37 | /** |
35 | 38 | * A ListPopupWindow anchors itself to a host view and displays a |
36 | 39 | * list of choices. |
@@ -92,6 +95,8 @@ public class ListPopupWindow { |
92 | 95 |
|
93 | 96 | private boolean mModal; |
94 | 97 |
|
| 98 | + private int mLayoutDirection; |
| 99 | + |
95 | 100 | /** |
96 | 101 | * The provided prompt view should appear above list content. |
97 | 102 | * |
@@ -193,6 +198,9 @@ public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, in |
193 | 198 | mContext = context; |
194 | 199 | mPopup = new PopupWindow(context, attrs, defStyleAttr, defStyleRes); |
195 | 200 | 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); |
196 | 204 | } |
197 | 205 |
|
198 | 206 | /** |
@@ -1013,6 +1021,8 @@ public void onNothingSelected(AdapterView<?> parent) { |
1013 | 1021 | mDropDownList.setOnItemSelectedListener(mItemSelectedListener); |
1014 | 1022 | } |
1015 | 1023 |
|
| 1024 | + mDropDownList.setLayoutDirection(mLayoutDirection); |
| 1025 | + |
1016 | 1026 | dropDownView = mDropDownList; |
1017 | 1027 |
|
1018 | 1028 | View hintView = mPromptView; |
@@ -1121,9 +1131,18 @@ public void onNothingSelected(AdapterView<?> parent) { |
1121 | 1131 | return listContent + otherHeights; |
1122 | 1132 | } |
1123 | 1133 |
|
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; |
1125 | 1144 | if (mDropDownList != null) { |
1126 | | - mDropDownList.setLayoutDirection(resolvedLayoutDirection); |
| 1145 | + mDropDownList.setLayoutDirection(mLayoutDirection); |
1127 | 1146 | } |
1128 | 1147 | } |
1129 | 1148 |
|
|
0 commit comments