Java 类android.preference.PreferenceGroup 实例源码

项目:lineagex86    文件:NotificationLightSettings.java   
private void setChildrenStarted(PreferenceGroup group, boolean started) {
    final int count = group.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference pref = group.getPreference(i);
        if (pref instanceof ApplicationLightPreference) {
            ApplicationLightPreference ap = (ApplicationLightPreference) pref;
            if (started) {
                ap.onStart();
            } else {
                ap.onStop();
            }
        } else if (pref instanceof PreferenceGroup) {
            setChildrenStarted((PreferenceGroup) pref, started);
        }
    }
}
项目:keepass2android    文件:InputLanguageSelection.java   
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
项目:order-by-android    文件:SettingsActivity.java   
@Override
public void onResume() {
    super.onResume();
    //Atribui os valores selecionados
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }
}
项目:order-by-android    文件:SettingsActivity.java   
@Override
public void onResume() {
    super.onResume();
    //Atribui os valores selecionados
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }
}
项目:IO_Classic_WatchFace    文件:SettingsFragment.java   
/**
 * Gets the list of preferences in a PreferenceScreen
 *
 * @param p    preference to add to the list
 * @param list of preferences in the PreferenceScreen
 * @return a list of all the preferences
 */
private ArrayList<Preference> getPreferenceList(Preference p, ArrayList<Preference> list) {
    if (p instanceof PreferenceCategory || p instanceof PreferenceScreen) {
        PreferenceGroup prefGroup = (PreferenceGroup) p;

        final int prefCount = prefGroup.getPreferenceCount();

        for (int i = 0; i < prefCount; i++) {
            getPreferenceList(prefGroup.getPreference(i), list);
        }
    }

    if (!(p instanceof PreferenceCategory)) {
        list.add(p);
    }

    return list;
}
项目:simple-keyboard    文件:CustomInputStyleSettingsFragment.java   
@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }

    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
项目:simple-keyboard    文件:CustomInputStyleSettingsFragment.java   
@Override
public void onAddCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey();
        mSubtypeEnablerNotificationDialog = createDialog();
        mSubtypeEnablerNotificationDialog.show();
        return;
    }

    // Newly added subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
项目:simple-keyboard    文件:TwoStatePreferenceHelper.java   
private static void replaceAllCheckBoxPreferencesBySwitchPreferences(
        final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference)preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup)preference);
            }
        }
    }
}
项目:chromium-for-android-56-debug-video    文件: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);
    }
}
项目:chromium-for-android-56-debug-video    文件: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);
    }
}
项目:AOSP-Kayboard-7.1.2    文件:UserDictionaryList.java   
/**
 * Creates the entries that allow the user to go into the user dictionary for each locale.
 * @param userDictGroup The group to put the settings in.
 */
protected void createUserDictSettings(final PreferenceGroup userDictGroup) {
    final Activity activity = getActivity();
    userDictGroup.removeAll();
    final TreeSet<String> localeSet =
            UserDictionaryList.getUserDictionaryLocalesSet(activity);

    if (localeSet.size() > 1) {
        // Have an "All languages" entry in the languages list if there are two or more active
        // languages
        localeSet.add("");
    }

    if (localeSet.isEmpty()) {
        userDictGroup.addPreference(createUserDictionaryPreference(null));
    } else {
        for (String locale : localeSet) {
            userDictGroup.addPreference(createUserDictionaryPreference(locale));
        }
    }
}
项目:AOSP-Kayboard-7.1.2    文件:CustomInputStyleSettingsFragment.java   
@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }

    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
项目:AOSP-Kayboard-7.1.2    文件:CustomInputStyleSettingsFragment.java   
@Override
public void onAddCustomInputStyle(final CustomInputStylePreference stylePref) {
    mIsAddingNewSubtype = false;
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        mSubtypePreferenceKeyForSubtypeEnabler = stylePref.getKey();
        mSubtypeEnablerNotificationDialog = createDialog();
        mSubtypeEnablerNotificationDialog.show();
        return;
    }

    // Newly added subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
项目:AOSP-Kayboard-7.1.2    文件:TwoStatePreferenceHelper.java   
private static void replaceAllCheckBoxPreferencesBySwitchPreferences(
        final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference)preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup)preference);
            }
        }
    }
}
项目:AOSP-Kayboard-7.1.2    文件:TwoStatePreferenceHelper.java   
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
        final PreferenceGroup group) {
    final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
    switchPref.setTitle(checkBox.getTitle());
    switchPref.setKey(checkBox.getKey());
    switchPref.setOrder(checkBox.getOrder());
    switchPref.setPersistent(checkBox.isPersistent());
    switchPref.setEnabled(checkBox.isEnabled());
    switchPref.setChecked(checkBox.isChecked());
    switchPref.setSummary(checkBox.getSummary());
    switchPref.setSummaryOn(checkBox.getSummaryOn());
    switchPref.setSummaryOff(checkBox.getSummaryOff());
    switchPref.setSwitchTextOn(EMPTY_TEXT);
    switchPref.setSwitchTextOff(EMPTY_TEXT);
    group.addPreference(switchPref);
    switchPref.setDependency(checkBox.getDependency());
}
项目:AOSP-Kayboard-7.1.2    文件:DictionarySettingsFragment.java   
private WordListPreference findWordListPreference(final String id) {
    final PreferenceGroup prefScreen = getPreferenceScreen();
    if (null == prefScreen) {
        Log.e(TAG, "Could not find the preference group");
        return null;
    }
    for (int i = prefScreen.getPreferenceCount() - 1; i >= 0; --i) {
        final Preference pref = prefScreen.getPreference(i);
        if (pref instanceof WordListPreference) {
            final WordListPreference wlPref = (WordListPreference)pref;
            if (id.equals(wlPref.mWordlistId)) {
                return wlPref;
            }
        }
    }
    Log.e(TAG, "Could not find the preference for a word list id " + id);
    return null;
}
项目:AOSP-Kayboard-7.1.2    文件:DictionarySettingsFragment.java   
void refreshInterface() {
    final Activity activity = getActivity();
    if (null == activity) return;
    final PreferenceGroup prefScreen = getPreferenceScreen();
    final Collection<? extends Preference> prefList =
            createInstalledDictSettingsCollection(mClientId);

    activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // TODO: display this somewhere
                // if (0 != lastUpdate) mUpdateNowPreference.setSummary(updateNowSummary);
                refreshNetworkState();

                removeAnyDictSettings(prefScreen);
                int i = 0;
                for (Preference preference : prefList) {
                    preference.setOrder(i++);
                    prefScreen.addPreference(preference);
                }
            }
        });
}
项目:KeePass2Android    文件:InputLanguageSelection.java   
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
项目:MaoMaoRobot    文件:Setting.java   
private void bind(PreferenceGroup group) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    for (int i = 0; i < group.getPreferenceCount(); i++) {
        Preference p = group.getPreference(i);
        if (p instanceof PreferenceGroup) {
            bind((PreferenceGroup) p);
        } else {
            if (p instanceof CheckBoxPreference) {
                ;
            } else {
                Object val = sp.getAll().get(p.getKey());
                p.setSummary(val == null ? "" : ("" + val));
                p.setOnPreferenceChangeListener(this);
            }
        }
    }
}
项目:haystack    文件:DevelopmentSettings.java   
@DexAppend
@Override
public void onCreate(Bundle icicle) {
    try {
        PreferenceGroup pg = (PreferenceGroup) findPreference(
                FakeSignatureGlobalUI.DEBUG_APPLICATIONS_CATEGORY_KEY);
        if (pg != null) {
            TwoStatePreference p = createTwoStatePreference(pg.getContext());
            p.setKey(FakeSignatureGlobalUI.SETTING_SECURE_KEY);
            p.setTitle(FakeSignatureGlobalUI.SETTING_TITLE);
            p.setSummary(FakeSignatureGlobalUI.SETTING_SUMMARY);
            p.setPersistent(false);
            mResetTwoStatePrefsAdd(p);
            mAllPrefs.add(p);
            //pg.setOrderingAsAdded(true);
            pg.addPreference(p);
            mAllowFakeSignatureGlobal = p;
        } else {
            Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "cannot find 'applications' preference category");
        }
    } catch (Throwable t) {
        Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "onCreate exception", t);
    }
}
项目:AndroidChromium    文件: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);
    }
}
项目: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);
    }
}
项目:Run-With-You    文件:SettingPreferenceFragment.java   
private void initPreferences() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        ((PreferenceGroup) findPreference(getString(R.string.pref_category_memory_resident))).removePreference(
                findPreference(getString(R.string.pref_memory_resident_white_list)));
    }

    Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e.onNext(mSettingRepository.getTargetStep());
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Integer>() {
        @Override
        public void accept(Integer target) throws Exception {
            findPreference(getString(R.string.pref_target_step)).setSummary(String.format(Locale.getDefault(),
                                                                                          "每日运动目标:%d步",
                                                                                          target));
        }
    });
}
项目:instalist-android    文件:SettingsFragment.java   
public void onEvent(final PluginFoundMessage _msg) {
    if (mInflater == null || mViewContainer == null) {
        Log.e(LOG_TAG, "onEvent: Faster than light, onCreateView was not called yet.");
        return;
    }

    PreferenceGroup preferenceGroup = new PreferenceCategory(mViewContainer.getContext());
    preferenceGroup.setTitle(_msg.mName);


    View prefView = preferenceGroup.getView(null, mViewContainer);
    /*prefView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), _msg.mSettingsActivity);
            startActivity(intent);
        }
    });*/
    ViewGroup viewGroup = (ViewGroup) mViewContainer.getChildAt(0);
    viewGroup.addView(prefView, viewGroup.getChildCount());

}
项目:Hupl    文件:GlobalSettingsActivity.java   
private List<Preference> getPreferenceList(Preference p, List<Preference> list)
{
    if (p instanceof PreferenceCategory || p instanceof PreferenceScreen)
    {
        PreferenceGroup g = (PreferenceGroup) p;
        int pCount = g.getPreferenceCount();
        for (int i = 0; i < pCount; i++)
        {
            getPreferenceList(g.getPreference(i), list);
        }
    }
    else
    {
        list.add(p);
    }
    return list;
}
项目:Vafrinn    文件: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().getProfiles()) {
        // 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);
    }
}
项目:Vafrinn    文件:AutofillPreferences.java   
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCards()) {
        // 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(AutofillCreditCardEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerCardPreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
项目:hackerskeyboard    文件:InputLanguageSelection.java   
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
项目:hackerskeyboard    文件:LatinIMESettings.java   
@Override
protected void onResume() {
    super.onResume();
    int autoTextSize = AutoText.getSize(getListView());
    if (autoTextSize < 1) {
        ((PreferenceGroup) findPreference(PREDICTION_SETTINGS_KEY))
                .removePreference(mQuickFixes);
    }

    Log.i(TAG, "compactModeEnabled=" + LatinIME.sKeyboardSettings.compactModeEnabled);
    if (!LatinIME.sKeyboardSettings.compactModeEnabled) {
        CharSequence[] oldEntries = mKeyboardModePortraitPreference.getEntries();
        CharSequence[] oldValues = mKeyboardModePortraitPreference.getEntryValues();

        if (oldEntries.length > 2) {
            CharSequence[] newEntries = new CharSequence[] { oldEntries[0], oldEntries[2] };
            CharSequence[] newValues = new CharSequence[] { oldValues[0], oldValues[2] };
            mKeyboardModePortraitPreference.setEntries(newEntries);
            mKeyboardModePortraitPreference.setEntryValues(newValues);
            mKeyboardModeLandscapePreference.setEntries(newEntries);
            mKeyboardModeLandscapePreference.setEntryValues(newValues);
        }
    }

    updateSummaries();
}
项目:AndroidPreferenceActivity    文件:PreferenceFragment.java   
/**
 * Restores the default preferences, which are contained by a specific preference group.
 *
 * @param preferenceGroup
 *         The preference group, whose preferences should be restored, as an instance of the
 *         class {@link PreferenceGroup}. The preference group may not be null
 * @param sharedPreferences
 *         The shared preferences, which should be used to restore the preferences, as an
 *         instance of the type {@link SharedPreferences}. The shared preferences may not be
 *         null
 */
private void restoreDefaults(@NonNull final PreferenceGroup preferenceGroup,
                             @NonNull final SharedPreferences sharedPreferences) {
    for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
        Preference preference = preferenceGroup.getPreference(i);

        if (preference instanceof PreferenceGroup) {
            restoreDefaults((PreferenceGroup) preference, sharedPreferences);
        } else if (preference.getKey() != null && !preference.getKey().isEmpty()) {
            Object oldValue = sharedPreferences.getAll().get(preference.getKey());

            if (notifyOnRestoreDefaultValueRequested(preference, oldValue)) {
                sharedPreferences.edit().remove(preference.getKey()).apply();
                preferenceGroup.removePreference(preference);
                preferenceGroup.addPreference(preference);
                Object newValue = sharedPreferences.getAll().get(preference.getKey());
                notifyOnRestoredDefaultValue(preference, oldValue, newValue);
            } else {
                preferenceGroup.removePreference(preference);
                preferenceGroup.addPreference(preference);
            }

        }
    }
}
项目:latex-it    文件:SettingsFragment.java   
/**
 * On resume it update every settings.
 */
