Revision d88d3ae1

b/res/layout/createaccount.xml
7 7
	<Spinner android:layout_height="wrap_content"
8 8
		android:layout_marginLeft="22dip" android:layout_marginRight="30dip"
9 9
		android:layout_width="fill_parent" android:id="@+id/provider_spinner"></Spinner>
10
	<TextView android:layout_height="wrap_content" android:text="Custom Authentication Server" android:layout_marginLeft="22dip" android:layout_width="fill_parent"></TextView>
11
	<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/custom_auth_server_edit" android:text="https://" android:layout_marginLeft="22dip" android:layout_marginRight="30dip"></EditText>
10 12
	<TextView android:layout_height="wrap_content" android:text="Username"
11 13
		android:layout_marginLeft="22dip" android:layout_width="fill_parent"></TextView>
12 14
	<EditText android:layout_width="fill_parent"
b/res/layout/listaccountcell.xml
3 3
  xmlns:android="http://schemas.android.com/apk/res/android"
4 4
  android:layout_width="fill_parent"
5 5
  android:orientation="horizontal" android:layout_height="64dip">
6
    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/account_type_icon" android:src="@drawable/rackspace60"></ImageView>
6
    <ImageView android:id="@+id/account_type_icon" android:layout_gravity="center" android:layout_height="fill_parent" android:layout_width="wrap_content" android:maxHeight="30dp" android:maxWidth="30dp" android:layout_marginLeft="10dip"></ImageView>
7 7
    <TableLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_marginLeft="10dip" android:id="@+id/tableLayout1" android:layout_width="190dip">
8 8
        <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow1" android:layout_width="wrap_content">
9 9
            <TextView android:textSize="24sp" android:textColor="#FFFFFF" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5px" android:id="@+id/label"></TextView>
......
12 12
            <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/sublabel"></TextView>
13 13
        </TableRow>
14 14
    </TableLayout>
15
    <ProgressBar android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:visibility="invisible" android:id="@+id/logon_progress_bar"></ProgressBar>
16 15
</LinearLayout>
b/res/layout/viewserver.xml
226 226
            android:layout_marginLeft="20dip"
227 227
            android:layout_marginTop="10dip"
228 228
            />
229
        
230
        <Button xmlns:android="http://schemas.android.com/apk/res/android"
231
            android:id="@+id/view_server_delete_button"
232
            android:text="Delete Server"
233
            android:layout_width="130dip"
234
            android:layout_height="wrap_content"
235
            android:layout_gravity="left"
236
            android:layout_marginLeft="10dip"
237
            android:layout_marginTop="10dip"
238
            />
229
        <Button android:layout_marginTop="10dip" android:id="@+id/view_server_delete_button" android:text="Delete Server" android:layout_width="130dip" android:layout_gravity="left" android:layout_marginLeft="10dip" android:layout_height="wrap_content"></Button>
239 230
    </LinearLayout>
240 231
    
241 232
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
b/src/com/rackspace/cloud/servers/api/client/FlavorManager.java
16 16
import org.apache.http.client.ClientProtocolException;
17 17
import org.apache.http.client.methods.HttpGet;
18 18
import org.apache.http.impl.client.BasicResponseHandler;
19
import org.apache.http.impl.client.DefaultHttpClient;
20 19
import org.xml.sax.InputSource;
21 20
import org.xml.sax.SAXException;
22 21
import org.xml.sax.XMLReader;
b/src/com/rackspace/cloud/servers/api/client/Image.java
11 11
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
12 12
 *
13 13
 */
14
public class Image extends Entity {
14
public class Image extends Entity implements Comparable<Image>{
15 15

  
16 16
	private static final long serialVersionUID = -9020224299062520935L;
17 17
	private static TreeMap<String, Image> images;
......
67 67
			iconResourceId = R.drawable.centos_icon;
68 68
		} else if ("49".equals(getId())) {
69 69
			iconResourceId = R.drawable.ubuntu_icon;
70
		} else if ("51".equals(getId())) {
71
			iconResourceId = R.drawable.centos_icon;
72
		} else if ("53".equals(getId())) {
73
			iconResourceId = R.drawable.fedora_icon;
74
		} else if ("55".equals(getId())) {
75
			iconResourceId = R.drawable.arch_icon;
76
		} else if ("56".equals(getId())) {
77
			iconResourceId = R.drawable.windows_icon;
78
		} else if ("57".equals(getId())) {
79
			iconResourceId = R.drawable.windows_icon;
80
		} else if ("58".equals(getId())) {
81
			iconResourceId = R.drawable.windows_icon;
82
		} else if ("62".equals(getId())) {
83
			iconResourceId = R.drawable.redhat_icon;
84
		} else if ("69".equals(getId())) {
85
			iconResourceId = R.drawable.ubuntu_icon;
86
		} else if ("71".equals(getId())) {
87
			iconResourceId = R.drawable.fedora_icon;
70 88
		}
71
		
72 89
		return iconResourceId;
73 90
	}
