androidx.preference.ListPreference Java Examples

The following examples show how to use androidx.preference.ListPreference. 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: WebSearchPreference.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
private void setProviderList(ListPreference list) {
    List<String> entries = new ArrayList<>();
    List<String> entryValues = new ArrayList<>();

    entries.add(getString(R.string.search_provider_none));
    entryValues.add(getString(R.string.gesture_action_default_value));

    // We only need the key as the value is stored in PreferenceHelper's Map.
    for (Map.Entry<String, String> provider : PreferenceHelper
            .getProviderList().entrySet()) {
        entries.add(provider.getKey());
        entryValues.add(provider.getKey());
    }

    CharSequence[] finalEntries = entries.toArray(new CharSequence[0]);
    CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]);

    list.setEntries(finalEntries);
    list.setEntryValues(finalEntryValues);
}
 
Example #2
Source File: ChatsPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);

  findPreference(TextSecurePreferences.MEDIA_DOWNLOAD_MOBILE_PREF)
      .setOnPreferenceChangeListener(new MediaDownloadChangeListener());
  findPreference(TextSecurePreferences.MEDIA_DOWNLOAD_WIFI_PREF)
      .setOnPreferenceChangeListener(new MediaDownloadChangeListener());
  findPreference(TextSecurePreferences.MEDIA_DOWNLOAD_ROAMING_PREF)
      .setOnPreferenceChangeListener(new MediaDownloadChangeListener());
  findPreference(TextSecurePreferences.MESSAGE_BODY_TEXT_SIZE_PREF)
      .setOnPreferenceChangeListener(new ListSummaryListener());

  findPreference(TextSecurePreferences.BACKUP_ENABLED)
      .setOnPreferenceClickListener(new BackupClickListener());
  findPreference(TextSecurePreferences.BACKUP_NOW)
      .setOnPreferenceClickListener(new BackupCreateListener());
  findPreference(TextSecurePreferences.BACKUP_PASSPHRASE_VERIFY)
      .setOnPreferenceClickListener(new BackupVerifyListener());

  initializeListSummary((ListPreference) findPreference(TextSecurePreferences.MESSAGE_BODY_TEXT_SIZE_PREF));

  EventBus.getDefault().register(this);
}
 
Example #3
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Since the "%s" summary is currently broken, this sets the preference change listener for all
 * {@link ListPreference} views to fill in the summary with the current entry value.
 */
private void fixListSummaries(PreferenceGroup group) {
  if (group == null) {
    return;
  }

  final int count = group.getPreferenceCount();

  for (int i = 0; i < count; i++) {
    final Preference preference = group.getPreference(i);

    if (preference instanceof PreferenceGroup) {
      fixListSummaries((PreferenceGroup) preference);
    } else if (preference instanceof ListPreference) {
      // First make sure the current summary is correct, then set the
      // listener. This is necessary for summaries to show correctly
      // on SDKs < 14.
      preferenceChangeListener.onPreferenceChange(
          preference, ((ListPreference) preference).getValue());

      preference.setOnPreferenceChangeListener(preferenceChangeListener);
    }
  }
}
 
Example #4
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 #5
Source File: SettingsActivity.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();

	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);
		
		// Set the summary to reflect the new value.
		preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example #6
Source File: SettingsFragment.java    From android-DarkTheme with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    ListPreference themePreference = findPreference("themePref");
    if (themePreference != null) {
        themePreference.setOnPreferenceChangeListener(
                new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        String themeOption = (String) newValue;
                        ThemeHelper.applyTheme(themeOption);
                        return true;
                    }
                });
    }
}
 
Example #7
Source File: SettingsFragment.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    ListPreference themePreference = findPreference("themePref");
    if (themePreference != null) {
        themePreference.setOnPreferenceChangeListener(
                new Preference.OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        String themeOption = (String) newValue;
                        ThemeHelper.applyTheme(themeOption);
                        return true;
                    }
                });
    }
}
 
