在 Android 中创建手势

发布于 2024-12-09 18:21:10 字数 1573 浏览 1 评论 0原文

您好,我正在关注本教程

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

软件包 de.vogella.android.gestures;

导入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 应用程序中添加手势的任何方法或链接。

Hi i am following this tutorial

http://www.vogella.de/articles/AndroidGestures/article.html
i want to create an application in which user can add his gesture inmy application and then use it for authentication.i know using this code i can check whether gesture entered by him is correct or not.

package 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();
            }
        }
    }
}

ok but please help me that how to add in gesture in R.raw.animate file.please suggest any way or link for adding a gesture in android app .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ㄖ落Θ余辉 2024-12-16 18:21:10

摘自此处

Android 1.6 及更高版本的 SDK 平台包含新应用程序
预装在模拟器上,称为“Gestures Builder”。您可以使用
该应用程序可以为您自己创建一组预定义手势
应用程序...

...

如您所见,手势始终与名称相关联。那个名字
非常重要,因为它可以识别您的每个手势
应用。名称不必是唯一的。其实也可以
非常有用的有几个同名的手势来增加
识别的精确度。 每次添加或编辑手势时
在Gestures Builder中,模拟器的SD上会生成一个文件
卡、/sdcard/手势。该文件包含所有的描述
手势,您需要将其打包到您的应用程序中
在资源目录中的 /res/raw
中。

这里您有手势生成器的源代码

手势生成器已安装在模拟器中,但您可以从 此处

以及手势源代码示例此处

Extracted from 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 you have the source code of Gesture Builder

Gesture builder is installed in the emulator , but you can download it from here

And gesture source code examples here

清醇 2024-12-16 18:21:10

另外,您可能需要在使用之前调用gestureLib.load()

Also, you may need to call gestureLib.load() before using it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文