Example usage for android.view KeyEvent KEYCODE_DPAD_RIGHT

List of usage examples for android.view KeyEvent KEYCODE_DPAD_RIGHT

Introduction

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

Prototype

int KEYCODE_DPAD_RIGHT

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

Click Source Link

Document

Key code constant: Directional Pad Right key.

Usage

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  ww  w  . jav  a  2  s .  com*/
            } else if (event.isCtrlPressed()) {
                showLargeThumbnail(videoUri);
            }

            return (true);
        }
    }

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

From source file:com.android.screenspeak.KeyboardSearchManager.java

@Override
public boolean onKeyEvent(KeyEvent event) {
    // Only handle single-key events here. The KeyComboManager will pass us combos.
    if (event.getModifiers() != 0 || !mNodeSearch.isActive()) {
        return false;
    }/*from w  w w  .ja v  a 2  s.c o  m*/

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_ENTER:
            if (mHasNavigated || mNodeSearch.hasMatch()) {
                finishSearch();
                mContext.getCursorController().clickCurrent();
            } else {
                cancelSearch();
            }
            return true;
        case KeyEvent.KEYCODE_DEL:
            resetHintTime();
            final String queryText = mNodeSearch.getCurrentQuery();
            if (queryText.isEmpty()) {
                cancelSearch();
            } else {
                final String lastChar = queryText.substring(queryText.length() - 1);
                mNodeSearch.backspaceQueryText();
                mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar),
                        SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null);
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveToEnd(NodeFocusFinder.SEARCH_BACKWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveToNext(NodeFocusFinder.SEARCH_BACKWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveToEnd(NodeFocusFinder.SEARCH_FORWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveToNext(NodeFocusFinder.SEARCH_FORWARD);
            return true;
        case KeyEvent.KEYCODE_SPACE:
            resetHintTime();
            if (mNodeSearch.tryAddQueryText(" ")) {
                mSpeechController.speak(mContext.getString(R.string.symbol_space),
                        SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null);
            } else {
                mContext.getFeedbackController().playAuditory(R.raw.complete);
            }
            return true;
        default:
            if (event.isPrintingKey()) {
                resetHintTime();
                final String key = String.valueOf(event.getDisplayLabel());
                if (mNodeSearch.tryAddQueryText(key)) {
                    mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL,
                            FeedbackItem.FLAG_NO_HISTORY, null);
                } else {
                    mContext.getFeedbackController().playAuditory(R.raw.complete);
                }
                return true;
            }
            break;
        }
    }

    return false;
}

From source file:ar.rulosoft.custompref.SeekBarCustomPreference.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (isEnabled()) {
        if (event.getAction() != KeyEvent.ACTION_UP) {
            int increment = mKeyProgressIncrement;

            switch (keyCode) {
            case KeyEvent.KEYCODE_PLUS:
            case KeyEvent.KEYCODE_EQUALS:
                setProgress(getProgress() + increment);
                return true;
            case KeyEvent.KEYCODE_MINUS:
                setProgress(getProgress() - increment);
                return true;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                increment = -increment;/*from  w w w . j a v  a 2  s  .  co  m*/
                // fallthrough
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                increment = ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_RTL ? -increment
                        : increment;
                setProgress(getProgress() + increment);
                return true;
            }
        }
    }
    return false;
}

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

