Java Code Examples for android.view.KeyEvent#KEYCODE_TAB

The following examples show how to use android.view.KeyEvent#KEYCODE_TAB . 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: TabViewPager.java    From 920-text-editor-v2 with Apache License 2.0 6 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) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll(FOCUS_LEFT);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll(FOCUS_RIGHT);
                break;
            case KeyEvent.KEYCODE_TAB:
                if (Build.VERSION.SDK_INT >= 11) {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if (KeyEventCompat.hasNoModifiers(event)) {
                        handled = arrowScroll(FOCUS_FORWARD);
                    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                        handled = arrowScroll(FOCUS_BACKWARD);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 2
Source File: CustomViewAbove.java    From quickmark with MIT License 6 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) {
	boolean handled = false;
	if (event.getAction() == KeyEvent.ACTION_DOWN) {
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_DPAD_LEFT:
			handled = arrowScroll(FOCUS_LEFT);
			break;
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			handled = arrowScroll(FOCUS_RIGHT);
			break;
		case KeyEvent.KEYCODE_TAB:
			if (Build.VERSION.SDK_INT >= 11) {
				// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
				// before Android 3.0. Ignore the tab key on those devices.
				if (KeyEventCompat.hasNoModifiers(event)) {
					handled = arrowScroll(FOCUS_FORWARD);
				} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
					handled = arrowScroll(FOCUS_BACKWARD);
				}
			}
			break;
		}
	}
	return handled;
}
 
Example 3
Source File: TokenCompleteTextView.java    From TokenAutoComplete with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    boolean handled = false;
    switch (keyCode) {
        case KeyEvent.KEYCODE_TAB:
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (event.hasNoModifiers()) {
                shouldFocusNext = true;
                handled = true;
            }
            break;
        case KeyEvent.KEYCODE_DEL:
            handled = !canDeleteSelection(1) || deleteSelectedObject();
            break;
    }

    return handled || super.onKeyDown(keyCode, event);
}
 
