List of usage examples for android.media AudioManager playSoundEffect
public void playSoundEffect(int effectType)
From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java
/** * Handle the tap event from the touchpad. *//*from w w w. j av a 2 s . c o m*/ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { // Handle tap events. case KeyEvent.KEYCODE_DPAD_CENTER: //case KeyEvent.KEYCODE_ENTER: AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); _speech.speak("The weather is" + mCurrent + "Fahrenheit and" + mDescription, TextToSpeech.QUEUE_FLUSH, null); Bitmap bitmap = loadImageFromURL("http://openweathermap.org/img/w/10d.png"); _weatherIconImageView.setImageBitmap(bitmap); return true; default: return super.onKeyDown(keyCode, event); } }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
private void onKeyUpPanel(int featureId, KeyEvent event) { if (mActionMode != null) { return;// w w w. j ava 2 s .c om } boolean playSoundEffect = false; final PanelFeatureState st = getPanelState(featureId, true); if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu() && !ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(mContext))) { if (!mDecorContentParent.isOverflowMenuShowing()) { if (!isDestroyed() && preparePanel(st, event)) { playSoundEffect = mDecorContentParent.showOverflowMenu(); } } else { playSoundEffect = mDecorContentParent.hideOverflowMenu(); } } else { if (st.isOpen || st.isHandled) { // Play the sound effect if the user closed an open menu (and not if // they just released a menu shortcut) playSoundEffect = st.isOpen; // Close menu closePanel(st, true); } else if (st.isPrepared) { boolean show = true; if (st.refreshMenuContent) { // Something may have invalidated the menu since we prepared it. // Re-prepare it to refresh. st.isPrepared = false; show = preparePanel(st, event); } if (show) { // Show menu openPanel(st, event); playSoundEffect = true; } } } if (playSoundEffect) { AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (audioManager != null) { audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); } else { Log.w(TAG, "Couldn't get audio manager"); } } }
From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java
private boolean onKeyUpPanel(int featureId, KeyEvent event) { if (mActionMode != null) { return false; }/*from ww w . ja v a 2s . c om*/ boolean handled = false; final PanelFeatureState st = getPanelState(featureId, true); if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu() && !ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(mContext))) { if (!mDecorContentParent.isOverflowMenuShowing()) { if (!isDestroyed() && preparePanel(st, event)) { handled = mDecorContentParent.showOverflowMenu(); } } else { handled = mDecorContentParent.hideOverflowMenu(); } } else { if (st.isOpen || st.isHandled) { // Play the sound effect if the user closed an open menu (and not if // they just released a menu shortcut) handled = st.isOpen; // Close menu closePanel(st, true); } else if (st.isPrepared) { boolean show = true; if (st.refreshMenuContent) { // Something may have invalidated the menu since we prepared it. // Re-prepare it to refresh. st.isPrepared = false; show = preparePanel(st, event); } if (show) { // Show menu openPanel(st, event); handled = true; } } } if (handled) { AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (audioManager != null) { audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); } else { Log.w(TAG, "Couldn't get audio manager"); } } return handled; }