Java Code Examples for android.view.KeyEvent#KEYCODE_PAGE_UP

The following examples show how to use android.view.KeyEvent#KEYCODE_PAGE_UP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtraSamplesActivity.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * small example of keyboard events on the mapview
 * page up = zoom out
 * page down = zoom in
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyUp (int keyCode, KeyEvent event){
    Fragment frag = getSupportFragmentManager().findFragmentByTag(SAMPLES_FRAGMENT_TAG);
    if (frag==null) {
        return super.onKeyUp(keyCode, event);
    }
    if (!(frag instanceof BaseSampleFragment)) {
        return super.onKeyUp(keyCode,event);
    }
    MapView mMapView = ((BaseSampleFragment)frag).getmMapView();
    if (mMapView==null)
        return super.onKeyUp(keyCode,event);
    switch (keyCode) {
        case KeyEvent.KEYCODE_PAGE_DOWN:
            mMapView.getController().zoomIn();
            return true;
        case KeyEvent.KEYCODE_PAGE_UP:
            mMapView.getController().zoomOut();
            return true;
    }
    return super.onKeyUp(keyCode,event);
}
 
Example 2
Source File: BugsTestingActivity.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * small example of keyboard events on the mapview
 * page up = zoom out
 * page down = zoom in
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyUp (int keyCode, KeyEvent event){
    Fragment frag = getSupportFragmentManager().findFragmentByTag(SAMPLES_FRAGMENT_TAG);
    if (frag==null) {
        return super.onKeyUp(keyCode, event);
    }
    if (!(frag instanceof BaseSampleFragment)) {
        return super.onKeyUp(keyCode,event);
    }
    MapView mMapView = ((BaseSampleFragment)frag).getmMapView();
    if (mMapView==null)
        return super.onKeyUp(keyCode,event);
    switch (keyCode) {
        case KeyEvent.KEYCODE_PAGE_DOWN:
            mMapView.getController().zoomIn();
            return true;
        case KeyEvent.KEYCODE_PAGE_UP:
            mMapView.getController().zoomOut();
            return true;
    }
    return super.onKeyUp(keyCode,event);
}
 
Example 3
Source File: GalleryActivity.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // Check volume
    if (Settings.getVolumePage()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
                keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            return true;
        }
    }

    // Check keyboard and Dpad
    if (keyCode == KeyEvent.KEYCODE_PAGE_UP ||
            keyCode == KeyEvent.KEYCODE_PAGE_DOWN ||
            keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
            keyCode == KeyEvent.KEYCODE_DPAD_UP ||
            keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
            keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
            keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||
            keyCode == KeyEvent.KEYCODE_SPACE ||
            keyCode == KeyEvent.KEYCODE_MENU) {
        return true;
    }

    return super.onKeyUp(keyCode, event);
}
 
Example 4
Source File: MainActivity.java    From android-app with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (currentFragment instanceof ArticleListsFragment) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_PAGE_UP:
            case KeyEvent.KEYCODE_PAGE_DOWN:
                ((ArticleListsFragment) currentFragment).scroll(keyCode == KeyEvent.KEYCODE_PAGE_UP);
                return true;

            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                if (settings.isVolumeButtonsScrollingEnabled()) {
                    ((ArticleListsFragment) currentFragment).scroll(keyCode == KeyEvent.KEYCODE_VOLUME_UP);
                    return true;
                }
                break;
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 5
Source File: CommentsActivity.java    From Hews with MIT License 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mIsKeyScrollEnabled) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_PAGE_UP) {
            if (getFragmentManager().findFragmentById(R.id.container) instanceof CommentsFragment) {
                ((CommentsFragment) getFragmentManager().findFragmentById(R.id.container))
                    .scrollUp(appbar.getHeight() + mAppBarOffset);
            }
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_PAGE_DOWN) {
            if (getFragmentManager().findFragmentById(R.id.container) instanceof CommentsFragment) {
                ((CommentsFragment) getFragmentManager().findFragmentById(R.id.container))
                    .scrollDown(appbar.getHeight() + mAppBarOffset);
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 6
Source File: MainActivity.java    From Hews with MIT License 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mIsKeyScrollEnabled) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_PAGE_UP) {
            if (getFragmentManager().findFragmentById(R.id.container) instanceof BasePostListFragment) {
                // mAppBarOffset is negative
                ((BasePostListFragment) getFragmentManager().findFragmentById(R.id.container))
                    .scrollUp(mAppbar.getHeight() + mAppBarOffset);
            }
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_PAGE_DOWN) {
            if (getFragmentManager().findFragmentById(R.id.container) instanceof BasePostListFragment) {
                ((BasePostListFragment) getFragmentManager().findFragmentById(R.id.container))
                    .scrollDown(mAppbar.getHeight() + mAppBarOffset);
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 7
Source File: FocusHelper.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper method to be used for playing sound effects.
 */
@Thunk static void playSoundEffect(int keyCode, View v) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_MOVE_END:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_MOVE_HOME:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
            break;
        default:
            break;
    }
}
 
