List of usage examples for android.preference PreferenceScreen setTitle
public void setTitle(CharSequence title)
From source file:com.nttec.everychan.chans.fourchan.FourchanModule.java
private void addPasscodePreference(PreferenceGroup preferenceGroup) { final Context context = preferenceGroup.getContext(); PreferenceScreen passScreen = preferenceGroup.getPreferenceManager().createPreferenceScreen(context); passScreen.setTitle("4chan pass"); EditTextPreference passTokenPreference = new EditTextPreference(context); EditTextPreference passPINPreference = new EditTextPreference(context); Preference passLoginPreference = new Preference(context); Preference passClearPreference = new Preference(context); passTokenPreference.setTitle("Token"); passTokenPreference.setDialogTitle("Token"); passTokenPreference.setKey(getSharedKey(PREF_KEY_PASS_TOKEN)); passTokenPreference.getEditText().setSingleLine(); passTokenPreference.getEditText()//from w w w. j a v a 2 s . c om .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); passPINPreference.setTitle("PIN"); passPINPreference.setDialogTitle("PIN"); passPINPreference.setKey(getSharedKey(PREF_KEY_PASS_PIN)); passPINPreference.getEditText().setSingleLine(); passPINPreference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); passLoginPreference.setTitle("Log In"); passLoginPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (!useHttps()) Toast.makeText(context, "Using HTTPS even if HTTP is selected", Toast.LENGTH_SHORT).show(); final String token = preferences.getString(getSharedKey(PREF_KEY_PASS_TOKEN), ""); final String pin = preferences.getString(getSharedKey(PREF_KEY_PASS_PIN), ""); final String authUrl = "https://sys.4chan.org/auth"; //only https final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask(); final ProgressDialog passAuthProgressDialog = new ProgressDialog(context); passAuthProgressDialog.setMessage("Logging in"); passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { passAuthTask.cancel(); } }); passAuthProgressDialog.setCanceledOnTouchOutside(false); passAuthProgressDialog.show(); Async.runAsync(new Runnable() { @Override public void run() { try { if (passAuthTask.isCancelled()) return; setPasscodeCookie(null, true); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("act", "do_login")); pairs.add(new BasicNameValuePair("id", token)); pairs.add(new BasicNameValuePair("pin", pin)); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build(); String response = HttpStreamer.getInstance().getStringFromUrl(authUrl, request, httpClient, null, passAuthTask, false); if (passAuthTask.isCancelled()) return; if (response.contains("Your device is now authorized")) { String passId = null; for (Cookie cookie : httpClient.getCookieStore().getCookies()) { if (cookie.getName().equals("pass_id")) { String value = cookie.getValue(); if (!value.equals("0")) { passId = value; break; } } } if (passId == null) { showToast("Could not get pass id"); } else { setPasscodeCookie(passId, true); showToast("Success! Your device is now authorized."); } } else if (response.contains("Your Token must be exactly 10 characters")) { showToast("Incorrect token"); } else if (response.contains("You have left one or more fields blank")) { showToast("You have left one or more fields blank"); } else if (response.contains("Incorrect Token or PIN")) { showToast("Incorrect Token or PIN"); } else { Matcher m = Pattern .compile("<strong style=\"color: red; font-size: larger;\">(.*?)</strong>") .matcher(response); if (m.find()) { showToast(m.group(1)); } else { showWebView(response); } } } catch (Exception e) { showToast(e.getMessage() == null ? resources.getString(R.string.error_unknown) : e.getMessage()); } finally { passAuthProgressDialog.dismiss(); } } private void showToast(final String message) { if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } }); } } private void showWebView(final String html) { if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { WebView webView = new WebView(context); webView.getSettings().setSupportZoom(true); webView.loadData(html, "text/html", null); new AlertDialog.Builder(context).setView(webView) .setNeutralButton(android.R.string.ok, null).show(); } }); } } }); return true; } }); passClearPreference.setTitle("Reset pass cookie"); passClearPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { setPasscodeCookie(null, true); Toast.makeText(context, "Cookie is reset", Toast.LENGTH_LONG).show(); return true; } }); passScreen.addPreference(passTokenPreference); passScreen.addPreference(passPINPreference); passScreen.addPreference(passLoginPreference); passScreen.addPreference(passClearPreference); preferenceGroup.addPreference(passScreen); }
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 ww w. j a v a 2 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 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: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 ww w . j a v a2s . 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:net.basilwang.StaticAttachmentActivity.java
private void reloadData(PreferenceCategory logonPreference, PreferenceScreen logonAddPreference, PreferenceManager preferenceManager) { // 2012-11-23 basilwang refresh tabbar title refreshActionBarTitle();/* w w w . j a v a 2s. com*/ logonPreference.removeAll(); logonPreference.addPreference(logonAddPreference); int accountId = PreferenceManager.getDefaultSharedPreferences(this) .getInt(LOGON_ACCOUNT_ID, 0); AccountService service = new AccountService(this); List<Account> list = service.getAccounts(); if (list.size() == 0) { logonAddPreference.setEnabled(true); } else { logonAddPreference.setEnabled(false); for (Account account : list) { PreferenceScreen preferenceItem = preferenceManager .createPreferenceScreen(this); // CheckBoxPreference checkBoxPreference = new // CheckBoxPreference(this); // make sure each key is unique preferenceItem.setKey(LOGON_ACCOUNT_PREFERENCES); preferenceItem.setTitle(PreferenceUtils.getPreferUserName(this)); if (accountId == account.getId()) preferenceItem.setSummary(R.string.already_checked); // preferenceItem.setChecked(false); // checkBoxPreference.setDisableDependentsState(disableDependentsState) // checkBoxPreference.setSelectable(false); preferenceItem.setOrder(0); preferenceItem.setOnPreferenceClickListener(this); logonPreference.addPreference(preferenceItem); } } }