2013-09-10 102 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