2013-09-10 3 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 
    } 

것 라이브러리 템플릿을 만드는 동안했던 것과 같은 패턴을 제공합니다. 그러나 나는 예측의 불일치가있을 때 템플릿 항목을 손으로 쓴 패턴으로 교체 할 수있는 유연성을 사용자에게주고 싶습니다.

아래 두 필기체 제스처 샘플은 패턴이 다르지만 문자는 아닙니다. 그러므로 제 시스템이 첫 번째 이미지 패턴을 지원합니다. 사용자가 두 번째 이미지 패턴을 줄 때 시스템에서 사용자에게 확인을 요청합니다. 그것을 A의 라이브러리 패턴으로 교체 한 다음 확인한 후에 교체하십시오. 다음에 시스템이 사용자 패턴을 훨씬 잘 인식 할 것입니다.

도움을 주시면 감사하겠습니다.

enter image description hereenter image description here

답변

5

난 당신이 새 것으로 이미 존재하는 제스처를 교체하려면, 제대로 이해한다면?

그래서 사용자가 라이브러리에없는 제스처를 입력하면 앱에서 사용자가 바꿀 제스처를 선택하도록 사용자에게 요청합니다. 귀하의 질문에서 사용자가 소문자 a을 그렸을 때 (그리고 a이 라이브러리에없는 경우) 사용자가 현재 지원하는 사용 가능한 모든 제스처/문자의 목록이 표시된다고 가정합니다. 그런 다음 사용자가 자본을 A으로 선택하면 대문자 인 A을 소문자 a으로 바꿔야합니다. 다음 코드에서 oldGesture는 A에 해당하는 제스처입니다. 그리고 newGesture은 방금 그린 제스처입니다.

그 과정은 다음과 같습니다. 이전 제스처를 삭제하고 이전 제스처의 이름을 사용하여 새 제스처를 추가하십시오. 제스처를 삭제하려면 GestureLibrary.removeGesture (문자열, 제스처)를 사용 : GestureLibrary.load를 사용

// Wrapper to hold a gesture 
static class GestureHolder { 
    String name; 
    Gesture 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) { 
    .... 
    .... 

    // 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(); 

} 

가능한 모든 제스처의 목록을 얻으려면

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 번째 예 (predict.score> 1.0) 해당 템플릿을 잡아 다음 다른 5 템플릿에 대한 조건이 발생합니다. 어떻게 관리 할 수 ​​있습니까? – ridoy

+0

현상금을 수여 할 수 있도록 답변을 삭제하십시오. – ridoy