Revision 378fe36a src/com/rackspace/cloud/android/ListAccountsActivity.java

b/src/com/rackspace/cloud/android/ListAccountsActivity.java
8 8
import java.io.ObjectOutputStream;
9 9
import java.io.StreamCorruptedException;
10 10
import java.util.ArrayList;
11
import java.util.TreeMap;
12 11

  
13 12
import android.app.AlertDialog;
14
import android.app.ProgressDialog;
13
import android.app.Dialog;
15 14
import android.content.Context;
16 15
import android.content.DialogInterface;
17 16
import android.content.DialogInterface.OnCancelListener;
......
27 26
import android.view.MenuItem;
28 27
import android.view.View;
29 28
import android.view.ViewGroup;
30
import android.view.ViewGroup.LayoutParams;
31
import android.view.WindowManager;
32 29
import android.widget.AdapterView.AdapterContextMenuInfo;
33 30
import android.widget.ArrayAdapter;
34 31
import android.widget.ImageView;
35 32
import android.widget.ListView;
36
import android.widget.ProgressBar;
37 33
import android.widget.TextView;
38 34

  
39
import com.rackspace.cloud.android.R;
40 35
import com.rackspace.cloud.servers.api.client.Account;
41 36
import com.rackspace.cloud.servers.api.client.CloudServersException;
42 37
import com.rackspace.cloud.servers.api.client.http.Authentication;
43 38

  
44 39
//
45
public class ListAccountsActivity extends CloudListActivity{
40
public class ListAccountsActivity extends CloudListActivity {
46 41

  
47 42
	private final String FILENAME = "accounts.data";
48 43
	private static final String PAGE_ROOT = "/Root";
49
	
44

  
50 45
	private boolean authenticating;
51 46
	private ArrayList<Account> accounts;
52 47
	private Intent tabViewIntent;
53
	private ProgressDialog dialog;
48
	private Dialog dialog;
54 49
	private Context context;
55
	//used to track the current asynctask
50
	// used to track the current asynctask
56 51
	@SuppressWarnings("rawtypes")
57 52
	private AsyncTask task;
58 53

  
......
71 66
		outState.putBoolean("authenticating", authenticating);
72 67
		outState.putSerializable("accounts", accounts);
73 68

  
74
		//need to set authenticating back to true because it is set to false
75
		//in hideAccountDialog()
76
		if(authenticating){
69
		// need to set authenticating back to true because it is set to false
70
		// in hideAccountDialog()
71
		if (authenticating) {
77 72
			hideAccountDialog();
78 73
			authenticating = true;
79 74
		}
......
85 80
	protected void onRestoreInstanceState(Bundle state) {
86 81

  
87 82
		/*
88
		 * need reference to the app so you can access
89
		 * isLoggingIn
83
		 * need reference to the app so you can access isLoggingIn
90 84
		 */
91 85

  
92

  
93
		if (state != null && state.containsKey("authenticating") && state.getBoolean("authenticating")) {
86
		if (state != null && state.containsKey("authenticating")
87
				&& state.getBoolean("authenticating")) {
94 88
			showAccountDialog();
95 89
		} else {
96 90
			hideAccountDialog();
97 91
		}
98 92
		if (state != null && state.containsKey("accounts")) {
99
			accounts = (ArrayList<Account>)state.getSerializable("accounts");
93
			accounts = (ArrayList<Account>) state.getSerializable("accounts");
100 94
			if (accounts.size() == 0) {
101 95
				displayNoAccountsCell();
102 96
			} else {
103
				getListView().setDividerHeight(1); // restore divider lines 
97
				getListView().setDividerHeight(1); // restore divider lines
104 98
				setListAdapter(new AccountAdapter());
105 99
			}
106 100
		} else {
107
			loadAccounts();        
108
		} 	
101
			loadAccounts();
102
		}
109 103
	}
110 104

  
111 105
	@Override
112
	protected void onStart(){
106
	protected void onStart() {
113 107
		super.onStart();
114
		if(authenticating){
108
		if (authenticating) {
115 109
			showAccountDialog();
116 110
		}
117 111
	}
118 112

  
119 113
	@Override
120
	protected void onStop(){
114
	protected void onStop() {
121 115
		super.onStop();
122
		if(authenticating){
116
		if (authenticating) {
123 117
			hideAccountDialog();
124 118
			authenticating = true;
125 119
		}
126 120
	}
127 121

  
128 122
	private void loadAccounts() {
129
		//check and see if there are any in memory
130
		if(accounts == null){
123
		// check and see if there are any in memory
124
		if (accounts == null) {
131 125
			accounts = readAccounts();
132 126
		}
133
		//if nothing was written before accounts will still be null
134
		if(accounts == null){
127
		// if nothing was written before accounts will still be null
128
		if (accounts == null) {
135 129
			accounts = new ArrayList<Account>();
136 130
		}
137 131

  
......
142 136
		if (accounts.size() == 0) {
143 137
			displayNoAccountsCell();
144 138
		} else {
145
			getListView().setDividerHeight(1); // restore divider lines 
139
			getListView().setDividerHeight(1); // restore divider lines
146 140
			this.setListAdapter(new AccountAdapter());
147 141
		}
148 142
	}
149 143

  
150
	private void writeAccounts(){
144
	private void writeAccounts() {
151 145
		FileOutputStream fos;
152 146
		ObjectOutputStream out = null;
153
		try{
147
		try {
154 148
			fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
155 149
			out = new ObjectOutputStream(fos);
156 150
			out.writeObject(accounts);
......
165 159
		}
166 160
	}
167 161

  
168
	private ArrayList<Account> readAccounts(){
162
	private ArrayList<Account> readAccounts() {
169 163
		FileInputStream fis;
170 164
		ObjectInputStream in;
171 165
		try {
172 166
			fis = openFileInput(FILENAME);
173 167
			in = new ObjectInputStream(fis);
174 168
			@SuppressWarnings("unchecked")
175
			ArrayList<Account> file = (ArrayList<Account>)in.readObject();
169
			ArrayList<Account> file = (ArrayList<Account>) in.readObject();
176 170
			in.close();
177
			return file; 
171
			return file;
178 172
		} catch (FileNotFoundException e) {
179
			//showAlert("Error", "Could not load accounts.");
173
			// showAlert("Error", "Could not load accounts.");
180 174
			e.printStackTrace();
181 175
			return null;
182 176
		} catch (StreamCorruptedException e) {
......
196 190
	private void displayNoAccountsCell() {
197 191
		String a[] = new String[1];
198 192
		a[0] = "No Accounts";
199
		setListAdapter(new ArrayAdapter<String>(getApplicationContext(), R.layout.noaccountscell, R.id.no_accounts_label, a));
193
		setListAdapter(new ArrayAdapter<String>(getApplicationContext(),
194
				R.layout.noaccountscell, R.id.no_accounts_label, a));
200 195
		getListView().setTextFilterEnabled(true);
201
		getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row
196
		getListView().setDividerHeight(0); // hide the dividers so it won't look
197
											// like a list row
202 198
		getListView().setItemsCanFocus(false);
203 199
	}
204 200

  
205 201
	protected void onListItemClick(ListView l, View v, int position, long id) {
206 202
		if (accounts != null && accounts.size() > 0) {
207
			//setActivityIndicatorsVisibility(View.VISIBLE, v);
203
			// setActivityIndicatorsVisibility(View.VISIBLE, v);
208 204
			Account.setAccount(accounts.get(position));
209
			Log.d("info", "the server is " + Account.getAccount().getAuthServerV2());
205
			Log.d("info", "the server is "
206
					+ Account.getAccount().getAuthServerV2());
210 207
			login();
211
		}		
208
		}
212 209
	}
213 210

  
214 211
	public void login() {
215
		//showActivityIndicators();
216
		//setLoginPreferences();
212
		// showActivityIndicators();
213
		// setLoginPreferences();
217 214
		new AuthenticateTask().execute((Void[]) null);
218 215
	}
219 216

  
220
	//setup menu for when menu button is pressed
217
	// setup menu for when menu button is pressed
221 218
	public boolean onCreateOptionsMenu(Menu menu) {
222 219
		super.onCreateOptionsMenu(menu);
223 220
		MenuInflater inflater = getMenuInflater();
224 221
		inflater.inflate(R.menu.accounts_list_menu, menu);
225 222
		return true;
226
	} 
223
	}
227 224

  
228
	@Override 
229
	//in options menu, when add account is selected go to add account activity
225
	@Override
226
	// in options menu, when add account is selected go to add account activity
230 227
	public boolean onOptionsItemSelected(MenuItem item) {
231 228
		switch (item.getItemId()) {
232 229
		case R.id.add_account:
233 230
			Intent intent = new Intent(this, AddAccountActivity.class);
234
			startActivityForResult(intent, 78); // arbitrary number; never used again
231
			startActivityForResult(intent, 78); // arbitrary number; never used
232
												// again
235 233
			return true;
236
		case R.id.login_pithos:
237
			
238
				final CharSequence[] items = {"Pithos+ Dev", "Pithos + Staging", "Pithos +"};
239

  
240
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
241
				builder.setTitle("Select Pithos Environment");
242
				builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
243
				    public void onClick(DialogInterface dialog, int item) {
244
				    String login;
245
				    String auth;
246
				    Log.d(getClass().getName(),"Item is :"+item);
247
				       if(item ==0){
248
				    	   login=Preferences.LOGIN_PITHOS_DEV_SERVER;
249
				    	   auth= Preferences.PITHOS_DEV_SERVER;
250
				       }
251
				       else if(item ==1){
252
				    	   login=Preferences.LOGIN_PITHOS_STAGING_SERVER;
253
				    	   auth= Preferences.PITHOS_STAGING_SERVER;
254
				       }
255
				       else{
256
				    	   login=Preferences.LOGIN_PITHOS_SERVER;
257
				    	   auth= Preferences.PITHOS_SERVER;
258
				       }
259
				       Intent intent2 = new Intent(ListAccountsActivity.this, PithosLoginActivity.class);
260
						//intent2.putExtra("login", "https://pithos.dev.grnet.gr/im/login");
261
						//intent2.putExtra("auth", Preferences.PITHOS_DEV_SERVER);
262
				       Log.d("LOGIN_URL",login);
263
				       Log.d("LOGIN_AUTH",auth);
264
						intent2.putExtra("login", login);
265
						intent2.putExtra("auth", auth);
266
						dialog.dismiss();
267
						startActivityForResult(intent2, 78);
268
				    }
269
				});
270
				AlertDialog alert2 = builder.create();
271
				alert2.show();
272
				
273 234
			/*
274
			Intent intent2 = new Intent(this, PithosLoginActivity.class);
275
			//intent2.putExtra("login", "https://pithos.dev.grnet.gr/im/login");
276
			//intent2.putExtra("auth", Preferences.PITHOS_DEV_SERVER);
277
			intent2.putExtra("login", "https://plus.pithos.grnet.gr/im/login");
278
			intent2.putExtra("auth", Preferences.PITHOS_SERVER);
279
			startActivityForResult(intent2, 78); // arbitrary number; never used again
280
			*/
281
			return true;
282

  
283
//		case R.id.contact_rackspace:
284
//			startActivity(new Intent(this, Abo.class));
285
//			return true;
286

  
287
//		case R.id.add_password:
288
//			startActivity(new Intent(this, CreatePasswordActivity.class));
289
//			return true;
290
		}	
235
			 * case R.id.login_pithos:
236
			 * 
237
			 * final CharSequence[] items = { "Pithos+ Dev", "Pithos + Staging",
238
			 * "Pithos +" };
239
			 * 
240
			 * AlertDialog.Builder builder = new AlertDialog.Builder(this);
241
			 * builder.setTitle("Select Pithos Environment");
242
			 * builder.setSingleChoiceItems(items, -1, new
243
			 * DialogInterface.OnClickListener() { public void
244
			 * onClick(DialogInterface dialog, int item) { String login; String
245
			 * auth; Log.d(getClass().getName(), "Item is :" + item); if (item
246
			 * == 0) { login = Preferences.LOGIN_PITHOS_DEV_SERVER; auth =
247
			 * Preferences.PITHOS_DEV_SERVER; } else if (item == 1) { login =
248
			 * Preferences.LOGIN_PITHOS_STAGING_SERVER; auth =
249
			 * Preferences.PITHOS_STAGING_SERVER; } else { login =
250
			 * Preferences.LOGIN_PITHOS_SERVER; auth =
251
			 * Preferences.PITHOS_SERVER;
252
			 * 
253
			 * 
254
			 * } Intent intent2 = new Intent( ListAccountsActivity.this,
255
			 * PithosLoginActivity.class); // intent2.putExtra("login", //
256
			 * "https://pithos.dev.grnet.gr/im/login"); //
257
			 * intent2.putExtra("auth", // Preferences.PITHOS_DEV_SERVER);
258
			 * Log.d("LOGIN_URL", login); Log.d("LOGIN_AUTH", auth);
259
			 * intent2.putExtra("login", login); intent2.putExtra("auth", auth);
260
			 * dialog.dismiss(); startActivityForResult(intent2, 78); } });
261
			 * AlertDialog alert2 = builder.create(); alert2.show();
262
			 * 
263
			 * /* //Intent intent2 = new Intent(this,
264
			 * PithosLoginActivity.class); ////intent2.putExtra("login",
265
			 * //"https://pithos.dev.grnet.gr/im/login");
266
			 * ////intent2.putExtra("auth", Preferences.PITHOS_DEV_SERVER);
267
			 * //intent2.putExtra("login",
268
			 * //"https://plus.pithos.grnet.gr/im/login");
269
			 * //intent2.putExtra("auth", Preferences.PITHOS_SERVER);
270
			 * //startActivityForResult(intent2, 78); // arbitrary number; never
271
			 * //used again
272
			 * 
273
			 * return true;
274
			 */
275

  
276
			// case R.id.contact_rackspace:
277
			// startActivity(new Intent(this, Abo.class));
278
			// return true;
279

  
280
			// case R.id.add_password:
281
			// startActivity(new Intent(this, CreatePasswordActivity.class));
282
			// return true;
283
		}
291 284
		return false;
292
	} 
285
	}
293 286

  
294
	//the context menu for a long press on an account
287
	// the context menu for a long press on an account
295 288
	public void onCreateContextMenu(ContextMenu menu, View v,
296 289
			ContextMenuInfo menuInfo) {
297 290
		super.onCreateContextMenu(menu, v, menuInfo);
......
299 292
		inflater.inflate(R.menu.account_context_menu, menu);
300 293
	}
301 294

  
302
	//removes the selected account from account list if remove is clicked
295
	// removes the selected account from account list if remove is clicked
303 296
	public boolean onContextItemSelected(MenuItem item) {
297

  
304 298
		if (accounts.size() == 0) {
305 299
			displayNoAccountsCell();
306 300
			return true;
307 301
		} else {
308
			AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
309
			accounts.remove(info.position);
310
			writeAccounts();
311
			loadAccounts();
312
			return true;
302
			switch (item.getItemId()) {
303
			case R.id.remove_account:
304
				AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
305
						.getMenuInfo();
306

  
307
				accounts.remove(info.position);
308
				writeAccounts();
309
				loadAccounts();
310
				return true;
311
			case R.id.view_account:
312
				info = (AdapterContextMenuInfo) item.getMenuInfo();
313
				Account acc = accounts.get(info.position);
314
				Intent intent = new Intent(this, AddAccountActivity.class);
315
				intent.putExtra("account_displayname", acc.getDisplayName());
316
				intent.putExtra("account_token", acc.getPassword());
317
				intent.putExtra("account_auth", acc.getAuthServer());
318
				startActivityForResult(intent, 78);
319
				return true;
320
			default:
321
				return true;
322
			}
313 323
		}
314 324
	}
315 325

  
......
322 332
		public View getView(int position, View convertView, ViewGroup parent) {
323 333

  
324 334
			LayoutInflater inflater = getLayoutInflater();
325
			View row = inflater.inflate(R.layout.listaccountcell, parent, false);
335
			View row = inflater
336
					.inflate(R.layout.listaccountcell, parent, false);
326 337

  
327 338
			TextView label = (TextView) row.findViewById(R.id.label);
328
			label.setText(accounts.get(position).getUsername());
339
			label.setText(accounts.get(position).getDisplayName()/* + " "
340
					+ accounts.get(position).getUsername()*/);
329 341

  
330 342
			TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
331 343
			sublabel.setText(getAccountServer(accounts.get(position)));
332 344

  
333
			ImageView icon = (ImageView) row.findViewById(R.id.account_type_icon);
345
			ImageView icon = (ImageView) row
346
					.findViewById(R.id.account_type_icon);
334 347
			icon.setImageResource(setAccountIcon(accounts.get(position)));
335 348

  
336 349
			return row;
337 350
		}
338 351
	}
339 352

  
340
	public String getAccountServer(Account account){
353
	public String getAccountServer(Account account) {
341 354
		String authServer = account.getAuthServer();
342
		if(authServer == null){
355
		if (authServer == null) {
343 356
			authServer = account.getAuthServerV2();
344 357
		}
345 358
		String result;
346
				
347
		if(authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER) || authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER_V2)){
359

  
360
		if (authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER)
361
				|| authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER_V2)) {
348 362
			result = "Rackspace Cloud (UK)";
349
		}
350
		else if(authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER) || authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER_V2)){
363
		} else if (authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER)
364
				|| authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER_V2)) {
351 365
			result = "Rackspace Cloud (US)";
352
		}
353
		else if(authServer.equals(Preferences.PITHOS_SERVER)){
366
		} else if (authServer.equals(Preferences.PITHOS_SERVER)) {
354 367
			result = "Pithos+";
355
		}
356
		else if(authServer.equals(Preferences.PITHOS_STAGING_SERVER)){
368
		} else if (authServer.equals(Preferences.PITHOS_STAGING_SERVER)) {
357 369
			result = "Pithos+ Staging";
358
		}
359
		else if(authServer.equals(Preferences.PITHOS_DEV_SERVER)){
370
		} else if (authServer.equals(Preferences.PITHOS_DEV_SERVER)) {
360 371
			result = "Pithos+ Dev";
361
		}
362
		else{
363
			result = "Custom:" +authServer;
364
			//setCustomIcon();
372
		} else {
373
			result = "Custom:" + authServer;
374
			// setCustomIcon();
365 375
		}
366 376
		return result;
367 377
	}
368 378

  
369
	//display rackspace logo for cloud accounts and openstack logo for others
370
	private int setAccountIcon(Account account){
379
	// display rackspace logo for cloud accounts and openstack logo for others
380
	private int setAccountIcon(Account account) {
371 381
		String authServer = account.getAuthServer();
372
		if(authServer == null){
382
		if (authServer == null) {
373 383
			authServer = account.getAuthServerV2();
374 384
		}
375
		if(authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER) 
385
		if (authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER)
376 386
				|| authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER)
377 387
				|| authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER_V2)
378
						|| authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER_V2)){
388
				|| authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER_V2)) {
379 389
			return R.drawable.rackspacecloud_icon;
380 390
		}
