Question

Suppose,i want to write a word named "test" using gesture on the screen and then segment it as letters(t,e,s,t). I Google for it and not found any helpful link to write a word using gesture and then segment the letters from the word.Any helpful link or tutorial over this topic will be thankful..(Currently i do some code which only write a letter at a time,a word can't,and then how to segment this text i can't understand)

my code is

public class GestureTest extends Activity implements OnGesturePerformedListener {

private static GestureLibrary gesturerLib;

TextView showText1;
TextView showText2;
EditText firstEditText;
ArrayList<String> bindList;
ArrayList<Prediction> result;

ListView listViewShow;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_gesture_test);



    GestureOverlayView gestureOverLayerView = new GestureOverlayView(this);

    //View inflate = getLayoutInflater().inflate(R.layout.activity_gesture_test,null);

    View inflate = getLayoutInflater().inflate(R.layout.activity_gesture_test,null);

    gestureOverLayerView.addView(inflate);
    gestureOverLayerView.addOnGesturePerformedListener(this);

    gesturerLib = GestureLibraries.fromRawResource(getApplicationContext(), R.raw.gestures);

    if(!gesturerLib.load()){
        finish();
    }

    setContentView(gestureOverLayerView);

}

@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    // TODO Auto-generated method stub

    showText1 = (TextView)findViewById(R.id.listView1);

    result = gesturerLib.recognize(gesture);

            String point=null;
    String firstLetter=null;
    StringBuffer sb = new StringBuffer();
    String  value1 = "";

        if(result.size() > 0 && result.get(0).score>1.0){

            value1 += result.get(0).name;   


            for(int j= 0;j< prescriptionNames.length;j++){

                           // prescriptionName is String[] 

                firstLetter =  prescriptionNames[j];
                Log.i("THE STRING[] VALUE",firstLetter );
                if( firstLetter.startsWith(value1)){

                   showText1.setText(firstLetter);                      

                }
            }

        }

for example link https://play.google.com/store/apps/details?id=com.visionobjects.stylusmobile.v3_2_store

i want to write word on screen with breaks example : write test on screen but i can write only t if i write second letter e , the first letter disappear.. that is the my problem

hope u can understand

please tell me it is possible or any wrong

Was it helpful?

Solution

In your activity:

GestureLibrary gLibrary;
GestureOverlayView mView;
String txtToDisplay="";
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (gLibrary != null) {
            if (!gLibrary.load()) {
                Log.e("GestureSample", "Gesture library was not loaded…");
                finish();
            } else {
                mView = (GestureOverlayView) findViewById(R.id.gestures);
                mView.addOnGesturePerformedListener(this);
            }
        }
    }

@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    ArrayList<Prediction> predictions = gLibrary.recognize(gesture);
    // one prediction needed
    if (predictions.size() > 0) {
        Prediction prediction = predictions.get(0);
        // checking prediction
        if (prediction.score > 1.0) {
                txtToDisplay+=prediction.name;
            yourTextView.setText(txtToDisplay);
        }
    }
}
}

In the XML you need to put this where you want to get the gestures recognized:

 <android.gesture.GestureOverlayView
        android:id="@+id/gestures"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gestureColor="#2a69a5"
        android:uncertainGestureColor="#e2e2e2" >
    </android.gesture.GestureOverlayView>

AND you need the library of gestures. Follow the first step of this tutorial: Android Gestures Tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top