Java Code Examples for android.support.v7.preference.Preference#setVisible()

The following examples show how to use android.support.v7.preference.Preference#setVisible() . 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: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@SuppressWarnings("SameParameterValue")
protected Preference updatePreference(@StringRes int keyResId, @DrawableRes Integer iconRes, CharSequence title, CharSequence summary, Boolean visible) {
    Preference pref = findPreference(getString(keyResId));
    if (pref != null) {
        if (summary != null) {
            pref.setSummary(summary);
        }
        if (title != null) {
            pref.setTitle(title);
        }
        if (iconRes != null && iconRes != 0) {
            if (isAllowedToTint(pref)) {
                pref.setIcon(_cu.tintDrawable(iconRes, getIconTintColor()));
            } else {
                pref.setIcon(iconRes);
            }
        }
        if (visible != null) {
            pref.setVisible(visible);
        }
    }
    return pref;
}
 
Example 2
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
@Nullable
@SuppressWarnings("SameParameterValue")
protected Preference updatePreference(@StringRes int keyResId, @DrawableRes Integer iconRes, CharSequence title, CharSequence summary, Boolean visible) {
    Preference pref = findPreference(getString(keyResId));
    if (pref != null) {
        if (summary != null) {
            pref.setSummary(summary);
        }
        if (title != null) {
            pref.setTitle(title);
        }
        if (iconRes != null && iconRes != 0) {
            if (isAllowedToTint(pref)) {
                pref.setIcon(_cu.tintDrawable(iconRes, getIconTintColor()));
            } else {
                pref.setIcon(iconRes);
            }
        }
        if (visible != null) {
            pref.setVisible(visible);
        }
    }
    return pref;
}
 
Example 3
Source File: GsPreferenceFragmentCompat.java    From Stringlate with MIT License 6 votes vote down vote up
@Nullable
@SuppressWarnings("SameParameterValue")
protected Preference updatePreference(@StringRes int keyResId, @DrawableRes Integer iconRes, CharSequence title, CharSequence summary, Boolean visible) {
    Preference pref = findPreference(getString(keyResId));
    if (pref != null) {
        if (summary != null) {
            pref.setSummary(summary);
        }
        if (title != null) {
            pref.setTitle(title);
        }
        if (iconRes != null && iconRes != 0) {
            if (isAllowedToTint(pref)) {
                pref.setIcon(_cu.tintDrawable(iconRes, getIconTintColor()));
            } else {
                pref.setIcon(iconRes);
            }
        }
        if (visible != null) {
            pref.setVisible(visible);
        }
    }
    return pref;
}
 
Example 4
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 6 votes vote down vote up
@Nullable
@SuppressWarnings("SameParameterValue")
protected Preference updatePreference(@StringRes int keyResId, @DrawableRes Integer iconRes, CharSequence title, CharSequence summary, Boolean visible) {
    Preference pref = findPreference(getString(keyResId));
    if (pref != null) {
        if (summary != null) {
            pref.setSummary(summary);
        }
        if (title != null) {
            pref.setTitle(title);
        }
        if (iconRes != null && iconRes != 0) {
            if (isAllowedToTint(pref)) {
                pref.setIcon(_cu.tintDrawable(iconRes, getIconTintColor()));
            } else {
                pref.setIcon(iconRes);
            }
        }
        if (visible != null) {
            pref.setVisible(visible);
        }
    }
    return pref;
}
 
Example 5
Source File: AccountSettingsActivity.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferencesFix(savedInstanceState, rootKey);
    Preference pref = findPreference(PREF_AUTH_VISIBLE);
    if (pref != null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            pref.setVisible(false);
        } else {
            pref.setOnPreferenceChangeListener((preference, newValue) -> {
                if (newValue instanceof Boolean) {
                    AccountManager am = AccountManager.get(getContext());
                    for (Account account : am.getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE)) {
                        am.setAccountVisibility(account, PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE, (Boolean) newValue ? VISIBILITY_USER_MANAGED_VISIBLE : VISIBILITY_USER_MANAGED_NOT_VISIBLE);
                    }
                }
                return true;
            });
        }
    }
}
 
