List of usage examples for android.content Context AUDIO_SERVICE
String AUDIO_SERVICE
To view the source code for android.content Context AUDIO_SERVICE.
Click Source Link
From source file:github.madmarty.madsonic.util.Util.java
@TargetApi(8) public static void requestAudioFocus(final Context context) { if (Build.VERSION.SDK_INT >= 8 && !hasFocus) { final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); hasFocus = true;// w w w .j a v a 2s .co m audioManager.requestAudioFocus(new OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { DownloadServiceImpl downloadService = (DownloadServiceImpl) context; if ((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !downloadService.isJukeboxEnabled()) { if (downloadService.getPlayerState() == PlayerState.STARTED) { SharedPreferences prefs = getPreferences(context); int lossPref = Integer .parseInt(prefs.getString(Constants.PREFERENCES_KEY_AUDIO_FOCUS, "1")); if (lossPref == 2 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)) { lowerFocus = true; downloadService.setVolume(0.1f); } else if (lossPref == 0 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)) { pauseFocus = true; downloadService.pause(); } } } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { if (pauseFocus) { pauseFocus = false; downloadService.start(); } else if (lowerFocus) { lowerFocus = false; downloadService.setVolume(1.0f); } } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS && !downloadService.isJukeboxEnabled()) { hasFocus = false; downloadService.pause(); audioManager.abandonAudioFocus(this); } } }, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates a system notification./* w w w . j a v a 2 s.c o m*/ * * @param context Context. * @param notSound Enable or disable the sound * @param notSoundRawId Custom raw sound id. If enabled and not set * default notification sound will be used. Set to -1 to * default system notification. * @param multipleNot Setting to True allows showing multiple notifications. * @param groupMultipleNotKey If is set, multiple notifications can be grupped by this key. * @param notAction Action for this notification * @param notTitle Title * @param notMessage Message * @param notClazz Class to be executed * @param extras Extra information * */ public static void notification_generate(Context context, boolean notSound, int notSoundRawId, boolean multipleNot, String groupMultipleNotKey, String notAction, String notTitle, String notMessage, Class<?> notClazz, Bundle extras, boolean wakeUp) { try { int iconResId = notification_getApplicationIcon(context); long when = System.currentTimeMillis(); Notification notification = new Notification(iconResId, notMessage, when); // Hide the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL; if (notSound) { if (notSoundRawId > 0) { try { notification.sound = Uri.parse("android.resource://" + context.getApplicationContext().getPackageName() + "/" + notSoundRawId); } catch (Exception e) { if (LOG_ENABLE) { Log.w(TAG, "Custom sound " + notSoundRawId + "could not be found. Using default."); } notification.defaults |= Notification.DEFAULT_SOUND; notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } else { notification.defaults |= Notification.DEFAULT_SOUND; notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } Intent notificationIntent = new Intent(context, notClazz); notificationIntent.setAction(notClazz.getName() + "." + notAction); if (extras != null) { notificationIntent.putExtras(extras); } //Set intent so it does not start a new activity // //Notes: // - The flag FLAG_ACTIVITY_SINGLE_TOP makes that only one instance of the activity exists(each time the // activity is summoned no onCreate() method is called instead, onNewIntent() is called. // - If we use FLAG_ACTIVITY_CLEAR_TOP it will make that the last "snapshot"/TOP of the activity it will // be this called this intent. We do not want this because the HOME button will call this "snapshot". // To avoid this behaviour we use FLAG_ACTIVITY_BROUGHT_TO_FRONT that simply takes to foreground the // activity. // //See http://developer.android.com/reference/android/content/Intent.html notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); int REQUEST_UNIQUE_ID = 0; if (multipleNot) { if (groupMultipleNotKey != null && groupMultipleNotKey.length() > 0) { REQUEST_UNIQUE_ID = groupMultipleNotKey.hashCode(); } else { if (random == null) { random = new Random(); } REQUEST_UNIQUE_ID = random.nextInt(); } PendingIntent.getActivity(context, REQUEST_UNIQUE_ID, notificationIntent, PendingIntent.FLAG_ONE_SHOT); } notification.setLatestEventInfo(context, notTitle, notMessage, intent); //This makes the device to wake-up is is idle with the screen off. if (wakeUp) { powersaving_wakeUp(context); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //We check if the sound is disabled to enable just for a moment AudioManager amanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int previousAudioMode = amanager.getRingerMode(); ; if (notSound && previousAudioMode != AudioManager.RINGER_MODE_NORMAL) { amanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } notificationManager.notify(REQUEST_UNIQUE_ID, notification); //We restore the sound setting if (previousAudioMode != AudioManager.RINGER_MODE_NORMAL) { //We wait a little so sound is played try { Thread.sleep(3000); } catch (Exception e) { } } amanager.setRingerMode(previousAudioMode); Log.d(TAG, "Android Notification created."); } catch (Exception e) { if (LOG_ENABLE) Log.e(TAG, "The notification could not be created (" + e.getMessage() + ")", e); } }
From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java
private void dialNumber(String phoneNumber, boolean isSpeakon) { Context context = getApplicationContext(); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); Constants.log(TAG_NAME, String.format("Dial phone:%s", phoneNumber)); // ??//from ww w . j a v a2 s . com Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(String.format("tel:%s", phoneNumber))); callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); callIntent.addFlags(Intent.FLAG_FROM_BACKGROUND); startActivity(callIntent); if (!(audioManager.isWiredHeadsetOn() || audioManager.isBluetoothA2dpOn())) { // 4.1??? 4.1??Permission Denial: not allowed to // send broadcast android.intent.action.HEADSET_PLUG from pid=1324, // uid=10017 // ??????android.permission.CALL_PRIVLEGED?????4.1??????????NULL?? Constants.log("speakerset", String.format("AudioManager before mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); if (isSpeakon) { try { Thread.sleep(500); } catch (InterruptedException e) { Constants.log("speakerset", "Problem while sleeping"); } Constants.log("speakerset", String.format("AudioManager answer mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); while (audioManager.getMode() != AudioManager.MODE_IN_CALL) { try { Thread.sleep(300); } catch (InterruptedException e) { Constants.log("speakerset", "Problem while sleeping"); } } // audioManager.setMicrophoneMute(true); audioManager.setSpeakerphoneOn(true); // audioManager.setMode(AudioManager.MODE_IN_CALL); Constants.log("speakerset", String.format("AudioManager set mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); } } }
From source file:com.android.messaging.datamodel.BugleNotifications.java
/** * Play the observable conversation notification sound (it's the regular notification sound, but * played at half-volume)/*from ww w.jav a 2s . com*/ */ private static void playObservableConversationNotificationSound(final Uri ringtoneUri) { final Context context = Factory.get().getApplicationContext(); final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); final boolean silenced = audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; if (silenced) { return; } final NotificationPlayer player = new NotificationPlayer(LogUtil.BUGLE_TAG); player.play(ringtoneUri, false, AudioManager.STREAM_NOTIFICATION, OBSERVABLE_CONVERSATION_NOTIFICATION_VOLUME); // Stop the sound after five seconds to handle continuous ringtones ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() { @Override public void run() { player.stop(); } }, 5000); }
From source file:org.drrickorang.loopback.LoopbackActivity.java
/** Save a .txt file of various test results. */ void saveReport(Uri uri) { ParcelFileDescriptor parcelFileDescriptor = null; FileOutputStream outputStream; try {//from w w w .j av a2 s . c om parcelFileDescriptor = getApplicationContext().getContentResolver().openFileDescriptor(uri, "w"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); outputStream = new FileOutputStream(fileDescriptor); log("Done creating output stream"); String endline = "\n"; final int stringLength = 300; StringBuilder sb = new StringBuilder(stringLength); sb.append("DateTime = " + mCurrentTime + endline); sb.append(INTENT_SAMPLING_FREQUENCY + " = " + getApp().getSamplingRate() + endline); sb.append(INTENT_RECORDER_BUFFER + " = " + getApp().getRecorderBufferSizeInBytes() / Constant.BYTES_PER_FRAME + endline); sb.append(INTENT_PLAYER_BUFFER + " = " + getApp().getPlayerBufferSizeInBytes() / Constant.BYTES_PER_FRAME + endline); sb.append(INTENT_AUDIO_THREAD + " = " + getApp().getAudioThreadType() + endline); int micSource = getApp().getMicSource(); String audioType = "unknown"; switch (getApp().getAudioThreadType()) { case Constant.AUDIO_THREAD_TYPE_JAVA: audioType = "JAVA"; break; case Constant.AUDIO_THREAD_TYPE_NATIVE: audioType = "NATIVE"; break; } sb.append(INTENT_AUDIO_THREAD + "_String = " + audioType + endline); sb.append(INTENT_MIC_SOURCE + " = " + micSource + endline); sb.append(INTENT_MIC_SOURCE + "_String = " + getApp().getMicSourceString(micSource) + endline); AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC); sb.append(INTENT_AUDIO_LEVEL + " = " + currentVolume + endline); switch (mTestType) { case Constant.LOOPBACK_PLUG_AUDIO_THREAD_TEST_TYPE_LATENCY: if (mCorrelation.mEstimatedLatencyMs > 0.0001) { sb.append(String.format("LatencyMs = %.2f", mCorrelation.mEstimatedLatencyMs) + endline); } else { sb.append(String.format("LatencyMs = unknown") + endline); } sb.append(String.format("LatencyConfidence = %.2f", mCorrelation.mEstimatedLatencyConfidence) + endline); break; case Constant.LOOPBACK_PLUG_AUDIO_THREAD_TEST_TYPE_BUFFER_PERIOD: sb.append("Buffer Test Duration (s) = " + mBufferTestDuration + endline); // report expected recorder buffer period int expectedRecorderBufferPeriod = mRecorderBufferSizeInBytes / Constant.BYTES_PER_FRAME * Constant.MILLIS_PER_SECOND / mSamplingRate; sb.append("Expected Recorder Buffer Period (ms) = " + expectedRecorderBufferPeriod + endline); // report recorder results int recorderBufferSize = mRecorderBufferSizeInBytes / Constant.BYTES_PER_FRAME; int[] recorderBufferData = null; int recorderBufferDataMax = 0; switch (mAudioThreadType) { case Constant.AUDIO_THREAD_TYPE_JAVA: recorderBufferData = mRecorderBufferPeriod.getBufferPeriodArray(); recorderBufferDataMax = mRecorderBufferPeriod.getMaxBufferPeriod(); break; case Constant.AUDIO_THREAD_TYPE_NATIVE: recorderBufferData = mNativeRecorderBufferPeriodArray; recorderBufferDataMax = mNativeRecorderMaxBufferPeriod; break; } if (recorderBufferData != null) { // this is the range of data that actually has values int usefulDataRange = Math.min(recorderBufferDataMax + 1, recorderBufferData.length); int[] usefulBufferData = Arrays.copyOfRange(recorderBufferData, 0, usefulDataRange); PerformanceMeasurement measurement = new PerformanceMeasurement(recorderBufferSize, mSamplingRate, usefulBufferData); boolean isBufferSizesMismatch = measurement.determineIsBufferSizesMatch(); double benchmark = measurement.computeWeightedBenchmark(); int outliers = measurement.countOutliers(); sb.append("Recorder Buffer Sizes Mismatch = " + isBufferSizesMismatch + endline); sb.append("Recorder Benchmark = " + benchmark + endline); sb.append("Recorder Number of Outliers = " + outliers + endline); } else { sb.append("Cannot Find Recorder Buffer Period Data!" + endline); } // report player results int playerBufferSize = mPlayerBufferSizeInBytes / Constant.BYTES_PER_FRAME; int[] playerBufferData = null; int playerBufferDataMax = 0; switch (mAudioThreadType) { case Constant.AUDIO_THREAD_TYPE_JAVA: playerBufferData = mPlayerBufferPeriod.getBufferPeriodArray(); playerBufferDataMax = mPlayerBufferPeriod.getMaxBufferPeriod(); break; case Constant.AUDIO_THREAD_TYPE_NATIVE: playerBufferData = mNativePlayerBufferPeriodArray; playerBufferDataMax = mNativePlayerMaxBufferPeriod; break; } if (playerBufferData != null) { // this is the range of data that actually has values int usefulDataRange = Math.min(playerBufferDataMax + 1, playerBufferData.length); int[] usefulBufferData = Arrays.copyOfRange(playerBufferData, 0, usefulDataRange); PerformanceMeasurement measurement = new PerformanceMeasurement(playerBufferSize, mSamplingRate, usefulBufferData); boolean isBufferSizesMismatch = measurement.determineIsBufferSizesMatch(); double benchmark = measurement.computeWeightedBenchmark(); int outliers = measurement.countOutliers(); sb.append("Player Buffer Sizes Mismatch = " + isBufferSizesMismatch + endline); sb.append("Player Benchmark = " + benchmark + endline); sb.append("Player Number of Outliers = " + outliers + endline); } else { sb.append("Cannot Find Player Buffer Period Data!" + endline); } // report expected player buffer period int expectedPlayerBufferPeriod = mPlayerBufferSizeInBytes / Constant.BYTES_PER_FRAME * Constant.MILLIS_PER_SECOND / mSamplingRate; if (audioType.equals("JAVA")) { // javaPlayerMultiple depends on the samples written per AudioTrack.write() int javaPlayerMultiple = 2; expectedPlayerBufferPeriod *= javaPlayerMultiple; } sb.append("Expected Player Buffer Period (ms) = " + expectedPlayerBufferPeriod + endline); // report estimated number of glitches int numberOfGlitches = estimateNumberOfGlitches(mGlitchesData); sb.append("Estimated Number of Glitches = " + numberOfGlitches + endline); // report if the total glitching interval is too long sb.append("Total glitching interval too long: " + mGlitchingIntervalTooLong + endline); } String info = getApp().getSystemInfo(); sb.append("SystemInfo = " + info + endline); outputStream.write(sb.toString().getBytes()); parcelFileDescriptor.close(); } catch (Exception e) { log("Failed to open text file " + e); } finally { try { if (parcelFileDescriptor != null) { parcelFileDescriptor.close(); } } catch (Exception e) { e.printStackTrace(); log("Error closing ParcelFile Descriptor"); } } }
From source file:github.popeen.dsub.service.DownloadService.java
public synchronized void setPlayerState(final PlayerState playerState) { Log.i(TAG, this.playerState.name() + " -> " + playerState.name() + " (" + currentPlaying + ")"); if (playerState == PAUSED) { lifecycleSupport.serializeDownloadQueue(); if (!isPastCutoff()) { checkAddBookmark(true);// w w w.j ava 2 s .co m } } boolean show = playerState == PlayerState.STARTED; boolean pause = playerState == PlayerState.PAUSED; boolean hide = playerState == PlayerState.STOPPED; Util.broadcastPlaybackStatusChange(this, (currentPlaying != null) ? currentPlaying.getSong() : null, playerState); this.playerState = playerState; if (playerState == STARTED) { AudioManager audioManager = (AudioManager) getApplicationContext() .getSystemService(Context.AUDIO_SERVICE); Util.requestAudioFocus(this, audioManager); } if (show) { Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong()); } else if (pause) { SharedPreferences prefs = Util.getPreferences(this); if (prefs.getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) { Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong()); } else { Notifications.hidePlayingNotification(this, this, handler); } } else if (hide) { Notifications.hidePlayingNotification(this, this, handler); } if (mRemoteControl != null) { mRemoteControl.setPlaybackState(playerState.getRemoteControlClientPlayState(), getCurrentPlayingIndex(), size()); } if (playerState == STARTED) { scrobbler.scrobble(this, currentPlaying, false, false); } else if (playerState == COMPLETED) { scrobbler.scrobble(this, currentPlaying, true, true); } if (playerState == STARTED && positionCache == null) { if (remoteState == LOCAL) { positionCache = new LocalPositionCache(); } else { positionCache = new PositionCache(); } Thread thread = new Thread(positionCache, "PositionCache"); thread.start(); } else if (playerState != STARTED && positionCache != null) { positionCache.stop(); positionCache = null; } if (remoteState != LOCAL) { if (playerState == STARTED) { if (!wifiLock.isHeld()) { wifiLock.acquire(); } } else if (playerState == PAUSED && wifiLock.isHeld()) { wifiLock.release(); } } if (remoteController != null && remoteController.isNextSupported()) { if (playerState == PREPARING || playerState == IDLE) { nextPlayerState = IDLE; } } onStateUpdate(); }
From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java
private boolean onKeyUpPanel(int featureId, KeyEvent event) { if (mActionMode != null) { return false; }//from w ww . j a v a2 s . 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; }
From source file:github.daneren2005.dsub.service.DownloadService.java
public void updateRemoteVolume(boolean up) { AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustVolume(up ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);//w w w . j av a 2s . co m }
From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java
public void readPrefs() { String valueTmp = ""; try {/*from w w w. j ava 2 s.c om*/ voltage_speech_alert = mPrefs.getString("voltage_speech_alert", voltage_speech_alert); height_speech_alert = mPrefs.getString("height_speech_alert", height_speech_alert); current_speech_alert = mPrefs.getString("current_speech_alert", current_speech_alert); used_speech_alert = mPrefs.getString("used_speech_alert", used_speech_alert); temp_speech_alert = mPrefs.getString("temp_speech_alert", temp_speech_alert); rpm_speech_alert = mPrefs.getString("rpm_speech_alert", rpm_speech_alert); speed_speech_alert = mPrefs.getString("speed_speech_alert", speed_speech_alert); mVoltageAlarm = getDouble("voltage", mVoltageAlarm); mUsedCap = getDouble("used_cap", mUsedCap); mCurrentAlarm = getDouble("current", mCurrentAlarm); mPowerAlarm = getDouble("power", mPowerAlarm); mSpeedAlarm = tools.getInteger("speed", mSpeedAlarm, mPrefs); // mSpeedAlarm = getInteger("speed", mSpeedAlarm); mRpmAlarm = getInteger("rpm", mRpmAlarm); mAltitudeAlarm = getInteger("altitude", mAltitudeAlarm); mFuelAlarm = getInteger("fuel", mFuelAlarm); voltage_hysteresis = getInteger("voltage_hysteresis", voltage_hysteresis); current_hysteresis = getInteger("current_hysteresis", current_hysteresis); rpm_hysteresis = getInteger("rpm_hysteresis", rpm_hysteresis); temperature_hysteresis = getInteger("temperature_hysteresis", temperature_hysteresis); power_hysteresis = getInteger("power_hysteresis", power_hysteresis); mTemperatureAlarm = getInteger("temperature", mTemperatureAlarm); speech_volume = getInteger("speech_volume", speech_volume); AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int sb2value = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); sb2value = sb2value * speech_volume / 100; am.setStreamVolume(AudioManager.STREAM_MUSIC, sb2value, 0); vibrate_on = mPrefs.getBoolean("vibrate_on", vibrate_on); metric = mPrefs.getBoolean("metric", metric); mpxData = mPrefs.getBoolean("mpx_data", mpxData); displayAlwaysOn = mPrefs.getBoolean("displayAlwaysOn", displayAlwaysOn); voltage_speech_ack = mPrefs.getBoolean("voltage_speech_ack", voltage_speech_ack); valueTmp = voltage_speech_label + ";" + voltage_speech_unit; valueTmp = mPrefs.getString("voltage_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); voltage_speech_label = tokens.nextToken().trim(); voltage_speech_unit = tokens.nextToken().trim(); } height_speech_ack = mPrefs.getBoolean("height_speech_ack", height_speech_ack); auto_connect = mPrefs.getBoolean("auto_connect", auto_connect); mpxData = mPrefs.getBoolean("mpx_data", mpxData); valueTmp = height_speech_label + ";" + height_speech_unit; valueTmp = mPrefs.getString("height_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); height_speech_label = tokens.nextToken().trim(); height_speech_unit = tokens.nextToken().trim(); } current_speech_ack = mPrefs.getBoolean("current_speech_ack", current_speech_ack); valueTmp = current_speech_label + ";" + current_speech_unit; valueTmp = mPrefs.getString("current_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); current_speech_label = tokens.nextToken().trim(); current_speech_unit = tokens.nextToken().trim(); } used_speech_ack = mPrefs.getBoolean("used_speech_ack", used_speech_ack); valueTmp = used_speech_label + ";" + used_speech_unit; valueTmp = mPrefs.getString("used_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); used_speech_label = tokens.nextToken().trim(); used_speech_unit = tokens.nextToken().trim(); } speed_speech_ack = mPrefs.getBoolean("speed_speech_ack", speed_speech_ack); valueTmp = speed_speech_label + ";" + speed_speech_unit; valueTmp = mPrefs.getString("speed_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); speed_speech_label = tokens.nextToken().trim(); speed_speech_unit = tokens.nextToken().trim(); } vario_delay = mPrefs.getString("vario_delay", vario_delay); rpm_speech_ack = mPrefs.getBoolean("rpm_speech_ack", rpm_speech_ack); valueTmp = rpm_speech_label + ";" + rpm_speech_unit; valueTmp = mPrefs.getString("rpm_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); rpm_speech_label = tokens.nextToken().trim(); rpm_speech_unit = tokens.nextToken().trim(); } temp_speech_ack = mPrefs.getBoolean("temp_speech_ack", temp_speech_ack); valueTmp = temp_speech_label + ";" + temp_speech_unit; valueTmp = mPrefs.getString("temp_speech_text", valueTmp); if (!valueTmp.equals("") && valueTmp.contains(";")) { StringTokenizer tokens = new StringTokenizer(valueTmp, ";"); temp_speech_label = tokens.nextToken().trim(); temp_speech_unit = tokens.nextToken().trim(); } } catch (Exception e) { } valueTmp = mPrefs.getString("log_file", log_file); if (valueTmp != "") { log_file = valueTmp; } valueTmp = mPrefs.getString("bluetooth_device", bluetooth_device); if (valueTmp != "") { bluetooth_device = valueTmp; } mSound_on = mPrefs.getBoolean("sound_on", mSound_on); speech_on = mPrefs.getBoolean("speech_on", speech_on); speech_intervall = mPrefs.getString("speech_intervall", speech_intervall); speech_alert_intervall = mPrefs.getString("speech_alert_intervall", speech_alert_intervall); mAlarm_on = mPrefs.getBoolean("alarm_on", mAlarm_on); mSpeak_on = mPrefs.getBoolean("speak_on", mSpeak_on); mlog_file = mPrefs.getBoolean("logging_on", mlog_file); alert_tone = mPrefs.getString("ringtone", alert_tone); label_rpm1 = mPrefs.getString("label_rpm1", label_rpm1); label_rpm2 = mPrefs.getString("label_rpm2", label_rpm2); label_temp1 = mPrefs.getString("label_temp1", label_temp1); label_temp2 = mPrefs.getString("label_temp2", label_temp2); unit_rpm1 = mPrefs.getString("unit_rpm1", unit_rpm1); unit_rpm2 = mPrefs.getString("unit_rpm2", unit_rpm2); unit_temp1 = mPrefs.getString("unit_temp1", unit_temp1); unit_temp2 = mPrefs.getString("unit_temp2", unit_temp2); current_sensor_type = mPrefs.getString("current_sensor_type", current_sensor_type); vario_delay = mPrefs.getString("vario_delay", vario_delay); alarm_voltage = mPrefs.getBoolean("alarm_voltage", alarm_voltage); alarm_used = mPrefs.getBoolean("alarm_used", alarm_used); alarm_current = mPrefs.getBoolean("alarm_current", alarm_current); alarm_speed = mPrefs.getBoolean("alarm_speed", alarm_speed); alarm_fuel = mPrefs.getBoolean("alarm_fuel", alarm_fuel); alarm_temperature = mPrefs.getBoolean("alarm_temperature", alarm_temperature); alarm_altitude = mPrefs.getBoolean("alarm_altitude", alarm_altitude); alarm_rpm = mPrefs.getBoolean("alarm_rpm", alarm_rpm); alarm_power = mPrefs.getBoolean("alarm_power", alarm_power); speak_voltage = mPrefs.getBoolean("speak_voltage", speak_voltage); speak_used = mPrefs.getBoolean("speak_used", speak_used); speak_current = mPrefs.getBoolean("speak_current", speak_current); speak_speed = mPrefs.getBoolean("speak_speed", speak_speed); speak_fuel = mPrefs.getBoolean("speak_fuel", speak_fuel); speak_temperature = mPrefs.getBoolean("speak_temperature", speak_temperature); speak_altitude = mPrefs.getBoolean("speak_altitude", speak_altitude); speak_rpm = mPrefs.getBoolean("speak_rpm", speak_rpm); speak_power = mPrefs.getBoolean("speak_power", speak_power); if (rpm1Label != null) rpm1Label.setText(label_rpm1); if (rpm2Label != null) rpm2Label.setText(label_rpm2); if (tempLabel != null) tempLabel.setText(label_temp1); if (temp2Label != null) temp2Label.setText(label_temp2); if (rpm1_unit != null) rpm1_unit.setText(unit_rpm1); if (rpm2_unit != null) rpm2_unit.setText(unit_rpm2); if (temp1_unit != null) temp1_unit.setText(unit_temp1); if (temp1_unit != null) temp1_unit.setText(unit_temp2); if (alert_tone.equals("")) { uri = null; } else { uri = Uri.parse(alert_tone); } if (mp != null) { mp.stop(); mp.release(); mp = null; if (uri != null && !uri.toString().equals("res/raw/alarm.mp3")) { mp = MediaPlayer.create(getApplicationContext(), uri); } else { mp = MediaPlayer.create(getApplicationContext(), R.raw.alarm); } } }
From source file:com.ieeton.user.activity.ChatActivity.java
private void playSound() { AudioManager mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); int curVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM); if (curVolume == 0) { return;//from w w w .j a va2 s . co m } mSoundPool.play(mSoundID, curVolume, curVolume, 0, 0, 1); }