74 91
	
......
121 138
			logoResourceId = R.drawable.centos_large;
122 139
		} else if ("49".equals(getId())) {
123 140
			logoResourceId = R.drawable.ubuntu_large;
141
		} else if ("51".equals(getId())) {
142
			logoResourceId = R.drawable.centos_large;
143
		} else if ("53".equals(getId())) {
144
			logoResourceId = R.drawable.fedora_large;
145
		} else if ("55".equals(getId())) {
146
			logoResourceId = R.drawable.arch_large;
147
		} else if ("56".equals(getId())) {
148
			logoResourceId = R.drawable.windows_large;
149
		} else if ("57".equals(getId())) {
150
			logoResourceId = R.drawable.windows_large;
151
		} else if ("58".equals(getId())) {
152
			logoResourceId = R.drawable.windows_large;
153
		} else if ("62".equals(getId())) {
154
			logoResourceId = R.drawable.redhat_large;
155
		} else if ("69".equals(getId())) {
156
			logoResourceId = R.drawable.ubuntu_large;
157
		} else if ("71".equals(getId())) {
158
			logoResourceId = R.drawable.fedora_large;
124 159
		}
125 160
		
126 161
		return logoResourceId;
......
164 199
	public static void setImages(TreeMap<String, Image> images) {
165 200
		Image.images = images;
166 201
	}
202

  
203
	@Override
204
	public int compareTo(Image b) {
205
		return this.getName().compareTo(b.getName());
206
	}
167 207
	
168 208
	
169 209
}
b/src/com/rackspace/cloud/servers/api/client/ServerManager.java
284 284
		}	
285 285
		return resp;
286 286
	}
287
	
288
	public HttpResponse confirmResize(Server server, Context context) throws CloudServersException {
289
		HttpResponse resp = null;
290
		CustomHttpClient httpclient = new CustomHttpClient(context);
291
		HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml");			
292
		post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
293
		post.addHeader("Content-Type", "application/xml");
294
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
295

  
296
		StringEntity tmp = null;
297
		try {
298
			tmp = new StringEntity("<confirmResize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\">");
299
		} catch (UnsupportedEncodingException e) {
300
			CloudServersException cse = new CloudServersException();
301
			cse.setMessage(e.getLocalizedMessage());
302
			throw cse;
303
		}
304
		post.setEntity(tmp);
305

  
306
		try {			
307
			resp = httpclient.execute(post);
308
		} catch (ClientProtocolException e) {
309
			CloudServersException cse = new CloudServersException();
310
			cse.setMessage(e.getLocalizedMessage());
311
			throw cse;
312
		} catch (IOException e) {
313
			CloudServersException cse = new CloudServersException();
314
			cse.setMessage(e.getLocalizedMessage());
315
			throw cse;
316
		} catch (FactoryConfigurationError e) {
317
			CloudServersException cse = new CloudServersException();
318
			cse.setMessage(e.getLocalizedMessage());
319
			throw cse;
320
		}	
321
		return resp;
322
	}
287 323

  
288 324

  
289 325
	public HttpResponse delete(Server server, Context context) throws CloudServersException {
b/src/com/rackspacecloud/android/AddAccountActivity.java
20 20
	
21 21
	EditText usernameText;
22 22
	EditText apiKeyText;
23
	EditText customServer;
23 24
	Spinner providerSpinner;
24 25
	String authServer;
25 26
	boolean isHidden;
......
29 30
        setContentView(R.layout.createaccount);
30 31
        usernameText = (EditText) findViewById(R.id.username);
31 32
        apiKeyText = (EditText) findViewById(R.id.addaccount_apikey);
33
        customServer = (EditText) findViewById(R.id.custom_auth_server_edit);
32 34
        ((Button) findViewById(R.id.submit_new_account)).setOnClickListener(this);
33 35
        isHidden = true;
36
        customServer.setEnabled(false);
34 37
        if(savedInstanceState != null)
35 38
        	isHidden = savedInstanceState.containsKey("isHidden") && savedInstanceState.getBoolean("isHidden");
36 39
        setUpApiText(savedInstanceState);
......
78 81
		//set the auth server default to us
79 82
		authServer = "https://auth.api.rackspacecloud.com/v1.0";
80 83
		providerSpinner = (Spinner) findViewById(R.id.provider_spinner);
81
		String[] providers = {"Rackspace Cloud (US)", "Rackspace Cloud (UK)"};
84
		String[] providers = {"Rackspace Cloud (US)", "Rackspace Cloud (UK)", "Custom"};
82 85
		ArrayAdapter<String> imageAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, providers);
83 86
		imageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
84 87
		providerSpinner.setAdapter(imageAdapter);
85 88
		providerSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
86 89
		    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
