Example usage for android.view KeyEvent KEYCODE_A

List of usage examples for android.view KeyEvent KEYCODE_A

Introduction

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

Prototype

int KEYCODE_A

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

Click Source Link

Document

Key code constant: 'A' key.

Usage

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Use this to monitor key events being delivered to the application.
 * We get first crack at them, and can either resume them or let them
 * continue to the app./*  w  w w .  j av  a2  s. com*/
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    //event.
    //Log.i("OnKeyDown", "Keycode: "+keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        // The InputMethodService already takes care of the back
        // key for us, to dismiss the input method if it is shown.
        // However, our keyboard could be showing a pop-up window
        // that back should dismiss, so we first allow it to do that.
        if (event.getRepeatCount() == 0 && mInputView != null) {
            if (mInputView.handleBack()) {
                return true;
            }
        }
        break;

    case KeyEvent.KEYCODE_DEL:
        // Special handling of the delete key: if we currently are
        // composing text for the user, we want to modify that instead
        // of let the application to the delete itself.
        if (mComposing.length() > 0) {
            onKey(Keyboard.KEYCODE_DELETE, null);
            return true;
        }
        break;

    case -2: //123 button
        //Log.i("KeyDown", "Keycode: "+keyCode);
        event.startTracking();
        return true;

    case KeyEvent.KEYCODE_ENTER:
        // Let the underlying text editor always handle these.
        return false;

    default:
        // For all other keys, if we want to do transformations on
        // text being entered with a hard keyboard, we need to process
        // it and do the appropriate action.
        if (PROCESS_HARD_KEYS) {
            if (keyCode == KeyEvent.KEYCODE_SPACE && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) {
                // A silly example: in our input method, Alt+Space
                // is a shortcut for 'android' in lower case.
                //InputConnection ic = ic;
                if (ic != null) {
                    // First, tell the editor that it is no longer in the
                    // shift state, since we are consuming this.
                    ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
                    keyDownUp(KeyEvent.KEYCODE_A);
                    keyDownUp(KeyEvent.KEYCODE_N);
                    keyDownUp(KeyEvent.KEYCODE_D);
                    keyDownUp(KeyEvent.KEYCODE_R);
                    keyDownUp(KeyEvent.KEYCODE_O);
                    keyDownUp(KeyEvent.KEYCODE_I);
                    keyDownUp(KeyEvent.KEYCODE_D);
                    // And we consume this event.
                    return true;
                }
            }
            if (mPredictionOn && translateKeyDown(keyCode, event)) {
                return true;
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.android.tv.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    /*//from   w w w  .  j av  a2  s .  c  om
     * The following keyboard keys map to these remote keys or "debug actions"
     *  - --------
     *  A KEYCODE_MEDIA_AUDIO_TRACK
     *  D debug: show debug options
     *  E updateChannelBannerAndShowIfNeeded
     *  I KEYCODE_TV_INPUT
     *  O debug: show display mode option
     *  P debug: togglePipView
     *  S KEYCODE_CAPTIONS: select subtitle
     *  W debug: toggle screen size
     *  V KEYCODE_MEDIA_RECORD debug: record the current channel for 30 sec
     *  X KEYCODE_BUTTON_X KEYCODE_PROG_BLUE debug: record current channel for a few minutes
     *  Y KEYCODE_BUTTON_Y KEYCODE_PROG_GREEN debug: Play a recording
     */
    if (SystemProperties.LOG_KEYEVENT.getValue()) {
        Log.d(TAG, "onKeyUp(" + keyCode + ", " + event + ")");
    }
    // If we are in the middle of channel change, finish it before showing overlays.
    finishChannelChangeIfNeeded();

    if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
        showSearchActivity();
        return true;
    }
    switch (mOverlayManager.onKeyUp(keyCode, event)) {
    case KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY:
        return super.onKeyUp(keyCode, event);
    case KEY_EVENT_HANDLER_RESULT_HANDLED:
        return true;
    case KEY_EVENT_HANDLER_RESULT_NOT_HANDLED:
        return false;
    case KEY_EVENT_HANDLER_RESULT_PASSTHROUGH:
    default:
        // pass through
    }
    if (mSearchFragment.isVisible()) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            getFragmentManager().popBackStack();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // When the event is from onUnhandledInputEvent, onBackPressed is not automatically
        // called. Therefore, we need to explicitly call onBackPressed().
        onBackPressed();
        return true;
    }

    if (!mChannelTuner.areAllChannelsLoaded()) {
        // Now channel map is under loading.
    } else if (mChannelTuner.getBrowsableChannelCount() == 0) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_NUMPAD_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_E:
        case KeyEvent.KEYCODE_MENU:
            showSettingsFragment();
            return true;
        }
    } else {
        if (KeypadChannelSwitchView.isChannelNumberKey(keyCode)) {
            showKeypadChannelSwitchView(keyCode);
            return true;
        }
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!PermissionUtils.hasModifyParentalControls(this)) {
                // TODO: support this feature for non-system LC app. b/23939816
                return true;
            }
            PinDialogFragment dialog = null;
            if (mTvView.isScreenBlocked()) {
                dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_CHANNEL,
                        new PinDialogFragment.ResultListener() {
                            @Override
                            public void done(boolean success) {
                                if (success) {
                                    unblockScreen(mTvView);
                                    mIsCurrentChannelUnblockedByUser = true;
                                }
                            }
                        });
            } else if (mTvView.getBlockedContentRating() != null) {
                final TvContentRating rating = mTvView.getBlockedContentRating();
                dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_PROGRAM,
                        new PinDialogFragment.ResultListener() {
                            @Override
                            public void done(boolean success) {
                                if (success) {
                                    mLastAllowedRatingForCurrentChannel = rating;
                                    mTvView.unblockContent(rating);
                                }
                            }
                        });
            }
            if (dialog != null) {
                mOverlayManager.showDialogFragment(PinDialogFragment.DIALOG_TAG, dialog, false);
            }
            return true;

        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_NUMPAD_ENTER:
        case KeyEvent.KEYCODE_E:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_MENU:
            if (event.isCanceled()) {
                // Ignore canceled key.
                // Note that if there's a TIS granted RECEIVE_INPUT_EVENT,
                // fallback keys not blacklisted will have FLAG_CANCELED.
                // See dispatchKeyEvent() for detail.
                return true;
            }
            if (keyCode != KeyEvent.KEYCODE_MENU) {
                updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_FORCE_SHOW);
            }
            if (keyCode != KeyEvent.KEYCODE_E) {
                mOverlayManager.showMenu(
                        mTvView.isRecordingPlayback() ? Menu.REASON_RECORDING_PLAYBACK : Menu.REASON_NONE);
            }
            return true;
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            // Channel change is already done in the head of this method.
            return true;
        case KeyEvent.KEYCODE_S:
            if (!SystemProperties.USE_DEBUG_KEYS.getValue()) {
                break;
            }
        case KeyEvent.KEYCODE_CAPTIONS: {
            mOverlayManager.getSideFragmentManager().show(new ClosedCaptionFragment());
            return true;
        }
        case KeyEvent.KEYCODE_A:
            if (!SystemProperties.USE_DEBUG_KEYS.getValue()) {
                break;
            }
        case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
            mOverlayManager.getSideFragmentManager().show(new MultiAudioFragment());
            return true;
        }
        case KeyEvent.KEYCODE_GUIDE: {
            mOverlayManager.showProgramGuide();
            return true;
        }
        case KeyEvent.KEYCODE_INFO: {
            mOverlayManager.showBanner();
            return true;
        }
        }
    }
    if (SystemProperties.USE_DEBUG_KEYS.getValue()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_W: {
            mDebugNonFullSizeScreen = !mDebugNonFullSizeScreen;
            if (mDebugNonFullSizeScreen) {
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams();
                params.width = 960;
                params.height = 540;
                params.gravity = Gravity.START;
                mTvView.setLayoutParams(params);
            } else {
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams();
                params.width = ViewGroup.LayoutParams.MATCH_PARENT;
                params.height = ViewGroup.LayoutParams.MATCH_PARENT;
                params.gravity = Gravity.CENTER;
                mTvView.setLayoutParams(params);
            }
            return true;
        }
        case KeyEvent.KEYCODE_P: {
            togglePipView();
            return true;
        }
        case KeyEvent.KEYCODE_CTRL_LEFT:
        case KeyEvent.KEYCODE_CTRL_RIGHT: {
            mUseKeycodeBlacklist = !mUseKeycodeBlacklist;
            return true;
        }
        case KeyEvent.KEYCODE_O: {
            mOverlayManager.getSideFragmentManager().show(new DisplayModeFragment());
            return true;
        }

        case KeyEvent.KEYCODE_D:
            mOverlayManager.getSideFragmentManager().show(new DebugOptionFragment());
            return true;

        case KeyEvent.KEYCODE_MEDIA_RECORD: // TODO(DVR) handle with debug_keys set
        case KeyEvent.KEYCODE_V: {
            DvrManager dvrManager = TvApplication.getSingletons(this).getDvrManager();
            long startTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(5);
            long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(35);
            dvrManager.addSchedule(getCurrentChannel(), startTime, endTime);
            return true;
        }
        case KeyEvent.KEYCODE_PROG_BLUE:
        case KeyEvent.KEYCODE_BUTTON_X:
        case KeyEvent.KEYCODE_X: {
            if (CommonFeatures.DVR.isEnabled(this)) {
                Channel channel = mTvView.getCurrentChannel();
                long channelId = channel.getId();
                Program p = mProgramDataManager.getCurrentProgram(channelId);
                if (p == null) {
                    long now = System.currentTimeMillis();
                    mDvrManager.addSchedule(channel, now, now + TimeUnit.MINUTES.toMillis(1));
                } else {
                    mDvrManager.addSchedule(p, mDvrManager.getScheduledRecordingsThatConflict(p));
                }
                return true;
            }
        }
        case KeyEvent.KEYCODE_PROG_YELLOW:
        case KeyEvent.KEYCODE_BUTTON_Y:
        case KeyEvent.KEYCODE_Y: {
            if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
                // TODO(DVR) only get finished recordings.
                List<RecordedProgram> recordedPrograms = mDvrDataManager.getRecordedPrograms();
                Log.d(TAG, "Found " + recordedPrograms.size() + "  recordings");
                if (recordedPrograms.isEmpty()) {
                    Toast.makeText(this, "No finished recording to play", Toast.LENGTH_LONG).show();
                } else {
                    RecordedProgram r = recordedPrograms.get(0);
                    Intent intent = new Intent(this, DvrPlayActivity.class);
                    intent.putExtra(ScheduledRecording.RECORDING_ID_EXTRA, r.getId());
                    startActivity(intent);
                }
                return true;
            }
        }
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

