use of android.view.KeyCharacterMap in project android_frameworks_base by ResurrectionRemix.
the class Input method sendText.
/**
* Convert the characters of string text into key event's and send to
* device.
*
* @param text is a string of characters you want to input to the device.
*/
private void sendText(int source, String text) {
StringBuffer buff = new StringBuffer(text);
boolean escapeFlag = false;
for (int i = 0; i < buff.length(); i++) {
if (escapeFlag) {
escapeFlag = false;
if (buff.charAt(i) == 's') {
buff.setCharAt(i, ' ');
buff.deleteCharAt(--i);
}
}
if (buff.charAt(i) == '%') {
escapeFlag = true;
}
}
char[] chars = buff.toString().toCharArray();
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
KeyEvent[] events = kcm.getEvents(chars);
for (int i = 0; i < events.length; i++) {
KeyEvent e = events[i];
if (source != e.getSource()) {
e.setSource(source);
}
injectKeyEvent(e);
}
}
use of android.view.KeyCharacterMap in project HoloEverywhere by Prototik.
the class TimePickerDialog method getAmOrPmKeyCode.
/**
* Get the keycode value for AM and PM in the current language.
*/
private int getAmOrPmKeyCode(int amOrPm) {
// Cache the codes.
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
// Find the first character in the AM/PM text that is unique.
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
char amChar;
char pmChar;
for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
if (amChar != pmChar) {
KeyEvent[] events = kcm.getEvents(new char[] { amChar, pmChar });
// There should be 4 events: a down and up for both AM and PM.
if (events != null && events.length == 4) {
mAmKeyCode = events[0].getKeyCode();
mPmKeyCode = events[2].getKeyCode();
} else {
Log.e(TAG, "Unable to find keycodes for AM and PM.");
}
break;
}
}
}
if (amOrPm == AM) {
return mAmKeyCode;
} else if (amOrPm == PM) {
return mPmKeyCode;
}
return -1;
}
use of android.view.KeyCharacterMap in project android_frameworks_base by crdroidandroid.
the class ToolbarActionBar method onKeyShortcut.
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
Menu menu = mDecorToolbar.getMenu();
if (menu != null) {
final KeyCharacterMap kmap = KeyCharacterMap.load(event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
menu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
menu.performShortcut(keyCode, event, 0);
}
// keyboard shortcuts.
return true;
}
use of android.view.KeyCharacterMap in project android_frameworks_base by crdroidandroid.
the class TextKeyListener method getKeyListener.
private KeyListener getKeyListener(KeyEvent event) {
KeyCharacterMap kmap = event.getKeyCharacterMap();
int kind = kmap.getKeyboardType();
if (kind == KeyCharacterMap.ALPHA) {
return QwertyKeyListener.getInstance(mAutoText, mAutoCap);
} else if (kind == KeyCharacterMap.NUMERIC) {
return MultiTapKeyListener.getInstance(mAutoText, mAutoCap);
} else if (kind == KeyCharacterMap.FULL || kind == KeyCharacterMap.SPECIAL_FUNCTION) {
// these applications should be modified to use KeyCharacterMap.VIRTUAL_KEYBOARD.
return QwertyKeyListener.getInstanceForFullKeyboard();
}
return NullKeyListener.getInstance();
}
use of android.view.KeyCharacterMap in project android_frameworks_base by crdroidandroid.
the class Input method sendText.
/**
* Convert the characters of string text into key event's and send to
* device.
*
* @param text is a string of characters you want to input to the device.
*/
private void sendText(int source, String text) {
StringBuffer buff = new StringBuffer(text);
boolean escapeFlag = false;
for (int i = 0; i < buff.length(); i++) {
if (escapeFlag) {
escapeFlag = false;
if (buff.charAt(i) == 's') {
buff.setCharAt(i, ' ');
buff.deleteCharAt(--i);
}
}
if (buff.charAt(i) == '%') {
escapeFlag = true;
}
}
char[] chars = buff.toString().toCharArray();
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
KeyEvent[] events = kcm.getEvents(chars);
for (int i = 0; i < events.length; i++) {
KeyEvent e = events[i];
if (source != e.getSource()) {
e.setSource(source);
}
injectKeyEvent(e);
}
}
Aggregations