Java Code Examples for android.view.KeyEvent#KEYCODE_POWER

The following examples show how to use android.view.KeyEvent#KEYCODE_POWER . 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: ContentViewCore.java    From 365browser with Apache License 2.0 7 votes vote down vote up
/**
 * Check whether a key should be propagated to the embedder or not.
 * We need to send almost every key to Blink. 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*.
 */
private static boolean shouldPropagateKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    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 false;
    }
    return true;
}
 
Example 2
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 3
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 4
Source File: BtnScreenOff.java    From XposedNavigationBar with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void showPowerMenu(Context context) {
    Instrumentation mInst = new Instrumentation();
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_POWER);
    mInst.sendKeySync(keyEvent);
}
 
Example 5
Source File: KeyBlockService.java    From KeyBlocker with GNU General Public License v3.0 4 votes vote down vote up
@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;
    }
}
 
Example 6
Source File: VolumeAccessibilityService.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean onKeyEvent(KeyEvent event) {
    if (null == event) return true; // WTF??

    // Make sure we're not in the middle of a phone call.
    if (null != mVolumePanel && mVolumePanel.getCallState() != TelephonyManager.CALL_STATE_IDLE)
        return super.onKeyEvent(event);

    final int flags = event.getFlags();
    final int code = event.getKeyCode();
    final boolean system = ((flags & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM);

    // Specifically avoid software keys or "fake" hardware buttons.
    if (((flags & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) ||
        ((flags & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY)) {
        return super.onKeyEvent(event);
    } else {
        // Specifically avoid handling certain keys. We never want to interfere
        // with them or harm performance in any way.
        switch (code) {
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_HOME:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_POWER:
            case KeyEvent.KEYCODE_SEARCH:
                return super.onKeyEvent(event);
        }
    }

    if (!system) return super.onKeyEvent(event);

    LOGI(TAG, "--onKeyEvent(code=" + event.getKeyCode() + ", action=" + event.getAction() +
            ", topPackage=" + mCurrentActivityPackage + ", disabledButtons=" + disabledButtons + ')');

    // Check if we're supposed to disable Noyze for a Blacklisted app.
    if (blacklist.contains(mCurrentActivityPackage)) {
        if (null != mVolumePanel) mVolumePanel.setEnabled(false);
        return super.onKeyEvent(event);
    } else {
        // NOTE: we need a "safe" way to enable the volume panel that
        // takes into consideration its previous state.
        if (null != mVolumePanel) mVolumePanel.enable();
    }

    // If we're told to disable one or more of the volume buttons, do so (returning true consumes the event).
    if (disabledButtons == code) return true;
    // NOTE: KeyEvent#KEYCODE_VOLUME_DOWN + KeyEvent#KEYCODE_VOLUME_UP == KeyEvent_KEYCODE_U
    final int upAndDown = (KeyEvent.KEYCODE_VOLUME_DOWN + KeyEvent.KEYCODE_VOLUME_UP); // 49
    final int upSquared = KeyEvent.KEYCODE_VOLUME_UP * KeyEvent.KEYCODE_VOLUME_UP; // 576
    if (disabledButtons == upAndDown && Utils.isVolumeKeyCode(upAndDown - code)) return true;
    if (disabledButtons == upSquared && mVolumePanel != null && mVolumePanel.isLocked()) return true;
    if (disabledButtons == upSquared && KEYGUARD.equals(mCurrentActivityPackage)) return true;

    // Check if the volume panel has been disabled, or shouldn't handle this event (e.g. "safe volume").
    if (null != mVolumePanel && mVolumePanel.isEnabled()) {
        if (Utils.isVolumeKeyCode(code)) {
            Message.obtain(mHandler, MESSAGE_KEY_EVENT, event).sendToTarget(); // Run asynchronously
            return true;
        }
    }

	return super.onKeyEvent(event);
}
 
Example 7
Source File: VolumeAccessibilityService.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean onKeyEvent(KeyEvent event) {
    if (null == event) return true; // WTF??

    // Make sure we're not in the middle of a phone call.
    if (null != mVolumePanel && mVolumePanel.getCallState() != TelephonyManager.CALL_STATE_IDLE)
        return super.onKeyEvent(event);

    final int flags = event.getFlags();
    final int code = event.getKeyCode();
    final boolean system = ((flags & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM);

    // Specifically avoid software keys or "fake" hardware buttons.
    if (((flags & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) ||
        ((flags & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY)) {
        return super.onKeyEvent(event);
    } else {
        // Specifically avoid handling certain keys. We never want to interfere
        // with them or harm performance in any way.
        switch (code) {
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_HOME:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_POWER:
            case KeyEvent.KEYCODE_SEARCH:
                return super.onKeyEvent(event);
        }
    }

    if (!system) return super.onKeyEvent(event);

    LOGI(TAG, "--onKeyEvent(code=" + event.getKeyCode() + ", action=" + event.getAction() +
            ", topPackage=" + mCurrentActivityPackage + ", disabledButtons=" + disabledButtons + ')');

    // Check if we're supposed to disable Noyze for a Blacklisted app.
    if (blacklist.contains(mCurrentActivityPackage)) {
        if (null != mVolumePanel) mVolumePanel.setEnabled(false);
        return super.onKeyEvent(event);
    } else {
        // NOTE: we need a "safe" way to enable the volume panel that
        // takes into consideration its previous state.
        if (null != mVolumePanel) mVolumePanel.enable();
    }

    // If we're told to disable one or more of the volume buttons, do so (returning true consumes the event).
    if (disabledButtons == code) return true;
    // NOTE: KeyEvent#KEYCODE_VOLUME_DOWN + KeyEvent#KEYCODE_VOLUME_UP == KeyEvent_KEYCODE_U
    final int upAndDown = (KeyEvent.KEYCODE_VOLUME_DOWN + KeyEvent.KEYCODE_VOLUME_UP); // 49
    final int upSquared = KeyEvent.KEYCODE_VOLUME_UP * KeyEvent.KEYCODE_VOLUME_UP; // 576
    if (disabledButtons == upAndDown && Utils.isVolumeKeyCode(upAndDown - code)) return true;
    if (disabledButtons == upSquared && mVolumePanel != null && mVolumePanel.isLocked()) return true;
    if (disabledButtons == upSquared && KEYGUARD.equals(mCurrentActivityPackage)) return true;

    // Check if the volume panel has been disabled, or shouldn't handle this event (e.g. "safe volume").
    if (null != mVolumePanel && mVolumePanel.isEnabled()) {
        if (Utils.isVolumeKeyCode(code)) {
            Message.obtain(mHandler, MESSAGE_KEY_EVENT, event).sendToTarget(); // Run asynchronously
            return true;
        }
    }

	return super.onKeyEvent(event);
}