private boolean validateSentence(SentenceItem sen) { String message = ""; Activity con = AddEditMySentencesActivity.this; if (sen.getNameJp() == null || sen.getNameJp().trim().isEmpty()) { message = Message.MUST_NOT_EMPTY(Consts.JAPANESE); Common.showToast(con, message, CustomToast.ERROR); return false; } if (sen.getNameVn().length() > Consts.MAX_VIE_CHAR_LENGTH) { message = Message.MAX_CHARACTER_LENGTH(sen.getNameVn(), Consts.MAX_VIE_CHAR_LENGTH); Common.showToast(con, message, CustomToast.ERROR); return false; } if (sen.getNameJp().length() > Consts.MAX_JAP_CHAR_LENGTH) { message = Message.MAX_CHARACTER_LENGTH(sen.getNameJp(), Consts.MAX_JAP_CHAR_LENGTH); Common.showToast(con, message, CustomToast.ERROR); return false; } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_new_my_sentences); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // h Common.setupUIForHideSoftKeyBroad( findViewById(R.id.activity_add_edit_my_sentence), AddEditMySentencesActivity.this); this.action_type = getIntent().getIntExtra(Consts.ACTION_TYPE, Consts.NOT_FOUND); findViewById(R.id.bt_addTagMySentences).setOnClickListener(listener); tagView = (TagView) findViewById(R.id.tagView1); img_photo = (ImageView) findViewById(R.id.img_photo); ed_vietnamese = (EditText) findViewById(R.id.ed_vietnamese); ed_japanese = (EditText) findViewById(R.id.ed_japanese); // Xy ly phan Record bt_record = (ImageButton) findViewById(R.id.bt_record); bt_recordPlay = (ImageButton) findViewById(R.id.bt_recordPlay); bt_recordDelete = (ImageButton) findViewById(R.id.bt_recordDelete); bt_recordPath = (ImageButton) findViewById(R.id.bt_recordPath); bt_takephoto = (ImageButton) findViewById(R.id.bt_takephoto); bt_gallery = (ImageButton) findViewById(R.id.bt_gallery); bt_photodelete = (ImageButton) findViewById(R.id.bt_photodelete); bt_accept2 = (ImageButton) findViewById(R.id.bt_accept2); bt_cancel2 = (ImageButton) findViewById(R.id.bt_cancel2); bt_record.setOnClickListener(listener); bt_recordPlay.setOnClickListener(listener); bt_recordDelete.setOnClickListener(listener); bt_recordPath.setOnClickListener(listener); bt_takephoto.setOnClickListener(listener); bt_gallery.setOnClickListener(listener); bt_photodelete.setOnClickListener(listener); bt_accept2.setOnClickListener(listener); bt_cancel2.setOnClickListener(listener); bt_recordPlay.setEnabled(false); bt_recordDelete.setEnabled(false); bt_photodelete.setEnabled(false); // hanlde for Float Button Record from main Intent intent1 = getIntent(); fab_record = intent1.getStringExtra("data1"); if (fab_record != null) { uri_record = fab_record; // Toast.makeText(getApplicationContext(), "Uri record: "+ uri_record, // Toast.LENGTH_SHORT).show(); bt_recordPlay.setEnabled(true); bt_recordDelete.setEnabled(true); bt_recordPath.setEnabled(false); } ; // handle for Float Button Camera from main uri_fabbutton = getIntent().getData(); Log.d("aaaaaaaaaaaaa", uri_fabbutton + ""); if (uri_fabbutton != null) { bt_photodelete.setEnabled(true); takingPhoto = uri_fabbutton; Picasso.with(this) .load(takingPhoto) .config(Bitmap.Config.RGB_565) .resize(600, 600) .centerInside() .into(img_photo); } /////// modify if (action_type == Consts.EDIT_MY_SEN) { Bundle extras = getIntent().getExtras(); if (extras != null) { SentenceItem item = extras.getParcelable(Consts.DATA); id_edit = item.getId(); uri_record = item.getSound(); if (uri_record != null && !uri_record.isEmpty()) { bt_recordPlay.setEnabled(true); bt_recordDelete.setEnabled(true); bt_record.setEnabled(false); bt_recordPath.setEnabled(false); } image_d = item.getImage(); if (image_d != null && !image_d.isEmpty()) { bt_photodelete.setEnabled(true); bt_takephoto.setEnabled(false); bt_gallery.setEnabled(false); } vn = item.getNameVn(); jp_hiragana = item.getNameJp(); ed_japanese.setText(jp_hiragana); ed_vietnamese.setText(vn); loadImg_edit(image_d); load_tag(id_edit); } } }