本文整理汇总了Java中android.view.KeyEvent.KEYCODE_POWER属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.KEYCODE_POWER属性的具体用法?Java KeyEvent.KEYCODE_POWER怎么用?Java KeyEvent.KEYCODE_POWER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.KEYCODE_POWER属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchKeyEvent
/**
* 屏蔽按键 然而并没什么用。。。
* @param keyEvent 按键事件
* @return 是否已经处理过按键
*/
@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
switch (keyEvent.getKeyCode()) {
case KeyEvent.KEYCODE_POWER:
case KeyEvent.KEYCODE_HOME:
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_CALL:
case KeyEvent.KEYCODE_SYM:
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_STAR:
return true;
}
return super.dispatchKeyEvent(keyEvent);
}
示例2: onKeyEvent
@Override
protected boolean onKeyEvent(KeyEvent event) {
int keycode = event.getKeyCode();
if (keycode == KeyEvent.KEYCODE_POWER) {
return false;
}
boolean enable_keyblock = mSp.getBoolean(Config.ENABLED_KEYBLOCK, false);
if (closeAdvancedFunction) {
return enable_keyblock;
}
if (event.getAction() == ACTION_DOWN) {
if (keycode == KeyEvent.KEYCODE_BACK) {
if (mSp.getBoolean(Config.DOUBLE_CLICK_EXIT, false) && enable_keyblock) {
long nowTime = System.currentTimeMillis();
if (nowTime - backClickTime <= 700) {
CloseBlock();
backClickTime = 0;
return true;
} else {
backClickTime = nowTime;
}
}
}
if (mSp.getBoolean(Config.DISPLAY_KEYCODE, false)) {
Toast.makeText(this, "Keycode: " + keycode, Toast.LENGTH_SHORT).show();
}
}
if (enable_keyblock) {
if (mSp.getBoolean(Config.ENABLED_VOLUME_KEY, false) && (keycode == KeyEvent.KEYCODE_VOLUME_UP || keycode == KeyEvent.KEYCODE_VOLUME_MUTE || keycode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
return false;
}
if (mSp.getBoolean(Config.ENABLED_CUSTOM_KEYCODE, false)) {
String[] sourceStrArray = mSp.getString(Config.CUSTOM_KEYCODE, "").split(" ");
Arrays.sort(sourceStrArray);
int index = Arrays.binarySearch(sourceStrArray, String.valueOf(keycode));
boolean isDisabled = index >= 0;
if (event.getAction() == ACTION_UP && mSp.getBoolean(Config.DISPLAY_KEYCODE, false)) {
if (isDisabled) {
Toast.makeText(this, "KeyCode: " + keycode + " " + getString(R.string.has_disabled), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "KeyCode: " + keycode, Toast.LENGTH_SHORT).show();
}
}
return isDisabled;
}
return true;
} else {
return false;
}
}
示例3: showPowerMenu
@Override
protected void showPowerMenu(Context context) {
Instrumentation mInst = new Instrumentation();
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POWER);
mInst.sendKeySync(keyEvent);
}