use of org.awesomeapp.messenger.provider.Imps in project Zom-Android by zom.
the class AccountSettingsActivity method onSharedPreferenceChanged.
/* save the preferences in Imps so they are accessible everywhere */
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
ContentResolver cr = getContentResolver();
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, mProviderId, true, /* don't keep updated */
null);
String value;
if (key.equals("pref_account_xmpp_resource")) {
value = prefs.getString(key, null);
settings.setXmppResource(value);
if (value != null) {
value = value.trim();
mXmppResource.setSummary(value);
// In case it was trimmed
mXmppResource.setText(value);
}
} else if (key.equals("pref_account_xmpp_resource_prio")) {
value = prefs.getString(key, "20");
try {
settings.setXmppResourcePrio(Integer.parseInt(value));
} catch (NumberFormatException nfe) {
Toast.makeText(getBaseContext(), getString(R.string.error_account_settings_priority), Toast.LENGTH_SHORT).show();
}
mXmppResourcePrio.setSummary(value);
} else if (key.equals("pref_account_port")) {
value = prefs.getString(key, "0");
try {
settings.setPort(Integer.parseInt(value));
} catch (NumberFormatException nfe) {
Toast.makeText(getBaseContext(), getString(R.string.error_account_settings_port), Toast.LENGTH_SHORT).show();
}
if (settings.getPort() != 0)
mPort.setSummary(value);
} else if (key.equals("pref_account_server")) {
value = prefs.getString(key, null);
settings.setServer(value);
if (value != null) {
value = value.trim();
mServer.setSummary(value);
// In case it was trimmed
mServer.setText(value);
}
} else if (key.equals("pref_security_allow_plain_auth")) {
settings.setAllowPlainAuth(prefs.getBoolean(key, false));
} else if (key.equals("pref_security_require_tls")) {
settings.setRequireTls(prefs.getBoolean(key, true));
} else if (key.equals("pref_security_tls_cert_verify")) {
settings.setTlsCertVerify(prefs.getBoolean(key, true));
} else if (key.equals("pref_security_do_dns_srv")) {
settings.setDoDnsSrv(prefs.getBoolean(key, true));
} else if (key.equals("pref_security_use_proxy") || key.equals("pref_security_proxy_host") || key.equals("pref_security_proxy_port")) {
String proxyHost = prefs.getString("pref_security_proxy_host", null);
int proxyPort = -1;
try {
proxyPort = Integer.parseInt(prefs.getString("pref_security_proxy_port", "-1"));
} catch (Exception e) {
}
settings.setUseProxy(prefs.getBoolean("pref_security_use_proxy", false), proxyHost, proxyPort);
mProxyServer.setText(proxyHost);
mProxyServer.setSummary(proxyHost);
if (proxyPort != -1) {
mProxyPort.setText(proxyPort + "");
mProxyPort.setSummary(proxyPort + "");
}
}
settings.setShowMobileIndicator(true);
settings.close();
}
Aggregations