Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

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

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:com.android.talkback.SpeechController.java

/**
 * Stops the TTS engine when the Ctrl key is tapped without any other keys.
 *///from  w  ww .  j av a  2 s  .  co  m
@Override
public boolean onKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        mInterruptKeyDown = (keyCode == KeyEvent.KEYCODE_CTRL_LEFT || keyCode == KeyEvent.KEYCODE_CTRL_RIGHT);
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        if (mInterruptKeyDown
                && (keyCode == KeyEvent.KEYCODE_CTRL_LEFT || keyCode == KeyEvent.KEYCODE_CTRL_RIGHT)) {
            mInterruptKeyDown = false;
            mService.interruptAllFeedback();
        }
    }

    return false;
}

From source file:org.zirco.ui.activities.MainActivity.java

/**
 * Select Text in the webview and automatically sends the selected text to the clipboard.
 *//*from   w w  w.  j a  v a 2  s. com*/
public void swithToSelectAndCopyTextMode() {
    try {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
        shiftPressEvent.dispatch(mCurrentWebView);
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

From source file:com.vuze.android.remote.fragment.FilesFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }// w  ww  .j  av  a 2  s  .c o  m
    switch (keyCode) {
    // NOTE:
    // KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_MENU);
    case KeyEvent.KEYCODE_MENU:
    case KeyEvent.KEYCODE_BUTTON_X:
    case KeyEvent.KEYCODE_INFO: {
        if (tb == null) {
            if (showFileContextMenu()) {
                return true;
            }
        }
        break;
    }
    }

    return false;
}

From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent evt) {

    boolean consumed = false;
    if (keyCode == KeyEvent.KEYCODE_BACK && chat_layout.getVisibility() == View.VISIBLE) {

        chat_layout.setVisibility(View.GONE);
        return false;
    }/*from   w  w w.j a v a2s. com*/
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (evt.getAction() == KeyEvent.ACTION_DOWN)
            return super.onKeyDown(keyCode, evt);
        else
            return super.onKeyUp(keyCode, evt);
    }

    try {
        if (evt.getAction() == KeyEvent.ACTION_DOWN || evt.getAction() == KeyEvent.ACTION_MULTIPLE) {
            consumed = inputHandler.onKeyDown(keyCode, evt);
        } else if (evt.getAction() == KeyEvent.ACTION_UP) {
            consumed = inputHandler.onKeyUp(keyCode, evt);
        }

        resetOnScreenKeys(keyCode);
    } catch (NullPointerException e) {
    }

    return consumed;
}

From source file:com.android.mail.ui.ConversationViewFragment.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        mOriginalKeyedView = view;//from w ww  .j a va 2 s.  c o m
    }

    if (mOriginalKeyedView != null) {
        final int id = mOriginalKeyedView.getId();
        final boolean isRtl = ViewUtils.isViewRtl(mOriginalKeyedView);
        final boolean isActionUp = keyEvent.getAction() == KeyEvent.ACTION_UP;
        final boolean isStart = KeyboardUtils.isKeycodeDirectionStart(keyCode, isRtl);
        final boolean isEnd = KeyboardUtils.isKeycodeDirectionEnd(keyCode, isRtl);
        final boolean isUp = keyCode == KeyEvent.KEYCODE_DPAD_UP;
        final boolean isDown = keyCode == KeyEvent.KEYCODE_DPAD_DOWN;

        // First we run the event by the controller
        // We manually check if the view+direction combination should shift focus away from the
        // conversation view to the thread list in two-pane landscape mode.
        final boolean isTwoPaneLand = mNavigationController.isTwoPaneLandscape();
        final boolean navigateAway = shouldNavigateAway(id, isStart, isTwoPaneLand);
        if (mNavigationController.onInterceptKeyFromCV(keyCode, keyEvent, navigateAway)) {
            return true;
        }

        // If controller didn't handle the event, check directional interception.
        if ((isStart || isEnd) && shouldInterceptLeftRightEvents(id, isStart, isEnd, isTwoPaneLand)) {
            return true;
        } else if (isUp || isDown) {
            // We don't do anything on up/down for overlay
            if (id == R.id.conversation_topmost_overlay) {
                return true;
            }

            // We manually handle up/down navigation through the overlay items because the
            // system's default isn't optimal for two-pane landscape since it's not a real list.
            final View next = mConversationContainer.getNextOverlayView(mOriginalKeyedView, isDown);
            if (next != null) {
                focusAndScrollToView(next);
            } else if (!isActionUp) {
                // Scroll in the direction of the arrow if next view isn't found.
                final int currentY = mWebView.getScrollY();
                if (isUp && currentY > 0) {
                    mWebView.scrollBy(0, -Math.min(currentY, DEFAULT_VERTICAL_SCROLL_DISTANCE_PX));
                } else if (isDown) {
                    final int webviewEnd = (int) (mWebView.getContentHeight() * mWebView.getScale());
                    final int currentEnd = currentY + mWebView.getHeight();
                    if (currentEnd < webviewEnd) {
                        mWebView.scrollBy(0,
                                Math.min(webviewEnd - currentEnd, DEFAULT_VERTICAL_SCROLL_DISTANCE_PX));
                    }
                }
            }
            return true;
        }

        // Finally we handle the special keys
        if (keyCode == KeyEvent.KEYCODE_BACK && id != R.id.conversation_topmost_overlay) {
            if (isActionUp) {
                mTopmostOverlay.requestFocus();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_ENTER && id == R.id.conversation_topmost_overlay) {
            if (isActionUp) {
                mWebView.scrollTo(0, 0);
                mConversationContainer.focusFirstMessageHeader();
            }
            return true;
        }
    }
    return false;
}