@Override
public void onResume() {
    super.onResume();
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }

}
项目:android-nmea-logger    文件:SettingsActivity.java   
private void hideAdvancedPreferences(PreferenceGroup group) {
    if(mAdvancedSettings.showAll()) {
        return;
    }

    int c = 0;
    while(c < group.getPreferenceCount()) {
        Preference pref = group.getPreference(c);
        if(!mAdvancedSettings.isVisible(group, pref)) {
            group.removePreference(pref);
        } else {
            if(pref instanceof PreferenceGroup) {
                hideAdvancedPreferences((PreferenceGroup)pref);
            }
            c++;
        }
    }
}
项目:RBTV-Sendeplan    文件:SettingsFragment.java   
@Override
public void onResume() {
    super.onResume();

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();

    // Register self als listener for changes
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);

    // Set initial summary state
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        Preference preference = getPreferenceScreen().getPreference(i);

        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); j++) {
                updatePreferenceSummary(sharedPreferences, preferenceGroup.getPreference(j));
            }
        } else {
            updatePreferenceSummary(sharedPreferences, preference);
        }
    }
}
项目:Camera2    文件:CameraSettingsActivity.java   
/**
 * Depending on camera availability on the device, this removes settings
 * for cameras the device doesn't have.
 */
private void setVisibilities() {
    PreferenceGroup resolutions =
            (PreferenceGroup) findPreference(PREF_CATEGORY_RESOLUTION);
    if (mPictureSizesBack == null) {
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_PICTURE_SIZE_BACK));
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_VIDEO_QUALITY_BACK));
    }
    if (mPictureSizesFront == null) {
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_PICTURE_SIZE_FRONT));
        recursiveDelete(resolutions,
                findPreference(Keys.KEY_VIDEO_QUALITY_FRONT));
    }
}
项目:Camera2    文件:CameraSettingsActivity.java   
/**
 * Recursively traverses the tree from the given group as the route and
 * tries to delete the preference. Traversal stops once the preference
 * was found and removed.
 */
