From d4e7790fee10e21b41a1c387c2734722bda56a0b Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 27 Oct 2014 17:50:51 -0700 Subject: Play CLICK sound effect when compound buttons are clicked Also plays the sound effect when the switch changes state as a result of dragging, since that's effectively the same as the click action. BUG: 16308311 Change-Id: Ic187ece2a8190082617f5ac7aaf05c3511fa80b5 --- core/java/android/widget/CompoundButton.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'core/java/android/widget/CompoundButton.java') diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java index 7d9d3052fe22..092e31c5a6b4 100644 --- a/core/java/android/widget/CompoundButton.java +++ b/core/java/android/widget/CompoundButton.java @@ -29,6 +29,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; import android.view.Gravity; +import android.view.SoundEffectConstants; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; @@ -114,15 +115,16 @@ public abstract class CompoundButton extends Button implements Checkable { @Override public boolean performClick() { - /* - * XXX: These are tiny, need some surrounding 'expanded touch area', - * which will need to be implemented in Button if we only override - * performClick() - */ - - /* When clicked, toggle the state */ toggle(); - return super.performClick(); + + final boolean handled = super.performClick(); + if (!handled) { + // View only makes a sound effect if the onClickListener was + // called, so we'll need to make one here instead. + playSoundEffect(SoundEffectConstants.CLICK); + } + + return handled; } @ViewDebug.ExportedProperty -- cgit v1.2.3