2013-09-10 103 views
4

是否可以從正在運行的應用程序中替換模板庫的手勢模板? 我建,其中有在手勢庫file.So的信件模板手寫識別系統基本上加載代碼庫裏面後,我比較用戶輸入手勢,如:替換android中的手勢庫模板

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
ArrayList<Prediction> predictions = gesturelib.recognize(gesture); 

    if (predictions.size() > 1) { 
    for(Prediction prediction: predictions){ 
     //i compare prediction name here and if matches print it in an edittext 
    } 

這應該工作良好,直到用戶將像我在構建圖庫模板時一樣給出相同的圖案。但是我想讓用戶能夠靈活地在預測不匹配時用他的手寫圖案替換模板項目。

由於以下2種手寫手勢樣本在圖案方面不同,但不能作爲字母。假設我的系統支持第一圖像圖案,我想在用戶給第二圖像圖案時系統會要求用戶確認將其替換爲A的庫模式,然後在確認後將其替換。因此,下次系統將更好地識別用戶模式。

任何幫助將不勝感激。

enter image description hereenter image description here

回答

5

如果我理解正確的話,你想用一個新的來替換現有的姿態?

因此,當用戶輸入不在庫中的手勢時,應用程序會要求用戶選擇他們想要替換的手勢?從你的問題中,我將假設當用戶繪製一個小寫字母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); 
     } 
    } 
} 
+0

謝謝您的回覆,我稍後會告訴你它是否有效與否。 – ridoy

+0

你可以解釋如果(用戶想要替換)條件嗎?因爲那樣會發生每n-1個案例。讓我解釋一下,如果我有6個模板,只繪製1個模板,那麼1st if(prediction.score> 1。0)捕獲該模板,然後其他條件對其他5個模板發生變化。如何管理? – ridoy

+0

請清除答案,以便我可以獎賞你的賞金。 – ridoy