If I understand correctly, do you want to replace an existing gesture with a new one?
So, when a user enters a gesture that is not in the library, your application asks the user to choose which gesture they want to replace? From your question, I will assume that when the user draws a lowercase a
(and if a
not in the library), the user is presented with a list of all available gestures / letters that your application currently supports. Then the user selects capital a
, and now capital a
should be replaced by lowercase a
. In the following code, oldGesture is the gesture corresponding to a
. And newGesture
- A gesture just drawn.
The process for this: delete the old gesture, add a new one using the old gesture name. To remove a gesture, use GestureLibrary.removeGesture (String, Gesture):
public void onGesturePerformed(GestureOverlayView overlay, final Gesture gesture) { ArrayList<Prediction> predictions = gesturelib.recognize(gesture); if (predictions.size() > 1) { for(Prediction prediction: predictions){ if (prediction.score > ...) { } else { if (user wants to replace) { showListWithAllGestures(gesture); } } } } } public void showListWithAllGestures(Gesture newGesture) { .... ....
To get a list of all available gestures:
// Wrapper to hold a gesture static class GestureHolder { String name; Gesture gesture; }
Load gestures using GestureLibrary.load ():
if (gesturelib.load()) { for (String name : gesturelib.getGestureEntries()) { for (Gesture gesture : gesturelib.getGestures(name)) { final GestureHolder gestureHolder = new GestureHolder(); gestureHolder.gesture = gesture; gestureHolder.name = name;
Edit:
Sorry, but the check that I suggested: if (wants to replace)
is performed in the wrong place in the code.
if (predictions.size() > 1) { // To check whether a match was found boolean gotAMatch = false; for(int i = 0; i < predictions.size() && !gotAMatch; i++){ if (prediction.score > ... ) { .... .... // Found a match, look no more gotAMatch = true; } } // If a match wasn't found, ask the user s/he wants to add it if (!gotAMatch) { if (user wants to replace) { showListWithAllGestures(gesture); } } }