87 90
		    	if(pos == 0){
88
					authServer = "https://auth.api.rackspacecloud.com/v1.0";
91
					authServer = Preferences.COUNTRY_US_AUTH_SERVER;
92
			        customServer.setEnabled(false);
89 93
				}
90 94
				else if(pos == 1){
91
					authServer = "https://lon.auth.api.rackspacecloud.com/v1.0";
95
					authServer = Preferences.COUNTRY_UK_AUTH_SERVER;
96
			        customServer.setEnabled(false);
97
				}
98
				else{
99
			        customServer.setEnabled(true);
92 100
				}
93 101
		    }
94 102
		    public void onNothingSelected(AdapterView<?> parent) {
......
97 105
	}
98 106
	
99 107
	public void onClick(View arg0) {
100
		
108

  
101 109
		if (hasValidInput()) {
102 110
			//showActivityIndicators();
103 111
			Intent result = new Intent();
104 112
			Bundle b = new Bundle();
105 113
			b.putString("username", usernameText.getText().toString());
106 114
			b.putString("apiKey", apiKeyText.getText().toString());
107
			b.putString("server", authServer);
115
			b.putString("server", getAuthServer());
108 116
			result.putExtra("accountInfo", b);
109 117
			setResult(RESULT_OK, result);
110 118
			finish();
......
114 122
		
115 123
	}
116 124
	
125
	private String getAuthServer(){
126
		if(customServer.isEnabled()){
127
			authServer = customServer.getText().toString();
128
		}
129
		return authServer;
130
	}
131
	
117 132
	private void showAlert(String title, String message) {
118 133
    	try {
119 134
		AlertDialog alert = new AlertDialog.Builder(this).create();
b/src/com/rackspacecloud/android/AddServerActivity.java
3 3
 */
4 4
package com.rackspacecloud.android;
5 5

  
6
import java.util.Arrays;
6 7
import java.util.Iterator;
7 8

  
8 9
import android.app.Activity;
......
67 68
			imageNames[i] = image.getName();
68 69
			i++;
69 70
		}
71
		
72
		//Sort so they display better in the spinner
73
		Arrays.sort(images);
74
		Arrays.sort(imageNames);
75
		
70 76
		selectedImageId = images[0].getId();
71 77
		ArrayAdapter<String> imageAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, imageNames);
72 78
		imageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
b/src/com/rackspacecloud/android/BackupServerActivity.java
23 23

  
24 24
import android.app.Activity;
25 25
import android.app.AlertDialog;
26
import android.content.Context;
26 27
import android.content.DialogInterface;
27 28

  
28 29
import android.os.AsyncTask;
......
112 113
		alert.show();
113 114
	}
114 115
	
116
    private void showToast(String message) {
117
		Context context = getApplicationContext();
118
		int duration = Toast.LENGTH_SHORT;
119
		Toast toast = Toast.makeText(context, message, duration);
120
		toast.show();
121
    }
122
	
115 123
	private CloudServersException parseCloudServersException(HttpResponse response) {
116 124
		CloudServersException cse = new CloudServersException();
117 125
		try {
......
147 155
		private CloudServersException exception;
148 156
		
149 157
		@Override
158
		//let user know their process has started
159
		protected void onPreExecute(){
160
			showToast("Changing backup schedule process has begun");
161
		}
162
		
163
		@Override
150 164
		protected HttpResponse doInBackground(Void... arg0) {
151 165
			HttpResponse resp = null;
152 166
			try {
......
164 178
				int statusCode = response.getStatusLine().getStatusCode();	
165 179
				Log.d("statuscode", Integer.toString(statusCode));
166 180
				if(statusCode == 204 || statusCode == 202){
167
					String mustMatch = "The server's backup schedule has been changed.";
168
					Toast passwordError = Toast.makeText(getApplicationContext(), mustMatch, Toast.LENGTH_SHORT);
169
					passwordError.show();
181
					showToast("The server's backup schedule has been change.");
170 182
					finish();
171 183
				}
172 184
				else if (statusCode != 204 && statusCode != 202) {
b/src/com/rackspacecloud/android/ListAccountsActivity.java
119 119
			out.flush();
120 120
			out.close();
121 121
		} catch (FileNotFoundException e) {
122
			// TODO Auto-generated catch block
122
			showAlert("Error", "Could not save accounts.");
123 123
			e.printStackTrace();
124 124
		} catch (IOException e) {
125
			// TODO Auto-generated catch block
125
			showAlert("Error", "Could not save accounts.");
126 126
			e.printStackTrace();
127 127
		}
128 128
	}
......
138 138
			Log.d("captin", Boolean.toString(file == null));
139 139
			return file;
140 140
		} catch (FileNotFoundException e) {
141
			// TODO Auto-generated catch block
141
			//showAlert("Error", "Could not load accounts.");
142 142
			e.printStackTrace();
143 143
			return null;
144 144
		} catch (StreamCorruptedException e) {
145
			// TODO Auto-generated catch block
145
			showAlert("Error", "Could not load accounts.");
146 146
			e.printStackTrace();
147 147
		} catch (IOException e) {
148
			// TODO Auto-generated catch block
148
			showAlert("Error", "Could not load accounts.");
149 149
			e.printStackTrace();
150 150
		} catch (ClassNotFoundException e) {
151
			// TODO Auto-generated catch block
151
			showAlert("Error", "Could not load accounts.");
152 152
			e.printStackTrace();
153 153
		}
154 154
		return null;
......
233 233
			sublabel.setText(getAccountServer(accounts.get(position)));
234 234
			
235 235
			ImageView icon = (ImageView) row.findViewById(R.id.account_type_icon);
236
			icon.setImageResource(R.drawable.rackspace60);
236
			icon.setImageResource(setAccountIcon(accounts.get(position)));
237 237
			
238 238
			return row;
239 239
		}
......
241 241
	
242 242
	public String getAccountServer(Account account){
243 243
		String authServer = account.getAuthServer();
244
		String result = "Rackspace Cloud";
245
		if(authServer.contains("lon")){
246
			result += " (UK)";
244
		String result;
245
		if(authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER)){
246
			result = "Rackspace Cloud (UK)";
247
		}
248
		else if(authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER)){
249
			result = "Rackspace Cloud (US)";
247 250
		}
248 251
		else{
249
			result += " (US)";
252
			result = "Custom";
253
			//setCustomIcon();
250 254
		}
251 255
		return result;
252 256
	}
