Example usage for android.view KeyEvent KEYCODE_0

List of usage examples for android.view KeyEvent KEYCODE_0

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_0.

Prototype

int KEYCODE_0

To view the source code for android.view KeyEvent KEYCODE_0.

Click Source Link

Document

Key code constant: '0' key.

Usage

From source file:com.mattfred.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from w w w.j  av a2  s . c  o  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) {
        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(RadialTimePickerDialogFragment.this, 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;
}

From source file:jp.seesaa.android.datetimepicker.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;
    }//from   www. ja v  a  2 s . co  m

    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() <= 3) {
            mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0);
            mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0);
        }
        //            mDoneButton.setEnabled(true);
    }

    return true;
}

From source file:cn.fulldroid.lib.datetimepicker.time.TimePickerDialog.java

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://from  w  w  w. j av  a  2 s.  c  om
        return -1;
    }
}

From source file:com.android.datetimepicker.time.TimePickerDialog.java

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:// w w w . j a  va2  s.  c  o  m
        return -1;
    }
}

From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key./*ww  w  .  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_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));
                }
                mDelegator.announceForAccessibility(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;
}

From source file:com.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key./*  ww  w . java 2s.c  o  m*/
 *
 * @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;
}

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from www.  j a v a2 s.  c o 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) {
        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);
        }
        doneClickValidateAndCallback();
        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.google.android.apps.mytracks.TrackDetailActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_M:
        if (trackId == recordingTrackId) {
            // Recording
            insertMarkerAction();//  w  w w .jav a 2 s .co  m
        }
        break;
    case KeyEvent.KEYCODE_H:
        if (tabHost.getCurrentTab() == 1) {
            ChartFragment f = (ChartFragment) tabManager.getCurrentFragment();
            f.scrollLeft();
        }
        break;
    case KeyEvent.KEYCODE_K:
        if (tabHost.getCurrentTab() == 1) {
            ChartFragment f = (ChartFragment) tabManager.getCurrentFragment();
            f.scrollRight();
        }
        break;
    case KeyEvent.KEYCODE_0:
        if (tabHost.getCurrentTab() == 2) {
            MapFragment f = (MapFragment) tabManager.getCurrentFragment();
            f.showMyLocation();
        }
        break;

    case KeyEvent.KEYCODE_Q:
        tabHost.setCurrentTab(0);
        break;

    case KeyEvent.KEYCODE_SPACE:
        if ((tabHost.getCurrentTab() == 1)
                && PreferencesUtils.getBoolean(this, R.string.settings_mapsprovider, true)) {
            // Use nogago Maps
        } else {
            tabHost.setCurrentTab(tabHost.getCurrentTab() + 1);
        }
        break;

    case KeyEvent.KEYCODE_I:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (tabHost.getCurrentTab() == 0) {
            Toast.makeText(getApplicationContext(), "Cannot zoom in on statistics", Toast.LENGTH_SHORT).show();
        } else if (tabHost.getCurrentTab() == 1) {
            ChartFragment f = (ChartFragment) tabManager.getCurrentFragment();
            f.zoomIn();
            // Toast.makeText(getApplicationContext(), "Currently at " +
            // f.getClass().toString(), Toast.LENGTH_SHORT).show();
        } else if (tabHost.getCurrentTab() == 2) {
            MapFragment f = (MapFragment) tabManager.getCurrentFragment();
            f.zoomIn();
            // Toast.makeText(getApplicationContext(), "Currently at " +
            // f.getClass().toString(), Toast.LENGTH_SHORT).show();
        }
        break;
    case KeyEvent.KEYCODE_O:
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (tabHost.getCurrentTab() == 0) {
            Toast.makeText(getApplicationContext(), "Cannot zoom in on statistics", Toast.LENGTH_SHORT).show();
        } else if (tabHost.getCurrentTab() == 1) {
            ChartFragment f = (ChartFragment) tabManager.getCurrentFragment();
            f.zoomOut();
            // Toast.makeText(getApplicationContext(), "Currently at " +
            // f.getClass().toString(), Toast.LENGTH_SHORT).show();
        } else if (tabHost.getCurrentTab() == 2) {
            MapFragment f = (MapFragment) tabManager.getCurrentFragment();
            f.zoomOut();
            // Toast.makeText(getApplicationContext(), "Currently at " +
            // f.getClass().toString(), Toast.LENGTH_SHORT).show();
        }
        break;
    case KeyEvent.KEYCODE_P:
        if (recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
            if (recordingTrackPaused) {
                // Paused -> Resume
                Toast.makeText(getApplicationContext(), "Resumed Recording", Toast.LENGTH_LONG).show();
                AnalyticsUtils.sendPageViews(TrackDetailActivity.this, "/action/detail/resume_track");
                updateMenuItems(true, false);
                TrackRecordingServiceConnectionUtils.resumeTrack(trackRecordingServiceConnection);
                trackController.update(true, false);
            } else {
                // Recording -> Paused
                Toast.makeText(getApplicationContext(), "Paused Recording", Toast.LENGTH_LONG).show();
                AnalyticsUtils.sendPageViews(TrackDetailActivity.this, "/action/detail/pause_track");
                updateMenuItems(true, true);
                TrackRecordingServiceConnectionUtils.pauseTrack(trackRecordingServiceConnection);
                trackController.update(true, true);
            }
        } else {
            Toast.makeText(getApplicationContext(), "Cannot pause track that is not recorded.",
                    Toast.LENGTH_LONG).show();
        }
        break;

    case KeyEvent.KEYCODE_S:
        AnalyticsUtils.sendPageViews(TrackDetailActivity.this, "/action/detail/stop_recording");
        updateMenuItems(false, true);
        TrackRecordingServiceConnectionUtils.stopRecording(TrackDetailActivity.this,
                trackRecordingServiceConnection, true);
        break;

    case KeyEvent.KEYCODE_A:
        Intent intent = IntentUtils.newIntent(this, SettingsActivity.class);
        startActivity(intent);
        break;

    }

    return super.onKeyUp(keyCode, event);
}

From source file:cn.fulldroid.lib.datetimepicker.time.TimePickerDialog.java

/**
 * Create a tree for deciding what keys can legally be typed.
 *//*from w  w w. j  ava2 s  .  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(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);
    }
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.// w w w . j  a va  2 s. c om
 * @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));
                }

                AccessibilityUtils.makeAnnouncement(this, 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 is 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;
}