Example #8
Source File: SettingsFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the preferences state and summaries
 */
private void setupPreferences() {
    // Theme preferences
    ListPreference themePref = (ListPreference)findPreference(Settings.KEY_PREF_THEME);
    themePref.setSummary(themePref.getEntry());

    // About preference
    String nameAndVersion = getActivity().getString(R.string.app_name);
    try {
        nameAndVersion += " " +
                          getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException exc) {
    }
    Preference aboutPreference = findPreference(Settings.KEY_PREF_ABOUT);
    aboutPreference.setSummary(nameAndVersion);
    aboutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AboutDialogFragment aboutDialog = new AboutDialogFragment();
            aboutDialog.show(getFragmentManager(), null);
            return true;
        }
    });
}
 
Example #9
Source File: GeneralPreferenceFragment.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void initStoragePaths(ListPreference storagePreference) {
    if(Build.VERSION.SDK_INT<Build.VERSION_CODES.KITKAT||!Global.hasStoragePermission(act)){
        storagePreference.setVisible(false);
        return;
    }
    List<File>files=Global.getUsableFolders(act);
    List<CharSequence>strings=new ArrayList<>(files.size());
    for(File f:files)strings.add(f.getAbsolutePath());
    storagePreference.setEntries(strings.toArray(new CharSequence[0]));
    storagePreference.setEntryValues(strings.toArray(new CharSequence[0]));
    storagePreference.setSummary(
            act.getSharedPreferences("Settings",Context.MODE_PRIVATE)
                    .getString(getString(R.string.key_save_path),Global.MAINFOLDER.getParent())
    );
    storagePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary(newValue.toString());
        return true;
    });
}
 
Example #10
Source File: RtspPreferenceActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    EditTextPreference url = findPreference(getString(R.string.key_server_url));
    if (url != null) {
        url.setText(getServerUrl());
    }

    ListPreference videoResolution = findPreference(getString(R.string.key_video_resolution));
    if (videoResolution != null) {
        String[] entries = createCameraResolutions(getContext());
        videoResolution.setEntries(entries);
        videoResolution.setEntryValues(entries);
    }

    setInputTypeNumber(R.string.key_server_port);
    setInputTypeNumber(R.string.key_video_bit_rate);
    setInputTypeNumber(R.string.key_video_frame_rate);
    setInputTypeNumber(R.string.key_video_iframe_interval);
    setInputTypeNumber(R.string.key_audio_bit_rate);
}
 
Example #11
Source File: SketchPropertiesFragment.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();
	
	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);
		
		// Set the summary to reflect the new value.
		preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example #12
Source File: WebSearchPreference.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
private void setProviderList(ListPreference list) {
    List<String> entries = new ArrayList<>();
    List<String> entryValues = new ArrayList<>();

    entries.add(getString(R.string.search_provider_none));
    entryValues.add(getString(R.string.gesture_action_default_value));

    // We only need the key as the value is stored in PreferenceHelper's Map.
    for (Map.Entry<String, String> provider : PreferenceHelper
            .getProviderList().entrySet()) {
        entries.add(provider.getKey());
        entryValues.add(provider.getKey());
    }

    CharSequence[] finalEntries = entries.toArray(new CharSequence[0]);
    CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]);

    list.setEntries(finalEntries);
    list.setEntryValues(finalEntryValues);
}
 
Example #13
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 #14
Source File: NotificationPreferenceFragment.java    From intra42 with Apache License 2.0 6 votes vote down vote up
private void updateCalendarList() {
    SparseArray<String> calendar = Calendar.getCalendarList(requireActivity());
    ListPreference prefListCalendar = findPreference(AppSettings.Notifications.SELECTED_CALENDAR);
    if (prefListCalendar == null)
        return;

    if (calendar != null) {
        CharSequence[] entryKey = new String[calendar.size()];
        CharSequence[] entryValues = new String[calendar.size()];

        for (int i = 0; i < calendar.size(); i++) {
            int key = calendar.keyAt(i);
            entryKey[i] = String.valueOf(key);
            entryValues[i] = calendar.get(key);
        }
        prefListCalendar.setEntries(entryValues);
        prefListCalendar.setEntryValues(entryKey);
    }
}
 
