List of usage examples for android.view KeyEvent KEYCODE_0
int KEYCODE_0
To view the source code for android.view KeyEvent KEYCODE_0.
Click Source Link
From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourView && mTypedTimes.size() == 4) || (!mIs24HourView && isTypedTimeFullyLegal())) { return false; }//from w w w . j a v a2s. co m mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); mDelegator.announceForAccessibility(String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourView && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } onValidationChanged(true); } return true; }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
/** * Helper to send a character to the editor as raw key events. *//*from ww w.ja v a 2 s. co m*/ private void sendKey(int keyCode) { switch (keyCode) { case '\n': keyDownUp(KeyEvent.KEYCODE_ENTER); break; default: if (keyCode >= '0' && keyCode <= '9') { keyDownUp(keyCode - '0' + KeyEvent.KEYCODE_0); } else { getCurrentInputConnection().commitText(String.valueOf((char) keyCode), 1); } break; } }
From source file:com.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourView && mTypedTimes.size() == 4) || (!mIs24HourView && isTypedTimeFullyLegal())) { return false; }// ww w. ja v a 2 s . c o m mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); ViewCompatUtils.announceForAccessibility(mDelegator, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourView && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } onValidationChanged(true); } return true; }
From source file:com.borax12.materialdaterangepicker.time.TimePickerDialog.java
/** * For keyboard mode, processes key events. * @param keyCode the pressed key./*from www . j a v a 2 s . c om*/ * @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; }
From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourView && mTypedTimes.size() == 4) || (!mIs24HourView && isTypedTimeFullyLegal())) { return false; }/* w w w .j av a 2s . c o m*/ mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); AccessibilityUtils.makeAnnouncement(this, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourView && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } onValidationChanged(true); } return true; }
From source file:com.philliphsu.bottomsheetpickers.time.grid.GridTimePickerDialog.java
/** * Create a tree for deciding what keys can legally be typed. *//*from w w w . ja v a 2s . c om*/ private void generateLegalTimesTree() { // Create a quick cache of numbers to their keycodes. int k0 = KeyEvent.KEYCODE_0; int k1 = KeyEvent.KEYCODE_1; int k2 = KeyEvent.KEYCODE_2; int k3 = KeyEvent.KEYCODE_3; int k4 = KeyEvent.KEYCODE_4; int k5 = KeyEvent.KEYCODE_5; int k6 = KeyEvent.KEYCODE_6; int k7 = KeyEvent.KEYCODE_7; int k8 = KeyEvent.KEYCODE_8; int k9 = KeyEvent.KEYCODE_9; // The root of the tree doesn't contain any numbers. mLegalTimesTree = new Node(); if (mIs24HourMode) { // We'll be re-using these nodes, so we'll save them. Node minuteFirstDigit = new Node(k0, k1, k2, k3, k4, k5); Node minuteSecondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); // The first digit must be followed by the second digit. minuteFirstDigit.addChild(minuteSecondDigit); // The first digit may be 0-1. Node firstDigit = new Node(k0, k1); mLegalTimesTree.addChild(firstDigit); // When the first digit is 0-1, the second digit may be 0-5. Node secondDigit = new Node(k0, k1, k2, k3, k4, k5); firstDigit.addChild(secondDigit); // We may now be followed by the first minute digit. E.g. 00:09, 15:58. secondDigit.addChild(minuteFirstDigit); // When the first digit is 0-1, and the second digit is 0-5, the third digit may be 6-9. Node thirdDigit = new Node(k6, k7, k8, k9); // The time must now be finished. E.g. 0:55, 1:08. secondDigit.addChild(thirdDigit); // When the first digit is 0-1, the second digit may be 6-9. secondDigit = new Node(k6, k7, k8, k9); firstDigit.addChild(secondDigit); // We must now be followed by the first minute digit. E.g. 06:50, 18:20. secondDigit.addChild(minuteFirstDigit); // The first digit may be 2. firstDigit = new Node(k2); mLegalTimesTree.addChild(firstDigit); // When the first digit is 2, the second digit may be 0-3. secondDigit = new Node(k0, k1, k2, k3); firstDigit.addChild(secondDigit); // We must now be followed by the first minute digit. E.g. 20:50, 23:09. secondDigit.addChild(minuteFirstDigit); // When the first digit is 2, the second digit may be 4-5. secondDigit = new Node(k4, k5); firstDigit.addChild(secondDigit); // We must now be followd by the last minute digit. E.g. 2:40, 2:53. secondDigit.addChild(minuteSecondDigit); // The first digit may be 3-9. firstDigit = new Node(k3, k4, k5, k6, k7, k8, k9); mLegalTimesTree.addChild(firstDigit); // We must now be followed by the first minute digit. E.g. 3:57, 8:12. firstDigit.addChild(minuteFirstDigit); } else { // We'll need to use the AM/PM node a lot. // Set up AM and PM to respond to "a" and "p". Node ampm = new Node(getAmOrPmKeyCode(HALF_DAY_1), getAmOrPmKeyCode(HALF_DAY_2)); // The first hour digit may be 1. Node firstDigit = new Node(k1); mLegalTimesTree.addChild(firstDigit); // We'll allow quick input of on-the-hour times. E.g. 1pm. firstDigit.addChild(ampm); // When the first digit is 1, the second digit may be 0-2. Node secondDigit = new Node(k0, k1, k2); firstDigit.addChild(secondDigit); // Also for quick input of on-the-hour times. E.g. 10pm, 12am. secondDigit.addChild(ampm); // When the first digit is 1, and the second digit is 0-2, the third digit may be 0-5. Node thirdDigit = new Node(k0, k1, k2, k3, k4, k5); secondDigit.addChild(thirdDigit); // The time may be finished now. E.g. 1:02pm, 1:25am. thirdDigit.addChild(ampm); // When the first digit is 1, the second digit is 0-2, and the third digit is 0-5, // the fourth digit may be 0-9. Node fourthDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); thirdDigit.addChild(fourthDigit); // The time must be finished now. E.g. 10:49am, 12:40pm. fourthDigit.addChild(ampm); // When the first digit is 1, and the second digit is 0-2, the third digit may be 6-9. thirdDigit = new Node(k6, k7, k8, k9); secondDigit.addChild(thirdDigit); // The time must be finished now. E.g. 1:08am, 1:26pm. thirdDigit.addChild(ampm); // When the first digit is 1, the second digit may be 3-5. secondDigit = new Node(k3, k4, k5); firstDigit.addChild(secondDigit); // When the first digit is 1, and the second digit is 3-5, the third digit may be 0-9. thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); secondDigit.addChild(thirdDigit); // The time must be finished now. E.g. 1:39am, 1:50pm. thirdDigit.addChild(ampm); // The hour digit may be 2-9. firstDigit = new Node(k2, k3, k4, k5, k6, k7, k8, k9); mLegalTimesTree.addChild(firstDigit); // We'll allow quick input of on-the-hour-times. E.g. 2am, 5pm. firstDigit.addChild(ampm); // When the first digit is 2-9, the second digit may be 0-5. secondDigit = new Node(k0, k1, k2, k3, k4, k5); firstDigit.addChild(secondDigit); // When the first digit is 2-9, and the second digit is 0-5, the third digit may be 0-9. thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); secondDigit.addChild(thirdDigit); // The time must be finished now. E.g. 2:57am, 9:30pm. thirdDigit.addChild(ampm); } }
From source file:com.borax12.materialdaterangepicker.time.TimePickerDialog.java
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourMode && mTypedTimes.size() == 4) || (!mIs24HourMode && isTypedTimeFullyLegal())) { return false; }// w w w . jav a 2 s . co m mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); if (tabHost.getCurrentTab() == 0) { Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val)); } else { Utils.tryAccessibilityAnnounce(mTimePickerEnd, String.format("%d", val)); } // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourMode && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } mOkButton.setEnabled(true); } return true; }
From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java
/** * For keyboard mode, processes key events. * @param keyCode the pressed key./*from w ww . j a v a 2 s. co m*/ * @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; }
From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourMode && mTypedTimes.size() == (mEnableSeconds ? 6 : 4)) || (!mIs24HourMode && isTypedTimeFullyLegal())) { return false; }//from w w w. j a v a 2 s .com mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourMode && mTypedTimes.size() <= (mEnableSeconds ? 5 : 3)) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } mOkButton.setEnabled(true); } return true; }
From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java
/** * Create a tree for deciding what keys can legally be typed. *///from w ww. j a v a 2s . c o m private void generateLegalTimesTree() { // Create a quick cache of numbers to their keycodes. final int k0 = KeyEvent.KEYCODE_0; final int k1 = KeyEvent.KEYCODE_1; final int k2 = KeyEvent.KEYCODE_2; final int k3 = KeyEvent.KEYCODE_3; final int k4 = KeyEvent.KEYCODE_4; final int k5 = KeyEvent.KEYCODE_5; final int k6 = KeyEvent.KEYCODE_6; final int k7 = KeyEvent.KEYCODE_7; final int k8 = KeyEvent.KEYCODE_8; final int k9 = KeyEvent.KEYCODE_9; // The root of the tree doesn't contain any numbers. mLegalTimesTree = new Node(); if (mIs24HourView) { // We'll be re-using these nodes, so we'll save them. Node minuteFirstDigit = new Node(k0, k1, k2, k3, k4, k5); Node minuteSecondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); // The first digit must be followed by the second digit. minuteFirstDigit.addChild(minuteSecondDigit); // The first digit may be 0-1. Node firstDigit = new Node(k0, k1); mLegalTimesTree.addChild(firstDigit); // When the first digit is 0-1, the second digit may be 0-5. Node secondDigit = new Node(k0, k1, k2, k3, k4, k5); firstDigit.addChild(secondDigit); // We may now be followed by the first minute digit. E.g. 00:09, 15:58. secondDigit.addChild(minuteFirstDigit); // When the first digit is 0-1, and the second digit is 0-5, the third digit may be 6-9. Node thirdDigit = new Node(k6, k7, k8, k9); // The time must now be finished. E.g. 0:55, 1:08. secondDigit.addChild(thirdDigit); // When the first digit is 0-1, the second digit may be 6-9. secondDigit = new Node(k6, k7, k8, k9); firstDigit.addChild(secondDigit); // We must now be followed by the first minute digit. E.g. 06:50, 18:20. secondDigit.addChild(minuteFirstDigit); // The first digit may be 2. firstDigit = new Node(k2); mLegalTimesTree.addChild(firstDigit); // When the first digit is 2, the second digit may be 0-3. secondDigit = new Node(k0, k1, k2, k3); firstDigit.addChild(secondDigit); // We must now be followed by the first minute digit. E.g. 20:50, 23:09. secondDigit.addChild(minuteFirstDigit); // When the first digit is 2, the second digit may be 4-5. secondDigit = new Node(k4, k5); firstDigit.addChild(secondDigit); // We must now be followd by the last minute digit. E.g. 2:40, 2:53. secondDigit.addChild(minuteSecondDigit); // The first digit may be 3-9. firstDigit = new Node(k3, k4, k5, k6, k7, k8, k9); mLegalTimesTree.addChild(firstDigit); // We must now be followed by the first minute digit. E.g. 3:57, 8:12. firstDigit.addChild(minuteFirstDigit); } else { // We'll need to use the AM/PM node a lot. // Set up AM and PM to respond to "a" and "p". Node ampm = new Node(getAmOrPmKeyCode(AM), getAmOrPmKeyCode(PM)); // The first hour digit may be 1. Node firstDigit = new Node(k1); mLegalTimesTree.addChild(firstDigit); // We'll allow quick input of on-the-hour times. E.g. 1pm. firstDigit.addChild(ampm); // When the first digit is 1, the second digit may be 0-2. Node secondDigit = new Node(k0, k1, k2); firstDigit.addChild(secondDigit); // Also for quick input of on-the-hour times. E.g. 10pm, 12am. secondDigit.addChild(ampm); // When the first digit is 1, and the second digit is 0-2, the third digit may be 0-5. Node thirdDigit = new Node(k0, k1, k2, k3, k4, k5); secondDigit.addChild(thirdDigit); // The time may be finished now. E.g. 1:02pm, 1:25am. thirdDigit.addChild(ampm); // When the first digit is 1, the second digit is 0-2, and the third digit is 0-5, // the fourth digit may be 0-9. Node fourthDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); thirdDigit.addChild(fourthDigit); // The time must be finished now. E.g. 10:49am, 12:40pm. fourthDigit.addChild(ampm); // When the first digit is 1, and the second digit is 0-2, the third digit may be 6-9. thirdDigit = new Node(k6, k7, k8, k9); secondDigit.addChild(thirdDigit); // The time must be finished now. E.g. 1:08am, 1:26pm. thirdDigit.addChild(ampm); // When the first digit is 1, the second digit may be 3-5. secondDigit = new Node(k3, k4, k5); firstDigit.addChild(secondDigit); // When the first digit is 1, and the second digit is 3-5, the third digit may be 0-9. thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); secondDigit.addChild(thirdDigit); // The time must be finished now. E.g. 1:39am, 1:50pm. thirdDigit.addChild(ampm); // The hour digit may be 2-9. firstDigit = new Node(k2, k3, k4, k5, k6, k7, k8, k9); mLegalTimesTree.addChild(firstDigit); // We'll allow quick input of on-the-hour-times. E.g. 2am, 5pm. firstDigit.addChild(ampm); // When the first digit is 2-9, the second digit may be 0-5. secondDigit = new Node(k0, k1, k2, k3, k4, k5); firstDigit.addChild(secondDigit); // When the first digit is 2-9, and the second digit is 0-5, the third digit may be 0-9. thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9); secondDigit.addChild(thirdDigit); // The time must be finished now. E.g. 2:57am, 9:30pm. thirdDigit.addChild(ampm); } }