Example usage for android.view KeyEvent isAltPressed

List of usage examples for android.view KeyEvent isAltPressed

Introduction

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

Prototype

public final boolean isAltPressed() 

Source Link

Document

Returns the pressed state of the ALT meta key.

Usage

From source file:org.odk.collect.android.widgets.ExStringWidget.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    return !event.isAltPressed() && super.onKeyDown(keyCode, event);
}

From source file:com.commonsware.android.kbmouse.hotkeys.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && event.getRepeatCount() == 0) {
        int position = adapter.getCheckedPosition();

        if (position >= 0) {
            Uri videoUri = adapter.getVideoUri(position);

            if (event.isAltPressed()) {
                playVideo(videoUri);/*from w  w  w.ja v  a 2  s  . co m*/
            } else if (event.isCtrlPressed()) {
                showLargeThumbnail(videoUri);
            }

            return (true);
        }
    }

    return (super.onKeyDown(keyCode, event));
}

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 {// ww  w  .j  a v a  2  s.  c  o  m
            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.fishstix.dosboxfree.DBGLSurfaceView.java

private boolean handleKey(int keyCode, final KeyEvent event) {
    if (mDebug)//w ww . ja  v a2s . c o 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.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  .  j a va 2s . 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 (!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  av  a2s  . 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 (!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:org.odk.collect.android.activities.FormEntryActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Collect.getInstance().getActivityLogger().logInstanceAction(this, "onKeyDown.KEYCODE_BACK", "quit");
        createQuitDialog();/*from   w  w  w.jav  a  2s . c o  m*/
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (event.isAltPressed() && !beenSwiped) {
            beenSwiped = true;
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onKeyDown.KEYCODE_DPAD_RIGHT",
                    "showNext");
            showNextView();
            return true;
        }
        break;
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (event.isAltPressed() && !beenSwiped) {
            beenSwiped = true;
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onKeyDown.KEYCODE_DPAD_LEFT",
                    "showPrevious");
            showPreviousView();
            return true;
        }
        break;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Collect.getInstance().getActivityLogger().logInstanceAction(this, "onKeyDown.KEYCODE_BACK", "quit");
        createQuitDialog();//from  ww w. j  a v  a  2s  .c  o m
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (event.isAltPressed() && !mBeenSwiped) {
            mBeenSwiped = true;
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onKeyDown.KEYCODE_DPAD_RIGHT",
                    "showNext");
            showNextView();
            return true;
        }
        break;
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (event.isAltPressed() && !mBeenSwiped) {
            mBeenSwiped = true;
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onKeyDown.KEYCODE_DPAD_LEFT",
                    "showPrevious");
            showPreviousView();
            return true;
        }
        break;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:info.guardianproject.otr.app.im.app.ChatView.java

