Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Non-Keyboard IME

Im trying to create an IME for android that is not a traditional keyboard (rows of keys corresponding to the different letters) and I am having trouble finding helpful resources on how to do so since all of the code examples in the SDK use a Keyboard API and it's built in functions.

I've designed the interface of the IME in an XML file as though it were simply an Activity within in application but I'm getting lost in their demos since their Keyboards are simply objects that are built from a different style of XML structure.

If anyone has a link to an open source project that does not use the tradional keyboard structure or could simply guide me to displaying the UI that I've already constructed onto the IME window, I think I can figure the rest out.

If you need any more specfic information, please feel free to ask. Thanks in advance.

like image 803
cmcowart Avatar asked Jun 23 '11 02:06

cmcowart


1 Answers

The SoftKeyboard sample is in fact structured similarly to what you need, though you don’t know it. Let’s break it down — here’s a complete stub to act as an input method service and use the standard XML keyboard:

import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;

public class MyInputMethod extends InputMethodService {
    private Keyboard mKeyboard;

    @Override public void onInitializeInterface() {
        mKeyboard = new Keyboard(this, R.xml.qwerty);
    }

    @Override public View onCreateInputView() {
        mInputView = (KeyboardView) getLayoutInflater().inflate(
                R.layout.input, null);
        mInputView.setKeyboard(mKeyboard);
        return mInputView;
    }
}

Note that two XML documents are named. The first, res/xml/qwerty.xml, defines the layout so that the KeyboardView class knows how to draw the keyboard.

But the layout which it inflates, res/layout/input.xml, consists of this (simplified):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <android.inputmethodservice.KeyboardView android:id="@+id/keyboard" />
</LinearLayout>

This is all you need to declaratively create a view! Creating a stand-alone View isn’t much different from creating an Activity. You don’t have the standard activity lifecycle, but both environments give you access to XML layouts. All you need to do is use the inflater, reference any subviews you need, and then return the main view.

So hopefully you’ll be able to inflate your layout after thinking about this.


You don’t even need to use XML layouts if your layout is simple enough. If your input method can consist entirely of a single view, you can just instantiate it directly in onCreateInputView. Here’s a complete stub input method service that doesn’t use any XML:

public class MyInputMethod extends InputMethodService {
    MyView view;

    @Override
    public View onCreateInputView() {
        return view = new MyView(this);
    }

}

(Of course the boilerplate in the manifest and res/xml/method.xml files would still be there.)

like image 145
Josh Lee Avatar answered Sep 20 '22 04:09

Josh Lee