android capture gesture and draw on canvas, incomplete draw -
i'm creating app user draws letter on canvas , gets validated if draw actual letter. i'm using gestureoverlayview canvas inside capture both gesture , path, problem canvas not drawing whole path/gesture hands. need find solution. need path/gesture drawn.
xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <android.gesture.gestureoverlayview android:id="@+id/gestures" android:layout_width="wrap_content" android:layout_height="wrap_content" android:eventsinterceptionenabled="true" android:gesturestroketype="multiple" android:layout_alignparentright="true" android:fadeoffset="500" android:background="#000000"> <cohen.projetotea.com.drawletter android:id="@+id/drawing" android:layout_width="wrap_content" android:layout_alignparentright="true" android:layout_height="wrap_content" android:background="#ffffff" /> </android.gesture.gestureoverlayview> </relativelayout>
activity
public class reconhecimento extends activity implements ongestureperformedlistener { gesturelibrary mlibrary; private final file mstorefile = new file(environment.getexternalstoragedirectory(), "gestures"); /** * called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.reconhecimento); //mlibrary = gesturelibraries.fromrawresource(this, r.raw.gestures); mlibrary = gesturelibraries.fromfile(mstorefile); if (!mlibrary.load()) { finish(); } gestureoverlayview gestures = (gestureoverlayview) findviewbyid(r.id.gestures); gestures.addongestureperformedlistener(this); gestures.setgesturevisible(false); } public void ongestureperformed(gestureoverlayview overlay, gesture gesture) { arraylist<prediction> predictions = mlibrary.recognize(gesture); if (predictions.size() > 0 && predictions.get(0).score > 1.0) { string result = predictions.get(0).name; toast.maketext(this, result, toast.length_long).show(); if ("open".equalsignorecase(result)) { toast.maketext(this, "opening document", toast.length_long).show(); } else if ("save".equalsignorecase(result)) { toast.maketext(this, "saving document", toast.length_long).show(); } } } }
drawletter app
public class drawletter extends view { //drawing path private path drawpath; //drawing , canvas paint private paint drawpaint, canvaspaint; //initial color private int paintcolor = 0xff660000; //canvas private canvas drawcanvas; //canvas bitmap private bitmap canvasbitmap; private boolean erase=false; public drawletter(context context, attributeset attrs){ super(context, attrs); setupdrawing(); } private void setupdrawing(){ drawpath = new path(); drawpaint = new paint(); drawpaint.setcolor(paintcolor); drawpaint.setantialias(true); drawpaint.setstrokewidth(5); drawpaint.setstyle(paint.style.stroke); drawpaint.setstrokejoin(paint.join.round); drawpaint.setstrokecap(paint.cap.round); canvaspaint = new paint(paint.dither_flag); } public void seterase(boolean iserase){ erase=iserase; if(erase){ drawpaint.setxfermode(new porterduffxfermode(porterduff.mode.clear)); drawpaint.setstrokewidth(10); } else{ drawpaint.setxfermode(null); drawpaint.setstrokewidth(5); } } @override protected void onsizechanged(int w, int h, int oldw, int oldh) { //view given size super.onsizechanged(w, h, oldw, oldh); canvasbitmap = bitmap.createbitmap(w, h, bitmap.config.argb_8888); drawcanvas = new canvas(canvasbitmap); } @override protected void ondraw(canvas canvas) { //draw view canvas.drawbitmap(canvasbitmap, 0, 0, canvaspaint); canvas.drawpath(drawpath, drawpaint); } @override public boolean ontouchevent(motionevent event) { //detect user touch float touchx = event.getx(); float touchy = event.gety(); switch (event.getaction()) { case motionevent.action_down: drawpath.moveto(touchx, touchy); break; case motionevent.action_move: drawpath.lineto(touchx, touchy); break; case motionevent.action_up: drawcanvas.drawpath(drawpath, drawpaint); drawpath.reset(); break; default: return false; } invalidate(); return true; } public boolean geterase(){ return erase; } }
you can in way. this
<android.gesture.gestureoverlayview android:id="@+id/g1" android:layout_width="fill_parent" android:layout_height="200dp" android:background="#ffffff" android:fadeoffset="999999" android:gesturecolor="#0000ff" android:gesturestroketype="multiple" android:gesturestrokewidth="5" > <android.gesture.gestureoverlayview android:id="@+id/g2" android:layout_width="fill_parent" android:layout_height="200dp" android:gesturestroketype="multiple" android:fadeoffset="001" android:gesturecolor="#000" android:gesturestrokeanglethreshold="0.0" android:gesturestrokelengththreshold="0.0" android:gesturestrokesquarenessthreshold="0.0" > </android.gesture.gestureoverlayview> </android.gesture.gestureoverlayview>
here gestureoverlayview g2 within g1.
g2 used recognize letters , fades once letter written.
but g1 not fades.
if don't want letter can clear gestureoverlayview.
Comments
Post a Comment