Search in sources :

Example 86 with PreferenceScreen

use of android.preference.PreferenceScreen in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsFragment method appendViewAllSitesOption.

private void appendViewAllSitesOption(Context context) {
    PreferenceCategory blogsCategory = (PreferenceCategory) findPreference(getString(R.string.pref_notification_blogs));
    PreferenceScreen prefScreen = getPreferenceManager().createPreferenceScreen(context);
    prefScreen.setTitle(R.string.all_your_sites);
    addSitesForViewAllSitesScreen(prefScreen);
    blogsCategory.addPreference(prefScreen);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory)

Example 87 with PreferenceScreen

use of android.preference.PreferenceScreen in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsFragment method configureBlogsSettings.

private void configureBlogsSettings(PreferenceCategory blogsCategory, boolean showAll) {
    if (!isAdded())
        return;
    List<SiteModel> sites;
    String trimmedQuery = "";
    if (mSearchView != null && !TextUtils.isEmpty(mSearchView.getQuery())) {
        trimmedQuery = mSearchView.getQuery().toString().trim();
        sites = mSiteStore.getWPComAndJetpackSitesByNameOrUrlMatching(trimmedQuery);
    } else {
        sites = mSiteStore.getWPComAndJetpackSites();
    }
    mSiteCount = sites.size();
    Context context = getActivity();
    blogsCategory.removeAll();
    int maxSitesToShow = showAll ? NO_MAXIMUM : MAX_SITES_TO_SHOW_ON_FIRST_SCREEN;
    int count = 0;
    for (SiteModel site : sites) {
        if (context == null)
            return;
        count++;
        if (maxSitesToShow != NO_MAXIMUM && count > maxSitesToShow)
            break;
        PreferenceScreen prefScreen = getPreferenceManager().createPreferenceScreen(context);
        prefScreen.setTitle(SiteUtils.getSiteNameOrHomeURL(site));
        prefScreen.setSummary(SiteUtils.getHomeURLOrHostName(site));
        addPreferencesForPreferenceScreen(prefScreen, Channel.BLOGS, site.getSiteId());
        blogsCategory.addPreference(prefScreen);
    }
    // Add a message in a preference if there are no matching search results
    if (mSiteCount == 0 && !TextUtils.isEmpty(trimmedQuery)) {
        Preference searchResultsPref = new Preference(context);
        searchResultsPref.setSummary(String.format(getString(R.string.notifications_no_search_results), trimmedQuery));
        blogsCategory.addPreference(searchResultsPref);
    }
    if (mSiteCount > maxSitesToShow && !showAll) {
        //append a "view all" option
        appendViewAllSitesOption(context);
    }
    updateSearchMenuVisibility();
}
Also used : Context(android.content.Context) PreferenceScreen(android.preference.PreferenceScreen) Preference(android.preference.Preference) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Example 88 with PreferenceScreen

use of android.preference.PreferenceScreen in project NetGuard by M66B.

the class ActivitySettings method checkPermissions.

@TargetApi(Build.VERSION_CODES.M)
private void checkPermissions() {
    PreferenceScreen screen = getPreferenceScreen();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Check if permission was revoked
    if (prefs.getBoolean("whitelist_roaming", false))
        if (!Util.hasPhoneStatePermission(this)) {
            prefs.edit().putBoolean("whitelist_roaming", false).apply();
            ((TwoStatePreference) screen.findPreference("whitelist_roaming")).setChecked(false);
            requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_INTERNATIONAL);
        }
    // Check if permission was revoked
    if (prefs.getBoolean("unmetered_2g", false))
        if (!Util.hasPhoneStatePermission(this)) {
            prefs.edit().putBoolean("unmetered_2g", false).apply();
            ((TwoStatePreference) screen.findPreference("unmetered_2g")).setChecked(false);
            requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2);
        }
    if (prefs.getBoolean("unmetered_3g", false))
        if (!Util.hasPhoneStatePermission(this)) {
            prefs.edit().putBoolean("unmetered_3g", false).apply();
            ((TwoStatePreference) screen.findPreference("unmetered_3g")).setChecked(false);
            requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3);
        }
    if (prefs.getBoolean("unmetered_4g", false))
        if (!Util.hasPhoneStatePermission(this)) {
            prefs.edit().putBoolean("unmetered_4g", false).apply();
            ((TwoStatePreference) screen.findPreference("unmetered_4g")).setChecked(false);
            requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4);
        }
    // Check if permission was revoked
    if (prefs.getBoolean("national_roaming", false))
        if (!Util.hasPhoneStatePermission(this)) {
            prefs.edit().putBoolean("national_roaming", false).apply();
            ((TwoStatePreference) screen.findPreference("national_roaming")).setChecked(false);
            requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_NATIONAL);
        }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) TargetApi(android.annotation.TargetApi)