Example 4
Source File: VelocityViewPager.java    From Muzesto with GNU General Public License v3.0 6 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) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll(FOCUS_LEFT);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll(FOCUS_RIGHT);
                break;
            case KeyEvent.KEYCODE_TAB:
                if (Build.VERSION.SDK_INT >= 11) {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if (KeyEventCompat.hasNoModifiers(event)) {
                        handled = arrowScroll(FOCUS_FORWARD);
                    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                        handled = arrowScroll(FOCUS_BACKWARD);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 5
Source File: YViewPager.java    From YViewPagerDemo with Apache License 2.0 6 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) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll(FOCUS_LEFT);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll(FOCUS_RIGHT);
                break;
            case KeyEvent.KEYCODE_TAB:
                if (Build.VERSION.SDK_INT >= 11) {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if (KeyEventCompat.hasNoModifiers(event)) {
                        handled = arrowScroll(FOCUS_FORWARD);
                    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                        handled = arrowScroll(FOCUS_BACKWARD);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 6
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Monitor key presses in this view to see if the user types
 * any commit keys, which consist of ENTER, TAB, or DPAD_CENTER.
 * If the user has entered text that has contact matches and types
 * a commit key, create a chip from the topmost matching contact.
 * If the user has entered text that has no contact matches and types
 * a commit key, then create a chip from the text they have entered.
 */
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_TAB:
            if (event.hasNoModifiers()) {
                if (mSelectedChip != null) {
                    clearSelectedChip();
                } else {
                    commitDefault();
                }
            }
            break;
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 7
Source File: ViewPager.java    From adt-leanback-support with Apache License 2.0 6 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) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll(FOCUS_LEFT);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll(FOCUS_RIGHT);
                break;
            case KeyEvent.KEYCODE_TAB:
                if (Build.VERSION.SDK_INT >= 11) {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if (KeyEventCompat.hasNoModifiers(event)) {
                        handled = arrowScroll(FOCUS_FORWARD);
                    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                        handled = arrowScroll(FOCUS_BACKWARD);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 8
Source File: CustomViewAbove.java    From zen4android with MIT License 6 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) {
	boolean handled = false;
	if (event.getAction() == KeyEvent.ACTION_DOWN) {
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_DPAD_LEFT:
			handled = arrowScroll(FOCUS_LEFT);
			break;
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			handled = arrowScroll(FOCUS_RIGHT);
			break;
		case KeyEvent.KEYCODE_TAB:
			if (Build.VERSION.SDK_INT >= 11) {
				// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
				// before Android 3.0. Ignore the tab key on those devices.
				if (KeyEventCompat.hasNoModifiers(event)) {
					handled = arrowScroll(FOCUS_FORWARD);
				} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
					handled = arrowScroll(FOCUS_BACKWARD);
				}
			}
			break;
		}
	}
	return handled;
}
 
Example 9
Source File: ViewPagerEx.java    From ImageSliderWithSwipes with Apache License 2.0 6 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) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll(FOCUS_LEFT);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll(FOCUS_RIGHT);
                break;
            case KeyEvent.KEYCODE_TAB:
                if (Build.VERSION.SDK_INT >= 11) {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if (KeyEventCompat.hasNoModifiers(event)) {
                        handled = arrowScroll(FOCUS_FORWARD);
                    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                        handled = arrowScroll(FOCUS_BACKWARD);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 10
Source File: SliderKeyTestCommon.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testActivateLastThumb_tab_unhandled() {
  slider.requestFocus();

  slider.setFocusedThumbIndex(countTestValues() - 1);

  activateFocusedThumb();

  KeyEventBuilder tab = new KeyEventBuilder(KeyEvent.KEYCODE_TAB);
  boolean handledDown = slider.dispatchKeyEvent(tab.buildDown());
  boolean handledUp = slider.dispatchKeyEvent(tab.buildUp());

  assertThat(handledDown).isFalse();
  assertThat(handledUp).isFalse();
}
 
Example 11
Source File: KeyboardNavigationListener.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_TAB && event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.hasNoModifiers()) {
            View forward = getNextFocusForward();
            if (forward != null) return forward.requestFocus();
        } else if (event.isShiftPressed()) {
            View backward = getNextFocusBackward();
            if (backward != null) return backward.requestFocus();
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
        return handleEnterKeyPress();
    }
    return false;
}
 
Example 12
Source File: KeyboardNavigationListener.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_TAB && event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.hasNoModifiers()) {
            View forward = getNextFocusForward();
            if (forward != null) return forward.requestFocus();
        } else if (event.isShiftPressed()) {
            View backward = getNextFocusBackward();
            if (backward != null) return backward.requestFocus();
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
        return handleEnterKeyPress();
    }
    return false;
}
 
Example 13
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * Monitor key presses in this view to see if the user types any commit keys, which consist of ENTER, TAB, or
 * DPAD_CENTER. If the user has entered text that has contact matches and types a commit key, create a chip from the
 * topmost matching contact. If the user has entered text that has no contact matches and types a commit key, then
 * create a chip from the text they have entered.
 */
@Override
public boolean onKeyUp(final int keyCode,final KeyEvent event)
  {
  switch(keyCode)
    {
    case KeyEvent.KEYCODE_TAB:
      if(event.hasNoModifiers())
        if(mSelectedChip!=null)
          clearSelectedChip();
        else commitDefault();
      break;
    }
  return super.onKeyUp(keyCode,event);
  }
 
Example 14
Source File: SliderKeyTestCommon.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testFocusLastThumb_tab_unhandled() {
  slider.requestFocus();

  slider.setFocusedThumbIndex(countTestValues() - 1);

  KeyEventBuilder tab = new KeyEventBuilder(KeyEvent.KEYCODE_TAB);
  boolean handledDown = slider.dispatchKeyEvent(tab.buildDown());
  boolean handledUp = slider.dispatchKeyEvent(tab.buildUp());

  assertThat(handledDown).isFalse();
  assertThat(handledUp).isFalse();
}
 
