Example usage for android.view KeyEvent isShiftPressed

List of usage examples for android.view KeyEvent isShiftPressed

Introduction

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

Prototype

public final boolean isShiftPressed() 

Source Link

Document

Returns the pressed state of the SHIFT meta key.

Usage

From source file:co.beem.project.beem.ui.wizard.AccountConfigureFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.wizard_account_configure, container, false);

    mNextButton = (TextView) v.findViewById(R.id.next);
    mNextButton.setEnabled(false);//w  w w .  ja v a 2s  .c om
    mNextButton.setOnClickListener(this);
    mErrorLabel = (TextView) v.findViewById(R.id.error_label);
    mSettingsWarningLabel = (TextView) v.findViewById(R.id.settings_warn_label);
    errorDivider = v.findViewById(R.id.error_divider);
    mAccountJID = (EditText) v.findViewById(R.id.account_username);
    mAccountJID.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            isAccountEdtFocused = hasFocus;
        }
    });
    mAccountPassword = (EditText) v.findViewById(R.id.account_password);
    mAccountPassword.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            isPasswordEdtFocused = hasFocus;
        }
    });
    //mAccountJID.setFilters(newFilters);
    mAccountJID.addTextChangedListener(mJidTextWatcher);
    mAccountPassword.addTextChangedListener(mPasswordTextWatcher);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) // true to disable the feature until ready
        v.findViewById(R.id.account_layout).setVisibility(View.GONE);
    mAccountPassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
    mAccountPassword.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                if (!event.isShiftPressed()) {
                    onClick(mNextButton);
                    return true;
                }
                return false;
            }
            onClick(mNextButton);
            return true;
        }
    });
    showBtn = (TextView) v.findViewById(R.id.login_show_btn);
    showBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isPasswordShowing) {
                showBtn.setText(getText(R.string.hide));
                mAccountPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            } else {
                showBtn.setText(getText(R.string.show));
                mAccountPassword
                        .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
            mAccountPassword.setSelection(mAccountPassword.length());
            isPasswordShowing = !isPasswordShowing;
        }
    });
    createNewAccountButton = (TextView) v.findViewById(R.id.create_new_account);
    createNewAccountButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((Account) getActivity()).pushFragment(
                    WebViewFragment.instanciate("https://m.facebook.com/r.php?loc=bottom&refid=8"));
        }
    });
    forgotPasswordTv = (TextView) v.findViewById(R.id.forgot_password_tv);
    forgotPasswordTv.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((Account) getActivity()).pushFragment(
                    WebViewFragment.instanciate("https://m.facebook.com/login/identify/?ctx=recover"));

        }
    });
    helpTextview = (TextView) v.findViewById(R.id.help_tv);
    helpTextview.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((Account) getActivity())
                    .pushFragment(WebViewFragment.instanciate("https://m.facebook.com/help/?refid=8"));
        }
    });
    return v;
}

