Java Code Examples for androidx.preference.ListPreference#getValue()

The following examples show how to use androidx.preference.ListPreference#getValue() . 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: AutoInputSettingsFragment.java    From SmsCode with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings_auto_input_code);

    SwitchPreference autoInputEnablePref = findPreference(ENABLE_AUTO_INPUT_CODE);
    autoInputEnablePref.setOnPreferenceChangeListener(this);

    mAutoInputModePref = findPreference(AUTO_INPUT_MODE);
    mAutoInputModePref.setOnPreferenceChangeListener(this);
    mAutoInputMode = mAutoInputModePref.getValue();

    ListPreference focusModePref = findPreference(FOCUS_MODE);
    focusModePref.setOnPreferenceChangeListener(this);
    mFocusMode = focusModePref.getValue();

    mManualFocusIfFailedPref = findPreference(MANUAL_FOCUS_IF_FAILED);

    refreshEnableAutoInputPreference(autoInputEnablePref.isChecked());
    refreshAutoInputModePreference(mAutoInputMode);
    refreshFocusModePreference(focusModePref, focusModePref.getValue());
    refreshManualFocusIfFailedPreference();
}
 
Example 2
Source File: SettingsFragment.java    From fresco with MIT License 6 votes vote down vote up
private void updateGridRecyclerLayoutSummary() {
  final ListPreference listPreference =
      (ListPreference) findPreference(Const.RECYCLER_LAYOUT_KEY);
  // We have to enable the Grid settings only if the selection is the related on
  final ListPreference gridPreference =
      (ListPreference) findPreference(Const.GRID_SPAN_COUNT_KEY);
  final String value = listPreference.getValue();
  final boolean gridGroupVisible = Const.GRID_RECYCLER_VIEW_LAYOUT_VALUE.equals(value);
  // We update summary
  if (gridGroupVisible) {
    final String spanCountValue = gridPreference.getValue();
    gridPreference.setSummary(
        getString(R.string.label_grid_recycler_span_count_summary, spanCountValue));
  }
  gridPreference.setVisible(gridGroupVisible);
}
 
Example 3
Source File: PreferencesMain.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("SameReturnValue")
private static void prepareListPreference(final ListPreference listPreference, final Activity activity)
{
    if (listPreference == null)
    {
        return;
    }

    if (listPreference.getValue() == null)
    {
        // to ensure we don't get a null value
        // set first value by default
        listPreference.setValueIndex(0);
    }

    if (listPreference.getEntry() != null)
    {
        listPreference.setSummary(listPreference.getEntry().toString());
    }
    listPreference.setOnPreferenceChangeListener((preference, newValue) ->
    {
        listPreference.setValue(newValue.toString());
        preference.setSummary(listPreference.getEntry().toString());
        if (activity != null)
        {
            final Intent intent = activity.getIntent();
            activity.finish();
            activity.startActivity(intent);
        }
        return true;
    });
}
 
Example 4
Source File: SettingsActivity.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private static void prepareListPreference(final Activity activity, final ListPreference listPreference)
{
    if (listPreference == null)
    {
        return;
    }

    if (listPreference.getValue() == null)
    {
        // to ensure we don't get a null value
        // set first value by default
        listPreference.setValueIndex(0);
    }

    if (listPreference.getEntry() != null)
    {
        listPreference.setSummary(listPreference.getEntry().toString());
    }
    listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue)
        {
            listPreference.setValue(newValue.toString());
            preference.setSummary(listPreference.getEntry().toString());
            if (activity != null)
            {
                final Intent intent = activity.getIntent();
                activity.finish();
                activity.startActivity(intent);
            }
            return true;
        }
    });
}
 
Example 5
Source File: SettingsPreferenceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void createCameraSettingsPreference(final Context context) {
    CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    ListPreference facingPref = findPreference("camera_facing");
    if (facingPref != null) {
        if (cameraManager != null) {
            final int facing;
            String value = facingPref.getValue();
            if (value == null) {
                facing = Settings.DEFAULT_CAMERA_FACING;
                facingPref.setValueIndex(Settings.DEFAULT_CAMERA_FACING);
            } else {
                facing = Integer.parseInt(value);
            }

            facingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                if (newValue instanceof String) {
                    int newFacing = Integer.parseInt((String) newValue);
                    createCameraPreviewPreference(cameraManager, newFacing);
                }
                return true;
            });

            createCameraPreviewPreference(cameraManager, facing);
        } else {
            facingPref.setEnabled(false);
        }
    }
}
 
Example 6
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreatePreferences(Bundle bundle, String s) {

        addPreferencesFromResource(R.xml.settings);

        // general groups
        mEnablePref = findPreference(PrefConst.ENABLE);
        mEnablePref.setOnPreferenceChangeListener(this);

        // listen mode preference
        ListPreference listenModePref = findPreference(LISTEN_MODE);
        listenModePref.setOnPreferenceChangeListener(this);
        mCurListenMode = listenModePref.getValue();
        refreshListenModePreference(listenModePref, mCurListenMode);

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//            // hide copy to clipboard preference
//            PreferenceGroup generalGroup = findPreference(KEY_GENERAL);
//            Preference copyToClipboardPref = findPreference(COPY_TO_CLIPBOARD);
//            generalGroup.removePreference(copyToClipboardPref);
//        }

        findPreference(ENTRY_AUTO_INPUT_CODE).setOnPreferenceClickListener(this);

        Preference chooseThemePref = findPreference(PrefConst.CHOOSE_THEME);
        chooseThemePref.setOnPreferenceClickListener(this);
        initChooseThemePreference(chooseThemePref);
        // general groups end


        // experimental groups
        findPreference(MARK_AS_READ).setOnPreferenceChangeListener(this);

        findPreference(BLOCK_NOTIFICATION).setOnPreferenceChangeListener(this);

        findPreference(DELETE_SMS).setOnPreferenceChangeListener(this);
        // experimental groups end


        // code message group
        findPreference(CODE_RULES).setOnPreferenceClickListener(this);
        findPreference(SMSCODE_TEST).setOnPreferenceClickListener(this);
        // code message group end


        // code records group
        Preference recordsEntryPref = findPreference(ENTRY_CODE_RECORDS);
        recordsEntryPref.setOnPreferenceClickListener(this);
        initRecordEntryPreference(recordsEntryPref);
        // code records group end


        // others group
        // exclude from recent apps preference
        mExcludeFromRecentsPref = findPreference(EXCLUDE_FROM_RECENTS);
        mExcludeFromRecentsPref.setOnPreferenceChangeListener(this);

        // verbose log preference
        SwitchPreference verboseLogPref = findPreference(VERBOSE_LOG_MODE);
        verboseLogPref.setOnPreferenceChangeListener(this);
        refreshVerboseLogPreference(verboseLogPref, verboseLogPref.isChecked());
        // others group end


        // about group
        Preference versionPref = findPreference(VERSION);
        refreshVersionInfoPreference(versionPref);
        findPreference(SOURCE_CODE).setOnPreferenceClickListener(this);
        findPreference(RATING).setOnPreferenceClickListener(this);
        findPreference(GET_ALIPAY_PACKET).setOnPreferenceClickListener(this);
        findPreference(DONATE_BY_ALIPAY).setOnPreferenceClickListener(this);
        // about group end
    }