Example 89 with PreferenceScreen

use of android.preference.PreferenceScreen in project android by nextcloud.

the class Preferences method onCreate.

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    if (ThemeUtils.themingEnabled()) {
        setTheme(R.style.FallbackThemingTheme);
    }
    getDelegate().installViewFactory();
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    // retrieve user's base uri
    setupBaseUri();
    setupActionBar();
    // Register context menu for list of preferences.
    registerForContextMenu(getListView());
    int accentColor = ThemeUtils.primaryAccentColor();
    String appVersion = getAppVersion();
    PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen");
    // General
    setupGeneralCategory(accentColor);
    // Synced folders
    setupAutoUploadCategory(accentColor, preferenceScreen);
    // Details
    setupDetailsCategory(accentColor, preferenceScreen);
    // More
    setupMoreCategory(accentColor, appVersion);
    // About
    setupAboutCategory(accentColor, appVersion);
    // Dev
    setupDevCategory(accentColor, preferenceScreen);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) StoragePoint(com.owncloud.android.datastorage.StoragePoint)

Example 90 with PreferenceScreen

use of android.preference.PreferenceScreen in project Memento-Calendar by alexstyl.

the class PreferenceManagerCompat method inflateFromIntent.

/**
 * Inflates a preference hierarchy from the preference hierarchies of
 * {@link Activity Activities} that match the given {@link Intent}. An
 * {@link Activity} defines its preference hierarchy with meta-data using
 * the {@link #METADATA_KEY_PREFERENCES} key.
 * <p>
 * If a preference hierarchy is given, the new preference hierarchies will
 * be merged in.
 *
 * @param queryIntent The intent to match activities.
 * @param rootPreferences Optional existing hierarchy to merge the new
 *            hierarchies into.
 * @return The root hierarchy (if one was not provided, the new hierarchy's
 *         root).
 */
static PreferenceScreen inflateFromIntent(PreferenceManager manager, Intent intent, PreferenceScreen screen) {
    try {
        Method m = PreferenceManager.class.getDeclaredMethod("inflateFromIntent", Intent.class, PreferenceScreen.class);
        m.setAccessible(true);
        PreferenceScreen prefScreen = (PreferenceScreen) m.invoke(manager, intent, screen);
        return prefScreen;
    } catch (Exception e) {
        Log.w(TAG, "Couldn't call PreferenceManager.inflateFromIntent by reflection", e);
    }
    return null;
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Method(java.lang.reflect.Method)

Aggregations

PreferenceScreen (android.preference.PreferenceScreen)153 Preference (android.preference.Preference)68 ListPreference (android.preference.ListPreference)42 CheckBoxPreference (android.preference.CheckBoxPreference)38 PreferenceCategory (android.preference.PreferenceCategory)32 Bundle (android.os.Bundle)26 EditTextPreference (android.preference.EditTextPreference)24 Method (java.lang.reflect.Method)20 Intent (android.content.Intent)19 SharedPreferences (android.content.SharedPreferences)11 RingtonePreference (android.preference.RingtonePreference)9 Test (org.junit.Test)9 Context (android.content.Context)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 TwoStatePreference (android.preference.TwoStatePreference)8 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6 ComponentName (android.content.ComponentName)6