1. How do I add a button or edittext to my keyboard?
2. How to close the popupkeyboard?
3. When you open the keyboard, move the text above it to see the cursor?
2. How to close the popupkeyboard?
3. When you open the keyboard, move the text above it to see the cursor?
Java:
package com.saulius;
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputConnection;
import android.view.*;
import android.widget.*;
import java.util.zip.*;
import android.view.ViewTreeObserver.*;
import android.view.View.*;
public class my extends InputMethodService implements KeyboardView.OnKeyboardActionListener
{
Keyboard keyboard;KeyboardView keyboardView;byte caps=0;final int aide=-1000;
@Override
public void onCreate()
{
super.onCreate();
}
@Override
public View onCreateInputView()
{
keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboardview, null);
keyboard = new Keyboard(this, R.layout.mygtukai);
keyboardView.setKeyboard(keyboard);
keyboardView.setOnKeyboardActionListener(this);
return keyboardView;
}
@Override
public void onKey(int primaryCode, int[] keyCodes)
{
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
switch (primaryCode)
{
case Keyboard.KEYCODE_DELETE:
CharSequence selectedText = ic.getSelectedText(0);
if (TextUtils.isEmpty(selectedText))
{
// no selection, so delete previous
ic.deleteSurroundingText(0, 0);
}
else
{
// delete the selection
ic.commitText("", 1);
}
ic.deleteSurroundingText(1, 0);
break;
case aide :break;
case Keyboard.KEYCODE_SHIFT:
if (caps == 0)
{caps = 1;keyboard.setShifted(true);}
else if (caps == 1)
caps = 2;else
{caps = 0;keyboard.setShifted(false);}
keyboardView.invalidateAllKeys();break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char) primaryCode;
if (Character.isLetter(code) && caps > 0)
code = Character.toUpperCase(code);
if (caps == 1)
{caps = 0;keyboard.setShifted(false);keyboardView.invalidateAllKeys();}
ic.commitText(String.valueOf(code), 1);
}
}
@Override
public void onPress(int primaryCode)
{}
@Override
public void onRelease(int primaryCode)
{
}
@Override
public void onText(CharSequence text)
{}
@Override
public void swipeLeft()
{}
@Override
public void swipeRight()
{}
@Override
public void swipeDown()
{}
@Override
public void swipeUp()
{}
}