|
7 | 7 | import android.app.TimePickerDialog; |
8 | 8 | import android.content.DialogInterface; |
9 | 9 | import android.content.Context; |
| 10 | +import android.os.Build; |
10 | 11 | import android.os.Handler; |
| 12 | +import android.util.Log; |
11 | 13 | import android.widget.TimePicker; |
12 | 14 | import android.view.View; |
13 | 15 | import android.widget.EditText; |
@@ -141,23 +143,30 @@ private boolean pickerIsInTextInputMode() { |
141 | 143 | */ |
142 | 144 | private void correctEnteredMinutes(final TimePicker view, final int hourOfDay, final int correctedMinutes) { |
143 | 145 | assertNotSpinner("spinner never needs to be corrected because wrong values are not offered to user (both in scrolling and textInput mode)!"); |
144 | | - final EditText textInput = (EditText) view.findFocus(); |
145 | | - |
146 | 146 | // 'correction' callback |
147 | 147 | runnable = new Runnable() { |
148 | 148 | @Override |
149 | 149 | public void run() { |
150 | | - if (pickerIsInTextInputMode()) { |
151 | | - // set valid minutes && move caret to the end of input |
152 | | - view.setCurrentHour(hourOfDay); |
153 | | - view.setCurrentMinute(correctedMinutes); |
154 | | - textInput.setSelection(textInput.getText().length()); |
| 150 | + // set valid hour & minutes |
| 151 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 152 | + view.setHour(hourOfDay); |
| 153 | + view.setMinute(correctedMinutes); |
155 | 154 | } else { |
156 | 155 | view.setCurrentHour(hourOfDay); |
157 | 156 | // we need to set minutes to 0 for this to work on older android devices |
158 | 157 | view.setCurrentMinute(0); |
159 | 158 | view.setCurrentMinute(correctedMinutes); |
160 | 159 | } |
| 160 | + if (pickerIsInTextInputMode()) { |
| 161 | + // move caret to the end of input |
| 162 | + View maybeTextInput = view.findFocus(); |
| 163 | + if (maybeTextInput instanceof EditText) { |
| 164 | + final EditText textInput = (EditText) maybeTextInput; |
| 165 | + textInput.setSelection(textInput.getText().length()); |
| 166 | + } else { |
| 167 | + Log.e("RN-datetimepicker", "could not set selection on time picker, this is a known issue on some Huawei devices"); |
| 168 | + } |
| 169 | + } |
161 | 170 | } |
162 | 171 | }; |
163 | 172 |
|
|
0 commit comments