commit 378fe36a99c28bf476c4db19caedb62c97d8f272
Author: Giannis Koutsoubos <koutsoub@gmail.com>
Date:   Wed Feb 20 16:09:16 2013 +0200

    center progress dialog, use displayname/uuid logic in login/permissions/others, unify login-addAccount, allow to edit account, fix problem on SDK version 3,4 with AsyncTaskExecution in download-delete-edit, fix http handling done in main thread and leading to crashes on 4.0+ devices, use 2.3 display since tab panel with images is not supported on 4+ devices, do not show size in flders if size is 0

diff --git a/src/com/rackspace/cloud/android/PithosLoginActivity.java b/src/com/rackspace/cloud/android/PithosLoginActivity.java
index 1a76697..c111090 100644
--- a/src/com/rackspace/cloud/android/PithosLoginActivity.java
+++ b/src/com/rackspace/cloud/android/PithosLoginActivity.java
@@ -1,20 +1,22 @@
 package com.rackspace.cloud.android;
 
-
-
-
-
 import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.StringTokenizer;
 
 import org.apache.http.impl.cookie.BasicClientCookie;
 
+import com.rackspace.cloud.files.api.client.ContainerObjectManager;
+import com.rackspace.cloud.servers.api.client.CloudServersException;
+
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.net.http.SslError;
+import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
 import android.text.method.PasswordTransformationMethod;
@@ -33,130 +35,142 @@ import android.widget.LinearLayout;
 import android.widget.LinearLayout.LayoutParams;
 import android.widget.TextView;
 