257
	
258
	//display rackspace logo for cloud accounts and openstack logo for others
259
	private int setAccountIcon(Account account){
260
		if(account.getAuthServer().equals(Preferences.COUNTRY_UK_AUTH_SERVER) 
261
				|| account.getAuthServer().equals(Preferences.COUNTRY_US_AUTH_SERVER)){
262
			return R.drawable.rackspacecloud_icon;
263
		}
264
		else{
265
			return R.drawable.openstack_icon;
266
		}
267
	}
253 268

  
254 269
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
255 270
		super.onActivityResult(requestCode, resultCode, data);
......
260 275
			acc.setApiKey(b.getString("apiKey"));
261 276
			acc.setUsername(b.getString("username"));
262 277
			acc.setAuthServer(b.getString("server"));
278
			Log.d("captin captin!", acc.getAuthServer());
263 279
			accounts.add(acc);
264 280
			writeAccounts();
265 281
			loadAccounts();
b/src/com/rackspacecloud/android/PasswordServerActivity.java
17 17

  
18 18
import android.app.Activity;
19 19
import android.app.AlertDialog;
20
import android.content.Context;
20 21
import android.content.DialogInterface;
21 22
import android.os.AsyncTask;
22 23
import android.os.Bundle;
......
56 57
			new PasswordServerTask().execute((Void[]) null);	
57 58
		}
58 59
		else{
59
			String mustMatch = "The password and confirmation do not match.";
60
			Toast passwordError = Toast.makeText(getApplicationContext(), mustMatch, Toast.LENGTH_SHORT);
61
			passwordError.show();
60
			showToast("The password and confirmation do not match");
62 61
		}
63 62
	}
64 63
	
......
72 71
			} }); 
73 72
		alert.show();
74 73
	}
74
	
75
	private void showToast(String message) {
76
		Context context = getApplicationContext();
77
		int duration = Toast.LENGTH_SHORT;
78
		Toast toast = Toast.makeText(context, message, duration);
79
		toast.show();
80
    }
