android gesture recognition

Keywords: Android xml encoding Java

No more details

Gesture recognition code http://download.csdn.net/detail/zhupengqq/9578532

After running the above project, it will generate such a gesture recognition library, gestures, and create a new project,

Under res, create a raw folder, and then import the library

 

Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.gesture.GestureOverlayView
        android:id="@+id/gestureOverlayView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/img1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/aa" />
    </android.gesture.GestureOverlayView>

</LinearLayout>
 
<span style="font-size:14px;">package com.example.gusturedetecterdemo2;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MainActivity2 extends Activity {
	private GestureOverlayView gestureOverlayView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main2);
		gestureOverlayView=(GestureOverlayView) findViewById(R.id.gestureOverlayView1);
		final GestureLibrary library=GestureLibraries.fromRawResource(MainActivity2.this, R.raw.gestures);
		library.load();
		gestureOverlayView.addOnGesturePerformedListener(new OnGesturePerformedListener() {

			@Override
			public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
				// Todo auto generated method stu read gesture
				//Read out the contents of gesture and recognize gesture
				ArrayList<Prediction> mygesture=library.recognize(gesture);
				Prediction predction=	mygesture.get(0);
				if(predction.score>5.0){
					if(predction.name.equals("Su")){
						Toast.makeText(MainActivity2.this, "One yuan voucher", Toast.LENGTH_LONG).show();
						finish();
					}
					if(predction.name.equals("Five corners")){
						Toast.makeText(MainActivity2.this, "Fifty cent voucher", Toast.LENGTH_LONG).show();
					}
					if(predction.name.equals("One")){
						Toast.makeText(MainActivity2.this, "Dime voucher", Toast.LENGTH_LONG).show();
					}
				}else{
					Toast.makeText(MainActivity2.this, "No such gesture", Toast.LENGTH_LONG).show();
				}
			}
		});
	}
}
</span>

After running, gesture recognition will appear when sliding the interface,
 

Published 194 original articles, won praise 1, visited 4010
Private letter follow

Posted by elToro on Sat, 01 Feb 2020 07:47:21 -0800