当前位置 : 主页 > 手机开发 > android >

在android中创建手势

来源:互联网 收集:自由互联 发布时间:2021-06-11
嗨,我正在按照本教程 http://www.vogella.de/articles/AndroidGestures/article.html 我想创建一个应用程序,用户可以在我的应用程序中添加他的手势,然后使用它进行身份验证.我知道使用此代码我可以
嗨,我正在按照本教程

http://www.vogella.de/articles/AndroidGestures/article.html
我想创建一个应用程序,用户可以在我的应用程序中添加他的手势,然后使用它进行身份验证.我知道使用此代码我可以检查他输入的手势是否正确.

包de.vogella.android.gestures;

import java.util.ArrayList;

public class GestureTest extends Activity implements OnGesturePerformedListener {
    private GestureLibrary gestureLib;


/** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
        View inflate = getLayoutInflater().inflate(R.layout.main, null);
        gestureOverlayView.addView(inflate);
        gestureOverlayView.addOnGesturePerformedListener(this);
        gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (!gestureLib.load()) {
            finish();
        }
        setContentView(gestureOverlayView);
    }

    @Override
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
        for (Prediction prediction : predictions) {
            if (prediction.score > 1.0) {
                Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }
}

好的,但请帮助我,如何在R.raw.animate文件中添加手势.请提示在Android应用程序中添加手势的任何方式或链接.

从 here中提取:

Android 1.6 and higher SDK platforms include a new application
pre-installed on the emulator, called Gestures Builder. You can use
this application to create a set of pre-defined gestures for your own
application

As you can see, a gesture is always associated with a name. That name
is very important because it identifies each gesture within your
application. The names do not have to be unique. Actually it can be
very useful to have several gestures with the same name to increase
the precision of the recognition. Every time you add or edit a gesture
in the Gestures Builder, a file is generated on the emulator’s SD
card, /sdcard/gestures. This file contains the description of all the
gestures, and you will need to package it inside your application
inside the resources directory, in /res/raw
.

Here你有Gesture Builder的源代码

Gesture构建器安装在模拟器中,但您可以从here下载它

和手势源代码示例here

网友评论