/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.gesture.builder;
import android.app.Dialog;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.os.Environment;
import android.view.View;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.gesture.GestureLibrary;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.ArrayAdapter;
import android.content.DialogInterface;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.text.TextUtils;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.BitmapDrawable;
import java.util.Map;
import java.util.Collections;
import java.util.HashMap;
import java.util.Comparator;
import java.util.Set;
import java.io.File;
public class GestureBuilderActivity extends ListActivity {
private static final int STATUS_SUCCESS = 0;
private static final int STATUS_CANCELLED = 1;
private static final int STATUS_NO_STORAGE = 2;
private static final int STATUS_NOT_LOADED = 3;
private static final int MENU_ID_RENAME = 1;
private static final int MENU_ID_REMOVE = 2;
private static final int DIALOG_RENAME_GESTURE = 1;
private static final int REQUEST_NEW_GESTURE = 1;
// Type: long (id)
private static final String GESTURES_INFO_ID = "gestures.info_id";
private final File mStoreFile = new File(Environment.getExternalStorageDirectory(), "gestures");
private final Comparator<NamedGesture> mSorter = new Comparator<NamedGesture>() {
public int compare(NamedGesture object1, NamedGesture object2) {
return object1.name.compareTo(object2.name);
}
};
private static GestureLibrary sStore;
private GesturesAdapter mAdapter;
private GesturesLoadTask mTask;
private TextView mEmpty;
private Dialog mRenameDialog;
private EditText mInput;
private NamedGesture mCurrentRenameGesture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gestures_list);
mAdapter = new GesturesAdapter(this);
setListAdapter(mAdapter);
if (sStore == null) {
sStore = GestureLibraries.fromFile(mStoreFile);
}
mEmpty = (TextView) findViewById(android.R.id.empty);
loadGestures();
registerForContextMenu(getListView());
}
static GestureLibrary getStore() {
return sStore;
}
@SuppressWarnings({"UnusedDeclaration"})
public void reloadGestures(View v) {
loadGestures();
}
@SuppressWarnings({"UnusedDeclaration"})
public void addGesture(View v) {
Intent intent = new Intent(this, CreateGestureActivity.class);
startActivityForResult(intent, REQUEST_NEW_GESTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_NEW_GESTURE:
loadGestures();
break;
}
}
}
private void loadGestures() {
if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
mTask.cancel(true);
}
mTask = (GesturesLoadTask) new GesturesLoadTask().execute();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
mTask.cancel(true);
mTask = null;
}
cleanupRenameDialog();
}
private void checkForEmpty() {
if (mAdapter.getCount() == 0) {
mEmpty.setText(R.string.gestures_empty);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mCurrentRenameGesture != null) {
outState.putLong(GESTURES_INFO_ID, mCurrentRenameGesture.gesture.getID());
}
}
@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
long id = state.getLong(GESTURES_INFO_ID, -1);
if (id != -1) {
final Set<String> entries = sStore.getGestureEntries();
out: for (String name : entries) {
for (Gesture gesture : sStore.getGestures(name)) {
if (gesture.getID() == id) {
mCurrentRenameGesture = new NamedGesture();
mCurrentRenameGesture.name = name;
mCurrentRenameGesture.gesture = gesture;
break out;
}
}
}
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle(((TextView) info.targetView).getText());
menu.add(0, MENU_ID_RENAME, 0, R.string.gestures_rename);
menu.add(0, MENU_ID_REMOVE, 0, R.string.gestures_delete);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)
item.getMenuInfo();
final NamedGesture gesture = (NamedGesture) menuInfo.targetView.getTag();
switch (item.getItemId()) {
case MENU_ID_RENAME:
renameGesture(gesture);
return true;
case MENU_ID_REMOVE:
deleteGesture(gesture);
return true;
}
return super.onContextItemSelected(item);
}
private void renameGesture(NamedGesture gesture) {
mCurrentRenameGesture = gesture;
showDialog(DIALOG_RENAME_GESTURE);
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == DIALOG_RENAME_GESTURE) {
return createRenameDialog();
}
return super.onCreateDialog(id);
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog);
if (id == DIALOG_RENAME_GESTURE) {
mInput.setText(mCurrentRenameGesture.name);
}
}
private Dialog createRenameDialog() {
final View layout = View.inflate(this, R.layout.dialog_rename, null);
mInput = (EditText) layout.findViewById(R.id.name);
((TextView) layout.findViewById(R.id.label)).setText(R.string.gestures_rename_label);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(0);
builder.setTitle(getString(R.string.gestures_rename_title));
builder.setCancelable(true);
builder.setOnCancelListener(new Dialo
没有合适的资源?快使用搜索试试~ 我知道了~
手势识别 添加指定手势
共69个文件
class:28个
xml:11个
png:10个
4星 · 超过85%的资源 需积分: 9 8 下载量 22 浏览量
2012-04-14
18:26:54
上传
评论
收藏 170KB ZIP 举报
温馨提示
给予手势识别做的心灵感应程序 目的讨女朋友欢心!里面可以自己添加指定手势 支持 多笔画的手势
资源推荐
资源详情
资源评论
收起资源包目录
eclipse1.zip (69个子文件)
InsertDesture
.project 849B
project.properties 360B
proguard.cfg 1KB
src
com
android
gesture
builder
CreateGestureActivity.java 4KB
GestureBuilderActivity.java 14KB
AndroidManifest.xml 1KB
res
drawable-hdpi
ic_gesturebuilder.png 5KB
drawable-mdpi
ic_gesturebuilder.png 3KB
layout
dialog_rename.xml 2KB
gestures_list.xml 2KB
create_gesture.xml 3KB
gestures_item.xml 1KB
values
colors.xml 796B
strings.xml 3KB
dimens.xml 810B
assets
gen
com
android
gesture
builder
R.java 4KB
.classpath 364B
bin
resources.ap_ 16KB
InsertDesture.apk 27KB
classes
com
android
gesture
builder
R$layout.class 542B
R$dimen.class 483B
GestureBuilderActivity$3.class 1000B
R$drawable.class 440B
R$attr.class 367B
GestureBuilderActivity$4.class 1000B
GestureBuilderActivity$1.class 1KB
GestureBuilderActivity$GesturesAdapter.class 3KB
CreateGestureActivity$GesturesProcessor.class 2KB
R$id.class 611B
CreateGestureActivity.class 4KB
GestureBuilderActivity$GesturesLoadTask.class 6KB
CreateGestureActivity$1.class 1KB
R.class 708B
R$string.class 1KB
GestureBuilderActivity.class 12KB
GestureBuilderActivity$NamedGesture.class 557B
GestureBuilderActivity$2.class 980B
R$color.class 427B
res
drawable-hdpi
ic_gesturebuilder.png 5KB
drawable-mdpi
ic_gesturebuilder.png 3KB
classes.dex 20KB
Gesture
.project 843B
project.properties 360B
proguard.cfg 1KB
src
hai
test
Gesture
GestureActivity.java 2KB
AndroidManifest.xml 736B
res
raw
gestures 5KB
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 789B
values
strings.xml 180B
assets
gen
hai
test
Gesture
R.java 893B
.classpath 364B
bin
Gesture.apk 18KB
resources.ap_ 14KB
classes
hai
test
Gesture
R$layout.class 388B
GestureActivity$GestureListener.class 2KB
R$drawable.class 401B
R$attr.class 334B
R$raw.class 383B
R$id.class 411B
GestureActivity.class 2KB
R.class 559B
R$string.class 421B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
classes.dex 5KB
共 69 条
- 1
资源评论
- sanjinlx2012-08-22附带了android生成手势库的源码,可以学习下
zhizhuo360
- 粉丝: 0
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功