private boolean recursiveDelete(PreferenceGroup group, Preference preference) {
    if (group == null) {
        Log.d(TAG, "attempting to delete from null preference group");
        return false;
    }
    if (preference == null) {
        Log.d(TAG, "attempting to delete null preference");
        return false;
    }
    if (group.removePreference(preference)) {
        // Removal was successful.
        return true;
    }

    for (int i = 0; i < group.getPreferenceCount(); ++i) {
        Preference pref = group.getPreference(i);
        if (pref instanceof PreferenceGroup) {
            if (recursiveDelete((PreferenceGroup) pref, preference)) {
                return true;
            }
        }
    }
    return false;
}
项目:talkback    文件:TalkBackPreferencesActivity.java   
private void assignPlayStoreIntentToPreference(int preferenceId, String url) {
    final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
            R.string.pref_category_miscellaneous_key);
    final Preference pref = findPreferenceByResId(preferenceId);
    if (pref == null) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    if (!canHandleIntent(intent)) {
        category.removePreference(pref);
        return;
    }

    pref.setIntent(intent);
}
项目:talkback    文件:TalkBackPreferencesActivity.java   
/**
 * Assigns the intent to open text-to-speech settings.
 */
private void assignTtsSettingsIntent() {
    PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
        R.string.pref_category_when_to_speak_key);
    Preference ttsSettingsPreference =
            findPreferenceByResId(R.string.pref_tts_settings_key);

    if (category == null || ttsSettingsPreference == null) {
        return;
    }

    Intent ttsSettingsIntent = new Intent(TalkBackService.INTENT_TTS_SETTINGS);
    ttsSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (!canHandleIntent(ttsSettingsIntent)) {
        // Need to remove preference item if no TTS Settings intent filter in settings app.
        category.removePreference(ttsSettingsPreference);
    }

    ttsSettingsPreference.setIntent(ttsSettingsIntent);
}
项目:talkback    文件:TalkBackPreferencesActivity.java   
/**
 * Assigns the appropriate intent to the tutorial preference.
 */
