android.view.KeyEvent.isLongPress()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(296)

本文整理了Java中android.view.KeyEvent.isLongPress()方法的一些代码示例,展示了KeyEvent.isLongPress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent.isLongPress()方法的具体详情如下:
包路径:android.view.KeyEvent
类名称:KeyEvent
方法名:isLongPress

KeyEvent.isLongPress介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  boolean handled = super.onKeyDown(keyCode, event);

  // Eat the long press event so the keyboard doesn't come up.
  if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
    return true;
  }

  return handled;
}

代码示例来源:origin: stackoverflow.com

private void bindKeyEvents(){
  this.webView.setOnKeyListener(new View.OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        if (event.getAction() == KeyEvent.ACTION_UP){
          Log.d("testApp", "Release");
          return true;
        }
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()){
          Log.d("testApp", "Long Press");
          return true;
        }
        if (event.getAction() == KeyEvent.ACTION_DOWN){
          event.startTracking();
          Log.d("testApp", "Press");
          return true;
        }
      }
      return true;
    }
  }); 
}

代码示例来源:origin: rockon999/LeanbackLauncher

public boolean dispatchKeyEvent(KeyEvent event) {
  int action = event.getAction();
  if (Util.isConfirmKey(event.getKeyCode())) {
    if (event.isLongPress()) {
      this.mEatDpadCenterKeyDown = true;
      Util.playErrorSound(getContext());
      return true;
    } else if (action == 1) {
      if (this.mEatDpadCenterKeyDown) {
        this.mEatDpadCenterKeyDown = false;
        return true;
      }
      this.mClickDeviceId = event.getDeviceId();
    }
  }
  return super.dispatchKeyEvent(event);
}

代码示例来源:origin: MoMoWait/LeanbackLauncher

public boolean dispatchKeyEvent(KeyEvent event) {
  int action = event.getAction();
  if (Util.isConfirmKey(event.getKeyCode())) {
    if (event.isLongPress()) {
      this.mEatDpadCenterKeyDown = true;
      Util.playErrorSound(getContext());
      return true;
    } else if (action == 1) {
      if (this.mEatDpadCenterKeyDown) {
        this.mEatDpadCenterKeyDown = false;
        return true;
      }
      this.mClickDeviceId = event.getDeviceId();
    }
  }
  return super.dispatchKeyEvent(event);
}

代码示例来源:origin: com.willowtreeapps/oak-demos

if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()) {
  mMenuKeyIsLongPress = true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {

代码示例来源:origin: WeAreFairphone/FP2-Launcher

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  final int uniChar = event.getUnicodeChar();
  final boolean handled = super.onKeyDown(keyCode, event);
  final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
  if (!handled && acceptFilter() && isKeyNotWhitespace) {
    boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
        keyCode, event);
    if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
      // something usable has been typed - start a search
      // the typed text will be retrieved and cleared by
      // showSearchDialog()
      // If there are multiple keystrokes before the search dialog takes focus,
      // onSearchRequested() will be called for every keystroke,
      // but it is idempotent, so it's fine.
      return onSearchRequested();
    }
  }
  // Eat the long press event so the keyboard doesn't come up.
  return keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress() || handled;
}

代码示例来源:origin: klinker24/launcher3

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  final int uniChar = event.getUnicodeChar();
  final boolean handled = super.onKeyDown(keyCode, event);
  final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
  if (!handled && acceptFilter() && isKeyNotWhitespace) {
    boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
        keyCode, event);
    if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
      // something usable has been typed - start a search
      // the typed text will be retrieved and cleared by
      // showSearchDialog()
      // If there are multiple keystrokes before the search dialog takes focus,
      // onSearchRequested() will be called for every keystroke,
      // but it is idempotent, so it's fine.
      return onSearchRequested();
    }
  }
  // Eat the long press event so the keyboard doesn't come up.
  if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
    return true;
  }
  return handled;
}

代码示例来源:origin: fookwood/Launcher3

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  final int uniChar = event.getUnicodeChar();
  final boolean handled = super.onKeyDown(keyCode, event);
  final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
  if (!handled && acceptFilter() && isKeyNotWhitespace) {
    boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
        keyCode, event);
    if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
      // something usable has been typed - start a search
      // the typed text will be retrieved and cleared by
      // showSearchDialog()
      // If there are multiple keystrokes before the search dialog takes focus,
      // onSearchRequested() will be called for every keystroke,
      // but it is idempotent, so it's fine.
      return onSearchRequested();
    }
  }
  // Eat the long press event so the keyboard doesn't come up.
  if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
    return true;
  }
  return handled;
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  final int uniChar = event.getUnicodeChar();
  final boolean handled = super.onKeyDown(keyCode, event);
  final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
  if (!handled && acceptFilter() && isKeyNotWhitespace) {
    boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
        keyCode, event);
    if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
      // something usable has been typed - start a search
      // the typed text will be retrieved and cleared by
      // showSearchDialog()
      // If there are multiple keystrokes before the search dialog takes focus,
      // onSearchRequested() will be called for every keystroke,
      // but it is idempotent, so it's fine.
      return onSearchRequested();
    }
  }
  // Eat the long press event so the keyboard doesn't come up.
  if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
    return true;
  }
  return handled;
}

代码示例来源:origin: enricocid/LaunchEnr

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  final int uniChar = event.getUnicodeChar();
  final boolean handled = super.onKeyDown(keyCode, event);
  final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
  if (!handled && acceptFilter() && isKeyNotWhitespace) {
    boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
        keyCode, event);
    if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
      // something usable has been typed - start a search
      // the typed text will be retrieved and cleared by
      // showSearchDialog()
      // If there are multiple keystrokes before the search dialog takes focus,
      // onSearchRequested() will be called for every keystroke,
      // but it is idempotent, so it's fine.
      return onSearchRequested();
    }
  }
  // Eat the long press event so the keyboard doesn't come up.
  if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
    return true;
  }
  return handled;
}

相关文章