Example 6
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds a {@link Preference} based on its key res id.
 *
 * @param key The key of the preference to retrieve.
 * @return The {@link Preference} with the key, or null.
 * @see android.support.v7.preference.PreferenceGroup#findPreference(CharSequence)
 */
public Preference setPreferenceVisible(@StringRes int key, boolean visible) {
    Preference pref;
    if ((pref = findPreference(key)) != null) {
        pref.setVisible(visible);
    }
    return pref;
}
 
Example 7
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Finds a {@link Preference} based on its key res id.
 *
 * @param key The key of the preference to retrieve.
 * @return The {@link Preference} with the key, or null.
 * @see android.support.v7.preference.PreferenceGroup#findPreference(CharSequence)
 */
public Preference setPreferenceVisible(@StringRes int key, boolean visible) {
    Preference pref;
    if ((pref = findPreference(key)) != null) {
        pref.setVisible(visible);
    }
    return pref;
}
 
Example 8
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 5 votes vote down vote up
/**
 * Finds a {@link Preference} based on its key res id.
 *
 * @param key The key of the preference to retrieve.
 * @return The {@link Preference} with the key, or null.
 * @see android.support.v7.preference.PreferenceGroup#findPreference(CharSequence)
 */
public Preference setPreferenceVisible(@StringRes int key, boolean visible) {
    Preference pref;
    if ((pref = findPreference(key)) != null) {
        pref.setVisible(visible);
    }
    return pref;
}
 
Example 9
Source File: SettingsActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void invalidateSettings() {
    Preference findPreference = findPreference("changelog");
    findPreference.setOnPreferenceClickListener(preference -> {
        openUrl(Constants.TELEGRAM_CHANGE_LOG);
        return true;
    });
    findPreference = findPreference("day_dream");
    findPreference.setVisible(false);
    findPreference.setOnPreferenceClickListener(preference -> {
        Intent intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
        startActivity(intent);
        return true;
    });
    findPreference = findPreference("user_info");
    findPreference.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getContext(), UserInfoActivity.class));
        return true;
    });
    findPreference = findPreference("open_source");
    findPreference.setOnPreferenceClickListener(preference -> {
        showLicenseDialog();
        return true;
    });
    findPreference = findPreference("about");
    findPreference.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getContext(), AboutActivity.class));
        return true;
    });
    findPreference = findPreference("app_version");
    try {
        PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        findPreference.setSummary(packageInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    TwoStatePreference toggleVolume = (TwoStatePreference) findPreference("toggle_volume");
    toggleVolume.setOnPreferenceChangeListener((preference, o) -> {
        Toast.makeText(getContext(), "Restart app!", Toast.LENGTH_SHORT).show();
        getActivity().recreate();
        return true;
    });
    TwoStatePreference colorAppShortcuts = (TwoStatePreference) findPreference("should_color_app_shortcuts");
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
        colorAppShortcuts.setVisible(false);
    } else {
        colorAppShortcuts.setChecked(PreferenceUtil.getInstance(getActivity()).coloredAppShortcuts());
        colorAppShortcuts.setOnPreferenceChangeListener((preference, newValue) -> {
            // Save preference
            PreferenceUtil.getInstance(getActivity()).setColoredAppShortcuts((Boolean) newValue);

            // Update app shortcuts
            new DynamicShortcutManager(getActivity()).updateDynamicShortcuts();

            return true;
        });
    }

    TwoStatePreference cornerWindow = (TwoStatePreference) findPreference("corner_window");
    cornerWindow.setOnPreferenceChangeListener((preference, newValue) -> {
        Toast.makeText(getContext(), "Restart app!", Toast.LENGTH_SHORT).show();
        getActivity().recreate();
        return true;
    });
}