Java Code Examples for android.preference.Preference#getSharedPreferences()

The following examples show how to use android.preference.Preference#getSharedPreferences() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomInputStyleSettingsFragment.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
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));
}
 
Example 2
Source File: CustomInputStyleSettingsFragment.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 3
Source File: CustomInputStyleSettingsFragment.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 4
Source File: CustomInputStyleSettingsFragment.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 5
Source File: CustomInputStyleSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 6
Source File: CustomInputStyleSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 7
Source File: GankIoActivity.java    From styT with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: lua.java    From styT with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: GankIoActivity.java    From styT with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: GankIoActivity.java    From stynico with MIT License 5 votes vote down vote up
@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;
  }
 
Example 11
Source File: lua.java    From stynico with MIT License 5 votes vote down vote up
@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;
   }
 
Example 12
Source File: GankIoActivity.java    From stynico with MIT License 5 votes vote down vote up
@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;
   }
 
Example 13
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
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());
        }
    }
 
Example 14
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
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());
        }
    }