My app has a bottom bar with a Send/record button. my goal is by using OntouchListener is: when the editText does not contain any text to enable recording function if editText contain text to ignore recording function and just add text to a list. how can I archive this?
The same function used inside WhatsApp record/send button (Chat activity)
I have tried using the code below, where send is the red button
(some variables have been declared in the outside this code)
send.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view,MotionEvent motionEvent) {
if(!editText.getText().toString().equals("")){
send.setImageDrawable(getDrawable(R.drawable.send));
String string = editText.getText().toString();
dati.add(new ModelloDati(tlDATE,""));
dati.add(new ModelloDati(tlTEXT,string));
adapter.notifyItemInserted(dati.size());
editText.getText().clear();
}
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
bar.setVisibility(View.GONE);
bar_rec.setVisibility(View.VISIBLE);
outputFile =
Environment.getExternalStorageDirectory().getAbsolutePath() + "
/recording.3gp";
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
recorder.setOutputFile(outputFile);
try {
recorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
recorder.start();
}else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
bar.setVisibility(View.VISIBLE);
bar_rec.setVisibility(View.GONE);
recorder.stop();
recorder.release();
chronometer.setBase(SystemClock.elapsedRealtime());
dati.add(new ModelloDati(tlAUDIO,outputFile));
adapter.notifyDataSetChanged();
}
recyclerView.smoothScrollToPosition(dati.size());
closeKeyboard();
return false;
}
});
