List of usage examples for android.preference CheckBoxPreference setOnPreferenceChangeListener
public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener)
From source file:fi.iki.murgo.irssinotifier.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "Opened settings"); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_screen); final Context ctx = this; final CheckBoxPreference enabled = (CheckBoxPreference) findPreference("NotificationsEnabled"); enabled.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean checked = (Boolean) newValue; String s = "Disabling notifications..."; if (checked) { s = "Enabling notifications..."; }/*from www .j a va 2 s . co m*/ SettingsSendingTask task = new SettingsSendingTask(SettingsActivity.this, "Sending settings", s); task.setCallback(new Callback<ServerResponse>() { @Override public void doStuff(ServerResponse result) { if (result.getException() != null) { if (result.getException() instanceof IOException) { MessageBox.Show(ctx, "Network error", "Ensure your internet connection works and try again.", null); } else if (result.getException() instanceof AuthenticationException) { MessageBox.Show(ctx, "Authentication error", "Unable to authenticate to server.", null); } else if (result.getException() instanceof ServerException) { MessageBox.Show(ctx, "Server error", "Mystical server error, check if updates are available", null); } else { MessageBox.Show(ctx, null, "Unable to send settings to the server! Please try again later!", null); } enabled.setChecked(!checked); } } }); task.execute(); return true; } }); Preference aboutPref = findPreference("about"); aboutPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent i = new Intent(ctx, AboutActivity.class); startActivity(i); finish(); return true; } }); Preference channelsPref = findPreference("channels"); channelsPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent i = new Intent(ctx, ChannelSettingsActivity.class); startActivity(i); return true; } }); ListPreference mode = (ListPreference) findPreference("notificationModeString"); mode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { NotificationMode m = NotificationMode.PerChannel; String v = (String) newValue; if (v.equals(ctx.getResources().getStringArray(R.array.notification_modes)[0])) m = NotificationMode.Single; if (v.equals(ctx.getResources().getStringArray(R.array.notification_modes)[1])) m = NotificationMode.PerChannel; if (v.equals(ctx.getResources().getStringArray(R.array.notification_modes)[2])) m = NotificationMode.PerMessage; Preferences p = new Preferences(ctx); p.setNotificationMode(m); return true; } }); Preference initialSettingsPref = findPreference("redoInitialSettings"); initialSettingsPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Preferences prefs = new Preferences(ctx); prefs.setAuthToken(null); prefs.setAccountName(null); prefs.setGcmRegistrationId(null); prefs.setLicenseCount(0); IrssiNotifierActivity.refreshIsNeeded(); finish(); return true; } }); Preference disableThemePref = findPreference("ThemeDisabled"); disableThemePref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { IrssiNotifierActivity.refreshIsNeeded(); return true; } }); handleColorPicker(); handleIcb(); if (!LicenseHelper.isPlusVersion(this)) { CheckBoxPreference usePullMechanismPref = (CheckBoxPreference) findPreference("UsePullMechanism"); usePullMechanismPref.setSummary(usePullMechanismPref.getSummary() + ". Only in Plus version."); usePullMechanismPref.setEnabled(false); usePullMechanismPref.setChecked(false); } }
From source file:com.doplgangr.secrecy.settings.SettingsFragment.java
private void preparePreferenceStealthMode() { final CheckBoxPreference stealth_mode = (CheckBoxPreference) findPreference(Config.STEALTH_MODE); stealth_mode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override// www .j a va2s. c o m public boolean onPreferenceChange(Preference preference, Object o) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getActivity()) .edit(); if (!(Boolean) o) { StealthMode.showApp(context); editor.putBoolean(Config.STEALTH_MODE, (Boolean) o); editor.putString(Config.STEALTH_MODE_PASSWORD, ""); editor.apply(); } else { editor.putBoolean(Config.STEALTH_MODE, (Boolean) o); editor.apply(); } return true; } }); }
From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java
private void setupSimplePreferencesScreen() { addPreferencesFromResource(R.xml.pref_application); applicationCategory = (PreferenceCategory) findPreference("header_application"); // Listen for check/uncheck all tap findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override/*from w w w. j a va 2s . c o m*/ public boolean onPreferenceChange(Preference arg0, Object arg1) { for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) { // Uncheck or check all items ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1); } return true; } }); class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> { private PackageManager packageManager; @Override protected void onPreExecute() { progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true); } @Override protected List<ApplicationInfo> doInBackground(String... notif) { packageManager = getApplicationContext().getPackageManager(); // Comparator used to sort applications by name class CustomComparator implements Comparator<ApplicationInfo> { @Override public int compare(ApplicationInfo arg0, ApplicationInfo arg1) { return arg0.loadLabel(packageManager).toString() .compareTo(arg1.loadLabel(packageManager).toString()); } } // Get installed applications Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ApplicationInfo> appList = getApplicationContext().getPackageManager() .getInstalledApplications(PackageManager.GET_META_DATA); // Sort by application name Collections.sort(appList, new CustomComparator()); return appList; } @Override protected void onPostExecute(List<ApplicationInfo> result) { // Add each application to screen for (ApplicationInfo appInfo : result) { CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this); c.setTitle(appInfo.loadLabel(packageManager).toString()); c.setSummary(appInfo.packageName); c.setIcon(appInfo.loadIcon(packageManager)); c.setKey(appInfo.packageName); c.setChecked(true); c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // On tap, show an enabled/disabled notification on the desktop Object[] notif = new Object[3]; if (arg1.toString().equals("true")) { notif[0] = arg0.getTitle().toString() + " notifications enabled"; notif[1] = "via LinConnect"; notif[2] = arg0.getIcon(); } else { notif[0] = arg0.getTitle().toString() + " notifications disabled"; notif[1] = "via LinConnect"; notif[2] = arg0.getIcon(); } new TestTask().execute(notif); return true; } }); applicationCategory.addPreference(c); } progressDialog.dismiss(); } } new ApplicationTask().execute(); }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); Resources resources = getResources(); TwoStatePreference runningPref = findPref("running_switch"); updateRunningState();/*from w ww.ja v a2 s. co m*/ runningPref.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { startServer(); } else { stopServer(); } return true; }); PreferenceScreen prefScreen = findPref("preference_screen"); Preference marketVersionPref = findPref("market_version"); marketVersionPref.setOnPreferenceClickListener(preference -> { // start the market at our application Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp")); try { // this can fail if there is no market installed startActivity(intent); } catch (Exception e) { Cat.e("Failed to launch the market."); e.printStackTrace(); } return false; }); if (!App.isFreeVersion()) { prefScreen.removePreference(marketVersionPref); } updateLoginInfo(); EditTextPreference usernamePref = findPref("username"); usernamePref.setOnPreferenceChangeListener((preference, newValue) -> { String newUsername = (String) newValue; if (preference.getSummary().equals(newUsername)) return false; if (!newUsername.matches("[a-zA-Z0-9]+")) { Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show(); return false; } stopServer(); return true; }); mPassWordPref = findPref("password"); mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); mAutoconnectListPref = findPref("autoconnect_preference"); mAutoconnectListPref.setOnPopulateListener(pref -> { Cat.d("autoconnect populate listener"); WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs == null) { Cat.e("Unable to receive wifi configurations, bark at user and bail"); Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points, Toast.LENGTH_LONG).show(); return; } CharSequence[] ssids = new CharSequence[configs.size()]; CharSequence[] niceSsids = new CharSequence[configs.size()]; for (int i = 0; i < configs.size(); ++i) { ssids[i] = configs.get(i).SSID; String ssid = configs.get(i).SSID; if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } niceSsids[i] = ssid; } pref.setEntries(niceSsids); pref.setEntryValues(ssids); }); mAutoconnectListPref.setOnPreferenceClickListener(preference -> { Cat.d("Clicked"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) { new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title) .setMessage(R.string.request_coarse_location_dlg_message) .setPositiveButton(android.R.string.ok, (dialog, which) -> { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); }).setOnCancelListener(dialog -> { mAutoconnectListPref.getDialog().cancel(); }).create().show(); } else { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); } } } return false; }); EditTextPreference portnum_pref = findPref("portNum"); portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default))); portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> { String newPortnumString = (String) newValue; if (preference.getSummary().equals(newPortnumString)) return false; int portnum = 0; try { portnum = Integer.parseInt(newPortnumString); } catch (Exception e) { Cat.d("Error parsing port number! Moving on..."); } if (portnum <= 0 || 65535 < portnum) { Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show(); return false; } preference.setSummary(newPortnumString); stopServer(); return true; }); Preference chroot_pref = findPref("chrootDir"); chroot_pref.setSummary(FsSettings.getChrootDirAsString()); chroot_pref.setOnPreferenceClickListener(preference -> { AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir()) .setSelectedButton(R.string.select, path -> { if (preference.getSummary().equals(path)) return; if (!FsSettings.setChrootDir(path)) return; // TODO: this is a hotfix, create correct resources, improve UI/UX final File root = new File(path); if (!root.canRead()) { Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.", Toast.LENGTH_LONG).show(); } else if (!root.canWrite()) { Toast.makeText(getActivity(), "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.", Toast.LENGTH_LONG).show(); } preference.setSummary(path); stopServer(); }).setNegativeButton(R.string.cancel, null).create(); folderPicker.show(); return true; }); final CheckBoxPreference wakelock_pref = findPref("stayAwake"); wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage"); String externalStorageUri = FsSettings.getExternalStorageUri(); if (externalStorageUri == null) { writeExternalStorage_pref.setChecked(false); } writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> { if ((boolean) newValue) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE); return false; } else { FsSettings.setExternalStorageUri(null); return true; } }); ListPreference theme = findPref("theme"); theme.setSummary(theme.getEntry()); theme.setOnPreferenceChangeListener((preference, newValue) -> { theme.setSummary(theme.getEntry()); getActivity().recreate(); return true; }); Preference help = findPref("help"); help.setOnPreferenceClickListener(preference -> { Cat.v("On preference help clicked"); Context context = getActivity(); AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title) .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create(); ad.show(); Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL); return true; }); Preference about = findPref("about"); about.setOnPreferenceClickListener(preference -> { startActivity(new Intent(getActivity(), AboutActivity.class)); return true; }); }
From source file:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) -? " SSL"//from ww w .j a v a2 s . c om * @param group , ??? * @param dependencyKey -?? ? , null */ protected void addUnsafeSslPreference(PreferenceGroup group, String dependencyKey) { final Context context = group.getContext(); CheckBoxPreference unsafeSslPref = new CheckBoxPreference(context); //? " SSL" unsafeSslPref.setTitle(R.string.pref_ignore_ssl_errors); unsafeSslPref.setSummary(R.string.pref_ignore_ssl_errors_summary); unsafeSslPref.setKey(getSharedKey(PREF_KEY_UNSAFE_SSL)); unsafeSslPref.setDefaultValue(false); unsafeSslPref.setOnPreferenceChangeListener(updateHttpListener); group.addPreference(unsafeSslPref); if (dependencyKey != null) unsafeSslPref.setDependency(dependencyKey); }
From source file:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) ? ?-?/* ww w . ja v a 2 s. c o m*/ * @param group , ??? */ protected void addProxyPreferences(PreferenceGroup group) { final Context context = group.getContext(); PreferenceCategory proxyCat = new PreferenceCategory(context); //? ? ? proxyCat.setTitle(R.string.pref_cat_proxy); group.addPreference(proxyCat); CheckBoxPreference useProxyPref = new CheckBoxPreference(context); //? "? ? " useProxyPref.setTitle(R.string.pref_use_proxy); useProxyPref.setSummary(R.string.pref_use_proxy_summary); useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY)); useProxyPref.setDefaultValue(false); useProxyPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(useProxyPref); EditTextPreference proxyHostPref = new EditTextPreference(context); // ? ?-? proxyHostPref.setTitle(R.string.pref_proxy_host); proxyHostPref.setDialogTitle(R.string.pref_proxy_host); proxyHostPref.setSummary(R.string.pref_proxy_host_summary); proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST)); proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST); proxyHostPref.getEditText().setSingleLine(); proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); proxyHostPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPref); proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); EditTextPreference proxyHostPort = new EditTextPreference(context); // ?-? proxyHostPort.setTitle(R.string.pref_proxy_port); proxyHostPort.setDialogTitle(R.string.pref_proxy_port); proxyHostPort.setSummary(R.string.pref_proxy_port_summary); proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT)); proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT); proxyHostPort.getEditText().setSingleLine(); proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); proxyHostPort.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPort); proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); }
From source file:com.juegoteca.actividades.Opciones.java
/** * Shows the simplified settings UI if the device configuration if the * device configuration dictates that a simplified, single-pane UI should be * shown.//from w w w. j av a 2s .com */ @SuppressWarnings("deprecation") private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) { return; } final SharedPreferences settings = getSharedPreferences("UserInfo", 0); // In the simplified UI, fragments are not used at all and we instead // use the older PreferenceActivity APIs. addPreferencesFromResource(R.xml.pref_container); // Add 'general' preferences. PreferenceCategory fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_general); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_general); CheckBoxPreference preferenciaOrden = (CheckBoxPreference) findPreference("orden_ultimos_anadidos"); preferenciaOrden.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("orden_ultimos_fecha_compra", true); editor.commit(); } else { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("orden_ultimos_fecha_compra", false); editor.commit(); } return true; } }); ListPreference preferenciaModeda = (ListPreference) findPreference("currencys"); preferenciaModeda.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences.Editor editor = settings.edit(); editor.putString("currency", newValue.toString()); editor.commit(); return true; } }); CheckBoxPreference preferenciaDetalle = (CheckBoxPreference) findPreference("detalle_imagen"); preferenciaDetalle.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("detalle_imagen", true); editor.commit(); } else { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("detalle_imagen", false); editor.commit(); } return true; } }); SwitchPreference preferenciaTwitter = (SwitchPreference) findPreference("twitter"); preferenciaTwitter.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue instanceof Boolean) { boolean isChecked = (boolean) newValue; if (isChecked) { Intent intent = new Intent(getApplicationContext(), TwitterActivity.class); startActivity(intent); return true; } } return true; } }); // Add 'data and sync' preferences, and a corresponding header. PreferenceCategory fakeHeader2 = new PreferenceCategory(this); fakeHeader2.setTitle(R.string.pref_header_data); getPreferenceScreen().addPreference(fakeHeader2); addPreferencesFromResource(R.xml.pref_datos_seguridad); // Establece las acciones al hacer click en las preferencias Preference preferenciaCopiaExportar = findPreference("exportar_copia_seguridad"); preferenciaCopiaExportar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Toast t; if (!utilidades.baseDatosEsVacia()) { new CopiaSeguridadFichero().execute(); } else { t = Toast.makeText(getApplicationContext(), getString(R.string.no_data_backup), Toast.LENGTH_SHORT); t.show(); } return true; } }); Preference preferenciaCopiaImportar = findPreference("importar_restaurar_seguridad"); preferenciaCopiaImportar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { AlertDialog.Builder builder = new AlertDialog.Builder(Opciones.this); builder.setMessage(R.string.alerta_restaurar_texto).setTitle(R.string.alerta_restaurar_titulo); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/zip"); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(intent, "Escoja el fichero de copia..."), FILE_SELECT_CODE); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog return; } }); AlertDialog dialog = builder.create(); dialog.show(); return true; } }); Preference preferenciaBorrar = findPreference("borrar_todo"); preferenciaBorrar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { utilidades.borrarTodosDatos(true); return true; } }); // Add 'otros' preferences. PreferenceCategory fakeHeader3 = new PreferenceCategory(this); fakeHeader3.setTitle(R.string.pref_header_otros); getPreferenceScreen().addPreference(fakeHeader3); addPreferencesFromResource(R.xml.pref_otros); Resources res = getResources(); // String versionName = res.getString(R.string.app_version); String versionName = ""; try { versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; } catch (NameNotFoundException e) { // versionName = res.getString(R.string.app_version); } String version = res.getString(R.string.pref_title_version, versionName); Preference preferenciaInicioSesion = findPreference("about"); preferenciaInicioSesion.setTitle(version); Preference preferenciaLicencia = findPreference("licenses"); preferenciaLicencia.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(getApplicationContext(), AcercaDe.class); startActivity(intent); return true; } }); }
From source file:fi.iki.murgo.irssinotifier.SettingsActivity.java
private void handleIcb() { CheckBoxPreference showIcbIconPreference = (CheckBoxPreference) findPreference("IcbEnabled"); if (!IntentSniffer.isPackageAvailable(this, IrssiConnectbotLauncher.PACKAGE_IRSSICONNECTBOT)) { PreferenceCategory icbCategory = (PreferenceCategory) findPreference("IcbCategory"); icbCategory.setEnabled(false);/*ww w. j a v a2s .c om*/ showIcbIconPreference.setChecked(false); showIcbIconPreference.setSummary("Install Irssi ConnectBot to show it in the action bar"); } else { showIcbIconPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { IrssiNotifierActivity.refreshIsNeeded(); return true; } }); Preference icbHostPref = findPreference("IcbHost"); Preferences prefs = new Preferences(this); String hostName = prefs.getIcbHostName(); String summary = "Select which Irssi ConnectBot host to open when pressing the ICB icon"; if (hostName != null) summary += ". Currently selected host: " + hostName; icbHostPref.setSummary(summary); icbHostPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent i = new Intent("android.intent.action.PICK"); i.setClassName(IrssiConnectbotLauncher.PACKAGE_IRSSICONNECTBOT, IrssiConnectbotLauncher.PACKAGE_IRSSICONNECTBOT + ".HostListActivity"); startActivityForResult(i, ICB_HOST_REQUEST_CODE); return true; } }); } }
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()); }/* www . jav a 2s.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)); } 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 w ww . j a v a 2s . c om*/ 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; } }); }