本文整理汇总了Java中android.gesture.Gesture类的典型用法代码示例。如果您正苦于以下问题:Java Gesture类的具体用法?Java Gesture怎么用?Java Gesture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Gesture类属于android.gesture包,在下文中一共展示了Gesture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRestoreInstanceState
import android.gesture.Gesture; //导入依赖的package包/类
@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;
}
}
}
}
}
示例2: onGesturePerformed
import android.gesture.Gesture; //导入依赖的package包/类
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
if (config.getString("swipeAction", "0").equals("1")) { // only pay attention if gestures are 'enabled'
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
Prediction prediction = predictions.get(0); // only use the first prediction
if (prediction.score > 1.0) {
Log.i("WTF","prediction.name = "+prediction.name);
// Toast.makeText(activity.getApplicationContext(), prediction.name, Toast.LENGTH_SHORT).show();
if (prediction.name.equals("up")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Top");
} else if (prediction.name.equals("down")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Bottom");
} else if (prediction.name.equals("left")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Left");
} else if (prediction.name.equals("right")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Right");
}
}
/*for (Prediction prediction : predictions) {
if (prediction.score > 1.0) {
Log.i("WTF","prediction.name = "+prediction.name);
// Toast.makeText(activity.getApplicationContext(), prediction.name, Toast.LENGTH_SHORT).show();
if (prediction.name.equals("up")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Top");
} else if (prediction.name.equals("down")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Bottom");
} else if (prediction.name.equals("left")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Left");
} else if (prediction.name.equals("right")) {
new sendButton().execute("http://"+playerIP+"/proc/empeg_notify?button=Right");
}
}
}*/
}
}
示例3: createBaseGestureOverlayView
import android.gesture.Gesture; //导入依赖的package包/类
private void createBaseGestureOverlayView() {
gestureOverlayView = new GestureOverlayView(this.context);
gestureOverlayView.setGestureStrokeType(GestureOverlayView.GESTURE_STROKE_TYPE_SINGLE);
gestureOverlayView.setEventsInterceptionEnabled(true);
gestureOverlayView.setOrientation(GestureOverlayView.ORIENTATION_VERTICAL);
gestureOverlayView.setUncertainGestureColor(Color.TRANSPARENT);
gestureOverlayView.addOnGesturePerformedListener(new OnGesturePerformedListener() {
public void onGesturePerformed(GestureOverlayView v, Gesture g) {
ArrayList<Prediction> l = UserUtil.glib.recognize(g);
if (l.size() > 0 && l.get(0).score > 1.0) {
String action = l.get(0).name;
onGestureActionRecognized(action, gestureStartPosition);
}
onGestureActionRecognized(l, gestureStartPosition);
}
});
}
示例4: done
import android.gesture.Gesture; //导入依赖的package包/类
private void done() {
Gesture gesture = gestureOverlayView.getGesture();
if (uri != null && gesture != null) {
int h = getResources().getDisplayMetrics().heightPixels;
int w = getResources().getDisplayMetrics().widthPixels;
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(gesture.toBitmap(w, h, 10, Color.BLACK), 0, 0, null);
try {
bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(uri.getPath()));
} catch (FileNotFoundException e) {
Log.e("content draw", "file not found", e);
}
setResult(RESULT_OK);
} else {
setResult(RESULT_CANCELED);
}
finish();
}
示例5: listBanav
import android.gesture.Gesture; //导入依赖的package包/类
/**
* badha gestures laine emne list ma mukse
*/
private void listBanav() {
try {
mGestureList = new ArrayList<GestureHolder>();
gLib = GestureLibraries.fromFile(getExternalFilesDir(null) + "/" + "gesture.txt");
gLib.load();
Set<String> gestureSet = gLib.getGestureEntries();
for(String gestureNaam: gestureSet){
ArrayList<Gesture> list = gLib.getGestures(gestureNaam);
for(Gesture g : list) {
mGestureList.add(new GestureHolder(g, gestureNaam));
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例6: initGesture
import android.gesture.Gesture; //导入依赖的package包/类
private void initGesture() {
final GestureLibrary gestureLibrary = GestureLibraries.fromRawResource(
context, R.raw.gestures);
gestureLibrary.load();
gestureOverlayView
.addOnGesturePerformedListener(new OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView overlay,
Gesture gesture) {
ArrayList<Prediction> arrayList = gestureLibrary
.recognize(gesture);
Prediction prediction = arrayList.get(0);
if (prediction.score >= 3.0) {
if (prediction.name.equals("back")) {
Toast.makeText(context, "退出",
Toast.LENGTH_SHORT).show();
finish();
}
} else {
Toast.makeText(context, "手势不存在", Toast.LENGTH_SHORT)
.show();
}
}
});
}
示例7: recognize
import android.gesture.Gesture; //导入依赖的package包/类
public List<ChronosGesture> recognize(Gesture gesture) {
ArrayList<ChronosGesture> gestures = new ArrayList<>();
if(gesture != null) {
ArrayList<Prediction> matches = mStore.recognize(gesture);
if (matches != null && !matches.isEmpty()) {
Collections.sort(matches, new Comparator<Prediction>() {
@Override
public int compare(Prediction lhs, Prediction rhs) {
return Double.valueOf(rhs.score).compareTo(Double.valueOf(lhs.score));
}
});
for (Gesture g : mStore.getGestures(matches.get(0).name)) {
gestures.add(new ChronosGesture(g, mChronosLibrary.get(g.getID())));
}
}
}
return gestures;
}
示例8: onGesturePerformed
import android.gesture.Gesture; //导入依赖的package包/类
public void onGesturePerformed(GestureOverlayView gestureView,Gesture gesture) {
ArrayList<Prediction> predictions = gLib.recognize(gesture);
// one prediction needed
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
// checking prediction
if (prediction.score > 1.0) {
if(prediction.name.contains("reload")) {
// perform reload action
}
if(prediction.name.contains("logout")) {
// perform logout action
}
if(prediction.name.contains("prev")) {
// perform next action
}
if(prediction.name.contains("new")) {
// perform new action
}
if(prediction.name.contains("next")) {
// perform next action
}
}
}
}
示例9: addGesture
import android.gesture.Gesture; //导入依赖的package包/类
/**
* Stores the given gesture.
*
* @param name The name of the gesture
* @param gesture The gesture
* @param action The action to perform when the touch gesture is performed
*/
public void addGesture(String name, Gesture gesture, AbstractAction action) {
GestureLibrary fileLib = GestureLibraries.fromFile(TOUCH_GESTURES_FILE);
if (fileLib.load()) {
fileLib.addGesture(name, gesture);
fileLib.save();
this.mMap.put(name, action);
saveHashMap();
DeLog.d(TAG, "Gesture " + name + " saved");
sendGestureChangedBroadcast();
} else {
DeLog.e(TAG, "Couldn't save gesture " + name);
}
}
示例10: loadInBackground
import android.gesture.Gesture; //导入依赖的package包/类
@Override
public List<NamedGesture> loadInBackground() {
DeLog.i(TAG, "onLoadInBackground called");
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
DeLog.e(TAG, "Media not mounted");
return null;
}
List<NamedGesture> mGestures = null;
if (mLibrary.load()) {
mGestures = new ArrayList<>();
for (String name : mLibrary.getGestureEntries()) {
for (Gesture gesture : mLibrary.getGestures(name)) {
final NamedGesture namedGesture = new NamedGesture(gesture, name);
// TODO For performance and memory efficiency, the thumbnails need to be loaded off the Loader
// it was done this way for simplicity reason
Bitmap thumbnail = gesture.toBitmap(mWidth, mHeight, mInset, mColor);
namedGesture.setThumbnail(thumbnail);
mGestures.add(namedGesture);
}
}
}
Collections.sort(mGestures);
return mGestures;
}
示例11: onGesturePerformed
import android.gesture.Gesture; //导入依赖的package包/类
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
if (predictions.isEmpty()) {
DeLog.d(TAG, "No predictions");
return;
}
Context context = SimpleOverlayActivity.this;
for (Prediction prediction : predictions) {
if (prediction.score > 2.0) {
AbstractAction action = GestureManager.getInstance(context).getActionOfGesture(prediction.name);
if (action != null) {
if (DEBUG) {
Log.d(TAG, "Deleted gesture: " + prediction.name + " :: " + prediction.score);
}
Toast.makeText(context, prediction.name, Toast.LENGTH_SHORT).show();
onGestureDetected(action);
mSuccess = true;
break;
}
}
}
if (!mSuccess) {
Toast.makeText(SimpleOverlayActivity.this, R.string.unrecognised_gesture, Toast.LENGTH_SHORT).show();
}
mTryCount++;
if (mSuccess || mTryCount > ALLOWED_GESTURE_TRIES) {
mTryCount = 1;
mSuccess = false;
onGestureFailed();
}
}
示例12: getOverlayContentView
import android.gesture.Gesture; //导入依赖的package包/类
/**
* Add the content view of the activity into a GestureOverlayView and return the new view
*
* @param contentView the original content view of the activity
* @param packageName the package name of the app who uses this library
* @param rawId the resource identifier of the gesture file in your raw folder
* @return the new contentView wrapped in a GestureOverlayView
*/
public static View getOverlayContentView(final View contentView, final String packageName,
int rawId) {
//load the gestures
final GestureLibrary gestureLib = GestureLibraries
.fromRawResource(contentView.getContext(), rawId);
if (!gestureLib.load()) {
Log.w(TAG, "could not load gestures");
return contentView;
}
GestureOverlayView gestureOverlayView = new GestureOverlayView(contentView.getContext());
gestureOverlayView.setGestureColor(Color.TRANSPARENT);
gestureOverlayView.setUncertainGestureColor(Color.TRANSPARENT);
gestureOverlayView.addView(contentView);
gestureOverlayView
.addOnGesturePerformedListener(new GestureOverlayView.OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
//load all gestures
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
//the only received prediction should be "netural"
for (Prediction prediction : predictions) {
if (prediction.score > 1.0) {
showDialog(contentView.getContext(), packageName);
}
}
}
});
return gestureOverlayView;
}
示例13: onGestureEnded
import android.gesture.Gesture; //导入依赖的package包/类
@Override
public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {
if(first){
Gesture gesture = overlay.getGesture();
library.addGesture("first", gesture);
first = false;
((TextView)findViewById(R.id.tv_unlock_message)).setText(getString(R.string.confirm_gesture));
} else {
Gesture gestureConfirm = overlay.getGesture();
ArrayList<Prediction> list = library.recognize(gestureConfirm);
if(list.get(0).score < 2) {
//gesture do not match
Toast.makeText(SetupGestureLock.this,getString(R.string.gesture_dont_match),Toast.LENGTH_SHORT).show();
((TextView)findViewById(R.id.tv_unlock_message)).setText(getString(R.string.gesture_dont_match_message));
first = true;
} else {
//gesture match
Toast.makeText(SetupGestureLock.this, getString(R.string.gesture_set), Toast.LENGTH_LONG).show();
library.save();
PreferenceManager.getDefaultSharedPreferences(SetupGestureLock.this).edit().putBoolean(AppLockApplication.LOCKSET,true).commit();
setResult(AppLockApplication.RESULT_OK);
finish();
if(!changeLock){
LocalBroadcastManager.getInstance(SetupGestureLock.this).sendBroadcast(new Intent(AppLockApplication.LAUNCH_PICKER));
} else {
PreferenceManager.getDefaultSharedPreferences(SetupGestureLock.this).edit().putString(AppLockApplication.LOCKTYPE,AppLockApplication.LOCKTYPE_GESTURE).commit();
}
}
}
}
示例14: onGesturePerformed
import android.gesture.Gesture; //导入依赖的package包/类
/**
* This function is pretty strongly based on the code in
* Samsung's "Penboard" whitepaper.
*/
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
final List<Prediction> predictions = mGestureLibrary.recognize(gesture);
Prediction bestPrediction = null;
if (!predictions.isEmpty()) {
bestPrediction = predictions.get(0);
}
ic = icGetter.getCurrentInputConnection();
if (ic != null) {
if (bestPrediction != null) {
if (bestPrediction.score > SCORE_TRESHOLD) {
for (KeyEvent keyEvent : charMap.getEvents(bestPrediction.name.toCharArray()))
sendKeyEvent(keyEvent);
} else {
clear(false);
}
}
for (IMEModifier modifier : modifiers.getSelection()) {
sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, modifier.keycode));
}
}
modifiers.clearSelection();
meta = 0;
invalidate();
x = y = -1;
}
示例15: onGesturePerformed
import android.gesture.Gesture; //导入依赖的package包/类
public void onGesturePerformed(GestureOverlayView view, Gesture gesture) {
// TODO Auto-generated method stub
ArrayList<Prediction> prediction = gestureLibrary.recognize(gesture);
if(prediction.size() > 0){
String gesture_found = prediction.get(0).name;
Log.d("gesture tag", "gesture detected");
//Toast.makeText(GestureMonitorActivity.this, gesture_found, Toast.LENGTH_SHORT).show();
Intent intent= new Intent();
intent.putExtra("gesture",gesture_found);
setResult(RESULT_OK,intent);
finish();
}
}