public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
        Bundle savedInstanceState) {//from  w w  w  .  j av a2 s.  c  o m

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "onCreateview " + this);
    }

    FragmentActivity activity = getActivity();
    Intent intent = activity.getIntent();

    final Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.e(TAG, "No extras!");
    } else {

        String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY);
        if (remoteProfileID != null) {
            sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity);
        }

        torrentID = extras.getLong("TorrentID");
    }

    Map<?, ?> torrent = sessionInfo.getTorrent(torrentID);
    if (torrent == null) {
        // In theory TorrentOpenOptionsActivity handled this NPE already
        return null;
    }

    View topView = inflater.inflate(R.layout.frag_fileselection, container, false);
    tvScrollTitle = (TextView) topView.findViewById(R.id.files_scrolltitle);
    tvSummary = (TextView) topView.findViewById(R.id.files_summary);

    listview = (RecyclerView) topView.findViewById(R.id.files_list);
    listview.setLayoutManager(new PreCachingLayoutManager(getContext()));
    listview.setAdapter(adapter);

    FlexibleRecyclerSelectionListener rs = new FlexibleRecyclerSelectionListener<FilesTreeAdapter, FilesAdapterDisplayObject>() {
        @Override
        public void onItemClick(FilesTreeAdapter adapter, int position) {
            if (AndroidUtils.usesNavigationControl()) {
                FilesAdapterDisplayObject oItem = adapter.getItem(position);
                if (adapter.isInEditMode()) {
                    adapter.flipWant(oItem);
                    return;
                }
                if (oItem instanceof FilesAdapterDisplayFolder) {
                    FilesAdapterDisplayFolder oFolder = (FilesAdapterDisplayFolder) oItem;
                    oFolder.expand = !oFolder.expand;
                    adapter.getFilter().filter("");
                }
            }
        }

        @Override
        public boolean onItemLongClick(FilesTreeAdapter adapter, int position) {
            return false;
        }

        @Override
        public void onItemSelected(FilesTreeAdapter adapter, int position, boolean isChecked) {

        }

        @Override
        public void onItemCheckedChanged(FilesTreeAdapter adapter, FilesAdapterDisplayObject item,
                boolean isChecked) {
        }
    };

    adapter = new FilesTreeAdapter(this.getActivity(), rs);
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeChanged(int positionStart, int itemCount) {
            if (tvSummary != null) {
                tvSummary.setText(DisplayFormatters.formatByteCountToKiBEtc(adapter.getTotalSizeWanted()));
            }
        }

        @Override
        public void onChanged() {
            super.onChanged();
            if (tvSummary != null) {
                tvSummary.setText(DisplayFormatters.formatByteCountToKiBEtc(adapter.getTotalSizeWanted()));
            }
        }
    });
    adapter.setInEditMode(true);
    adapter.setSessionInfo(sessionInfo);
    adapter.setCheckOnSelectedAfterMS(0);
    listview.setAdapter(adapter);

    listview.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            {
                if (event.getAction() != KeyEvent.ACTION_DOWN) {
                    return false;
                }
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_RIGHT: {
                    // expand
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (!((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = true;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }

                case KeyEvent.KEYCODE_DPAD_LEFT: {
                    // collapse
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = false;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }
                }

                return false;
            }
        }
    });

    listview.setOnScrollListener(new RecyclerView.OnScrollListener() {
        int firstVisibleItem = 0;

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            LinearLayoutManager lm = (LinearLayoutManager) listview.getLayoutManager();
            int firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition();
            if (firstVisibleItem != this.firstVisibleItem) {
                this.firstVisibleItem = firstVisibleItem;
                FilesAdapterDisplayObject itemAtPosition = adapter.getItem(firstVisibleItem);

                if (itemAtPosition == null) {
                    return;
                }
                if (itemAtPosition.parent != null) {
                    if (tvScrollTitle != null) {
                        tvScrollTitle.setText(itemAtPosition.parent.folder);
                    }
                } else {
                    if (tvScrollTitle != null) {
                        tvScrollTitle.setText("");
                    }
                }
            }
        }
    });

    if (torrent.containsKey("files")) {
        adapter.setTorrentID(torrentID);
    } else {
        sessionInfo.executeRpc(new RpcExecuter() {
            @Override
            public void executeRpc(TransmissionRPC rpc) {
                rpc.getTorrentFileInfo(TAG, torrentID, null, new TorrentListReceivedListener() {

                    @Override
                    public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                            List<?> removedTorrentIDs) {
                        AndroidUtils.runOnUIThread(OpenOptionsFilesFragment.this, new Runnable() {
                            @Override
                            public void run() {
                                adapter.setTorrentID(torrentID);
                            }
                        });
                    }
                });
            }
        });
    }

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "set " + adapter + " for " + listview + " to " + sessionInfo + "/" + torrentID);
    }

    return topView;
}

