/** * Sets status for all accounts. * * @param statusMode * @param statusText can be <code>null</code> if value was not changed. */ public void setStatus(StatusMode statusMode, String statusText) { SettingsManager.setStatusMode(statusMode); if (statusText != null) { addSavedStatus(statusMode, statusText); SettingsManager.setStatusText(statusText); } for (AccountItem accountItem : accountItems.values()) { setStatus( accountItem, statusMode, statusText == null ? accountItem.getStatusText() : statusText); } resendPresence(); onAccountsChanged(new ArrayList<String>(AccountManager.getInstance().getAllAccounts())); }
@Override public void onDestroy() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.unregisterOnSharedPreferenceChangeListener(this); super.onDestroy(); SettingsManager.save(); }
@Override public void onDestroy() { PreferenceGroup prefGroup = getPreferenceScreen(); for (int i = 0; i < prefGroup.getPreferenceCount(); i++) { Preference pref = prefGroup.getPreference(i); if (pref instanceof CheckBoxPreference) { CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref; SettingsManager.setPreferenceBoolean(checkBoxPref.getKey(), checkBoxPref.isChecked()); } } super.onDestroy(); }
/** * Sets status for account. * * @param account * @param statusMode * @param statusText */ public void setStatus(String account, StatusMode statusMode, String statusText) { addSavedStatus(statusMode, statusText); AccountItem accountItem = getAccount(account); setStatus(accountItem, statusMode, statusText); try { PresenceManager.getInstance().resendPresence(account); } catch (NetworkException e) { } boolean found = false; for (AccountItem check : accountItems.values()) if (check.isEnabled() && SettingsManager.statusMode() == check.getRawStatusMode()) { found = true; break; } if (!found) SettingsManager.setStatusMode(statusMode); found = false; for (AccountItem check : accountItems.values()) if (check.isEnabled() && SettingsManager.statusText().equals(check.getStatusText())) { found = true; break; } if (!found) SettingsManager.setStatusText(statusText); onAccountChanged(account); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings_emu_fragment); PreferenceGroup prefGroup = getPreferenceScreen(); for (int i = 0; i < prefGroup.getPreferenceCount(); i++) { Preference pref = prefGroup.getPreference(i); if (pref instanceof CheckBoxPreference) { CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref; checkBoxPref.setChecked(SettingsManager.getPreferenceBoolean(checkBoxPref.getKey())); } } }
/** * Creates new account. * * @param user full or bare jid. * @param password * @param accountType xmpp account type can be replaced depend on server part. * @param syncable * @param storePassword * @param useOrbot * @return assigned account name. * @throws NetworkException if user or server part are invalid. */ public String addAccount( String user, String password, AccountType accountType, boolean syncable, boolean storePassword, boolean useOrbot) throws NetworkException { if (accountType.getProtocol().isOAuth()) { int index = 1; while (true) { user = String.valueOf(index); boolean found = false; for (AccountItem accountItem : accountItems.values()) if (accountItem .getConnectionSettings() .getServerName() .equals(accountType.getFirstServer()) && accountItem.getConnectionSettings().getUserName().equals(user)) { found = true; break; } if (!found) break; index++; } } if (user == null) throw new NetworkException(R.string.EMPTY_USER_NAME); if (user.indexOf("@") == -1) { if ("".equals(accountType.getFirstServer())) throw new NetworkException(R.string.EMPTY_SERVER_NAME); else user += "@" + accountType.getFirstServer(); } String serverName = StringUtils.parseServer(user); String userName = StringUtils.parseName(user); String resource = StringUtils.parseResource(user); String host = accountType.getHost(); int port = accountType.getPort(); boolean tlsRequired = accountType.isTLSRequired(); if (useOrbot) tlsRequired = true; if ("".equals(serverName)) { throw new NetworkException(R.string.EMPTY_SERVER_NAME); } else if (!accountType.isAllowServer() && !serverName.equals(accountType.getFirstServer())) throw new NetworkException(R.string.INCORRECT_USER_NAME); if ("".equals(userName)) throw new NetworkException(R.string.EMPTY_USER_NAME); if ("".equals(resource)) resource = "android" + StringUtils.randomString(8); if (accountType.getId() == R.array.account_type_xmpp) { host = serverName; for (AccountType check : accountTypes) if (check.getServers().contains(serverName)) { accountType = check; host = check.getHost(); port = check.getPort(); tlsRequired = check.isTLSRequired(); break; } } AccountItem accountItem; for (; ; ) { if (getAccount(userName + '@' + serverName + '/' + resource) == null) break; resource = "android" + StringUtils.randomString(8); } accountItem = addAccount( accountType.getProtocol(), true, host, port, serverName, userName, storePassword, password, resource, getNextColorIndex(), 0, StatusMode.available, SettingsManager.statusText(), true, true, tlsRequired ? TLSMode.required : TLSMode.enabled, false, useOrbot ? ProxyType.orbot : ProxyType.none, "localhost", 8080, "", "", syncable, null, null, ArchiveMode.available); onAccountChanged(accountItem.getAccount()); if (accountItems.size() > 1 && SettingsManager.contactsEnableShowAccounts()) SettingsManager.enableContactsShowAccount(); return accountItem.getAccount(); }
/** * @return Selected account to show contacts. <code>null</code> if * <ul> * <li>there is no selected account, * <li>selected account does not exists or disabled, * <li>Group by account is enabled. * </ul> */ public String getSelectedAccount() { if (SettingsManager.contactsShowAccounts()) return null; String selected = SettingsManager.contactsSelectedAccount(); if (enabledAccounts.contains(selected)) return selected; return null; }