private void assignTutorialIntent() {
    final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
            R.string.pref_category_miscellaneous_key);
    final Preference prefTutorial = findPreferenceByResId(R.string.pref_tutorial_key);

    if ((category == null) || (prefTutorial == null)) {
        return;
    }

    final int touchscreenState = getResources().getConfiguration().touchscreen;
    if (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) {
        category.removePreference(prefTutorial);
        return;
    }

    Activity activity = getActivity();
    if (activity != null) {
        final Intent tutorialIntent = new Intent(
                activity, AccessibilityTutorialActivity.class);
        tutorialIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        tutorialIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        prefTutorial.setIntent(tutorialIntent);
    }
}
项目:talkback    文件:TalkBackPreferencesActivity.java   
/**
 * Assigns the appropriate intent to the label manager preference.
 */
private void assignLabelManagerIntent() {
    final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
            R.string.pref_category_touch_exploration_key);
    final Preference prefManageLabels = findPreferenceByResId(
            R.string.pref_manage_labels_key);

    if ((category == null) || (prefManageLabels == null)) {
        return;
    }

    if (Build.VERSION.SDK_INT < LabelManagerSummaryActivity.MIN_API_LEVEL) {
        category.removePreference(prefManageLabels);
        return;
    }

    Activity activity = getActivity();
    if (activity != null) {
        final Intent labelManagerIntent = new Intent(
                activity, LabelManagerSummaryActivity.class);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        prefManageLabels.setIntent(labelManagerIntent);
    }
}
项目:talkback    文件:TalkBackPreferencesActivity.java   
/**
 * Assigns the appropriate intent to the keyboard shortcut preference.
 */
private void assignKeyboardShortcutIntent() {
    final PreferenceGroup category =
            (PreferenceGroup) findPreferenceByResId(
                    R.string.pref_category_miscellaneous_key);
    final Preference keyboardShortcutPref = findPreferenceByResId(
            R.string.pref_category_manage_keyboard_shortcut_key);

    if ((category == null) || (keyboardShortcutPref == null)) {
        return;
    }

    if (Build.VERSION.SDK_INT < KeyComboManager.MIN_API_LEVEL) {
        category.removePreference(keyboardShortcutPref);
        return;
    }

    Activity activity = getActivity();
    if (activity != null) {
        final Intent labelManagerIntent = new Intent(activity,
                TalkBackKeyboardShortcutPreferencesActivity.class);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        keyboardShortcutPref.setIntent(labelManagerIntent);
    }
}