1

I'm new on Android Programming, well, on all kind of programming in fact; but I'm trying to adapt the free-code of a translator from a app that I found to a soft keyboard. I need some help because I'm sure that I'm making so big error. Basically due to the app crashes on launch.

public class Keyboard_main extends InputMethodService implements KeyboardView.OnKeyboardActionListener {

public KeyboardView kv = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
private Keyboard keyboard = new Keyboard(this, R.xml.qwerty);
private boolean caps = false;
static final int KEYCODE_TRANSKEY = -1201;

As you can see, I have an specific KEYCODE:

    static final int KEYCODE_TRANSKEY = -1201;

And I applied here later in my Keyboard_main class with onKey():

@Override
public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
    Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    vibrator.vibrate(60);
    playClick(primaryCode);
    switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            ic.deleteSurroundingText(1, 0);
            break;
        case Keyboard.KEYCODE_SHIFT:
            caps = !caps;
            keyboard.setShifted(caps);
            kv.invalidateAllKeys();
            break;
        case Keyboard.KEYCODE_DONE:
            ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
            break;
        case KEYCODE_TRANSKEY:
            View popUpView = getLayoutInflater().inflate(R.layout.main_page, null);
            PopupWindow popupWindow = new PopupWindow(popUpView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
            popupWindow.showAtLocation(popUpView, Gravity.CENTER, 0, 0);
            break;
        default:
            char code = (char) primaryCode;
            if (Character.isLetter(code) && caps) {
                code = Character.toUpperCase(code);
            }
            ic.commitText(String.valueOf(code), 1);
    }}

I forget to mention that my other activity has to be a PopUp due to will be a translator.

Thanks in advance,

ARNAU GONZÁLEZ

SoftWario
  • 11
  • 4
  • "Basically due to the app crashes on launch" -- use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Sep 15 '15 at 20:57
  • Okay thanks a lot, I will give it a try! – SoftWario Sep 16 '15 at 13:00
  • Solved! I just used an Intent and deleted the popUpView! Working fine! And thanks because I found the issue with the LogCat :D – SoftWario Sep 21 '15 at 10:08

0 Answers0