android - Single click on button for voice recording -
i working on android application in using voice recording functionality, making button tapping recording if user hold button more 3 seconds allow recording. using touch listener, problem if user click button without keeping hold recording or function called. code given below, please me out here:
mbtnsendaudio.setontouchlistener(new ontouchlistener() { boolean shouldrecord = true; @override public boolean ontouch(view v, motionevent event) { if(!canchat) { toast.maketext(getbasecontext(), "turned off chat", toast.length_short).show(); return true; } if (event.getaction() == motionevent.action_down) { mlastdown = system.currenttimemillis(); shouldrecord = true; startrecording(); mllaudiorecordinghover.setvisibility(view.visible); rectaudiobutton = new rect(v.getleft(), v.gettop(), v.getright(), v.getbottom()); mstarttime = system.currenttimemillis(); mrecordhandler.removecallbacks(mupdatetimetask); mrecordhandler.postdelayed(mupdatetimetask, 100); } else if (event.getaction() == motionevent.action_up) { if (shouldrecord) { mllaudiorecordinghover.setvisibility(view.gone); mlastduration = system.currenttimemillis() - mlastdown; mrecordhandler.removecallbacks(mupdatetimetask); mllaudiorecordinghover.setvisibility(view.gone); stoprecording(true, mlastduration); } } if (event.getaction() == motionevent.action_move) { // finger move outside of button's bounds if (!rectaudiobutton.contains(v.getleft() + (int) event.getx(), v.gettop()+ (int) event.gety()) && shouldrecord) { mrecordhandler.removecallbacks(mupdatetimetask); shouldrecord = false; stoprecording(shouldrecord, 0); mllaudiorecordinghover.setvisibility(view.gone); } } return v.ontouchevent(event); } });
once try follows
mbtnsendaudio.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view arg0, motionevent arg1) { switch (arg1.getaction()) { case motionevent.action_down: mrecordhandler.postdelayed(run, 3500/* or amount of time want */); break; default: mrecordhandler.removecallbacks(run); break; } return true; } });
and here runnable change status of recording
runnable run = new runnable() { @override public void run() { shouldrecord = true; }
};
update :
then have use gesturedetector follows
private gesturedetector gesturedetector = new gesturedetector(this, new simpleongesturelistener { @override public boolean onsingletapconfirmed(motionevent event) { return true; } });
then in ontouch(-,-) of ontouchlistener
if (gesturedetector.ontouchevent(arg1)) { // single tap //write code single click return true; }
hope helps you.
Comments
Post a Comment