如果我理解正确的话,你想用一个新的来替换现有的姿态?
因此,当用户输入不在库中的手势时,应用程序会要求用户选择他们想要替换的手势?从你的问题中,我将假设当用户绘制一个小写字母a
(如果a
不在库中),用户会看到你的应用当前支持的所有可用手势/字母列表。然后,用户选择资本A
,现在,资本A
必须替换为小写a
。在以下代码中,oldGesture是对应于A
的手势。而newGesture
是刚刚绘制的手势。
该过程将是:删除旧手势,使用旧手势的名称添加新手势。要删除一个手势,使用GestureLibrary.removeGesture(字符串,手势):
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) {
....
....
// User picks a gesture
Gesture oldGesture = userPickedItem.gesture;
String gestureName = userPickedItem.name;
// delete the gesture
gesturelib.removeGesture(gestureName, oldGesture);
gesturelib.save();
// add gesture
gesturelib.addGesture(gestureName, newGesture);
gesturelib.save();
}
获得所有可用手势的列表:使用GestureLibrary.load()
// Wrapper to hold a gesture
static class GestureHolder {
String name;
Gesture gesture;
}
负载手势:
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;
// Add `gestureHolder` to a list
}
}
// Return the list that holds GestureHolder objects
}
编辑:
抱歉,该检查我提示:if (wants to replace)
正在代码中执行错误的地方。
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);
}
}
}
谢谢您的回复,我稍后会告诉你它是否有效与否。 – ridoy
你可以解释如果(用户想要替换)条件吗?因为那样会发生每n-1个案例。让我解释一下,如果我有6个模板,只绘制1个模板,那么1st if(prediction.score> 1。0)捕获该模板,然后其他条件对其他5个模板发生变化。如何管理? – ridoy
请清除答案,以便我可以奖赏你的赏金。 – ridoy