Permalink
Browse files

SmartBar: Touch sound support

Because it is the right thing to do

Change-Id: I5e300e33eea532a3d8f19d6c67fe27fffe6125f0
  • Loading branch information...
bigrushdog authored and akhilnarang committed Jun 2, 2017
1 parent 1ee0a94 commit 51897e4ea5879f7f3d21eefec222ef7d55d0955b
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/com/android/systemui/navigation/smartbar/SmartButtonView.java
@@ -30,13 +30,16 @@
import com.facebook.rebound.SpringListener;
import android.animation.ObjectAnimator;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.text.TextUtils;
import android.util.AttributeSet;
//import android.content.res.ThemeConfig;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
@@ -75,6 +78,13 @@
private SmartBarView mHost;
View.OnLongClickListener mLongPressBackListener;
static AudioManager mAudioManager;
static AudioManager getAudioManager(Context context) {
if (mAudioManager == null)
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
return mAudioManager;
}
private Spring mSpring;
private SpringListener mSpringListener = new SpringListener() {
@@ -112,6 +122,7 @@ public SmartButtonView(Context context, AttributeSet attrs, int defStyleAttr, in
super(context, attrs, defStyleAttr, defStyleRes);
setClickable(true);
setLongClickable(false);
mAudioManager = getAudioManager(context);
}
public void setHost(SmartBarView host) {
@@ -321,6 +332,7 @@ public boolean onTouchEvent(MotionEvent ev) {
mSpring.setEndValue(1f);
}
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
playSoundEffect(SoundEffectConstants.CLICK);
if (isDoubleTapPending) {
isDoubleTapPending = false;
wasConsumed = true;
@@ -395,13 +407,15 @@ private void doLongPress() {
wasConsumed = true;
if (mScreenPinningEnabled && mLongPressBackListener != null) {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
playSoundEffect(SoundEffectConstants.CLICK);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
mLongPressBackListener.onLongClick(this);
} else {
if (mConfig != null) {
String action = mConfig.getActionConfig(ActionConfig.SECOND).getAction();
fireActionIfSecure(action);
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
playSoundEffect(SoundEffectConstants.CLICK);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
}
}
@@ -435,4 +449,8 @@ public void run() {
}
}
};
public void playSoundEffect(int soundConstant) {
mAudioManager.playSoundEffect(soundConstant, ActivityManager.getCurrentUser());
};
}

0 comments on commit 51897e4

Please sign in to comment.