android.preference.Preference#setFragment ( )源码实例Demo

下面列出了android.preference.Preference#setFragment ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openboard   文件: UserDictionaryList.java
/**
 * Create a single User Dictionary Preference object, with its parameters set.
 * @param localeString The locale for which this user dictionary is for.
 * @return The corresponding preference.
 */
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
    final Preference newPref = new Preference(getActivity());
    final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
    if (null == localeString) {
        newPref.setTitle(Locale.getDefault().getDisplayName());
    } else {
        if (localeString.isEmpty()) {
            newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
        } else {
            newPref.setTitle(
                    LocaleUtils.constructLocaleFromString(localeString).getDisplayName());
        }
        intent.putExtra("locale", localeString);
        newPref.getExtras().putString("locale", localeString);
    }
    newPref.setIntent(intent);
    newPref.setFragment(UserDictionarySettings.class.getName());
    return newPref;
}
 
源代码2 项目: openboard   文件: CorrectionSettingsFragment.java
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
    final Activity activity = getActivity();
    final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
    if (null == localeList) {
        // The locale list is null if and only if the user dictionary service is
        // not present or disabled. In this case we need to remove the preference.
        getPreferenceScreen().removePreference(userDictionaryPreference);
    } else if (localeList.size() <= 1) {
        userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
        // If the size of localeList is 0, we don't set the locale parameter in the
        // extras. This will be interpreted by the UserDictionarySettings class as
        // meaning "the current locale".
        // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
        // the locale list always has at least one element, since it always includes the current
        // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
        if (localeList.size() == 1) {
            final String locale = (String)localeList.toArray()[0];
            userDictionaryPreference.getExtras().putString("locale", locale);
        }
    } else {
        userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
    }
}
 
源代码3 项目: Android-Keyboard   文件: UserDictionaryList.java
/**
 * Create a single User Dictionary Preference object, with its parameters set.
 * @param localeString The locale for which this user dictionary is for.
 * @return The corresponding preference.
 */
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
    final Preference newPref = new Preference(getActivity());
    final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
    if (null == localeString) {
        newPref.setTitle(Locale.getDefault().getDisplayName());
    } else {
        if (localeString.isEmpty()) {
            newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
        } else {
            newPref.setTitle(
                    LocaleUtils.constructLocaleFromString(localeString).getDisplayName());
        }
        intent.putExtra("locale", localeString);
        newPref.getExtras().putString("locale", localeString);
    }
    newPref.setIntent(intent);
    newPref.setFragment(UserDictionarySettings.class.getName());
    return newPref;
}
 
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
    final Activity activity = getActivity();
    final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
    if (null == localeList) {
        // The locale list is null if and only if the user dictionary service is
        // not present or disabled. In this case we need to remove the preference.
        getPreferenceScreen().removePreference(userDictionaryPreference);
    } else if (localeList.size() <= 1) {
        userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
        // If the size of localeList is 0, we don't set the locale parameter in the
        // extras. This will be interpreted by the UserDictionarySettings class as
        // meaning "the current locale".
        // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
        // the locale list always has at least one element, since it always includes the current
        // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
        if (localeList.size() == 1) {
            final String locale = (String)localeList.toArray()[0];
            userDictionaryPreference.getExtras().putString("locale", locale);
        }
    } else {
        userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
    }
}
 
源代码5 项目: AOSP-Kayboard-7.1.2   文件: UserDictionaryList.java
/**
 * Create a single User Dictionary Preference object, with its parameters set.
 * @param localeString The locale for which this user dictionary is for.
 * @return The corresponding preference.
 */
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
    final Preference newPref = new Preference(getActivity());
    final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
    if (null == localeString) {
        newPref.setTitle(Locale.getDefault().getDisplayName());
    } else {
        if (localeString.isEmpty()) {
            newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
        } else {
            newPref.setTitle(
                    LocaleUtils.constructLocaleFromString(localeString).getDisplayName());
        }
        intent.putExtra("locale", localeString);
        newPref.getExtras().putString("locale", localeString);
    }
    newPref.setIntent(intent);
    newPref.setFragment(UserDictionarySettings.class.getName());
    return newPref;
}
 
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
    final Activity activity = getActivity();
    final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
    if (null == localeList) {
        // The locale list is null if and only if the user dictionary service is
        // not present or disabled. In this case we need to remove the preference.
        getPreferenceScreen().removePreference(userDictionaryPreference);
    } else if (localeList.size() <= 1) {
        userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
        // If the size of localeList is 0, we don't set the locale parameter in the
        // extras. This will be interpreted by the UserDictionarySettings class as
        // meaning "the current locale".
        // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
        // the locale list always has at least one element, since it always includes the current
        // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
        if (localeList.size() == 1) {
            final String locale = (String)localeList.toArray()[0];
            userDictionaryPreference.getExtras().putString("locale", locale);
        }
    } else {
        userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
    }
}
 
