Java Code Examples for android.view.KeyEvent#isAltPressed()

The following examples show how to use android.view.KeyEvent#isAltPressed() . 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: FormEntryActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            FirebaseAnalyticsUtil.reportFormQuitAttempt(AnalyticsParamValue.BACK_BUTTON_PRESS);
            triggerUserQuitInput();
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.isAltPressed() && !uiController.shouldIgnoreSwipeAction()) {
                uiController.setIsAnimatingSwipe();
                uiController.showNextView();
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.isAltPressed() && !uiController.shouldIgnoreSwipeAction()) {
                uiController.setIsAnimatingSwipe();
                uiController.showPreviousView(true);
                return true;
            }
            break;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: DrawActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:

            createQuitDrawDialog();
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.isAltPressed()) {

                createQuitDrawDialog();
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.isAltPressed()) {

                createQuitDrawDialog();
                return true;
            }
            break;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 3
Source File: EditMessage.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent e) {
    if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) {
        lastInputWasTab = false;
        if (keyboardListener != null && keyboardListener.onEnterPressed()) {
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) {
        if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) {
            lastInputWasTab = true;
            return true;
        }
    } else {
        lastInputWasTab = false;
    }
    return super.onKeyDown(keyCode, e);
}
 
Example 4
Source File: ScrollViewer.java    From AirFree-Client with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 *
 * @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()) {
		 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, false);
		 } else {
			 handled = fullScroll(View.FOCUS_UP, false);
		 }
		 break;
	 case KeyEvent.KEYCODE_DPAD_DOWN:
		 if (!event.isAltPressed()) {
			 handled = arrowScroll(View.FOCUS_DOWN, false);
		 } else {
			 handled = fullScroll(View.FOCUS_DOWN, false);
		 }
		 break;
	 case KeyEvent.KEYCODE_DPAD_LEFT:
		 if (!event.isAltPressed()) {
			 handled = arrowScroll(View.FOCUS_LEFT, true);
		 } else {
			 handled = fullScroll(View.FOCUS_LEFT, true);
		 }
		 break;
	 case KeyEvent.KEYCODE_DPAD_RIGHT:
		 if (!event.isAltPressed()) {
			 handled = arrowScroll(View.FOCUS_RIGHT, true);
		 } else {
			 handled = fullScroll(View.FOCUS_RIGHT, true);
		 }
		 break;
	 }
 }
 return handled;
}
 
Example 5
Source File: StringWidget.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.isAltPressed()) {
        return false;
    }
    widgetEntryChanged();
    return super.onKeyDown(keyCode, event);
}
 
Example 6
Source File: KeyAssignmentUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a KeyEvent into a long which can be kept in settings and compared to key presses when
 * the service is in use.
 *
 * @param keyEvent The key event to convert. The (non-extended) keycode must not be a modifier.
 * @return An extended key code that includes modifier information
 */
public static long keyEventToExtendedKeyCode(KeyEvent keyEvent) {
  long returnValue = keyEvent.getKeyCode();
  returnValue |= (keyEvent.isShiftPressed()) ? (((long) KeyEvent.META_SHIFT_ON) << 32) : 0;
  returnValue |= (keyEvent.isCtrlPressed()) ? (((long) KeyEvent.META_CTRL_ON) << 32) : 0;
  returnValue |= (keyEvent.isAltPressed()) ? (((long) KeyEvent.META_ALT_ON) << 32) : 0;
  return returnValue;
}
 
Example 7
Source File: NestedScrollView.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean executeKeyEvent(KeyEvent event) {
    this.mTempRect.setEmpty();
    if (canScroll()) {
        boolean handled = false;
        if (event.getAction() == 0) {
            switch (event.getKeyCode()) {
                case 19:
                    if (!event.isAltPressed()) {
                        handled = arrowScroll(33);
                        break;
                    }
                    handled = fullScroll(33);
                    break;
                case 20:
                    if (!event.isAltPressed()) {
                        handled = arrowScroll(130);
                        break;
                    }
                    handled = fullScroll(130);
                    break;
                case 62:
                    pageScroll(event.isShiftPressed() ? 33 : 130);
                    break;
            }
        }
        return handled;
    } else if (!isFocused() || event.getKeyCode() == 4) {
        return false;
    } else {
        View currentFocused = findFocus();
        if (currentFocused == this) {
            currentFocused = null;
        }
        View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, 130);
        if (nextFocused == null || nextFocused == this || !nextFocused.requestFocus(130)) {
            return false;
        }
        return true;
    }
}
 