Example #15
Source File: Preferences.java    From materialistic with Apache License 2.0 5 votes vote down vote up
private static void sync(PreferenceManager preferenceManager, String key) {
    Preference pref = preferenceManager.findPreference(key);
    if (pref instanceof ListPreference) {
        ListPreference listPref = (ListPreference) pref;
        pref.setSummary(listPref.getEntry());
    }
}
 
Example #16
Source File: ChatsPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);

  mediaQuality = (ListPreference) this.findPreference("pref_compression");
  mediaQuality.setOnPreferenceChangeListener((preference, newValue) -> {
    updateListSummary(preference, newValue);
    dcContext.setConfigInt(DcHelper.CONFIG_MEDIA_QUALITY, Util.objectToInt(newValue));
    return true;
  });

  showEmails = (ListPreference) this.findPreference("pref_show_emails");
  showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
    updateListSummary(preference, newValue);
    dcContext.setConfigInt(CONFIG_SHOW_EMAILS, Util.objectToInt(newValue));
    return true;
  });

  readReceiptsCheckbox = (CheckBoxPreference) this.findPreference("pref_read_receipts");
  readReceiptsCheckbox.setOnPreferenceChangeListener(new ReadReceiptToggleListener());

  this.findPreference("preference_category_blocked").setOnPreferenceClickListener(new BlockedContactsClickListener());

  Preference backup = this.findPreference("pref_backup");
  backup.setOnPreferenceClickListener(new BackupListener());

  autoDelDevice = findPreference("autodel_device");
  autoDelDevice.setOnPreferenceChangeListener(new AutodelChangeListener("delete_device_after"));

  autoDelServer = findPreference("autodel_server");
  autoDelServer.setOnPreferenceChangeListener(new AutodelChangeListener("delete_server_after"));
}
 
Example #17
Source File: AppearancePreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);

  this.findPreference(Prefs.THEME_PREF).setOnPreferenceChangeListener(new ListSummaryListener());
  this.findPreference(Prefs.LANGUAGE_PREF).setOnPreferenceChangeListener(new ListSummaryListener());
  initializeListSummary((ListPreference)findPreference(Prefs.THEME_PREF));
  initializeListSummary((ListPreference)findPreference(Prefs.LANGUAGE_PREF));
  this.findPreference(Prefs.BACKGROUND_PREF).setOnPreferenceClickListener(new BackgroundClickListener());
  this.findPreference(Prefs.MESSAGE_BODY_TEXT_SIZE_PREF).setOnPreferenceChangeListener(new ListSummaryListener());
  initializeListSummary((ListPreference) findPreference(Prefs.MESSAGE_BODY_TEXT_SIZE_PREF));
}
 
Example #18
Source File: ListSummaryPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
protected String getSelectedSummary(Preference preference, Object value) {
  ListPreference listPref = (ListPreference) preference;
  int entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);
  return entryIndex >= 0 && entryIndex < listPref.getEntries().length
          ? listPref.getEntries()[entryIndex].toString()
          : getString(R.string.unknown);
}
 
Example #19
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 #20
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference list = (ListPreference) preference;
    String value = (String) newValue;

    // Workaround due to the use of setSummary in onCreate.
    switch (value) {
        case "handler":
            list.setSummary(R.string.gesture_action_handler);
            break;
        case "widget":
            list.setSummary(R.string.gesture_action_widget);
            break;
        case "status":
            list.setSummary(R.string.gesture_action_status);
            break;
        case "list":
            list.setSummary(R.string.gesture_action_list);
            break;
        case "app":
            // Create the Bundle to pass to AppSelectionPreferenceDialog.
            Bundle appListBundle = new Bundle();
            appListBundle.putString("key", list.getKey());
            appListBundle.putCharSequenceArray("entries", appListEntries);
            appListBundle.putCharSequenceArray("entryValues", appListEntryValues);

            // Call and create AppSelectionPreferenceDialog.
            AppSelectionPreferenceDialog appList = new AppSelectionPreferenceDialog();
            appList.setTargetFragment(GesturesPreference.this, APPLICATION_DIALOG_CODE);
            appList.setArguments(appListBundle);
            appList.show(requireFragmentManager(), "AppSelectionDialog");
            break;
        case "none":
        default:
            list.setSummary(R.string.gesture_action_default);
            break;
    }
    return true;
}
 
