title: Android: How/where to put gesture code into IME?
body: <p>I'm new to Android but I'm trying to create an IME that allows for gesture-character recognition.  I can already do simple apps that perform gesture recognition but am not sure where to hook in the gesture views/obj with an IME.  Here is a starting skeleton of what I have for the IME so far.  I would like to use <code>android.gesture.Gesture/Prediction/GestureOverlayView/OnGesturePerformedListener</code>.  Does anyone have advice?</p>
  
  <p>gestureIME.java</p>
  
  <pre><code>public class gestureIME extends InputMethodService {
      private static Keyboard keyboard;
      private static KeyboardView kView;
  
      private int lastDisplayWidth;
  
  @Override public void onCreate() {
      super.onCreate();
  }
  
  @Override public void onInitializeInterface() {      
   int displayWidth;
  
      if (keyboard != null) {
       displayWidth = getMaxWidth();
  
          if (displayWidth == lastDisplayWidth) return;
          else lastDisplayWidth = getMaxWidth();
      }
  
      keyboard = new GestureKeyboard(this, R.xml.keyboard);
  }
  
  @Override public View onCreateInputView() {
      kView = (KeyboardView) getLayoutInflater().inflate(R.layout.input, null);
      kView.setOnKeyboardActionListener(kListener);
      kView.setKeyboard(keyboard);
  
      return kView;
  }
  
  @Override public View onCreateCandidatesView() {
   return null;
  }
  
  @Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
      super.onStartInputView(attribute, restarting);
  
      kView.setKeyboard(keyboard);
      kView.closing();                  //what does this do???
  }   
  
  @Override public void onStartInput(EditorInfo attribute, boolean restarting) {
      super.onStartInput(attribute, restarting);
  
  }  
  
  @Override public void onFinishInput() {
      super.onFinishInput();
  }
  
  
  public KeyboardView.OnKeyboardActionListener kListener = new KeyboardView.OnKeyboardActionListener() {
   @Override public void onKey(int keyCode, int[] otherKeyCodes) {
    if(keyCode==Keyboard.KEYCODE_CANCEL) handleClose();
    if(keyCode==10) getCurrentInputConnection().commitText(String.valueOf((char) keyCode), 1); //keyCode RETURN
   }
  
  @Override public void onPress(int primaryCode) {}  // TODO Auto-generated method stub
  @Override public void onRelease(int primaryCode) {}  // TODO Auto-generated method stub
  @Override public void onText(CharSequence text) {}  // TODO Auto-generated method stub
  @Override public void swipeDown() {}     // TODO Auto-generated method stub
  @Override public void swipeLeft() {}     // TODO Auto-generated method stub 
  @Override public void swipeRight() {}     // TODO Auto-generated method stub 
  @Override public void swipeUp() {}      // TODO Auto-generated method stub
  };
  
  private void handleClose() {
      requestHideSelf(0);
      kView.closing();
  }
  }
  </code></pre>
  
  <p>GestureKeyboard.java</p>
  
  <pre><code>    package com.android.jt.gestureIME;
  
      import android.content.Context;
      import android.inputmethodservice.Keyboard;
  
      public class GestureKeyboard extends Keyboard {
          public GestureKeyboard(Context context, int xmlLayoutResId) {
              super(context, xmlLayoutResId);
          }
  }
  </code></pre>
  
  <p>GesureKeyboardView.java</p>
  
  <pre><code>package com.android.jt.gestureIME;
  
  import android.content.Context;
  import android.inputmethodservice.KeyboardView;
  import android.inputmethodservice.Keyboard.Key;
  import android.util.AttributeSet;
  
  public class GestureKeyboardView extends KeyboardView {
      public GestureKeyboardView(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public GestureKeyboardView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
      }
  
      @Override protected boolean onLongPress(Key key) {
          return super.onLongPress(key);
      }
  
  }
  </code></pre>
  
  <p>keyboard.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
      android:keyWidth="10%p"
      android:horizontalGap="0px"
      android:verticalGap="0px"
      android:keyHeight="@dimen/key_height"
      &gt;
      &lt;Row android:rowEdgeFlags="bottom"&gt;
           &lt;Key android:codes="-3" android:keyLabel="Close"  android:keyWidth="20%p" android:keyEdgeFlags="left"/&gt;
           &lt;Key android:codes="10" android:keyLabel="Return" android:keyWidth="20%p" android:keyEdgeFlags="right"/&gt;
      &lt;/Row&gt;
  &lt;/Keyboard&gt;
  </code></pre>
  
  <p>input.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;com.android.jt.gestureIME.GestureKeyboardView
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/gkeyboard"
          android:layout_alignParentBottom="true"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          /&gt;
  </code></pre>