java类android.preference.PreferenceGroup的实例源码

SettingsFragment.java 文件源码 项目:latex-it 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 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);
        }
    }

}
SettingsActivity.java 文件源码 项目:android-nmea-logger 阅读 26 收藏 0 点赞 0 评论 0
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++;
        }
    }
}
SettingsFragment.java 文件源码 项目:RBTV-Sendeplan 阅读 35 收藏 0 点赞 0 评论 0
@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);
        }
    }
}
CameraSettingsActivity.java 文件源码 项目:Camera2 阅读 16 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
CameraSettingsActivity.java 文件源码 项目:Camera2 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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;
}
TalkBackPreferencesActivity.java 文件源码 项目:talkback 阅读 26 收藏 0 点赞 0 评论 0
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);
}
TalkBackPreferencesActivity.java 文件源码 项目:talkback 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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);
}
TalkBackPreferencesActivity.java 文件源码 项目:talkback 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
TalkBackPreferencesActivity.java 文件源码 项目:talkback 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
TalkBackPreferencesActivity.java 文件源码 项目:talkback 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号