我正在创建一个android应用程序。其中我正在识别直线(垂直和水平)。我使用了以下步骤。
1) Creating straight lines gesture file using "Gestures Builder" application.
2) Added the "gestures" file in my application and used the "OnGesturePerformedListener" to recognize the line.
The problem is,
I can't recognize the vertical lines(Both Top to Bottom & Bottom to Top).
我能认出直线而不是竖线。有人知道如何检测垂直线吗?
代码段:
public class GestureActivity extends Activity implements OnGesturePerformedListener {
private GestureLibrary mLibrary;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
View inflate = getLayoutInflater().inflate(R.layout.activity_gesture,
null);
gestureOverlayView.addView(inflate);
gestureOverlayView.addOnGesturePerformedListener(this);
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
setContentView(gestureOverlayView);
}
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
if (prediction.name.equals("Line") && prediction.score > 1.0) {
Toast.makeText(this, "Line", Toast.LENGTH_LONG).show();
}
}
}
}