Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid gesture detection and recognition
    primarykey
    data
    text
    <p>I'm trying to add "fling" gesture detection in simple gesture recognition source code that developer has(<a href="http://android-developers.blogspot.com/2009/10/gestures-on-android-16.html" rel="nofollow">on this site</a>). and this is the code:</p> <pre><code>public class GestureMix extends Activity implements OnGesturePerformedListener{ /** Called when the activity is first created. */ private GestureLibrary mLibrary; private static final int LARGE_MOVE= 60; private static final String TAG= "Debug"; private GestureDetector gestureDetector; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv= (TextView)findViewById(R.id.textView1); gestureDetector= new GestureDetector(this, new SimpleOnGestureListener(){ @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ if(e1.getY()- e2.getY() &gt; LARGE_MOVE){ tv.setText("\nFling Ke Atas dengan kecepatan" +velocityY); //tv.append("\nFling Ke Atas dengan kecepatan" +velocityY); Log.d(TAG, "\nFling Ke Atas dengan kecepatan" +velocityY); return true; } else if(e2.getY()-e1.getY() &gt; LARGE_MOVE){ tv.setText("\nFling Ke Bawah dengan kecepatan" +velocityY); //tv.append("\nFling Ke Bawah dengan kecepatan" +velocityY); Log.d(TAG,"\nFling Ke Bawah dengan kecepatan" +velocityY ); return true; } else if(e1.getX()-e2.getX() &gt; LARGE_MOVE){ tv.setText("\nFling Ke Kiri dengan kecepatan" +velocityX); //tv.append("\nFling Ke Kiri dengan kecepatan" +velocityX); Log.d(TAG, "\nFling Ke Kiri dengan kecepatan" +velocityX); return true; } else if(e2.getX()-e1.getX() &gt; LARGE_MOVE){ tv.setText("\nFling Ke Kanan dengan kecepatan" +velocityX); //tv.append("\nFling Ke Kanan dengan kecepatan" +velocityX); Log.d(TAG,"\nFling Ke Kanan dengan kecepatan" +velocityX ); return true; } return false; } }); Log.d(TAG, "d on create"); mLibrary= GestureLibraries.fromRawResource(this, R.raw.gestures); if(!mLibrary.load()){ finish(); } GestureOverlayView gst= (GestureOverlayView) findViewById(R.id.gesture); gst.addOnGesturePerformedListener(this); } @Override public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { // TODO Auto-generated method stub Log.d(TAG, "d gesture perform"); ArrayList&lt;Prediction&gt; predictions= mLibrary.recognize(gesture); if(predictions.size()&gt;0){ Prediction prediction= predictions.get(0); if(prediction.score &gt;1.0){ Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show(); Log.d(TAG, prediction.name); } } } @Override public boolean onTouchEvent(MotionEvent event){ Log.d(TAG, "d on touch"); return gestureDetector.onTouchEvent(event); } </code></pre> <p>}</p> <p>The gesture recognition went well (it toast the right result), but the gesture detection (onfling) won't show the result (it won't appear whether in the textview or in the logCat. It seems the gesture detector won't work on <strong>gestureoverlayview</strong>.</p> <p>How could I fix this code, so I could see the gesture recognition and the velocity of the fling as the result?</p> <p>Any advice would be greatly appreciated. Please ask for clarification and I'll happily tell you the specifics of what I've tried.</p> <p>I'm sorry for my bad in English and less knowledge in programming. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload