List of usage examples for android.preference CheckBoxPreference setChecked
public void setChecked(boolean checked)
From source file:net.freifunk.android.discover.SettingsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_data_sync); // get data via the key ArrayList<NodeMap> nodeMapArrayList = new ArrayList<NodeMap>(MapMaster.getInstance().getMaps().values()); PreferenceCategory communities = (PreferenceCategory) findPreference("communities"); // sort by Name Collections.sort(nodeMapArrayList, new NodeMapComparator()); if (nodeMapArrayList != null && communities != null) { for (final NodeMap nm : nodeMapArrayList) { PreferenceScreen communityPreferenceScreen = getPreferenceManager() .createPreferenceScreen(SettingsActivity.this); communityPreferenceScreen.setTitle(nm.getMapName()); communityPreferenceScreen.setKey(nm.getMapName()); final CheckBoxPreference deactivateCommunityPreference = new CheckBoxPreference( SettingsActivity.this); // TODO: move Strings to resources deactivateCommunityPreference.setTitle("Community aktiv"); deactivateCommunityPreference .setSummary("deaktivieren, falls Community nicht auf der Karte angezeigt werden soll"); deactivateCommunityPreference.setKey("community_deactivate_" + nm.getMapName()); deactivateCommunityPreference.setChecked(nm.isActive()); deactivateCommunityPreference .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Database db = Database.getInstance(null); boolean newActive = newValue.toString().equals("true") ? true : false; nm.setActive(newActive); db.addNodeMap(nm); // reload if set to active if (newActive) { nm.loadNodes(); } else { nm.updateNodes(); }//from w ww . j a v a2 s . c o m return true; } }); EditTextPreference editCommunityPreference = new EditTextPreference(SettingsActivity.this); // TODO: move Strings to resources editCommunityPreference.setTitle("URL bearbeiten"); editCommunityPreference.setSummary("aendern, falls eine andere Quelle genutzt werden soll."); editCommunityPreference.setKey("community_edit_" + nm.getMapName()); editCommunityPreference.setText(nm.getMapUrl()); editCommunityPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Database db = Database.getInstance(null); // remove old nodes from map nm.setActive(false); EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_NODES, nm)); // we should probably do this async as well db.deleteAllNodesForMap(nm); // load new nodes NodeMap newMap = new NodeMap(nm.getMapName(), (String) newValue, true); db.addNodeMap(newMap); //HashMap<String, NodeMap> nodeResult = new HashMap<String, NodeMap>(1); //nodeResult.put(nm.getMapName(), nm); newMap.updateNodes(); //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.LOAD_NODES, nm)); //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_MAP, nodeResult)); return true; } }); communityPreferenceScreen.addPreference(deactivateCommunityPreference); communityPreferenceScreen.addPreference(editCommunityPreference); communities.addPreference(communityPreferenceScreen); } } setupActionBar(); }
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 www. j av a 2s . c o 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:de.j4velin.wifiAutoOff.Preferences.java
@SuppressWarnings("deprecation") @Override// w w w . j a v a 2s.co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); if (BuildConfig.DEBUG && PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); } status = (StatusPreference) findPreference("status"); status.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); boolean connected = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); if (wm.isWifiEnabled() && !connected) { try { startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } else if (!wm.isWifiEnabled()) { wm.setWifiEnabled(true); } else { try { startActivity( new Intent(Settings.ACTION_WIFI_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } return true; } }); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final CheckBoxPreference screen_off = (CheckBoxPreference) findPreference("off_screen_off"); screen_off.setSummary( getString(R.string.for_at_least, prefs.getInt("screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF))); if (!keepWiFiOn(this)) { screen_off.setChecked(false); } screen_off.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { if (!keepWiFiOn(Preferences.this)) { new AlertDialog.Builder(Preferences.this).setMessage(R.string.sleep_policy) .setPositiveButton(R.string.adv_wifi_settings, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Settings.ACTION_WIFI_IP_SETTINGS) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show(); } } }).setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create().show(); return false; } if (android.os.Build.VERSION.SDK_INT >= 11) { APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false); } else { showPre11NumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false); } } return true; } }); findPreference("off_no_network").setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { if (android.os.Build.VERSION.SDK_INT >= 11) { APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false); } else { showPre11NumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false); } } return true; } }); final CheckBoxPreference on_at = (CheckBoxPreference) findPreference("on_at"); on_at.setTitle(getString(R.string.at_summary, prefs.getString("on_at_time", Receiver.ON_AT_TIME))); on_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { String[] time = prefs.getString("on_at_time", Receiver.ON_AT_TIME).split(":"); final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { prefs.edit().putString("on_at_time", hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit(); on_at.setTitle(getString(R.string.at_summary, hourOfDay + ":" + (minute < 10 ? "0" + minute : minute))); } }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { on_at.setChecked(false); } }); dialog.setTitle(getString(R.string.turn_wifi_on_at_)); dialog.show(); } return true; } }); final CheckBoxPreference off_at = (CheckBoxPreference) findPreference("off_at"); off_at.setTitle(getString(R.string.at_summary, prefs.getString("off_at_time", Receiver.OFF_AT_TIME))); off_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { String[] time = prefs.getString("off_at_time", Receiver.OFF_AT_TIME).split(":"); final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { prefs.edit().putString("off_at_time", hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit(); off_at.setTitle(getString(R.string.at_summary, hourOfDay + ":" + (minute < 10 ? "0" + minute : minute))); } }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { off_at.setChecked(false); } }); dialog.setTitle(getString(R.string.turn_wifi_off_at_)); dialog.show(); } return true; } }); final Preference on_every = findPreference("on_every"); final String[] time_names = getResources().getStringArray(R.array.time_names); // default 2 hours on_every.setTitle(getString(R.string.every_summary, prefs.getString("on_every_str", time_names[4]))); on_every.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((Boolean) newValue) { AlertDialog.Builder builder = new AlertDialog.Builder(Preferences.this); builder.setTitle(R.string.turn_wifi_on_every).setItems(time_names, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { prefs.edit().putInt("on_every_time_min", time_values[which]) .putString("on_every_str", time_names[which]).commit(); on_every.setTitle(getString(R.string.every_summary, time_names[which])); } }); builder.create().show(); } return true; } }); Preference locations = findPreference("locations"); if (BuildConfig.FLAVOR.equals("play")) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK)) { locations.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { startActivity(new Intent(Preferences.this, Locations.class)); return true; } }); } else { locations.setEnabled(false); } } else { locations.setSummary("Not available in F-Droid version"); locations.setEnabled(false); } final Preference power = findPreference("power_connected"); power.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { if ((boolean) newValue) { Intent battery = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (battery != null && battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0) { // already connected to external power prefs.edit().putBoolean("ignore_screen_off", true).commit(); } } else { prefs.edit().putBoolean("ignore_screen_off", false).commit(); } return true; } }); }
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. j av a2 s. c o m*/ 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: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 w w. j a v 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)); } 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 ww w . ja va2s . 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)); } 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:org.span.manager.ChangeSettingsActivity.java
private void updateView() { // user id//from www . jav a 2 s.c o m EditTextPreference uidEditTextPref = (EditTextPreference) findPreference("uidpref"); uidEditTextPref.setText(manetcfg.getUserId()); // wifi group wifiGroupPref = (PreferenceGroup) findPreference("wifiprefs"); boolean bluetoothOn = manetcfg.isUsingBluetooth(); wifiGroupPref.setEnabled(!bluetoothOn); // wifi encryption algorithm WifiEncryptionAlgorithmEnum encAlgorithm = manetcfg.getWifiEncryptionAlgorithm(); ListPreference wifiEncAlgorithmPref = (ListPreference) findPreference("encalgorithmpref"); wifiEncAlgorithmPref.setEnabled(false); // TODO: disable until tested wifiEncAlgorithmPref.setEntries(WifiEncryptionAlgorithmEnum.descriptionValues()); wifiEncAlgorithmPref.setEntryValues(WifiEncryptionAlgorithmEnum.stringValues()); wifiEncAlgorithmPref.setValueIndex(encAlgorithm.ordinal()); // wifi encryption setup method ListPreference wifiEncSetupMethodPref = (ListPreference) findPreference("encsetuppref"); wifiEncSetupMethodPref.setEnabled(false); // TODO: disable until tested if (encAlgorithm == WifiEncryptionAlgorithmEnum.NONE) { wifiEncSetupMethodPref.setEnabled(false); } else { wifiEncSetupMethodPref.setEnabled(true); if (manetcfg.getWifiDriver().startsWith("softap") || manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) { if (wifiEncSetupMethodPref != null) { wifiGroupPref.removePreference(wifiEncSetupMethodPref); } } else { wifiEncSetupMethodPref.setEntries(WifiEncryptionSetupMethodEnum.descriptionValues()); wifiEncSetupMethodPref.setEntryValues(WifiEncryptionSetupMethodEnum.stringValues()); wifiEncSetupMethodPref.setValueIndex(manetcfg.getWifiEncryptionSetupMethod().ordinal()); } } // wifi encryption password final EditTextPreference wifiEncPasswordEditTextPref = (EditTextPreference) findPreference("passwordpref"); wifiEncPasswordEditTextPref.setEnabled(false); // TODO: disable until tested if (encAlgorithm == WifiEncryptionAlgorithmEnum.NONE) { wifiEncPasswordEditTextPref.setEnabled(false); } else { wifiEncPasswordEditTextPref.setEnabled(true); final int origTextColorWifiEncKey = wifiEncPasswordEditTextPref.getEditText().getCurrentTextColor(); if (manetcfg.getWifiDriver().startsWith("softap") || manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) { Validation.setupWpaEncryptionValidators(wifiEncPasswordEditTextPref, origTextColorWifiEncKey); } else { Validation.setupWepEncryptionValidators(wifiEncPasswordEditTextPref, origTextColorWifiEncKey); } wifiEncPasswordEditTextPref.setText(manetcfg.getWifiEncryptionPassword()); } // wifi SSID EditTextPreference wifiSsidEditTextPref = (EditTextPreference) findPreference("ssidpref"); Validation.setupWifiSsidValidator(wifiSsidEditTextPref); wifiSsidEditTextPref.setText(manetcfg.getWifiSsid()); // wifi channel ListPreference channelpref = (ListPreference) findPreference("channelpref"); channelpref.setEnabled(false); // TODO: disable until tested String[] channelStrValues = WifiChannelEnum.stringValues(); String[] channelDescValues = WifiChannelEnum.descriptionValues(); // remove auto channel option if not supported by device if (!manetcfg.getWifiDriver().startsWith("softap") || !manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) { // auto channel option at first index String[] newChannelStrValues = new String[channelStrValues.length - 1]; String[] newChannelDescValues = new String[channelStrValues.length - 1]; for (int i = 1; i < channelStrValues.length; i++) { newChannelStrValues[i - 1] = channelStrValues[i]; newChannelDescValues[i - 1] = channelDescValues[i]; } channelpref.setEntries(newChannelDescValues); channelpref.setEntryValues(newChannelStrValues); WifiChannelEnum wifiChannel = manetcfg.getWifiChannel(); if (wifiChannel == WifiChannelEnum.AUTO) { channelpref.setValueIndex(WifiChannelEnum.CHANNEL_1.ordinal() - 1); } else { channelpref.setValueIndex(wifiChannel.ordinal() - 1); } } else { channelpref.setEntries(channelDescValues); channelpref.setEntryValues(channelStrValues); channelpref.setValueIndex(manetcfg.getWifiChannel().ordinal()); } // wifi transmit power ListPreference txpowerPreference = (ListPreference) findPreference("txpowerpref"); if (!manetcfg.isTransmitPowerSupported()) { // DEBUG if (txpowerPreference != null) { wifiGroupPref.removePreference(txpowerPreference); } } else { txpowerPreference.setEntries(WifiTxpowerEnum.descriptionValues()); txpowerPreference.setEntryValues(WifiTxpowerEnum.stringValues()); txpowerPreference.setValueIndex(manetcfg.getWifiTxpower().ordinal()); } // bluetooth group // disable bluetooth adhoc if not supported by the kernel if (true) { // !manetcfg.isBluetoothSupported() // TODO: disable until tested PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs"); btGroup.setEnabled(false); } // bluetooth // NOTE: bluetooth dependencies are specified in the layout XML // CheckBoxPreference bluetoothCheckboxPref = (CheckBoxPreference)findPreference("bluetoothonpref"); // bluetooth keep wifi CheckBoxPreference btKeepWifiCheckBoxPref = (CheckBoxPreference) findPreference("bluetoothkeepwifipref"); if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.ECLAIR) { PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs"); if (btKeepWifiCheckBoxPref != null) { btGroup.removePreference(btKeepWifiCheckBoxPref); } } else { btKeepWifiCheckBoxPref.setChecked(!manetcfg.isWifiDisabledWhenUsingBluetooth()); } // bluetooth discoverable CheckBoxPreference btdiscoverablePreference = (CheckBoxPreference) findPreference( "bluetoothdiscoverablepref"); if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.ECLAIR) { PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs"); if (btdiscoverablePreference != null) { btGroup.removePreference(btdiscoverablePreference); } } else { btdiscoverablePreference.setChecked(manetcfg.isBluetoothDiscoverableWhenInAdhocMode()); } // ip address EditTextPreference ipAddressEditTextPref = (EditTextPreference) findPreference("ippref"); Validation.setupIpAddressValidator(ipAddressEditTextPref); ipAddressEditTextPref.setText(manetcfg.getIpAddress()); // dns server EditTextPreference dnsServerEditTextPref = (EditTextPreference) findPreference("dnspref"); Validation.setupIpAddressValidator(dnsServerEditTextPref); dnsServerEditTextPref.setText(manetcfg.getDnsServer()); // routing protocol String currRoutingProtocol = manetcfg.getRoutingProtocol(); List<String> routingProtocolList = CoreTask.getRoutingProtocols(); String[] routingProtocols = new String[routingProtocolList.size()]; routingProtocolList.toArray(routingProtocols); ListPreference routingProtocolPreference = (ListPreference) findPreference("routingprotocolpref"); routingProtocolPreference.setEntries(routingProtocols); routingProtocolPreference.setEntryValues(routingProtocols); routingProtocolPreference.setValue(currRoutingProtocol); // routing ignore list JSONArray array = new JSONArray(manetcfg.getRoutingIgnoreList()); sharedPreferences.edit().putString("ignorepref", array.toString()).commit(); // wifi interface String currInterface = manetcfg.getWifiInterface(); String defaultInterface = DeviceConfig.getWifiInterface(manetcfg.getDeviceType()); List<String> interfaceList = CoreTask.getNetworkInterfaces(); if (!interfaceList.contains(defaultInterface)) { interfaceList.add(defaultInterface); } String[] interfaces = new String[interfaceList.size()]; interfaceList.toArray(interfaces); ListPreference interfacePreference = (ListPreference) findPreference("interfacepref"); interfacePreference.setEntries(interfaces); interfacePreference.setEntryValues(interfaces); if (interfaceList.contains(currInterface)) { interfacePreference.setValue(currInterface); } else { interfacePreference.setValue(defaultInterface); currInterface = defaultInterface; } // routing gateway String currGatewayInterface = manetcfg.getGatewayInterface(); interfaceList.remove(currInterface); // remove ad-hoc interface interfaceList.add(0, ManetConfig.GATEWAY_INTERFACE_NONE); interfaces = new String[interfaceList.size()]; interfaceList.toArray(interfaces); ListPreference gatewayPreference = (ListPreference) findPreference("gatewaypref"); gatewayPreference.setEntries(interfaces); gatewayPreference.setEntryValues(interfaces); gatewayPreference.setValue(currGatewayInterface); if (interfaceList.contains(currGatewayInterface)) { gatewayPreference.setValue(currGatewayInterface); } else { gatewayPreference.setValue(ManetConfig.GATEWAY_INTERFACE_NONE); } // screen on CheckBoxPreference screenOnPreference = (CheckBoxPreference) findPreference("screenonpref"); screenOnPreference.setChecked(manetcfg.isScreenOnWhenInAdhocMode()); // battery temperature setupFlag = true; }
From source file:github.daneren2005.dsub.fragments.SettingsFragment.java
private PreferenceScreen expandServer(final int instance) { final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); final EditTextPreference serverNamePreference = new EditTextPreference(context); serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); }//from w ww. j a v a2 s.c om serverNamePreference.setSummary(serverNamePreference.getText()); final EditTextPreference serverUrlPreference = new EditTextPreference(context); serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance); serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); } serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { super.onAddEditTextToDialogView(dialogView, editText); ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0); Button defaultButton = new Button(getContext()); defaultButton.setText(internalSSIDDisplay); defaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(internalSSID); } }); root.addView(defaultButton); } }; serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue(""); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(context); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(context); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); serverPasswordPreference.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); serverPasswordPreference.setSummary("***"); serverPasswordPreference.setTitle(R.string.settings_server_password); final CheckBoxPreference serverTagPreference = new CheckBoxPreference(context); serverTagPreference.setKey(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance); serverTagPreference.setChecked(Util.isTagBrowsing(context, instance)); serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary); serverTagPreference.setTitle(R.string.settings_browse_by_tags); serverPasswordPreference.setDialogTitle(R.string.settings_server_password); final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); serverOpenBrowser.setTitle(R.string.settings_server_open_browser); serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { openInBrowser(instance); return true; } }); Preference serverRemoveServerPreference = new Preference(context); serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance); serverRemoveServerPreference.setPersistent(false); serverRemoveServerPreference.setTitle(R.string.settings_servers_remove); serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Reset values to null so when we ask for them again they are new serverNamePreference.setText(null); serverUrlPreference.setText(null); serverUsernamePreference.setText(null); serverPasswordPreference.setText(null); // Don't use Util.getActiveServer since it is 0 if offline int activeServer = Util.getPreferences(context) .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); for (int i = instance; i <= serverCount; i++) { Util.removeInstanceName(context, i, activeServer); } serverCount--; SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.commit(); removeCurrent(); SubsonicFragment parentFragment = context.getCurrentFragment(); if (parentFragment instanceof SettingsFragment) { SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment; serverSelectionFragment.checkForRemoved(); } } }); return true; } }); Preference serverTestConnectionPreference = new Preference(context); serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance); serverTestConnectionPreference.setPersistent(false); serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title); serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { testConnection(instance); return false; } }); screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverTagPreference); screen.addPreference(serverSyncPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); return screen; }
From source file:github.popeen.dsub.fragments.SettingsFragment.java
private PreferenceScreen expandServer(final int instance) { final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); final EditTextPreference serverNamePreference = new EditTextPreference(context); serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); }/*from w w w .j a va 2s . c o m*/ serverNamePreference.setSummary(serverNamePreference.getText()); final EditTextPreference serverUrlPreference = new EditTextPreference(context); serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance); serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); } serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { super.onAddEditTextToDialogView(dialogView, editText); ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0); Button defaultButton = new Button(getContext()); defaultButton.setText(internalSSIDDisplay); defaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(internalSSID); } }); root.addView(defaultButton); } }; serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue(""); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(context); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(context); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); serverPasswordPreference.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); serverPasswordPreference.setSummary("***"); serverPasswordPreference.setTitle(R.string.settings_server_password); final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); serverOpenBrowser.setTitle(R.string.settings_server_open_browser); serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { openInBrowser(instance); return true; } }); Preference serverRemoveServerPreference = new Preference(context); serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance); serverRemoveServerPreference.setPersistent(false); serverRemoveServerPreference.setTitle(R.string.settings_servers_remove); serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Reset values to null so when we ask for them again they are new serverNamePreference.setText(null); serverUrlPreference.setText(null); serverUsernamePreference.setText(null); serverPasswordPreference.setText(null); // Don't use Util.getActiveServer since it is 0 if offline int activeServer = Util.getPreferences(context) .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); for (int i = instance; i <= serverCount; i++) { Util.removeInstanceName(context, i, activeServer); } serverCount--; SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.commit(); removeCurrent(); SubsonicFragment parentFragment = context.getCurrentFragment(); if (parentFragment instanceof SettingsFragment) { SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment; serverSelectionFragment.checkForRemoved(); } } }); return true; } }); Preference serverTestConnectionPreference = new Preference(context); serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance); serverTestConnectionPreference.setPersistent(false); serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title); serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { testConnection(instance); return false; } }); screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverSyncPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); return screen; }
From source file:org.linphone.SettingsFragment.java
private void uncheckAndHidePreference(int preferenceKey) { Preference preference = findPreference(getString(preferenceKey)); if (!(preference instanceof CheckBoxPreference)) return;/*from w w w. jav a2 s . c o m*/ CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference; checkBoxPreference.setChecked(false); hidePreference(checkBoxPreference); }