Java Code Examples for android.preference.PreferenceCategory#findPreference()

The following examples show how to use android.preference.PreferenceCategory#findPreference() . 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 sms-ticket with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void fillDualSimList(PreferenceScreen preferenceScreen) {
    PreferenceCategory category = (PreferenceCategory) preferenceScreen.findPreference("sms_category");
    ListPreference preference = (ListPreference) category.findPreference(Preferences.DUALSIM_SIM);
    List<String> simIds = new ArrayList<>();
    List<String> simNames = new ArrayList<>();
    simIds.add(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    simNames.add(getString(R.string.sim_default));
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    for (SubscriptionInfo subscriptionInfo : subscriptionManager.getActiveSubscriptionInfoList()) {
        simIds.add(String.valueOf(subscriptionInfo.getSubscriptionId()));
        simNames.add(getString(R.string.sim_name, subscriptionInfo.getSimSlotIndex() + 1, subscriptionInfo
            .getDisplayName()));
    }
    preference.setEntries(simNames.toArray(new String[simNames.size()]));
    preference.setEntryValues(simIds.toArray(new String[simIds.size()]));
    preference.setDefaultValue(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    preference.setSummary(preference.getEntry());
}
 
Example 2
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 3
Source File: TalkBackKeyboardShortcutPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  keymap = getArguments().getString(BUNDLE_KEYMAP);

  PreferenceSettingsUtils.addPreferencesFromResource(this, getPreferenceResourceId(keymap));

  PreferenceScreen resetKeymapPreferenceScreen =
      (PreferenceScreen) findPreference(getString(R.string.pref_reset_keymap_key));
  resetKeymapPreferenceScreen.setOnPreferenceClickListener(resetKeymapPreferenceClickListener);

  boolean isArc = FeatureSupport.isArc();

  // Hide select keymap preference in Arc if current keymap is already set to default
  // keymap.
  if (isArc && getKeyComboManager().getKeyComboModel() instanceof DefaultKeyComboModel) {
    PreferenceCategory keymapPreferenceCategory =
        (PreferenceCategory)
            getPreferenceScreen().findPreference(getString(R.string.pref_keymap_category_key));
    ListPreference keymapListPreference =
        (ListPreference)
            keymapPreferenceCategory.findPreference(getString(R.string.pref_select_keymap_key));
    keymapPreferenceCategory.removePreference(keymapListPreference);
  }

  int[] hiddenShortcutKeyIds =
      isArc ? HIDDEN_SHORTCUT_KEY_IDS_IN_ARC : HIDDEN_SHORTCUT_KEY_IDS_IN_NON_ARC;
  Set<String> hiddenShortcutKeys = new HashSet<>();
  for (int id : hiddenShortcutKeyIds) {
    hiddenShortcutKeys.add(getString(id));
  }

  initPreferenceUIs(getPreferenceScreen(), hiddenShortcutKeys);
}
 
Example 4
Source File: SettingsFragment.java    From yahnac with Apache License 2.0 5 votes vote down vote up
private void configureAccountPreferences() {
    loginSharedPreferences = LoginSharedPreferences.newInstance();
    if (loginSharedPreferences.isLoggedIn()) {
        addPreferencesFromResource(R.xml.account_settings);
        PreferenceCategory accountCategory = (PreferenceCategory) findPreference(getString(R.string.settings_category_key_account));
        Preference logoutNotification = accountCategory.findPreference(getString(R.string.settings_key_logout));
        logoutNotification.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                listener.onShowLogoutDialog();
                return true;
            }
        });
    }
}
 
Example 5
Source File: SettingsFragment.java    From yahnac with Apache License 2.0 5 votes vote down vote up
private void addPreferenceClickListenerForCommunity() {
    PreferenceCategory communityCategory = (PreferenceCategory) findPreference(getString(R.string.settings_category_key_community));
    Preference communityPreference = communityCategory.findPreference(getString(R.string.settings_key_community));
    communityPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/108233780766400792163"));
            startActivity(browserIntent);
            return true;
        }

    });
}
 
Example 6
Source File: SettingsFragment.java    From yahnac with Apache License 2.0 5 votes vote down vote up
private void addPreferenceClickListenerForAppInvite() {
    PreferenceCategory communityCategory = (PreferenceCategory) findPreference(getString(R.string.settings_category_key_community));
    Preference invitePreference = communityCategory.findPreference(getString(R.string.settings_key_invite));
    invitePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            listener.onAppInviteRequested();
            return true;
        }

    });
}
 
Example 7
Source File: PrefFragment.java    From BlitzMail with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
	super.onResume();
	getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

	// recreate send now preference
	PreferenceCategory cat = (PreferenceCategory) findPreference("pref_sending");
	if(cat.findPreference("pref_send_now") != null) {
		cat.removePreference(findPreference("pref_send_now"));
	}
	addSendNowPref(getActivity());
}
 
Example 8
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 4 votes vote down vote up
private ScanningMethodPreference getScanningMethodPreference() {
  PreferenceCategory customizeScanningCategory =
      (PreferenceCategory) findPreference(R.string.pref_category_customize_scanning_key);
  return (ScanningMethodPreference)
      customizeScanningCategory.findPreference(getString(R.string.pref_scanning_methods_key));
}