Java Code Examples for android.view.KeyEvent#KEYCODE_9
The following examples show how to use
android.view.KeyEvent#KEYCODE_9 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimePickerDialog.java From Conquer with Apache License 2.0 | 6 votes |
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; } }
Example 2
Source File: SwitchTimePicker.java From Android-SwitchDateTimePicker with Apache License 2.0 | 6 votes |
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; } }
Example 3
Source File: TimePickerDialog.java From Blackbulb with GNU General Public License v3.0 | 6 votes |
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; } }
Example 4
Source File: SublimeTimePicker.java From SublimePicker with Apache License 2.0 | 6 votes |
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; } }
Example 5
Source File: GridTimePickerDialog.java From BottomSheetPickers with Apache License 2.0 | 6 votes |
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; } }
Example 6
Source File: TimePickerDialog.java From MaterialDateRangePicker with Apache License 2.0 | 6 votes |
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; } }
Example 7
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 4 votes |
/** * 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; }
Example 8
Source File: TimePickerDialog.java From date_picker_converter with Apache License 2.0 | 4 votes |
/** * 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(mLocale, "%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; }
Example 9
Source File: SwitchTimePicker.java From Android-SwitchDateTimePicker with Apache License 2.0 | 4 votes |
/** * 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 (onTimeSelectedListener != null) { onTimeSelectedListener.onTimeSelected(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(Locale.getDefault(), "%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; }
Example 10
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 4 votes |
/** * 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; }
Example 11
Source File: TimePickerDialog.java From Conquer with Apache License 2.0 | 4 votes |
/** * 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; }
Example 12
Source File: DialpadFragment.java From call_manage with MIT License | 4 votes |
/** * Act when a key is pressed (Plays tune and sets the text) * * @param keyCode */ private void keyPressed(int keyCode) { updatePreferences(); if (getView().getTranslationY() != 0) { return; } if (!mIsSilent) { switch (keyCode) { case KeyEvent.KEYCODE_1: playTone(ToneGenerator.TONE_DTMF_1); break; case KeyEvent.KEYCODE_2: playTone(ToneGenerator.TONE_DTMF_2); break; case KeyEvent.KEYCODE_3: playTone(ToneGenerator.TONE_DTMF_3); break; case KeyEvent.KEYCODE_4: playTone(ToneGenerator.TONE_DTMF_4); break; case KeyEvent.KEYCODE_5: playTone(ToneGenerator.TONE_DTMF_5); break; case KeyEvent.KEYCODE_6: playTone(ToneGenerator.TONE_DTMF_6); break; case KeyEvent.KEYCODE_7: playTone(ToneGenerator.TONE_DTMF_7); break; case KeyEvent.KEYCODE_8: playTone(ToneGenerator.TONE_DTMF_8); break; case KeyEvent.KEYCODE_9: playTone(ToneGenerator.TONE_DTMF_9); break; case KeyEvent.KEYCODE_0: playTone(ToneGenerator.TONE_DTMF_0); break; case KeyEvent.KEYCODE_POUND: playTone(ToneGenerator.TONE_DTMF_P); break; case KeyEvent.KEYCODE_STAR: playTone(ToneGenerator.TONE_DTMF_S); break; default: break; } } vibrate(); KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); // Add the digit to mDigits mDigits.onKeyDown(keyCode, event); // An option for an outer response if (mOnKeyDownListener != null) mOnKeyDownListener.onKeyPressed(keyCode, event); // If the cursor is at the end of the text we hide it. final int length = mDigits.length(); if (length == mDigits.getSelectionStart() && length == mDigits.getSelectionEnd()) { mDigits.setCursorVisible(false); } }
Example 13
Source File: SudokuBoardView.java From opensudoku with GNU General Public License v3.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (!mReadonly) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: return moveCellSelection(0, -1); case KeyEvent.KEYCODE_DPAD_RIGHT: return moveCellSelection(1, 0); case KeyEvent.KEYCODE_DPAD_DOWN: return moveCellSelection(0, 1); case KeyEvent.KEYCODE_DPAD_LEFT: return moveCellSelection(-1, 0); case KeyEvent.KEYCODE_0: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_DEL: // clear value in selected cell // TODO: I'm not really sure that this is thread-safe if (mSelectedCell != null) { if (event.isShiftPressed() || event.isAltPressed()) { setCellNote(mSelectedCell, CellNote.EMPTY); } else { setCellValue(mSelectedCell, 0); moveCellSelectionRight(); } } return true; case KeyEvent.KEYCODE_DPAD_CENTER: if (mSelectedCell != null) { onCellTapped(mSelectedCell); } return true; } if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9 && mSelectedCell != null) { int selNumber = keyCode - KeyEvent.KEYCODE_0; Cell cell = mSelectedCell; if (event.isShiftPressed() || event.isAltPressed()) { // add or remove number in cell's note setCellNote(cell, cell.getNote().toggleNumber(selNumber)); } else { // enter number in cell setCellValue(cell, selNumber); moveCellSelectionRight(); } return true; } } return false; }
Example 14
Source File: Apps.java From emerald with GNU General Public License v3.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) { return super.onKeyDown(keyCode, event); } if (keyCode == KeyEvent.KEYCODE_MENU) { menu(); return true; } else if (keyCode == KeyEvent.KEYCODE_BACK) { //Log.v(APP_TAG, "BACK pressed"); if (searchIsOpened) { closeSearch(); } else if (!isDefaultLauncher()) { finish(); return true; } else { if (categories.getCurCategory().equals(CategoryManager.HIDDEN)) { findViewById(R.id.quit_hidden_apps).setVisibility(View.GONE); hideMainBarIfNeeded(); } categories.prevCategory(); } loadFilteredApps(); return true; } else if (event.isAltPressed()) { if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) { Object app = dock.getApp(keyCode-KeyEvent.KEYCODE_1); if (app != null) { if (app instanceof AppData) { launch((AppData)app); } else if (app instanceof ShortcutData) { launch((ShortcutData)app); } return true; } else { return super.onKeyDown(keyCode, event); } } else if (keyCode == KeyEvent.KEYCODE_0 && !searchIsOpened) { openSearch(); } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS)); loadFilteredApps(); } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { categories.setCurCategory(categories.getCategory(CategoryManager.NEXT)); loadFilteredApps(); } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { openCategoriesList(); } else { return super.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { View view = getCurrentFocus(); if (view != null) { Object viewTag = view.getTag(); if (viewTag instanceof AppData) { launch((AppData)viewTag); return true; } else if (viewTag instanceof ShortcutData) { launch((ShortcutData)viewTag); return true; } return super.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (options.getBoolean(Keys.VOLUME_BUTTONS, false)) { categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS)); loadFilteredApps(); return true; } else { return super.onKeyDown(keyCode, event); } } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (options.getBoolean(Keys.VOLUME_BUTTONS, false)) { categories.setCurCategory(categories.getCategory(CategoryManager.NEXT)); loadFilteredApps(); return true; } else { return super.onKeyDown(keyCode, event); } } else { return super.onKeyDown(keyCode, event); } }
Example 15
Source File: AppCompatTimePickerDelegate.java From AppCompat-Extension-Library with Apache License 2.0 | 4 votes |
/** * 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_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)); } ViewCompatUtils.announceForAccessibility(mDelegator, 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 || (!mIs24HourView && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mRadialTimePickerView == 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; }
Example 16
Source File: TimePickerDialog.java From MaterialDateTimePicker with Apache License 2.0 | 4 votes |
/** * 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_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(mLocale, "%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; }
Example 17
Source File: TimePickerDialog.java From MaterialDateRangePicker with Apache License 2.0 | 4 votes |
/** * 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(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes(),mTimePickerEnd.getHours(), mTimePickerEnd.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)); } if(tabHost.getCurrentTab()==0){ Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); }else{ Utils.tryAccessibilityAnnounce(mTimePickerEnd, 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; }
Example 18
Source File: TimePickerDialog.java From DateTimepicker with Apache License 2.0 | 4 votes |
/** * 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; }
Example 19
Source File: DialPadView.java From FamilyChat with Apache License 2.0 | 4 votes |
private void keyPressed(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_1: triggerFeedBack(ToneGenerator.TONE_DTMF_1, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_2: triggerFeedBack(ToneGenerator.TONE_DTMF_2, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_3: triggerFeedBack(ToneGenerator.TONE_DTMF_3, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_4: triggerFeedBack(ToneGenerator.TONE_DTMF_4, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_5: triggerFeedBack(ToneGenerator.TONE_DTMF_5, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_6: triggerFeedBack(ToneGenerator.TONE_DTMF_6, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_7: triggerFeedBack(ToneGenerator.TONE_DTMF_7, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_8: triggerFeedBack(ToneGenerator.TONE_DTMF_8, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_9: triggerFeedBack(ToneGenerator.TONE_DTMF_9, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_0: triggerFeedBack(ToneGenerator.TONE_DTMF_0, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_POUND: triggerFeedBack(ToneGenerator.TONE_DTMF_P, TONE_LENGTH_INFINITE); break; case KeyEvent.KEYCODE_STAR: triggerFeedBack(ToneGenerator.TONE_DTMF_S, TONE_LENGTH_INFINITE); break; default: break; } KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); mEdInput.onKeyDown(keyCode, event); // 如果光标在文本末尾就隐藏光标 final int length = mEdInput.length(); if (length == mEdInput.getSelectionStart() && length == mEdInput.getSelectionEnd()) mEdInput.setCursorVisible(false); }
Example 20
Source File: TimePickerDialog.java From AlarmOn with Apache License 2.0 | 4 votes |
/** * 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(mTimePicker, 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; }