Example 8
Source File: Apps.java    From emerald with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (event.getAction() != KeyEvent.ACTION_DOWN) {
		return super.onKeyDown(keyCode, event);
	}
	if (keyCode == KeyEvent.KEYCODE_MENU) {
		menu();
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_BACK) {
		//Log.v(APP_TAG, "BACK pressed");
		if (searchIsOpened) {
			closeSearch();
		} else if (!isDefaultLauncher()) {
			finish();
			return true;
		} else {
			if (categories.getCurCategory().equals(CategoryManager.HIDDEN)) {
				findViewById(R.id.quit_hidden_apps).setVisibility(View.GONE);
				hideMainBarIfNeeded();
			}
			categories.prevCategory();
		}
		loadFilteredApps();
		return true;
	} else if (event.isAltPressed()) {
		if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) {
			Object app = dock.getApp(keyCode-KeyEvent.KEYCODE_1);
			if (app != null) {
				if (app instanceof AppData) {
					launch((AppData)app);
				} else if (app instanceof ShortcutData) {
					launch((ShortcutData)app);
				}
				return true;
			} else {
				return super.onKeyDown(keyCode, event);
			}
		} else if (keyCode == KeyEvent.KEYCODE_0 && !searchIsOpened) {
			openSearch();
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
			categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS));
			loadFilteredApps();
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			categories.setCurCategory(categories.getCategory(CategoryManager.NEXT));
			loadFilteredApps();
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
			openCategoriesList();
		} else {
			return super.onKeyDown(keyCode, event);
		}
		return super.onKeyDown(keyCode, event);
	} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
		View view = getCurrentFocus();
		if (view != null) {
			Object viewTag = view.getTag();
			if (viewTag instanceof AppData) {
				launch((AppData)viewTag);
				return true;
			} else if (viewTag instanceof ShortcutData) {
				launch((ShortcutData)viewTag);
				return true;
			}
			return super.onKeyDown(keyCode, event);
		}
		return super.onKeyDown(keyCode, event);
	} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
		if (options.getBoolean(Keys.VOLUME_BUTTONS, false)) {
			categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS));
			loadFilteredApps();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
		if (options.getBoolean(Keys.VOLUME_BUTTONS, false)) {
			categories.setCurCategory(categories.getCategory(CategoryManager.NEXT));
			loadFilteredApps();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	} else {
		return super.onKeyDown(keyCode, event);
	}
}
 
Example 9
Source File: PlaybackActivity.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
@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 {
            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);
    }
}
 
Example 10
Source File: MyScrollView.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
boolean executeKeyEvent(@NonNull 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 = fullScroll(View.FOCUS_UP);
                } else {
                    handled = arrowScroll(View.FOCUS_UP);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (event.isAltPressed()) {
                    handled = fullScroll(View.FOCUS_DOWN);
                } else {
                    handled = arrowScroll(View.FOCUS_DOWN);
                }
                break;
            case KeyEvent.KEYCODE_SPACE:
                pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
                break;
        }
    }

    return handled;
}
 
Example 11
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @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;
}
 
Example 12
Source File: KeyboardShortcuts.java    From delion with Apache License 2.0 4 votes vote down vote up
private static int getMetaState(KeyEvent event) {
    return (event.isCtrlPressed() ? CTRL : 0)
            | (event.isAltPressed() ? ALT : 0)
            | (event.isShiftPressed() ? SHIFT : 0);
}
 
Example 13
Source File: TwoDScrollView.java    From intra42 with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    tempRect.setEmpty();
    if (!canScroll()) {
        if (isFocused()) {
            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, false);
                } else {
                    handled = fullScroll(View.FOCUS_UP, false);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_DOWN, false);
                } else {
                    handled = fullScroll(View.FOCUS_DOWN, false);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_LEFT, true);
                } else {
                    handled = fullScroll(View.FOCUS_LEFT, true);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_RIGHT, true);
                } else {
                    handled = fullScroll(View.FOCUS_RIGHT, true);
                }
                break;
        }
    }
    return handled;
}
 