Example 15
Source File: SliderPager.java    From Android-Image-Slider with Apache License 2.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(@NonNull KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                    handled = pageLeft();
                } else {
                    handled = arrowScroll(FOCUS_LEFT);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (event.hasModifiers(KeyEvent.META_ALT_ON)) {
                    handled = pageRight();
                } else {
                    handled = arrowScroll(FOCUS_RIGHT);
                }
                break;
            case KeyEvent.KEYCODE_TAB:
                if (event.hasNoModifiers()) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
                break;
        }
    }
    return handled;
}
 
Example 16
Source File: ContentViewClient.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean shouldOverrideKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    // We need to send almost every key to WebKit. However:
    // 1. We don't want to block the device on the renderer for
    // some keys like menu, home, call.
    // 2. There are no WebKit equivalents for some of these keys
    // (see app/keyboard_codes_win.h)
    // Note that these are not the same set as KeyEvent.isSystemKey:
    // for instance, AKEYCODE_MEDIA_* will be dispatched to webkit.
    if (keyCode == KeyEvent.KEYCODE_MENU ||
        keyCode == KeyEvent.KEYCODE_HOME ||
        keyCode == KeyEvent.KEYCODE_BACK ||
        keyCode == KeyEvent.KEYCODE_CALL ||
        keyCode == KeyEvent.KEYCODE_ENDCALL ||
        keyCode == KeyEvent.KEYCODE_POWER ||
        keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
        keyCode == KeyEvent.KEYCODE_CAMERA ||
        keyCode == KeyEvent.KEYCODE_FOCUS ||
        keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
        keyCode == KeyEvent.KEYCODE_VOLUME_MUTE ||
        keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        return true;
    }

    // We also have to intercept some shortcuts before we send them to the ContentView.
    if (event.isCtrlPressed() && (
            keyCode == KeyEvent.KEYCODE_TAB ||
            keyCode == KeyEvent.KEYCODE_W ||
            keyCode == KeyEvent.KEYCODE_F4)) {
        return true;
    }

    return false;
}
 
Example 17
Source File: SdkCenteredViewPager.java    From Android-SDK-Demo with MIT License 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)
{
    boolean handled = false;
    if ( event.getAction() == KeyEvent.ACTION_DOWN )
    {
        switch ( event.getKeyCode() )
        {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll( FOCUS_LEFT );
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll( FOCUS_RIGHT );
                break;
            case KeyEvent.KEYCODE_TAB:
                if ( Build.VERSION.SDK_INT >= 11 )
                {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if ( event.hasNoModifiers() )
                    {
                        handled = arrowScroll( FOCUS_FORWARD );
                    }
                    else if ( event.hasModifiers( KeyEvent.META_SHIFT_ON ) )
                    {
                        handled = arrowScroll( FOCUS_BACKWARD );
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 18
Source File: SearchView.java    From zen4android with MIT License 4 votes vote down vote up
/**
 * React to the user typing while in the suggestions list. First, check for
 * action keys. If not handled, try refocusing regular characters into the
 * EditText.
 */
private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) {
    // guard against possible race conditions (late arrival after dismiss)
    if (mSearchable == null) {
        return false;
    }
    if (mSuggestionsAdapter == null) {
        return false;
    }
    if (event.getAction() == KeyEvent.ACTION_DOWN && KeyEventCompat.hasNoModifiers(event)) {
        // First, check for enter or search (both of which we'll treat as a
        // "click")
        if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_TAB) {
            int position = mQueryTextView.getListSelection();
            return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null);
        }

        // Next, check for left/right moves, which we use to "return" the
        // user to the edit view
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            // give "focus" to text editor, with cursor at the beginning if
            // left key, at end if right key
            // TODO: Reverse left/right for right-to-left languages, e.g.
            // Arabic
            int selPoint = (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) ? 0 : mQueryTextView
                    .length();
            mQueryTextView.setSelection(selPoint);
            mQueryTextView.setListSelection(0);
            mQueryTextView.clearListSelection();
            ensureImeVisible(mQueryTextView, true);

            return true;
        }

        // Next, check for an "up and out" move
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mQueryTextView.getListSelection()) {
            // TODO: restoreUserQuery();
            // let ACTV complete the move
            return false;
        }

        // Next, check for an "action key"
        // TODO SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
        // TODO if ((actionKey != null)
        // TODO         && ((actionKey.getSuggestActionMsg() != null) || (actionKey
        // TODO                 .getSuggestActionMsgColumn() != null))) {
        // TODO     // launch suggestion using action key column
        // TODO     int position = mQueryTextView.getListSelection();
        // TODO     if (position != ListView.INVALID_POSITION) {
        // TODO         Cursor c = mSuggestionsAdapter.getCursor();
        // TODO         if (c.moveToPosition(position)) {
        // TODO             final String actionMsg = getActionKeyMessage(c, actionKey);
        // TODO             if (actionMsg != null && (actionMsg.length() > 0)) {
        // TODO                 return onItemClicked(position, keyCode, actionMsg);
        // TODO             }
        // TODO         }
        // TODO     }
        // TODO }
    }
    return false;
}
 
