List of usage examples for android.preference CheckBoxPreference setOnPreferenceClickListener
public void setOnPreferenceClickListener(OnPreferenceClickListener onPreferenceClickListener)
From source file:de.azapps.mirakel.settings.model_settings.special_list.SpecialListDetailFragment.java
private CheckBoxPreference getIsActivePreference() { final CheckBoxPreference active = new CheckBoxPreference(getActivity()); active.setTitle(R.string.special_list_active); active.setChecked(mItem.isActive()); active.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override/* w w w .j a va 2 s. co m*/ public boolean onPreferenceClick(Preference preference) { boolean a = !active.isChecked(); mItem.setActive(a); mItem.save(); active.setChecked(mItem.isActive()); mAdapter.notifyDataSetChanged(); return true; } }); return active; }
From source file:org.exobel.routerkeygen.ui.Preferences.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getActionBar().setDisplayHomeAsUpEnabled(true); findPreference("download").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { if (isDictionaryServiceRunning()) { Toast.makeText(getBaseContext(), getString(R.string.pref_msg_download_running), Toast.LENGTH_SHORT).show(); return true; }// ww w . j a v a 2 s .com ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo == null || !netInfo.isConnectedOrConnecting()) { Toast.makeText(getBaseContext(), getString(R.string.pref_msg_no_network), Toast.LENGTH_SHORT) .show(); return true; } // Don't complain about dictionary size if user is on a // wifi connection if ((((WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE))).getConnectionInfo() .getSSID() != null) { try { checkCurrentDictionary(); } catch (FileNotFoundException e) { e.printStackTrace(); } } else showDialog(DIALOG_ASK_DOWNLOAD); return true; } }); // boolean app_installed = AdsUtils.checkDonation(this); final PreferenceCategory mCategory = (PreferenceCategory) findPreference("2section"); // if (!app_installed) { // mCategory.removePreference(findPreference("analytics_enabled")); // // If you haven't the donate app installed remove the paypal donate // // link. // mCategory.removePreference(findPreference("donate_paypal")); // findPreference("donate_playstore").setOnPreferenceClickListener( // new OnPreferenceClickListener() { // public boolean onPreferenceClick(Preference preference) { // try { // startActivity(new Intent(Intent.ACTION_VIEW, // Uri.parse("market://details?id=" // + GOOGLE_PLAY_DOWNLOADER))); // } catch (android.content.ActivityNotFoundException anfe) { // startActivity(new Intent( // Intent.ACTION_VIEW, // Uri.parse("http://play.google.com/store/apps/details?id=" // + GOOGLE_PLAY_DOWNLOADER))); // } // Toast.makeText(getApplicationContext(), // R.string.msg_donation, Toast.LENGTH_LONG) // .show(); // return true; // } // }); // } else { // // If you have the donate app installed no need to link to it. // mCategory.removePreference(findPreference("donate_playstore")); // if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) { // //Play Store is quite restrictive nowadays // mCategory.removePreference(findPreference("donate_paypal")); // } else { // findPreference("donate_paypal").setOnPreferenceClickListener( // new OnPreferenceClickListener() { // public boolean onPreferenceClick(Preference preference) { // final String donateLink = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V3FFBTRTTV5DN"; // Uri uri = Uri.parse(donateLink); // startActivity(new Intent(Intent.ACTION_VIEW, uri)); // // return true; // } // }); // } // } if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) { mCategory.removePreference(findPreference("update")); } else { findPreference("update").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { protected void onPreExecute() { showDialog(DIALOG_WAIT); } protected Void doInBackground(Void... params) { lastVersion = UpdateCheckerService.getLatestVersion(); return null; } protected void onPostExecute(Void result) { removeDialog(DIALOG_WAIT); if (isFinishing()) return; if (lastVersion == null) { showDialog(DIALOG_ERROR); return; } if (!Preferences.VERSION.equals(lastVersion.version)) { showDialog(DIALOG_UPDATE_NEEDED); } else { Toast.makeText(Preferences.this, R.string.msg_app_updated, Toast.LENGTH_SHORT) .show(); } } }; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { task.execute(); } else { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } // Checking for updates every week startService(new Intent(getApplicationContext(), UpdateCheckerService.class)); return true; } }); } findPreference("changelog").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { showDialog(DIALOG_CHANGELOG); return true; } }); findPreference("about").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { showDialog(DIALOG_ABOUT); return true; } }); findPreference(dicLocalPref).setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { startActivityForResult(new Intent(getApplicationContext(), FileChooserActivity.class), 0); return true; } }); final CheckBoxPreference autoScan = (CheckBoxPreference) findPreference("autoScan"); autoScan.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { findPreference("autoScanInterval").setEnabled(autoScan.isChecked()); return true; } }); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); findPreference("autoScanInterval").setEnabled( prefs.getBoolean(Preferences.autoScanPref, getResources().getBoolean(R.bool.autoScanDefault))); }
From source file:org.wordpress.android.ui.prefs.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Resources resources = getResources(); if (savedInstanceState == null) { AnalyticsTracker.track(AnalyticsTracker.Stat.OPENED_SETTINGS); }/*from w w w . ja va 2 s. c om*/ addPreferencesFromResource(R.xml.settings); OnPreferenceChangeListener preferenceChangeListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue != null) { // cancelled dismiss keyboard preference.setSummary(newValue.toString()); } ActivityUtils.hideKeyboard(getActivity()); return true; } }; mTaglineTextPreference = (WPEditTextPreference) findPreference( resources.getString(R.string.pref_key_post_sig)); if (mTaglineTextPreference != null) { mTaglineTextPreference.setOnPreferenceChangeListener(preferenceChangeListener); } findPreference(resources.getString(R.string.pref_key_notifications)) .setOnPreferenceClickListener(notificationPreferenceClickListener); findPreference(resources.getString(R.string.pref_key_language)) .setOnPreferenceClickListener(languagePreferenceClickListener); findPreference(resources.getString(R.string.pref_key_app_about)) .setOnPreferenceClickListener(launchActivitiyClickListener); findPreference(resources.getString(R.string.pref_key_oss_licenses)) .setOnPreferenceClickListener(launchActivitiyClickListener); findPreference(resources.getString(R.string.pref_key_help_and_support)) .setOnPreferenceClickListener(launchActivitiyClickListener); findPreference(resources.getString(R.string.pref_key_passlock)) .setOnPreferenceChangeListener(passcodeCheckboxChangeListener); findPreference(resources.getString(R.string.pref_key_signout)) .setOnPreferenceClickListener(signOutPreferenceClickListener); findPreference(resources.getString(R.string.pref_key_reset_shared_pref)) .setOnPreferenceClickListener(resetAUtoSharePreferenceClickListener); mSettings = PreferenceManager.getDefaultSharedPreferences(getActivity()); initNotifications(); // Passcode Lock not supported if (AppLockManager.getInstance().isAppLockFeatureEnabled()) { final CheckBoxPreference passcodeEnabledCheckBoxPreference = (CheckBoxPreference) findPreference( resources.getString(R.string.pref_key_passlock)); // disable on-click changes on the property passcodeEnabledCheckBoxPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { passcodeEnabledCheckBoxPreference .setChecked(AppLockManager.getInstance().getCurrentAppLock().isPasswordLocked()); return false; } }); } else { PreferenceScreen rootScreen = (PreferenceScreen) findPreference( resources.getString(R.string.pref_key_settings_root)); PreferenceGroup passcodeGroup = (PreferenceGroup) findPreference( resources.getString(R.string.pref_key_passlock_section)); rootScreen.removePreference(passcodeGroup); } displayPreferences(); }
From source file:com.nttec.everychan.chans.allchan.AllchanModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addOnlyNewPostsPreference(preferenceGroup, true); final ListPreference captchaPreference = new LazyPreferences.ListPreference(context); //captcha_type captchaPreference.setTitle(R.string.pref_captcha_type); captchaPreference.setDialogTitle(R.string.pref_captcha_type); captchaPreference.setKey(getSharedKey(PREF_KEY_CAPTCHA_TYPE)); captchaPreference.setEntryValues(CAPTCHA_TYPES_KEYS); captchaPreference.setEntries(CAPTCHA_TYPES); captchaPreference.setDefaultValue(CAPTCHA_TYPE_DEFAULT); int i = Arrays.asList(CAPTCHA_TYPES_KEYS) .indexOf(preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT)); if (i >= 0) captchaPreference.setSummary(CAPTCHA_TYPES[i]); preferenceGroup.addPreference(captchaPreference); addHttpsPreference(preferenceGroup, true); addCloudflareRecaptchaFallbackPreference(preferenceGroup); addProxyPreferences(preferenceGroup); final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup .findPreference(getSharedKey(PREF_KEY_USE_PROXY)); proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override/*w ww . j a va 2 s.co m*/ public boolean onPreferenceClick(Preference preference) { if (proxyPreference.isChecked() && captchaPreference.getValue().equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); } return false; } }); captchaPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (proxyPreference.isChecked() && newValue.equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); return false; } return true; } }); }
From source file:nya.miku.wishmaster.chans.tumbach.TumbachModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addOnlyNewPostsPreference(preferenceGroup, true); final ListPreference captchaPreference = new LazyPreferences.ListPreference(context); //captcha_type captchaPreference.setTitle(R.string.pref_captcha_type); captchaPreference.setDialogTitle(R.string.pref_captcha_type); captchaPreference.setKey(getSharedKey(PREF_KEY_CAPTCHA_TYPE)); captchaPreference.setEntryValues(CAPTCHA_TYPES_KEYS); captchaPreference.setEntries(CAPTCHA_TYPES); captchaPreference.setDefaultValue(CAPTCHA_TYPE_DEFAULT); int i = Arrays.asList(CAPTCHA_TYPES_KEYS) .indexOf(preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT)); if (i >= 0) captchaPreference.setSummary(CAPTCHA_TYPES[i]); preferenceGroup.addPreference(captchaPreference); addPasswordPreference(preferenceGroup); addHttpsPreference(preferenceGroup, true); addCloudflareRecaptchaFallbackPreference(preferenceGroup); addProxyPreferences(preferenceGroup); final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup .findPreference(getSharedKey(PREF_KEY_USE_PROXY)); proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override/*from w ww .ja v a 2 s . c o m*/ public boolean onPreferenceClick(Preference preference) { if (proxyPreference.isChecked() && captchaPreference.getValue().equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); } return false; } }); captchaPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (proxyPreference.isChecked() && newValue.equals("recaptcha")) { captchaPreference.setValue("recaptcha-fallback"); return false; } return true; } }); }
From source file:com.nttec.everychan.chans.fourchan.FourchanModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addPasscodePreference(preferenceGroup); CheckBoxPreference newRecaptchaPref = new LazyPreferences.CheckBoxPreference(context); newRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha); newRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_summary); newRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA)); newRecaptchaPref.setDefaultValue(NEW_RECAPTCHA_DEFAULT); preferenceGroup.addPreference(newRecaptchaPref); final CheckBoxPreference fallbackRecaptchaPref = new LazyPreferences.CheckBoxPreference(context); fallbackRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha_fallback); fallbackRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_fallback_summary); fallbackRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA_FALLBACK)); fallbackRecaptchaPref.setDefaultValue(false); preferenceGroup.addPreference(fallbackRecaptchaPref); fallbackRecaptchaPref.setDependency(getSharedKey(PREF_KEY_NEW_RECAPTCHA)); addPasswordPreference(preferenceGroup); addHttpsPreference(preferenceGroup, true); addProxyPreferences(preferenceGroup); final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup .findPreference(getSharedKey(PREF_KEY_USE_PROXY)); fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked()); proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override/* www . j av a2 s.c om*/ public boolean onPreferenceClick(Preference preference) { fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked()); if (proxyPreference.isChecked() && !fallbackRecaptchaPref.isChecked()) fallbackRecaptchaPref.setChecked(true); return false; } }); }
From source file:org.linphone.AccountPreferencesFragment.java
private void initAccountPreferencesFields(PreferenceScreen parent) { boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n; accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl()); accountCreator.setListener(this); PreferenceCategory account = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_sipaccount_key)); EditTextPreference username = (EditTextPreference) account.getPreference(0); username.setOnPreferenceChangeListener(usernameChangedListener); if (!isNewAccount) { username.setText(mPrefs.getAccountUsername(n)); username.setSummary(username.getText()); }//from w ww . j a va2 s. c o m EditTextPreference userid = (EditTextPreference) account.getPreference(1); userid.setOnPreferenceChangeListener(useridChangedListener); if (!isNewAccount) { userid.setText(mPrefs.getAccountUserId(n)); userid.setSummary(userid.getText()); } EditTextPreference password = (EditTextPreference) account.getPreference(2); password.setOnPreferenceChangeListener(passwordChangedListener); if (!isNewAccount) { password.setText(mPrefs.getAccountPassword(n)); } EditTextPreference domain = (EditTextPreference) account.getPreference(3); domain.setOnPreferenceChangeListener(domainChangedListener); if (!isNewAccount) { domain.setText(mPrefs.getAccountDomain(n)); domain.setSummary(domain.getText()); } EditTextPreference displayName = (EditTextPreference) account.getPreference(4); displayName.setOnPreferenceChangeListener(displayNameChangedListener); if (!isNewAccount) { displayName.setText(mPrefs.getAccountDisplayName(n)); displayName.setSummary(displayName.getText()); } PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_advanced_key)); mTransportPreference = (ListPreference) advanced.getPreference(0); initializeTransportPreference(mTransportPreference); mTransportPreference.setOnPreferenceChangeListener(transportChangedListener); if (!isNewAccount) { mTransportPreference.setSummary(mPrefs.getAccountTransportString(n)); } mProxyPreference = (EditTextPreference) advanced.getPreference(1); mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener); if (!isNewAccount) { mProxyPreference.setText(mPrefs.getAccountProxy(n)); mProxyPreference .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null) ? getString(R.string.pref_help_proxy) : mProxyPreference.getText()); } CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2); outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener); if (!isNewAccount) { outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n)); } EditTextPreference expires = (EditTextPreference) advanced.getPreference(3); expires.setOnPreferenceChangeListener(expiresChangedListener); if (!isNewAccount) { expires.setText(mPrefs.getExpires(n)); expires.setSummary(mPrefs.getExpires(n)); } EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4); prefix.setOnPreferenceChangeListener(prefixChangedListener); if (!isNewAccount) { String prefixValue = mPrefs.getPrefix(n); prefix.setText(prefixValue); prefix.setSummary(prefixValue); } CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5); avpf.setOnPreferenceChangeListener(avpfChangedListener); if (!isNewAccount) { avpf.setChecked(mPrefs.avpfEnabled(n)); } EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6); avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener); if (!isNewAccount) { avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n)); avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n)); } CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7); escape.setOnPreferenceChangeListener(escapeChangedListener); if (!isNewAccount) { escape.setChecked(mPrefs.getReplacePlusByZeroZero(n)); } Preference linkAccount = advanced.getPreference(8); linkAccount.setOnPreferenceClickListener(linkAccountListener); PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_manage_key)); final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0); disable.setEnabled(true); disable.setOnPreferenceChangeListener(disableChangedListener); if (!isNewAccount) { disable.setChecked(!mPrefs.isAccountEnabled(n)); } CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1); mainAccount.setChecked(isDefaultAccount); mainAccount.setEnabled(!mainAccount.isChecked()); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.setDefaultAccount(n); disable.setEnabled(false); disable.setChecked(false); preference.setEnabled(false); return true; } }); if (!isNewAccount) { mainAccount.setEnabled(!mainAccount.isChecked()); } final Preference changePassword = manage.getPreference(2); if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) { changePassword.setEnabled(!isNewAccount); changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance()); LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater(); View layout = inflater.inflate(R.layout.new_password, null); final EditText pass1 = (EditText) layout.findViewById(R.id.password1); final EditText pass2 = (EditText) layout.findViewById(R.id.password2); alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinphoneAccountCreator.PasswordCheck status = accountCreator .setPassword(pass1.getText().toString()); if (status.equals(LinphoneAccountCreator.PasswordCheck.Ok)) { if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) { accountCreator.setUsername(mPrefs.getAccountUsername(n)); accountCreator.setHa1(mPrefs.getAccountHa1(n)); LinphoneAccountCreator.RequestStatus req_status = accountCreator .updatePassword(pass1.getText().toString()); if (!req_status.equals(LinphoneAccountCreator.RequestStatus.Ok)) { LinphoneUtils.displayErrorAlert( LinphoneUtils.errorForRequestStatus(req_status), LinphoneActivity.instance()); } else { progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); Drawable d = new ColorDrawable(ContextCompat .getColor(LinphoneActivity.instance(), R.color.colorE)); d.setAlpha(200); progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); progress.getWindow().setBackgroundDrawable(d); progress.setContentView(R.layout.progress_dialog); progress.show(); } } else { LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched), LinphoneActivity.instance()); } return; } LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForPasswordStatus(status), LinphoneActivity.instance()); } }); alert.setView(layout); alert.show(); return true; } }); } else { changePassword.setEnabled(false); } final Preference delete = manage.getPreference(3); delete.setEnabled(!isNewAccount); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.deleteAccount(n); LinphoneActivity.instance().refreshAccounts(); LinphoneActivity.instance().displaySettings(); return true; } }); }
From source file:co.taqat.call.AccountPreferencesFragment.java
private void initAccountPreferencesFields(PreferenceScreen parent) { boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n; accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl()); accountCreator.setListener(this); PreferenceCategory account = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_sipaccount_key)); EditTextPreference username = (EditTextPreference) account.getPreference(0); username.setOnPreferenceChangeListener(usernameChangedListener); if (!isNewAccount) { username.setText(mPrefs.getAccountUsername(n)); username.setSummary(username.getText()); }//from www.jav a 2 s.co m EditTextPreference userid = (EditTextPreference) account.getPreference(1); userid.setOnPreferenceChangeListener(useridChangedListener); if (!isNewAccount) { userid.setText(mPrefs.getAccountUserId(n)); userid.setSummary(userid.getText()); } EditTextPreference password = (EditTextPreference) account.getPreference(2); password.setOnPreferenceChangeListener(passwordChangedListener); if (!isNewAccount) { password.setText(mPrefs.getAccountPassword(n)); } EditTextPreference domain = (EditTextPreference) account.getPreference(3); domain.setOnPreferenceChangeListener(domainChangedListener); if (!isNewAccount) { domain.setText(mPrefs.getAccountDomain(n)); domain.setSummary(domain.getText()); } EditTextPreference displayName = (EditTextPreference) account.getPreference(4); displayName.setOnPreferenceChangeListener(displayNameChangedListener); if (!isNewAccount) { displayName.setText(mPrefs.getAccountDisplayName(n)); displayName.setSummary(displayName.getText()); } PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_advanced_key)); mTransportPreference = (ListPreference) advanced.getPreference(0); initializeTransportPreference(mTransportPreference); mTransportPreference.setOnPreferenceChangeListener(transportChangedListener); if (!isNewAccount) { mTransportPreference.setSummary(mPrefs.getAccountTransportString(n)); } mProxyPreference = (EditTextPreference) advanced.getPreference(1); mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener); if (!isNewAccount) { mProxyPreference.setText(mPrefs.getAccountProxy(n)); mProxyPreference .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null) ? getString(R.string.pref_help_proxy) : mProxyPreference.getText()); } CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2); outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener); if (!isNewAccount) { outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n)); } EditTextPreference expires = (EditTextPreference) advanced.getPreference(3); expires.setOnPreferenceChangeListener(expiresChangedListener); if (!isNewAccount) { expires.setText(mPrefs.getExpires(n)); expires.setSummary(mPrefs.getExpires(n)); } EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4); prefix.setOnPreferenceChangeListener(prefixChangedListener); if (!isNewAccount) { String prefixValue = mPrefs.getPrefix(n); prefix.setText(prefixValue); prefix.setSummary(prefixValue); } CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5); avpf.setOnPreferenceChangeListener(avpfChangedListener); if (!isNewAccount) { avpf.setChecked(mPrefs.avpfEnabled(n)); } EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6); avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener); if (!isNewAccount) { avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n)); avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n)); } CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7); escape.setOnPreferenceChangeListener(escapeChangedListener); if (!isNewAccount) { escape.setChecked(mPrefs.getReplacePlusByZeroZero(n)); } CheckBoxPreference friendlistSubscribe = (CheckBoxPreference) advanced.getPreference(8); friendlistSubscribe.setOnPreferenceChangeListener(friendlistSubscribeListener); if (!isNewAccount) { friendlistSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled()); } Preference linkAccount = advanced.getPreference(9); linkAccount.setOnPreferenceClickListener(linkAccountListener); PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_manage_key)); final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0); disable.setEnabled(true); disable.setOnPreferenceChangeListener(disableChangedListener); if (!isNewAccount) { disable.setChecked(!mPrefs.isAccountEnabled(n)); } CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1); mainAccount.setChecked(isDefaultAccount); mainAccount.setEnabled(!mainAccount.isChecked()); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.setDefaultAccount(n); disable.setEnabled(false); disable.setChecked(false); preference.setEnabled(false); return true; } }); if (!isNewAccount) { mainAccount.setEnabled(!mainAccount.isChecked()); } final Preference changePassword = manage.getPreference(2); if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) { changePassword.setEnabled(!isNewAccount); changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance()); LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater(); View layout = inflater.inflate(R.layout.new_password, null); final EditText pass1 = (EditText) layout.findViewById(R.id.password1); final EditText pass2 = (EditText) layout.findViewById(R.id.password2); alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinphoneAccountCreator.Status status = accountCreator .setPassword(pass1.getText().toString()); if (status.equals(LinphoneAccountCreator.Status.Ok)) { if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) { accountCreator.setUsername(mPrefs.getAccountUsername(n)); accountCreator.setHa1(mPrefs.getAccountHa1(n)); status = accountCreator.updatePassword(pass1.getText().toString()); if (!status.equals(LinphoneAccountCreator.Status.Ok)) { LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance()); } else { progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); Drawable d = new ColorDrawable(ContextCompat .getColor(LinphoneActivity.instance(), R.color.colorE)); d.setAlpha(200); progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); progress.getWindow().setBackgroundDrawable(d); progress.setContentView(R.layout.progress_dialog); progress.show(); } } else { LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched), LinphoneActivity.instance()); } return; } LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance()); } }); alert.setView(layout); alert.show(); return true; } }); } else { changePassword.setEnabled(false); } final Preference delete = manage.getPreference(3); delete.setEnabled(!isNewAccount); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.deleteAccount(n); LinphoneActivity.instance().refreshAccounts(); LinphoneActivity.instance().displaySettings(); return true; } }); }
From source file:com.almalence.opencam.Fragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); thiz = this;// www.ja v a 2s . com String settings = getArguments().getString("type"); ApplicationScreen.getPluginManager().loadHeaderContent(settings, this); if (null == getPreferenceScreen()) return; for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) { initSummary(getPreferenceScreen().getPreference(i)); } Preference nightPreference = findPreference("night"); if (nightPreference != null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (prefs.getBoolean("useCamera2Pref", false)) { getPreferenceScreen().removePreference(nightPreference); } else { Preference superPreference = findPreference("super"); getPreferenceScreen().removePreference(superPreference); } } final SeekBarPreference brightnessPref = (SeekBarPreference) this.findPreference("brightnessPref"); if (brightnessPref != null) { // Set seekbar summary : float gamma = PreferenceManager.getDefaultSharedPreferences(getActivity()).getFloat("gammaPref", 0.5f); brightnessPref.setSummary( this.getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma)); brightnessPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { private final Map<Integer, Float> gamma_map = new HashMap<Integer, Float>() { { put(0, 0.5f); put(1, 0.55f); put(2, 0.6f); put(3, 0.65f); put(4, 0.7f); } }; @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int radius = (Integer) newValue; float gamma = gamma_map.get(radius); PreferenceManager .getDefaultSharedPreferences(Fragment.thiz.getActivity().getApplicationContext()).edit() .putFloat("gammaPref", gamma).commit(); brightnessPref.setSummary(getActivity() .getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma)); return true; } }); } final CheckBoxPreference upscalePref = (CheckBoxPreference) this.findPreference("upscaleResult"); if (upscalePref != null) { Size size = CameraController.getMaxCameraImageSize(CameraController.YUV); long resMpx = 0; float mpix = 0.0f; if (size != null) { resMpx = (long) ((long) size.getWidth() * (long) size.getHeight() * 2.25); mpix = (float) resMpx / 1000000.f; } String name = String.format("%3.1f Mpix ", mpix); upscalePref.setSummary( getActivity().getString(R.string.Pref_Super_SummaryUpscale).replace("$1", "" + name)); } Preference cameraParameters = findPreference("camera_parameters"); if (cameraParameters != null) { cameraParameters.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { showCameraParameters(); } catch (Exception e) { e.printStackTrace(); } return true; } }); } CheckBoxPreference helpPref = (CheckBoxPreference) findPreference("showHelpPrefCommon"); if (helpPref != null) helpPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { if (((CheckBoxPreference) preference).isChecked()) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(MainScreen.getMainContext()); Editor prefsEditor = prefs.edit(); prefsEditor.putBoolean("droShowHelp", true); prefsEditor.putBoolean("sequenceRemovalShowHelp", true); prefsEditor.putBoolean("panoramaShowHelp", true); prefsEditor.putBoolean("superShowHelp", true); prefsEditor.putBoolean("groupshotRemovalShowHelp", true); prefsEditor.putBoolean("objectRemovalShowHelp", true); prefsEditor.putBoolean("bestShotShowHelp", true); prefsEditor.commit(); } return true; } }); EditTextPreference prefix = (EditTextPreference) this .findPreference(getResources().getString(R.string.Preference_SavePathPrefixValue)); EditTextPreference postfix = (EditTextPreference) this .findPreference(getResources().getString(R.string.Preference_SavePathPostfixValue)); initExportName(null, null); if (prefix != null) { prefix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { initExportName(preference, newValue); return true; } }); } if (postfix != null) { postfix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { initExportName(preference, newValue); return true; } }); } Preference sonyPreference = findPreference(MainScreen.sSonyCamerasPref); if (sonyPreference != null) { sonyPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean sonyCamerasAvailable = (Boolean) newValue; if (sonyCamerasAvailable) { Toast.makeText(getActivity(), getActivity().getString(R.string.pref_general_more_sonyCamera_available), Toast.LENGTH_SHORT).show(); } return true; } }); } ListPreference saveToPreference = (ListPreference) this .findPreference(getResources().getString(R.string.Preference_SaveToValue)); // if android 5+, then remove "save to SD card" option. Because it's // equals to "save to custom folder" option. if (saveToPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CharSequence[] entries = saveToPreference.getEntries(); CharSequence[] entriyValues = saveToPreference.getEntryValues(); CharSequence[] newEntries = new String[2]; CharSequence[] newEntriyValues = new String[2]; newEntries[0] = entries[0]; newEntries[1] = entries[2]; newEntriyValues[0] = entriyValues[0]; newEntriyValues[1] = entriyValues[2]; saveToPreference.setEntries(newEntries); saveToPreference.setEntryValues(newEntriyValues); } if (saveToPreference != null) { saveToPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int v = -1; int v_old = 0; try { v = Integer.parseInt(newValue.toString()); v_old = Integer.parseInt(((ListPreference) preference).getValue()); } catch (NumberFormatException e) { } if ((v == 2 || v == 1) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Toast.makeText(MainScreen.getInstance(), MainScreen.getAppResources() .getString(R.string.pref_advanced_saving_saveToPref_CantSaveToSD), Toast.LENGTH_LONG).show(); if (isDeviceRooted()) { Intent intent = new Intent(Preferences.thiz, FolderPicker.class); intent.putExtra(MainScreen.sSavePathPref, v_old); Preferences.thiz.startActivity(intent); return true; } else return false; } } if (v == 2 || v == 1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, CHOOSE_FOLDER_CODE); } else if (v != 1) { Intent intent = new Intent(Preferences.thiz, FolderPicker.class); intent.putExtra(MainScreen.sSavePathPref, v_old); Preferences.thiz.startActivity(intent); } } return true; } }); } PreferenceCategory cat = (PreferenceCategory) this.findPreference("Pref_VFCommon_Preference_Category"); if (cat != null) { CheckBoxPreference cp = (CheckBoxPreference) cat.findPreference("maxScreenBrightnessPref"); if (cp != null) { cp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean value = Boolean.parseBoolean(newValue.toString()); setScreenBrightness(value); return true; } }); } } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); boolean MaxScreenBrightnessPreference = prefs.getBoolean("maxScreenBrightnessPref", false); setScreenBrightness(MaxScreenBrightnessPreference); }
From source file:com.ubuntuone.android.files.activity.PreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mContext = this; mTracker = GoogleAnalyticsTracker.getInstance(); mTracker.start(Analytics.U1F_ACCOUNT, this); mTracker.trackPageView(TAG);/* w ww. j a v a2s.c o m*/ super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Account category. final Preference username = findPreference(Preferences.USERNAME_KEY); final String usernameSummary = Preferences.getString(Preferences.USERNAME_KEY, "(?)"); username.setSummary(usernameSummary); setupOnClickPreference(Pref.INVITE_FRIEND, this); final Preference purchaseStorage = findPreference(Pref.PURCHASE_STORAGE); purchaseStorage.setOnPreferenceClickListener(mPurchaseStorageListener); final Preference upgradePlan = findPreference(Pref.UPGRADE_PLAN); upgradePlan.setOnPreferenceClickListener(mLinkListener); // Options category. final PreferenceScreen mediaUploadScreen = (PreferenceScreen) findPreference(Pref.MEDIA_UPLOAD); mediaUploadScreen.setOnPreferenceClickListener(whiteHackClick); // Photo Auto Upload final CheckBoxPreference photosAutoUploadToggle = (CheckBoxPreference) findPreference( Preferences.PHOTO_UPLOAD_ENABLED_KEY); photosAutoUploadToggle.setOnPreferenceClickListener(mPhotosAutoUploadToggleListener); final Preference photosAutoUploadSources = findPreference(Pref.PHOTOS_AUTO_UPLOAD_SOURCES); photosAutoUploadSources.setOnPreferenceClickListener(mPhotosAutoUploadSourcesListener); mPhotosAutoUploadDir = (Preference) findPreference(Preferences.PHOTO_UPLOAD_DIR_KEY); mPhotosAutoUploadDir.setOnPreferenceClickListener(mPhotosAutoUploadDirListener); final String photosAutoUploadDirectory = Preferences.getPhotoUploadDirectory(); mPhotosAutoUploadDir.setDefaultValue(photosAutoUploadDirectory); mPhotosAutoUploadDir.setSummary(photosAutoUploadDirectory); final Preference uploadPhotosNow = findPreference(Pref.UPLOAD_PHOTOS_NOW); uploadPhotosNow.setOnPreferenceClickListener(mUploadPhotosNowListener); final Preference cancelAllUploads = findPreference(Pref.CANCEL_ALL_UPLOADS); cancelAllUploads.setOnPreferenceClickListener(mCancelAllUploadsListener); // General final PreferenceScreen advancedOptionsScreen = (PreferenceScreen) findPreference(Pref.ADVANCED_OPTIONS); advancedOptionsScreen.setOnPreferenceClickListener(whiteHackClick); final Preference autoRetry = findPreference(Preferences.AUTO_RETRY_FAILED); autoRetry.setOnPreferenceChangeListener(mAutoRetryListener); final Preference clearPreviewCache = findPreference(Pref.CLEAR_PREVIEW_CACHE); clearPreviewCache.setOnPreferenceClickListener(mClearPreviewCacheListener); final Preference clearThumbCache = findPreference(Pref.CLEAR_THUMB_CACHE); clearThumbCache.setOnPreferenceClickListener(mClearThumbCacheListener); final Preference removeDevice = findPreference(Pref.REMOVE_DEVICE); removeDevice.setOnPreferenceClickListener(mRemoveDeviceListener); mRetryFailed = findPreference(Pref.RETRY_FAILED); mRetryFailed.setOnPreferenceClickListener(mRetryFailedListener); mCancelFailed = findPreference(Pref.CANCEL_FAILED); mCancelFailed.setOnPreferenceClickListener(mCancelFailedListener); // Manage category. final Preference manageAccount = findPreference(Pref.MANAGE_ACCOUNT); manageAccount.setOnPreferenceClickListener(mLinkListener); final Preference supportOptions = findPreference(Pref.SUPPORT_OPTIONS); supportOptions.setOnPreferenceClickListener(mLinkListener); final Preference feedback = findPreference(Pref.FEEDBACK); feedback.setOnPreferenceClickListener(mFeedbackListener); final PreferenceScreen reportScreen = (PreferenceScreen) findPreference(Pref.REPORT_PROBLEM); reportScreen.setOnPreferenceClickListener(whiteHackClick); mCollectLogs = (CheckBoxPreference) findPreference(Pref.COLLECT_LOGS); mCollectLogs.setOnPreferenceClickListener(mCollectLogsListener); mReviewLogs = findPreference(Pref.REVIEW_LOGS); mReviewLogs.setOnPreferenceClickListener(mReviewLogsListener); mSendLogs = findPreference(Pref.SEND_LOGS); mSendLogs.setOnPreferenceClickListener(mSendLogsListener); final PreferenceScreen about = (PreferenceScreen) findPreference(Pref.ABOUT); about.setSummary(UbuntuOneFiles.getVersion()); about.setOnPreferenceClickListener(whiteHackClick); final Preference license = findPreference(Pref.LICENSE); license.setOnPreferenceClickListener(mLinkListener); final Preference changelog = findPreference(Pref.CHANGELOG); changelog.setOnPreferenceClickListener(mChangelogListener); final Preference author = findPreference(Pref.AUTHORS); author.setOnPreferenceClickListener(mLinkListener); final Preference webpage = findPreference(Pref.WEBPAGE); webpage.setOnPreferenceClickListener(mLinkListener); final Preference greendroid = findPreference(Pref.GREENDROID); greendroid.setOnPreferenceClickListener(mLinkListener); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UpDownService.BROADCAST_UPLOAD_INFO.equals(action)) { final String info = intent.getStringExtra(Intent.EXTRA_TEXT); if (info != null) { runOnUiThread(new Runnable() { @Override public void run() { adjustTransferPreferencesState(); Preference p = findPreference(Pref.UPLOAD_PHOTOS_NOW); if (p != null) { p.setSummary(info); } } }); } } } }; registerAutoUploadInfoReceiver(receiver); Intent intent = getIntent(); if (intent != null) { if (intent.hasExtra(AUTOUPLOAD_SCREEN)) { openPreference(Pref.MEDIA_UPLOAD); } else if (intent.hasExtra(PURCHASE_STORAGE_SCREEN)) { openPreference(Pref.PURCHASE_STORAGE); } else if (intent.hasExtra(SHOW_RETRY_FAILED)) { // Simply shows top screen. Hilight retry failed pref? } } }