本文整理汇总了Java中android.view.KeyEvent.KEYCODE_9属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.KEYCODE_9属性的具体用法?Java KeyEvent.KEYCODE_9怎么用?Java KeyEvent.KEYCODE_9使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.KEYCODE_9属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValFromKeyCode
private static int getValFromKeyCode(int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_0:
return 0;
case KeyEvent.KEYCODE_1:
return 1;
case KeyEvent.KEYCODE_2:
return 2;
case KeyEvent.KEYCODE_3:
return 3;
case KeyEvent.KEYCODE_4:
return 4;
case KeyEvent.KEYCODE_5:
return 5;
case KeyEvent.KEYCODE_6:
return 6;
case KeyEvent.KEYCODE_7:
return 7;
case KeyEvent.KEYCODE_8:
return 8;
case KeyEvent.KEYCODE_9:
return 9;
default:
return -1;
}
}
示例2: getValFromKeyCode
private int getValFromKeyCode(int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_0:
return 0;
case KeyEvent.KEYCODE_1:
return 1;
case KeyEvent.KEYCODE_2:
return 2;
case KeyEvent.KEYCODE_3:
return 3;
case KeyEvent.KEYCODE_4:
return 4;
case KeyEvent.KEYCODE_5:
return 5;
case KeyEvent.KEYCODE_6:
return 6;
case KeyEvent.KEYCODE_7:
return 7;
case KeyEvent.KEYCODE_8:
return 8;
case KeyEvent.KEYCODE_9:
return 9;
default:
return -1;
}
}
示例3: sendDtmf
/**
* Send a dtmf signal to a call
*
* @param callId the call to send the signal
* @param keyCode the keyCode to send (android style)
* @return
*/
public int sendDtmf(int callId, int keyCode) throws SameThreadException {
if (!created) {
return -1;
}
String keyPressed = "";
// Since some device (xoom...) are apparently buggy with key character
// map loading...
// we have to do crappy thing here
if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {
keyPressed = Integer.toString(keyCode - KeyEvent.KEYCODE_0);
} else if (keyCode == KeyEvent.KEYCODE_POUND) {
keyPressed = "#";
} else if (keyCode == KeyEvent.KEYCODE_STAR) {
keyPressed = "*";
} else {
// Fallback... should never be there if using visible dialpad, but
// possible using keyboard
KeyCharacterMap km = KeyCharacterMap.load(KeyCharacterMap.NUMERIC);
keyPressed = Integer.toString(km.getNumber(keyCode));
}
return sendDtmf(callId, keyPressed);
}
示例4: onKey
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.isShiftPressed()) {// Handle * # and other keys
return false;
}
if (keyCode >= KeyEvent.KEYCODE_0
&& keyCode <= KeyEvent.KEYCODE_9) {// Only deal with
// numbers
if (result.size() < pswLength) {
result.add(keyCode - 7);
invalidate();
ensureFinishInput();
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_DEL) {
if (!result.isEmpty()) {// Not empty, delete the last one
saveResult = result.size();
result.remove(result.size() - 1);
invalidate();
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_ENTER) {
ensureFinishInput();
return true;
}
}
return false;
}
示例5: sendFunctionKey
/**
* @param key
* @return successful
*/
private boolean sendFunctionKey(int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_1:
((vt320) buffer).keyPressed(vt320.KEY_F1, ' ', 0);
return true;
case KeyEvent.KEYCODE_2:
((vt320) buffer).keyPressed(vt320.KEY_F2, ' ', 0);
return true;
case KeyEvent.KEYCODE_3:
((vt320) buffer).keyPressed(vt320.KEY_F3, ' ', 0);
return true;
case KeyEvent.KEYCODE_4:
((vt320) buffer).keyPressed(vt320.KEY_F4, ' ', 0);
return true;
case KeyEvent.KEYCODE_5:
((vt320) buffer).keyPressed(vt320.KEY_F5, ' ', 0);
return true;
case KeyEvent.KEYCODE_6:
((vt320) buffer).keyPressed(vt320.KEY_F6, ' ', 0);
return true;
case KeyEvent.KEYCODE_7:
((vt320) buffer).keyPressed(vt320.KEY_F7, ' ', 0);
return true;
case KeyEvent.KEYCODE_8:
((vt320) buffer).keyPressed(vt320.KEY_F8, ' ', 0);
return true;
case KeyEvent.KEYCODE_9:
((vt320) buffer).keyPressed(vt320.KEY_F9, ' ', 0);
return true;
case KeyEvent.KEYCODE_0:
((vt320) buffer).keyPressed(vt320.KEY_F10, ' ', 0);
return true;
default:
return false;
}
}
示例6: onKey
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.isShiftPressed()) {//处理*#等键
return false;
}
if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {//只处理数字
if (result.size() < count) {
result.add(keyCode - 7);
invalidate();
ensureFinishInput();
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_DEL) {
if (!result.isEmpty()) {//不为空,删除最后一个
result.remove(result.size() - 1);
invalidate();
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_ENTER) {
ensureFinishInput();
return true;
}
}
return false;
}
示例7: onKey
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.isShiftPressed()) {//处理*#等键
return false;
}
if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {//只处理数字
if (result.size() < pswLength) {
result.add(keyCode - 7);
invalidate();
FinishInput();
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_DEL) {
if (!result.isEmpty()) {//不为空时,删除最后一个数字
saveResult = result.size();
result.remove(result.size() - 1);
invalidate();
}
return true;
}
if (keyCode == KeyEvent.KEYCODE_ENTER) {
FinishInput();
return true;
}
}
return false;
}
示例8: sendKeyEvent
@Override
public boolean sendKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() >= KeyEvent.KEYCODE_0
&& event.getKeyCode() <= KeyEvent.KEYCODE_9) {
char c = event.getKeyCharacterMap().getNumber(event.getKeyCode());
commitText(String.valueOf(c), 1);
} else if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
deleteSurroundingText(1, 0);
}
}
return super.sendKeyEvent(event);
}
示例9: isKeyCodeNumeric
private static boolean isKeyCodeNumeric(int keyCode) {
return keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
|| keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
|| keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
|| keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
|| keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9;
}
示例10: processKeyUp
/**
* For keyboard mode, processes key events.
*
* @param keyCode the pressed key.
* @return true if the key was successfully processed, false otherwise.
*/
private boolean processKeyUp(int keyCode) {
if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
if (mInKbMode) {
if (isTypedTimeFullyLegal()) {
finishKbMode(true);
}
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (mInKbMode) {
if (!isTypedTimeFullyLegal()) {
return true;
}
finishKbMode(false);
}
sendBroadcastResult();
handleCallbackResult(mTimePicker);
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
if (mInKbMode) {
if (!mTypedTimes.isEmpty()) {
int deleted = deleteLastTypedKey();
String deletedKeyStr;
if (deleted == getAmOrPmKeyCode(AM)) {
deletedKeyStr = mAmText;
} else if (deleted == getAmOrPmKeyCode(PM)) {
deletedKeyStr = mPmText;
} else {
deletedKeyStr = String.format(Locale.ENGLISH, "%d", getValFromKeyCode(deleted));
}
Utils.tryAccessibilityAnnounce(mTimePicker,
String.format(mDeletedKeyFormat, deletedKeyStr));
updateDisplay(true);
}
}
} else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
|| keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
|| keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
|| keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
|| keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
|| (!mIs24HourMode &&
(keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
if (!mInKbMode) {
if (mTimePicker == null) {
// Something's wrong, because time picker should definitely not be null.
Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
return true;
}
mTypedTimes.clear();
tryStartingKbMode(keyCode);
return true;
}
// We're already in keyboard mode.
if (addKeyIfLegal(keyCode)) {
updateDisplay(false);
}
return true;
}
return false;
}
示例11: processKeyUp
/**
* For keyboard mode, processes key events.
*
* @param keyCode the pressed key.
* @return true if the key was successfully processed, false otherwise.
*/
private boolean processKeyUp(int keyCode) {
if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
if (mInKbMode) {
if (isTypedTimeFullyLegal()) {
finishKbMode(true);
}
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (mInKbMode) {
if (!isTypedTimeFullyLegal()) {
return true;
}
finishKbMode(false);
}
if (mCallback != null) {
mCallback.onTimeSet(mTimePicker,
mTimePicker.getHours(), mTimePicker.getMinutes());
}
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
if (mInKbMode) {
if (!mTypedTimes.isEmpty()) {
int deleted = deleteLastTypedKey();
String deletedKeyStr;
if (deleted == getAmOrPmKeyCode(AM)) {
deletedKeyStr = mAmText;
} else if (deleted == getAmOrPmKeyCode(PM)) {
deletedKeyStr = mPmText;
} else {
deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
}
Utils.tryAccessibilityAnnounce(mTimePicker,
String.format(mDeletedKeyFormat, deletedKeyStr));
updateDisplay(true);
}
}
} else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
|| keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
|| keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
|| keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
|| keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
|| (!mIs24HourMode &&
(keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
if (!mInKbMode) {
if (mTimePicker == null) {
// Something's wrong, because time picker should definitely not be null.
Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
return true;
}
mTypedTimes.clear();
tryStartingKbMode(keyCode);
return true;
}
// We're already in keyboard mode.
if (addKeyIfLegal(keyCode)) {
updateDisplay(false);
}
return true;
}
return false;
}
示例12: processKeyUp
/**
* For keyboard mode, processes key events.
* @param keyCode the pressed key.
* @return true if the key was successfully processed, false otherwise.
*/
private boolean processKeyUp(int keyCode) {
if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
if(isCancelable()) dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
if(mInKbMode) {
if (isTypedTimeFullyLegal()) {
finishKbMode(true);
}
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (mInKbMode) {
if (!isTypedTimeFullyLegal()) {
return true;
}
finishKbMode(false);
}
if (mCallback != null) {
mCallback.onTimeSet(this,
mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
}
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
if (mInKbMode) {
if (!mTypedTimes.isEmpty()) {
int deleted = deleteLastTypedKey();
String deletedKeyStr;
if (deleted == getAmOrPmKeyCode(AM)) {
deletedKeyStr = mAmText;
} else if (deleted == getAmOrPmKeyCode(PM)) {
deletedKeyStr = mPmText;
} else {
deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
}
Utils.tryAccessibilityAnnounce(mTimePicker,
String.format(mDeletedKeyFormat, deletedKeyStr));
updateDisplay(true);
}
}
} else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
|| keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
|| keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
|| keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
|| keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
|| (!mIs24HourMode &&
(keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
if (!mInKbMode) {
if (mTimePicker == null) {
// Something's wrong, because time picker should definitely not be null.
Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
return true;
}
mTypedTimes.clear();
tryStartingKbMode(keyCode);
return true;
}
// We're already in keyboard mode.
if (addKeyIfLegal(keyCode)) {
updateDisplay(false);
}
return true;
}
return false;
}