75 81

  
76 82
	private CloudServersException parseCloudServersException(HttpResponse response) {
77 83
		CloudServersException cse = new CloudServersException();
......
107 113

  
108 114
		private CloudServersException exception;
109 115

  
116
		protected void onPreExecute(){
117
			showToast("Change root password process has begun");
118
		}
119
		
110 120
		@Override
111 121
		protected HttpResponse doInBackground(Void... arg0) {
112 122
			HttpResponse resp = null;
/dev/null
1
package com.rackspacecloud.android;
2

  
3
import java.util.ArrayList;
4
import java.util.TreeMap;
5

  
6
import android.app.Activity;
7
import android.app.AlertDialog;
8
import android.content.Context;
9
import android.content.DialogInterface;
10
import android.content.Intent;
11
import android.content.SharedPreferences;
12
import android.content.SharedPreferences.Editor;
13
import android.os.AsyncTask;
14
import android.os.Bundle;
15
import android.text.method.PasswordTransformationMethod;
16
import android.text.method.SingleLineTransformationMethod;
17
import android.util.Log;
18
import android.view.KeyEvent;
19
import android.view.Menu;
20
import android.view.MenuItem;
21
import android.view.View;
22
import android.view.View.OnClickListener;
23
import android.widget.Button;
24
import android.widget.CheckBox;
25
import android.widget.EditText;
26
import android.widget.ProgressBar;
27
import android.widget.TextView;
28
import android.widget.TextView.OnEditorActionListener;
29

  
30
import com.rackspace.cloud.servers.api.client.Account;
31
import com.rackspace.cloud.servers.api.client.Flavor;
32
import com.rackspace.cloud.servers.api.client.FlavorManager;
33
import com.rackspace.cloud.servers.api.client.Image;
34
import com.rackspace.cloud.servers.api.client.ImageManager;
35
import com.rackspace.cloud.servers.api.client.http.Authentication;
36

  
37

  
38
public class RackspaceCloudActivity{ //extends Activity implements View.OnClickListener, OnEditorActionListener {
39
	
40
	private static final String OPT_USERNAME = "username";
41
	private static final String OPT_USERNAME_DEF = "";
42
	private static final String OPT_API_KEY = "apiKey";
43
	private static final String OPT_API_KEY_DEF = "";
44

  
45
	private static final int SHOW_PREFERENCES = 1;
46

  
47
	private Intent tabViewIntent;
48
	private boolean authenticating;
49
	private Context context;
50
	private boolean showApi;
51

  
52
    /** Called when the activity is first created. */
53
	/*
54
    @Override
55
    public void onCreate(Bundle savedInstanceState) {
56
        super.onCreate(savedInstanceState);
57
        
58
        //use different layouts for different orientation
59
        int orientation = getWindowManager().getDefaultDisplay().getOrientation();
60
        if(orientation == 0){
61
        	setContentView(R.layout.main);
62
        }
63
        if(orientation == 1){
64
        	setContentView(R.layout.mainhoriz);
65
        }
66
        
67
        final CheckBox show_clear = (CheckBox) findViewById(R.id.show_clear);
68
        final EditText loginApiKey = (EditText) findViewById(R.id.login_apikey);
69
        
70
        context = getApplicationContext();
71
        
72
        show_clear.setOnClickListener(new OnClickListener() {
73
        	@Override 
74
			public void onClick(View v) {
75
		        if (((CheckBox) v).isChecked()) {
76
		        	loginApiKey.setTransformationMethod(new SingleLineTransformationMethod());
77
		        	showApi = true;
78
		        } else {    	
79
		        	loginApiKey.setTransformationMethod(new PasswordTransformationMethod());	
80
		        	showApi = false;
81
		        }
82
		        loginApiKey.requestFocus();
83
		    }	
84
		});
85

  
86
        ((Button) findViewById(R.id.button)).setOnClickListener(this);
87
        
88
		loginApiKey.setOnEditorActionListener(this);
89
        loadLoginPreferences();
90
        restoreState(savedInstanceState);
91
        // use the TabViewActivity when Cloud Files is added
92
        // tabViewIntent = new Intent(this, TabViewActivity.class);
93
        
94
        tabViewIntent = new Intent(this, TabViewActivity.class);
95
    }
96

  
97
	@Override
98
	protected void onSaveInstanceState(Bundle outState) {
99
		super.onSaveInstanceState(outState);
100
		outState.putBoolean("authenticating", authenticating);
101
		Log.d("storing apikey", Boolean.toString(showApi));
102
		outState.putBoolean("showApiKey", showApi);
103
	}
104

  
105
    private void restoreState(Bundle state) {
106
		if (state != null && state.containsKey("authenticating") && state.getBoolean("authenticating")) {
107
			showActivityIndicators();
108
		} else {
109
			hideActivityIndicators();
110
		}
111
	
112
		if (state != null && state.containsKey("showApiKey") && state.getBoolean("showApiKey")) {
113
			((EditText) findViewById(R.id.login_apikey)).setTransformationMethod(new SingleLineTransformationMethod());
114
	    } else {    
115
	    	((EditText) findViewById(R.id.login_apikey)).setTransformationMethod(new PasswordTransformationMethod());	
116
	    }
117
		
118
	}
119

  
120
	public boolean onCreateOptionsMenu(Menu menu) {
121
    	MenuItem settings = menu.add(0, SHOW_PREFERENCES, 0, R.string.preference_name);
122
    	settings.setIcon(android.R.drawable.ic_menu_preferences);
123
        return true;
124
    }
125
	
126
    public boolean onOptionsItemSelected(MenuItem item) {
127
        
128
    	switch (item.getItemId()) {
129
    		case SHOW_PREFERENCES:
130
    			showPreferences();
131
    			break;
132
			}	
133
    	return true;
134
    }
135

  
136
    public void showPreferences() {
137
        Intent settingsActivity = new Intent(getBaseContext(),
138
                Preferences.class);
139
        startActivity(settingsActivity);
140
    }
141
    
142
    public void login() {
143
    	if (hasValidInput()) {
144
        	showActivityIndicators();
145
        	setLoginPreferences();
146
        	new AuthenticateTask().execute((Void[]) null);
147
    	} else {
148
    		showAlert("Fields Missing", "User Name and API Key are required.");
149
    	}
150
    }
151
    
152
    public void onClick(View view) {
153
    	login();
154
    }
155
    
156
	public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
157
		login();
158
		return false;
159
	}    
160

  
161
	private void loadLoginPreferences() {
162
    	SharedPreferences sp = this.getPreferences(Context.MODE_PRIVATE);
163
    	String username = sp.getString(OPT_USERNAME, OPT_USERNAME_DEF);    	
164
    	String apiKey = sp.getString(OPT_API_KEY, OPT_API_KEY_DEF);
165
    	EditText usernameText = (EditText) findViewById(R.id.login_username);
166
    	usernameText.setText(username);
167
    	EditText apiKeyText = (EditText) findViewById(R.id.login_apikey);
168
    	apiKeyText.setText(apiKey);
169
    }
170
    
171
    private void setLoginPreferences() {
172
        SharedPreferences prefs = getSharedPreferences(
173
                Preferences.SHARED_PREFERENCES_NAME,
174
                Context.MODE_PRIVATE);
175
        String resultType = prefs.getString(
176
                Preferences.PREF_KEY_RESULTS_TYPE,
177
                String.valueOf(Preferences.COUNTRY_US));
178
        int resultTypeInt = Integer.parseInt(resultType);
179
        
180
        
181
        //Default Auth Server
182
        String authServer = Preferences.COUNTRY_US_AUTH_SERVER; 
183
        if (resultTypeInt == Preferences.COUNTRY_UK)
184
        	authServer = Preferences.COUNTRY_UK_AUTH_SERVER;
185
        
186
        String customAuthServer = prefs.getString(Preferences.PREF_KEY_AUTH_SERVER, "http://");
187
        if (!customAuthServer.equals("http://"))
188
        	authServer = customAuthServer;
189
        
190
        Log.d("RackSpace-Cloud", "Using AuthServer: " + authServer);
191
        
192
    	String username = ((EditText) findViewById(R.id.login_username)).getText().toString();
193
    	String apiKey = ((EditText) findViewById(R.id.login_apikey)).getText().toString();
194
    	Account.setUsername(username);
195
    	Account.setApiKey(apiKey);
196
    	Account.setAuthServer(authServer);
197
    	
198
    	Editor e = this.getPreferences(Context.MODE_PRIVATE).edit();
199
    	e.putString(OPT_USERNAME, username);
200
    	e.putString(OPT_API_KEY, apiKey);
201
    	e.commit();        	
202
    }
203
    
204
    private void showAlert(String title, String message) {
205
		AlertDialog alert = new AlertDialog.Builder(this).create();
206
		alert.setTitle(title);
207
		alert.setMessage(message);
208
		alert.setButton("OK", new DialogInterface.OnClickListener() {
209
	      public void onClick(DialogInterface dialog, int which) {
210
	        return;
211
	    } }); 
212
		alert.show();
213
		hideActivityIndicators();
214
    }
215
    
216
    private boolean hasValidInput() {
217
    	String username = ((EditText) findViewById(R.id.login_username)).getText().toString();
218
    	String apiKey = ((EditText) findViewById(R.id.login_apikey)).getText().toString();
219
    	return !"".equals(username) && !"".equals(apiKey);
220
    }
221

  
222
    private void setActivityIndicatorsVisibility(int visibility) {
223
        ProgressBar pb = (ProgressBar) findViewById(R.id.login_progress_bar);
224
    	TextView tv = (TextView) findViewById(R.id.login_authenticating_label);
225
        pb.setVisibility(visibility);
226
        tv.setVisibility(visibility);
227
    }
228

  
229
    private void showActivityIndicators() {
230
    	setActivityIndicatorsVisibility(View.VISIBLE);
231
    }
232
    
233
    private void hideActivityIndicators() {
234
    	setActivityIndicatorsVisibility(View.INVISIBLE);
235
    }
236
    
237
    private class AuthenticateTask extends AsyncTask<Void, Void, Boolean> {
238
    	
239
		@Override
240
		protected Boolean doInBackground(Void... arg0) {
241
			authenticating = true;
242
<<<<<<< HEAD
243
			return new Boolean(Authentication.authenticate(context));
244
=======
245
			//return new Boolean(Authentication.authenticate());
246
			return true;
247
>>>>>>> refs/heads/mutipleAccounts
248
		}
249
    	
250
		@Override
251
		protected void onPostExecute(Boolean result) {
252
			authenticating = false;
253
			if (result.booleanValue()) {
254
				//startActivity(tabViewIntent);
255
	        	new LoadImagesTask().execute((Void[]) null);				
256
			} else {
257
				showAlert("Login Failure", "Authentication failed.  Please check your User Name and API Key.");
258
			}
259
		}
260
    }
261

  
262
    private class LoadFlavorsTask extends AsyncTask<Void, Void, ArrayList<Flavor>> {
263
    	
264
		@Override
265
		protected ArrayList<Flavor> doInBackground(Void... arg0) {
266
<<<<<<< HEAD
267
			return (new FlavorManager()).createList(true, context);
268
=======
269
			//return (new FlavorManager()).createList(true);
270
			return new ArrayList<Flavor>();
271
>>>>>>> refs/heads/mutipleAccounts
272
		}
273
    	
274
		@Override
275
		protected void onPostExecute(ArrayList<Flavor> result) {
276
			if (result != null && result.size() > 0) {
277
				TreeMap<String, Flavor> flavorMap = new TreeMap<String, Flavor>();
278
				for (int i = 0; i < result.size(); i++) {
279
					Flavor flavor = result.get(i);
280
					flavorMap.put(flavor.getId(), flavor);
281
				}
282
				Flavor.setFlavors(flavorMap);
283
				startActivity(tabViewIntent);
284
			} else {
285
				showAlert("Login Failure", "There was a problem loading server flavors.  Please try again.");
286
			}
287
			hideActivityIndicators();
288
		}
289
    }
290

  
291
    private class LoadImagesTask extends AsyncTask<Void, Void, ArrayList<Image>> {
292
    	
293
		@Override
294
		protected ArrayList<Image> doInBackground(Void... arg0) {
295
			return (new ImageManager()).createList(true, context);
296
		}
297
    	
298
		@Override
299
		protected void onPostExecute(ArrayList<Image> result) {
300
			if (result != null && result.size() > 0) {
301
				TreeMap<String, Image> imageMap = new TreeMap<String, Image>();
302
				for (int i = 0; i < result.size(); i++) {
303
					Image image = result.get(i);
304
					imageMap.put(image.getId(), image);
305
				}
306
				Image.setImages(imageMap);
307
				new LoadFlavorsTask().execute((Void[]) null);
308
				//startActivity(tabViewIntent);
309
			} else {
310
				showAlert("Login Failure", "There was a problem loading server images.  Please try again.");
311
			}
312
			//hideActivityIndicators();
313
		}
314
    }
315
<<<<<<< HEAD
316

  
317
}
318
=======
319
*/
320
}
321

  
b/src/com/rackspacecloud/android/ViewServerActivity.java
5 5

  
6 6
import java.io.IOException;
7 7
import java.io.StringReader;
8
import java.util.Arrays;
8 9
import java.util.Iterator;
9 10

  
10 11
import javax.xml.parsers.FactoryConfigurationError;
......
36 37
import android.widget.ImageView;
37 38
import android.widget.LinearLayout;
38 39
import android.widget.TextView;
40
import android.widget.Toast;
39 41

  
40 42
import com.rackspace.cloud.servers.api.client.CloudServersException;
41 43
import com.rackspace.cloud.servers.api.client.Flavor;
......
152 154
	        	tv.setText(privateIps[i]);
153 155
	        	layout.addView(tv, layoutIndex++);
154 156
	    	}
155

  
156
	    	loadImage();
157 157
	    	ipAddressesLoaded = true;
158 158
    	}
