blob: 352652de91286fbcc5c4492a7809060ef9e670ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package eu.siacs.conversations.ui;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import de.tzur.conversations.Settings;
import eu.siacs.conversations.entities.Account;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceManager;
public class SettingsActivity extends XmppActivity implements
OnSharedPreferenceChangeListener {
private SettingsFragment mSettingsFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSettingsFragment = new SettingsFragment();
getFragmentManager().beginTransaction()
.replace(android.R.id.content, mSettingsFragment).commit();
}
@Override
void onBackendConnected() {
}
@Override
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
ListPreference resources = (ListPreference) mSettingsFragment
.findPreference("resource");
if (resources != null) {
ArrayList<CharSequence> entries = new ArrayList<CharSequence>(
Arrays.asList(resources.getEntries()));
entries.add(0, Build.MODEL);
resources.setEntries(entries.toArray(new CharSequence[entries
.size()]));
resources.setEntryValues(entries.toArray(new CharSequence[entries
.size()]));
}
}
@Override
public void onStop() {
super.onStop();
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences,
String name) {
switch (name) {
case "resource":
String resource = preferences.getString("resource", "mobile")
.toLowerCase(Locale.US);
if (xmppConnectionServiceBound) {
for (Account account : xmppConnectionService.getAccounts()) {
account.setResource(resource);
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
xmppConnectionService.reconnectAccount(account, false);
}
}
}
break;
case "keep_foreground_service":
xmppConnectionService.toggleForegroundService();
break;
}
Settings.synchronizeSettingsClassWithPreferences(getPreferences(), name);
}
}
|