@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { if (TextUtils.isEmpty(stringValue)) { preference.setSummary(R.string.pref_ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { preference.setSummary(null); } else { String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else { preference.setSummary(stringValue); } return true; }
private void playSounds(boolean locked) { // User feedback for keyguard. if (mSuppressNextLockSound) { mSuppressNextLockSound = false; return; } final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { final String whichSound = locked ? Settings.System.LOCK_SOUND : Settings.System.UNLOCK_SOUND; final String soundPath = Settings.System.getString(cr, whichSound); if (soundPath != null) { final Uri soundUri = Uri.parse("file://" + soundPath); if (soundUri != null) { final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); if (sfx != null) { sfx.setStreamType(AudioManager.STREAM_SYSTEM); sfx.play(); } else { Log.d(TAG, "playSounds: failed to load ringtone from uri: " + soundUri); } } else { Log.d(TAG, "playSounds: could not parse Uri: " + soundPath); } } else { Log.d(TAG, "playSounds: whichSound = " + whichSound + "; soundPath was null"); } } }
public AlarmPreListAdap(Context context, Alarm alarm) { setContext(context); Log.d("AlarmPreListAdap", "Loading Ringtones..."); RingtoneManager ringtoneMgr = new RingtoneManager(getContext()); ringtoneMgr.setType(RingtoneManager.TYPE_ALARM); Cursor alarmsCursor = ringtoneMgr.getCursor(); alarmTones = new String[alarmsCursor.getCount() + 1]; alarmTones[0] = "Silent"; alarmTonePaths = new String[alarmsCursor.getCount() + 1]; alarmTonePaths[0] = ""; if (alarmsCursor.moveToFirst()) { do { alarmTones[alarmsCursor.getPosition() + 1] = ringtoneMgr.getRingtone(alarmsCursor.getPosition()).getTitle(getContext()); alarmTonePaths[alarmsCursor.getPosition() + 1] = ringtoneMgr.getRingtoneUri(alarmsCursor.getPosition()).toString(); } while (alarmsCursor.moveToNext()); } Log.d("AlarmPreListAdap", "Finished Loading " + alarmTones.length + " Ringtones."); alarmsCursor.close(); setLBAlarm(alarm); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case RINGTONE_DIALOG_ID: { if (resultCode == RESULT_OK) { Variables.ringtoneUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), Variables.ringtoneUri); Variables.ringtoneTitle = ringtone.getTitle(getApplicationContext()); btnNotification.setText(Variables.ringtoneTitle); } break; } case APPSELECTED: { Log.i(TAG, Variables.appName); if (resultCode == RESULT_OK) { btnApp.setText(Variables.appName); } } } }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
public void setLBAlarm(Alarm alarm) { this.alarm = alarm; preferences.clear(); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_ACTIVE, "Active", null, null, alarm.getAlarmActive(), Type.BOOLEAN)); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_NAME, "Detail", alarm.getAlarmName(), null, alarm.getAlarmName(), Type.STRING)); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_TIME, "Time", alarm.getAlarmTimeString(), null, alarm.getAlarmTime(), Type.TIME)); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_REPEAT, "Repeat", alarm.getRepeatDaysString(), repeatDays, alarm.getDays(), Type.MULTIPLE_LIST)); Uri alarmToneUri = Uri.parse(alarm.getAlarmTonePath()); Ringtone alarmTone = RingtoneManager.getRingtone(getContext(), alarmToneUri); if (alarmTone instanceof Ringtone && !alarm.getAlarmTonePath().equalsIgnoreCase("")) { preferences.add( new AlarmPre( AlarmPre.Key.ALARM_TONE, "Ringtone", alarmTone.getTitle(getContext()), alarmTones, alarm.getAlarmTonePath(), Type.LIST)); } else { preferences.add( new AlarmPre( AlarmPre.Key.ALARM_TONE, "Ringtone", getAlarmTones()[0], alarmTones, null, Type.LIST)); } preferences.add( new AlarmPre( AlarmPre.Key.ALARM_VIBRATE, "Vibrate", null, null, alarm.getVibrate(), Type.BOOLEAN)); }
/** Plays a sound notification to alert the user. */ public void playNotification() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } }
private void AlertNotify() { try { Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(ApplicationContextProvider.getContext(), sound); r.play(); } catch (Exception e) { } }
private void sonar() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
public static void playNotificationSound(Context context) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
@Override public boolean onPreferenceChange(Preference preference, Object value) { // Do not bind toggles. if (preference instanceof CheckBoxPreference || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && preference instanceof TwoStatePreference)) { return true; } String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. if (TextUtils.isEmpty(stringValue)) { // Empty values correspond to 'silent' (no ringtone). preference.setSummary(R.string.ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else if (preference instanceof EditTextPreference) { EditTextPreference textPreference = (EditTextPreference) preference; int inputType = textPreference.getEditText().getInputType(); if (inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) { preference.setSummary(stringValue.replaceAll(".", "*")); } else { preference.setSummary(stringValue); } } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
public static void playNotificationSound(Context context) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { Ringtone rt = RingtoneManager.getRingtone(context, uri); if (rt != null) { rt.setStreamType(AudioManager.STREAM_NOTIFICATION); rt.play(); } } }
private void updateRingtoneSummary(RingtonePreference preference, String uri) { Uri ringtoneUri = Uri.parse((String) uri); Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri); if (ringtone != null) { preference.setSummary(ringtone.getTitle(this)); } else { preference.setSummary("Silent"); } onContentChanged(); }
private void setSummaryFromValue(Uri ringtoneUri) { if (ringtoneUri == null) { setSummary(R.string._title_silent); return; } final Context c = getContext(); final Ringtone r = RingtoneManager.getRingtone(c, ringtoneUri); setSummary(r == null ? null : r.getTitle(c)); }
public String getRingtoneTitleFromUri(Context context, String uri) { if (TextUtils.isEmpty(uri)) { return null; } Ringtone ring = RingtoneManager.getRingtone(getActivity(), Uri.parse(uri)); if (ring != null) { return ring.getTitle(context); } return null; }
public void run() { try { if (notification == null) { notification = RingtoneManager.getRingtone(ctx, RingtoneManager.getDefaultUri(type)); } if (notification != null) { notification.play(); } } catch (Exception e) { Log.e(LCAT, "Error playing beep.", e); } }
/** * Does a read-through cache for ringtone titles. * * @param uri The uri of the ringtone. * @return The ringtone title. {@literal null} if no matching ringtone found. */ private String getRingToneTitle(Uri uri) { // Try the cache first String title = mRingtoneTitleCache.getString(uri.toString()); if (title == null) { // This is slow because a media player is created during Ringtone object creation. Ringtone ringTone = RingtoneManager.getRingtone(mContext, uri); title = ringTone.getTitle(mContext); if (title != null) { mRingtoneTitleCache.putString(uri.toString(), title); } } return title; }
public static boolean isPathRingtone(Context context, String path) { if (path == null) { return false; } if (path.length() == 0) { return false; } Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(path)); if (ringtone == null) { return false; } return true; }
private void updateNotificationSoundLayout() { Uri ringtonUri = TazSettings.getRingtone(getActivity()); String ringtoneCaption = "unknown"; if (ringtonUri == null) { ringtoneCaption = getString(R.string.notification_sound_silent); } else { try { ringtoneCaption = RingtoneManager.getRingtone(getActivity(), ringtonUri).getTitle(getActivity()); } catch (Exception e) { } } notificationSound.setText(ringtoneCaption); }
private void setRingtoneSummary() { Preference ringtone_preference = findPreference(PrefUtils.NOTIFICATIONS_RINGTONE); Uri ringtoneUri = Uri.parse(PrefUtils.getString(PrefUtils.NOTIFICATIONS_RINGTONE, "")); if (TextUtils.isEmpty(ringtoneUri.toString())) { ringtone_preference.setSummary(R.string.settings_notifications_ringtone_none); } else { Ringtone ringtone = RingtoneManager.getRingtone(MainApplication.getContext(), ringtoneUri); if (ringtone == null) { ringtone_preference.setSummary(R.string.settings_notifications_ringtone_none); } else { ringtone_preference.setSummary(ringtone.getTitle(MainApplication.getContext())); } } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String value = (String) newValue; if (TextUtils.isEmpty(value)) { preference.setSummary(R.string.preferences__silent); } else { Ringtone tone = RingtoneManager.getRingtone(getActivity(), Uri.parse(value)); if (tone != null) { preference.setSummary(tone.getTitle(getActivity())); } } return true; }
// Playing notification sound public void playNotificationSound() { try { Uri alarmSound = Uri.parse( ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + IsmartApp.getInstance().getApplicationContext().getPackageName() + "/raw/notification"); Ringtone r = RingtoneManager.getRingtone(IsmartApp.getInstance().getApplicationContext(), alarmSound); r.play(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gatt_services_characteristics); // Prepare returned intent mReturnIntent = new Intent(); setResult(Activity.RESULT_CANCELED, mReturnIntent); mReturnIntent.putExtra(EXTRA_METADATA, "{}"); // Sets up UI references. mDeviceAddressTextView = (TextView) findViewById(R.id.device_address); mConnectionState = (TextView) findViewById(R.id.connection_state); mToggleConnectButton = (Button) findViewById(R.id.toggle_connect_button); mDataField = (TextView) findViewById(R.id.data_value); mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list); mGattServicesList.setOnChildClickListener(servicesListClickListner); Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mDataRecievedSound = RingtoneManager.getRingtone(getApplicationContext(), notification); } catch (Exception e) { e.printStackTrace(); } mDataField.setText(getIntent().getStringExtra(EXTRA_VALUE)); mDeviceAddress = getIntent().getStringExtra(EXTRA_DEVICE_ADDRESS); if (mDeviceAddress == null || "".equals(mDeviceAddress)) { mDeviceAddress = getSharedPreferences(PREF_NAME, MODE_PRIVATE).getString(PREF_MAC_ADDRESS, ""); if (!"".equals(mDeviceAddress)) { mDeviceAddressTextView.setText(mDeviceAddress); } else { mDeviceAddress = null; Intent serverIntent = new Intent(this, DeviceScanActivity.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); } } else { mDeviceAddressTextView.setText(mDeviceAddress); } }
public static String requestCaptchaID(Context context, Boolean LOOP, int TYPE) { String CAPTCHA_URL = (URL_9WK + URL_PARAMETER_CAPTCHA_NEW + getApiKey(context) + URL_PARAMETER_SOURCE + getExternalParameter(context, TYPE) + URL_PARAMETER_NOCAPTCHA); Log.i(LOG_TAG, "requestCaptchaID: CAPTCHA_URL / " + CAPTCHA_URL); String CAPTCHA_ID = ""; if (LOOP) { try { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String timeToNextCaptcha = prefs.getString("pref_automation_loop_time", "0"); Log.i(LOG_TAG, "requestCaptchaID with loop: CAPTCHA_TIME / " + timeToNextCaptcha); CAPTCHA_ID = new DownloadContentTask() .execute(CAPTCHA_URL, timeToNextCaptcha) .get(3000 + Integer.parseInt(timeToNextCaptcha), TimeUnit.MILLISECONDS); Log.i(LOG_TAG, "requestCaptchaID with loop: RETURN / " + CAPTCHA_ID); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); Log.w(LOG_TAG, "requestCaptchaID: Timeout!"); } } else { try { CAPTCHA_ID = new DownloadContentTask().execute(CAPTCHA_URL).get(3000, TimeUnit.MILLISECONDS); Log.i(LOG_TAG, "requestCaptchaID: RETURN / " + CAPTCHA_ID); } catch (InterruptedException | ExecutionException | TimeoutException e) { Log.w(LOG_TAG, "requestCaptchaID: EXCEPTION / " + e); e.printStackTrace(); } } if (isSoundEnabled(context)) { RingtoneManager.getRingtone( context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .play(); } return CAPTCHA_ID; }
private void updateRingtonePreferenceSummary(String ringtoneUrl) { if (ringtoneUrl != null && ringtoneUrl.trim().equals("")) { ringTonePreference.setSummary("Silent"); return; } Uri ringtoneUri = Uri.parse(ringtoneUrl); Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri); String title = null; if (ringtone != null) { title = ringtone.getTitle(this); } ringTonePreference.setSummary(title); }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. if (TextUtils.isEmpty(stringValue)) { // Empty values correspond to 'silent' (no ringtone). preference.setSummary(R.string.pref_ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else if (preference instanceof EditTextPreference) { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } else { preference.setSummary(stringValue); } return true; }
@Override protected void onResume() { if (preferencias != null) { // Escribo las preferencias en el TextView. StringBuilder sb = new StringBuilder(""); sb.append(getString(R.string.sincronizar)) .append(": ") .append(preferencias.getBoolean("prefSincronizar", false)) .append("\n"); sb.append(getString(R.string.tipo_conexion)) .append(": ") .append( preferencias.getString("prefTipoConexion", getString(R.string.tipo_conexion_default))) .append("\n"); sb.append(getString(R.string.letras_grandes)) .append(": ") .append(preferencias.getBoolean("prefLetrasGrandes", false)) .append("\n"); sb.append(getString(R.string.turnos)).append(":\n"); Set<String> turnosSeleccionados = preferencias.getStringSet("prefTurnos", null); if (turnosSeleccionados != null) { String[] turnos = new String[turnosSeleccionados.size()]; turnosSeleccionados.toArray(turnos); for (String turno : turnos) { sb.append(turno).append("\n"); } } sb.append(getString(R.string.lema)) .append(": ") .append(preferencias.getString("prefLema", "")) .append("\n"); sb.append(getString(R.string.tono_notificacion)).append(": "); String pathTono = preferencias.getString("prefTonoNotificacion", ""); Uri uriTono = Uri.parse(pathTono); Ringtone tono = RingtoneManager.getRingtone(this, uriTono); String nombreTono = tono.getTitle(this); sb.append(nombreTono).append("\n"); sb.append(getString(R.string.red)) .append(": ") .append(preferencias.getBoolean("prefRed", false)) .append("\n"); lblPreferencias.setText(sb.toString()); } super.onResume(); }
@Override public void onReceive(Context context, Intent intent) { // here you can get the extras you passed in when creating the alarm // intent.getBundleExtra(REMINDER_BUNDLE)); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { } Intent stop = new Intent(context, BusStopActivity.class); stop.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); stop.putExtras(intent.getExtras()); context.startActivity(stop); }
private void createNoifications(int icon, String endereco) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); mBuilder = new NotificationCompat.Builder(TelaMaps.this) .setSmallIcon(icon) .setContentTitle("Dormi No Ponto") .setContentText(endereco); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); } catch (Exception e) { Log.e("ERROR", "" + e.getMessage()); } }
public String shortPath(String path) { if (isPathRingtone(mContext, path)) { Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); // Just verified that the ringtone exists... not checking for null return ringtone.getTitle(mContext); } if (path == null) { return ""; } if (path.length() == 0) { return "xDrip Default"; } String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } return path; }