android - How to implement custom gesture on an ImageView? -



android - How to implement custom gesture on an ImageView? -

i succeed in implementing custom gesture @ level of activity, through next "standard" code. entire screen "reacts" gesture.

however able observe custom gesture when done on specific imageview. possible?

thanks

public class displaymultiimageactivity extends activity implements ongestureperformedlistener { gesturelibrary mlibrary; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_display_multiimage); mlibrary = gesturelibraries.fromrawresource(this, r.raw.gestures); if (!mlibrary.load()) { finish(); } gestureoverlayview gestures = (gestureoverlayview) findviewbyid(r.id.gestures); gestures.addongestureperformedlistener(this); } @override 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; if ("mycustomgesture".equalsignorecase(result)) { toast.maketext(this, "custom gesture detected!!", toast.length_long).show(); } } } }

in xml-file, gestureoverlayview takes whole screen. if want react on gestures on imageview, should set gestureoverlayview on imageview.

<android.gesture.gestureoverlayview android:id="@+id/gestures" android:layout_width="wrap_content" android:layout_height="wrap_content"> <imageview // attributes of imageview /> </android.gesture.gestureoverlayview>

edit

the ongestureperformedlistener receives gestureoverlayview on gesture performed in method ongestureperformed(gestureoverlayview, gesture).

in method, check gestureoverlayview used, , execute related action.

so should set diferent gestureoverlayview on every imageview want track gestures on.

@override public void ongestureperformed(gestureoverlayview overlay, gesture gesture) { switch(overlay.getid()) { case (r.id.overlay1): \\ imageview 1 break; case (r.id.overlay2): \\ imageview 2 break; case (r.id.overlay3): \\ imageview 3 break; default: \\ } }

android imageview gesture

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -