use of android.preference.Preference in project Timber by naman14.
the class SettingsFragment method invalidateSettings.
public void invalidateSettings() {
mAteKey = ((SettingsActivity) getActivity()).getATEKey();
ATEColorPreference primaryColorPref = (ATEColorPreference) findPreference("primary_color");
primaryColorPref.setColor(Config.primaryColor(getActivity(), mAteKey), Color.BLACK);
primaryColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new ColorChooserDialog.Builder((SettingsActivity) getActivity(), R.string.primary_color).preselect(Config.primaryColor(getActivity(), mAteKey)).show();
return true;
}
});
ATEColorPreference accentColorPref = (ATEColorPreference) findPreference("accent_color");
accentColorPref.setColor(Config.accentColor(getActivity(), mAteKey), Color.BLACK);
accentColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new ColorChooserDialog.Builder((SettingsActivity) getActivity(), R.string.accent_color).preselect(Config.accentColor(getActivity(), mAteKey)).show();
return true;
}
});
findPreference("dark_theme").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// Marks both theme configs as changed so MainActivity restarts itself on return
Config.markChanged(getActivity(), "light_theme");
Config.markChanged(getActivity(), "dark_theme");
// The dark_theme preference value gets saved by Android in the default PreferenceManager.
// It's used in getATEKey() of both the Activities.
getActivity().recreate();
return true;
}
});
final ATECheckBoxPreference statusBarPref = (ATECheckBoxPreference) findPreference("colored_status_bar");
final ATECheckBoxPreference navBarPref = (ATECheckBoxPreference) findPreference("colored_nav_bar");
statusBarPref.setChecked(Config.coloredStatusBar(getActivity(), mAteKey));
statusBarPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ATE.config(getActivity(), mAteKey).coloredStatusBar((Boolean) newValue).apply(getActivity());
return true;
}
});
navBarPref.setChecked(Config.coloredNavigationBar(getActivity(), mAteKey));
navBarPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ATE.config(getActivity(), mAteKey).coloredNavigationBar((Boolean) newValue).apply(getActivity());
return true;
}
});
}
use of android.preference.Preference in project KeepScore by nolanlawson.
the class SettingsActivity method setUpPreferences.
private void setUpPreferences() {
plusButtonPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_plus_button);
minusButtonPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_minus_button);
button1Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_1);
button2Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_2);
button3Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_3);
button4Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_4);
twoPlayerButton1Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_1);
twoPlayerButton2Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_2);
twoPlayerButton3Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_3);
twoPlayerButton4Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_4);
greenTextPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_green_text);
showRoundTotalsPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_show_round_totals);
showInitialMessagePref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_initial_message);
disableHighlightTagPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_disable_highlight_tag);
showColorsPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_show_colors);
updateDelayPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_update_delay);
initialScorePref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_initial_score);
resetPref = findPreferenceById(R.string.CONSTANT_pref_reset);
aboutPref = findPreferenceById(R.string.CONSTANT_pref_about);
colorSchemePref = (ListPreference) findPreferenceById(R.string.CONSTANT_pref_color_scheme);
orientationPref = (ListPreference) findPreferenceById(R.string.CONSTANT_pref_orientation);
loadSettingsPref = findPreferenceById(R.string.CONSTANT_pref_load_settings);
saveSettingsPref = findPreferenceById(R.string.CONSTANT_pref_save_settings);
// changed
for (EditTextPreference pref : new EditTextPreference[] { button1Pref, button2Pref, button3Pref, button4Pref, twoPlayerButton1Pref, twoPlayerButton2Pref, twoPlayerButton3Pref, twoPlayerButton4Pref, plusButtonPref, minusButtonPref }) {
setDynamicSummary(pref);
}
// do a special check for the update delay value
updateDelayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (!IntegerUtil.validInt(newValue.toString()) || Integer.parseInt(newValue.toString()) < 1 || Integer.parseInt(newValue.toString()) > 600) {
ToastHelper.showLong(SettingsActivity.this, R.string.toast_valid_update_delay_values);
return false;
}
PreferenceHelper.resetCache();
return true;
}
});
// do another special check for the initial score value
initialScorePref.setSummary(initialScorePref.getText());
initialScorePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (!IntegerUtil.validInt(newValue.toString())) {
ToastHelper.showLong(SettingsActivity.this, R.string.toast_valid_initial_score);
return false;
}
preference.setSummary(newValue.toString());
return true;
}
});
// show the version number in the "about" summary text
String version = String.format(getString(R.string.text_version_number), PackageHelper.getVersionName(this));
aboutPref.setSummary(version);
// do a special popup for the reset preference
resetPref.setOnPreferenceClickListener(this);
loadSettingsPref.setOnPreferenceClickListener(this);
saveSettingsPref.setOnPreferenceClickListener(this);
setDynamicListPreferenceSummary(colorSchemePref);
setDynamicListPreferenceSummary(orientationPref);
// go to the about activity if the about pref is pressed
aboutPref.setOnPreferenceClickListener(this);
greenTextPref.setOnPreferenceChangeListener(this);
showRoundTotalsPref.setOnPreferenceChangeListener(this);
disableHighlightTagPref.setOnPreferenceChangeListener(this);
showInitialMessagePref.setOnPreferenceChangeListener(this);
showColorsPref.setOnPreferenceChangeListener(this);
}
use of android.preference.Preference in project KeepScore by nolanlawson.
the class SettingsActivity method getSettingsToDisplay.
/**
* Grab a map of all settings, using user-friendly display names for the
* settings
*
* @param settingSet
* @return
*/
private Map<String, ?> getSettingsToDisplay(String settingSet) {
Map<String, ?> inputMap = SettingSetHelper.getSettingsSet(this, settingSet);
Map<String, Object> outputMap = new LinkedHashMap<String, Object>();
// works
for (int i = 0; i < getListView().getAdapter().getCount(); i++) {
Object obj = getListView().getAdapter().getItem(i);
if (!(obj instanceof Preference)) {
continue;
}
Preference pref = (Preference) obj;
if (pref instanceof PreferenceCategory || !pref.isPersistent()) {
// 'reset'
continue;
}
Object value = inputMap.get(pref.getKey());
// Android seems to
value = value != null ? value : Boolean.FALSE;
// store false
// booleans as null
outputMap.put(pref.getTitle().toString(), value);
}
return outputMap;
}
use of android.preference.Preference in project android-sms-relay by nyaruka.
the class SettingsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View title = getWindow().findViewById(android.R.id.title);
title.setPadding(5, 0, 0, 0);
addPreferencesFromResource(R.xml.preferences);
// Add a listener for relay password
Preference relayPassword = (Preference) findPreference("relay_password");
relayPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String password = newValue.toString();
Log.d(TAG, "New password " + password);
return true;
}
});
Preference prefNetwork = (Preference) findPreference("pref_net");
prefNetwork.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.d(TAG, "Your preferred network has been changed to: " + newValue);
return true;
}
});
// Add a listener for our clear button, with a confirmation
Preference clearMessages = (Preference) findPreference("clear_messages");
clearMessages.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
// show a confirmation dialog
new AlertDialog.Builder(SettingsActivity.this).setTitle("WARNING").setMessage("This will remove all messages, including ones not yet sent to the server or mobile phones.\n\nThis operation cannot be undone.").setPositiveButton("Reset", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
AndroidRelay.clearMessages(SettingsActivity.this);
Toast.makeText(SettingsActivity.this, "Messages cleared", Toast.LENGTH_LONG).show();
}
}).setNegativeButton(android.R.string.cancel, null).show();
return true;
}
});
Preference sendLog = (Preference) findPreference("send_log");
sendLog.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
RelayService.doSendLog = true;
WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(1), getApplicationContext());
Toast.makeText(SettingsActivity.this, "Log will be sent shortly.", Toast.LENGTH_LONG).show();
return true;
}
});
Preference updateInterval = (Preference) findPreference("update_interval");
updateInterval.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(Long.parseLong(newValue.toString())), SettingsActivity.this);
Log.d(TAG, "Rescheduling alarms based on new update_interval value: " + newValue);
return true;
}
});
Preference setRapidHost = (Preference) findPreference("router_hostname");
setRapidHost.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String hostname = newValue.toString();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
String backend = prefs.getString("router_backend", "android");
String password = prefs.getString("router_password", null);
updateEndpoints(hostname, backend, password);
return true;
}
});
Preference setRapidBackend = (Preference) findPreference("router_backend");
setRapidBackend.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String backend = newValue.toString();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
String hostname = prefs.getString("router_hostname", null);
String password = prefs.getString("router_password", null);
updateEndpoints(hostname, backend, password);
return true;
}
});
Preference setRapidPassword = (Preference) findPreference("router_password");
setRapidPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String password = newValue.toString();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
String backend = prefs.getString("router_backend", "android");
String hostname = prefs.getString("router_hostname", null);
updateEndpoints(hostname, backend, password);
return true;
}
});
}
use of android.preference.Preference in project scdl by passy.
the class DownloadPreferencesDelegateImpl method setupAboutHandlers.
private void setupAboutHandlers() {
final Uri uri = mPackageHelper.getMarketUri();
final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);
mPreferenceManager.findPreference(ApplicationPreferences.KEY_RATE_APP).setIntent(rateAppIntent);
final Intent aboutIntent = new Intent(mContext, AboutActivity.class);
mPreferenceManager.findPreference(ApplicationPreferences.KEY_ABOUT_ME).setIntent(aboutIntent);
final Intent donateIntent = new Intent(mContext, BuyAdFreeActivity.class);
final Preference donatePreference = mPreferenceManager.findPreference(ApplicationPreferences.KEY_DONATE);
if (Config.Features.NEW_DONATE) {
throw new IllegalStateException("New Donate isn't implemented yet, doh!");
} else {
donatePreference.setIntent(donateIntent);
donatePreference.setTitle(mContext.getString(R.string.remove_ads));
donatePreference.setEnabled(!mAppPreferences.isAdFree());
}
}
Aggregations