From source file:com.stoyanr.feeder.activity.ItemsActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (KeyUtils.interpretDirection(keyCode)) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return prevChannel();
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return nextChannel();
    default:/*from  w w  w  . ja  v a2  s  .  c  o m*/
        return super.onKeyUp(keyCode, event);
    }
}

From source file:com.lib.media.widget.seekbar.VerticalSeekBar.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (isEnabled()) {
        final boolean handled;
        int direction = 0;

        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_DOWN:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_90) ? 1 : -1;
            handled = true;//from   w w w.  jav  a  2s. c o  m
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_270) ? 1 : -1;
            handled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            // move view focus to previous/next view
            return false;
        default:
            handled = false;
            break;
        }

        if (handled) {
            final int keyProgressIncrement = getKeyProgressIncrement();
            int progress = getProgress();

            progress += (direction * keyProgressIncrement);

            if (progress >= 0 && progress <= getMax()) {
                _setProgressFromUser(progress, true);
            }

            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (isEnabled()) {
        final boolean handled;
        int direction = 0;

        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_DOWN:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_90) ? 1 : -1;
            handled = true;//from   w  w w.  j  a  v a 2 s.c  om
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            direction = (mRotationAngle == ROTATION_ANGLE_CW_270) ? 1 : -1;
            handled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = true;
            break;
        default:
            handled = false;
            break;
        }

        if (handled) {
            final int keyProgressIncrement = getKeyProgressIncrement();
            int progress = getProgress();

            progress += (direction * keyProgressIncrement);

            if (progress >= 0 && progress <= getMax()) {
                setProgress(progress - keyProgressIncrement, true);
            }

            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.stoyanr.feeder.activity.ViewItemActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (KeyUtils.interpretDirection(keyCode)) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return newerItem();
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return olderItem();
    default://from w  w  w.  j a  v  a  2 s  .c om
        return super.onKeyUp(keyCode, event);
    }
}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

protected void scrollToBegin(Runnable verify) throws Throwable {
    int key;/*from w w  w  .j  a v a 2 s  .c  om*/
    if (mOrientation == BaseGridView.HORIZONTAL) {
        if (mGridView.getLayoutDirection() == ViewGroup.LAYOUT_DIRECTION_RTL) {
            key = KeyEvent.KEYCODE_DPAD_RIGHT;
        } else {
            key = KeyEvent.KEYCODE_DPAD_LEFT;
        }
    } else {
        key = KeyEvent.KEYCODE_DPAD_UP;
    }
    scroll(key, verify);
}

From source file:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java

private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) {
    int keyEvent = specialKeyMap.get(key, 0);
    if (keyEvent == 0)
        return false;
    InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection();
    //        Log.d("RemoteKeyboardPlugin", "Handling special key " + key + " translated to " + keyEvent + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt);

    // special sequences:
    if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) {
        // Ctrl + right -> next word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = currentTextLength(extractedText);
        else//from   ww w .j  av  a 2 s . c o  m
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) { // Shift -> select word (otherwise jump)
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            //                Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (sel.first < cursor || // active selection from left to right -> grow
                    sel.first > sel.second) // active selection from right to left -> shrink
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) {
        // Ctrl + left -> previous word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = 0;
        else
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) {
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            //                Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (cursor < sel.first || // active selection from right to left -> grow
                    sel.first < sel.second) // active selection from right to left -> shrink
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT
            || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN
            || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) {
        // Shift + up/down/left/right/home/end
        long now = SystemClock.uptimeMillis();
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
        inputConn.sendKeyEvent(
                new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(
                new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
    } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) {
        // Enter key
        EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo();
        //            Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions);
        if (editorInfo != null
                && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) { // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?)
            // check for special DONE/GO/etc actions first:
            int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND,
                    EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_DONE }; // note: DONE should be last or we might hide the ime instead of "go"
            for (int i = 0; i < actions.length; i++) {
                if ((editorInfo.imeOptions & actions[i]) == actions[i]) {
                    //                        Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]);
                    inputConn.performEditorAction(actions[i]);
                    return true;
                }
            }
        } else {
            // else: fall back to regular Enter-event:
            //                Log.d("RemoteKeyboardPlugin", "Enter: normal keypress");
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
        }
    } else {
        // default handling:
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
    }

    return true;
}