Example 8
Source File: FocusLogic.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns true only if this utility class handles the key code.
 */
public static boolean shouldConsume(int keyCode) {
    return (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
            keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
            keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END ||
            keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN ||
            keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL);
}
 
Example 9
Source File: EditText.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    int keycode = event.getKeyCode();
    if ( !mCtrlPreIme ){
        // CTRL + KEYDOWN
        int meta = (int)event.getMetaState();
        boolean ctrl = (meta & mShortcutCtrlKey)!=0 ; // one of meta keies is pressed

        if ( ctrl ){
            if (event.getAction() == KeyEvent.ACTION_DOWN ){
                Log.d("=================>", ""+keycode);
                if (doShortcut(keycode)){
                    return true;
                }
            }else if (event.getAction() == KeyEvent.ACTION_UP){
                return true;
            }
        }
    }
    if ( IS01FullScreen.isIS01orLynx() ){
        if ( keycode == KeyEvent.KEYCODE_PAGE_UP ||
             keycode == KeyEvent.KEYCODE_PAGE_DOWN ){
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 10
Source File: FocusLogic.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns true only if this utility class handles the key code.
 */
public static boolean shouldConsume(int keyCode) {
    return (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
            keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
            keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END ||
            keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN);
}
 
Example 11
Source File: StarterMapActivity.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * small example of keyboard events on the mapview
 * page up = zoom out
 * page down = zoom in
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyUp (int keyCode, KeyEvent event){
    switch (keyCode) {
        case KeyEvent.KEYCODE_PAGE_DOWN:
            starterMapFragment.zoomIn();
            return true;
        case KeyEvent.KEYCODE_PAGE_UP:
            starterMapFragment.zoomOut();
            return true;
    }
    return super.onKeyUp(keyCode,event);
}
 
Example 12
Source File: FocusHelper.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
            || keyCode == KeyEvent.KEYCODE_PAGE_DOWN || keyCode == KeyEvent.KEYCODE_PAGE_UP) {
        // Handle the key event just like a workspace icon would in these cases. In this case,
        // it will basically act as if there is a single icon in the top left (so you could
        // think of the fullscreen page as a focusable fullscreen widget).
        return FocusHelper.handleIconKeyEvent(v, keyCode, event);
    }
    return false;
}
 
