[TimePicker] Default to text input mode in landscape

PiperOrigin-RevId: 775714779
This commit is contained in:
pfthomas 2025-06-25 16:09:23 +00:00 committed by Hunter Stich
parent 5853d725fa
commit dcfe2ee9ee
3 changed files with 55 additions and 20 deletions

View File

@ -248,7 +248,11 @@ public final class MaterialTimePicker extends DialogFragment implements OnDouble
if (time == null) {
time = new TimeModel();
}
int defaultInputMode = time.format == CLOCK_24H ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
boolean forceKeyboardInputMode =
getResources().getBoolean(R.bool.timepicker_force_input_mode_keyboard);
int defaultInputMode =
forceKeyboardInputMode || time.format == CLOCK_24H ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
inputMode = bundle.getInt(INPUT_MODE_EXTRA, defaultInputMode);
titleResId = bundle.getInt(TITLE_RES_EXTRA, 0);
titleText = bundle.getCharSequence(TITLE_TEXT_EXTRA);
@ -299,14 +303,11 @@ public final class MaterialTimePicker extends DialogFragment implements OnDouble
cancelButton = root.findViewById(R.id.material_timepicker_cancel_button);
cancelButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
for (OnClickListener listener : negativeButtonListeners) {
listener.onClick(v);
}
dismiss();
v -> {
for (OnClickListener listener : negativeButtonListeners) {
listener.onClick(v);
}
dismiss();
});
if (negativeButtonTextResId != 0) {
cancelButton.setText(negativeButtonTextResId);
@ -317,12 +318,9 @@ public final class MaterialTimePicker extends DialogFragment implements OnDouble
updateCancelButtonVisibility();
modeButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
inputMode = (inputMode == INPUT_MODE_CLOCK) ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
updateInputMode(modeButton);
}
v -> {
inputMode = (inputMode == INPUT_MODE_CLOCK) ? INPUT_MODE_KEYBOARD : INPUT_MODE_CLOCK;
updateInputMode(modeButton);
});
return root;
@ -563,14 +561,11 @@ public final class MaterialTimePicker extends DialogFragment implements OnDouble
private TimeModel time = new TimeModel();
@Nullable private Integer inputMode;
@StringRes
private int titleTextResId = 0;
@StringRes private int titleTextResId = 0;
private CharSequence titleText;
@StringRes
private int positiveButtonTextResId = 0;
@StringRes private int positiveButtonTextResId = 0;
private CharSequence positiveButtonText;
@StringRes
private int negativeButtonTextResId = 0;
@StringRes private int negativeButtonTextResId = 0;
private CharSequence negativeButtonText;
private int overrideThemeResId = 0;

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2025 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources>
<bool name="timepicker_force_input_mode_keyboard">false</bool>
</resources>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2025 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources>
<bool name="timepicker_force_input_mode_keyboard">true</bool>
</resources>