Skip to content

Commit 3625174

Browse files
kendrickumstattdhunterstich
authored andcommitted
[TimePicker] Add toggle button, split button, and time picker AM/PM sound effects.
These were not present because the sound effect is only automatically triggered on click, not on checked state. PiperOrigin-RevId: 774911150
1 parent 60b0325 commit 3625174

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.text.TextUtils.TruncateAt;
2626
import android.util.AttributeSet;
2727
import android.util.Log;
28+
import android.view.SoundEffectConstants;
2829
import android.view.View;
2930
import android.view.ViewGroup;
3031
import android.view.accessibility.AccessibilityNodeInfo;
@@ -534,6 +535,7 @@ void onButtonCheckedStateChanged(@NonNull MaterialButton button, boolean isCheck
534535
if (skipCheckedStateTracker) {
535536
return;
536537
}
538+
button.playSoundEffect(SoundEffectConstants.CLICK);
537539
checkInternal(button.getId(), isChecked);
538540
}
539541
}

lib/java/com/google/android/material/button/MaterialSplitButton.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;
2222

2323
import android.content.Context;
24-
import android.os.Build.VERSION;
25-
import android.os.Build.VERSION_CODES;
2624
import android.util.AttributeSet;
25+
import android.view.SoundEffectConstants;
2726
import android.view.View;
2827
import android.view.ViewGroup;
2928
import android.widget.Button;
3029
import androidx.annotation.NonNull;
3130
import androidx.annotation.Nullable;
31+
import androidx.core.view.ViewCompat;
3232

3333
/**
3434
* A container for two {@link MaterialButton}s that together create a split button. The {@link
@@ -108,24 +108,28 @@ public void addView(@NonNull View child, int index, @Nullable ViewGroup.LayoutPa
108108
if (indexOfChild(child) == 1) {
109109
buttonChild.setCheckable(true);
110110
buttonChild.setA11yClassName(Button.class.getName());
111-
if (VERSION.SDK_INT >= VERSION_CODES.R) {
112-
// Set initial content description based on checked state when focused.
113-
buttonChild.setStateDescription(
114-
getResources()
115-
.getString(
116-
buttonChild.isChecked()
117-
? R.string.mtrl_button_expanded_content_description
118-
: R.string.mtrl_button_collapsed_content_description));
111+
// Set initial content description based on checked state when focused.
112+
ViewCompat.setStateDescription(
113+
buttonChild,
114+
getResources()
115+
.getString(
116+
buttonChild.isChecked()
117+
? R.string.mtrl_button_expanded_content_description
118+
: R.string.mtrl_button_collapsed_content_description));
119119

120-
buttonChild.addOnCheckedChangeListener(
121-
(button, isChecked) ->
122-
button.setStateDescription(
123-
getResources()
124-
.getString(
125-
isChecked
126-
? R.string.mtrl_button_expanded_content_description
127-
: R.string.mtrl_button_collapsed_content_description)));
128-
}
120+
buttonChild.addOnCheckedChangeListener(
121+
(button, isChecked) -> {
122+
// Play sound effect when checked state changes.
123+
button.playSoundEffect(SoundEffectConstants.CLICK);
124+
// Update content description when checked state changes.
125+
ViewCompat.setStateDescription(
126+
buttonChild,
127+
getResources()
128+
.getString(
129+
isChecked
130+
? R.string.mtrl_button_expanded_content_description
131+
: R.string.mtrl_button_collapsed_content_description));
132+
});
129133
}
130134
}
131135
}

0 commit comments

Comments
 (0)