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
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.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 @@
// 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 @@
newState = getTargetCheckedState();
}
} else {
- newState = isChecked();
+ newState = oldState;
}
- setChecked(newState);
+ if (newState != oldState) {
+ playSoundEffect(SoundEffectConstants.CLICK);
+ setChecked(newState);
+ }
+
cancelSuperTouch(ev);
}