Example #21
Source File: AppListPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
private void setIconList(ListPreference list) {
    PackageManager manager = requireActivity().getPackageManager();
    List<String> entries = new ArrayList<>();
    List<String> entryValues = new ArrayList<>();

    // Get default value.
    entries.add(getString(R.string.icon_pack_default));
    entryValues.add(getString(R.string.icon_pack_default_value));

    // Fetch all available icon pack.
    Intent intent = new Intent("org.adw.launcher.THEMES");
    List<ResolveInfo> info = manager.queryIntentActivities(intent,
            PackageManager.GET_META_DATA);
    for (ResolveInfo resolveInfo : info) {
        ActivityInfo activityInfo = resolveInfo.activityInfo;
        String packageName = activityInfo.packageName;
        String appName = activityInfo.loadLabel(manager).toString();
        entries.add(appName);
        entryValues.add(packageName);
    }

    CharSequence[] finalEntries = entries.toArray(new CharSequence[0]);
    CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]);

    list.setEntries(finalEntries);
    list.setEntryValues(finalEntryValues);
}
 
Example #22
Source File: LoginSettingsFragment.java    From tindroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference preference = findPreference(key);
    Context context = getContext();
    if (preference == null || context == null) {
        return;
    }

    switch (preference.getKey()) {
        case "pref_wireTransport":
            ListPreference listPreference = (ListPreference) preference;
            int prefIndex = listPreference.findIndexOfValue(sharedPreferences.getString(key,null));
            if (prefIndex >= 0) {
                preference.setSummary(getString(R.string.settings_wire_explained,
                        listPreference.getEntries()[prefIndex]));
            }
            break;
        case "pref_useTLS":
            break;
        case "pref_hostName":
            preference.setSummary(getString(R.string.settings_host_name_explained,
                    sharedPreferences.getString("pref_hostName", TindroidApp.getDefaultHostName(context))));
            break;
        default:
            Log.w(TAG, "Unknown preference '" + key + "'");
            // do nothing.
    }
}
 
Example #23
Source File: NotificationColorSettingsFragment.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initNotificationPart() {
    // notification custom color.
    findPreference(getString(R.string.key_notification_custom_color)).setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setNotificationCustomColorEnabled((Boolean) newValue);
        initNotificationPart();
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        return true;
    });

    // notification background.
    ColorPreferenceCompat notificationBackgroundColor = findPreference(getString(R.string.key_notification_background_color));
    notificationBackgroundColor.setEnabled(getSettingsOptionManager().isNotificationCustomColorEnabled());
    notificationBackgroundColor.setOnPreferenceChangeListener((preference, newValue) -> {
        getSettingsOptionManager().setNotificationBackgroundColor((Integer) newValue);
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        return true;
    });

    // notification text color.
    ListPreference notificationTextColor = findPreference(getString(R.string.key_notification_text_color));
    notificationTextColor.setSummary(
            getSettingsOptionManager().getNotificationTextColor().getNotificationTextColorName(
                    getActivity()
            )
    );
    notificationTextColor.setOnPreferenceChangeListener((preference, newValue) -> {
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        preference.setSummary(
                getSettingsOptionManager().getNotificationTextColor().getNotificationTextColorName(
                        getActivity()
                )
        );
        return true;
    });
}
 
