如果我理解正確的話,你想用一個新的來替換現有的姿態?
因此,當用戶輸入不在庫中的手勢時,應用程序會要求用戶選擇他們想要替換的手勢?從你的問題中,我將假設當用戶繪製一個小寫字母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