android.view.KeyEvent#hasNoModifiers ( )源码实例Demo

下面列出了android.view.KeyEvent#hasNoModifiers ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: AutoCompleteTextView.java
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    boolean consumed = mPopup.onKeyUp(keyCode, event);
    if (consumed) {
        switch (keyCode) {
        // if the list accepts the key events and the key event
        // was a click, the text view gets the selected item
        // from the drop down as its content
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_TAB:
            if (event.hasNoModifiers()) {
                performCompletion();
            }
            return true;
        }
    }

    if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) {
        performCompletion();
        return true;
    }

    return super.onKeyUp(keyCode, event);
}
 
private boolean onKeyEventInternal(KeyEvent event) {
  if (!processKeyEvent(event)) {
    return false;
  }

  // The plain backspace key clears the shortcut; anything else is treated as a new shortcut.
  if (event.getKeyCode() == KeyEvent.KEYCODE_DEL && event.hasNoModifiers()) {
    clearTemporaryKeyComboCode();
  } else {
    setTemporaryKeyComboCodeWithTriggerModifier(KeyComboManager.getKeyComboCode(event));
  }

  updateKeyAssignmentText();

  return true;
}
 
源代码3 项目: ncalc   文件: NineOldViewPager.java
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @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;
}
 
源代码4 项目: AsteroidOSSync   文件: CustomViewPager.java
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @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;
}
 
源代码5 项目: talk-android   文件: RecipientEditTextView.java
/**
 * 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);
}
 
源代码6 项目: VelocityViewPager   文件: VelocityViewPager.java
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @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 (event.hasNoModifiers()) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
                break;
        }
    }
    return handled;
}
 
@Override
public boolean onKeyDown(int keyCode, 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 = deleteSelectedObject(false);
            break;
    }

    return handled || super.onKeyDown(keyCode, event);
}
 
源代码8 项目: AppCompat-Extension-Library   文件: ViewPager.java
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @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;
}
 
源代码9 项目: 365browser   文件: LocationBarLayout.java
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    boolean retVal = super.dispatchKeyEvent(event);
    if (retVal && mUrlHasFocus && mUrlFocusedWithoutAnimations
            && event.getAction() == KeyEvent.ACTION_DOWN && event.isPrintingKey()
            && event.hasNoModifiers()) {
        handleUrlFocusAnimation(mUrlHasFocus);
    }
    return retVal;
}
 
源代码10 项目: CoolViewPager   文件: CoolViewPager.java
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @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;
}
 
源代码11 项目: Android-Image-Slider   文件: SliderPager.java
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @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;
}
 
源代码12 项目: ChipsLibrary   文件: RecipientEditTextView.java
/**
 * If there is a selected chip, delegate the key events to the selected chip.
 */
@Override
public boolean onKeyDown(final int keyCode,final KeyEvent event)
  {
  if(mSelectedChip!=null&&keyCode==KeyEvent.KEYCODE_DEL)
    {
    if(mAlternatesPopup!=null&&mAlternatesPopup.isShowing())
      mAlternatesPopup.dismiss();
    removeChip(mSelectedChip,true);
    }
  switch(keyCode)
    {
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_DPAD_CENTER:
      if(event.hasNoModifiers())
        {
        if(commitDefault())
          return true;
        if(mSelectedChip!=null)
          {
          clearSelectedChip();
          return true;
          }
        else if(focusNext())
          return true;
        }
      break;
    }
  return super.onKeyDown(keyCode,event);
  }
 
