コード例 #1
0
  public void buttonSaveClick(View view) {
    if (!checkValidations()) {
      return;
    }

    if (state == NEW_STATE) {
      Thing thing = new Thing();
      thing.setImagePath(photoFile.getAbsolutePath());
      thing.setTags(etTags.getText().toString());
      thing.setLocation(etLocation.getText().toString());
      thing.setModifDate(new Date());

      ThingsDB db = new ThingsDB(this);
      db.insertThing(thing);
      db.cleanup();
    } else {
      Thing thing = new Thing();
      thing.setId(thingId);
      thing.setImagePath(photoFile.getAbsolutePath());
      thing.setTags(etTags.getText().toString());
      thing.setLocation(etLocation.getText().toString());
      thing.setModifDate(new Date());

      ThingsDB db = new ThingsDB(this);
      db.updateThing(thing);
      db.cleanup();
    }

    returnToMainActivity();
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_location);

    ivPhoto = (ImageView) findViewById(R.id.ivPhoto);
    etTags = (EditText) findViewById(R.id.etTags);
    etLocation = (EditText) findViewById(R.id.etLocation);
    btnDelete = (Button) findViewById(R.id.btnDelete);
    btnCancel = (Button) findViewById(R.id.btnCancel);
    btnSave = (Button) findViewById(R.id.btnSave);

    Intent intent = getIntent();
    state = intent.getIntExtra("state", 0);
    switch (state) {
      case NEW_STATE:
        photoFile = new File((String) intent.getExtras().get("photoFile"));
        btnDelete.setVisibility(View.GONE);
        break;
      case VIEW_STATE:
        thingId = intent.getLongExtra("id", -1);

        ThingsDB db = new ThingsDB(this);
        Thing thing = db.getThingById(thingId);
        db.cleanup();

        photoFile = new File(thing.getImagePath());
        etTags.setText(thing.getTags());
        etLocation.setText(thing.getLocation());
        break;
    }

    // get the screen height to calculate image height (0.3 * screenHeight)
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    ivPhoto.setImageBitmap(composeImage((int) (0.3 * size.y)));
  }