From source file:com.instiwork.RegistrationFacebookActivity.java

public void dialogTermsUse() {
    View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_terms_use, null);
    mBottomSheetDialogTermsUse = new Dialog(RegistrationFacebookActivity.this, R.style.MaterialDialogSheet);
    mBottomSheetDialogTermsUse.setContentView(view);
    mBottomSheetDialogTermsUse.setCancelable(false);
    mBottomSheetDialogTermsUse.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBottomSheetDialogTermsUse.getWindow()
                .addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        mBottomSheetDialogTermsUse.getWindow().setStatusBarColor(Color.parseColor("#536942"));
    }//from   w ww. j  a  v a  2s. com
    mBottomSheetDialogTermsUse.getWindow().setGravity(Gravity.BOTTOM);
    mBottomSheetDialogTermsUse.show();

    view.findViewById(R.id.back_me_dlog_payment).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mBottomSheetDialogTermsUse.dismiss();
        }
    });

    pBarTermsUse = (ProgressBar) view.findViewById(R.id.pbar_terms_use);
    //        txtTermsUse = (RobotoLight) view.findViewById(R.id.txt_terms_use);

    webViewTermsUse = (WebView) view.findViewById(R.id.webv);
    webViewTermsUse.getSettings().setJavaScriptEnabled(true);
    webViewTermsUse.setVisibility(View.GONE);

    getTermsUse(InstiworkConstants.URL_DOMAIN + "Privacy_control");

    mBottomSheetDialogTermsUse.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
                if ((keyCode == KeyEvent.KEYCODE_BACK)) {
                    mBottomSheetDialogTermsUse.dismiss();
                    return true;
                }
            return false;
        }
    });
}

From source file:com.andrew.apolloMod.service.ApolloService.java

/** Return notification remote views
 * /*from   ww  w  . j a  v  a2s  . c o  m*/
 * @return [views, bigViews]
 */
public RemoteViews[] getNotificationViews() {
    Bitmap b = getAlbumBitmap();

    RemoteViews bigViews = new RemoteViews(getPackageName(), R.layout.status_bar_expanded);
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar);

    if (b != null) {
        bigViews.setImageViewBitmap(R.id.status_bar_album_art, b);
        views.setViewVisibility(R.id.status_bar_icon, View.GONE);
        views.setViewVisibility(R.id.status_bar_album_art, View.VISIBLE);
        views.setImageViewBitmap(R.id.status_bar_album_art, b);
    } else {
        views.setViewVisibility(R.id.status_bar_icon, View.VISIBLE);
        views.setViewVisibility(R.id.status_bar_album_art, View.GONE);
    }

    ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.putExtra(CMDNOTIF, 1);
    mediaButtonIntent.setComponent(rec);
    KeyEvent mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent);
    bigViews.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent);

    mediaButtonIntent.putExtra(CMDNOTIF, 2);
    mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 2, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent);
    bigViews.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent);

    mediaButtonIntent.putExtra(CMDNOTIF, 4);
    mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 4, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    bigViews.setOnClickPendingIntent(R.id.status_bar_prev, mediaPendingIntent);

    mediaButtonIntent.putExtra(CMDNOTIF, 3);
    mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent);
    bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent);

    views.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause);
    bigViews.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause);

    views.setTextViewText(R.id.status_bar_track_name, getTrackName());
    bigViews.setTextViewText(R.id.status_bar_track_name, getTrackName());

    views.setTextViewText(R.id.status_bar_artist_name, getArtistName());
    bigViews.setTextViewText(R.id.status_bar_artist_name, getArtistName());

    bigViews.setTextViewText(R.id.status_bar_album_name, getAlbumName());

    return new RemoteViews[] { views, bigViews };

}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