源代码13 项目: ChipsLibrary   文件: RecipientEditTextView.java
/**
 * 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);
  }
 
源代码14 项目: Android-SDK-Demo   文件: SdkCenteredViewPager.java
/**
 * You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy.
 *
 * @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;
}
 
源代码15 项目: material-components-android   文件: BaseSlider.java
private Boolean onKeyDownNoActiveThumb(int keyCode, @NonNull KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_TAB:
      if (event.hasNoModifiers()) {
        return moveFocus(1);
      }

      if (event.isShiftPressed()) {
        return moveFocus(-1);
      }
      return false;
    case KeyEvent.KEYCODE_DPAD_LEFT:
      moveFocusInAbsoluteDirection(-1);
      return true;
    case KeyEvent.KEYCODE_MINUS:
      moveFocus(-1);
      return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
      moveFocusInAbsoluteDirection(1);
      return true;
    case KeyEvent.KEYCODE_EQUALS:
      // Numpad Plus == Shift + Equals, at least in AVD, so fall through.
    case KeyEvent.KEYCODE_PLUS:
      moveFocus(1);
      return true;
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
      activeThumbIdx = focusedThumbIdx;
      postInvalidate();
      return true;
    default:
      // Nothing to do in this case.
  }

  return null;
}
 
@Override
public void handleKeyboardEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && mTab.getActivity() != null) {
        if (mTab.getActivity().onKeyDown(event.getKeyCode(), event)) return;

        // Handle the Escape key here (instead of in KeyboardShortcuts.java), so it doesn't
        // interfere with other parts of the activity (e.g. the URL bar).
        if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNoModifiers()) {
            WebContents wc = mTab.getWebContents();
            if (wc != null) wc.stop();
            return;
        }
    }
    handleMediaKey(event);
}
 
源代码17 项目: android_9.0.0_r45   文件: SearchView.java
public boolean onKey(View v, int keyCode, KeyEvent event) {
    // guard against possible race conditions
    if (mSearchable == null) {
        return false;
    }

    if (DBG) {
        Log.d(LOG_TAG, "mTextListener.onKey(" + keyCode + "," + event + "), selection: "
                + mSearchSrcTextView.getListSelection());
    }

    // If a suggestion is selected, handle enter, search key, and action keys
    // as presses on the selected suggestion
    if (mSearchSrcTextView.isPopupShowing()
            && mSearchSrcTextView.getListSelection() != ListView.INVALID_POSITION) {
        return onSuggestionsKey(v, keyCode, event);
    }

    // If there is text in the query box, handle enter, and action keys
    // The search key is handled by the dialog's onKeyDown().
    if (!mSearchSrcTextView.isEmpty() && event.hasNoModifiers()) {
        if (event.getAction() == KeyEvent.ACTION_UP) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                v.cancelLongPress();

                // Launch as a regular search.
                launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, mSearchSrcTextView.getText()
                        .toString());
                return true;
            }
        }
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
            if ((actionKey != null) && (actionKey.getQueryActionMsg() != null)) {
                launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mSearchSrcTextView
                        .getText().toString());
                return true;
            }
        }
    }
    return false;
}
 
源代码18 项目: android_tv_metro   文件: MetroLayout.java
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Handle automatic focus changes.
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int direction = 0;
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_LEFT;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_RIGHT;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_UP:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_UP;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_DOWN;
                }
                break;
            case KeyEvent.KEYCODE_TAB:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_FORWARD;
                } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                    direction = View.FOCUS_BACKWARD;
                }
                break;
        }
        if (direction == View.FOCUS_DOWN || direction == View.FOCUS_UP) {
            View focused = findFocus();
            if (focused != null) {
                View v = focused.focusSearch(direction);
                if (v == null) {
                    Utils.playKeySound(this, Utils.SOUND_ERROR_KEY);
                    mMetroCursorView.showIndicator();
                }
            }
        }
    }
    boolean ret = super.dispatchKeyEvent(event);
    return ret;
}
 
源代码19 项目: DateTimePicker   文件: SimpleMonthView.java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // We need to handle focus change within the SimpleMonthView because we are simulating
    // multiple Views. The arrow keys will move between days until there is no space (no
    // day to the left, top, right, or bottom). Focus forward and back jumps out of the
    // SimpleMonthView, skipping over other SimpleMonthViews in the parent ViewPager
    // to the next focusable View in the hierarchy.
    boolean focusChanged = false;
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(!isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay > 7) {
                    mHighlightedDay -= 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay <= mDaysInMonth - 7) {
                    mHighlightedDay += 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (mHighlightedDay != -1) {
                onDayClicked(mHighlightedDay);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_TAB: {
            int focusChangeDirection = 0;
            if (event.hasNoModifiers()) {
                focusChangeDirection = View.FOCUS_FORWARD;
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                focusChangeDirection = View.FOCUS_BACKWARD;
            }
            if (focusChangeDirection != 0) {
                final ViewParent parent = getParent();
                // move out of the ViewPager next/previous
                View nextFocus = this;
                do {
                    nextFocus = nextFocus.focusSearch(focusChangeDirection);
                } while (nextFocus != null && nextFocus != this &&
                        nextFocus.getParent() == parent);
                if (nextFocus != null) {
                    nextFocus.requestFocus();
                    return true;
                }
            }
            break;
        }
    }
    if (focusChanged) {
        invalidate();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
 
源代码20 项目: material-components-android   文件: BaseSlider.java
@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
  if (!isEnabled()) {
    return super.onKeyDown(keyCode, event);
  }

  // If there's only one thumb, we can select it right away.
  if (values.size() == 1) {
    activeThumbIdx = 0;
  }

  // If there is no active thumb, key events will be used to pick the thumb to change.
  if (activeThumbIdx == -1) {
    Boolean handled = onKeyDownNoActiveThumb(keyCode, event);
    return handled != null ? handled : super.onKeyDown(keyCode, event);
  }

  isLongPress |= event.isLongPress();
  Float increment = calculateIncrementForKey(keyCode);
  if (increment != null) {
    if (snapActiveThumbToValue(values.get(activeThumbIdx) + increment)) {
      updateHaloHotspot();
      postInvalidate();
    }
    return true;
  }
  switch (keyCode) {
    case KeyEvent.KEYCODE_TAB:
      if (event.hasNoModifiers()) {
        return moveFocus(1);
      }

      if (event.isShiftPressed()) {
        return moveFocus(-1);
      }
      return false;
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
      activeThumbIdx = -1;
      for (TooltipDrawable label : labels) {
        ViewUtils.getContentViewOverlay(this).remove(label);
      }
      postInvalidate();
      return true;
    default:
      // Nothing to do in this case.
  }

  return super.onKeyDown(keyCode, event);
}
 
 方法所在类
 同类方法