0

I made custom keyboardview in Android. I used to this in my application where I don't want to use any other keyboard. Soft keyboard is hide. I can't get capital letters from keyboard. Have you got any idea how can I get capital letter in my editview?

BasicOnKeyboardActionListener

 @Override
public void onKey(int primaryCode, int[] keyCodes) {

    long eventTime = System.currentTimeMillis();
    KeyEvent event = new KeyEvent(eventTime, eventTime,
            KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
            KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
    mTargetActivity.dispatchKeyEvent(event);

I have tried check capital letter with event.isCapsLockOn() and event.isShiftPressed(), but without success. For capslock I used to 115 code, but for shift 59 code in xml for keyboard.

I look forward to receiving your reply. Many thanks

Endrju
  • 1
  • 1

2 Answers2

1

You can use the toUpperCase function for that.

You can also refer following link for the same. Text-transform:uppercase equivalent in Android?

Community
  • 1
  • 1
Mohit Ajwani
  • 1,328
  • 12
  • 24
  • You are right, but I would like to have an opportunity to change size letter between capital letter and non-capital letter from keyboardview. – Endrju Jan 26 '15 at 12:16
0

In your onKey handler, you'll need to know if "shift" has been clicked. You could do something like:

case Keyboard.KEYCODE_SHIFT:
            shifted = !shifted;
            keyboardView.setShifted(shifted);
            keyboardView.invalidateAllKeys();
            break;

Where "shifted" is a field in your listener. This field can be used when you handle key presses for other keys, for example your default onKey implementation could be:

char code = (char) primaryCode;
if (Character.isLetter(code) && shofted) {
    code = Character.toUpperCase(code);
}
commitText(String.valueOf(code), 1);

If your listener extends something like BaseInputConnection then you override getEditable to return the editText you're bound to and you get convenient methods like commitText and deleteSurroundingText.

Check out http://www.fampennings.nl/maarten/android/09keyboard/index.htm for a really nice overview of this sort of behavior.

ejw
  • 151
  • 1
  • 5