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
| public class GestureSampleActivity extends Activity implements OnGesturePerformedListener{
GestureLibrary gLibrary;
GestureOverlayView mView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if(gLibrary != null)
{
if(!gLibrary.load())
{
Log.e("GestureSample", "Gesture library was not loaded
");
finish();
}
else
{
mView = (GestureOverlayView) findViewById(R.id.gestures);
mView.addOnGesturePerformedListener(this);
}
}
}
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
// TODO Auto-generated method stub
ArrayList<Prediction> predictions = gLibrary.recognize(gesture);
// one prediction needed
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
// checking prediction
if (prediction.score > 1.0) {
// and action
Toast.makeText(this, prediction.name,Toast.LENGTH_SHORT).show();
}
}
}
} |
Partager