2014-11-04 14:19:48 +00:00
|
|
|
package org.thoughtcrime.securesms.preferences;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.preference.RingtonePreference;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
2014-12-12 06:08:04 +00:00
|
|
|
public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment {
|
2014-11-04 14:19:48 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle paramBundle) {
|
|
|
|
super.onCreate(paramBundle);
|
|
|
|
addPreferencesFromResource(R.xml.preferences_notifications);
|
|
|
|
|
|
|
|
this.findPreference(TextSecurePreferences.LED_COLOR_PREF)
|
2014-12-12 03:36:46 +00:00
|
|
|
.setOnPreferenceChangeListener(new ListSummaryListener());
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(TextSecurePreferences.LED_BLINK_PREF)
|
2014-12-12 03:36:46 +00:00
|
|
|
.setOnPreferenceChangeListener(new ListSummaryListener());
|
2014-11-04 14:19:48 +00:00
|
|
|
this.findPreference(TextSecurePreferences.RINGTONE_PREF)
|
2014-12-12 03:36:46 +00:00
|
|
|
.setOnPreferenceChangeListener(new RingtoneSummaryListener());
|
|
|
|
this.findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF)
|
|
|
|
.setOnPreferenceChangeListener(new ListSummaryListener());
|
2014-11-04 14:19:48 +00:00
|
|
|
|
|
|
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_COLOR_PREF));
|
|
|
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF));
|
2014-12-12 03:36:46 +00:00
|
|
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF));
|
2014-11-04 14:19:48 +00:00
|
|
|
initializeRingtoneSummary((RingtonePreference) findPreference(TextSecurePreferences.RINGTONE_PREF));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__notifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class RingtoneSummaryListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
String value = (String) newValue;
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(value)) {
|
|
|
|
preference.setSummary(R.string.preferences__default);
|
|
|
|
} else {
|
|
|
|
Ringtone tone = RingtoneManager.getRingtone(getActivity(), Uri.parse(value));
|
|
|
|
if (tone != null) {
|
|
|
|
preference.setSummary(tone.getTitle(getActivity()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeRingtoneSummary(RingtonePreference pref) {
|
|
|
|
RingtoneSummaryListener listener =
|
|
|
|
(RingtoneSummaryListener) pref.getOnPreferenceChangeListener();
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
|
|
|
|
listener.onPreferenceChange(pref, sharedPreferences.getString(pref.getKey(), ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CharSequence getSummary(Context context) {
|
|
|
|
final int onCapsResId = R.string.ApplicationPreferencesActivity_On;
|
|
|
|
final int offCapsResId = R.string.ApplicationPreferencesActivity_Off;
|
|
|
|
|
|
|
|
return context.getString(TextSecurePreferences.isNotificationsEnabled(context) ? onCapsResId : offCapsResId);
|
|
|
|
}
|
|
|
|
}
|