How to write and read text from gesture input in android?

Let's say I want to spell a word named "test" using a gesture on the screen and then segment it as letters (t, e, s, t). I googled for this and didn't find a useful link for spelling a word using a gesture and then separating letters from the word. Any helpful link or tutorial on this topic would be appreciated. (Currently I am doing code that only write a letter at a time, the word cannot, and then how to segment this text, I cannot figure out)

my code

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 a word on screen with breaks example: write test on screen, but I can only write t, if I write the second letter e, the first letter disappears .. that's my problem

I hope you can understand

Please tell me that this is possible or something is wrong.

+1


source to share


1 answer


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);
        }
    }
}
}

      

You need to put this in XML so that you recognize the recognized gestures:



 <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 a gesture library. Follow the first step of this tutorial: Android Gestures Tutorial

+2


source







All Articles