@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_repo); // Check to see if extras were passed to the intent. In that case, edit the repository if (getIntent().getExtras() != null) { Bundle rec_bundle = getIntent().getExtras(); // Get the repository to edit edit_repo = rec_bundle.getLong("editRepo", -1); // If the repository id is valid, set the activity to edit mode if (edit_repo >= 0) { edit_mode = true; this.setTitle(R.string.add_repo_edit_title); } } encrypt_helper = EncryptionHelper.getInstance("DEADBEEF".toCharArray(), new byte[] {'L', 'O', 'L'}); db_helper = DatabaseHelper.getInstance(this); repo_name = (EditText) findViewById(R.id.repo_name); username = (EditText) findViewById(R.id.add_repo_username); password = (EditText) findViewById(R.id.add_repo_password); password.setRawInputType( InputType.TYPE_TEXT_VARIATION_PASSWORD); // Make this into a password box password.setTransformationMethod(new PasswordTransformationMethod()); key = (EditText) findViewById(R.id.add_repo_key); url = (EditText) findViewById(R.id.add_repo_url); repo_types = (Spinner) findViewById(R.id.repo_type_spinner); repo_auth = (Spinner) findViewById(R.id.repo_authentication_spinner); // Create a new list for storing the services the program can handle ArrayList<String> services = new ArrayList<String>(); // Add the services supported by the program services.add("HGWeb Served"); services.add("Google Code"); services.add("Bitbucket"); services.add("CodePlex"); // Create a new adapter with the list of services AddRepoAdapter type_adapter = new AddRepoAdapter(this, services); // Add the adapter to the spinner that stores the list of services repo_types.setAdapter(type_adapter); // Create a new list to store authentication types ArrayList<String> authentication = new ArrayList<String>(); // Add the authentication types authentication.add(0, "None"); authentication.add(Mercury.AuthenticationTypes.HTTP, "HTTP"); authentication.add(Mercury.AuthenticationTypes.TOKEN, "Token"); // authentication.add(SSH, "SSH"); // Create a new adapter based on the authentication types AddRepoAdapter auth_adapter = new AddRepoAdapter(this, authentication); // Add the adapter to the authentication spinner repo_auth.setAdapter(auth_adapter); // Create a listener that triggers whenever the authentication type is changed repo_auth.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterview, View view, int position, long id) { // If anything other than "None" is selected, enable the username and password or ssh // fields if (position > Mercury.AuthenticationTypes.NONE) { if (position == Mercury.AuthenticationTypes.TOKEN) { if (username.getVisibility() != View.GONE || password.getVisibility() != View.GONE) { // Hide both the username and password if they're not already gone username.setVisibility(View.GONE); password.setVisibility(View.GONE); } // Make the key text box visible key.setVisibility(View.VISIBLE); // Enable the controls on the key text box key.setEnabled(true); key.setFocusable(true); key.setClickable(true); key.setFocusableInTouchMode(true); } else { // Make the username and password visible username.setVisibility(View.VISIBLE); password.setVisibility(View.VISIBLE); key.setVisibility(View.GONE); key.setText(""); // Re-enable the username and password text boxes username.setEnabled(true); username.setCursorVisible(true); username.setClickable(true); username.setFocusable(true); username.setFocusableInTouchMode(true); password.setEnabled(true); password.setCursorVisible(true); password.setClickable(true); password.setFocusable(true); password.setFocusableInTouchMode(true); } // Otherwise, disable all fields from user interaction } else { key.setEnabled(false); key.setFocusable(false); key.setClickable(false); username.setEnabled(false); username.setFocusable(false); username.setClickable(false); password.setEnabled(false); password.setClickable(false); password.setFocusable(false); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // Will never be called on a spinner } }); Button save_button = (Button) findViewById(R.id.add_repo_save); Button discard = (Button) findViewById(R.id.add_repo_discard); discard.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { killActivity(Activity.RESULT_CANCELED); } }); save_button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // Check the user input if (checkInput()) { // Attempt to save the repository if (saveRepository()) // If successful go back to the list killActivity(Activity.RESULT_OK); } } }); if (edit_mode) { // Get the information for this repository Beans.RepositoryBean repo_info = db_helper.getRepository(edit_repo, null); // Set the information in the activity repo_name.setText(repo_info.getTitle()); url.setText(repo_info.getUrl()); username.setText(repo_info.getUsername()); password.setText(repo_info.getPassword()); key.setText(repo_info.getSSHKey()); repo_types.setSelection(repo_info.getType()); repo_auth.setSelection(repo_info.getAuthentication()); } }