Revision 378fe36a src/com/rackspace/cloud/android/AddAccountActivity.java
b/src/com/rackspace/cloud/android/AddAccountActivity.java | ||
---|---|---|
4 | 4 |
import android.os.Bundle; |
5 | 5 |
import android.text.method.PasswordTransformationMethod; |
6 | 6 |
import android.text.method.SingleLineTransformationMethod; |
7 |
import android.util.Log; |
|
7 | 8 |
import android.view.View; |
8 | 9 |
import android.view.View.OnClickListener; |
9 | 10 |
import android.widget.AdapterView; |
... | ... | |
13 | 14 |
import android.widget.EditText; |
14 | 15 |
import android.widget.Spinner; |
15 | 16 |
|
16 |
import com.rackspace.cloud.android.R;
|
|
17 |
import com.rackspace.cloud.servers.api.client.Account;
|
|
17 | 18 |
|
18 |
public class AddAccountActivity extends CloudActivity implements OnClickListener{ |
|
19 |
|
|
20 |
private final String[] PROVIDERS = {"Rackspace Cloud (US)", "Rackspace Cloud (UK)","Pithos +", "Pithos+ Staging", "Pithos+ Dev","Custom"}; |
|
19 |
public class AddAccountActivity extends CloudActivity implements |
|
20 |
OnClickListener { |
|
21 |
|
|
22 |
private final String[] PROVIDERS = { "Pithos +", "Pithos+ Staging", |
|
23 |
"Pithos+ Dev", "Rackspace Cloud (US)", "Rackspace Cloud (UK)", |
|
24 |
"Custom" }; |
|
21 | 25 |
private EditText usernameText; |
22 | 26 |
private EditText passwordText; |
23 | 27 |
private EditText customServer; |
24 | 28 |
private Spinner providerSpinner; |
25 | 29 |
private String authServer; |
26 | 30 |
boolean isHidden; |
27 |
|
|
31 |
private Button loginButton; |
|
32 |
private Account accountFromLogin = null; |
|
33 |
|
|
28 | 34 |
public void onCreate(Bundle savedInstanceState) { |
29 |
super.onCreate(savedInstanceState); |
|
30 |
trackPageView(GoogleAnalytics.PAGE_PROVIDERS); |
|
31 |
setContentView(R.layout.createaccount); |
|
32 |
usernameText = (EditText) findViewById(R.id.username); |
|
33 |
passwordText = (EditText) findViewById(R.id.addaccount_apikey); |
|
34 |
customServer = (EditText) findViewById(R.id.custom_auth_server_edit); |
|
35 |
((Button) findViewById(R.id.submit_new_account)).setOnClickListener(this); |
|
36 |
isHidden = true; |
|
37 |
customServer.setEnabled(false); |
|
38 |
if(savedInstanceState != null) |
|
39 |
isHidden = savedInstanceState.containsKey("isHidden") && savedInstanceState.getBoolean("isHidden"); |
|
40 |
setUpApiText(savedInstanceState); |
|
41 |
setUpCheckBox(); |
|
42 |
loadProviderSpinner(); |
|
43 |
} |
|
44 |
|
|
35 |
super.onCreate(savedInstanceState); |
|
36 |
trackPageView(GoogleAnalytics.PAGE_PROVIDERS); |
|
37 |
setContentView(R.layout.createaccount); |
|
38 |
|
|
39 |
usernameText = (EditText) findViewById(R.id.username); |
|
40 |
passwordText = (EditText) findViewById(R.id.addaccount_apikey); |
|
41 |
customServer = (EditText) findViewById(R.id.custom_auth_server_edit); |
|
42 |
((Button) findViewById(R.id.submit_new_account)) |
|
43 |
.setOnClickListener(this); |
|
44 |
loginButton = ((Button) findViewById(R.id.login_account)); |
|
45 |
loginButton.setOnClickListener(new OnClickListener() { |
|
46 |
|
|
47 |
@Override |
|
48 |
public void onClick(View v) { |
|
49 |
startLoginProcess(); |
|
50 |
|
|
51 |
} |
|
52 |
}); |
|
53 |
isHidden = true; |
|
54 |
customServer.setEnabled(false); |
|
55 |
if (savedInstanceState != null) |
|
56 |
isHidden = savedInstanceState.containsKey("isHidden") |
|
57 |
&& savedInstanceState.getBoolean("isHidden"); |
|
58 |
setUpApiText(savedInstanceState); |
|
59 |
setUpCheckBox(); |
|
60 |
loadProviderSpinner(); |
|
61 |
if (getIntent().getExtras() != null) { |
|
62 |
String u = getIntent().getExtras().getString("account_displayname"); |
|
63 |
if (u != null) { |
|
64 |
usernameText.setText(u); |
|
65 |
String t = getIntent().getExtras().getString("account_token"); |
|
66 |
passwordText.setText(t); |
|
67 |
String a = getIntent().getExtras().getString("account_auth"); |
|
68 |
if (a.equals(Preferences.PITHOS_DEV_SERVER)) { |
|
69 |
providerSpinner.setSelection(2); |
|
70 |
} else if (a.equals(Preferences.PITHOS_STAGING_SERVER)) { |
|
71 |
providerSpinner.setSelection(1); |
|
72 |
} else if (a.equals(Preferences.PITHOS_SERVER)) { |
|
73 |
providerSpinner.setSelection(0); |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
45 | 79 |
protected void onSaveInstanceState(Bundle outState) { |
46 | 80 |
super.onSaveInstanceState(outState); |
47 | 81 |
outState.putBoolean("isHidden", isHidden); |
48 | 82 |
} |
49 |
|
|
50 |
//setup the API textedit to be password dots or regular text |
|
51 |
private void setUpApiText(Bundle state){ |
|
52 |
isHidden = true; |
|
53 |
if(state != null) |
|
54 |
isHidden = state.containsKey("isHidden") && state.getBoolean("isHidden"); |
|
55 |
if(isHidden){ |
|
56 |
passwordText.setTransformationMethod(new PasswordTransformationMethod()); |
|
57 |
} |
|
58 |
else{ |
|
59 |
passwordText.setTransformationMethod(new SingleLineTransformationMethod()); |
|
83 |
|
|
84 |
// setup the API textedit to be password dots or regular text |
|
85 |
private void setUpApiText(Bundle state) { |
|
86 |
isHidden = true; |
|
87 |
if (state != null) |
|
88 |
isHidden = state.containsKey("isHidden") |
|
89 |
&& state.getBoolean("isHidden"); |
|
90 |
if (isHidden) { |
|
91 |
passwordText |
|
92 |
.setTransformationMethod(new PasswordTransformationMethod()); |
|
93 |
} else { |
|
94 |
passwordText |
|
95 |
.setTransformationMethod(new SingleLineTransformationMethod()); |
|
60 | 96 |
} |
61 | 97 |
} |
62 |
|
|
63 |
private void setUpCheckBox(){ |
|
98 |
|
|
99 |
private void setUpCheckBox() {
|
|
64 | 100 |
final CheckBox show_clear = (CheckBox) findViewById(R.id.show_clear); |
65 | 101 |
show_clear.setChecked(!isHidden); |
66 |
show_clear.setOnClickListener(new OnClickListener() {
|
|
67 |
@Override
|
|
102 |
show_clear.setOnClickListener(new OnClickListener() {
|
|
103 |
@Override
|
|
68 | 104 |
public void onClick(View v) { |
69 |
if (((CheckBox) v).isChecked()) { |
|
70 |
passwordText.setTransformationMethod(new SingleLineTransformationMethod()); |
|
71 |
isHidden = false; |
|
72 |
} else { |
|
73 |
passwordText.setTransformationMethod(new PasswordTransformationMethod()); |
|
74 |
isHidden = true; |
|
75 |
} |
|
76 |
passwordText.requestFocus(); |
|
77 |
} |
|
105 |
if (((CheckBox) v).isChecked()) { |
|
106 |
passwordText |
|
107 |
.setTransformationMethod(new SingleLineTransformationMethod()); |
|
108 |
isHidden = false; |
|
109 |
} else { |
|
110 |
passwordText |
|
111 |
.setTransformationMethod(new PasswordTransformationMethod()); |
|
112 |
isHidden = true; |
|
113 |
} |
|
114 |
passwordText.requestFocus(); |
|
115 |
} |
|
78 | 116 |
}); |
79 | 117 |
} |
80 |
|
|
81 |
private void loadProviderSpinner(){ |
|
82 |
//set the auth server default to us |
|
118 |
|
|
119 |
private void loadProviderSpinner() {
|
|
120 |
// set the auth server default to us
|
|
83 | 121 |
authServer = "https://auth.api.rackspacecloud.com/v2.0"; |
84 | 122 |
providerSpinner = (Spinner) findViewById(R.id.provider_spinner); |
85 |
ArrayAdapter<String> imageAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, PROVIDERS); |
|
86 |
imageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
123 |
ArrayAdapter<String> imageAdapter = new ArrayAdapter<String>(this, |
|
124 |
android.R.layout.simple_spinner_item, PROVIDERS); |
|
125 |
imageAdapter |
|
126 |
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
87 | 127 |
providerSpinner.setAdapter(imageAdapter); |
88 |
providerSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
|
|
89 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
|
90 |
if(pos == 0){
|
|
91 |
authServer = Preferences.COUNTRY_US_AUTH_SERVER_V2;
|
|
92 |
customServer.setEnabled(false);
|
|
93 |
}
|
|
94 |
else if(pos == 1){
|
|
95 |
authServer = Preferences.COUNTRY_UK_AUTH_SERVER_V2;
|
|
96 |
customServer.setEnabled(false);
|
|
97 |
}
|
|
98 |
else if(pos == 2){
|
|
99 |
authServer = Preferences.PITHOS_SERVER;
|
|
100 |
customServer.setEnabled(false);
|
|
101 |
}
|
|
102 |
else if(pos == 3){
|
|
103 |
authServer = Preferences.PITHOS_STAGING_SERVER;
|
|
104 |
customServer.setEnabled(false);
|
|
105 |
}
|
|
106 |
else if(pos == 4){
|
|
107 |
authServer = Preferences.PITHOS_DEV_SERVER;
|
|
108 |
customServer.setEnabled(false); |
|
109 |
}
|
|
110 |
else{
|
|
111 |
customServer.setEnabled(true);
|
|
112 |
} |
|
113 |
} |
|
114 |
public void onNothingSelected(AdapterView<?> parent) {
|
|
115 |
}
|
|
116 |
}); |
|
128 |
providerSpinner |
|
129 |
.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
130 |
public void onItemSelected(AdapterView<?> parent,
|
|
131 |
View view, int pos, long id) {
|
|
132 |
if (pos == 0) {
|
|
133 |
authServer = Preferences.PITHOS_SERVER;
|
|
134 |
customServer.setEnabled(false);
|
|
135 |
} else if (pos == 1) {
|
|
136 |
authServer = Preferences.PITHOS_STAGING_SERVER;
|
|
137 |
customServer.setEnabled(false);
|
|
138 |
} else if (pos == 2) {
|
|
139 |
authServer = Preferences.PITHOS_DEV_SERVER;
|
|
140 |
customServer.setEnabled(false);
|
|
141 |
} else if (pos == 3) {
|
|
142 |
authServer = Preferences.COUNTRY_US_AUTH_SERVER_V2;
|
|
143 |
customServer.setEnabled(false);
|
|
144 |
} else if (pos == 4) {
|
|
145 |
authServer = Preferences.COUNTRY_UK_AUTH_SERVER_V2;
|
|
146 |
customServer.setEnabled(false);
|
|
147 |
}
|
|
148 |
|
|
149 |
else {
|
|
150 |
customServer.setEnabled(true);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
public void onNothingSelected(AdapterView<?> parent) {
|
|
155 |
}
|
|
156 |
});
|
|
117 | 157 |
} |
118 |
|
|
119 |
public void onClick(View arg0) { |
|
120 | 158 |
|
159 |
public void onClick(View arg0) { |
|
160 |
// check |
|
121 | 161 |
if (hasValidInput()) { |
122 |
//showActivityIndicators(); |
|
123 |
Intent result = new Intent(); |
|
124 |
Bundle b = new Bundle(); |
|
125 |
b.putString("username", usernameText.getText().toString()); |
|
126 |
b.putString("apiKey", passwordText.getText().toString()); |
|
127 |
b.putString("server", getAuthServer()); |
|
128 |
result.putExtra("accountInfo", b); |
|
129 |
setResult(RESULT_OK, result); |
|
130 |
finish(); |
|
162 |
// showActivityIndicators(); |
|
163 |
Account acc = new Account(); |
|
164 |
acc.setPassword(passwordText.getText().toString()); |
|
165 |
acc.setAuthServer(getAuthServer()); |
|
166 |
acc.setDisplayName(usernameText.getText().toString()); |
|
167 |
Account.setAccount(acc); |
|
168 |
acc.setUsername(Account.getUUIDForDisplayName(acc.getDisplayName(), |
|
169 |
AddAccountActivity.this)); |
|
170 |
if (acc.getUsername() == null) { |
|
171 |
showAlert("Username Not Found", |
|
172 |
"The Username was not found or the API Key is invalid."); |
|
173 |
} else { |
|
174 |
Intent result = new Intent(); |
|
175 |
Bundle b = new Bundle(); |
|
176 |
if (accountFromLogin != null) { |
|
177 |
b.putString("username", accountFromLogin.getUsername()); |
|
178 |
} |
|
179 |
b.putString("displayname", usernameText.getText().toString()); |
|
180 |
b.putString("apiKey", passwordText.getText().toString()); |
|
181 |
b.putString("server", getAuthServer()); |
|
182 |
|
|
183 |
result.putExtra("accountInfo", b); |
|
184 |
setResult(RESULT_OK, result); |
|
185 |
finish(); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
else { |
|
190 |
|
|
191 |
showAlert("Required Fields Missing", |
|
192 |
"Username and API Key are required."); |
|
193 |
} |
|
194 |
|
|
195 |
} |
|
196 |
|
|
197 |
public void startLoginProcess() { |
|
198 |
// Intent result = new Intent(); |
|
199 |
// Bundle b = new Bundle(); |
|
200 |
// b.putInt("item", providerSpinner.getSelectedItemPosition()); |
|
201 |
// result.putExtra("serverused", b); |
|
202 |
// setResult(RESULT_OK, result); |
|
203 |
// finish(); |
|
204 |
String login; |
|
205 |
String auth; |
|
206 |
int item = providerSpinner.getSelectedItemPosition(); |
|
207 |
Log.d(getClass().getName(), "Item is :" + item); |
|
208 |
if (item == 0) { |
|
209 |
login = Preferences.LOGIN_PITHOS_SERVER; |
|
210 |
auth = Preferences.PITHOS_SERVER; |
|
211 |
} else if (item == 1) { |
|
212 |
login = Preferences.LOGIN_PITHOS_STAGING_SERVER; |
|
213 |
auth = Preferences.PITHOS_STAGING_SERVER; |
|
131 | 214 |
} else { |
132 |
showAlert("Required Fields Missing", "Username and API Key are required."); |
|
215 |
login = Preferences.LOGIN_PITHOS_DEV_SERVER; |
|
216 |
auth = Preferences.PITHOS_DEV_SERVER; |
|
217 |
|
|
133 | 218 |
} |
134 |
|
|
219 |
Intent intent2 = new Intent(AddAccountActivity.this, |
|
220 |
PithosLoginActivity.class); |
|
221 |
// intent2.putExtra("login", |
|
222 |
// "https://pithos.dev.grnet.gr/im/login"); |
|
223 |
// intent2.putExtra("auth", |
|
224 |
// Preferences.PITHOS_DEV_SERVER); |
|
225 |
Log.d("LOGIN_URL", login); |
|
226 |
Log.d("LOGIN_AUTH", auth); |
|
227 |
intent2.putExtra("login", login); |
|
228 |
intent2.putExtra("auth", auth); |
|
229 |
startActivityForResult(intent2, 178); |
|
135 | 230 |
} |
136 |
|
|
137 |
private String getAuthServer(){ |
|
138 |
if(customServer.isEnabled()){
|
|
231 |
|
|
232 |
private String getAuthServer() {
|
|
233 |
if (customServer.isEnabled()) {
|
|
139 | 234 |
authServer = customServer.getText().toString(); |
140 | 235 |
} |
141 | 236 |
return authServer; |
142 | 237 |
} |
143 |
|
|
238 |
|
|
144 | 239 |
private boolean hasValidInput() { |
145 |
String username = usernameText.getText().toString();
|
|
146 |
String apiKey = passwordText.getText().toString();
|
|
147 |
return !"".equals(username) && !"".equals(apiKey);
|
|
148 |
}
|
|
240 |
String username = usernameText.getText().toString();
|
|
241 |
String apiKey = passwordText.getText().toString();
|
|
242 |
return !"".equals(username) && !"".equals(apiKey);
|
|
243 |
}
|
|
149 | 244 |
|
245 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
246 |
super.onActivityResult(requestCode, resultCode, data); |
|
247 |
|
|
248 |
if (resultCode == RESULT_OK && requestCode == 178) { |
|
249 |
|
|
250 |
Account acc = new Account(); |
|
251 |
Bundle b = data.getBundleExtra("accountInfo"); |
|
252 |
acc.setPassword(b.getString("apiKey")); |
|
253 |
acc.setAuthServer(b.getString("server")); |
|
254 |
acc.setUsername(b.getString("username")); |
|
255 |
|
|
256 |
if (b.getString("displayname") != null) { |
|
257 |
acc.setDisplayName(b.getString("displayname")); |
|
258 |
} else { |
|
259 |
Account.setAccount(acc); |
|
260 |
acc.setDisplayName(Account.getDisplayNameForUUID( |
|
261 |
acc.getUsername(), AddAccountActivity.this)); |
|
262 |
} |
|
263 |
this.accountFromLogin = acc; |
|
264 |
this.usernameText.setText(accountFromLogin.getDisplayName()); |
|
265 |
this.passwordText.setText(acc.getPassword()); |
|
266 |
} |
|
267 |
} |
|
150 | 268 |
} |
Also available in: Unified diff