Play sound on ACTION_DOWN for navigation keys
am: 05bce15da9
Change-Id: I99ee8746b710c131dcd781a1623aa3b5edbbc84d
This commit is contained in:
@@ -59,6 +59,7 @@ public class KeyButtonView extends ImageView implements ButtonDispatcher.ButtonI
|
|||||||
private AudioManager mAudioManager;
|
private AudioManager mAudioManager;
|
||||||
private boolean mGestureAborted;
|
private boolean mGestureAborted;
|
||||||
private boolean mLongClicked;
|
private boolean mLongClicked;
|
||||||
|
private OnClickListener mOnClickListener;
|
||||||
|
|
||||||
private final Runnable mCheckLongPress = new Runnable() {
|
private final Runnable mCheckLongPress = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -109,6 +110,12 @@ public class KeyButtonView extends ImageView implements ButtonDispatcher.ButtonI
|
|||||||
mCode = code;
|
mCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnClickListener(OnClickListener onClickListener) {
|
||||||
|
super.setOnClickListener(onClickListener);
|
||||||
|
mOnClickListener = onClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
public void loadAsync(String uri) {
|
public void loadAsync(String uri) {
|
||||||
new AsyncTask<String, Void, Drawable>() {
|
new AsyncTask<String, Void, Drawable>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -190,6 +197,7 @@ public class KeyButtonView extends ImageView implements ButtonDispatcher.ButtonI
|
|||||||
// Provide the same haptic feedback that the system offers for virtual keys.
|
// Provide the same haptic feedback that the system offers for virtual keys.
|
||||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||||
}
|
}
|
||||||
|
playSoundEffect(SoundEffectConstants.CLICK);
|
||||||
removeCallbacks(mCheckLongPress);
|
removeCallbacks(mCheckLongPress);
|
||||||
postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
|
postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
|
||||||
break;
|
break;
|
||||||
@@ -215,14 +223,14 @@ public class KeyButtonView extends ImageView implements ButtonDispatcher.ButtonI
|
|||||||
if (doIt) {
|
if (doIt) {
|
||||||
sendEvent(KeyEvent.ACTION_UP, 0);
|
sendEvent(KeyEvent.ACTION_UP, 0);
|
||||||
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
|
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
|
||||||
playSoundEffect(SoundEffectConstants.CLICK);
|
|
||||||
} else {
|
} else {
|
||||||
sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
|
sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no key code, just a regular ImageView
|
// no key code, just a regular ImageView
|
||||||
if (doIt) {
|
if (doIt && mOnClickListener != null) {
|
||||||
performClick();
|
mOnClickListener.onClick(this);
|
||||||
|
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeCallbacks(mCheckLongPress);
|
removeCallbacks(mCheckLongPress);
|
||||||
|
|||||||
Reference in New Issue
Block a user