2015-01-07 14:00:18 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
2015-03-15 21:36:39 +01:00
|
|
|
import android.content.Intent;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceCategory;
|
|
|
|
import android.preference.PreferenceManager;
|
2015-03-28 20:39:46 +01:00
|
|
|
import android.support.v4.app.NavUtils;
|
2015-04-19 12:35:23 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-03-28 20:39:46 +01:00
|
|
|
import android.view.MenuItem;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
|
|
|
public class SettingsActivity extends PreferenceActivity {
|
|
|
|
@Override
|
|
|
|
protected void onPostCreate(Bundle savedInstanceState) {
|
|
|
|
super.onPostCreate(savedInstanceState);
|
2015-03-28 20:39:46 +01:00
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
2015-01-07 14:00:18 +01:00
|
|
|
setupSimplePreferencesScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupSimplePreferencesScreen() {
|
|
|
|
// Add 'general' preferences.
|
|
|
|
addPreferencesFromResource(R.xml.pref_general);
|
|
|
|
|
2015-03-29 17:12:06 +02:00
|
|
|
// Add 'date' preferences, and a corresponding header.
|
|
|
|
PreferenceCategory fakeHeaderDateTime = new PreferenceCategory(this);
|
|
|
|
fakeHeaderDateTime.setTitle(R.string.pref_header_datetime);
|
|
|
|
getPreferenceScreen().addPreference(fakeHeaderDateTime);
|
|
|
|
addPreferencesFromResource(R.xml.pref_datetime);
|
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
// Add 'notifications' preferences, and a corresponding header.
|
|
|
|
PreferenceCategory fakeHeader = new PreferenceCategory(this);
|
|
|
|
fakeHeader.setTitle(R.string.pref_header_notifications);
|
|
|
|
getPreferenceScreen().addPreference(fakeHeader);
|
|
|
|
addPreferencesFromResource(R.xml.pref_notification);
|
|
|
|
|
2015-03-15 21:36:39 +01:00
|
|
|
Preference pref = (Preference) findPreference("notifications_generic");
|
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
|
|
|
startActivity(enableIntent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2015-04-01 23:00:05 +02:00
|
|
|
// Add 'development' preferences, and a corresponding header.
|
|
|
|
PreferenceCategory fakeHeaderDev = new PreferenceCategory(this);
|
|
|
|
fakeHeaderDev.setTitle(R.string.pref_header_development);
|
|
|
|
getPreferenceScreen().addPreference(fakeHeaderDev);
|
|
|
|
addPreferencesFromResource(R.xml.pref_development);
|
|
|
|
|
2015-04-19 12:35:23 +02:00
|
|
|
|
|
|
|
final Preference developmentMiaddr = findPreference("development_miaddr");
|
|
|
|
bindPreferenceSummaryToValue(developmentMiaddr);
|
|
|
|
|
|
|
|
developmentMiaddr.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
Intent refreshIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
|
|
|
preference.setSummary(newVal.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
|
|
|
// their values. When their values change, their summaries are updated
|
|
|
|
// to reflect the new value, per the Android Design guidelines.
|
2015-04-19 12:35:23 +02:00
|
|
|
|
2015-03-06 14:00:56 +01:00
|
|
|
//bindPreferenceSummaryToValue(findPreference("notifications_sms_whenscreenon"));
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A preference value change listener that updates the preference's summary
|
|
|
|
* to reflect its new value.
|
|
|
|
*/
|
|
|
|
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
|
|
|
|
@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 {
|
|
|
|
// For all other preferences, set the summary to the value's
|
|
|
|
// simple string representation.
|
|
|
|
preference.setSummary(stringValue);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds a preference's summary to its value. More specifically, when the
|
|
|
|
* preference's value is changed, its summary (line of text below the
|
|
|
|
* preference title) is updated to reflect the value. The summary is also
|
|
|
|
* immediately updated upon calling this method. The exact display format is
|
|
|
|
* dependent on the type of preference.
|
|
|
|
*
|
|
|
|
* @see #sBindPreferenceSummaryToValueListener
|
|
|
|
*/
|
|
|
|
private static void bindPreferenceSummaryToValue(Preference preference) {
|
|
|
|
// Set the listener to watch for value changes.
|
|
|
|
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
|
|
|
|
|
|
|
|
// Trigger the listener immediately with the preference's
|
|
|
|
// current value.
|
|
|
|
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
|
|
|
|
PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(preference.getContext())
|
|
|
|
.getString(preference.getKey(), ""));
|
|
|
|
}
|
|
|
|
|
2015-03-28 20:39:46 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
NavUtils.navigateUpFromSameTask(this);
|
|
|
|
return true;
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
2015-03-28 20:39:46 +01:00
|
|
|
return super.onOptionsItemSelected(item);
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
|
|
|
}
|