Java Code Examples for android.preference.PreferenceScreen#setSummary()

The following examples show how to use android.preference.PreferenceScreen#setSummary() . 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: SettingsFragment.java    From NewsPushMonitor with Apache License 2.0 5 votes vote down vote up
private void addMonitorApp(String pkg) {
    if (TextUtils.isEmpty(pkg)) {
        return;
    }

    PreferenceManager manager = getPreferenceManager();
    try {
        PreferenceScreen screen = (PreferenceScreen) RefUtil.callDeclaredMethod(manager,
                "inflateFromResource",
                new Class[]{Context.class, int.class, PreferenceScreen.class},
                getActivity(), R.xml.prefs_monitor_apps, null);
        screen.setKey(pkg);
        screen.setTitle(pkg);
        screen.setSummary(getMonitorAppSummary(pkg, null));

        PreferenceGroup appConfigPref = (PreferenceGroup) screen.findPreference("monitor_app_config_pref");
        appConfigPref.setTitle(pkg);

        Preference titleViewIdPref = appConfigPref.findPreference("title_view_id_pref");
        titleViewIdPref.setKey(GlobalConfig.getSharedPrefKeyForTitleId(pkg));
        titleViewIdPref.getExtras().putString(KEY_PREF_EXTRA, pkg);
        titleViewIdPref.setOnPreferenceChangeListener(mOnPreferenceChangeListener);

        Preference contentViewIdPref = appConfigPref.findPreference("content_view_id_pref");
        contentViewIdPref.setKey(GlobalConfig.getSharedPrefKeyForContentId(pkg));
        contentViewIdPref.getExtras().putString(KEY_PREF_EXTRA, pkg);
        contentViewIdPref.setOnPreferenceChangeListener(mOnPreferenceChangeListener);

        PreferenceCategory container = (PreferenceCategory)
                getPreferenceManager().findPreference("monitor_apps_pref");
        container.addPreference(screen);
    } catch (Exception e) {
        LogWriter.e(TAG, "Add monitor ppp to preference error!", e);
    }
}
 
Example 2
Source File: SavePasswordsPreferences.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void passwordListAvailable(int count) {
    resetList(PREF_CATEGORY_SAVED_PASSWORDS);
    mNoPasswords = count == 0;
    if (mNoPasswords) {
        if (mNoPasswordExceptions) displayEmptyScreenMessage();
        return;
    }

    displayManageAccountLink();

    PreferenceCategory profileCategory = new PreferenceCategory(getActivity());
    profileCategory.setKey(PREF_CATEGORY_SAVED_PASSWORDS);
    profileCategory.setTitle(R.string.section_saved_passwords);
    profileCategory.setOrder(ORDER_SAVED_PASSWORDS);
    getPreferenceScreen().addPreference(profileCategory);
    for (int i = 0; i < count; i++) {
        PasswordUIView.SavedPasswordEntry saved =
                mPasswordManagerHandler.getSavedPasswordEntry(i);
        PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
        String url = saved.getUrl();
        String name = saved.getUserName();
        screen.setTitle(url);
        screen.setOnPreferenceClickListener(this);
        screen.setSummary(name);
        Bundle args = screen.getExtras();
        args.putString(PASSWORD_LIST_NAME, name);
        args.putString(PASSWORD_LIST_URL, url);
        args.putInt(PASSWORD_LIST_ID, i);
        profileCategory.addPreference(screen);
    }
}
 
