@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    appContext = getApplicationContext();
    setContentView(R.layout.connection_setup_activity);

    hostname = (EditText) findViewById(R.id.hostname);
    vmname = (EditText) findViewById(R.id.vmname);
    user = (EditText) findViewById(R.id.user);
    password = (EditText) findViewById(R.id.password);

    // Define what happens when one taps the Advanced Settings button.
    advancedSettingsButton = (Button) findViewById(R.id.advancedSettingsButton);
    advancedSettingsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View arg0) {
            saveSelectedPreferences(false);

            Intent intent =
                new Intent(ConnectionSetupActivity.this, AdvancedSettingsActivity.class);
            intent.putExtra("com.undatech.opaque.ConnectionSettings", currentConnection);
            startActivityForResult(intent, Constants.ADVANCED_SETTINGS);
          }
        });

    // Define what happens when one taps the Connect button.
    saveButton = (Button) findViewById(R.id.saveButton);
    saveButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View arg0) {
            String u = user.getText().toString();
            String h = hostname.getText().toString();

            // Only if a username and a hostname were entered, save the connection and try to
            // connect.
            if (!(u.equals("") || h.equals(""))) {
              saveSelectedPreferences(true);
              finish();
              // Intent intent = new Intent(ConnectionSetupActivity.this,
              // RemoteCanvasActivity.class);
              // intent.putExtra("com.undatech.opaque.ConnectionSettings", currentConnection);
              // startActivity(intent);
              // Otherwise, let the user know that at least a user and hostname are required.
            } else {
              Toast toast =
                  Toast.makeText(appContext, R.string.error_no_user_hostname, Toast.LENGTH_LONG);
              toast.show();
            }
          }
        });

    // Load any existing list of connection preferences.
    loadConnections();

    Intent i = getIntent();
    currentSelectedConnection = (String) i.getStringExtra("com.undatech.opaque.connectionToEdit");
    android.util.Log.e(TAG, "currentSelectedConnection SET TO: " + currentSelectedConnection);

    // If no currentSelectedConnection was passed in, then generate one.
    if (currentSelectedConnection == null) {
      currentSelectedConnection = nextLargestNumber(connectionsArray);
      newConnection = true;
    }

    currentConnection = new ConnectionSettings(currentSelectedConnection);
    if (newConnection) {
      // Save the empty connection preferences to override any values of a previously
      // deleted connection.
      saveSelectedPreferences(false);
    }

    // Finally, load the preferences for the currentSelectedConnection.
    loadSelectedPreferences();

    // Load list of items from asset folder and populate this:
    List<String> spinnerArray = null;
    try {
      spinnerArray = listFiles("layouts");
    } catch (IOException e) {
      e.printStackTrace();
    }
    layoutMapSpinner = (Spinner) findViewById(R.id.layoutMaps);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerArray);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    layoutMapSpinner.setAdapter(adapter);
    int selection = spinnerArray.indexOf(currentConnection.getLayoutMap());
    if (selection < 0) {
      selection = spinnerArray.indexOf(Constants.DEFAULT_LAYOUT_MAP);
    }
    layoutMapSpinner.setSelection(selection);
  }