本文整理匯總了Java中android.view.KeyEvent.getCharacters方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.getCharacters方法的具體用法?Java KeyEvent.getCharacters怎麽用?Java KeyEvent.getCharacters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.getCharacters方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onKeyMultiple
import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, final KeyEvent event)
{
if( event.getCharacters() != null )
{
// International text input
for(int i = 0; i < event.getCharacters().length(); i++ )
{
nativeKey( event.getKeyCode(), 1, event.getCharacters().codePointAt(i), 0 );
nativeKey( event.getKeyCode(), 0, event.getCharacters().codePointAt(i), 0 );
}
}
return true;
}
示例2: sendKeyEvent
import android.view.KeyEvent; //導入方法依賴的package包/類
public void sendKeyEvent(final KeyEvent keyEvent) {
if (DEBUG_BATCH_NESTING) checkBatchEdit();
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
// This method is only called for enter or backspace when speaking to old applications
// (target SDK <= 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)), or for digits.
// When talking to new applications we never use this method because it's inherently
// racy and has unpredictable results, but for backward compatibility we continue
// sending the key events for only Enter and Backspace because some applications
// mistakenly catch them to do some stuff.
switch (keyEvent.getKeyCode()) {
case KeyEvent.KEYCODE_ENTER:
mCommittedTextBeforeComposingText.append("\n");
mExpectedSelStart += 1;
mExpectedSelEnd = mExpectedSelStart;
break;
case KeyEvent.KEYCODE_DEL:
if (0 == mComposingText.length()) {
if (mCommittedTextBeforeComposingText.length() > 0) {
mCommittedTextBeforeComposingText.delete(
mCommittedTextBeforeComposingText.length() - 1,
mCommittedTextBeforeComposingText.length());
}
} else {
mComposingText.delete(mComposingText.length() - 1, mComposingText.length());
}
if (mExpectedSelStart > 0 && mExpectedSelStart == mExpectedSelEnd) {
// TODO: Handle surrogate pairs.
mExpectedSelStart -= 1;
}
mExpectedSelEnd = mExpectedSelStart;
break;
case KeyEvent.KEYCODE_UNKNOWN:
if (null != keyEvent.getCharacters()) {
mCommittedTextBeforeComposingText.append(keyEvent.getCharacters());
mExpectedSelStart += keyEvent.getCharacters().length();
mExpectedSelEnd = mExpectedSelStart;
}
break;
default:
final String text = StringUtils.newSingleCodePointString(keyEvent.getUnicodeChar());
mCommittedTextBeforeComposingText.append(text);
mExpectedSelStart += text.length();
mExpectedSelEnd = mExpectedSelStart;
break;
}
}
if (isConnected()) {
mIC.sendKeyEvent(keyEvent);
}
}