Example 3
Source File: SavePasswordsPreferences.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void passwordListAvailable(int count) {
    resetList(PREF_CATEGORY_SAVED_PASSWORDS);
    mNoPasswords = count == 0;
    if (mNoPasswords) {
        if (mNoPasswordExceptions) displayEmptyScreenMessage();
        return;
    }

    displayManageAccountLink();

    PreferenceCategory profileCategory = new PreferenceCategory(getActivity());
    profileCategory.setKey(PREF_CATEGORY_SAVED_PASSWORDS);
    profileCategory.setTitle(R.string.section_saved_passwords);
    profileCategory.setOrder(ORDER_SAVED_PASSWORDS);
    getPreferenceScreen().addPreference(profileCategory);
    for (int i = 0; i < count; i++) {
        PasswordUIView.SavedPasswordEntry saved =
                mPasswordManagerHandler.getSavedPasswordEntry(i);
        PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
        String url = saved.getUrl();
        String name = saved.getUserName();
        screen.setTitle(url);
        screen.setOnPreferenceClickListener(this);
        screen.setSummary(name);
        Bundle args = screen.getExtras();
        args.putString(PASSWORD_LIST_NAME, name);
        args.putString(PASSWORD_LIST_URL, url);
        args.putInt(PASSWORD_LIST_ID, i);
        profileCategory.addPreference(screen);
    }
}
 
Example 4
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void adjustAutoscanPrefs() {
  PreferenceScreen autoScanScreen =
      (PreferenceScreen) findPreference(R.string.pref_category_auto_scan_key);
  PreferenceCategory movementAndSelectionCategory = getMovementAndSelectionCategory();
  Preference autoScanKeyPreference =
      movementAndSelectionCategory.findPreference(
          getString(R.string.pref_key_mapped_to_auto_scan_key));
  Preference reverseAutoScanKeyPreference =
      movementAndSelectionCategory.findPreference(
          getString(R.string.pref_key_mapped_to_reverse_auto_scan_key));

  boolean isAutoScanEnabled = SwitchAccessPreferenceUtils.isAutoScanEnabled(getActivity());
  if (isAutoScanEnabled) {
    autoScanScreen.setSummary(R.string.preference_on);
    autoScanKeyPreference.setTitle(R.string.title_pref_category_auto_scan);
    reverseAutoScanKeyPreference.setTitle(R.string.action_name_reverse_auto_scan);

    if (FeatureFlags.groupSelectionWithAutoScan()) {
      return;
    }

    if (SwitchAccessPreferenceUtils.isGroupSelectionEnabled(getActivity())) {
      /* If somehow both autoscan and group selection are enabled, turn off group selection. */
      SwitchAccessPreferenceUtils.setScanningMethod(
          getActivity(), R.string.row_col_scanning_key);
    }
  } else {
    autoScanScreen.setSummary(R.string.preference_off);
    autoScanKeyPreference.setTitle(R.string.title_pref_auto_scan_disabled);
    reverseAutoScanKeyPreference.setTitle(R.string.title_pref_reverse_auto_scan_disabled);
    if (SwitchAccessPreferenceUtils.isGroupSelectionEnabled(getActivity())
        && !FeatureFlags.groupSelectionWithAutoScan()) {
      findPreference(R.string.pref_category_auto_scan_key).setEnabled(false);
    }
  }
  ((BaseAdapter) autoScanScreen.getRootAdapter()).notifyDataSetChanged();
  ScanningMethodPreference scanMethodsPref = getScanningMethodPreference();
  scanMethodsPref.enableScanningMethod(R.string.group_selection_key, !isAutoScanEnabled);
}
 
