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);
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations