Reputation: 1268
Following this tutorial I have created a fully working Android OS keyboard. it is a standard qwerty alpha/numeric.
I have a second keyboard mark-up for numeric keyboard.
What I can't seem to detect is what type of keyboard is being specified by the text input box. The edittext specifies the type
editText.setInputType(InputType.TYPE_CLASS_TEXT);
but how does my IME service detect this so it can present the correct keyboard?
public class MyKeybdIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
private KeyboardView kv;
private Keyboard keyboard;
private Keyboard numboard;
private boolean caps = false;
@Override
public View onCreateInputView() {
kv = (MKeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.qwertyfull);
numboard = new Keyboard(this, R.xml.num);
// InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//How can you detect what is being asked for?
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
// Or am I on the wrong path for this part?
kv.setKeyboard(keyboard);//... Or numboard when the entry requests a numeric keyboard
kv.setOnKeyboardActionListener(this);
return kv;
}
Upvotes: 1
Views: 841
Reputation: 511746
You can override onStartInput
in your custom keyboard class. Here is a the relevant code taken from the sample Android keyboard:
@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
// ...
switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
case InputType.TYPE_CLASS_NUMBER:
// ...
break;
case InputType.TYPE_CLASS_DATETIME:
// ...
break;
case InputType.TYPE_CLASS_PHONE:
// ...
break;
case InputType.TYPE_CLASS_TEXT:
// ...
break;
default:
// ...
}
// ...
}
Upvotes: 1