Example 19
Source File: UndoRedoSupportEditText.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
     * CTRL + C copy
     * CTRL + V paste
     * CTRL + B: compile
     * CTRL + R generate
     * CTRL + X cut
     * CTRL + Z undo
     * CTRL + Y redo
     * CTRL + Q quit
     * CTRL + S save
     * CTRL + O open
     * CTRL + F find
     * CTRL + H find and replace
     * CTRL + L format code
     * CTRL + G: goto line
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (DLog.DEBUG) Log.w(TAG, "onKeyDown: " + keyCode + " " + event);
        if (handleControlKey(keyCode, event, false)) {
            return true;
        }
        if (event.isCtrlPressed() || mKeyListener.mControlKey.isActive()) {
//            Log.i(TAG, "onKeyDown: process");
            switch (keyCode) {
                case KeyEvent.KEYCODE_A:
                    selectAll();
                    return true;
                case KeyEvent.KEYCODE_X:
                    cut();
                    return true;
                case KeyEvent.KEYCODE_C:
                    copy();
                    return true;
                case KeyEvent.KEYCODE_V:
                    paste();
                    return true;
                case KeyEvent.KEYCODE_G: //go to line
                    if (editorControl != null)
                        editorControl.goToLine();
                    return true;
                case KeyEvent.KEYCODE_L: //format
                    if (editorControl != null)
                        editorControl.formatCode();
                    return true;
                case KeyEvent.KEYCODE_Z:
                    if (canUndo()) {
                        undo();
                    }
                    return true;
                case KeyEvent.KEYCODE_Y:
                    if (canRedo()) {
                        redo();
                    }
                    return true;
                case KeyEvent.KEYCODE_S:
                    if (editorControl != null)
                        editorControl.saveCurrentFile();
                    return true;
                case KeyEvent.KEYCODE_N:
                    if (editorControl != null)
                        editorControl.saveAs();
                    return true;
                default:
                    return super.onKeyDown(keyCode, event);
            }
        } else {
            switch (keyCode) {
                case KeyEvent.KEYCODE_TAB:
                    String textToInsert = mSettings.getTabStr();
                    int start, end;
                    start = Math.max(getSelectionStart(), 0);
                    end = Math.max(getSelectionEnd(), 0);
                    getText().replace(Math.min(start, end), Math.max(start, end),
                            textToInsert, 0, textToInsert.length());
                    return true;
                default:
                    try {
                        return super.onKeyDown(keyCode, event);
                    } catch (Exception e) {
                    }
                    return false;

            }
        }
    }
 
Example 20
Source File: GridTimePickerDialog.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(HALF_DAY_1)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(HALF_DAY_2)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(HALF_DAY_1) || keyCode == getAmOrPmKeyCode(HALF_DAY_2)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}