159 159
    	
160
    	Log.d("server refesh", "serer was refereshed");
160
    	loadImage();
161 161
    }
162 162
    
163 163
    private void loadFlavors() {
......
187 187
			imageNames[i] = image.getName(); 
188 188
			i++;
189 189
		}
190
		//sort arrays so they display nicely in the spinner
191
		Arrays.sort(images);
192
		Arrays.sort(imageNames);
190 193
		selectedImageId = images[0].getId();
191 194
		
192 195
    }
......
272 275
	    } }); 
273 276
		alert.show();
274 277
    }
278
    
279
    private void showToast(String message) {
280
		Context context = getApplicationContext();
281
		int duration = Toast.LENGTH_SHORT;
282
		Toast toast = Toast.makeText(context, message, duration);
283
		toast.show();
284
    }
275 285
	
276 286
    /**
277 287
	 * @return the server
......
467 477
		private CloudServersException exception;
468 478
		
469 479
		@Override
480
		//let user know their process has started
481
		protected void onPreExecute(){
482
			showToast("Reboot process has begun");
483
		}
484
		
485
		@Override
470 486
		protected HttpResponse doInBackground(Void... arg0) {
471 487
			HttpResponse resp = null;
472 488
			try {
......
481 497
		protected void onPostExecute(HttpResponse response) {
482 498

  
483 499
			if (response != null) {
484
				int statusCode = response.getStatusLine().getStatusCode();				
500
				int statusCode = response.getStatusLine().getStatusCode();	
501
				if(statusCode == 202){ showToast("Reboot successful"); }
485 502
				if (statusCode != 202) {
486 503
					CloudServersException cse = parseCloudServersException(response);
487 504
					if ("".equals(cse.getMessage())) {
......
500 517
	private class HardRebootServerTask extends AsyncTask<Void, Void, HttpResponse> {
501 518
    	
502 519
		private CloudServersException exception;
520
		
521
		@Override
522
		//let user know their process has started
523
		protected void onPreExecute(){
524
			showToast("Reboot process has begun");
525
		}
503 526

  
504 527
		@Override
505 528
		protected HttpResponse doInBackground(Void... arg0) {
......
515 538
		@Override
516 539
		protected void onPostExecute(HttpResponse response) {
517 540
			if (response != null) {
518
				int statusCode = response.getStatusLine().getStatusCode();			
541
				int statusCode = response.getStatusLine().getStatusCode();	
542
				if(statusCode == 202){ showToast("Reboot successful"); }
519 543
				if (statusCode != 202) {
520 544
					CloudServersException cse = parseCloudServersException(response);
521 545
					if ("".equals(cse.getMessage())) {
......
551 575
			if (response != null) {
552 576
				int statusCode = response.getStatusLine().getStatusCode();			
553 577
				if (statusCode == 202) {
578
					showToast("Resize process has begun, please confirm your resize after process finishes.");
554 579
					new PollServerTask().execute((Void[]) null);
555 580
				} else {					
556 581
					CloudServersException cse = parseCloudServersException(response);
557 582
					if ("".equals(cse.getMessage())) {
558
						showAlert("Error", "There was a problem deleting your server.");
583
						showAlert("Error", "There was a problem resizing your server.");
559 584
					} else {
560
						showAlert("Error", "There was a problem deleting your server: " + cse.getMessage());
585
						showAlert("Error", "There was a problem resizing your server: " + cse.getMessage());
561 586
					}					
562 587
				}
563 588
			} else if (exception != null) {
......
568 593
		}
569 594
    }
570 595
	
596
	
571 597
	public class DeleteServerTask extends AsyncTask<Void, Void, HttpResponse> {
572 598
    	
573 599
		private CloudServersException exception;
574

  
600
		
601
		@Override
602
		//let user know their process has started
603
		protected void onPreExecute(){
604
			showToast("Delete process has begun");
605
		}
575 606
		@Override
576 607
		protected HttpResponse doInBackground(Void... arg0) {
577 608
			HttpResponse resp = null;
......
588 619
			if (response != null) {
589 620
				int statusCode = response.getStatusLine().getStatusCode();
590 621
				if (statusCode == 202) {
622
					showToast("Delete successful");
591 623
					setResult(Activity.RESULT_OK);
592 624
					finish();
593 625
				} else {
......
609 641
		private CloudServersException exception;
610 642
		
611 643
		@Override
644
		//let user know their process has started
645
		protected void onPreExecute(){
646
			showToast("Rename process has begun");
647
		}
648
		
649
		@Override
612 650
		protected HttpResponse doInBackground(Void... arg0) {
613 651
			HttpResponse resp = null;
614 652
			try {
......
622 660
		@Override
623 661
		protected void onPostExecute(HttpResponse response) {
624 662
			if (response != null) {
625
				int statusCode = response.getStatusLine().getStatusCode();			
663
				int statusCode = response.getStatusLine().getStatusCode();	
626 664
				if (statusCode == 204) {	
665
					showToast("Rename successful");
627 666
					new PollServerTask().execute((Void[]) null);
628 667
				} else {
629 668
					CloudServersException cse = parseCloudServersException(response);
......
635 674
				}
636 675
			}
637 676
		    else if (exception != null) {
638
		    	showAlert("Error", "There was a problem rebooting your server: " + exception.getMessage());	
677
		    	showAlert("Error", "There was a problem renaming your server: " + exception.getMessage());	
639 678
		    }
640 679
		}
641 680
		
......
644 683
	private class RebuildServerTask extends AsyncTask<Void, Void, HttpResponse> {
645 684
    	
646 685
		private CloudServersException exception;
647

  
686
		
648 687
		@Override
649 688
		protected HttpResponse doInBackground(Void... arg0) {
650 689
			HttpResponse resp = null;
......
661 700
			if (response != null) {
662 701
				int statusCode = response.getStatusLine().getStatusCode();			
663 702
				if (statusCode == 202) {
703
					showToast("Rebuild process has begun");
664 704
					new PollServerTask().execute((Void[]) null);
665 705
				} else {					
666 706
					CloudServersException cse = parseCloudServersException(response);
667 707
					if ("".equals(cse.getMessage())) {
668
						showAlert("Error", "There was a problem deleting your server.");
708
						showAlert("Error", "There was a problem rebuilding your server.");
669 709
					} else {
670
						showAlert("Error", "There was a problem deleting your server: " + cse.getMessage());
710
						showAlert("Error", "There was a problem rebuilding your server: " + cse.getMessage());
671 711
					}					
672 712
				}
673 713
			} else if (exception != null) {
674
				showAlert("Error", "There was a problem resizing your server: " + exception.getMessage());
714
				showAlert("Error", "There was a problem rebuilding your server: " + exception.getMessage());
675 715
				
676 716
			}
677 717
			

Also available in: Unified diff