Example #24
Source File: SettingsFragment.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateSummary(ListPreference pref, String val, String prefix) {
    int prefIndex = pref.findIndexOfValue(val);
    if (prefIndex >= 0) {
        //finally set's it value changed
        pref.setSummary(prefix + pref.getEntries()[prefIndex]);
    }
}
 
Example #25
Source File: PolicyManagementFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private void onCreateSetNewPasswordWithComplexityPreference() {
    ListPreference complexityPref =
        (ListPreference) findPreference(SET_NEW_PASSWORD_WITH_COMPLEXITY);
    List<CharSequence> entries = new ArrayList<>();
    List<CharSequence> values = new ArrayList<>();
    int size = PASSWORD_COMPLEXITY.size();
    for (int i = 0; i < size; i++) {
        entries.add(getString(PASSWORD_COMPLEXITY.valueAt(i)));
        values.add(Integer.toString(PASSWORD_COMPLEXITY.keyAt(i)));
    }
    complexityPref.setEntries(entries.toArray(new CharSequence[size]));
    complexityPref.setEntryValues(values.toArray(new CharSequence[size]));
    complexityPref.setOnPreferenceChangeListener(this);
}
 
Example #26
Source File: GeneralPrefsFragment.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
private void setupPrefs() {
    final ListPreference bookmarkCount = (ListPreference) findPreference(getString(R.string.nav_drawer_bookmark_count_pref));
    bookmarkCount.setSummary(String.valueOf(MimiPrefs.navDrawerBookmarkCount(getActivity())));
    bookmarkCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String val = String.valueOf(newValue);
            bookmarkCount.setSummary(val);

            return true;
        }
    });
}
 
Example #27
Source File: SettingsActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary(Preference preference, @NonNull Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else {
        preference.setSummary(stringValue);
    }
}
 
Example #28
Source File: DesktopPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ListPreference orientationMode = findPreference("orientation_mode");

    orientationMode.setOnPreferenceChangeListener(RotatingListListener);

    // Window bar hiding works only reliably in KitKat and above.
    if (Utils.atLeastKitKat()) {
        findPreference("windowbar_mode").setVisible(true);
    } else {
        findPreference("windowbar_status_switch").setVisible(true);
    }
}
 
Example #29
Source File: ListSummaryPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
  ListPreference listPref   = (ListPreference) preference;
  int            entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);

  listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length
                      ? listPref.getEntries()[entryIndex]
                      : getString(R.string.preferences__led_color_unknown));
  return true;
}
 
Example #30
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getAppList();

    ListPreference gestureLeftList = findPreference("gesture_left");
    ListPreference gestureRightList = findPreference("gesture_right");
    ListPreference gestureDownList = findPreference("gesture_down");
    ListPreference gestureUpList = findPreference("gesture_up");
    ListPreference gestureTapList = findPreference("gesture_single_tap");
    ListPreference gestureDoubleTapList = findPreference("gesture_double_tap");
    ListPreference gesturePinchList = findPreference("gesture_pinch");
    ListPreference gestureHandlerList = findPreference("gesture_handler");

    setNestedListSummary(gestureLeftList);
    setNestedListSummary(gestureRightList);
    setNestedListSummary(gestureDownList);
    setNestedListSummary(gestureUpList);
    setNestedListSummary(gestureTapList);
    setNestedListSummary(gestureDoubleTapList);
    setNestedListSummary(gesturePinchList);

    setGestureHandlerList(gestureHandlerList);
    gestureLeftList.setOnPreferenceChangeListener(NestingListListener);
    gestureRightList.setOnPreferenceChangeListener(NestingListListener);
    gestureDownList.setOnPreferenceChangeListener(NestingListListener);
    gestureUpList.setOnPreferenceChangeListener(NestingListListener);
    gestureDoubleTapList.setOnPreferenceChangeListener(NestingListListener);
    gestureTapList.setOnPreferenceChangeListener(NestingListListener);
    gesturePinchList.setOnPreferenceChangeListener(NestingListListener);
}