mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
Java
49 lines
1.6 KiB
Java
/**
|
|
* Copyright (c) 2012 Todoroo Inc
|
|
*
|
|
* See the file "LICENSE" for the full license governing this code.
|
|
*/
|
|
package com.todoroo.andlib.widget;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import android.app.Activity;
|
|
import android.gesture.Gesture;
|
|
import android.gesture.GestureLibraries;
|
|
import android.gesture.GestureLibrary;
|
|
import android.gesture.GestureOverlayView;
|
|
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
|
|
import android.gesture.Prediction;
|
|
|
|
import com.todoroo.andlib.widget.GestureService.GestureInterface;
|
|
|
|
public class Api4GestureDetector implements OnGesturePerformedListener {
|
|
private final GestureLibrary mLibrary;
|
|
private final GestureInterface listener;
|
|
|
|
public Api4GestureDetector(Activity activity, int view, int gestureLibrary, GestureInterface listener) {
|
|
this.listener = listener;
|
|
mLibrary = GestureLibraries.fromRawResource(activity, gestureLibrary);
|
|
|
|
if(mLibrary.load()) {
|
|
GestureOverlayView gestures = (GestureOverlayView) activity.findViewById(view);
|
|
if(gestures != null)
|
|
gestures.addOnGesturePerformedListener(this);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
|
|
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
|
|
|
|
// We want at least one prediction
|
|
if (predictions.size() > 0) {
|
|
Prediction prediction = predictions.get(0);
|
|
// We want at least some confidence in the result
|
|
if (prediction.score > 2.0) {
|
|
listener.gesturePerformed(prediction.name);
|
|
}
|
|
}
|
|
}
|
|
}
|