2016-06-19 20:06:00 +02:00
|
|
|
package info.nightscout.androidaps;
|
|
|
|
|
2017-11-01 20:43:59 +01:00
|
|
|
import android.content.Intent;
|
2016-06-19 20:06:00 +02:00
|
|
|
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;
|
2017-09-20 13:54:05 +02:00
|
|
|
import android.text.TextUtils;
|
2017-01-26 12:07:25 +01:00
|
|
|
|
2016-06-19 20:06:00 +02:00
|
|
|
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;
|
2017-11-01 20:43:59 +01:00
|
|
|
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
2017-09-18 22:58:18 +02:00
|
|
|
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
2017-11-01 20:43:59 +01:00
|
|
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
2017-05-24 18:24:23 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin;
|
2017-04-21 12:15:08 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference;
|
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
2017-09-13 00:35:03 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
2017-04-30 21:08:00 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
2017-04-21 12:15:08 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
2017-06-30 11:56:36 +02:00
|
|
|
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
2017-07-07 15:08:21 +02:00
|
|
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
2017-11-01 20:43:59 +01:00
|
|
|
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
2017-02-18 18:13:13 +01:00
|
|
|
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
2017-05-06 15:18:19 +02:00
|
|
|
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
2016-07-06 22:50:25 +02:00
|
|
|
import info.nightscout.utils.LocaleHelper;
|
2017-07-04 00:16:35 +02:00
|
|
|
import info.nightscout.utils.OKDialog;
|
|
|
|
import info.nightscout.utils.SP;
|
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();
|
2017-11-08 10:20:49 +01:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("id", getIntent().getIntExtra("id", -1));
|
|
|
|
myPreferenceFragment.setArguments(args);
|
2016-07-07 17:17:54 +02:00
|
|
|
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) {
|
2017-02-17 16:16:20 +01:00
|
|
|
MainApp.bus().post(new EventPreferenceChange(key));
|
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();
|
2017-06-16 08:37:07 +02:00
|
|
|
MainApp.bus().post(new EventRefreshGui());
|
2016-07-06 22:50:25 +02:00
|
|
|
}
|
2017-01-21 23:48:05 +01:00
|
|
|
if (key.equals("short_tabtitles")) {
|
2017-06-16 08:37:07 +02:00
|
|
|
MainApp.bus().post(new EventRefreshGui());
|
2017-01-21 23:48:05 +01:00
|
|
|
}
|
2017-07-04 00:16:35 +02:00
|
|
|
if (key.equals("openapsama_useautosens") && SP.getBoolean("openapsama_useautosens", false)) {
|
|
|
|
OKDialog.show(this, MainApp.sResources.getString(R.string.configbuilder_sensitivity), MainApp.sResources.getString(R.string.sensitivity_warning), null);
|
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
updatePrefSummary(myPreferenceFragment.getPreference(key));
|
2017-02-09 10:41:02 +01:00
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
private static void updatePrefSummary(Preference pref) {
|
2016-07-07 17:17:54 +02:00
|
|
|
if (pref instanceof ListPreference || pref instanceof BluetoothDevicePreference) {
|
|
|
|
ListPreference listPref = (ListPreference) pref;
|
|
|
|
pref.setSummary(listPref.getEntry());
|
|
|
|
}
|
|
|
|
if (pref instanceof EditTextPreference) {
|
|
|
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
2017-04-14 15:33:39 +02:00
|
|
|
if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
|
2016-07-07 17:17:54 +02:00
|
|
|
pref.setSummary("******");
|
2017-09-13 00:35:03 +02:00
|
|
|
} else if (pref.getKey().equals(MainApp.sResources.getString(R.string.key_danars_name))) {
|
2017-11-01 20:43:59 +01:00
|
|
|
pref.setSummary(SP.getString(R.string.key_danars_name, ""));
|
2017-01-25 20:19:00 +01:00
|
|
|
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
|
|
|
|
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
|
|
|
pref.setSummary(editTextPref.getText());
|
2017-11-01 20:43:59 +01:00
|
|
|
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())) {
|
2017-09-20 13:54:05 +02:00
|
|
|
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
|
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
if (pref instanceof MultiSelectListPreference) {
|
|
|
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
|
|
|
pref.setSummary(editTextPref.getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 20:29:41 +01:00
|
|
|
public static void initSummary(Preference p) {
|
2016-07-07 17:17:54 +02:00
|
|
|
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 {
|
2017-11-08 10:20:49 +01:00
|
|
|
private Integer id;
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2017-11-08 10:20:49 +01:00
|
|
|
@Override
|
|
|
|
public void setArguments(Bundle args) {
|
|
|
|
super.setArguments(args);
|
2017-11-08 15:07:10 +01:00
|
|
|
id = args.getInt("id");
|
2017-11-01 20:43:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
|
|
|
|
if (p.isEnabled(type) && p.getPreferencesId() != -1)
|
|
|
|
addPreferencesFromResource(p.getPreferencesId());
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:00 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-11-01 20:43:59 +01:00
|
|
|
|
|
|
|
if (id != -1) {
|
|
|
|
addPreferencesFromResource(id);
|
|
|
|
} else {
|
|
|
|
if (!Config.NSCLIENT) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_password);
|
2017-10-10 19:14:43 +02:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResource(R.xml.pref_age);
|
|
|
|
addPreferencesFromResource(R.xml.pref_language);
|
|
|
|
|
|
|
|
if (!Config.NSCLIENT) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_quickwizard);
|
2017-04-30 21:08:00 +02:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL);
|
|
|
|
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS);
|
|
|
|
if (Config.APS) {
|
|
|
|
addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginBase.LOOP);
|
|
|
|
addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginBase.APS);
|
|
|
|
addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginBase.APS);
|
2017-09-13 00:35:03 +02:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
|
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginBase.SENSITIVITY);
|
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY);
|
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY);
|
|
|
|
|
|
|
|
if (!Config.NSCLIENT) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_profile);
|
2016-07-15 20:56:07 +02:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
|
|
|
|
if (Config.DANAR) {
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginBase.PUMP);
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginBase.PUMP);
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginBase.PUMP);
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginBase.PUMP);
|
|
|
|
|
|
|
|
if (DanaRPlugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
|
|
|
|| DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
|
|
|
|| DanaRv2Plugin.getPlugin().isEnabled(PluginBase.PROFILE)
|
|
|
|
|| DanaRSPlugin.getPlugin().isEnabled(PluginBase.PROFILE)) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_danarprofile);
|
|
|
|
}
|
2017-05-24 18:24:23 +02:00
|
|
|
}
|
2017-11-01 23:25:37 +01:00
|
|
|
|
|
|
|
if (Config.COMBO) {
|
|
|
|
addPreferencesFromResourceIfEnabled(ComboPlugin.getPlugin(), PluginBase.PUMP);
|
|
|
|
}
|
2017-08-14 13:20:09 +02:00
|
|
|
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP);
|
2017-02-18 18:13:13 +01:00
|
|
|
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN);
|
|
|
|
|
|
|
|
addPreferencesFromResourceIfEnabled(NSClientInternalPlugin.getPlugin(), PluginBase.GENERAL);
|
|
|
|
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL);
|
|
|
|
|
|
|
|
if (!Config.NSCLIENT) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_others);
|
|
|
|
}
|
|
|
|
addPreferencesFromResource(R.xml.pref_advanced);
|
2017-04-14 15:33:39 +02:00
|
|
|
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginBase.GENERAL);
|
|
|
|
addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginBase.GENERAL);
|
2017-05-06 15:18:19 +02:00
|
|
|
}
|
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
initSummary(getPreferenceScreen());
|
2016-07-07 17:17:54 +02:00
|
|
|
}
|
2016-06-19 20:06:00 +02:00
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
public Preference getPreference(String key) {
|
2016-07-07 17:17:54 +02:00
|
|
|
return findPreference(key);
|
2016-06-19 20:06:00 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-07 01:02:08 +01:00
|
|
|
}
|