private boolean handleKey(int keyCode, final KeyEvent event) {
    if (mDebug)// w  w  w  . java  2  s.  c om
        Log.d("DosBoxTurbo", "handleKey keyCode=" + keyCode);
    int tKeyCode = 0;

    // check for xperia play back case
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isAltPressed()) {
        int backval = customMap.get(DosBoxPreferences.XPERIA_BACK_BUTTON);
        if (backval > 0) {
            // Special Sony XPeria Play case
            if (mEnableDpad) {
                // FIRE2
                if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                    DosBoxControl.nativeMouse(0, 0, 0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1,
                            BTN_B);
                } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                    DosBoxControl.nativeJoystick(0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1,
                            BTN_B);
                }
            } else {
                // sony xperia play O (circle) button
                DosBoxControl.sendNativeKey(backval, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl,
                        mModifierAlt, mModifierShift);
                return true; // consume event
            }
        }
        return true; // consume event
    }

    // Handle all other keyevents
    int value = customMap.get(keyCode);

    if (value > 0) {
        // found a valid mapping
        tKeyCode = getMappedKeyCode(value, event);
        if (tKeyCode > MAP_NONE) {
            DosBoxControl.sendNativeKey(tKeyCode, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl,
                    mModifierAlt, mModifierShift);
            return true; // consume KeyEvent
        } else if (tKeyCode == MAP_EVENT_CONSUMED) {
            return true;
        }
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // fishstix, allow remap of Android back button
        // catch no mapping
        if (event.getAction() == KeyEvent.ACTION_UP) {
            DBMenuSystem.doConfirmQuit(mParent);
        }
        return true;
    }

    switch (keyCode) {
    case KeyEvent.KEYCODE_UNKNOWN:
        break;

    default:
        boolean down = (event.getAction() == KeyEvent.ACTION_DOWN);
        if (mDebug)
            Log.d("DosBoxTurbo", "handleKey (default) keyCode=" + keyCode + " down=" + down);

        if (!down || (event.getRepeatCount() == 0)) {
            int unicode = event.getUnicodeChar();

            // filter system generated keys, but not hardware keypresses
            if ((event.isAltPressed() || event.isShiftPressed()) && (unicode == 0)
                    && ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0))
                break;

            //fixed alt key problem for physical keyboard with only left alt
            if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_ALT_LEFT)) {
                break;
            }

            if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)) {
                break;
            }

            if ((keyCode > 255) || (unicode > 255)) {
                //unknown keys
                break;
            }

            keyCode = keyCode | (unicode << 8);

            long diff = event.getEventTime() - event.getDownTime();

            if (!down && (diff < 50)) {
                //simulate as long press
                if (mDebug)
                    Log.d("DosBoxTurbo", "LongPress consumed keyCode=" + keyCode + " down=" + down);
                mKeyHandler.removeMessages(keyCode);
                mKeyHandler.sendEmptyMessageDelayed(keyCode, BUTTON_REPEAT_DELAY - diff);
            } else if (down && mKeyHandler.hasMessages(keyCode)) {
                if (mDebug)
                    Log.d("DosBoxTurbo", "KeyUp consumed keyCode=" + keyCode + " down=" + down);
                //there is an key up in queue, should be repeated event
            } else {
                boolean result = DosBoxControl.sendNativeKey(keyCode, down, mModifierCtrl, mModifierAlt,
                        mModifierShift);
                if (!down) {
                    mModifierCtrl = false;
                    mModifierAlt = false;
                    mModifierShift = false;
                }
                return result;
            }
        }
    }

    return false;
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

@TargetApi(Build.VERSION_CODES.FROYO)
private boolean handleVolumeButtonEvent(KeyEvent event) {

    //Disable volume button handling during TTS
    if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) {
        return false;
    }/*from   w w w. j a va  2  s . c  om*/

    Activity activity = getActivity();

    if (activity == null) {
        return false;
    }

    boolean invert = false;

    int rotation = Surface.ROTATION_0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        rotation = display.getRotation();
    }

    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
        invert = false;
        break;
    case Surface.ROTATION_180:
    case Surface.ROTATION_270:
        invert = true;
        break;
    }

    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return true;
    }

    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
        if (invert) {
            pageDown(Orientation.HORIZONTAL);
        } else {
            pageUp(Orientation.HORIZONTAL);
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (invert) {
            pageUp(Orientation.HORIZONTAL);
        } else {
            pageDown(Orientation.HORIZONTAL);
        }
    }

    return true;
}