Example 14
Source File: SudokuBoardView.java    From opensudoku with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (!mReadonly) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_UP:
                return moveCellSelection(0, -1);
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                return moveCellSelection(1, 0);
            case KeyEvent.KEYCODE_DPAD_DOWN:
                return moveCellSelection(0, 1);
            case KeyEvent.KEYCODE_DPAD_LEFT:
                return moveCellSelection(-1, 0);
            case KeyEvent.KEYCODE_0:
            case KeyEvent.KEYCODE_SPACE:
            case KeyEvent.KEYCODE_DEL:
                // clear value in selected cell
                // TODO: I'm not really sure that this is thread-safe
                if (mSelectedCell != null) {
                    if (event.isShiftPressed() || event.isAltPressed()) {
                        setCellNote(mSelectedCell, CellNote.EMPTY);
                    } else {
                        setCellValue(mSelectedCell, 0);
                        moveCellSelectionRight();
                    }
                }
                return true;
            case KeyEvent.KEYCODE_DPAD_CENTER:
                if (mSelectedCell != null) {
                    onCellTapped(mSelectedCell);
                }
                return true;
        }

        if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9 && mSelectedCell != null) {
            int selNumber = keyCode - KeyEvent.KEYCODE_0;
            Cell cell = mSelectedCell;

            if (event.isShiftPressed() || event.isAltPressed()) {
                // add or remove number in cell's note
                setCellNote(cell, cell.getNote().toggleNumber(selNumber));
            } else {
                // enter number in cell
                setCellValue(cell, selNumber);
                moveCellSelectionRight();
            }
            return true;
        }
    }


    return false;
}
 
Example 15
Source File: CustomScrollView.java    From zhangshangwuda with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 * 
 * @param event
 *            The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
	mTempRect.setEmpty();

	boolean handled = false;

	if (event.getAction() == KeyEvent.ACTION_DOWN) {
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_DPAD_LEFT:
			if (canScrollH()) {
				if (!event.isAltPressed()) {
					handled = arrowScrollH(View.FOCUS_LEFT);
				} else {
					handled = fullScrollH(View.FOCUS_LEFT);
				}
			}
			break;
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			if (canScrollH()) {
				if (!event.isAltPressed()) {
					handled = arrowScrollH(View.FOCUS_RIGHT);
				} else {
					handled = fullScrollH(View.FOCUS_RIGHT);
				}
			}
			break;
		case KeyEvent.KEYCODE_DPAD_UP:
			if (canScrollV()) {
				if (!event.isAltPressed()) {
					handled = arrowScrollV(View.FOCUS_UP);
				} else {
					handled = fullScrollV(View.FOCUS_UP);
				}
			}
			break;
		case KeyEvent.KEYCODE_DPAD_DOWN:
			if (canScrollV()) {
				if (!event.isAltPressed()) {
					handled = arrowScrollV(View.FOCUS_DOWN);
				} else {
					handled = fullScrollV(View.FOCUS_DOWN);
				}
			}
			break;
		}
	}
	return handled;
}
 
Example 16
Source File: TwoDScrollView.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 *
 * @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()) {
            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, false);
                } else {
                    handled = fullScroll(View.FOCUS_UP, false);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_DOWN, false);
                } else {
                    handled = fullScroll(View.FOCUS_DOWN, false);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_LEFT, true);
                } else {
                    handled = fullScroll(View.FOCUS_LEFT, true);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_RIGHT, true);
                } else {
                    handled = fullScroll(View.FOCUS_RIGHT, true);
                }
                break;
        }
    }
    return handled;
}
 
Example 17
Source File: HVScrollView.java    From JsDroidEditor with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    mTempRect.setEmpty();

    boolean handled = false;

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (canScrollH()) {
                    if (!event.isAltPressed()) {
                        handled = arrowScrollH(View.FOCUS_LEFT);
                    } else {
                        handled = fullScrollH(View.FOCUS_LEFT);
                    }
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (canScrollH()) {
                    if (!event.isAltPressed()) {
                        handled = arrowScrollH(View.FOCUS_RIGHT);
                    } else {
                        handled = fullScrollH(View.FOCUS_RIGHT);
                    }
                }
                break;
            case KeyEvent.KEYCODE_DPAD_UP:
                if (canScrollV()) {
                    if (!event.isAltPressed()) {
                        handled = arrowScrollV(View.FOCUS_UP);
                    } else {
                        handled = fullScrollV(View.FOCUS_UP);
                    }
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (canScrollV()) {
                    if (!event.isAltPressed()) {
                        handled = arrowScrollV(View.FOCUS_DOWN);
                    } else {
                        handled = fullScrollV(View.FOCUS_DOWN);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 18
Source File: NestedScrollView.java    From MyBlogDemo with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @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;
}
 
Example 19
Source File: KeyboardShortcuts.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private static int getMetaState(KeyEvent event) {
    return (event.isCtrlPressed() ? CTRL : 0)
            | (event.isAltPressed() ? ALT : 0)
            | (event.isShiftPressed() ? SHIFT : 0);
}
 
Example 20
Source File: HorizontalScrollView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @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()) {
            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;
    }

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

    return handled;
}