Skip to content

Commit dcfe2ee

Browse files
paulfthomashunterstich
authored andcommitted
[TimePicker] Default to text input mode in landscape
PiperOrigin-RevId: 775714779
1 parent 5853d72 commit dcfe2ee

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

lib/java/com/google/android/material/timepicker/MaterialTimePicker.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ private void restoreState(@Nullable Bundle bundle) {
248248
if (time == null) {
249249
time = new TimeModel();
250250
}
251-
int defaultInputMode = time.format == CLOCK_24H ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
251+
252+
boolean forceKeyboardInputMode =
253+
getResources().getBoolean(R.bool.timepicker_force_input_mode_keyboard);
254+
int defaultInputMode =
255+
forceKeyboardInputMode || time.format == CLOCK_24H ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
252256
inputMode = bundle.getInt(INPUT_MODE_EXTRA, defaultInputMode);
253257
titleResId = bundle.getInt(TITLE_RES_EXTRA, 0);
254258
titleText = bundle.getCharSequence(TITLE_TEXT_EXTRA);
@@ -299,14 +303,11 @@ public void onClick(View v) {
299303

300304
cancelButton = root.findViewById(R.id.material_timepicker_cancel_button);
301305
cancelButton.setOnClickListener(
302-
new OnClickListener() {
303-
@Override
304-
public void onClick(View v) {
305-
for (OnClickListener listener : negativeButtonListeners) {
306-
listener.onClick(v);
307-
}
308-
dismiss();
306+
v -> {
307+
for (OnClickListener listener : negativeButtonListeners) {
308+
listener.onClick(v);
309309
}
310+
dismiss();
310311
});
311312
if (negativeButtonTextResId != 0) {
312313
cancelButton.setText(negativeButtonTextResId);
@@ -317,12 +318,9 @@ public void onClick(View v) {
317318
updateCancelButtonVisibility();
318319

319320
modeButton.setOnClickListener(
320-
new OnClickListener() {
321-
@Override
322-
public void onClick(View v) {
323-
inputMode = (inputMode == INPUT_MODE_CLOCK) ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
324-
updateInputMode(modeButton);
325-
}
321+
v -> {
322+
inputMode = (inputMode == INPUT_MODE_CLOCK) ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
323+
updateInputMode(modeButton);
326324
});
327325

328326
return root;
@@ -563,14 +561,11 @@ public static final class Builder {
563561
private TimeModel time = new TimeModel();
564562

565563
@Nullable private Integer inputMode;
566-
@StringRes
567-
private int titleTextResId = 0;
564+
@StringRes private int titleTextResId = 0;
568565
private CharSequence titleText;
569-
@StringRes
570-
private int positiveButtonTextResId = 0;
566+
@StringRes private int positiveButtonTextResId = 0;
571567
private CharSequence positiveButtonText;
572-
@StringRes
573-
private int negativeButtonTextResId = 0;
568+
@StringRes private int negativeButtonTextResId = 0;
574569
private CharSequence negativeButtonText;
575570
private int overrideThemeResId = 0;
576571

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2025 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<resources>
19+
<bool name="timepicker_force_input_mode_keyboard">false</bool>
20+
</resources>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2025 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<resources>
19+
<bool name="timepicker_force_input_mode_keyboard">true</bool>
20+
</resources>

0 commit comments

Comments
 (0)