@Override
protected void onFinishInflate() {
    //  mStatusIcon = (ImageView) findViewById(R.id.statusIcon);
    //   mDeliveryIcon = (ImageView) findViewById(R.id.deliveryIcon);
    // mTitle = (TextView) findViewById(R.id.title);
    mHistory = (ListView) findViewById(R.id.history);
    mComposeMessage = (EditText) findViewById(R.id.composeMessage);
    mSendButton = (ImageButton) findViewById(R.id.btnSend);
    mHistory.setOnItemClickListener(mOnItemClickListener);
    mButtonAttach = (ImageButton) findViewById(R.id.btnAttach);
    mViewAttach = findViewById(R.id.attachPanel);

    mStatusWarningView = findViewById(R.id.warning);
    mWarningText = (TextView) findViewById(R.id.warningText);

    mProgressTransfer = (ProgressBar) findViewById(R.id.progressTransfer);
    // mOtrSwitch = (CompoundButton)findViewById(R.id.otrSwitch);
    mProgressBarOtr = (ProgressBar) findViewById(R.id.progressBarOtr);

    mButtonAttach.setOnClickListener(new OnClickListener() {

        @Override// ww  w. j  av a2 s.  co  m
        public void onClick(View v) {

            if (mViewAttach.getVisibility() == View.GONE)
                mViewAttach.setVisibility(View.VISIBLE);
            else
                mViewAttach.setVisibility(View.GONE);
        }

    });

    ((ImageButton) findViewById(R.id.btnAttachAudio)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startAudioPicker();
        }

    });

    ((ImageButton) findViewById(R.id.btnAttachPicture)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startImagePicker();
        }

    });

    ((ImageButton) findViewById(R.id.btnTakePicture)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startPhotoTaker();
        }

    });

    ((ImageButton) findViewById(R.id.btnAttachFile)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startFilePicker();
        }

    });

    mHistory.setOnItemLongClickListener(new OnItemLongClickListener() {

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            if (arg1 instanceof MessageView) {

                String textToCopy = ((MessageView) arg1).getLastMessage();

                int sdk = android.os.Build.VERSION.SDK_INT;
                if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mNewChatActivity
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(textToCopy); //
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mNewChatActivity
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("chat", textToCopy);
                    clipboard.setPrimaryClip(clip); //
                }

                Toast.makeText(mNewChatActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard),
                        Toast.LENGTH_SHORT).show();

                return true;

            }

            return false;
        }

    });

    mWarningText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showVerifyDialog();
        }
    });

    //mOtrSwitch.setOnCheckedChangeListener(mOtrListener);

    mComposeMessage.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                    sendMessage();
                    return true;

                case KeyEvent.KEYCODE_ENTER:
                    if (event.isAltPressed()) {
                        mComposeMessage.append("\n");
                        return true;
                    }
                }
            }
            return false;
        }
    });

    mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                if (event.isAltPressed()) {
                    return false;
                }
            }

            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null && imm.isActive(v)) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
            sendMessage();
            return true;
        }
    });

    // TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with
    // the soft keyboard, we should remove this hack.
    mComposeMessage.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int before, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int after) {
            //log("TextWatcher: " + s);
            userActionDetected();
        }

        public void afterTextChanged(Editable s) {
        }
    });

    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            sendMessage();
        }
    });

    Button btnApproveSubscription = (Button) findViewById(R.id.btnApproveSubscription);
    btnApproveSubscription.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            mNewChatActivity.approveSubscription(mProviderId, mRemoteAddress);

            mHandler.postDelayed(new Runnable() {
                public void run() {
                    bindChat(mLastChatId);
                }
            }, 2000);

        }

    });

    Button btnDeclineSubscription = (Button) findViewById(R.id.btnDeclineSubscription);
    btnDeclineSubscription.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            mHandler.postDelayed(new Runnable() {
                public void run() {
                    mNewChatActivity.declineSubscription(mProviderId, mRemoteAddress);

                }
            }, 500);

        }

    });

    /*
    mActionBox = (View)findViewById(R.id.actionBox);
    ImageButton btnActionBox = (ImageButton)findViewById(R.id.btnActionBox);
    btnActionBox.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        mEmojiPager.setVisibility(View.GONE);
            
            
        if (mActionBox.getVisibility() == View.GONE)
            mActionBox.setVisibility(View.VISIBLE);
        else
            mActionBox.setVisibility(View.GONE);
    }
            
    });
            
    View btnEndChat = findViewById(R.id.btnEndChat);
    btnEndChat.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        ChatView.this.closeChatSession();
    }
            
    });
            
    View btnProfile = findViewById(R.id.btnProfile);
    btnProfile.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        viewProfile();
    }
            
    });
            
    View btnSharePicture = findViewById(R.id.btnSendPicture);
    btnSharePicture.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED)
        {
            mNewChatActivity.startImagePicker();
        }
        else
        {
            mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files));
        }
    }
            
    });
            
    View btnShareFile = findViewById(R.id.btnSendFile);
    btnShareFile.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED)
        {
            mNewChatActivity.startFilePicker();
        }
        else
        {
            mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files));
            
        }
    }
            
    });
    */

    initEmoji();

    mMessageAdapter = new MessageAdapter(mNewChatActivity, null);
    mHistory.setAdapter(mMessageAdapter);
}