下面列出了android.preference.Preference#getSharedPreferences ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static void updateCustomInputStylesSummary(final Preference pref) {
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeLocaleUtils.init(pref.getContext());
final Resources res = pref.getContext().getResources();
final SharedPreferences prefs = pref.getSharedPreferences();
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
final ArrayList<String> subtypeNames = new ArrayList<>();
for (final InputMethodSubtype subtype : subtypes) {
subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
}
// TODO: A delimiter of custom input styles should be localized.
pref.setSummary(TextUtils.join(", ", subtypeNames));
}
static void updateCustomInputStylesSummary(final Preference pref) {
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeLocaleUtils.init(pref.getContext());
final Resources res = pref.getContext().getResources();
final SharedPreferences prefs = pref.getSharedPreferences();
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
final ArrayList<String> subtypeNames = new ArrayList<>();
for (final InputMethodSubtype subtype : subtypes) {
subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
}
// TODO: A delimiter of custom input styles should be localized.
pref.setSummary(TextUtils.join(", ", subtypeNames));
}
static void updateCustomInputStylesSummary(final Preference pref) {
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeLocaleUtils.init(pref.getContext());
final Resources res = pref.getContext().getResources();
final SharedPreferences prefs = pref.getSharedPreferences();
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
final ArrayList<String> subtypeNames = new ArrayList<>();
for (final InputMethodSubtype subtype : subtypes) {
subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
}
// TODO: A delimiter of custom input styles should be localized.
pref.setSummary(TextUtils.join(", ", subtypeNames));
}
static void updateCustomInputStylesSummary(final Preference pref) {
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeLocaleUtils.init(pref.getContext());
final Resources res = pref.getContext().getResources();
final SharedPreferences prefs = pref.getSharedPreferences();
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
final ArrayList<String> subtypeNames = new ArrayList<>();
for (final InputMethodSubtype subtype : subtypes) {
subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
}
// TODO: A delimiter of custom input styles should be localized.
pref.setSummary(TextUtils.join(", ", subtypeNames));
}
static void updateCustomInputStylesSummary(final Preference pref) {
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeLocaleUtils.init(pref.getContext());
final Resources res = pref.getContext().getResources();
final SharedPreferences prefs = pref.getSharedPreferences();
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
final ArrayList<String> subtypeNames = new ArrayList<>();
for (final InputMethodSubtype subtype : subtypes) {
subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
}
// TODO: A delimiter of custom input styles should be localized.
pref.setSummary(TextUtils.join(", ", subtypeNames));
}
static void updateCustomInputStylesSummary(final Preference pref) {
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeLocaleUtils.init(pref.getContext());
final Resources res = pref.getContext().getResources();
final SharedPreferences prefs = pref.getSharedPreferences();
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
final ArrayList<String> subtypeNames = new ArrayList<>();
for (final InputMethodSubtype subtype : subtypes) {
subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
}
// TODO: A delimiter of custom input styles should be localized.
pref.setSummary(TextUtils.join(", ", subtypeNames));
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
{
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
{
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
{
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
}
public static void handleUnitsChange(Preference preference, Object newValue, AllPrefsFragment allPrefsFragment) {
try {
SharedPreferences preferences;
if (preference!= null) {
preferences = preference.getSharedPreferences();
} else {
preferences = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
}
final Double highVal = Double.parseDouble(preferences.getString("highValue", "0"));
final Double lowVal = Double.parseDouble(preferences.getString("lowValue", "0"));
final Double default_insulin_sensitivity = Double.parseDouble(preferences.getString("profile_insulin_sensitivity_default", "54"));
final Double default_target_glucose = Double.parseDouble(preferences.getString("plus_target_range", "100"));
static_units = newValue.toString();
if (newValue.toString().equals("mgdl")) {
if (highVal < 36) {
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
preferences.edit().putString("highValue", Long.toString(Math.round(highVal * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", Long.toString(Math.round(default_insulin_sensitivity * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("plus_target_range", Long.toString(Math.round(default_target_glucose * Constants.MMOLL_TO_MGDL))).apply();
Profile.invalidateProfile();
}
if (lowVal < 36) {
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
preferences.edit().putString("lowValue", Long.toString(Math.round(lowVal * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", Long.toString(Math.round(default_insulin_sensitivity * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("plus_target_range", Long.toString(Math.round(default_target_glucose * Constants.MMOLL_TO_MGDL))).apply();
Profile.invalidateProfile();
}
} else {
if (highVal > 35) {
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
preferences.edit().putString("highValue", JoH.qs(highVal * Constants.MGDL_TO_MMOLL, 1)).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", JoH.qs(default_insulin_sensitivity * Constants.MGDL_TO_MMOLL, 2)).apply();
preferences.edit().putString("plus_target_range", JoH.qs(default_target_glucose * Constants.MGDL_TO_MMOLL,1)).apply();
Profile.invalidateProfile();
}
if (lowVal > 35) {
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
preferences.edit().putString("lowValue", JoH.qs(lowVal * Constants.MGDL_TO_MMOLL, 1)).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", JoH.qs(default_insulin_sensitivity * Constants.MGDL_TO_MMOLL, 2)).apply();
preferences.edit().putString("plus_target_range", JoH.qs(default_target_glucose * Constants.MGDL_TO_MMOLL,1)).apply();
Profile.invalidateProfile();
}
}
if (preference != null) preference.setSummary(newValue.toString());
if (allPrefsFragment != null) {
allPrefsFragment.setSummary("highValue");
allPrefsFragment.setSummary("lowValue");
}
if (profile_insulin_sensitivity_default != null) {
Log.d(TAG, "refreshing profile insulin sensitivity default display");
profile_insulin_sensitivity_default.setTitle(format_insulin_sensitivity(profile_insulin_sensitivity_default.getTitle().toString(), ProfileEditor.minMaxSens(ProfileEditor.loadData(false))));
// do_format_insulin_sensitivity(profile_insulin_sensitivity_default, AllPrefsFragment.this.prefs, false, null);
}
Profile.reloadPreferences(preferences);
} catch (Exception e) {
Log.e(TAG, "Got excepting processing high/low value preferences: " + e.toString());
}
}
public static void handleUnitsChange(Preference preference, Object newValue, AllPrefsFragment allPrefsFragment) {
try {
SharedPreferences preferences;
if (preference!= null) {
preferences = preference.getSharedPreferences();
} else {
preferences = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
}
final Double highVal = Double.parseDouble(preferences.getString("highValue", "0"));
final Double lowVal = Double.parseDouble(preferences.getString("lowValue", "0"));
final Double default_insulin_sensitivity = Double.parseDouble(preferences.getString("profile_insulin_sensitivity_default", "54"));
final Double default_target_glucose = Double.parseDouble(preferences.getString("plus_target_range", "100"));
static_units = newValue.toString();
if (newValue.toString().equals("mgdl")) {
if (highVal < 36) {
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
preferences.edit().putString("highValue", Long.toString(Math.round(highVal * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", Long.toString(Math.round(default_insulin_sensitivity * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("plus_target_range", Long.toString(Math.round(default_target_glucose * Constants.MMOLL_TO_MGDL))).apply();
Profile.invalidateProfile();
}
if (lowVal < 36) {
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
preferences.edit().putString("lowValue", Long.toString(Math.round(lowVal * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", Long.toString(Math.round(default_insulin_sensitivity * Constants.MMOLL_TO_MGDL))).apply();
preferences.edit().putString("plus_target_range", Long.toString(Math.round(default_target_glucose * Constants.MMOLL_TO_MGDL))).apply();
Profile.invalidateProfile();
}
} else {
if (highVal > 35) {
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
preferences.edit().putString("highValue", JoH.qs(highVal * Constants.MGDL_TO_MMOLL, 1)).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", JoH.qs(default_insulin_sensitivity * Constants.MGDL_TO_MMOLL, 2)).apply();
preferences.edit().putString("plus_target_range", JoH.qs(default_target_glucose * Constants.MGDL_TO_MMOLL,1)).apply();
Profile.invalidateProfile();
}
if (lowVal > 35) {
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
preferences.edit().putString("lowValue", JoH.qs(lowVal * Constants.MGDL_TO_MMOLL, 1)).apply();
preferences.edit().putString("profile_insulin_sensitivity_default", JoH.qs(default_insulin_sensitivity * Constants.MGDL_TO_MMOLL, 2)).apply();
preferences.edit().putString("plus_target_range", JoH.qs(default_target_glucose * Constants.MGDL_TO_MMOLL,1)).apply();
Profile.invalidateProfile();
}
}
if (preference != null) preference.setSummary(newValue.toString());
if (allPrefsFragment != null) {
allPrefsFragment.setSummary("highValue");
allPrefsFragment.setSummary("lowValue");
}
if (profile_insulin_sensitivity_default != null) {
Log.d(TAG, "refreshing profile insulin sensitivity default display");
profile_insulin_sensitivity_default.setTitle(format_insulin_sensitivity(profile_insulin_sensitivity_default.getTitle().toString(), ProfileEditor.minMaxSens(ProfileEditor.loadData(false))));
// do_format_insulin_sensitivity(profile_insulin_sensitivity_default, AllPrefsFragment.this.prefs, false, null);
}
Profile.reloadPreferences(preferences);
} catch (Exception e) {
Log.e(TAG, "Got excepting processing high/low value preferences: " + e.toString());
}
}