private void setPowerNotificationRingtone(Intent intent) { final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); final String toneName; final String toneUriPath; if ( uri != null ) { final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri); toneName = ringtone.getTitle(getActivity()); toneUriPath = uri.toString(); } else { // silent toneName = getString(R.string.power_notifications_ringtone_silent); toneUriPath = POWER_NOTIFICATIONS_SILENT_URI; } mPowerSoundsRingtone.setSummary(toneName); CMSettings.Global.putString(getContentResolver(), CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath); }
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } } }); }
/** * Handles incoming data events from the mesh - toasts the contents of the data. * * @param e event object from mesh */ private void handleDataReceived(MeshManager.RightMeshEvent e) { final MeshManager.DataReceivedEvent event = (MeshManager.DataReceivedEvent) e; runOnUiThread(new Runnable() { @Override public void run() { // Toast data contents. String message = new String(event.data); Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show(); // Play a notification. Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(MainActivity.this, notification); r.play(); } }); }
@NonNull public static String getRingtoneName(@NonNull Context context, @Nullable Uri uri) { String title = context.getString(R.string.sound_chooser_summary); if (uri != null) { Ringtone ringtone = RingtoneManager.getRingtone(context, uri); if (ringtone != null) { return ringtone.getTitle(context); } else { try (Cursor cur = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?", new String[]{uri.getLastPathSegment()}, null)) { if (cur != null) { title = cur.getString(1); if (InputHelper.isEmpty(title)) { title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE)); } } } catch (Exception ignored) {} } } return title; }
private void handleChangePolicies(Application application) { SharedPreferences sharedPref = application.getSharedPreferences( application.getString(R.string.preference_file_key), Context.MODE_PRIVATE); Uri sound = getTone(sharedPref); if (notificationNeeded(application, sharedPref)) { Log.i("TTM", "Changes found. Would fire!"); switch (sharedPref.getString("onChangeForm", "Banner")) { case "None": if (sound != null) { Ringtone r = RingtoneManager.getRingtone(application.getApplicationContext(), sound); r.play(); } break; case "Banner": fireBanner(sound); break; } } else { Log.i("TTM", "Change check negative -> Won't fire any notification for change."); } }
private void maybePlaySound() { if (mSoundEnabled && (!mPowerManager.isInteractive() || !mSoundWhenScreenOffOnly)) { try { final Ringtone sfx = RingtoneManager.getRingtone(mContext, Uri.parse(mSoundUri)); if (sfx != null) { AudioAttributes attrs = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); sfx.setAudioAttributes(attrs); sfx.play(); } } catch (Throwable t) { XposedBridge.log(t); } } }
/** * Get the title of the ringtone from the uri of ringtone. * * @param context instance of the caller * @param uri uri of the tone to search * @return title of the tone or return null if no tone found. */ @Nullable public static String getRingtoneName(@NonNull Context context, @NonNull Uri uri) { Ringtone ringtone = RingtoneManager.getRingtone(context, uri); if (ringtone != null) { return ringtone.getTitle(context); } else { Cursor cur = context .getContentResolver() .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?", new String[]{uri.getLastPathSegment()}, null); String title = null; if (cur != null) { title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE)); cur.close(); } return title; } }
private void initializeRingtonePreference() { Preference.OnPreferenceChangeListener ringtoneChangedListener = new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object value) { if ("".equals(value)) { preference.setSummary(R.string.silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(ReminderPreferences.this, value == null ? RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION) : Uri.parse((String) value)); preference.setSummary(ringtone == null ? "" : ringtone.getTitle(ReminderPreferences.this)); } return true; } }; String ringtoneKey = getString(R.string.p_rmd_ringtone); Preference ringtonePreference = findPreference(ringtoneKey); ringtonePreference.setOnPreferenceChangeListener(ringtoneChangedListener); ringtoneChangedListener.onPreferenceChange(ringtonePreference, PreferenceManager.getDefaultSharedPreferences(this) .getString(ringtoneKey, null)); }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (isListPreference(preference)) { ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (isRingtonePreference(preference)) { if (TextUtils.isEmpty(stringValue)) { preference.setSummary(R.string.pref_ringtone_silent); } else { Ringtone ringtone = getRingtone(preference, stringValue); if (ringtone == null) { preference.setSummary(null); } else { preference.setSummary(getRingtoneTitle(preference, ringtone)); } } } else { preference.setSummary(stringValue); } return true; }
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; }
private String shortPath(String path) { try { if (path != null) { if (path.length() == 0) { return "xDrip Default"; } Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); if (ringtone != null) { return ringtone.getTitle(mContext); } else { String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } } } return ""; } catch (SecurityException e) { // need external storage permission? checkStoragePermissions("Need permission to access audio files"); return ""; } }
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { } } } } } }); }
private void initSeekBar(int stream_type, Ringtone tone, int iconRes, boolean enabled) { if (enabled) { View v = getLayoutInflater().inflate(R.layout.volume_sider_item, volume_sliders_container, false); ((ImageView) v.findViewById(R.id.vs_icon)).setImageResource(iconRes); final SeekBar seek = (SeekBar) v.findViewById(R.id.vs_seek); seek.setTag(stream_type); seek.setMax(am.getStreamMaxVolume(stream_type)); seek.setProgress(am.getStreamVolume(stream_type)); seek.setOnSeekBarChangeListener(this); ringtoneMap.put(stream_type, tone); volume_sliders_container.addView(v); if (mLastControlledSeekbar == null) { mLastControlledSeekbar = seek; } } }
@Override public void onStopTrackingTouch(SeekBar seekBar) { final int stream = (Integer) seekBar.getTag(); am.setStreamVolume(stream, seekBar.getProgress(), 0); if (stream == AudioManager.STREAM_RING) { volume_modes.check(seekBar.getProgress() > 0 ? (VolumeTracker.isVibrateOn(this, am) ? R.id.rd_vol_4 : R.id.rd_vol_3) : R.id.rd_vol_1); } Ringtone tone = ringtoneMap.get(stream); if (tone!=null && playMusic) { tone.setStreamType(stream); tone.play(); } mLastControlledSeekbar = seekBar; }
@Override public void onReceive(final Context context, Intent intent) { //this will sound the alarm tone //this will sound the alarm once, if you wish to //raise alarm in loop continuously then use MediaPlayer and setLooping(true) Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alarmUri == null) { alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri); ringtone.play(); //this will send a notification message ComponentName comp = new ComponentName(context.getPackageName(), AlarmService.class.getName()); startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); }
public void setMathAlarm(Alarm alarm) { this.alarm = alarm; preferences.clear(); preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_ACTIVE,"Active", null, null, alarm.getAlarmActive(),Type.BOOLEAN)); preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_NAME, "Label",alarm.getAlarmName(), null, alarm.getAlarmName(), Type.STRING)); preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_TIME, "Set time",alarm.getAlarmTimeString(), null, alarm.getAlarmTime(), Type.TIME)); preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_REPEAT, "Repeat",alarm.getRepeatDaysString(), repeatDays, alarm.getDays(),Type.MULTIPLE_LIST)); preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_DIFFICULTY,"Difficulty", alarm.getDifficulty().toString(), alarmDifficulties, alarm.getDifficulty(), Type.LIST)); Uri alarmToneUri = Uri.parse(alarm.getAlarmTonePath()); Ringtone alarmTone = RingtoneManager.getRingtone(getContext(), alarmToneUri); if(alarmTone instanceof Ringtone && !alarm.getAlarmTonePath().equalsIgnoreCase("")){ preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_TONE, "Ringtone", alarmTone.getTitle(getContext()),alarmTones, alarm.getAlarmTonePath(), Type.LIST)); }else{ preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_TONE, "Ringtone", getAlarmTones()[0],alarmTones, null, Type.LIST)); } preferences.add(new AlarmPreference(AlarmPreference.Key.ALARM_VIBRATE, "Vibrate",null, null, alarm.getVibrate(), Type.BOOLEAN)); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); Ringtone ringTone = RingtoneManager.getRingtone(getApplicationContext(), uri); ringtone_name.setText(ringTone.getTitle(this)); switch (requestCode) { case REQUEST_TONE_PICKER_CUSTOM: mSettingsHelper.setString("custom_ringtone", uri.toString()); break; case REQUEST_TONE_PICKER_NEW_COMMENT: mSettingsHelper.setString("new_comment_ringtone", uri.toString()); break; case REQUEST_TONE_PICKER_MSG_RECALL: mSettingsHelper.setString("msg_recall_ringtone", uri.toString()); break; case REQUEST_TONE_PICKER_COMMENT_RECALL: mSettingsHelper.setString("comment_recall_ringtone", uri.toString()); break; } } }
/** * Set the Ring tone that is selected for the disconnect Hiro or Find phone * through. * * @param model */ private void setRingname(DeviceInfoModel model) { String phoneRing = preferences.getString("PhoneRing", ""); String disRing = model.getDisconnectRing(); if (disRing != null && !disRing.equalsIgnoreCase("")) { Uri uri = Uri.parse(disRing); Ringtone ringtone = RingtoneManager.getRingtone( SettingsActivity.this, uri); String name = ringtone.getTitle(SettingsActivity.this); if (name != null && !name.equalsIgnoreCase("")) txtDisconnectRingtone.setText(name); } if (phoneRing != null && !phoneRing.equalsIgnoreCase("")) { Uri uri1 = Uri.parse(phoneRing); Ringtone ringtone1 = RingtoneManager.getRingtone( SettingsActivity.this, uri1); String name1 = ringtone1.getTitle(SettingsActivity.this); txtPhoneRing.setText(name1); } }
private void buildSummary() { if (SettingUtils.getEnableFetchMSG()) { String value = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(SettingActivity.FREQUENCY, "1"); frequency.setSummary(getActivity().getResources().getStringArray(R.array.frequency)[Integer.valueOf(value) - 1]); } else { frequency.setSummary(getString(R.string.stopped)); } if (uri != null) { Ringtone r = RingtoneManager.getRingtone(getActivity(), uri); ringtone.setSummary(r.getTitle(getActivity())); } else { ringtone.setSummary(getString(R.string.silent)); } }
public String shortPath(String path) { if(path != null) { if(path.length() == 0) { return "xDrip Default"; } Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); if (ringtone != null) { return ringtone.getTitle(mContext); } else { String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } } } return ""; }
private void buildSummary() { if (SettingUtility.getEnableFetchMSG()) { String value = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString(SettingActivity.FREQUENCY, "1"); frequency.setSummary(getActivity().getResources().getStringArray(R.array.frequency)[ Integer.valueOf(value) - 1]); } else { frequency.setSummary(getString(R.string.stopped)); } if (uri != null) { Ringtone r = RingtoneManager.getRingtone(getActivity(), uri); ringtone.setSummary(r.getTitle(getActivity())); } else { ringtone.setSummary(getString(R.string.silent)); } }