Android Open Source - android-rackspacecloud Add Account Activity From Project Back to project page android-rackspacecloud .
License The source code is released under:
MIT License
If you think the Android project android-rackspacecloud listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.rackspacecloud.android;
/ / w w w . j a v a 2 s . c o m
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
public class AddAccountActivity extends GaActivity implements OnClickListener{
EditText usernameText;
EditText apiKeyText;
EditText customServer;
Spinner providerSpinner;
String authServer;
boolean isHidden;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
trackPageView(PAGE_PROVIDERS);
setContentView(R.layout.createaccount);
usernameText = (EditText) findViewById(R.id.username);
apiKeyText = (EditText) findViewById(R.id.addaccount_apikey);
customServer = (EditText) findViewById(R.id.custom_auth_server_edit);
((Button) findViewById(R.id.submit_new_account)).setOnClickListener(this );
isHidden = true;
customServer.setEnabled(false);
if (savedInstanceState != null)
isHidden = savedInstanceState.containsKey("isHidden" ) && savedInstanceState.getBoolean("isHidden" );
setUpApiText(savedInstanceState);
setUpCheckBox();
loadProviderSpinner();
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("isHidden" , isHidden);
}
//setup the API textedit to be password dots or regular text
private void setUpApiText(Bundle state){
isHidden = true;
if (state != null)
isHidden = state.containsKey("isHidden" ) && state.getBoolean("isHidden" );
if (isHidden){
apiKeyText.setTransformationMethod(new PasswordTransformationMethod());
}
else {
apiKeyText.setTransformationMethod(new SingleLineTransformationMethod());
}
}
private void setUpCheckBox(){
final CheckBox show_clear = (CheckBox) findViewById(R.id.show_clear);
show_clear.setChecked(!isHidden);
show_clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
apiKeyText.setTransformationMethod(new SingleLineTransformationMethod());
isHidden = false;
} else {
apiKeyText.setTransformationMethod(new PasswordTransformationMethod());
isHidden = true;
}
apiKeyText.requestFocus();
}
});
}
private void loadProviderSpinner(){
//set the auth server default to us
authServer = "https://auth.api.rackspacecloud.com/v1.0" ;
providerSpinner = (Spinner) findViewById(R.id.provider_spinner);
String[] providers = {"Rackspace Cloud (US)" , "Rackspace Cloud (UK)" , "Custom" };
ArrayAdapter<String> imageAdapter = new ArrayAdapter<String>(this , android.R.layout.simple_spinner_item, providers);
imageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
providerSpinner.setAdapter(imageAdapter);
providerSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (pos == 0){
authServer = Preferences.COUNTRY_US_AUTH_SERVER;
customServer.setEnabled(false);
}
else if (pos == 1){
authServer = Preferences.COUNTRY_UK_AUTH_SERVER;
customServer.setEnabled(false);
}
else {
customServer.setEnabled(true);
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public void onClick(View arg0) {
if (hasValidInput()) {
//showActivityIndicators();
Intent result = new Intent();
Bundle b = new Bundle();
b.putString("username" , usernameText.getText().toString());
b.putString("apiKey" , apiKeyText.getText().toString());
b.putString("server" , getAuthServer());
result.putExtra("accountInfo" , b);
setResult(RESULT_OK, result);
finish();
} else {
showAlert("Required Fields Missing" , "Username and API Key are required." );
}
}
private String getAuthServer(){
if (customServer.isEnabled()){
authServer = customServer.getText().toString();
}
return authServer;
}
private void showAlert(String title, String message) {
try {
AlertDialog alert = new AlertDialog.Builder(this ).create();
alert.setTitle(title);
alert.setMessage(message);
alert.setButton("OK" , new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return ;
} });
alert.show();
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean hasValidInput() {
String username = usernameText.getText().toString();
String apiKey = apiKeyText.getText().toString();
return !"" .equals(username) && !"" .equals(apiKey);
}
}
Java Source Code List com.rackspace.cloud.files.api.client.ContainerManager.java com.rackspace.cloud.files.api.client.ContainerObjectManager.java com.rackspace.cloud.files.api.client.ContainerObjects.java com.rackspace.cloud.files.api.client.Container.java com.rackspace.cloud.files.api.client.CustomHttpClient.java com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser.java com.rackspace.cloud.files.api.client.parsers.ContainerXMLParser.java com.rackspace.cloud.servers.api.client.Account.java com.rackspace.cloud.servers.api.client.Backup.java com.rackspace.cloud.servers.api.client.CloudServersException.java com.rackspace.cloud.servers.api.client.EntityManager.java com.rackspace.cloud.servers.api.client.Entity.java com.rackspace.cloud.servers.api.client.FlavorManager.java com.rackspace.cloud.servers.api.client.Flavor.java com.rackspace.cloud.servers.api.client.ImageManager.java com.rackspace.cloud.servers.api.client.Image.java com.rackspace.cloud.servers.api.client.ServerManager.java com.rackspace.cloud.servers.api.client.Server.java com.rackspace.cloud.servers.api.client.http.Authentication.java com.rackspace.cloud.servers.api.client.http.HttpBundle.java com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser.java com.rackspace.cloud.servers.api.client.parsers.FlavorsXMLParser.java com.rackspace.cloud.servers.api.client.parsers.ImagesXMLParser.java com.rackspace.cloud.servers.api.client.parsers.ServersXMLParser.java com.rackspacecloud.android.AddAccountActivity.java com.rackspacecloud.android.AddContainerActivity.java com.rackspacecloud.android.AddFileActivity.java com.rackspacecloud.android.AddServerActivity.java com.rackspacecloud.android.AndroidCloudApplication.java com.rackspacecloud.android.BackupServerActivity.java com.rackspacecloud.android.Config.java com.rackspacecloud.android.ConfirmResizeActivity.java com.rackspacecloud.android.ContactActivity.java com.rackspacecloud.android.ContainerObjectDetails.java com.rackspacecloud.android.ContainerObjectsActivity.java com.rackspacecloud.android.CreatePasswordActivity.java com.rackspacecloud.android.EnableCDNActivity.java com.rackspacecloud.android.ErrorDetailsActivity.java com.rackspacecloud.android.GaActivity.java com.rackspacecloud.android.GaListActivity.java com.rackspacecloud.android.ListAccountsActivity.java com.rackspacecloud.android.ListContainerActivity.java com.rackspacecloud.android.ListServersActivity.java com.rackspacecloud.android.PasswordManager.java com.rackspacecloud.android.PasswordServerActivity.java com.rackspacecloud.android.PingServerActivity.java com.rackspacecloud.android.Preferences.java com.rackspacecloud.android.ServerErrorActivity.java com.rackspacecloud.android.TabViewActivity.java com.rackspacecloud.android.ViewServerActivity.java net.elasticgrid.rackspace.cloudservers.Addresses.java net.elasticgrid.rackspace.cloudservers.BackupSchedule.java net.elasticgrid.rackspace.cloudservers.CloudServersException.java net.elasticgrid.rackspace.cloudservers.CloudServers.java net.elasticgrid.rackspace.cloudservers.File.java net.elasticgrid.rackspace.cloudservers.Flavor.java net.elasticgrid.rackspace.cloudservers.HTTPVerb.java net.elasticgrid.rackspace.cloudservers.Image.java net.elasticgrid.rackspace.cloudservers.Limits.java net.elasticgrid.rackspace.cloudservers.Personality.java net.elasticgrid.rackspace.cloudservers.RebootType.java net.elasticgrid.rackspace.cloudservers.Server.java net.elasticgrid.rackspace.cloudservers.SharedIPGroup.java net.elasticgrid.rackspace.cloudservers.XMLCloudServers.java net.elasticgrid.rackspace.cloudservers.package-info.java net.elasticgrid.rackspace.common.RackspaceConnection.java net.elasticgrid.rackspace.common.RackspaceException.java net.elasticgrid.rackspace.common.package-info.java org.jclouds.date.joda.JodaDateService.java org.jclouds.date.joda.config.JodaDateServiceModule.java org.jclouds.encryption.bouncycastle.BouncyCastleEncryptionService.java org.jclouds.encryption.bouncycastle.config.BouncyCastleEncryptionServiceModule.java org.jclouds.enterprise.config.EnterpriseConfigurationModule.java org.jclouds.gae.GaeHttpCommandExecutorService.java org.jclouds.gae.config.GoogleAppEngineConfigurationModule.java org.jclouds.http.apachehc.ApacheHCHttpCommandExecutorService.java org.jclouds.http.apachehc.ApacheHCUtils.java org.jclouds.http.apachehc.config.ApacheHCHttpCommandExecutorServiceModule.java org.jclouds.http.httpnio.config.NioTransformingHttpCommandExecutorServiceModule.java org.jclouds.http.httpnio.pool.NioHttpCommandConnectionHandle.java org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPool.java org.jclouds.http.httpnio.pool.NioHttpCommandExecutionHandler.java org.jclouds.http.httpnio.pool.NioTransformingHttpCommandExecutorService.java org.jclouds.http.httpnio.util.NioHttpUtils.java org.jclouds.http.pool.ConnectionPoolTransformingHttpCommandExecutorService.java org.jclouds.http.pool.HttpCommandConnectionHandle.java org.jclouds.http.pool.HttpCommandConnectionPool.java org.jclouds.http.pool.config.ConnectionPoolCommandExecutorServiceModule.java org.jclouds.logging.log4j.Log4JLogger.java org.jclouds.logging.log4j.config.Log4JLoggingModule.java org.jclouds.ssh.jsch.JschSshClient.java org.jclouds.ssh.jsch.config.JschSshClientModule.java