use of android.support.v7.preference.CheckBoxPreference in project platform_packages_apps_Settings by BlissRoms.
the class ApplicationSettings method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.application_settings);
mToggleAdvancedSettings = (CheckBoxPreference) findPreference(KEY_TOGGLE_ADVANCED_SETTINGS);
mToggleAdvancedSettings.setChecked(isAdvancedSettingsEnabled());
getPreferenceScreen().removePreference(mToggleAdvancedSettings);
// not ready for prime time yet
if (false) {
getPreferenceScreen().removePreference(mInstallLocation);
}
mInstallLocation = (ListPreference) findPreference(KEY_APP_INSTALL_LOCATION);
// Is app default install location set?
boolean userSetInstLocation = (Settings.Global.getInt(getContentResolver(), Settings.Global.SET_INSTALL_LOCATION, 0) != 0);
if (!userSetInstLocation) {
getPreferenceScreen().removePreference(mInstallLocation);
} else {
mInstallLocation.setValue(getAppInstallLocation());
mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
handleUpdateAppInstallLocation(value);
return false;
}
});
}
}
use of android.support.v7.preference.CheckBoxPreference in project TumCampusApp by TCA-Team.
the class SettingsFragment method populateNewsSources.
private void populateNewsSources() {
PreferenceCategory newsSourcesPreference = (PreferenceCategory) findPreference("card_news_sources");
NewsController newsController = new NewsController(mContext);
List<NewsSources> newsSources = newsController.getNewsSources();
final NetUtils net = new NetUtils(mContext);
for (NewsSources newsSource : newsSources) {
final CheckBoxPreference pref = new CheckBoxPreference(mContext);
pref.setKey("card_news_source_" + newsSource.getId());
pref.setDefaultValue(true);
// Load news source icon in background and set it
final String url = newsSource.getIcon();
if (url != null) {
// Skip News that do not have a image
new Thread(() -> {
final Optional<Bitmap> bmp = net.downloadImageToBitmap(url);
mContext.runOnUiThread(() -> {
if (bmp.isPresent()) {
pref.setIcon(new BitmapDrawable(getResources(), bmp.get()));
}
});
}).start();
}
pref.setTitle(newsSource.getTitle());
if (newsSourcesPreference != null) {
newsSourcesPreference.addPreference(pref);
}
}
}
use of android.support.v7.preference.CheckBoxPreference in project TumCampusApp by TCA-Team.
the class SettingsFragment method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key);
if (pref instanceof ListPreference) {
ListPreference listPreference = (ListPreference) pref;
listPreference.setSummary(listPreference.getEntry());
}
// Refresh the cards after a change has been made to them
if (key.startsWith("card_")) {
CardManager.setShouldRefresh();
}
// selected source if one of all was selected before
if ("news_newspread".equals(key)) {
SharedPreferences.Editor e = sharedPreferences.edit();
boolean value = false;
for (int i = 7; i < 14; i++) {
if (sharedPreferences.getBoolean("card_news_source_" + i, false)) {
value = true;
}
e.putBoolean("card_news_source_" + i, false);
}
String newSource = sharedPreferences.getString(key, "7");
e.putBoolean("card_news_source_" + newSource, value);
e.apply();
CardManager.setShouldRefresh();
}
// the service to call onHandleIntent which checks available lectures
if (key.equals(Const.SILENCE_SERVICE)) {
Intent service = new Intent(mContext, SilenceService.class);
if (sharedPreferences.getBoolean(key, false)) {
if (!SilenceService.hasPermissions(mContext)) {
// disable until silence service permission is resolved
CheckBoxPreference silenceCheckbox = (CheckBoxPreference) findPreference(Const.SILENCE_SERVICE);
if (silenceCheckbox != null) {
silenceCheckbox.setChecked(false);
}
Utils.setSetting(mContext, Const.SILENCE_SERVICE, false);
SilenceService.requestPermissions(mContext);
} else {
mContext.startService(service);
}
} else {
mContext.stopService(service);
}
}
// the service to call onHandleIntent which updates all background data
if (key.equals(Const.BACKGROUND_MODE)) {
Intent service = new Intent(mContext, BackgroundService.class);
if (sharedPreferences.getBoolean(key, false)) {
mContext.startService(service);
} else {
mContext.stopService(service);
}
}
}
use of android.support.v7.preference.CheckBoxPreference in project TumCampusApp by TCA-Team.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
// Load the correct preference category
setPreferencesFromResource(R.xml.settings, rootKey);
mContext = getActivity();
// Disables silence service if the app is used without TUMOnline access
CheckBoxPreference silent = (CheckBoxPreference) findPreference("silent_mode");
if (silent != null && !new AccessTokenManager(mContext).hasValidAccessToken()) {
silent.setEnabled(false);
}
// Only do these things if we are in the root of the preferences
if (rootKey == null) {
// Click listener for preference list entries. Used to simulate a button
// (since it is not possible to add a button to the preferences screen)
findPreference(BUTTON_CLEAR_CACHE).setOnPreferenceClickListener(this);
// Set summary for these preferences
setSummary("card_cafeteria_default_G");
setSummary("card_cafeteria_default_K");
setSummary("card_cafeteria_default_W");
setSummary("card_role");
setSummary("card_stations_default_G");
setSummary("card_stations_default_C");
setSummary("card_stations_default_K");
setSummary("card_default_campus");
setSummary("silent_mode_set_to");
setSummary("background_mode_set_to");
} else if (rootKey.equals("card_eduroam")) {
findPreference(SETUP_EDUROAM).setOnPreferenceClickListener(this);
}
// Register the change listener to react immediately on changes
PreferenceManager.getDefaultSharedPreferences(mContext).registerOnSharedPreferenceChangeListener(this);
}
use of android.support.v7.preference.CheckBoxPreference in project i2p.i2p-bote by i2p.
the class AdvancedPreferenceFragment method setupAdvancedSettings.
private void setupAdvancedSettings() {
final Context ctx = getPreferenceManager().getContext();
final PreferenceCategory i2pCat = (PreferenceCategory) findPreference("i2pCategory");
CheckBoxPreference routerAuto = (CheckBoxPreference) findPreference("i2pbote.router.auto");
if (!routerAuto.isChecked()) {
setupI2PCategory(ctx, i2pCat);
}
routerAuto.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final Boolean checked = (Boolean) newValue;
if (!checked) {
setupI2PCategory(ctx, i2pCat);
} else {
Preference p1 = i2pCat.findPreference("i2pbote.router.use");
Preference p2 = i2pCat.findPreference("i2pbote.i2cp.tcp.host");
Preference p3 = i2pCat.findPreference("i2pbote.i2cp.tcp.port");
if (p1 != null)
i2pCat.removePreference(p1);
if (p2 != null)
i2pCat.removePreference(p2);
if (p3 != null)
i2pCat.removePreference(p3);
}
return true;
}
});
}
Aggregations