@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 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; }
@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)); }
@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; }
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)); }
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(); }
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; }
/** * 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; }
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; }
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(); }
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 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); Settings.Global.putString( getContentResolver(), Settings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath); }
@Override public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (data == null) { return; } Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); String name = null; if (ringtone != null) { Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone); if (rng != null) { if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) { name = LocaleController.getString("Default", R.string.Default); } else { name = rng.getTitle(getParentActivity()); } rng.stop(); } } SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences( "Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (requestCode == 12) { if (name != null && ringtone != null) { editor.putString("sound_" + dialog_id, name); editor.putString("sound_path_" + dialog_id, ringtone.toString()); } else { editor.putString("sound_" + dialog_id, "NoSound"); editor.putString("sound_path_" + dialog_id, "NoSound"); } } editor.commit(); listView.invalidateViews(); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); String name = null; if (ringtone != null && parentActivity != null) { Ringtone rng = RingtoneManager.getRingtone(parentActivity, ringtone); if (rng != null) { name = rng.getTitle(parentActivity); rng.stop(); } } SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (requestCode == 4) { if (name != null && ringtone != null) { editor.putString("GlobalSound", name); editor.putString("GlobalSoundPath", ringtone.toString()); } else { editor.putString("GlobalSound", "NoSound"); editor.putString("GlobalSoundPath", "NoSound"); } } else if (requestCode == 9) { if (name != null && ringtone != null) { editor.putString("GroupSound", name); editor.putString("GroupSoundPath", ringtone.toString()); } else { editor.putString("GroupSound", "NoSound"); editor.putString("GroupSoundPath", "NoSound"); } } editor.commit(); listView.invalidateViews(); } }
String getAlarmRingtoneTitle(Uri uri) { // Special case: no ringtone has a title of "Silent". if (Alarm.NO_RINGTONE_URI.equals(uri)) { return mContext.getString(R.string.silent_ringtone_title); } // Check the cache. String title = mRingtoneTitles.get(uri); if (title == null) { // This is slow because a media player is created during Ringtone object creation. final Ringtone ringtone = RingtoneManager.getRingtone(mContext, uri); if (ringtone == null) { LogUtils.e("No ringtone for uri: %s", uri); return mContext.getString(R.string.unknown_ringtone_title); } // Cache the title for later use. title = ringtone.getTitle(mContext); mRingtoneTitles.put(uri, title); } return title; }
protected void updateRingtonePreference(Preference preference, Uri ringtoneUri) { Context context = getActivity(); Ringtone ringtone = RingtoneManager.getRingtone(context, ringtoneUri); preference.setSummary(ringtone.getTitle(context)); }
@Override public View getView(int position, View view, ViewGroup parent) { if (view == null) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.alert_list_item, parent, false); } AlertModel alert = (AlertModel) getItem(position); TextView txtName = (TextView) view.findViewById(R.id.alert_item_name); txtName.setText(alert.name); TextView txtTone = (TextView) view.findViewById(R.id.alarm_tone); Ringtone ringtone = RingtoneManager.getRingtone(mContext, alert.alarmTone); txtTone.setText(ringtone.getTitle(mContext)); TextView txtAccount = (TextView) view.findViewById(R.id.account_name); txtAccount.setText(alert.userAccount); TextView txtLabel = (TextView) view.findViewById(R.id.alert_label_name); txtLabel.setText(alert.labelName); TextView txtLastChecked = (TextView) view.findViewById(R.id.last_checked); java.text.DateFormat df = DateFormat.getDateFormat(view.getContext()); if (alert.lastCheckDate != null) { String msg = df.format(alert.lastCheckDate) + " " + DateFormat.format("HH:mm:ss", alert.lastCheckDate); txtLastChecked.setText(msg); } else { txtLastChecked.setText(R.string.never); } MessageModel msg = dbHelper.findMessage(alert.lastMessageId); view.findViewById(R.id.mail_group).setVisibility(msg != null ? View.VISIBLE : View.GONE); if (msg != null) { ((TextView) view.findViewById(R.id.mail_from)).setText(msg.from); ((TextView) view.findViewById(R.id.mail_to)).setText(msg.to); ((TextView) view.findViewById(R.id.mail_subject)).setText(msg.subject); } TextView txtError = (TextView) view.findViewById(R.id.error); if (alert.lastError != null && alert.isEnabled) { txtError.setText(alert.lastError); txtError.setVisibility(View.VISIBLE); } else { txtError.setText(""); txtError.setVisibility(View.GONE); } ToggleButton btnEnabled = (ToggleButton) view.findViewById(R.id.alert_item_toggle); btnEnabled.setChecked(alert.isEnabled); btnEnabled.setTag(alert.id); btnEnabled.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ((AlertListActivity) mContext).setAlertEnabled((Long) buttonView.getTag(), isChecked); } }); final View leftInfo = view.findViewById(R.id.left_info); leftInfo.setTag(alert.id); leftInfo.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { ((AlertListActivity) mContext).startAlertDetailsActivity((Long) leftInfo.getTag()); } }); leftInfo.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { ((AlertListActivity) mContext).deleteAlarm((Long) leftInfo.getTag()); return true; } }); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_event); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); context = this; textViewAddress = (TextView) findViewById(R.id.idShowEventAddress); textViewCity = (TextView) findViewById(R.id.idShowEventCity); textViewDate = (TextView) findViewById(R.id.idShowEventDate); textViewReminder = (TextView) findViewById(R.id.idShowEventReminder); textViewAlertTone = (TextView) findViewById(R.id.idShowEventTone); Bundle extras = getIntent().getExtras(); if (extras != null) { rowTitle = extras.getString("rowTitle"); } actionBar.setTitle(rowTitle); EventsSQLiteHelper eventsDB = new EventsSQLiteHelper(this, "eventsDB", null, 1); SQLiteDatabase db = eventsDB.getReadableDatabase(); String[] campos = new String[] {"address", "city", "date", "time", "reminderDate", "reminderTime", "alert"}; String[] args = new String[] {rowTitle}; Cursor c = db.query("Events", campos, "title=?", args, null, null, null); if (c.moveToFirst()) { do { address = c.getString(0); Log.d("eventLog", address); city = c.getString(1); Log.d("eventLog", city); date = c.getString(2); Log.d("eventLog", date); time = c.getString(3); Log.d("eventLog", time); reminderDate = c.getString(4); Log.d("eventLog", reminderDate); reminderTime = c.getString(5); Log.d("eventLog", reminderTime); alertTone = c.getString(6); Log.d("eventLog", alertTone); } while (c.moveToNext()); } db.close(); completeAddress = address + ", " + city; addresses = Utils.getLocationInfo(completeAddress, this); textViewAddress.setText(address); textViewCity.setText(city); // Formateamos date y time para obtener la fecha y la hora en una sola cadena String[] rawDate = date.split(" "); String[] rawTime = time.split(":"); String finalDate = rawDate[2] + "/" + rawDate[1] + "/" + rawDate[5] + " " + rawTime[0] + ":" + rawTime[1]; Log.d("validateLOG", finalDate); textViewDate.setText(finalDate); // Formateamos reminderDate y reminderTime para obtener la fecha y la hora en una sola cadena String[] rawReminderDate = reminderDate.split(" "); String[] rawReminderTime = reminderTime.split(":"); String finalReminderDate = rawReminderDate[2] + "/" + rawReminderDate[1] + "/" + rawReminderDate[5] + " " + rawReminderTime[0] + ":" + rawReminderTime[1]; Log.d("validateLOG", finalReminderDate); textViewReminder.setText(finalReminderDate); // Formateamos la cadena alertTone para obtener el nombre de la alerta if (alertTone == null) { textViewAlertTone.setText("NINGUNO"); } else { Uri uri = Uri.parse(alertTone); Ringtone ringtone = RingtoneManager.getRingtone(this, uri); String alertToneName = ringtone.getTitle(this); textViewAlertTone.setText(alertToneName); } }
private void updatePrefences(Preference preference) { if (preference instanceof EditTextPreference) { if (preference.getKey().equals(MyApplication.PROFILE_NAME_KEY)) { EditTextPreference etp = (EditTextPreference) preference; if (etp.getText() != null && !etp.getText().equals("")) { profile.setName(etp.getText()); isNameSet = true; } isReady = isNameSet && isRepeatingSet && isActivatoinSet; etp.setSummary(etp.getText()); } } else if (preference instanceof ListPreference) { ListPreference lp = (ListPreference) preference; if (preference.getKey().equals(MyApplication.AUTO_ACTIVATION_KEY)) { lp.setSummary(lp.getEntry()); int idx = Integer.parseInt(lp.getValue()); switch (idx) { case 0: break; case 1: showFromDialog(); profile.setAcivationMode(MyApplication.BY_TIME); // lp.setSummary(profile.getSubTitle()); break; case 2: profile.setAcivationMode(MyApplication.BY_LOCATOIN); profile.setSubTitle("By Location "); isActivatoinSet = true; isReady = isNameSet && isRepeatingSet && isActivatoinSet; break; } lp.setSummary(profile.getSubTitle()); } else if (preference.getKey().equals(MyApplication.RING_MODE_KEY)) { lp.setSummary(lp.getEntry()); profile.setRingerMode(Integer.parseInt(lp.getValue())); } else if (preference.getKey().equals(MyApplication.CHANGE_WIFI_KEY)) { lp.setSummary(lp.getEntry()); profile.setWifiMode(Integer.parseInt(lp.getValue())); } else if (preference.getKey().equals(MyApplication.CHANGE_BLUETOOEH_KEY)) { lp.setSummary(lp.getEntry()); profile.setBlueToothMode(Integer.parseInt(lp.getValue())); } } else if (preference instanceof MultiSelectListPreference) { if (preference.getKey().equals(MyApplication.REPEATIN_DAYS_KEY)) { MultiSelectListPreference msp = (MultiSelectListPreference) preference; Set<String> selectedDays = msp.getValues(); ArrayList<Integer> selectedIndx = new ArrayList<>(); for (String day : selectedDays) { selectedIndx.add(Integer.parseInt(day)); // Toast.makeText(MyApplication.APP_CNTX,day,Toast.LENGTH_SHORT).show(); } Collections.sort(selectedIndx); String summary = ""; for (int idx : selectedIndx) { summary += MyApplication.DAYS_OF_WEEK[idx % 7].substring(0, 3) + ","; } if (summary.length() == 0) summary = "NONE"; msp.setSummary(summary); profile.setRepeatingDays(selectedIndx); isRepeatingSet = true; isReady = isNameSet && isRepeatingSet && isActivatoinSet; } } else if (preference instanceof CheckBoxPreference) { CheckBoxPreference cbp = (CheckBoxPreference) preference; if (cbp.getKey().equals(MyApplication.CHANGE_RINGTONE_KEY)) { findPreference(MyApplication.CHOOSE_RINGTONE_KEY).setEnabled(cbp.isChecked()); profile.setChangeRingtone(cbp.isChecked()); } else if (cbp.getKey().equals(MyApplication.CHANGE_NOTIFICATION_KEY)) { findPreference(MyApplication.CHOOSE_NOTIFICATION_KEY).setEnabled(cbp.isChecked()); profile.setChangeNotiTone(cbp.isChecked()); } } else if (preference instanceof RingtonePreference) { RingtonePreference rtp = (RingtonePreference) preference; if (rtp.getKey().equals(MyApplication.CHOOSE_RINGTONE_KEY)) { String ring = getRingToneURI(); Uri uri = Uri.parse(ring); Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri); if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity())); profile.setRingeToneURI(ring); } else if (rtp.getKey().equals(MyApplication.CHOOSE_NOTIFICATION_KEY)) { String ring = getNotiToneURI(); Uri uri = Uri.parse(ring); Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri); if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity())); profile.setNotiToneURI(ring); } } }
public boolean onPreferenceChange(Preference preference, Object newValue) { ContentResolver resolver = mContext.getContentResolver(); if (preference == mQuietHoursTimeRange) { Settings.System.putInt( resolver, Settings.System.QUIET_HOURS_START, mQuietHoursTimeRange.getStartTime()); Settings.System.putInt( resolver, Settings.System.QUIET_HOURS_END, mQuietHoursTimeRange.getEndTime()); SmsCallHelper.scheduleService(mContext); return true; } else if (preference == mQuietHoursEnabled) { Settings.System.putInt( resolver, Settings.System.QUIET_HOURS_ENABLED, (Boolean) newValue ? 1 : 0); SmsCallHelper.scheduleService(mContext); return true; } else if (preference == mQuietHoursMute) { Settings.System.putInt( resolver, Settings.System.QUIET_HOURS_MUTE, (Boolean) newValue ? 1 : 0); return true; } else if (preference == mQuietHoursStill) { Settings.System.putInt( resolver, Settings.System.QUIET_HOURS_STILL, (Boolean) newValue ? 1 : 0); return true; } else if (preference == mQuietHoursDim) { Settings.System.putInt(resolver, Settings.System.QUIET_HOURS_DIM, (Boolean) newValue ? 1 : 0); return true; } else if (preference == mQuietHoursHaptic) { Settings.System.putInt( resolver, Settings.System.QUIET_HOURS_HAPTIC, (Boolean) newValue ? 1 : 0); return true; } else if (preference == mRingtoneLoop) { mRingtoneLoop.setSummary( (Boolean) newValue ? R.string.quiet_hours_bypass_ringtone_loop_summary_on : R.string.quiet_hours_bypass_ringtone_loop_summary_off); return true; } else if (preference == mAutoSms) { mSmsPref = Integer.parseInt((String) newValue); mAutoSms.setSummary(mAutoSms.getEntries()[mSmsPref]); shouldDisplayTextPref(); return true; } else if (preference == mAutoSmsCall) { mCallPref = Integer.parseInt((String) newValue); mAutoSmsCall.setSummary(mAutoSmsCall.getEntries()[mCallPref]); shouldDisplayTextPref(); return true; } else if (preference == mSmsBypass) { mSmsBypassPref = Integer.parseInt((String) newValue); mSmsBypass.setSummary(mSmsBypass.getEntries()[mSmsBypassPref]); mSmsBypassCode.setEnabled(mSmsBypassPref != 0); shouldDisplayRingerPrefs(); return true; } else if (preference == mCallBypass) { mCallBypassPref = Integer.parseInt((String) newValue); mCallBypass.setSummary(mCallBypass.getEntries()[mCallBypassPref]); mCallBypassNumber.setEnabled(mCallBypassPref != 0); shouldDisplayRingerPrefs(); return true; } else if (preference == mCallBypassNumber) { int val = Integer.parseInt((String) newValue); mCallBypassNumber.setSummary( mCallBypassNumber.getEntries()[val - 2] + getResources().getString(R.string.quiet_hours_calls_required_summary)); return true; } else if (preference == mBypassRingtone) { Uri val = Uri.parse((String) newValue); SharedPreferences.Editor editor = mPrefs.edit(); Ringtone ringtone = RingtoneManager.getRingtone(mContext, val); if (ringtone != null) { editor.putString(KEY_BYPASS_RINGTONE, val.toString()).apply(); mBypassRingtone.setSummary(ringtone.getTitle(mContext)); } else { // No silent option, won't reach here editor.putString(KEY_BYPASS_RINGTONE, null).apply(); } return true; } return false; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getPreferenceManager() != null) { addPreferencesFromResource(R.xml.quiet_hours_settings); mContext = getActivity().getApplicationContext(); ContentResolver resolver = mContext.getContentResolver(); PreferenceScreen prefSet = getPreferenceScreen(); mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); // Load the preferences mQuietHoursNote = prefSet.findPreference(KEY_QUIET_HOURS_NOTE); mQuietHoursEnabled = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_ENABLED); mQuietHoursTimeRange = (TimeRangePreference) prefSet.findPreference(KEY_QUIET_HOURS_TIMERANGE); mQuietHoursMute = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_MUTE); mQuietHoursStill = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_STILL); mQuietHoursHaptic = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_HAPTIC); mQuietHoursDim = (CheckBoxPreference) findPreference(KEY_QUIET_HOURS_DIM); mRingtoneLoop = (CheckBoxPreference) findPreference(KEY_LOOP_BYPASS_RINGTONE); mAutoSms = (ListPreference) findPreference(KEY_AUTO_SMS); mAutoSmsCall = (ListPreference) findPreference(KEY_AUTO_SMS_CALL); mAutoSmsMessage = (Preference) findPreference(KEY_AUTO_SMS_MESSAGE); mSmsBypass = (ListPreference) findPreference(KEY_SMS_BYPASS); mCallBypass = (ListPreference) findPreference(KEY_CALL_BYPASS); mCallBypassNumber = (ListPreference) findPreference(KEY_REQUIRED_CALLS); mSmsBypassCode = (Preference) findPreference(KEY_SMS_BYPASS_CODE); mBypassRingtone = (RingtonePreference) findPreference(KEY_BYPASS_RINGTONE); // Remove the "Incoming calls behaviour" note if the device does not support phone calls if (mQuietHoursNote != null && getResources().getBoolean(com.android.internal.R.bool.config_voice_capable) == false) { getPreferenceScreen().removePreference(mQuietHoursNote); } // Set the preference state and listeners where applicable mQuietHoursEnabled.setChecked( Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_ENABLED, 0) == 1); mQuietHoursEnabled.setOnPreferenceChangeListener(this); mQuietHoursTimeRange.setTimeRange( Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_START, 0), Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_END, 0)); mQuietHoursTimeRange.setOnPreferenceChangeListener(this); mQuietHoursMute.setChecked( Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_MUTE, 0) == 1); mQuietHoursMute.setOnPreferenceChangeListener(this); mQuietHoursStill.setChecked( Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_STILL, 0) == 1); mQuietHoursStill.setOnPreferenceChangeListener(this); mQuietHoursHaptic.setChecked( Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_HAPTIC, 0) == 1); mQuietHoursHaptic.setOnPreferenceChangeListener(this); mRingtoneLoop.setOnPreferenceChangeListener(this); mAutoSms.setValue(mPrefs.getString(KEY_AUTO_SMS, "0")); mAutoSms.setOnPreferenceChangeListener(this); mAutoSmsCall.setValue(mPrefs.getString(KEY_AUTO_SMS_CALL, "0")); mAutoSmsCall.setOnPreferenceChangeListener(this); mSmsBypass.setValue(mPrefs.getString(KEY_SMS_BYPASS, "0")); mSmsBypass.setOnPreferenceChangeListener(this); mCallBypass.setValue(mPrefs.getString(KEY_CALL_BYPASS, "0")); mCallBypass.setOnPreferenceChangeListener(this); mCallBypassNumber.setValue(mPrefs.getString(KEY_REQUIRED_CALLS, "2")); mCallBypassNumber.setOnPreferenceChangeListener(this); mBypassRingtone.setOnPreferenceChangeListener(this); TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) { prefSet.removePreference((PreferenceGroup) findPreference("sms_respond")); prefSet.removePreference((PreferenceGroup) findPreference("quiethours_bypass")); } else { int callBypassNumber = Integer.parseInt(mPrefs.getString(KEY_REQUIRED_CALLS, "2")); boolean loopRingtone = mPrefs.getBoolean(KEY_LOOP_BYPASS_RINGTONE, true); mSmsBypassPref = Integer.parseInt(mPrefs.getString(KEY_SMS_BYPASS, "0")); mSmsPref = Integer.parseInt(mPrefs.getString(KEY_AUTO_SMS, "0")); mCallPref = Integer.parseInt(mPrefs.getString(KEY_AUTO_SMS_CALL, "0")); mCallBypassPref = Integer.parseInt(mPrefs.getString(KEY_CALL_BYPASS, "0")); Uri alertSoundUri = SmsCallHelper.returnUserRingtone(mContext); Ringtone ringtoneAlarm = RingtoneManager.getRingtone(mContext, alertSoundUri); mBypassRingtone.setSummary(ringtoneAlarm.getTitle(mContext)); mRingtoneLoop.setChecked(loopRingtone); mRingtoneLoop.setSummary( loopRingtone ? R.string.quiet_hours_bypass_ringtone_loop_summary_on : R.string.quiet_hours_bypass_ringtone_loop_summary_off); mSmsBypass.setSummary(mSmsBypass.getEntries()[mSmsBypassPref]); mCallBypass.setSummary(mCallBypass.getEntries()[mCallBypassPref]); mCallBypassNumber.setSummary( mCallBypassNumber.getEntries()[callBypassNumber - 2] + getResources().getString(R.string.quiet_hours_calls_required_summary)); mAutoSms.setSummary(mAutoSms.getEntries()[mSmsPref]); mAutoSmsCall.setSummary(mAutoSmsCall.getEntries()[mCallPref]); mCallBypassNumber.setEnabled(mCallBypassPref != 0); mSmsBypassCode.setEnabled(mSmsBypassPref != 0); shouldDisplayRingerPrefs(); shouldDisplayTextPref(); setSmsBypassCodeSummary(); } // Remove the notification light setting if the device does not support it if (mQuietHoursDim != null && getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed) == false) { getPreferenceScreen().removePreference(mQuietHoursDim); } else { mQuietHoursDim.setChecked( Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_DIM, 0) == 1); mQuietHoursDim.setOnPreferenceChangeListener(this); } mPreferencesChangeListener = new OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.equals(KEY_AUTO_SMS_CALL) || key.equals(KEY_AUTO_SMS) || key.equals(KEY_CALL_BYPASS) || key.equals(KEY_SMS_BYPASS)) { SmsCallHelper.scheduleService(mContext); } if (key.equals(KEY_SMS_BYPASS_CODE)) { setSmsBypassCodeSummary(); } } }; } }
@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 CheckBoxPreference) { SettingHelpers.p("Changing checkbox preference"); if ("showDebugNotifications".equals(preference.getKey())) { SettingHelpers.p("show debug"); boolean val = (Boolean) value; if (val) { SettingHelpers.setMultiProcessBooleanValue( "showDebugNotifications", true, preference.getContext().getApplicationContext()); Toast.makeText( preference.getContext().getApplicationContext(), "Showing now notifications", Toast.LENGTH_LONG) .show(); } else { SettingHelpers.setMultiProcessBooleanValue( "showDebugNotifications", false, preference.getContext().getApplicationContext()); } } if ("enableContextDataService".equals(preference.getKey())) { boolean val = (Boolean) value; if (val) { SettingHelpers.p("context data service enabled"); SettingHelpers.setMultiProcessBooleanValue( "enableContextDataService", true, preference.getContext().getApplicationContext()); Toast.makeText( preference.getContext().getApplicationContext(), "Context Data Service enabled", Toast.LENGTH_LONG) .show(); } else { SettingHelpers.p("context data service disabled"); SettingHelpers.setMultiProcessBooleanValue( "enableContextDataService", false, preference.getContext().getApplicationContext()); } } } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); SettingHelpers.setStringValue( preference.getKey(), stringValue, preference.getContext()); } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ContentResolver resolver = getContentResolver(); int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); addPreferencesFromResource(R.xml.sound_settings); if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) { // device is not CDMA, do not display CDMA emergency_tone getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE)); } mVolumeOverlay = (ListPreference) findPreference(KEY_VOLUME_OVERLAY); mVolumeOverlay.setOnPreferenceChangeListener(this); int volumeOverlay = Settings.System.getInt( getContentResolver(), Settings.System.MODE_VOLUME_OVERLAY, VolumePanel.VOLUME_OVERLAY_EXPANDABLE); mVolumeOverlay.setValue(Integer.toString(volumeOverlay)); mVolumeOverlay.setSummary(mVolumeOverlay.getEntry()); mRingMode = (ListPreference) findPreference(KEY_RING_MODE); if (!getResources().getBoolean(R.bool.has_silent_mode)) { getPreferenceScreen().removePreference(mRingMode); findPreference(KEY_RING_VOLUME).setDependency(null); } else { mRingMode.setOnPreferenceChangeListener(this); } if (getResources().getBoolean(com.android.internal.R.bool.config_useFixedVolume)) { // device with fixed volume policy, do not display volumes submenu getPreferenceScreen().removePreference(findPreference(KEY_RING_VOLUME)); } mQuietHours = (PreferenceScreen) findPreference(KEY_QUIET_HOURS); updateQuietHoursSummary(); mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS); if (!Utils.hasVolumeRocker(getActivity())) { getPreferenceScreen().removePreference(findPreference(KEY_VOLUME_ADJUST_SOUNDS)); } mRingtonePreference = findPreference(KEY_RINGTONE); mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND); Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if (vibrator == null || !vibrator.hasVibrator()) { removePreference(KEY_VIBRATE); removePreference(KEY_HAPTIC_FEEDBACK); removePreference(KEY_VIBRATION_INTENSITY); removePreference(KEY_CONVERT_SOUND_TO_VIBRATE); removePreference(KEY_VIBRATE_DURING_CALLS); } else if (!VibratorIntensity.isSupported()) { removePreference(KEY_VIBRATION_INTENSITY); } if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) { ListPreference emergencyTonePreference = (ListPreference) findPreference(KEY_EMERGENCY_TONE); emergencyTonePreference.setValue( String.valueOf( Settings.Global.getInt( resolver, Settings.Global.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE))); emergencyTonePreference.setOnPreferenceChangeListener(this); } mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS); mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX); Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); mMusicFx.setIntent(i); PackageManager p = getPackageManager(); List<ResolveInfo> ris = p.queryIntentActivities(i, 0); if (ris.size() == 0) { mSoundSettings.removePreference(mMusicFx); } else if (ris.size() == 1) { mMusicFx.setSummary(ris.get(0).loadLabel(p)); } if (!Utils.isVoiceCapable(getActivity())) { for (String prefKey : NEED_VOICE_CAPABILITY) { Preference pref = findPreference(prefKey); if (pref != null) { getPreferenceScreen().removePreference(pref); } } mRingtonePreference = null; } mRingtoneLookupRunnable = new Runnable() { public void run() { if (mRingtonePreference != null) { updateRingtoneName( RingtoneManager.TYPE_RINGTONE, mRingtonePreference, MSG_UPDATE_RINGTONE_SUMMARY); } if (mNotificationPreference != null) { updateRingtoneName( RingtoneManager.TYPE_NOTIFICATION, mNotificationPreference, MSG_UPDATE_NOTIFICATION_SUMMARY); } } }; // power state change notification sounds mPowerSounds = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS); mPowerSounds.setChecked( Settings.Global.getInt(resolver, Settings.Global.POWER_NOTIFICATIONS_ENABLED, 0) != 0); mPowerSoundsVibrate = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE); mPowerSoundsVibrate.setChecked( Settings.Global.getInt(resolver, Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) != 0); if (vibrator == null || !vibrator.hasVibrator()) { removePreference(KEY_POWER_NOTIFICATIONS_VIBRATE); } mPowerSoundsRingtone = findPreference(KEY_POWER_NOTIFICATIONS_RINGTONE); String currentPowerRingtonePath = Settings.Global.getString(resolver, Settings.Global.POWER_NOTIFICATIONS_RINGTONE); // set to default notification if we don't yet have one if (currentPowerRingtonePath == null) { currentPowerRingtonePath = Settings.System.DEFAULT_NOTIFICATION_URI.toString(); Settings.Global.putString( getContentResolver(), Settings.Global.POWER_NOTIFICATIONS_RINGTONE, currentPowerRingtonePath); } // is it silent ? if (currentPowerRingtonePath.equals(POWER_NOTIFICATIONS_SILENT_URI)) { mPowerSoundsRingtone.setSummary(getString(R.string.power_notifications_ringtone_silent)); } else { final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(currentPowerRingtonePath)); if (ringtone != null) { mPowerSoundsRingtone.setSummary(ringtone.getTitle(getActivity())); } } initDockSettings(); }