381
		if(authServer.equals(Preferences.PITHOS_DEV_SERVER) 
382
				|| authServer.equals(Preferences.PITHOS_SERVER)|| authServer.equals(Preferences.PITHOS_STAGING_SERVER)){
391
		if (authServer.equals(Preferences.PITHOS_DEV_SERVER)
392
				|| authServer.equals(Preferences.PITHOS_SERVER)
393
				|| authServer.equals(Preferences.PITHOS_STAGING_SERVER)) {
383 394
			return R.drawable.pithos_icon;
384
		}
385
		else{
395
		} else {
386 396
			return R.drawable.openstack_icon;
387 397
		}
388 398
	}
......
390 400
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
391 401
		super.onActivityResult(requestCode, resultCode, data);
392 402

  
393
		if(requestCode == 187){
394
			hideAccountDialog(); 
403
		if (requestCode == 187) {
404
			hideAccountDialog();
395 405
		}
396 406

  
397
		if (resultCode == RESULT_OK && requestCode == 78) {	  
407
		if (resultCode == RESULT_OK && requestCode == 78) {
408
			if (data.getBundleExtra("serverused") != null) {
409
				String login;
410
				String auth;
411
				int item = data.getBundleExtra("serverused").getInt("item");
412
				if (item == 2) {
413
					login = Preferences.LOGIN_PITHOS_DEV_SERVER;
414
					auth = Preferences.PITHOS_DEV_SERVER;
415
				} else if (item == 1) {
416
					login = Preferences.LOGIN_PITHOS_STAGING_SERVER;
417
					auth = Preferences.PITHOS_STAGING_SERVER;
418
				} else {
419
					login = Preferences.LOGIN_PITHOS_SERVER;
420
					auth = Preferences.PITHOS_SERVER;
421
				}
422
				Intent intent2 = new Intent(ListAccountsActivity.this,
423
						PithosLoginActivity.class);
424
				Log.d("LOGIN_URL", login);
425
				Log.d("LOGIN_AUTH", auth);
426
				intent2.putExtra("login", login);
427
				intent2.putExtra("auth", auth);
428
				startActivityForResult(intent2, 78);
429
				return;
430
			}
431

  
398 432
			Account acc = new Account();
399 433
			Bundle b = data.getBundleExtra("accountInfo");
400 434
			acc.setPassword(b.getString("apiKey"));
401
			acc.setUsername(b.getString("username"));
402 435
			acc.setAuthServer(b.getString("server"));
436
			if (b.getString("username") != null)
437
				acc.setUsername(b.getString("username"));
438
			else {
439
				acc.setDisplayName(b.getString("displayname"));
440
				Account.setAccount(acc);
441
				acc.setUsername(Account.getUUIDForDisplayName(
442
						acc.getDisplayName(), ListAccountsActivity.this));
443
			}
444
			if (b.getString("displayname") != null) {
445
				acc.setDisplayName(b.getString("displayname"));
446
			} else {
447
				Account.setAccount(acc);
448
				acc.setDisplayName(Account.getDisplayNameForUUID(
449
						acc.getUsername(), ListAccountsActivity.this));
450
			}
403 451
			Log.d("info", "the set server was " + b.getString("server"));
404 452
			Log.d("info", "the server is " + acc.getAuthServer());
405 453
			boolean found = false;
406
			for(Account a : accounts){
407
				if(a.getUsername().equals(acc.getUsername())&&a.getAuthServer().equals(acc.getAuthServer())){
454
			for (Account a : accounts) {
455
				if (a.getUsername().equals(acc.getUsername())
456
						&& a.getAuthServer().equals(acc.getAuthServer())) {
408 457
					a.setPassword(acc.getPassword());
409
					found=true;
458
					found = true;
459
					break;
410 460
				}
411 461
			}
412
			if(!found)
462
			if (!found)
413 463
				accounts.add(acc);
414 464
			writeAccounts();
415 465
			loadAccounts();
416 466
		}
417
	}	
467
	}
418 468

  
419 469
	private void showAccountDialog() {
420 470
		app.setIsLoggingIn(true);
421 471
		authenticating = true;
422
		if(dialog == null || !dialog.isShowing()){
423
			dialog = new ProgressDialog(this);
424
			dialog.setProgressStyle(R.style.NewDialog);
425
			dialog.setOnCancelListener(new OnCancelListener() {
426

  
427
				@Override
428
				public void onCancel(DialogInterface dialog) {
429
					app.setIsLoggingIn(false);
430
					//need to cancel the old task or we may get a double login
431
					task.cancel(true);
432
					hideAccountDialog();
433
				}
434
			});
435
			dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
472
		if (dialog == null || !dialog.isShowing()) {
473
			dialog = CenteredProgressDialog.show(this, "", "", false, true,
474
					new OnCancelListener() {
475
						@Override
476
						public void onCancel(DialogInterface dialog) {
477
							app.setIsLoggingIn(false);
478
							// need to cancel the old task or we may get a
479
							// double login
480
							task.cancel(true);
481
							hideAccountDialog();
482
						}
483
					});
436 484
			dialog.show();
437
			dialog.setContentView(new ProgressBar(this), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
485

  
438 486
		}
439 487

  
440
		
441 488
	}
442 489

  
443 490
	private void hideAccountDialog() {
444
		if(dialog != null){
491
		if (dialog != null) {
445 492
			dialog.dismiss();
446 493
		}
447 494
		authenticating = false;
......
450 497
	private class AuthenticateTask extends AsyncTask<Void, Void, Boolean> {
451 498

  
452 499
		@Override
453
		protected void onPreExecute(){
500
		protected void onPreExecute() {
454 501
			Log.d("info", "Starting authenticate");
455 502
			task = this;
456 503
			showAccountDialog();
......
469 516
		@Override
470 517
		protected void onPostExecute(Boolean result) {
471 518
			if (result.booleanValue()) {
472
				//startActivity(tabViewIntent);
473
				/*if(app.isLoggingIn()){
474
					new LoadImagesTask().execute((Void[]) null);
475
				} else {
476
					hideAccountDialog();
477
				}*/
519
				// startActivity(tabViewIntent);
520
				/*
521
				 * if(app.isLoggingIn()){ new LoadImagesTask().execute((Void[])
522
				 * null); } else { hideAccountDialog(); }
523
				 */
478 524
				hideAccountDialog();
479
				if(app.isLoggingIn()){
525
				if (app.isLoggingIn()) {
480 526
					startActivityForResult(tabViewIntent, 187);
481 527
				}
482 528
			} else {
483 529
				hideAccountDialog();
484
				if(app.isLoggingIn()){
485
					showAlert("Login Failure", "Authentication failed.  Please check your User Name and API Key.");
530
				if (app.isLoggingIn()) {
531
					showAlert("Login Failure",
532
							"Authentication failed.  Please check your User Name and API Key.");
486 533
				}
487 534
			}
488 535
		}
489 536
	}
490 537

  
491
	
492

  
493
	}
538
}

Also available in: Unified diff