Example 5
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void adjustPointScanPrefs() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
    // Remove point scan screen
    PreferenceCategory customizeScanningCategory =
        (PreferenceCategory) findPreference(R.string.pref_category_customize_scanning_key);
    customizeScanningCategory.removePreference(
        findPreference(R.string.pref_category_point_scan_key));
  } else {
    SwitchPreference pointScanPreference =
        (SwitchPreference) findPreference(R.string.pref_key_point_scan_enabled);
    String enableAnimationsMessage =
        ((VERSION.SDK_INT >= VERSION_CODES.O) && !ValueAnimator.areAnimatorsEnabled())
            ? getString(R.string.point_scan_enable_animations_message)
            : "";
    String pointScanPreferenceSummary =
        getString(R.string.summary_pref_point_scan, enableAnimationsMessage);
    pointScanPreference.setSummary(pointScanPreferenceSummary);
    pointScanPreference.setEnabled(
        (VERSION.SDK_INT < VERSION_CODES.O) || ValueAnimator.areAnimatorsEnabled());

    // Make sure the subtitle reflects Point scan state
    PreferenceScreen pointScanScreen =
        (PreferenceScreen) findPreference(R.string.pref_category_point_scan_key);
    if (SwitchAccessPreferenceUtils.isPointScanEnabled(getActivity())) {
      pointScanScreen.setSummary(R.string.preference_on);
    } else {
      pointScanScreen.setSummary(R.string.preference_off);
    }
    ((BaseAdapter) pointScanScreen.getRootAdapter()).notifyDataSetChanged();
  }
}
 
Example 6
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void adjustSpokenFeedbackPrefs() {
  PreferenceScreen spokenFeedbackScreen =
      (PreferenceScreen)
          findPreference(R.string.pref_key_category_switch_access_speech_sound_vibration);
  if (SwitchAccessPreferenceUtils.isSpokenFeedbackEnabled(getActivity())) {
    spokenFeedbackScreen.setSummary(R.string.preference_on);
  } else {
    spokenFeedbackScreen.setSummary(R.string.preference_off);
  }
  ((BaseAdapter) spokenFeedbackScreen.getRootAdapter()).notifyDataSetChanged();
}
 
Example 7
Source File: SavePasswordsPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void passwordListAvailable(int count) {
    resetList(PREF_CATEGORY_SAVED_PASSWORDS);
    resetList(PREF_CATEGORY_SAVED_PASSWORDS_NO_TEXT);

    mNoPasswords = count == 0;
    if (mNoPasswords) {
        if (mNoPasswordExceptions) displayEmptyScreenMessage();
        return;
    }

    displayManageAccountLink();

    PreferenceCategory profileCategory = new PreferenceCategory(getActivity());
    profileCategory.setKey(PREF_CATEGORY_SAVED_PASSWORDS);
    profileCategory.setTitle(R.string.section_saved_passwords);
    profileCategory.setOrder(ORDER_SAVED_PASSWORDS);
    getPreferenceScreen().addPreference(profileCategory);
    for (int i = 0; i < count; i++) {
        PasswordUIView.SavedPasswordEntry saved =
                mPasswordManagerHandler.getSavedPasswordEntry(i);
        PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
        String url = saved.getUrl();
        String name = saved.getUserName();
        screen.setTitle(url);
        screen.setOnPreferenceClickListener(this);
        screen.setSummary(name);
        Bundle args = screen.getExtras();
        args.putString(PASSWORD_LIST_NAME, name);
        args.putString(PASSWORD_LIST_URL, url);
        args.putInt(PASSWORD_LIST_ID, i);
        profileCategory.addPreference(screen);
    }
}
 
Example 8
Source File: SettingsActivity.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
protected void updatePrefsSummary(Preference pref) {
    if (pref == null) {
        return;
    }

    if (pref instanceof ListPreference) {
        ListPreference lst = (ListPreference) pref;
        String currentValue = lst.getValue();

        int index = lst.findIndexOfValue(currentValue);
        CharSequence[] entries = lst.getEntries();
        if (index >= 0 && index < entries.length) {
            pref.setSummary(entries[index]);
        }
    } else if (pref instanceof PreferenceScreen) {
        PreferenceScreen screen = (PreferenceScreen) pref;

        if (screen.getKey().equals(getString(R.string.prefs_key_account_info))) {
            if (mTokenStorage.isLoggedIn()) {
                screen.setSummary(getString(R.string.logged_in));
            } else {
                screen.setSummary(R.string.tap_to_sign_in);
            }
        }
    } else if (pref instanceof DragReorderActionsPreference) {
        pref.setSummary(pref.getSummary());
    }
}