源代码7 项目: delion   文件: ManagedPreferenceDelegate.java
/**
 * Initializes the Preference based on the state of any policies that may affect it,
 * e.g. by showing a managed icon or disabling clicks on the preference.
 *
 * This should be called once, before the preference is displayed.
 */
public void initPreference(Preference preference) {
    if (isPreferenceControlledByPolicy(preference)) {
        preference.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());

        if (isPreferenceClickDisabledByPolicy(preference)) {
            // Disable the views and prevent the Preference from mucking with the enabled state.
            preference.setShouldDisableView(false);

            // Prevent default click behavior.
            preference.setFragment(null);
            preference.setIntent(null);
            preference.setOnPreferenceClickListener(null);
        }
    }
}
 
源代码8 项目: delion   文件: AutofillPreferences.java
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
源代码9 项目: delion   文件: AutofillPreferences.java
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
/**
 * Initializes the Preference based on the state of any policies that may affect it,
 * e.g. by showing a managed icon or disabling clicks on the preference.
 *
 * This should be called once, before the preference is displayed.
 */
public void initPreference(Preference preference) {
    if (isPreferenceControlledByPolicy(preference)) {
        preference.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());

        if (isPreferenceClickDisabledByPolicy(preference)) {
            // Disable the views and prevent the Preference from mucking with the enabled state.
            preference.setShouldDisableView(false);

            // Prevent default click behavior.
            preference.setFragment(null);
            preference.setIntent(null);
            preference.setOnPreferenceClickListener(null);
        }
    }
}
 
源代码11 项目: AndroidChromium   文件: UsbChooserPreferences.java
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_chooser_preferences);

    if (mPermissionsByObject.isEmpty() && mSearch.isEmpty() && mEmptyView != null) {
        mEmptyView.setText(R.string.website_settings_usb_no_devices);
    }

    for (Pair<ArrayList<UsbInfo>, ArrayList<Website>> entry : mPermissionsByObject.values()) {
        Preference preference = new Preference(getActivity());
        Bundle extras = preference.getExtras();
        extras.putInt(UsbDevicePreferences.EXTRA_CATEGORY, mCategory.toContentSettingsType());
        extras.putString(
                SingleCategoryPreferences.EXTRA_TITLE, getActivity().getTitle().toString());
        extras.putSerializable(UsbDevicePreferences.EXTRA_USB_INFOS, entry.first);
        extras.putSerializable(UsbDevicePreferences.EXTRA_SITES, entry.second);
        preference.setIcon(R.drawable.settings_usb);
        preference.setTitle(entry.first.get(0).getName());
        preference.setFragment(UsbDevicePreferences.class.getCanonicalName());
        getPreferenceScreen().addPreference(preference);
    }
}
 
源代码12 项目: AndroidChromium   文件: UsbDevicePreferences.java
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_device_preferences);

    PreferenceScreen preferenceScreen = getPreferenceScreen();
    Preference header = preferenceScreen.findPreference(PREF_OBJECT_NAME);
    header.setTitle(mUsbInfo.getName());
    header.setOnPreferenceClickListener(this);

    for (int i = 0; i < mSites.size(); ++i) {
        Website site = mSites.get(i);
        Preference preference = new WebsitePreference(getActivity(), site, mCategory);
        preference.getExtras().putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
        preference.setFragment(SingleWebsitePreferences.class.getCanonicalName());
        preferenceScreen.addPreference(preference);
    }

    // Force this list to be reloaded if the activity is resumed.
    mSites = null;
}
 
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
    final Activity activity = getActivity();
    final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
    if (null == localeList) {
        // The locale list is null if and only if the user dictionary service is
        // not present or disabled. In this case we need to remove the preference.
        getPreferenceScreen().removePreference(userDictionaryPreference);
    } else if (localeList.size() <= 1) {
        userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
        // If the size of localeList is 0, we don't set the locale parameter in the
        // extras. This will be interpreted by the UserDictionarySettings class as
        // meaning "the current locale".
        // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
        // the locale list always has at least one element, since it always includes the current
        // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
        if (localeList.size() == 1) {
            final String locale = (String)localeList.toArray()[0];
            userDictionaryPreference.getExtras().putString("locale", locale);
        }
    } else {
        userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
    }
}
 
