summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavisLWebb <davislwebb@ymail.com>2014-05-03 19:47:41 -0400
committerDavisLWebb <davislwebb@ymail.com>2014-05-03 19:47:41 -0400
commit409bd3bc05a942e890770cbd5df6ed337c2f4bec (patch)
treeee630bb567137ce315d35008d6c6c4fc3700f477
parentc9f037f138f2df44ea1e9696cfedd5547b8a5766 (diff)
Added meat to the SketchpadView.java
-rw-r--r--src/us/minak/SketchpadView.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/us/minak/SketchpadView.java b/src/us/minak/SketchpadView.java
index e69de29..26cc19c 100644
--- a/src/us/minak/SketchpadView.java
+++ b/src/us/minak/SketchpadView.java
@@ -0,0 +1,54 @@
+import java.util.List;
+
+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 android.util.AttributeSet;
+
+public class SketchpadView extends GestureOverlayView implements OnGesturePerformedListener{
+ //Setting score thresh hold
+ private static final double score_threshold = 3.0;
+ //loads gesture library
+ private final GestureLibrary gestureLib;
+ //used to capture drawn gestures
+ private onGestureRecognizedListener gestureRecognizer;
+
+ public SketchpadView (Context context, AttributeSet attrs){
+ super(context, attrs);
+ mGestureLibrary = GestureLibraries.fromRawResource(context, R.raw.gestures);
+ mGestureLibrary.load();
+ addOnGesturePerformedListener(this);
+ }
+
+ public void setOnGestureRecognizedListener(OnGestureRecognizedListener onGestureRecognizedListener) {
+ gestureRecognizer = onGestureRecognizedListener;
+ }
+
+ @Override
+ public void onGesturePerformed(GestureOverlayView view, Gesture gesture){
+ //create list of predicted characters to be entered
+ List<Prediction> predictions = gestureLib.recognize(gesture);
+ Prediction bestPrediction = null;
+ //if we have a prediction
+ if(!predictions.isEmpty()){
+ //I believe that this just blidnly adds a predicted character without any checks
+ //we need to see if there is a way to actual get the best prediction
+ //if this lists them based on the best, then fuck me and ignore this/delete this
+ bestPrediction = predictions.get(0);
+ }
+ //if we have a gesture and a decent prediction
+ if(gestureRecognizer != null && bestPrediction != null){
+ //if the prediction is good enough
+ if(bestPrediction.score > score_threshold){
+ //we recognize it
+ gestureRecognizer.gestureRecognized(bestPrediction.name);
+ }else{
+ //why?
+ clear(false);
+ }
+ }
+ }
+}