author | nikita@mapiproxy |
Tue, 25 Aug 2009 02:08:51 +0200 | |
changeset 352 | 0b709101a42f |
parent 349 | 84d45a88699f |
child 392 | 73f7707528f0 |
permissions | -rw-r--r-- |
212 | 1 |
package com.beem.project.beem.ui; |
2 |
||
3 |
import java.util.ArrayList; |
|
234
b539dc53b9c7
Reoganisation login + contact list sans utiliser beemapplication.
marseille@marseille-desktop
parents:
232
diff
changeset
|
4 |
|
212 | 5 |
import android.app.Activity; |
6 |
import android.content.Intent; |
|
7 |
import android.content.SharedPreferences; |
|
8 |
import android.os.Bundle; |
|
9 |
import android.util.Log; |
|
10 |
import android.view.Menu; |
|
11 |
import android.view.MenuInflater; |
|
12 |
import android.view.MenuItem; |
|
13 |
import android.view.View; |
|
14 |
import android.view.View.OnClickListener; |
|
15 |
import android.widget.ArrayAdapter; |
|
16 |
import android.widget.Button; |
|
17 |
import android.widget.CheckBox; |
|
18 |
import android.widget.EditText; |
|
19 |
import android.widget.Spinner; |
|
20 |
import android.widget.TabHost; |
|
21 |
import android.widget.Toast; |
|
22 |
||
23 |
import com.beem.project.beem.R; |
|
24 |
||
25 |
/** |
|
349 | 26 |
* This class represents an activity which allows the user to change his account or proxy parameters. |
212 | 27 |
* @author dasilvj |
28 |
*/ |
|
29 |
public class EditSettings extends Activity { |
|
30 |
||
348 | 31 |
private static final String LOG_MSG_SETTINGS_SAVED = "Settings saved successfully."; |
32 |
private static final String LOG_MSG_XMPP_SETTINGS_REGISTERED = "XMPP Settings has been registered."; |
|
33 |
private static final String LOG_MSG_ACCOUNT_SETTINGS_REGISTERED = "Account Settings has been registered."; |
|
34 |
private static final String LOG_MSG_PROXY_SETTINGS_REGISTERED = "Proxy Settings has been registered."; |
|
212 | 35 |
|
348 | 36 |
private static final boolean DEFAULT_BOOLEAN_VALUE = false; |
37 |
private static final String DEFAULT_STRING_VALUE = ""; |
|
38 |
private static final int DEFAULT_INT_VALUE = 0; |
|
212 | 39 |
|
348 | 40 |
private static final String DEFAULT_XMPP_PORT = "5222"; |
212 | 41 |
|
348 | 42 |
private static final int NOTIFICATION_DURATION = Toast.LENGTH_SHORT; |
212 | 43 |
|
348 | 44 |
private SharedPreferences mSettings; |
212 | 45 |
|
348 | 46 |
private EditText mAccUsernameField; |
47 |
private EditText mAccPasswordField; |
|
212 | 48 |
|
348 | 49 |
private EditText mXmppServerField; |
50 |
private EditText mXmppPortField; |
|
51 |
private CheckBox mXmppUseTlsCheckBox; |
|
212 | 52 |
|
348 | 53 |
private CheckBox mProxyUseCheckBox; |
54 |
private Spinner mProxyTypeSpinner; |
|
55 |
private EditText mProxyServerField; |
|
56 |
private EditText mProxyPortField; |
|
57 |
private EditText mProxyUsernameField; |
|
58 |
private EditText mProxyPasswordField; |
|
212 | 59 |
|
60 |
/** |
|
349 | 61 |
* Constructor. |
62 |
*/ |
|
63 |
public EditSettings() { } |
|
64 |
||
65 |
/** |
|
348 | 66 |
* Add a labeled "Account" tab on the tabbed window view passed by parameter. |
259 | 67 |
* @param tHost a tabbed window view |
212 | 68 |
*/ |
69 |
private void addAccountTab(TabHost tHost) { |
|
70 |
TabHost.TabSpec accountTab = tHost.newTabSpec(getString(R.string.settings_tab_tag_account)); |
|
71 |
accountTab.setIndicator(getString(R.string.settings_tab_label_account)); |
|
72 |
accountTab.setContent(R.id.settings_account); |
|
73 |
tHost.addTab(accountTab); |
|
74 |
} |
|
75 |
||
76 |
/** |
|
348 | 77 |
* Add a labeled "Proxy" tab on the tabbed window view passed by parameter. |
259 | 78 |
* @param tHost a tabbed window view |
212 | 79 |
*/ |
80 |
private void addProxyTab(TabHost tHost) { |
|
81 |
TabHost.TabSpec proxyTab = tHost.newTabSpec(getString(R.string.settings_tab_tag_proxy)); |
|
82 |
proxyTab.setIndicator(getString(R.string.settings_tab_label_proxy)); |
|
83 |
proxyTab.setContent(R.id.settings_proxy); |
|
84 |
tHost.addTab(proxyTab); |
|
85 |
} |
|
86 |
||
87 |
/** |
|
348 | 88 |
* Add a labeled "XMPP" tab on the tabbed window view passed by parameter. |
259 | 89 |
* @param tHost a tabbed window view |
212 | 90 |
*/ |
91 |
private void addXMPPTab(TabHost tHost) { |
|
92 |
TabHost.TabSpec personalTab = tHost.newTabSpec(getString(R.string.settings_tab_tag_xmpp)); |
|
93 |
personalTab.setIndicator(getString(R.string.settings_tab_label_xmpp)); |
|
94 |
personalTab.setContent(R.id.settings_xmpp); |
|
95 |
tHost.addTab(personalTab); |
|
96 |
} |
|
97 |
||
98 |
/** |
|
348 | 99 |
* Disable proxy parameters fields. |
212 | 100 |
*/ |
101 |
private void disableProxyParameters() { |
|
340 | 102 |
mProxyTypeSpinner.setEnabled(false); |
103 |
mProxyServerField.setEnabled(false); |
|
104 |
mProxyPortField.setEnabled(false); |
|
105 |
mProxyUsernameField.setEnabled(false); |
|
106 |
mProxyPasswordField.setEnabled(false); |
|
107 |
mProxyTypeSpinner.setFocusable(false); |
|
108 |
mProxyServerField.setFocusable(false); |
|
109 |
mProxyPortField.setFocusable(false); |
|
110 |
mProxyUsernameField.setFocusable(false); |
|
111 |
mProxyPasswordField.setFocusable(false); |
|
112 |
mProxyTypeSpinner.setFocusableInTouchMode(false); |
|
113 |
mProxyServerField.setFocusableInTouchMode(false); |
|
114 |
mProxyPortField.setFocusableInTouchMode(false); |
|
115 |
mProxyUsernameField.setFocusableInTouchMode(false); |
|
116 |
mProxyPasswordField.setFocusableInTouchMode(false); |
|
212 | 117 |
} |
118 |
||
348 | 119 |
/** |
120 |
* Display a brief notification. |
|
349 | 121 |
* @param msg the message to display. |
348 | 122 |
*/ |
212 | 123 |
private void displayNotification(CharSequence msg) { |
124 |
Toast toast = Toast.makeText(getApplicationContext(), msg, NOTIFICATION_DURATION); |
|
125 |
toast.show(); |
|
126 |
} |
|
127 |
||
128 |
/** |
|
348 | 129 |
* Enable proxy parameters fields. |
212 | 130 |
*/ |
131 |
private void enableProxyParameters() { |
|
340 | 132 |
mProxyTypeSpinner.setEnabled(true); |
133 |
mProxyServerField.setEnabled(true); |
|
134 |
mProxyPortField.setEnabled(true); |
|
135 |
mProxyUsernameField.setEnabled(true); |
|
136 |
mProxyPasswordField.setEnabled(true); |
|
137 |
mProxyTypeSpinner.setFocusable(true); |
|
138 |
mProxyServerField.setFocusable(true); |
|
139 |
mProxyPortField.setFocusable(true); |
|
140 |
mProxyUsernameField.setFocusable(true); |
|
141 |
mProxyPasswordField.setFocusable(true); |
|
142 |
mProxyTypeSpinner.setFocusableInTouchMode(true); |
|
143 |
mProxyServerField.setFocusableInTouchMode(true); |
|
144 |
mProxyPortField.setFocusableInTouchMode(true); |
|
145 |
mProxyUsernameField.setFocusableInTouchMode(true); |
|
146 |
mProxyPasswordField.setFocusableInTouchMode(true); |
|
212 | 147 |
} |
148 |
||
149 |
/** |
|
348 | 150 |
* Retrieve the value of a CheckBox. |
151 |
* @param viewId identifier of the checkbox |
|
212 | 152 |
* @return true if the CheckBox is checked, else false |
153 |
*/ |
|
154 |
private boolean getCheckBoxValue(int viewId) { |
|
155 |
final CheckBox checkBox = (CheckBox) findViewById(viewId); |
|
156 |
if (checkBox.isChecked()) |
|
348 | 157 |
return true; |
158 |
return false; |
|
212 | 159 |
} |
160 |
||
161 |
/** |
|
348 | 162 |
* Retrieve account password from the preferences. |
212 | 163 |
* @return Registered account password |
164 |
*/ |
|
165 |
private String getRegisteredAccountPassword() { |
|
348 | 166 |
return mSettings.getString(getString(R.string.settings_key_account_password), DEFAULT_STRING_VALUE); |
212 | 167 |
} |
168 |
||
169 |
/** |
|
348 | 170 |
* Retrieve account username from the preferences. |
212 | 171 |
* @return Registered account username |
172 |
*/ |
|
173 |
private String getRegisteredAccountUsername() { |
|
348 | 174 |
return mSettings.getString(getString(R.string.settings_key_account_username), DEFAULT_STRING_VALUE); |
212 | 175 |
} |
176 |
||
177 |
/** |
|
348 | 178 |
* Retrieve proxy password from the preferences. |
212 | 179 |
* @return Registered proxy password |
180 |
*/ |
|
181 |
private String getRegisteredProxyPassword() { |
|
348 | 182 |
return mSettings.getString(getString(R.string.settings_key_proxy_password), DEFAULT_STRING_VALUE); |
212 | 183 |
} |
184 |
||
185 |
/** |
|
348 | 186 |
* Retrieve proxy port from the preferences. |
212 | 187 |
* @return Registered proxy port |
188 |
*/ |
|
189 |
private String getRegisteredProxyPort() { |
|
348 | 190 |
return mSettings.getString(getString(R.string.settings_key_proxy_port), DEFAULT_STRING_VALUE); |
212 | 191 |
} |
192 |
||
193 |
/** |
|
348 | 194 |
* Retrieve proxy server from the preferences. |
212 | 195 |
* @return Registered proxy server |
196 |
*/ |
|
197 |
private String getRegisteredProxyServer() { |
|
348 | 198 |
return mSettings.getString(getString(R.string.settings_key_proxy_server), DEFAULT_STRING_VALUE); |
212 | 199 |
} |
200 |
||
201 |
/** |
|
348 | 202 |
* Retrieve proxy type from the preferences. |
212 | 203 |
* @return Registered proxy type |
204 |
*/ |
|
205 |
private int getRegisteredProxyType() { |
|
348 | 206 |
return mSettings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE); |
212 | 207 |
} |
208 |
||
209 |
/** |
|
348 | 210 |
* Retrieve proxy use from the preferences. |
212 | 211 |
* @return Registered proxy use |
212 |
*/ |
|
213 |
private boolean getRegisteredProxyUse() { |
|
348 | 214 |
return mSettings.getBoolean(getString(R.string.settings_key_proxy_use), DEFAULT_BOOLEAN_VALUE); |
212 | 215 |
} |
216 |
||
217 |
/** |
|
348 | 218 |
* Retrieve proxy username from the preferences. |
212 | 219 |
* @return Registered proxy username |
220 |
*/ |
|
221 |
private String getRegisteredProxyUsername() { |
|
348 | 222 |
return mSettings.getString(getString(R.string.settings_key_proxy_username), DEFAULT_STRING_VALUE); |
212 | 223 |
} |
224 |
||
225 |
/** |
|
348 | 226 |
* Retrieve xmpp port from the preferences. |
212 | 227 |
* @return Registered xmpp port |
228 |
*/ |
|
229 |
private String getRegisteredXMPPPort() { |
|
348 | 230 |
return mSettings.getString(getString(R.string.settings_key_xmpp_port), DEFAULT_XMPP_PORT); |
212 | 231 |
} |
232 |
||
233 |
/** |
|
348 | 234 |
* Retrieve xmpp server from the preferences. |
212 | 235 |
* @return Registered xmpp server |
236 |
*/ |
|
237 |
private String getRegisteredXMPPServer() { |
|
348 | 238 |
return mSettings.getString(getString(R.string.settings_key_xmpp_server), DEFAULT_STRING_VALUE); |
212 | 239 |
} |
240 |
||
241 |
/** |
|
348 | 242 |
* Retrieve TLS use from the preferences. |
212 | 243 |
* @return Registered TLS use |
244 |
*/ |
|
245 |
private boolean getRegisteredXMPPTLSUse() { |
|
348 | 246 |
return mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), DEFAULT_BOOLEAN_VALUE); |
212 | 247 |
} |
248 |
||
249 |
/** |
|
348 | 250 |
* Initialize Account tab fields. |
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
251 |
*/ |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
252 |
private void initAccountFields() { |
340 | 253 |
mAccUsernameField = (EditText) findViewById(R.id.settings_account_username); |
254 |
mAccPasswordField = (EditText) findViewById(R.id.settings_account_password); |
|
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
255 |
} |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
256 |
|
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
257 |
/** |
348 | 258 |
* Initialize all of the components displayed in tabs (EditText fields, CheckBoxes, Spinners...). |
212 | 259 |
*/ |
260 |
private void initFields() { |
|
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
261 |
initAccountFields(); |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
262 |
initXMPPFields(); |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
263 |
initProxyFields(); |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
264 |
} |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
265 |
|
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
266 |
/** |
348 | 267 |
* Initialize Proxy tab fields. |
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
268 |
*/ |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
269 |
private void initProxyFields() { |
340 | 270 |
mProxyUseCheckBox = (CheckBox) findViewById(R.id.settings_proxy_use); |
271 |
mProxyTypeSpinner = (Spinner) findViewById(R.id.settings_proxy_type); |
|
272 |
mProxyServerField = (EditText) findViewById(R.id.settings_proxy_server); |
|
273 |
mProxyPortField = (EditText) findViewById(R.id.settings_proxy_port); |
|
274 |
mProxyUsernameField = (EditText) findViewById(R.id.settings_proxy_username); |
|
275 |
mProxyPasswordField = (EditText) findViewById(R.id.settings_proxy_password); |
|
212 | 276 |
} |
277 |
||
278 |
/** |
|
348 | 279 |
* Initialize proxy's types spinner of the proxy tab. |
212 | 280 |
*/ |
281 |
private void initProxyTypesSpinner() { |
|
282 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.proxy_types, |
|
259 | 283 |
android.R.layout.simple_spinner_item); |
212 | 284 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
340 | 285 |
mProxyTypeSpinner.setAdapter(adapter); |
212 | 286 |
} |
287 |
||
288 |
/** |
|
348 | 289 |
* Initialize the checkbox allowing user to use a proxy. |
212 | 290 |
*/ |
291 |
private void initProxyUseCheckBox() { |
|
340 | 292 |
mProxyUseCheckBox.setOnClickListener(new OnClickListener() { |
212 | 293 |
|
294 |
public void onClick(View v) { |
|
340 | 295 |
if (mProxyUseCheckBox.isChecked()) { |
212 | 296 |
enableProxyParameters(); |
297 |
} else { |
|
298 |
disableProxyParameters(); |
|
299 |
} |
|
300 |
} |
|
301 |
}); |
|
302 |
} |
|
303 |
||
304 |
/** |
|
348 | 305 |
* Initialize "save" buttons allowing user to save settings. |
212 | 306 |
*/ |
307 |
private void initSaveButtons() { |
|
308 |
final ArrayList<Integer> views = new ArrayList<Integer>(); |
|
309 |
Button saveButton = null; |
|
310 |
||
311 |
views.add(R.id.settings_account_button_save); |
|
312 |
views.add(R.id.settings_proxy_button_save); |
|
313 |
views.add(R.id.settings_xmpp_button_save); |
|
314 |
||
315 |
for (int i = 0; i < views.size(); i++) { |
|
316 |
saveButton = (Button) findViewById(views.get(i)); |
|
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
317 |
saveButton.setFocusable(true); |
212 | 318 |
saveButton.setOnClickListener(new View.OnClickListener() { |
319 |
||
320 |
public void onClick(View v) { |
|
321 |
saveSettings(); |
|
263
ff0b4790a5ed
La gestion de la connection et des changement de settings a ete revu.
marseille@marseille-desktop
parents:
260
diff
changeset
|
322 |
setResult(69); |
212 | 323 |
} |
324 |
}); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
/** |
|
348 | 329 |
* Initialize tabbed window view by adding tabs and setting the default tab. |
212 | 330 |
*/ |
331 |
private void initTabbedWindow() { |
|
332 |
TabHost tHost = (TabHost) this.findViewById(R.id.settings_tab_host); |
|
333 |
tHost.setup(); |
|
334 |
addAccountTab(tHost); |
|
335 |
addXMPPTab(tHost); |
|
336 |
addProxyTab(tHost); |
|
337 |
tHost.setCurrentTab(0); |
|
338 |
} |
|
339 |
||
340 |
/** |
|
348 | 341 |
* Initialize XMPP tab fields. |
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
342 |
*/ |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
343 |
private void initXMPPFields() { |
340 | 344 |
mXmppServerField = (EditText) findViewById(R.id.settings_xmpp_server); |
345 |
mXmppPortField = (EditText) findViewById(R.id.settings_xmpp_port); |
|
346 |
mXmppUseTlsCheckBox = (CheckBox) findViewById(R.id.settings_xmpp_use_tls); |
|
230
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
347 |
} |
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
348 |
|
21d91ef67e97
Bug #166 - Passage des différents EditText de l'activité Settings en SingleLine. Correction d'un bug poussant le champs Port en dehors de la zone de vue dans les tabs Proxy et XMPP.
dasilvj@jean-manuel-da-silvas-macbook.local
parents:
227
diff
changeset
|
349 |
/** |
212 | 350 |
* {@inheritDoc} |
351 |
*/ |
|
352 |
@Override |
|
353 |
public void onCreate(Bundle savedInstanceState) { |
|
354 |
super.onCreate(savedInstanceState); |
|
355 |
setContentView(R.layout.edit_settings); |
|
356 |
initTabbedWindow(); |
|
357 |
initFields(); |
|
340 | 358 |
mSettings = getSharedPreferences(getString(R.string.settings_filename), MODE_PRIVATE); |
212 | 359 |
} |
360 |
||
361 |
/** |
|
362 |
* {@inheritDoc} |
|
363 |
*/ |
|
364 |
@Override |
|
365 |
public boolean onCreateOptionsMenu(Menu menu) { |
|
366 |
MenuInflater mInflater = getMenuInflater(); |
|
367 |
mInflater.inflate(R.menu.edit_settings, menu); |
|
368 |
return true; |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
* {@inheritDoc} |
|
373 |
*/ |
|
374 |
@Override |
|
375 |
public boolean onOptionsItemSelected(MenuItem item) { |
|
376 |
Intent i = null; |
|
377 |
switch (item.getItemId()) { |
|
348 | 378 |
case R.id.settings_menu_create_account: |
379 |
i = new Intent(this, CreateAccount.class); |
|
380 |
startActivity(i); |
|
381 |
return true; |
|
382 |
case R.id.settings_menu_login: |
|
383 |
finish(); |
|
384 |
return true; |
|
385 |
default: |
|
386 |
return false; |
|
256 | 387 |
} |
212 | 388 |
} |
389 |
||
390 |
/** |
|
391 |
* {@inheritDoc} |
|
392 |
*/ |
|
393 |
@Override |
|
394 |
public void onResume() { |
|
395 |
super.onResume(); |
|
396 |
refreshAccountTabFields(); |
|
397 |
refreshXMPPTabFields(); |
|
398 |
refreshProxyTabFields(); |
|
399 |
||
340 | 400 |
if (!mProxyUseCheckBox.isChecked()) |
212 | 401 |
disableProxyParameters(); |
402 |
} |
|
403 |
||
404 |
/** |
|
405 |
* {@inheritDoc} |
|
406 |
*/ |
|
407 |
@Override |
|
408 |
public void onStart() { |
|
409 |
super.onStart(); |
|
410 |
initProxyTypesSpinner(); |
|
411 |
initProxyUseCheckBox(); |
|
412 |
initSaveButtons(); |
|
413 |
} |
|
414 |
||
415 |
/** |
|
348 | 416 |
* Refresh values of "Account" tab fields. |
212 | 417 |
*/ |
418 |
private void refreshAccountTabFields() { |
|
340 | 419 |
mAccUsernameField.setText(getRegisteredAccountUsername()); |
420 |
mAccPasswordField.setText(getRegisteredAccountPassword()); |
|
212 | 421 |
} |
422 |
||
423 |
/** |
|
348 | 424 |
* Refresh values of "Account" tab fields. |
212 | 425 |
*/ |
426 |
private void refreshProxyTabFields() { |
|
340 | 427 |
mProxyUseCheckBox.setChecked(getRegisteredProxyUse()); |
428 |
mProxyTypeSpinner.setSelection(getRegisteredProxyType()); |
|
429 |
mProxyServerField.setText(getRegisteredProxyServer()); |
|
430 |
mProxyPortField.setText(getRegisteredProxyPort()); |
|
431 |
mProxyUsernameField.setText(getRegisteredProxyUsername()); |
|
432 |
mProxyPasswordField.setText(getRegisteredProxyPassword()); |
|
212 | 433 |
} |
434 |
||
435 |
/** |
|
348 | 436 |
* Refresh values of "Account" tab fields. |
212 | 437 |
*/ |
438 |
private void refreshXMPPTabFields() { |
|
340 | 439 |
mXmppServerField.setText(getRegisteredXMPPServer()); |
440 |
mXmppPortField.setText(getRegisteredXMPPPort()); |
|
441 |
mXmppUseTlsCheckBox.setChecked(getRegisteredXMPPTLSUse()); |
|
212 | 442 |
} |
443 |
||
444 |
/** |
|
348 | 445 |
* Register account settings changes in SharedPreferences.Editor object passed by parameter. |
446 |
* @param settingsEditor the editor to use. |
|
212 | 447 |
*/ |
448 |
private void registerAccountSettingsChanges(SharedPreferences.Editor settingsEditor) { |
|
340 | 449 |
final String usernameFieldValue = mAccUsernameField.getText().toString(); |
450 |
final String passwordFieldValue = mAccPasswordField.getText().toString(); |
|
212 | 451 |
|
348 | 452 |
if (!getRegisteredAccountUsername().equals(usernameFieldValue)) |
212 | 453 |
settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue); |
348 | 454 |
if (!getRegisteredAccountPassword().equals(passwordFieldValue)) |
212 | 455 |
settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue); |
456 |
Log.i(getString(R.string.edit_settings_tag), LOG_MSG_ACCOUNT_SETTINGS_REGISTERED); |
|
457 |
} |
|
458 |
||
459 |
/** |
|
348 | 460 |
* Register proxy settings changes in SharedPreferences.Editor object passed by parameter. |
461 |
* @param settingsEditor the editor to use. |
|
212 | 462 |
*/ |
463 |
private void registerProxySettingsChanges(SharedPreferences.Editor settingsEditor) { |
|
340 | 464 |
final int proxyTypeFieldValue = mProxyTypeSpinner.getSelectedItemPosition(); |
465 |
final String serverFieldValue = mProxyServerField.getText().toString(); |
|
466 |
final String portFieldValue = mProxyPortField.getText().toString(); |
|
467 |
final String usernameFieldValue = mProxyUsernameField.getText().toString(); |
|
468 |
final String passwordFieldValue = mProxyPasswordField.getText().toString(); |
|
212 | 469 |
|
470 |
if (getRegisteredProxyType() != proxyTypeFieldValue) |
|
471 |
settingsEditor.putInt(getString(R.string.settings_key_proxy_type), proxyTypeFieldValue); |
|
348 | 472 |
if (!getRegisteredProxyServer().equals(serverFieldValue)) |
212 | 473 |
settingsEditor.putString(getString(R.string.settings_key_proxy_server), serverFieldValue); |
348 | 474 |
if (!getRegisteredProxyPort().equals(portFieldValue)) |
212 | 475 |
settingsEditor.putString(getString(R.string.settings_key_proxy_port), portFieldValue); |
348 | 476 |
if (!getRegisteredProxyUsername().equals(usernameFieldValue)) |
212 | 477 |
settingsEditor.putString(getString(R.string.settings_key_proxy_username), usernameFieldValue); |
348 | 478 |
if (!getRegisteredProxyPassword().equals(passwordFieldValue)) |
212 | 479 |
settingsEditor.putString(getString(R.string.settings_key_proxy_password), passwordFieldValue); |
480 |
Log.i(getString(R.string.edit_settings_tag), LOG_MSG_PROXY_SETTINGS_REGISTERED); |
|
481 |
} |
|
482 |
||
483 |
/** |
|
348 | 484 |
* Register XMPP settings changes in SharedPreferences.Editor object passed by parameter. |
485 |
* @param settingsEditor the editor to use. |
|
212 | 486 |
*/ |
487 |
private void registerXMPPSettingsChanges(SharedPreferences.Editor settingsEditor) { |
|
488 |
final boolean tlsUseCheckBoxValue = getCheckBoxValue(R.id.settings_xmpp_use_tls); |
|
340 | 489 |
final String serverFieldValue = mXmppServerField.getText().toString(); |
490 |
final String portFieldValue = mXmppPortField.getText().toString(); |
|
212 | 491 |
|
492 |
if (getRegisteredXMPPTLSUse() != tlsUseCheckBoxValue) |
|
493 |
settingsEditor.putBoolean(getString(R.string.settings_key_xmpp_tls_use), tlsUseCheckBoxValue); |
|
348 | 494 |
if (!getRegisteredXMPPServer().equals(serverFieldValue)) |
212 | 495 |
settingsEditor.putString(getString(R.string.settings_key_xmpp_server), serverFieldValue); |
348 | 496 |
if (!getRegisteredXMPPPort().equals(portFieldValue)) |
212 | 497 |
settingsEditor.putString(getString(R.string.settings_key_xmpp_port), portFieldValue); |
498 |
Log.i(getString(R.string.edit_settings_tag), LOG_MSG_XMPP_SETTINGS_REGISTERED); |
|
499 |
} |
|
500 |
||
501 |
/** |
|
348 | 502 |
* Save settings in shared preferences. |
212 | 503 |
*/ |
504 |
private void saveSettings() { |
|
352 | 505 |
final SharedPreferences.Editor settingsEditor = mSettings.edit(); |
212 | 506 |
final boolean proxyUseCheckBoxValue = getCheckBoxValue(R.id.settings_proxy_use); |
507 |
||
508 |
if (getRegisteredProxyUse() != proxyUseCheckBoxValue) |
|
509 |
settingsEditor.putBoolean(getString(R.string.settings_key_proxy_use), proxyUseCheckBoxValue); |
|
510 |
if (proxyUseCheckBoxValue) |
|
511 |
registerProxySettingsChanges(settingsEditor); |
|
512 |
registerAccountSettingsChanges(settingsEditor); |
|
513 |
registerXMPPSettingsChanges(settingsEditor); |
|
340 | 514 |
String password = mAccPasswordField.getText().toString(); |
515 |
String username = mAccUsernameField.getText().toString(); |
|
516 |
String port = mXmppPortField.getText().toString(); |
|
348 | 517 |
if ("".equals(password) || "".equals(username) |
326 | 518 |
|| "".equals(port)) |
324
5601d949c5aa
Ajout d'une verification que le compte est configure avant de lancer la
nikita@localhost
parents:
322
diff
changeset
|
519 |
settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), false); |
5601d949c5aa
Ajout d'une verification que le compte est configure avant de lancer la
nikita@localhost
parents:
322
diff
changeset
|
520 |
else |
5601d949c5aa
Ajout d'une verification que le compte est configure avant de lancer la
nikita@localhost
parents:
322
diff
changeset
|
521 |
settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true); |
212 | 522 |
|
523 |
if (settingsEditor.commit()) { |
|
524 |
displayNotification(getText(R.string.settings_saved_ok)); |
|
525 |
Log.i(getString(R.string.edit_settings_tag), LOG_MSG_SETTINGS_SAVED); |
|
526 |
} |
|
527 |
} |
|
528 |
} |