From source file:org.peterbaldwin.vlcremote.app.PlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int c = event.getUnicodeChar();
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel + 20);
        } else {/*from   w  w w.  j a  v a 2s.com*/
            mMediaServer.status().command.volumeUp();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel - 20);
        } else {
            mMediaServer.status().command.volumeDown();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-left");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-right");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        mMediaServer.status().command.key("nav-up");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        mMediaServer.status().command.key("nav-down");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        mMediaServer.status().command.key("nav-activate");
        return true;
    } else if (c == ' ') {
        mMediaServer.status().command.playback.pause();
        return true;
    } else if (c == 's') {
        mMediaServer.status().command.playback.stop();
        return true;
    } else if (c == 'p') {
        mMediaServer.status().command.playback.previous();
        return true;
    } else if (c == 'n') {
        mMediaServer.status().command.playback.next();
        return true;
    } else if (c == '+') {
        // TODO: Play faster
        return super.onKeyDown(keyCode, event);
    } else if (c == '-') {
        // TODO: Play slower
        return super.onKeyDown(keyCode, event);
    } else if (c == 'f') {
        mMediaServer.status().command.fullscreen();
        return true;
    } else if (c == 'm') {
        mute();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

/**
 * Select Text in the webview and automatically sends the selected text to the clipboard. From
 * http://cosmez.blogspot.com/2010/04/webview-emulateshiftheld-on-android.html
 *//*from ww  w . j  a  v a 2  s  . co m*/
private void selectAndCopyText() {
    try {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
        shiftPressEvent.dispatch(mCard);
        shiftPressEvent.isShiftPressed();
        mIsSelecting = true;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

From source file:com.hxqc.mall.thirdshop.views.CustomScrollView.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy./*w w w.ja v  a 2s.  co m*/
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    mTempRect.setEmpty();

    if (!canScroll()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this)
                currentFocused = null;
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }

    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_UP);
            } else {
                handled = fullScroll(View.FOCUS_UP);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_DOWN);
            } else {
                handled = fullScroll(View.FOCUS_DOWN);
            }
            break;
        case KeyEvent.KEYCODE_SPACE:
            pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
            break;
        default:
            break;
        }
    }

    return handled;
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy./*from w  w  w  .  j  a v  a 2  s  . co m*/
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    mTempRect.setEmpty();

    if (!canScroll()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this)
                currentFocused = null;
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }

    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_UP);
            } else {
                handled = fullScroll(View.FOCUS_UP);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_DOWN);
            } else {
                handled = fullScroll(View.FOCUS_DOWN);
            }
            break;
        case KeyEvent.KEYCODE_SPACE:
            pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
            break;
        }
    }

    return handled;
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

/**
 * Select Text in the webview and automatically sends the selected text to the clipboard. From
 * http://cosmez.blogspot.com/2010/04/webview-emulateshiftheld-on-android.html
 *///from   w w w. j  av  a 2 s  .  com
private void selectAndCopyText() {
    try {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
        if (mCurrentSimpleInterface) {
            shiftPressEvent.dispatch(mSimpleCard);
        } else {
            shiftPressEvent.dispatch(mCard);
        }
        shiftPressEvent.isShiftPressed();
        mIsSelecting = true;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//  w ww . j  a va2s. c  o  m
 *
 * @param event
 *            The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    mTempRect.setEmpty();

    if (!canVerticalScroll()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this)
                currentFocused = null;
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }
    if (!canHorizontalScroll()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this)
                currentFocused = null;
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }

    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_UP);
            } else {
                handled = fullScroll(View.FOCUS_UP);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed()) {
                handled = arrowScroll(View.FOCUS_DOWN);
            } else {
                handled = fullScroll(View.FOCUS_DOWN);
            }
            break;
        case KeyEvent.KEYCODE_SPACE:
            pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
            break;
        }
    }

    return handled;
}

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

private boolean handleKey(int keyCode, final KeyEvent event) {
    if (mDebug)/*  w w w  . j  a v  a 2 s  .  co  m*/
        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:com.hippo.widget.BothScrollView.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//w  w  w  .  j  a  v  a2s  . co  m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    mTempRect.setEmpty();

    if (!canScrollHorizontally()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this) {
                currentFocused = null;
            }
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_RIGHT);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_RIGHT);
        }
        return false;
    }

    if (!canScrollVertically()) {
        if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
            View currentFocused = findFocus();
            if (currentFocused == this) {
                currentFocused = null;
            }
            View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN);
            return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN);
        }
        return false;
    }

    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (!event.isAltPressed()) {
                handled = arrowScrollHorizontally(View.FOCUS_LEFT);
            } else {
                handled = fullScroll(View.FOCUS_LEFT);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!event.isAltPressed()) {
                handled = arrowScrollHorizontally(View.FOCUS_RIGHT);
            } else {
                handled = fullScroll(View.FOCUS_RIGHT);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed()) {
                handled = arrowScrollVertically(View.FOCUS_UP);
            } else {
                handled = fullScroll(View.FOCUS_UP);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed()) {
                handled = arrowScrollVertically(View.FOCUS_DOWN);
            } else {
                handled = fullScroll(View.FOCUS_DOWN);
            }
            break;
        case KeyEvent.KEYCODE_SPACE:
            if (event.isCtrlPressed()) {
                pageScroll(event.isShiftPressed() ? View.FOCUS_LEFT : View.FOCUS_RIGHT);
            } else {
                pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
            }
            break;
        }
    }

    return handled;
}