voidaddGesture(String entryName, Gesture gesture);//添加一个名为entryName的手势 Set<String>getGestureEntries();//获取该手势库中的所有手势的名称 ArrayList<Gesture>getGestures(String entryName);//获取entryName名称对应的全部手势 ArrayList<Prediction>recognize(Gesture gesture);//从当前手势库中识别与gesture匹配的全部手势 voidremoveEntry(String entryName);//删除手势库中entryName对应的手势 voidremoveGesture(String entryName, Gesture gesture);//删除手势库中entryName、gesture对应的手势 booleansave();//手势库文件有改动后调用该方法保存手势库
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请在下面屏幕上绘制手势"
/>
<android.gesture.GestureOverlayView
android:id="@+id/gesture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<!--该参数指定是否一笔完成,single为一笔完成-->
android:gestureStrokeType="multiple"
/>
</LinearLayout>
<?xmlversionxmlversion="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:androidLinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dip"
android:text="@string/gesture_name"
/>
<!-- 定义一个文本框来让用户输入手势名 -->
<EditText
android:id="@+id/gesture_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<!-- 定义一个图片框来显示手势 -->
<ImageView
android:id="@+id/show"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
public class AddGesture extends Activity
{
EditText editText;
GestureOverlayView gestureView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText) findViewById(R.id.gesture_name);
gestureView = (GestureOverlayView) findViewById(R.id.gesture);
// 设置手势的绘制颜色
gestureView.setGestureColor(Color.RED);
// 设置手势的绘制宽度
gestureView.setGestureStrokeWidth(4);
// 为gesture的手势完成事件绑定事件监听器
gestureView.addOnGesturePerformedListener(
new OnGesturePerformedListener()
{
@Override
public void onGesturePerformed(GestureOverlayView overlay
,final Gesture gesture)
{
//加载save.xml界面布局代表的视图
View saveDialog = getLayoutInflater().inflate(
R.layout.save, null);
// 获取saveDialog里的show组件
ImageView imageView = (ImageView) saveDialog
.findViewById(R.id.show);
// 获取saveDialog里的gesture_name组件
final EditText gestureName = (EditText) saveDialog
.findViewById(R.id.gesture_name);
// 根据Gesture包含的手势创建一个位图
Bitmap bitmap = gesture.toBitmap(128, 128, 10, 0xFFFF0000);
imageView.setImageBitmap(bitmap);
//使用对话框显示saveDialog组件
new AlertDialog.Builder(AddGesture.this)
.setView(saveDialog)
.setPositiveButton("保存", new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog,
int which)
{
// 获取指定文件对应的手势库
GestureLibrary gestureLib = GestureLibraries
.fromFile("/mnt/sdcard/mygestures");
// 添加手势
gestureLib.addGesture(
gestureName.getText().toString()
,gesture);
// 保存手势库
gestureLib.save();
}
})
.setNegativeButton("取消", null)
.show();
}
});
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有