源代码14 项目: AndroidChromium   文件: AutofillPreferences.java
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
源代码15 项目: 365browser   文件: ManagedPreferenceDelegate.java
/**
 * Initializes the Preference based on the state of any policies that may affect it,
 * e.g. by showing a managed icon or disabling clicks on the preference.
 *
 * This should be called once, before the preference is displayed.
 */
public void initPreference(Preference preference) {
    if (isPreferenceControlledByPolicy(preference)) {
        preference.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
    } else if (isPreferenceControlledByCustodian(preference)) {
        preference.setIcon(R.drawable.ic_account_child_grey600_36dp);
    }

    if (isPreferenceClickDisabledByPolicy(preference)) {
        // Disable the views and prevent the Preference from mucking with the enabled state.
        preference.setShouldDisableView(false);

        // Prevent default click behavior.
        preference.setFragment(null);
        preference.setIntent(null);
        preference.setOnPreferenceClickListener(null);
    }
}
 
源代码16 项目: 365browser   文件: UsbChooserPreferences.java
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_chooser_preferences);

    if (mPermissionsByObject.isEmpty() && mSearch.isEmpty() && mEmptyView != null) {
        mEmptyView.setText(R.string.website_settings_usb_no_devices);
    }

    for (Pair<ArrayList<UsbInfo>, ArrayList<Website>> entry : mPermissionsByObject.values()) {
        Preference preference = new Preference(getActivity());
        Bundle extras = preference.getExtras();
        extras.putInt(UsbDevicePreferences.EXTRA_CATEGORY, mCategory.toContentSettingsType());
        extras.putString(
                SingleCategoryPreferences.EXTRA_TITLE, getActivity().getTitle().toString());
        extras.putSerializable(UsbDevicePreferences.EXTRA_USB_INFOS, entry.first);
        extras.putSerializable(UsbDevicePreferences.EXTRA_SITES, entry.second);
        preference.setIcon(R.drawable.settings_usb);
        preference.setTitle(entry.first.get(0).getName());
        preference.setFragment(UsbDevicePreferences.class.getCanonicalName());
        getPreferenceScreen().addPreference(preference);
    }
}
 
源代码17 项目: 365browser   文件: UsbDevicePreferences.java
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_device_preferences);

    PreferenceScreen preferenceScreen = getPreferenceScreen();
    Preference header = preferenceScreen.findPreference(PREF_OBJECT_NAME);
    header.setTitle(mUsbInfo.getName());
    header.setOnPreferenceClickListener(this);

    for (int i = 0; i < mSites.size(); ++i) {
        Website site = mSites.get(i);
        Preference preference = new WebsitePreference(getActivity(), site, mCategory);
        preference.getExtras().putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
        preference.setFragment(SingleWebsitePreferences.class.getCanonicalName());
        preferenceScreen.addPreference(preference);
    }

    // Force this list to be reloaded if the activity is resumed.
    mSites = null;
}
 
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.addPreferencesFromResource(this, R.xml.autofill_and_payments_preferences);
    getActivity().setTitle(R.string.prefs_autofill_and_payments);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
        Preference pref = new Preference(getActivity());
        pref.setTitle(getActivity().getString(R.string.payment_apps_title));
        pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName());
        pref.setShouldDisableView(true);
        pref.setKey(PREF_ANDROID_PAYMENT_APPS);
        getPreferenceScreen().addPreference(pref);
    }
}
 
源代码19 项目: Indic-Keyboard   文件: UserDictionaryList.java
/**
 * Create a single User Dictionary Preference object, with its parameters set.
 * @param localeString The locale for which this user dictionary is for.
 * @return The corresponding preference.
 */
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
    final Preference newPref = new Preference(getActivity());
    final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
    if (null == localeString) {
        newPref.setTitle(Locale.getDefault().getDisplayName());
    } else {
        if (localeString.isEmpty()) {
            newPref.setTitle(getString(R.string.user_dict_settings_all_languages));
        } else {
            newPref.setTitle(
                    LocaleUtils.constructLocaleFromString(localeString).getDisplayName());
        }
        intent.putExtra("locale", localeString);
        newPref.getExtras().putString("locale", localeString);
    }
    newPref.setIntent(intent);
    newPref.setFragment(UserDictionarySettings.class.getName());
    return newPref;
}
 
源代码20 项目: CSipSimple   文件: PrefsLoaderFragment.java
private void setPreferenceScreenType(Class<?> classObj, String key, int type) {
    Preference pf = findPreference(key);
    pf.setFragment(classObj.getCanonicalName());
    Bundle b = pf.getExtras();
    b.putInt(PrefsLogic.EXTRA_PREFERENCE_TYPE, type);
}