public void saveData() { vn = ed_vietnamese.getText().toString(); jp_hiragana = ed_japanese.getText().toString(); audio = uri_record; if (takingPhoto != null) image_d = takingPhoto + ""; if (selectedImage != null) image_d = selectedImage + ""; addNewSenDAO = new SentencesDAO(); addtagMySenDAO = new TagDAO(); int countId = addNewSenDAO.findLastIDMySenNumber() + 1; id = "s" + countId; item = new SentenceItem(id, jp_hiragana, vn, audio, image_d); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_addTagMySentences: Intent i = new Intent(getApplicationContext(), AddEditTagActivity.class); i.putExtra(Consts.ACTION_TYPE, Consts.EDIT_TAG_ADD_SEN); i.putStringArrayListExtra(Consts.AVAILABLE_TAG, resultTag); startActivityForResult(i, REQUEST_CODE_ADD_TAG); break; case R.id.bt_record: Intent intent = new Intent(getApplicationContext(), RecordActivity.class); startActivityForResult(intent, REQUEST_CODE_RECORD); break; case R.id.bt_recordPlay: MediaPlayer m = new MediaPlayer(); try { m.setDataSource(uri_record); } catch (IOException e) { e.printStackTrace(); } try { m.prepare(); } catch (IOException e) { e.printStackTrace(); } m.start(); Toast.makeText(getApplicationContext(), "オーディオをしています", Toast.LENGTH_LONG).show(); break; case R.id.bt_recordPath: openFolderRecord(); break; case R.id.bt_recordDelete: ConfirmDeleteDialog confirm = new ConfirmDeleteDialog( AddEditMySentencesActivity.this, Consts.DELETE_RECORD, Message.CONFIRM_DELETE) { @Override public void onClickAccept() { file = new File(uri_record); file.delete(); bt_recordDelete.setEnabled(false); bt_recordPlay.setEnabled(false); bt_record.setEnabled(true); bt_recordPath.setEnabled(true); uri_record = ""; Common.showToast( AddEditMySentencesActivity.this, Message.ITEM_IS_DELETED(Consts.AUDIO)); } }; confirm.show(); break; case R.id.bt_takephoto: dispatchTakePictureIntent(); break; case R.id.bt_gallery: dispatchPhotoSelectionIntent(); break; case R.id.bt_photodelete: if (takingPhoto != null || selectedImage != null || !image_d.isEmpty()) { ConfirmDeleteDialog confirm1 = new ConfirmDeleteDialog( AddEditMySentencesActivity.this, Consts.DELETE_PHOTO, Message.CONFIRM_DELETE) { @Override public void onClickAccept() { bt_photodelete.setEnabled(false); bt_takephoto.setEnabled(true); bt_gallery.setEnabled(true); if (action_type == Consts.EDIT_MY_SEN) { file = new File(image_d); file.delete(); image_d = ""; img_photo.setImageResource(R.drawable.default_image); } else { file = new File( Environment.getExternalStorageDirectory() + File.separator + folder_main + image_namefile); file.delete(); takingPhoto = null; selectedImage = null; img_photo.setImageResource(R.drawable.default_image); } Common.showToast( AddEditMySentencesActivity.this, Message.ITEM_IS_DELETED(Consts.IMAGE)); } }; confirm1.show(); } break; case R.id.bt_cancel2: if (action_type == Consts.EDIT_MY_SEN) { CancelDialog dialog = new CancelDialog(AddEditMySentencesActivity.this) { @Override public void onClickAccept() { finish(); } }; dialog.show(); } else { if ((ed_vietnamese.getText().toString()).isEmpty() && (ed_japanese.getText().toString()).isEmpty() && takingPhoto == null && selectedImage == null) { finish(); } else { CancelDialog dialog = new CancelDialog(AddEditMySentencesActivity.this) { @Override public void onClickAccept() { if (uri_record != null) { file = new File(uri_record); file.delete(); } if (takingPhoto != null) { file = new File( Environment.getExternalStorageDirectory() + File.separator + folder_main + image_namefile); file.delete(); } finish(); } }; dialog.show(); } } break; case R.id.bt_accept2: saveData(); if (validateSentence(item)) { if (action_type == Consts.ADD_MY_SEN) { addNewSenDAO.addSentences(item); addtagMySenDAO.addTagToTags(id, resultTag); } else if (action_type == Consts.EDIT_MY_SEN) { addNewSenDAO.updateSentences(id_edit, item); addtagMySenDAO.addTagToTags(id_edit, resultTag); } else { addNewSenDAO.addSentences(item); addtagMySenDAO.addTagToTags(id, resultTag); } finish(); String mess = Consts.ADD_SUCCESSFUL; Common.showToast(AddEditMySentencesActivity.this, mess, CustomToast.SUCCESS); takingPhoto = null; selectedImage = null; } break; } }