Ejemplo n.º 1
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tick_project);
    setTitle(R.string.editAscent);
    setupActionBar();
    Bundle b = this.getIntent().getExtras();
    long projectId = b.getLong("projectId");
    db = new InternalDB(this);
    project = db.getProject(projectId);
    TextView routeView = (TextView) this.findViewById(R.id.route);
    routeView.setText(
        project.getRoute().getName()
            + " "
            + project.getRoute().getGrade()
            + " ("
            + project.getRoute().getCrag().getName()
            + ")");

    TextView dateDisplay = (TextView) findViewById(R.id.dateDisplay);
    Date date = new Date();
    String dateString = fmt.format(date);
    dateDisplay.setText(dateString);
    cal.setTime(date);
    Button dateButton = (Button) findViewById(R.id.pickDate);
    dateButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
          }
        });

    EditText commentsView = (EditText) findViewById(R.id.comment);
    EditText attemptsView = (EditText) findViewById(R.id.attempts);
    attemptsView.setText("" + project.getAttempts());
    RatingBar starsView = (RatingBar) findViewById(R.id.stars);

    Button cancel = (Button) findViewById(R.id.cancel);
    cancel.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            setResult(RESULT_CANCELED);
            finish();
          }
        });
    Button button = (Button) findViewById(R.id.ok);
    button.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            String text = null;
            EditText attemptsView = (EditText) findViewById(R.id.attempts);
            String string = attemptsView.getText().toString();
            int attempts = 1;
            if (string != null) {
              try {
                attempts = Integer.parseInt(string);
              } catch (NumberFormatException e) {
              }
            }
            TextView dateDisplay = (TextView) findViewById(R.id.dateDisplay);
            String dateString = dateDisplay.getText().toString();
            Date date = new Date();
            try {
              date = fmt.parse(dateString);
            } catch (ParseException e) {
            }
            RatingBar starsView = (RatingBar) findViewById(R.id.stars);
            EditText commentView = (EditText) findViewById(R.id.comment);
            String comment = commentView.getText().toString();
            db.addAscent(project, date, attempts, 3, comment, (int) starsView.getRating());
            text = "Ascent added";

            if (text != null) {
              Toast.makeText(TickProjectActivity.this, text, Toast.LENGTH_SHORT).show();
            }
            setResult(RESULT_OK);
            finish();
          }
        });
  }
Ejemplo n.º 2
0
 public void onDestroy() {
   super.onDestroy();
   db.close();
 }