/**
 * Handle hotkeys/*from w  ww  . j a  v  a 2  s .co  m*/
 * 
 * <p>
 * This method is called by {@link #dispatchKeyEvent(KeyEvent)} before any
 * view had the chance to consume this key event.
 * </p>
 * 
 * @param keyCode
 *            The value in {@code event.getKeyCode()}.
 * @param event
 *            Description of the key event.
 * 
 * @return {@code true} if this event was consumed.
 */
public boolean onCustomKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP: {
        if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST
                && K9.useVolumeKeysForNavigationEnabled()) {
            showPreviousMessage();
            return true;
        } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveUp();
            return true;
        }

        break;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST
                && K9.useVolumeKeysForNavigationEnabled()) {
            showNextMessage();
            return true;
        } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveDown();
            return true;
        }

        break;
    }
    case KeyEvent.KEYCODE_C: {
        mMessageListFragment.onCompose();
        return true;
    }
    case KeyEvent.KEYCODE_Q: {
        if (mMessageListFragment != null && mMessageListFragment.isSingleAccountMode()) {
            onShowFolderList();
        }
        return true;
    }
    case KeyEvent.KEYCODE_O: {
        mMessageListFragment.onCycleSort();
        return true;
    }
    case KeyEvent.KEYCODE_I: {
        mMessageListFragment.onReverseSort();
        return true;
    }
    case KeyEvent.KEYCODE_DEL:
    case KeyEvent.KEYCODE_D: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onDelete();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onDelete();
        }
        return true;
    }
    case KeyEvent.KEYCODE_S: {
        mMessageListFragment.toggleMessageSelect();
        return true;
    }
    case KeyEvent.KEYCODE_G: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleFlagged();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleFlagged();
        }
        return true;
    }
    case KeyEvent.KEYCODE_M: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onMove();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onMove();
        }
        return true;
    }
    case KeyEvent.KEYCODE_V: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onArchive();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onArchive();
        }
        return true;
    }
    case KeyEvent.KEYCODE_Y: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onCopy();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onCopy();
        }
        return true;
    }
    case KeyEvent.KEYCODE_Z: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleRead();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleRead();
        }
        return true;
    }
    case KeyEvent.KEYCODE_F: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onForward();
        }
        return true;
    }
    case KeyEvent.KEYCODE_A: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onReplyAll();
        }
        return true;
    }
    case KeyEvent.KEYCODE_R: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onReply();
        }
        return true;
    }
    case KeyEvent.KEYCODE_J:
    case KeyEvent.KEYCODE_P: {
        if (mMessageViewFragment != null) {
            showPreviousMessage();
        }
        return true;
    }
    case KeyEvent.KEYCODE_N:
    case KeyEvent.KEYCODE_K: {
        if (mMessageViewFragment != null) {
            showNextMessage();
        }
        return true;
    }
    /*
     * FIXME case KeyEvent.KEYCODE_Z: { mMessageViewFragment.zoom(event);
     * return true; }
     */
    case KeyEvent.KEYCODE_H: {
        Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG);
        toast.show();
        return true;
    }

    }

    return false;
}