-
-public class PithosLoginActivity extends CloudActivity{
-	String loginUrl=null;
+public class PithosLoginActivity extends CloudActivity {
+	String loginUrl = null;
 	String auth = null;
-	
+
 	public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        trackPageView(GoogleAnalytics.PAGE_PROVIDERS);
-        Log.i("LOGIN","START");
-        
-        setContentView(R.layout.login);
-        CookieSyncManager.createInstance(this);
+		super.onCreate(savedInstanceState);
+		trackPageView(GoogleAnalytics.PAGE_PROVIDERS);
+		Log.i("LOGIN", "START");
+
+		setContentView(R.layout.login);
+		CookieSyncManager.createInstance(this);
 		CookieSyncManager.getInstance().startSync();
 		CookieSyncManager.getInstance().sync();
-		//String loginUrl ="https://plus.pithos.grnet.gr/im/login/";//invitation?code=3219662435709009446");
+		// String loginUrl
+		// ="https://plus.pithos.grnet.gr/im/login/";//invitation?code=3219662435709009446");
 		/*
-		CookieManager.getInstance().setCookie(loginUrl, "_pithos2_a='';expires=Mon, 17 Oct 2010 10:47:11 UTC;");
-		CookieManager.getInstance().removeExpiredCookie();
-		CookieManager.getInstance().removeSessionCookie();*/
+		 * CookieManager.getInstance().setCookie(loginUrl,
+		 * "_pithos2_a='';expires=Mon, 17 Oct 2010 10:47:11 UTC;");
+		 * CookieManager.getInstance().removeExpiredCookie();
+		 * CookieManager.getInstance().removeSessionCookie();
+		 */
 		CookieManager.getInstance().removeAllCookie();
-		final WebView webview = (WebView) findViewById(R.id.browser);//new WebView(this);
-		
-        loginUrl = getIntent().getExtras().getString("login");
-        auth = getIntent().getExtras().getString("auth");
-        webview.requestFocus(View.FOCUS_DOWN);
-        webview.setOnTouchListener(new View.OnTouchListener() {
-            @Override
-            public boolean onTouch(View v, MotionEvent event) {
-                switch (event.getAction()) {
-                    case MotionEvent.ACTION_DOWN:
-                    case MotionEvent.ACTION_UP:
-                        if (!v.hasFocus()) {
-                            v.requestFocus();
-                        }
-                        break;
-                }
-                return false;
-            }
-        });
-        doLogin(webview);
-    
-        
-    } 
+		final WebView webview = (WebView) findViewById(R.id.browser);// new
+																		// WebView(this);
+
+		loginUrl = getIntent().getExtras().getString("login");
+		auth = getIntent().getExtras().getString("auth");
+		webview.requestFocus(View.FOCUS_DOWN);
+
+		webview.setOnTouchListener(new View.OnTouchListener() {
+			@Override
+			public boolean onTouch(View v, MotionEvent event) {
+				switch (event.getAction()) {
+				case MotionEvent.ACTION_DOWN:
+				case MotionEvent.ACTION_UP:
+					if (!v.hasFocus()) {
+						v.requestFocus();
+					}
+					break;
+				}
+				return false;
+			}
+		});
+		doLogin(webview);
+
+	}
+
 	/*
-	protected void onSaveInstanceState(Bundle outState) {
-		super.onSaveInstanceState(outState);
-		//outState.putBoolean("isHidden", isHidden);
-	}*/
-	
-	private void doLogin(final WebView webview){
-		
+	 * protected void onSaveInstanceState(Bundle outState) {
+	 * super.onSaveInstanceState(outState); //outState.putBoolean("isHidden",
+	 * isHidden); }
+	 */
+
+	private void doLogin(final WebView webview) {
+
 		webview.getSettings().setJavaScriptEnabled(true);
 		// webview.setHttpAuthUsernamePassword("vho.grnet.gr", "VHO login",
 		// "ebs-koutsoub", "mwJBdgbtv");
-		
+
 		webview.clearCache(true);
 		webview.clearFormData();
 		webview.clearHistory();
-		
-		
-		webview.getSettings().setBuiltInZoomControls(true);
-		//webview.getSettings().setDefaultZoom(ZoomDensity.);
-		//if(Build.VERSION.SDK_INT!=7)
-			//webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
-		
+
+		// webview.getSettings().setBuiltInZoomControls(true);
+		webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
+		// if(Build.VERSION.SDK_INT!=7)
+		// webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
+
 		webview.setWebViewClient(new WebViewClient() {
-			
-			public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
-		          handler.proceed();
-		     }
-
-			  @Override public boolean shouldOverrideUrlLoading(WebView view,
-			  String url) { 
-				  view.loadUrl(url); return true;
-			  }
-			 
+
+			public void onReceivedSslError(WebView view,
+					SslErrorHandler handler, SslError error) {
+				handler.proceed();
+			}
+
 			@Override
+			public boolean shouldOverrideUrlLoading(WebView view, String url) {
+				view.loadUrl(url);
+				return true;
+			}
 
+			@Override
 			public void onPageFinished(WebView view, String url) {
 				super.onPageFinished(view, url);
-				
+
 				CookieSyncManager.getInstance().sync();
-				
+
 				String cookie = CookieManager.getInstance().getCookie(url);
-				if(cookie!=null)
-				Log.i("LOGIN COOKIE",url+" c: "+cookie +" "+cookie.contains("_pithos2_a"));
-				/*if(url.indexOf('?')!=-1){
-					String q = url.substring(url.indexOf('?'),url.length());
-					Log.i("LOGIN COOKIE",url+" c: "+q);
-					Map<String,String> params = getQueryMap(q);
-					String token = params.get("token");
-					String user = params.get("user");
-					if(token!=null&&user!=null)
-						exit(user,token);
-					
-				}*/
-				if(null!=cookie && cookie.contains("_pithos2_a")){
-					StringTokenizer str1 = new StringTokenizer(cookie,";");
-					while(str1.hasMoreTokens()){
+				if (cookie != null)
+					Log.i("LOGIN COOKIE",
+							url + " c: " + cookie + " "
+									+ cookie.contains("_pithos2_a"));
+				/*
+				 * if(url.indexOf('?')!=-1){ String q =
+				 * url.substring(url.indexOf('?'),url.length());
+				 * Log.i("LOGIN COOKIE",url+" c: "+q); Map<String,String> params
+				 * = getQueryMap(q); String token = params.get("token"); String
+				 * user = params.get("user"); if(token!=null&&user!=null)
+				 * exit(user,token);
+				 * 
+				 * }
+				 */
+				if (null != cookie && cookie.contains("_pithos2_a")) {
+					StringTokenizer str1 = new StringTokenizer(cookie, ";");
+					while (str1.hasMoreTokens()) {
 						String cc = str1.nextToken();
-						Log.i("LOGIN","token:"+cc);
-						if(cc.trim().startsWith("_pithos2_a")){
-							Log.i("LOGIN COOKIE INSIDE",url+" c: "+cc);
+						Log.i("LOGIN", "token:" + cc);
+						if (cc.trim().startsWith("_pithos2_a")) {
+							Log.i("LOGIN COOKIE INSIDE", url + " c: " + cc);
 							try {
-								String value = URLDecoder.decode(parseRawCookie(cc).getValue());
-								StringTokenizer str = new StringTokenizer(value,"|");
-								if(str.countTokens()==2){
+								String value = URLDecoder
+										.decode(parseRawCookie(cc).getValue());
+								StringTokenizer str = new StringTokenizer(
+										value, "|");
+								if (str.countTokens() == 2) {
 									String u = str.nextToken();
 									String t = str.nextToken();
-									Log.i("value",value);
-									Log.i("s1",u);
-									Log.i("s2",t);
-									exit(u,t);
+									if (u.startsWith("\""))
+										u = u.substring(1, u.length());
+									if (t.endsWith("\""))
+										t = t.substring(0, t.length() - 1);
+									Log.i("value", value);
+									Log.i("s1", u);
+									Log.i("s2", t);
+									exit(u, t);
 									return;
 								}
-								
-								//exit(s[0], s[1]);
+
+								// exit(s[0], s[1]);
 							} catch (Exception e) {
 								// TODO Auto-generated catch block
 								e.printStackTrace();
 							}
 						}
 					}
-					
+
 				}
 			}
 
@@ -166,81 +180,91 @@ public class PithosLoginActivity extends CloudActivity{
 				String[] up = view.getHttpAuthUsernamePassword(host, realm);
 				if (up != null && up.length == 2) {
 					handler.proceed(up[0], up[1]);
-					
+
 				} else {
-						final AlertDialog.Builder alert = new AlertDialog.Builder(PithosLoginActivity.this);
-			        	alert.setTitle("Pithos Login");
-			        	//View lv = findViewById(R.layout.dialoglogin);
-			        	//alert.setView(lv);
-			    		final EditText input = new EditText(PithosLoginActivity.this);//(EditText) lv.findViewById(R.id.username); 
-			    		final EditText pass = new EditText(PithosLoginActivity.this);//(EditText) lv.findViewById(R.id.password);
-			    		pass.setTransformationMethod(new PasswordTransformationMethod());
-			    		LinearLayout layout = new LinearLayout(PithosLoginActivity.this);
-			    		layout.setOrientation(LinearLayout.VERTICAL);
-			    		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
-			    		layout.setLayoutParams(params);
-			    		input.setLayoutParams(params);
-			    		pass.setLayoutParams(params);
-			    		TextView username = new TextView(PithosLoginActivity.this);
-			    		username.setText("Username:");
-			    		
-			    		TextView password = new TextView(PithosLoginActivity.this);
-			    		password.setText("Password:");
-			    		layout.addView(username);
-			    		layout.addView(input);
-			    		layout.addView(password);
-			    		layout.addView(pass);
-			    		alert.setView(layout);
-			    		
-			    		alert.setPositiveButton("Login", new DialogInterface.OnClickListener() {
-			    			public void onClick(DialogInterface dialog, int whichButton) {
-			    				String uvalue = input.getText().toString().trim();
-			    				String pvalue = pass.getText().toString().trim();
-			    				handler.proceed(uvalue, pvalue);			    				
-			    			}
-			    		});
-
-			    		alert.setNegativeButton("Cancel",
-			    				new DialogInterface.OnClickListener() {
-			    					public void onClick(DialogInterface dialog, int whichButton) {
-			    						dialog.cancel();
-			    					}
-			    				});
-			    		alert.show();
-					}
+					final AlertDialog.Builder alert = new AlertDialog.Builder(
+							PithosLoginActivity.this);
+					alert.setTitle("Pithos Login");
+					// View lv = findViewById(R.layout.dialoglogin);
+					// alert.setView(lv);
+					final EditText input = new EditText(
+							PithosLoginActivity.this);// (EditText)
+														// lv.findViewById(R.id.username);
+					final EditText pass = new EditText(PithosLoginActivity.this);// (EditText)
+																					// lv.findViewById(R.id.password);
+					pass.setTransformationMethod(new PasswordTransformationMethod());
+					LinearLayout layout = new LinearLayout(
+							PithosLoginActivity.this);
+					layout.setOrientation(LinearLayout.VERTICAL);
+					LayoutParams params = new LayoutParams(
+							LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+					layout.setLayoutParams(params);
+					input.setLayoutParams(params);
+					pass.setLayoutParams(params);
+					TextView username = new TextView(PithosLoginActivity.this);
+					username.setText("Username:");
+
+					TextView password = new TextView(PithosLoginActivity.this);
+					password.setText("Password:");
+					layout.addView(username);
+					layout.addView(input);
+					layout.addView(password);
+					layout.addView(pass);
+					alert.setView(layout);
+
+					alert.setPositiveButton("Login",
+							new DialogInterface.OnClickListener() {
+								public void onClick(DialogInterface dialog,
+										int whichButton) {
+									String uvalue = input.getText().toString()
+											.trim();
+									String pvalue = pass.getText().toString()
+											.trim();
+									handler.proceed(uvalue, pvalue);
+								}
+							});
+
+					alert.setNegativeButton("Cancel",
+							new DialogInterface.OnClickListener() {
+								public void onClick(DialogInterface dialog,
+										int whichButton) {
+									dialog.cancel();
+								}
+							});
+					alert.show();
 				}
+			}
 
-			
 		});
-		Log.i("LOGIN","LOADING:"+loginUrl);
-		//setContentView(webview);
+		Log.i("LOGIN", "LOADING:" + loginUrl);
+		// setContentView(webview);
 		webview.clearSslPreferences();
-		//webview.loadUrl("https://pithos.dev.grnet.gr/im/login/invitation?code=6879429392467020041");
-		
-		
-		webview.loadUrl(loginUrl);//invitation?code=3219662435709009446");
-		
-		//webview.loadUrl("http://www.google.gr");
+		// webview.loadUrl("https://pithos.dev.grnet.gr/im/login/invitation?code=6879429392467020041");
+
+		webview.loadUrl(loginUrl);// invitation?code=3219662435709009446");
+
+		// webview.loadUrl("http://www.google.gr");
 	}
-	
+
 	public static Map<String, String> getQueryMap(String query) {
 		String[] params = query.split("&");
 		Map<String, String> map = new HashMap<String, String>();
 		for (String param : params) {
 			String name = param.split("=")[0];
 			String value = param.split("=")[1];
-			if(param.endsWith("=="))
-				value=value+"==";
-			else if(param.endsWith("="))
-				value=value+"=";
-			
-			Log.d("DD",name +" "+value);
+			if (param.endsWith("=="))
+				value = value + "==";
+			else if (param.endsWith("="))
+				value = value + "=";
+
+			Log.d("DD", name + " " + value);
 			map.put(name, value);
 		}
 		return map;
 	}
-	void exit(String username,String token){
-		Log.i("LOGINA",username+" "+token);
+
+	void exit(final String username, final String token) {
+		Log.d("LOGINA", username + " " + token);
 		Intent result = new Intent();
 		Bundle b = new Bundle();
 		b.putString("username", username);
@@ -248,67 +272,87 @@ public class PithosLoginActivity extends CloudActivity{
 		b.putString("server", auth);
 		result.putExtra("accountInfo", b);
 		setResult(RESULT_OK, result);
+		PithosLoginActivity.this.finish();
+	}
+
+	public void returnToCaller(Bundle b) {
+		Intent result = new Intent();
+		result.putExtra("accountInfo", b);
+		setResult(RESULT_OK, result);
 		finish();
 	}
-	
-	
+
 	BasicClientCookie parseRawCookie(String rawCookie) throws Exception {
-	    String[] rawCookieParams = rawCookie.split(";");
+		String[] rawCookieParams = rawCookie.split(";");
 
-	    String[] rawCookieNameAndValue = rawCookieParams[0].split("=");
-	    if (rawCookieNameAndValue.length != 2) {
-	        throw new Exception("Invalid cookie: missing name and value.");
-	    }
+		String[] rawCookieNameAndValue = rawCookieParams[0].split("=");
+		if (rawCookieNameAndValue.length != 2) {
+			throw new Exception("Invalid cookie: missing name and value.");
+		}
 
-	    String cookieName = rawCookieNameAndValue[0].trim();
-	    String cookieValue = rawCookieNameAndValue[1].trim();
-	    BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue);
-	    for (int i = 1; i < rawCookieParams.length; i++) {
-	        String rawCookieParamNameAndValue[] = rawCookieParams[i].trim().split("=");
+		String cookieName = rawCookieNameAndValue[0].trim();
+		String cookieValue = rawCookieNameAndValue[1].trim();
+		BasicClientCookie cookie = new BasicClientCookie(cookieName,
+				cookieValue);
+		for (int i = 1; i < rawCookieParams.length; i++) {
+			String rawCookieParamNameAndValue[] = rawCookieParams[i].trim()
+					.split("=");
 
-	        String paramName = rawCookieParamNameAndValue[0].trim();
+			String paramName = rawCookieParamNameAndValue[0].trim();
 
-	        if (paramName.equalsIgnoreCase("secure")) {
-	            cookie.setSecure(true);
-	        } else {
-	            if (rawCookieParamNameAndValue.length != 2) {
-	                throw new Exception("Invalid cookie: attribute not a flag or missing value.");
-	            }
+			if (paramName.equalsIgnoreCase("secure")) {
+				cookie.setSecure(true);
+			} else {
+				if (rawCookieParamNameAndValue.length != 2) {
+					throw new Exception(
+							"Invalid cookie: attribute not a flag or missing value.");
+				}
 
-	            String paramValue = rawCookieParamNameAndValue[1].trim();
+				String paramValue = rawCookieParamNameAndValue[1].trim();
 
-	            
-	        }
-	    }
+			}
+		}
 
-	    return cookie;
+		return cookie;
 	}
-	
+
 	private String lastHtml;
-	
+
 	public void setLastHtml(String lastHtml) {
 		this.lastHtml = lastHtml;
 	}
-	
+
 	public String getLastHtml() {
 		return lastHtml;
 	}
-	  class MyJavaScriptInterface {
-	  
-	  public void showHTML(String html) { 
-		  setLastHtml(html);
-	  
-	  } }
-	  
-	  private String getHtmlValue(String substring, String html){ String
-	  result=null; boolean found = false; found = html.contains(substring); if
-	  (found) { int indx = html.indexOf(substring); StringBuffer res = new
-	  StringBuffer(); for (int i = indx + substring.length(); i < html
-	  .length(); i++) { char c = html.charAt(i); if (c == '<') break;
-	  res.append(c); }
-	  
-	  result = res.toString(); result = result.trim();
-	  
-	  } return result; }
-	 
+
+	class MyJavaScriptInterface {
+
+		public void showHTML(String html) {
+			setLastHtml(html);
+
+		}
+	}
+
+	private String getHtmlValue(String substring, String html) {
+		String result = null;
+		boolean found = false;
+		found = html.contains(substring);
+		if (found) {
+			int indx = html.indexOf(substring);
+			StringBuffer res = new StringBuffer();
+			for (int i = indx + substring.length(); i < html.length(); i++) {
+				char c = html.charAt(i);
+				if (c == '<')
+					break;
+				res.append(c);
+			}
+
+			result = res.toString();
+			result = result.trim();
+
+		}
+		return result;
+	}
+
 }
