当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent类代码示例

本文整理汇总了Java中android.view.KeyEvent的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent类的具体用法?Java KeyEvent怎么用?Java KeyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeyEvent类属于android.view包,在下文中一共展示了KeyEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onKeyDown

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      // Don't allow this value to go to 0. It shuts the screen off.
      if (minBrightness > 1) {
        minBrightness -= 1;
        updateDisplay();
        Util.setActivityBrightness(getWindow(), minBrightness);
      }
      return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
      if (minBrightness < 255) {
        minBrightness += 1;
        updateDisplay();
        Util.setActivityBrightness(getWindow(), minBrightness);
      }
      return true;
    default:
      return super.onKeyDown(keyCode, event);
  }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:23,代码来源:CalibrateActivity.java

示例2: onKeyDown

import android.view.KeyEvent; //导入依赖的package包/类
/**
 * 顶部焦点获取
 *
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean focusFlag = false;
    for (View v : mViews) {
        if (v.isFocused()) {
            focusFlag = true;
        }
    }
    Log.d(TAG, "code:" + keyCode + " flag:" + focusFlag);
    if (focusFlag) {
        if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) {
            if (mCurrentIndex > 0) {
                mViews[--mCurrentIndex].requestFocus();
            }
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_RIGHT == keyCode) {
            if (mCurrentIndex < 2) {
                mViews[++mCurrentIndex].requestFocus();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:32,代码来源:MainActivity.java

示例3: onKey

import android.view.KeyEvent; //导入依赖的package包/类
@Override
  public void onKey(int primaryCode, int[] keyCodes) {
      InputConnection ic = getCurrentInputConnection() ;
      playclick(primaryCode);
      switch (primaryCode) {
          case Keyboard.KEYCODE_DELETE:
              ic.deleteSurroundingText(1, 0);
              break;
          case Keyboard.KEYCODE_SHIFT:
              caps = !caps;
              keyboard.setShifted(caps);
              kv.invalidateAllKeys();
              break;
          case Keyboard.KEYCODE_DONE:
              ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
              break;
          default:
              char code = (char) primaryCode;
              if(Character.isLetter(code) && caps) {
                  code = Character.toUpperCase(code);
              }

              ic.commitText(String.valueOf(code), 1);
break;
      }
  }
 
开发者ID:zhaofengli,项目名称:airboard,代码行数:27,代码来源:AirBoard.java

示例4: onReceive

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
        String reason = intent.getStringExtra(SYSTEM_REASON);
        if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {
            //表示按了home键,程序到了后台
            if (currentKeyCode==KeyEvent.KEYCODE_HOME && isLongPressedHome){
                isLongPressedHome=false;
                return;
            }
        }else if(TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)){
            //表示长按home键,显示最近使用的程序列表
            if (currentKeyCode==KeyEvent.KEYCODE_APP_SWITCH && isLongPressedRecent){
                isLongPressedRecent=false;
                return;
            }
        }else {
            return;
        }
        refreshViewState(false);
    }
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:24,代码来源:KeyPressedTipViewController.java

示例5: setButtonPlumbedToJs

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void setButtonPlumbedToJs(int keyCode, boolean override) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_MENU:
            // TODO: Why are search and menu buttons handled separately?
            if (override) {
                boundKeyCodes.add(keyCode);
            } else {
                boundKeyCodes.remove(keyCode);
            }
            return;
        default:
            throw new IllegalArgumentException("Unsupported keycode: " + keyCode);
    }
}
 
开发者ID:alex-shpak,项目名称:keemob,代码行数:19,代码来源:CordovaWebViewImpl.java

示例6: run

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void run() {
    try {
        int data = peripheralDevice.getTouched();

        for (int i = 0; i < Mpr121.NB_ELECTRODES; i++) {
            if ((data & (1 << i)) != 0) {
                if (!inputStatus[i]) {
                    Log.d(TAG, "#" + i + " touched");
                    inputStatus[i] = true;
                    emitInputEvents(keycodes[i], KeyEvent.ACTION_DOWN);
                }
            } else {
                if (inputStatus[i]) {
                    Log.d(TAG, "#" + i + " released");
                    inputStatus[i] = false;
                    emitInputEvents(keycodes[i], KeyEvent.ACTION_UP);
                }
            }
        }
    } catch (IOException e) {
        Log.e(TAG, "Error getting data from peripheral device", e);
    } finally {
        inputHandler.postDelayed(this, SOFTWAREPOLL_DELAY_MS);
    }
}
 
开发者ID:Nilhcem,项目名称:mpr121-androidthings,代码行数:27,代码来源:Mpr121InputDriver.java

示例7: challengePressBackAndQuit

import android.view.KeyEvent; //导入依赖的package包/类
@Test
public void challengePressBackAndQuit() {
    onView(withId(R.id.search)).perform(click());
    onView(isRoot()).perform(waitForMatch(withId(R.id.empty_layout), UI_TEST_TIMEOUT));
    onView(isAssignableFrom(EditText.class)).perform(typeText("R"), pressKey(KeyEvent.KEYCODE_ENTER));

    tryIsDisplayed(withText("Runnest IHL"), UI_TEST_TIMEOUT);
    onView(withText("Runnest IHL")).perform(click());

    //Create challenge
    onView(isRoot()).perform(waitForMatch(withId(R.id.main_layout), UI_TEST_TIMEOUT));
    onView(withText(R.string.challenge)).perform(click());
    tryIsDisplayed(withId(R.id.define_challenge), UI_TEST_TIMEOUT);
    onView(withId(R.id.customize_positive_btn)).perform(click());

    //Wait
    Espresso.pressBack();
    tryIsDisplayed(withId(android.R.id.button1), UI_TEST_TIMEOUT);
    onView(withText(R.string.quit)).perform(click());
}
 
开发者ID:IrrilevantHappyLlamas,项目名称:Runnest,代码行数:21,代码来源:ChallengeTest.java

示例8: onKeyUp

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    PlaybackOverlayFragment playbackOverlayFragment = (PlaybackOverlayFragment) getFragmentManager().findFragmentById(R.id.playback_controls_fragment);
    switch (keyCode) {
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            playbackOverlayFragment.togglePlayback(false);
            return true;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            playbackOverlayFragment.togglePlayback(false);
            return true;
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            if (mPlaybackState == LeanbackPlaybackState.PLAYING) {
                playbackOverlayFragment.togglePlayback(false);
            } else {
                playbackOverlayFragment.togglePlayback(true);
            }
            return true;
        default:
            return super.onKeyUp(keyCode, event);
    }
}
 
开发者ID:cleaninsights,项目名称:cleaninsights-android-sdk,代码行数:22,代码来源:PlaybackOverlayActivity.java

示例9: executeKeyEvent

import android.view.KeyEvent; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:34,代码来源:ViewPagerEx.java

示例10: dispatchKeyEventInFullScreen

import android.view.KeyEvent; //导入依赖的package包/类
public boolean dispatchKeyEventInFullScreen(KeyEvent event) {

        if (event == null) return false;
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                if (EmoticonsKeyboardUtils.isFullScreen((Activity) getContext()) && mLayoutKVML.isShown()) {
                    reset();
                    return true;
                }
            default:
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    boolean isFocused;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        isFocused = mIMLayout.getETChat().getShowSoftInputOnFocus();
                    } else {
                        isFocused = mIMLayout.getETChat().isFocused();
                    }
                    if (isFocused)
                        mIMLayout.getETChat().onKeyDown(event.getKeyCode(), event);
                }
        }
        return false;
    }
 
开发者ID:Zyj163,项目名称:yyox,代码行数:24,代码来源:EmoticonsKeyBoard.java

示例11: onKeyDown

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
        if (mWebView.getUrl().equals(INDEXURL)) {
            if (System.currentTimeMillis() - exitTime > 2000) {
                CommonUtils.showToast(this, getString(R.string.w_exit_app));
                exitTime = System.currentTimeMillis();
            } else {
                for (int i = 0; i < MyApplication.list.size(); i++) {
                    MyApplication.list.get(i).finish();
                }
            }
        } else {
            mWebView.goBack();
        }
    }
    return true;
}
 
开发者ID:JunGeges,项目名称:AliZhiBoHao,代码行数:19,代码来源:WebActivity.java

示例12: onKeyUp

import android.view.KeyEvent; //导入依赖的package包/类
public boolean onKeyUp(int keyCode, KeyEvent event) {
    boolean ret = false;
    switch (keyCode) {
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            // if (isChild() == true) {
            // final VideoBrowserActivity parent = (VideoBrowserActivity)
            // getParent();
            // parent.launchGlobalResume();
            // }
            ret = true;
    }

    // if (!ret)
    // ret = super.onKeyUp(keyCode, event);

    return ret;
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:20,代码来源:Browser.java

示例13: onKeyDown

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //TODO: Should we reverse the keys for RTL? The framework's SeekBar does NOT....
    boolean handled = false;
    if (isEnabled()) {
        int progress = getAnimatedProgress();
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = true;
                if (progress <= mMin) break;
                animateSetProgress(progress - mKeyProgressIncrement);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = true;
                if (progress >= mMax) break;
                animateSetProgress(progress + mKeyProgressIncrement);
                break;
        }
    }

    return handled || super.onKeyDown(keyCode, event);
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:23,代码来源:DiscreteSeekBar.java

示例14: onKey

import android.view.KeyEvent; //导入依赖的package包/类
@Override
public final boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        return onKeyDown(keyCode, event);
    }
    return false;
}
 
开发者ID:shenhuanet,项目名称:AndroidOpen,代码行数:8,代码来源:BottomPopup.java

示例15: onKeyDown

import android.view.KeyEvent; //导入依赖的package包/类
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
//                if (!mDelegation.onTurnBack()) return true;
                break;
        }
        return super.onKeyDown(keyCode, event);
    }
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:10,代码来源:TopicTweetActivity.java


注:本文中的android.view.KeyEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。