2016-06-19 20:06:00 +02:00
|
|
|
package info.nightscout.androidaps;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
2016-07-07 17:17:54 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.EditTextPreference;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.MultiSelectListPreference;
|
|
|
|
import android.preference.Preference;
|
2016-06-19 20:06:00 +02:00
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceFragment;
|
2016-07-07 17:17:54 +02:00
|
|
|
import android.preference.PreferenceGroup;
|
2016-06-19 20:06:00 +02:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
2016-07-06 22:50:25 +02:00
|
|
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
2016-07-15 20:56:07 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
2016-07-07 17:17:54 +02:00
|
|
|
import info.nightscout.androidaps.plugins.DanaR.BluetoothDevicePreference;
|
2016-07-15 20:56:07 +02:00
|
|
|
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
|
2016-08-05 23:54:03 +02:00
|
|
|
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
|
2016-07-06 22:50:25 +02:00
|
|
|
import info.nightscout.utils.LocaleHelper;
|
2016-06-19 20:06:00 +02:00
|
|
|
|
|
|
|
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2016-07-07 17:17:54 +02:00
|
|
|
MyPreferenceFragment myPreferenceFragment;
|
|
|
|
|
2016-06-19 20:06:00 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-07-07 17:17:54 +02:00
|
|
|
myPreferenceFragment = new MyPreferenceFragment();
|
|
|
|
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
2016-06-19 20:06:00 +02:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
MainApp.bus().post(new EventPreferenceChange());
|
2016-07-06 22:50:25 +02:00
|
|
|
if (key.equals("language")) {
|
2016-07-07 17:17:54 +02:00
|
|
|
String lang = sharedPreferences.getString("language", "en");
|
2016-07-06 22:50:25 +02:00
|
|
|
LocaleHelper.setLocale(getApplicationContext(), lang);
|
|
|
|
recreate();
|
|
|
|
MainApp.bus().post(new EventRefreshGui());
|
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
updatePrefSummary(myPreferenceFragment.getPreference(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void updatePrefSummary(Preference pref) {
|
|
|
|
if (pref instanceof ListPreference || pref instanceof BluetoothDevicePreference) {
|
|
|
|
ListPreference listPref = (ListPreference) pref;
|
|
|
|
pref.setSummary(listPref.getEntry());
|
|
|
|
}
|
|
|
|
if (pref instanceof EditTextPreference) {
|
|
|
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
|
|
|
if (pref.getTitle().toString().toLowerCase().contains("password"))
|
|
|
|
{
|
|
|
|
pref.setSummary("******");
|
2016-07-14 23:29:21 +02:00
|
|
|
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")){
|
2016-07-07 17:17:54 +02:00
|
|
|
pref.setSummary(editTextPref.getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pref instanceof MultiSelectListPreference) {
|
|
|
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
|
|
|
pref.setSummary(editTextPref.getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void initSummary(Preference p) {
|
|
|
|
if (p instanceof PreferenceGroup) {
|
|
|
|
PreferenceGroup pGrp = (PreferenceGroup) p;
|
|
|
|
for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
|
|
|
|
initSummary(pGrp.getPreference(i));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updatePrefSummary(p);
|
|
|
|
}
|
2016-06-19 20:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class MyPreferenceFragment extends PreferenceFragment {
|
|
|
|
@Override
|
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-07-06 22:50:25 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_language);
|
2016-07-14 23:29:21 +02:00
|
|
|
if (Config.CAREPORTALENABLED)
|
|
|
|
addPreferencesFromResource(R.xml.pref_careportal);
|
2016-06-19 20:06:00 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_treatments);
|
2016-06-26 11:43:26 +02:00
|
|
|
if (Config.APS)
|
|
|
|
addPreferencesFromResource(R.xml.pref_closedmode);
|
2016-06-19 20:06:00 +02:00
|
|
|
if (Config.OPENAPSMAENABLED)
|
|
|
|
addPreferencesFromResource(R.xml.pref_openapsma);
|
2016-07-07 17:17:54 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_nightscout);
|
2016-07-15 20:56:07 +02:00
|
|
|
if (Config.DANAR) {
|
2016-08-05 23:54:03 +02:00
|
|
|
DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
2016-08-13 12:33:20 +02:00
|
|
|
if (danaRPlugin.isEnabled(PluginBase.PUMP)) {
|
2016-09-10 15:37:37 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_danar);
|
2016-07-15 20:56:07 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_danarprofile);
|
|
|
|
}
|
|
|
|
}
|
2016-07-13 15:56:27 +02:00
|
|
|
if (Config.MM640G)
|
|
|
|
addPreferencesFromResource(R.xml.pref_mm640g);
|
2016-07-14 23:29:21 +02:00
|
|
|
if (Config.SMSCOMMUNICATORENABLED)
|
|
|
|
addPreferencesFromResource(R.xml.pref_smscommunicator);
|
2016-07-07 17:17:54 +02:00
|
|
|
initSummary(getPreferenceScreen());
|
|
|
|
}
|
2016-06-19 20:06:00 +02:00
|
|
|
|
2016-07-07 17:17:54 +02:00
|
|
|
public Preference getPreference (String key) {
|
|
|
|
return findPreference(key);
|
2016-06-19 20:06:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|