diff options
author | Alan Viverette <alanv@google.com> | 2014-10-27 17:50:51 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-10-27 17:50:51 -0700 |
commit | d4e7790fee10e21b41a1c387c2734722bda56a0b (patch) | |
tree | 3805b8ed6cc692ce517fb4c581444af40506675e /core/java/android/widget | |
parent | e8d9810cdef5b3e288f54f42adc3205532343406 (diff) | |
download | frameworks_base-d4e7790fee10e21b41a1c387c2734722bda56a0b.zip frameworks_base-d4e7790fee10e21b41a1c387c2734722bda56a0b.tar.gz frameworks_base-d4e7790fee10e21b41a1c387c2734722bda56a0b.tar.bz2 |
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
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/CompoundButton.java | 18 | ||||
-rw-r--r-- | core/java/android/widget/Switch.java | 10 |
2 files changed, 18 insertions, 10 deletions
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java index 7d9d305..092e31c 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 diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java index a898084..4c8aa51 100644 --- a/core/java/android/widget/Switch.java +++ b/core/java/android/widget/Switch.java @@ -39,6 +39,7 @@ import android.util.FloatProperty; import android.util.MathUtils; import android.view.Gravity; import android.view.MotionEvent; +import android.view.SoundEffectConstants; import android.view.VelocityTracker; import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; @@ -797,6 +798,7 @@ public class Switch extends CompoundButton { // Commit the change if the event is up and not canceled and the switch // has not been disabled during the drag. final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled(); + final boolean oldState = isChecked(); final boolean newState; if (commitChange) { mVelocityTracker.computeCurrentVelocity(1000); @@ -807,10 +809,14 @@ public class Switch extends CompoundButton { newState = getTargetCheckedState(); } } else { - newState = isChecked(); + newState = oldState; + } + + if (newState != oldState) { + playSoundEffect(SoundEffectConstants.CLICK); + setChecked(newState); } - setChecked(newState); cancelSuperTouch(ev); } |