List of usage examples for android.preference CheckBoxPreference setOnPreferenceChangeListener
public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener)
From source file:com.xperia64.cosi.PrefsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); CheckBoxPreference cp = (CheckBoxPreference) this.findPreference("cosiNotify"); cp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override/*ww w .ja v a 2s. c o m*/ public boolean onPreferenceChange(Preference preference, Object newValue) { if ((Boolean) newValue) { ((CosiActivity) getActivity()).scheduleAlarm(); } else { ((CosiActivity) getActivity()).cancelAlarm(); } return true; } }); CheckBoxPreference cp2 = (CheckBoxPreference) this.findPreference("darkTheme"); cp2.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { getActivity().recreate(); return true; } }); }
From source file:com.johan.vertretungsplan_2.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); Preference changeSchoolPref = findPreference("change_school"); if (BuildConfig.FIXED_SCHOOL == null) { changeSchoolPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override/*www . ja v a2s .c o m*/ public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(getActivity(), SelectSchoolActivity.class); getActivity().startActivity(intent); return true; } }); } CheckBoxPreference analyticsPref = (CheckBoxPreference) findPreference("analytics"); analyticsPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Log.d("Vertretungsplan", "Analytics Opt-out"); GoogleAnalytics.getInstance(getActivity().getApplicationContext()) .setAppOptOut(!(boolean) newValue); return true; } }); }
From source file:com.mattprecious.notisync.preferences.DevicePreferenceFragment.java
@Override public void onResume() { super.onResume(); BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { return;//from w w w .j a v a2 s.c om } PreferenceScreen screen = getPreferenceScreen(); screen.removeAll(); Set<String> selectedDevices = Preferences.getDevices(getActivity()); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { CheckBoxPreference preference = new CheckBoxPreference(getActivity()); preference.setOnPreferenceChangeListener(preferenceListener); preference.setTitle(device.getName()); preference.setSummary(device.getAddress()); int iconResId = Helpers.getBtClassDrawable(device); if (iconResId != 0) { preference.setIcon(iconResId); } if (selectedDevices.contains(device.getAddress())) { preference.setDefaultValue(true); localDeviceSet.add(device.getAddress()); } getPreferenceScreen().addPreference(preference); } }
From source file:fr.free.nrw.commons.settings.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { AndroidInjection.inject(this); super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); // Update spinner to show selected value as summary ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE); licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue()))); // Keep summary updated when changing value licensePreference.setOnPreferenceChangeListener((preference, newValue) -> { preference.setSummary(getString(Utils.licenseNameFor((String) newValue))); return true; });//w ww .ja v a2s . c om CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme"); themePreference.setOnPreferenceChangeListener((preference, newValue) -> { getActivity().recreate(); return true; }); final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads"); int uploads = prefs.getInt(Prefs.UPLOADS_SHOWING, 100); uploadLimit.setText(uploads + ""); uploadLimit.setSummary(uploads + ""); uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> { int value = Integer.parseInt(newValue.toString()); final SharedPreferences.Editor editor = prefs.edit(); if (value > 500) { new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit) .setMessage(R.string.maximum_limit_alert) .setPositiveButton(android.R.string.yes, (dialog, which) -> { }).setIcon(android.R.drawable.ic_dialog_alert).show(); editor.putInt(Prefs.UPLOADS_SHOWING, 500); editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); uploadLimit.setSummary(500 + ""); uploadLimit.setText(500 + ""); } else { editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString())); editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); uploadLimit.setSummary(newValue.toString()); } editor.apply(); return true; }); Preference sendLogsPreference = findPreference("sendLogFile"); sendLogsPreference.setOnPreferenceClickListener(preference -> { //first we need to check if we have the necessary permissions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { sendAppLogsViaEmail(); } else { //first get the necessary permission requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_CODE_WRITE_EXTERNAL_STORAGE); } } else { sendAppLogsViaEmail(); } return true; }); }
From source file:com.chromium.fontinstaller.ui.settings.SettingsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); prefs = PreferencesManager.getInstance(getActivity()); billingHelper = new IabHelper(getActivity(), SecretStuff.LICENSE_KEY); CheckBoxPreference trueFont = (CheckBoxPreference) findPreference("trueFont"); trueFont.setOnPreferenceChangeListener((pref, newValue) -> handleTrueFont(newValue)); Preference clearCache = findPreference("clearCache"); clearCache.setOnPreferenceClickListener(pref -> clearCache()); Preference source = findPreference("viewSource"); source.setOnPreferenceClickListener(pref -> viewSource()); Preference licenses = findPreference("licenses"); licenses.setOnPreferenceClickListener(pref -> openLicensesDialog()); Preference appVersion = findPreference("appVersion"); appVersion.setSummary(BuildConfig.VERSION_NAME + " - " + BuildConfig.BUILD_TYPE); donate = findPreference("donate"); billingHelper.startSetup(result -> { if (result.isSuccess()) { donate.setEnabled(true);//from w w w . ja v a 2 s . c o m } else { donate.setSummary("A problem was encountered while setting up In-App Billing"); } }); donate.setOnPreferenceClickListener(pref -> showDonationDialog()); }
From source file:org.deviceconnect.android.client.fragment.AbstractSettingsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); Bundle args = new Bundle(); args.putParcelableArrayList(OpenSourceLicenseFragment.EXTRA_OSS, getOpenSourceSoftware()); mOssFragment = new OpenSourceLicenseFragment(); mOssFragment.setArguments(args);// w w w. jav a 2 s . com Bundle policyArgs = new Bundle(); policyArgs.putInt(Intent.EXTRA_TITLE, R.string.privacy_policy); policyArgs.putInt(Intent.EXTRA_TEXT, R.raw.privacypolicy); mPrivacyPolicyFragment = new TextDialogFragment(); mPrivacyPolicyFragment.setArguments(policyArgs); Bundle tosArgs = new Bundle(); tosArgs.putInt(Intent.EXTRA_TITLE, R.string.terms_of_service); tosArgs.putInt(Intent.EXTRA_TEXT, R.raw.termsofservice); mTermsOfServiceFragment = new TextDialogFragment(); mTermsOfServiceFragment.setArguments(tosArgs); PreferenceScreen versionPreferences = (PreferenceScreen) getPreferenceScreen() .findPreference(getString(R.string.key_settings_about_appinfo)); try { versionPreferences.setSummary((getActivity().getPackageManager() .getPackageInfo(getActivity().getPackageName(), 0).versionName)); } catch (NameNotFoundException e) { e.printStackTrace(); } CheckBoxPreference checkBoxSslPreferences = (CheckBoxPreference) getPreferenceScreen() .findPreference(getString(R.string.key_settings_dconn_ssl)); checkBoxSslPreferences.setOnPreferenceChangeListener(this); EditTextPreference editHostPreferences = (EditTextPreference) getPreferenceScreen() .findPreference(getString(R.string.key_settings_dconn_host)); editHostPreferences.setOnPreferenceChangeListener(this); editHostPreferences.setSummary(editHostPreferences.getText()); EditTextPreference editPortPreferences = (EditTextPreference) getPreferenceScreen() .findPreference(getString(R.string.key_settings_dconn_port)); editPortPreferences.setOnPreferenceChangeListener(this); editPortPreferences.setSummary(editPortPreferences.getText()); // Local OAuth SettingsActivity activity = (SettingsActivity) getActivity(); EditTextPreference editClientIdPreferences = (EditTextPreference) getPreferenceScreen() .findPreference(getString(R.string.key_settings_dconn_client_id)); editClientIdPreferences.setSummary(activity.getClientId()); EditTextPreference editClientSecretPreferences = (EditTextPreference) getPreferenceScreen() .findPreference(getString(R.string.key_settings_dconn_client_secret)); editClientSecretPreferences.setSummary(activity.getClientSecret()); EditTextPreference editAccessTokenPreferences = (EditTextPreference) getPreferenceScreen() .findPreference(getString(R.string.key_settings_dconn_access_token)); editAccessTokenPreferences.setSummary(activity.getAccessToken()); }
From source file:com.chess.genesis.activity.Settings.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; final Pref pref = new Pref(this); // set layout mode final boolean isTablet = pref.getBool(R.array.pf_tabletMode); if (isTablet) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else/*w w w .j a v a 2 s .c o m*/ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_settings); addPreferencesFromResource(R.xml.settings); net = new NetworkClient(this, handle); progress = new ProgressMsg(this); final View button = findViewById(R.id.topbar_genesis); button.setOnLongClickListener(this); final boolean isLoggedin = pref.getBool(R.array.pf_isLoggedIn); final Preference bench = findPreference("benchmark"); bench.setOnPreferenceClickListener(this); final IntListPreference poll = (IntListPreference) findPreference(pref.key(R.array.pf_notifierPolling)); poll.setOnPreferenceChangeListener(this); CheckBoxPreference check = (CheckBoxPreference) findPreference(pref.key(R.array.pf_emailNoteEnabled)); check.setOnPreferenceChangeListener(this); check.setEnabled(isLoggedin); check = (CheckBoxPreference) findPreference(pref.key(R.array.pf_noteEnabled)); check.setOnPreferenceChangeListener(this); check.setEnabled(isLoggedin); CallBackPreference callbackPref = (CallBackPreference) findPreference("deleteLocalTable"); callbackPref.setCallBack(this); callbackPref = (CallBackPreference) findPreference("resyncOnlineTable"); callbackPref.setCallBack(this); callbackPref.setEnabled(isLoggedin); callbackPref = (CallBackPreference) findPreference("resyncArchiveTable"); callbackPref.setCallBack(this); callbackPref.setEnabled(isLoggedin); callbackPref = (CallBackPreference) findPreference("resyncMsgTable"); callbackPref.setCallBack(this); callbackPref.setEnabled(isLoggedin); callbackPref = (CallBackPreference) findPreference("bcReset"); callbackPref.setCallBack(this); // Set email note value from server if (pref.getBool(R.array.pf_isLoggedIn)) { progress.setText("Retrieving Settings"); net.get_option("emailnote"); new Thread(net).start(); } }
From source file:com.prey.activities.PreyConfigurationSMSActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_sms); PreyStatus.getInstance().setPreyConfigurationActivityResume(true); try {/*from w ww.j a v a 2 s . co m*/ CheckBoxPreference pSMS = (CheckBoxPreference) findPreference("PREFS_SMS_COMMAND"); PreyConfig preyConfig = PreyConfig.getPreyConfig(getApplicationContext()); PreyLogger.i("preyConfig.isSmsCommand:" + preyConfig.isSmsCommand()); pSMS.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { CheckBoxPreference pSMS = (CheckBoxPreference) findPreference("PREFS_SMS_COMMAND"); PreyLogger.i("preyConfig.newValue:" + newValue); boolean value = ((Boolean) newValue).booleanValue(); PreyConfig.getPreyConfig(getApplicationContext()).setSmsCommand(value); pSMS.setChecked(value); pSMS.setDefaultValue(value); if (value) { requestPermission(); ; } return false; } }); if (!preyConfig.isSmsCommand()) { pSMS.setChecked(false); pSMS.setDefaultValue(false); } else { pSMS.setChecked(true); pSMS.setDefaultValue(true); } } catch (Exception e) { } setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
From source file:com.esminis.server.library.activity.DrawerFragment.java
protected void setupPreferences(PreferenceScreen screen, Context context) { final CheckBoxPreference preference = createPreferenceCheckbox(context, Preferences.START_ON_BOOT, false, R.string.server_start_on_boot_title, R.string.server_start_on_boot_summary); preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override//from w w w .ja va 2 s .c om public boolean onPreferenceChange(Preference preference, Object newValue) { onPreferenceChanged(preference, newValue); return true; } }); screen.addPreference(preference); screen.addPreference( requestStatusOnChange(createPreferenceCheckbox(context, Preferences.SHOW_NOTIFICATION_SERVER, true, R.string.show_notification_server, R.string.show_notification_server_summary))); }
From source file:de.hero.vertretungsplan.PrefsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); ListPreference listPref = (ListPreference) findPreference("prefs_benachrichtigungsintervall"); listPref.setSummary(//w w w.j a va 2s. co m getSummaryInterval(mySharedPreferences.getString("prefs_benachrichtigungsintervall", "1"))); listPref.setOnPreferenceChangeListener(new ListPreference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummary(getSummaryInterval(newValue.toString())); MainActivity.setNewAlarm(getBaseContext(), true, newValue.toString()); return true; } }); Preference klasse = findPreference("prefs_klasse"); klasse.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { showDialog(R.string.dialog_klasse); return true; } }); CheckBoxPreference ckBxPref = (CheckBoxPreference) findPreference("prefs_benachrichtigungen"); ckBxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals("prefs_benachrichtigungen")) { MainActivity.setNewAlarm(getBaseContext(), !((CheckBoxPreference) preference).isChecked(), mySharedPreferences); } return true; } }); CheckBoxPreference ckBxPrefAppUpdate = (CheckBoxPreference) findPreference("prefs_check_for_app_updates"); ckBxPrefAppUpdate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals("prefs_check_for_app_updates")) { Intent i = new Intent(getBaseContext(), CheckForAppUpdate.class); i.putExtra("setTimer", !((CheckBoxPreference) preference).isChecked()); if (!((CheckBoxPreference) preference).isChecked()) { i.putExtra("checkNow", true); } getBaseContext().startService(i); } return true; } }); Preference ueber = findPreference("ueber"); ueber.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Dialog ueberDialog = new Dialog(PrefsActivity.this); ueberDialog.setContentView(R.layout.ueber_dialog_layout); ueberDialog.setTitle(getString(R.string.ueber)); ueberDialog.setCancelable(true); ueberDialog.setCanceledOnTouchOutside(true); TextView dialogText = (TextView) ueberDialog.findViewById(R.id.text_in_dialog); dialogText.setTextColor(Color.BLACK); dialogText.setAutoLinkMask(Linkify.ALL); dialogText.setText(String.format(getString(R.string.ueberTextFormated), getString(R.string.version_nr), getString(R.string.emailAdresseEntwickler), getString(R.string.webAdresseAppDownload), getString(R.string.GNU_GPLwebadresse))); ueberDialog.show(); return true; } }); CheckBoxPreference ckBxPrefDebugging = (CheckBoxPreference) findPreference("prefs_debug"); ckBxPrefDebugging.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals("prefs_debug")) { Log.d("PrefsActivity", "new"); if (!((CheckBoxPreference) preference).isChecked()) { AlertDialog.Builder builder = new AlertDialog.Builder(preference.getContext()); builder.setMessage(getString(R.string.debugText)).setTitle(getString(R.string.debugTitel)); AlertDialog dialog = builder.create(); dialog.show(); } } return true; } }); }