Example 13
Source File: EditText.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    int keycode = event.getKeyCode();
    if ( !mCtrlPreIme ){
        // CTRL + KEYDOWN
        int meta = (int)event.getMetaState();
        boolean ctrl = (meta & mShortcutCtrlKey)!=0 ; // one of meta keies is pressed

        if ( ctrl ){
            if (event.getAction() == KeyEvent.ACTION_DOWN ){
                Log.d("=================>", ""+keycode);
                if (doShortcut(keycode)){
                    return true;
                }
            }else if (event.getAction() == KeyEvent.ACTION_UP){
                return true;
            }
        }
    }
    if ( IS01FullScreen.isIS01orLynx() ){
        if ( keycode == KeyEvent.KEYCODE_PAGE_UP ||
             keycode == KeyEvent.KEYCODE_PAGE_DOWN ){
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 14
Source File: FocusLogic.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public static int handleKeyEvent(int keyCode, int [][] map, int iconIdx, int pageIndex,
        int pageCount, boolean isRtl) {

    int cntX = map == null ? -1 : map.length;
    int cntY = map == null ? -1 : map[0].length;

    int newIndex = NOOP;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, -1 /*increment*/, isRtl);
            if (!isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_RIGHT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_RIGHT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, 1 /*increment*/, isRtl);
            if (!isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_LEFT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_LEFT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, 1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, -1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            newIndex = handleMoveHome();
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            newIndex = handleMoveEnd();
            break;
        case KeyEvent.KEYCODE_PAGE_DOWN:
            newIndex = handlePageDown(pageIndex, pageCount);
            break;
        case KeyEvent.KEYCODE_PAGE_UP:
            newIndex = handlePageUp(pageIndex);
            break;
        default:
            break;
    }
    return newIndex;
}
 
Example 15
Source File: FastEdit.java    From fastedit with Apache License 2.0 4 votes vote down vote up
void onKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (action) {
        case KeyEvent.ACTION_DOWN: {

            //输入模式
            int unicodeChar = event.getUnicodeChar();
            if (unicodeChar != 0) {

                input((char) unicodeChar);
                event.cancel();
            }
            if (!event.isCanceled() && !event.isCtrlPressed() && !event.isAltPressed()
                    && !event.isShiftPressed()) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_TAB:
                        //tab
                        input(tabText);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_SPACE:
                        //空格
                        input(' ');
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_ENTER:
                        //enter
                        onKeyCodeEnter(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DEL:
                        //del
                        onKeyCodeDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_FORWARD_DEL:
                        //del
                        onKeyCodeForwardDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_LEFT:
                        //left
                        onKeyCodeDpadLeft(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_RIGHT:
                        //right
                        onKeyCodeDpadRight(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_UP:
                        //up
                        onKeyCodeDpadUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_DOWN:
                        //down
                        onKeyCodeDpadDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_DOWN:

                    case KeyEvent.KEYCODE_PAGE_DOWN:
                        //page down
                        onKeyCodePageDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_UP:

                    case KeyEvent.KEYCODE_PAGE_UP:
                        //page up
                        onKeyCodePageUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_HOME:
                        onKeyCodeMoveHome(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_END:
                        onKeyCodeMoveEnd(event);
                        event.cancel();
                        break;
                }
            }
            if (!event.isCanceled()) {
                //快捷键模式
                if (onShortKey(event.isCtrlPressed(), event.isAltPressed(), event.isShiftPressed(), keyCode)) {
                    event.cancel();
                }
            }

            break;
        }

    }
}
 
Example 16
Source File: FocusLogic.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public static int handleKeyEvent(int keyCode, int cntX, int cntY,
        int [][] map, int iconIdx, int pageIndex, int pageCount, boolean isRtl) {

    if (DEBUG) {
        Log.v(TAG, String.format(
                "handleKeyEvent START: cntX=%d, cntY=%d, iconIdx=%d, pageIdx=%d, pageCnt=%d",
                cntX, cntY, iconIdx, pageIndex, pageCount));
    }

    int newIndex = NOOP;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, -1 /*increment*/);
            if (isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_RIGHT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_RIGHT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, 1 /*increment*/);
            if (isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_LEFT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_LEFT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, 1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, -1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            newIndex = handleMoveHome();
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            newIndex = handleMoveEnd();
            break;
        case KeyEvent.KEYCODE_PAGE_DOWN:
            newIndex = handlePageDown(pageIndex, pageCount);
            break;
        case KeyEvent.KEYCODE_PAGE_UP:
            newIndex = handlePageUp(pageIndex);
            break;
        default:
            break;
    }

    if (DEBUG) {
        Log.v(TAG, String.format("handleKeyEvent FINISH: index [%d -> %s]",
                iconIdx, getStringIndex(newIndex)));
    }
    return newIndex;
}
 
Example 17
Source File: ReadArticleActivity.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int code = event.getKeyCode();
    boolean triggerAction;
    if (code == KeyEvent.KEYCODE_PAGE_UP || code == KeyEvent.KEYCODE_PAGE_DOWN) {
        triggerAction = (event.getAction() == KeyEvent.ACTION_UP);
    } else {
        triggerAction = (event.getAction() == KeyEvent.ACTION_DOWN);
    }

    if (triggerAction) {
        if (code == disableTouchKeyCode && (disableTouch || disableTouchOptionEnabled)) {
            disableTouch = !disableTouch;
            settings.setDisableTouchLastState(disableTouch);

            Log.d(TAG, "toggling touch screen, now disableTouch is " + disableTouch);
            showDisableTouchToast();
            return true;
        }

        boolean scroll = false;
        boolean up = false;

        switch (code) {
            case KeyEvent.KEYCODE_PAGE_UP:
            case KeyEvent.KEYCODE_PAGE_DOWN:
                scroll = true;
                up = code == KeyEvent.KEYCODE_PAGE_UP;
                break;

            case KeyEvent.KEYCODE_DPAD_UP:
            case KeyEvent.KEYCODE_DPAD_DOWN:
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                scroll = true;
                up = code == KeyEvent.KEYCODE_DPAD_UP || code == KeyEvent.KEYCODE_DPAD_LEFT;
                break;

            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                if (volumeButtonsScrolling) {
                    scroll = true;
                    up = code == KeyEvent.KEYCODE_VOLUME_UP;
                }
                break;
        }

        if (scroll) {
            scroll(up, screenScrollingPercent, smoothScrolling, true);
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}
 
Example 18
Source File: GalleryActivity.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mGalleryView == null) {
        return super.onKeyDown(keyCode, event);
    }

    // Check volume
    if (Settings.getVolumePage()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageRight();
            } else {
                mGalleryView.pageLeft();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageLeft();
            } else {
                mGalleryView.pageRight();
            }
            return true;
        }
    }

    // Check keyboard and Dpad
    switch (keyCode) {
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageRight();
            } else {
                mGalleryView.pageLeft();
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            mGalleryView.pageLeft();
            return true;
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageLeft();
            } else {
                mGalleryView.pageRight();
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            mGalleryView.pageRight();
            return true;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_SPACE:
        case KeyEvent.KEYCODE_MENU:
            onTapMenuArea();
            return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 19
Source File: GalleryActivity.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mGalleryView == null) {
        return super.onKeyDown(keyCode, event);
    }

    // Check volume
    if (Settings.getVolumePage()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageRight();
            } else {
                mGalleryView.pageLeft();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageLeft();
            } else {
                mGalleryView.pageRight();
            }
            return true;
        }
    }

    // Check keyboard and Dpad
    switch (keyCode) {
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageRight();
            } else {
                mGalleryView.pageLeft();
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            mGalleryView.pageLeft();
            return true;
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) {
                mGalleryView.pageLeft();
            } else {
                mGalleryView.pageRight();
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            mGalleryView.pageRight();
            return true;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_SPACE:
        case KeyEvent.KEYCODE_MENU:
            onTapMenuArea();
            return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 20
Source File: BaseMovementMethod.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Performs a movement key action.
 * The default implementation decodes the key down and invokes movement actions
 * such as {@link #down} and {@link #up}.
 * {@link #onKeyDown(TextView, Spannable, int, KeyEvent)} calls this method once
 * to handle an {@link KeyEvent#ACTION_DOWN}.
 * {@link #onKeyOther(TextView, Spannable, KeyEvent)} calls this method repeatedly
 * to handle each repetition of an {@link KeyEvent#ACTION_MULTIPLE}.
 *
 * @param widget The text view.
 * @param buffer The text buffer.
 * @param event The key event.
 * @param keyCode The key code.
 * @param movementMetaState The keyboard meta states used for movement.
 * @param event The key event.
 * @return True if the event was handled.
 */
protected boolean handleMovementKey(TextView widget, Spannable buffer,
        int keyCode, int movementMetaState, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return left(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return leftWord(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return lineStart(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return right(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return rightWord(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return lineEnd(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return up(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return top(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return down(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return bottom(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return pageUp(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return top(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return pageDown(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return bottom(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return home(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return top(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return end(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return bottom(widget, buffer);
            }
            break;
    }
    return false;
}