blob: 7f9c3fa1795550964acc99d7c0f4e03b3c47ff5b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
********************************************************************************
* Copyright (c) 2012 Samsung Electronics, Inc.
* All rights reserved.
*
* This software is a confidential and proprietary information of Samsung
* Electronics, Inc. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with the terms
* of the license agreement you entered into with Samsung Electronics.
********************************************************************************
*/
package us.minak;
import java.util.List;
import android.content.Context;
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;
/**
* Represent a space where drawing gestures are performed.
*/
public class DrawingSpaceView extends GestureOverlayView implements OnGesturePerformedListener {
private static final double SCORE_TRESHOLD = 3.0;
private final GestureLibrary mGestureLibrary;
private OnGestureRecognizedListener mOnGestureRecognizedListener;
public DrawingSpaceView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureLibrary = GestureLibraries.fromRawResource(context, R.raw.gestures);
mGestureLibrary.load();
addOnGesturePerformedListener(this);
}
public void setOnGestureRecognizedListener(OnGestureRecognizedListener onGestureRecognizedListener) {
mOnGestureRecognizedListener = onGestureRecognizedListener;
}
@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);
}
if (mOnGestureRecognizedListener != null && bestPrediction != null) {
if (bestPrediction.score > SCORE_TRESHOLD) {
mOnGestureRecognizedListener.gestureRecognized(bestPrediction.name);
} else {
clear(false);
}
}
}
}
|