Example usage for android.view KeyEvent KEYCODE_POWER

List of usage examples for android.view KeyEvent KEYCODE_POWER

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_POWER.

Prototype

int KEYCODE_POWER

To view the source code for android.view KeyEvent KEYCODE_POWER.

Click Source Link

Document

Key code constant: Power key.

Usage

From source file:Main.java

public static String getKeyNameByCode(int code) {
    switch (code) {
    case KeyEvent.KEYCODE_0:
        return "<0>";
    case KeyEvent.KEYCODE_1:
        return "<1>";
    case KeyEvent.KEYCODE_2:
        return "<2>";
    case KeyEvent.KEYCODE_3:
        return "<3>";
    case KeyEvent.KEYCODE_4:
        return "<4>";
    case KeyEvent.KEYCODE_5:
        return "<5>";
    case KeyEvent.KEYCODE_6:
        return "<6>";
    case KeyEvent.KEYCODE_7:
        return "<7>";
    case KeyEvent.KEYCODE_8:
        return "<8>";
    case KeyEvent.KEYCODE_9:
        return "<9>";
    case KeyEvent.KEYCODE_A:
        return "<A>";
    case KeyEvent.KEYCODE_B:
        return "<B>";
    case KeyEvent.KEYCODE_C:
        return "<C>";
    case KeyEvent.KEYCODE_D:
        return "<D>";
    case KeyEvent.KEYCODE_E:
        return "<E>";
    case KeyEvent.KEYCODE_F:
        return "<F>";
    case KeyEvent.KEYCODE_G:
        return "<G>";
    case KeyEvent.KEYCODE_H:
        return "<H>";
    case KeyEvent.KEYCODE_I:
        return "<I>";
    case KeyEvent.KEYCODE_J:
        return "<J>";
    case KeyEvent.KEYCODE_K:
        return "<K>";
    case KeyEvent.KEYCODE_L:
        return "<L>";
    case KeyEvent.KEYCODE_M:
        return "<M>";
    case KeyEvent.KEYCODE_N:
        return "<N>";
    case KeyEvent.KEYCODE_O:
        return "<O>";
    case KeyEvent.KEYCODE_P:
        return "<P>";
    case KeyEvent.KEYCODE_Q:
        return "<Q>";
    case KeyEvent.KEYCODE_R:
        return "<R>";
    case KeyEvent.KEYCODE_S:
        return "<S>";
    case KeyEvent.KEYCODE_T:
        return "<T>";
    case KeyEvent.KEYCODE_U:
        return "<U>";
    case KeyEvent.KEYCODE_V:
        return "<V>";
    case KeyEvent.KEYCODE_W:
        return "<W>";
    case KeyEvent.KEYCODE_X:
        return "<X>";
    case KeyEvent.KEYCODE_Y:
        return "<Y>";
    case KeyEvent.KEYCODE_Z:
        return "<Z>";
    case KeyEvent.KEYCODE_APOSTROPHE:
        return "<'>";
    case KeyEvent.KEYCODE_AT:
        return "<@>";
    case KeyEvent.KEYCODE_BACK:
        return "<Back>";
    case KeyEvent.KEYCODE_BACKSLASH:
        return "<\\>";
    case KeyEvent.KEYCODE_CALL:
        return "<Call>";
    case KeyEvent.KEYCODE_CAMERA:
        return "<Camera>";
    case KeyEvent.KEYCODE_CLEAR:
        return "<Clear>";
    case KeyEvent.KEYCODE_COMMA:
        return "<,>";
    case KeyEvent.KEYCODE_DEL:
        return "<Del>";
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "<PadCenter>";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "<PadDown>";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "<PadLeft>";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "<PadRight>";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "<PadUp>";
    case KeyEvent.KEYCODE_ENDCALL:
        return "<EndCall>";
    case KeyEvent.KEYCODE_ENTER:
        return "<Enter>";
    case KeyEvent.KEYCODE_ENVELOPE:
        return "<Envelope>";
    case KeyEvent.KEYCODE_EQUALS:
        return "<=>";
    case KeyEvent.KEYCODE_EXPLORER:
        return "<Explorer>";
    case KeyEvent.KEYCODE_FOCUS:
        return "<??? 0>";
    case KeyEvent.KEYCODE_GRAVE:
        return "<??? 1>";
    case KeyEvent.KEYCODE_HEADSETHOOK:
        return "<??? 2>";
    case KeyEvent.KEYCODE_HOME:
        return "<Home>";
    case KeyEvent.KEYCODE_LEFT_BRACKET:
        return "<(>";
    case KeyEvent.KEYCODE_MENU:
        return "<Menu>";
    case KeyEvent.KEYCODE_MINUS:
        return "<->";
    case KeyEvent.KEYCODE_NOTIFICATION:
        return "<??? 3>";
    case KeyEvent.KEYCODE_NUM:
        return "<Num>";
    case KeyEvent.KEYCODE_PERIOD:
        return "<??? 4>";
    case KeyEvent.KEYCODE_PLUS:
        return "<+>";
    case KeyEvent.KEYCODE_POUND:
        return "<??? 5>";
    case KeyEvent.KEYCODE_POWER:
        return "<Power>";
    case KeyEvent.KEYCODE_RIGHT_BRACKET:
        return "<)>";
    case KeyEvent.KEYCODE_SEMICOLON:
        return "<;>";
    case KeyEvent.KEYCODE_SLASH:
        return "</>";
    case KeyEvent.KEYCODE_SOFT_LEFT:
        return "<??? 6>";
    case KeyEvent.KEYCODE_SOFT_RIGHT:
        return "<??? 7>";
    case KeyEvent.KEYCODE_SPACE:
        return "<Space>";
    case KeyEvent.KEYCODE_STAR:
        return "<*>";
    case KeyEvent.KEYCODE_SYM:
        return "<Sym>";
    case KeyEvent.KEYCODE_TAB:
        return "<Tab>";
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        return "<VolumeDown>";
    case KeyEvent.KEYCODE_VOLUME_UP:
        return "<VolumeUp>";
    case KeyEvent.KEYCODE_UNKNOWN:
    default:/*from w  w  w.  j a  va  2 s.  com*/
        return "<Unknown>";
    }
}

From source file:freed.cam.ActivityFreeDcamMain.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (activityIsResumed) {
        Log.d(TAG, "KeyCode Pressed:" + keyCode);
        int appSettingsKeyShutter = 0;

        if (getAppSettings().getApiString(AppSettingsManager.SETTING_EXTERNALSHUTTER).equals(StringUtils.VoLP))
            appSettingsKeyShutter = KeyEvent.KEYCODE_VOLUME_UP;
        else if (getAppSettings().getApiString(AppSettingsManager.SETTING_EXTERNALSHUTTER)
                .equals(StringUtils.VoLM))
            appSettingsKeyShutter = KeyEvent.KEYCODE_VOLUME_DOWN;
        else if (getAppSettings().getApiString(AppSettingsManager.SETTING_EXTERNALSHUTTER)
                .equals(StringUtils.Hook)
                || getAppSettings().getApiString(AppSettingsManager.SETTING_EXTERNALSHUTTER).equals(""))
            appSettingsKeyShutter = KeyEvent.KEYCODE_HEADSETHOOK;

        if (keyCode == KeyEvent.KEYCODE_3D_MODE || keyCode == KeyEvent.KEYCODE_POWER
                || keyCode == appSettingsKeyShutter || keyCode == KeyEvent.KEYCODE_UNKNOWN
                || keyCode == KeyEvent.KEYCODE_CAMERA) {
            cameraFragment.GetModuleHandler().DoWork();
            return true;
        }/*from ww w. j  a  v a  2s. c  om*/
        if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
            closeActivity();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.easyaccess.phonedialer.CallingScreen.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // long press of power button will end the call
    if (KeyEvent.KEYCODE_POWER == event.getKeyCode()) {
        TelephonyManager telephony = (TelephonyManager) getApplicationContext()
                .getSystemService(Context.TELEPHONY_SERVICE);
        try {/*from w w w  .  ja  v  a  2s  .co m*/
            Class<?> c = Class.forName(telephony.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            ITelephony telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService.endCall();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        // do nothing
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.stasbar.knowyourself.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LOGGER.v("dispatchKeyEvent: %s", keyEvent);

    switch (keyEvent.getKeyCode()) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_POWER:
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_HEADSETHOOK:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) {
            switch (mVolumeBehavior) {
            case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE:
                snooze();//  w  ww . ja  v a2 s  .com
                break;
            case SettingsActivity.VOLUME_BEHAVIOR_DISMISS:
                dismiss();
                break;
            default:
                break;
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(keyEvent);
    }
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent keyEvent) {
    // Do this in dispatch to intercept a few of the system keys.
    LogUtils.v(LOGTAG, "dispatchKeyEvent: %s", keyEvent);

    switch (keyEvent.getKeyCode()) {
    // Volume keys and camera keys dismiss the alarm.
    case KeyEvent.KEYCODE_POWER:
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
    case KeyEvent.KEYCODE_CAMERA:
    case KeyEvent.KEYCODE_FOCUS:
        if (!mAlarmHandled && keyEvent.getAction() == KeyEvent.ACTION_UP) {
            switch (mVolumeBehavior) {
            case SettingsActivity.VOLUME_BEHAVIOR_SNOOZE:
                snooze();/*w  w  w  .  j a  v  a  2  s .c o m*/
                break;
            case SettingsActivity.VOLUME_BEHAVIOR_DISMISS:
                dismiss();
                break;
            default:
                break;
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(keyEvent);
    }
}

From source file:com.android.settings.accessibility.AccessibilitySettings.java

private void initializeAllPreferences() {
    for (int i = 0; i < CATEGORIES.length; i++) {
        PreferenceCategory prefCategory = (PreferenceCategory) findPreference(CATEGORIES[i]);
        mCategoryToPrefCategoryMap.put(CATEGORIES[i], prefCategory);
    }/*  w w  w.  j a  va2 s .c  om*/

    // Text contrast.
    mToggleHighTextContrastPreference = (SwitchPreference) findPreference(TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE);

    // Display inversion.
    mToggleInversionPreference = (SwitchPreference) findPreference(TOGGLE_INVERSION_PREFERENCE);
    mToggleInversionPreference.setOnPreferenceChangeListener(this);

    // Power button ends calls.
    mTogglePowerButtonEndsCallPreference = (SwitchPreference) findPreference(
            TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE);
    if (!KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) || !Utils.isVoiceCapable(getActivity())) {
        mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL)
                .removePreference(mTogglePowerButtonEndsCallPreference);
    }

    // Lock screen rotation.
    mToggleLockScreenRotationPreference = (SwitchPreference) findPreference(
            TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE);
    if (!RotationPolicy.isRotationSupported(getActivity())) {
        mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL)
                .removePreference(mToggleLockScreenRotationPreference);
    }

    // Large pointer icon.
    mToggleLargePointerIconPreference = (SwitchPreference) findPreference(TOGGLE_LARGE_POINTER_ICON);

    // Master Mono
    mToggleMasterMonoPreference = (SwitchPreference) findPreference(TOGGLE_MASTER_MONO);

    // Long press timeout.
    mSelectLongPressTimeoutPreference = (ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
    mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
    if (mLongPressTimeoutValueToTitleMap.size() == 0) {
        String[] timeoutValues = getResources().getStringArray(R.array.long_press_timeout_selector_values);
        mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
        String[] timeoutTitles = getResources().getStringArray(R.array.long_press_timeout_selector_titles);
        final int timeoutValueCount = timeoutValues.length;
        for (int i = 0; i < timeoutValueCount; i++) {
            mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
        }
    }

    // Captioning.
    mCaptioningPreferenceScreen = findPreference(CAPTIONING_PREFERENCE_SCREEN);

    // Display magnification.
    mDisplayMagnificationPreferenceScreen = findPreference(DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
    configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreferenceScreen);

    // Font size.
    mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);

    // Autoclick after pointer stops.
    mAutoclickPreferenceScreen = findPreference(AUTOCLICK_PREFERENCE_SCREEN);

    // Display color adjustments.
    mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);

    // Accessibility shortcut
    mAccessibilityShortcutPreferenceScreen = findPreference(ACCESSIBILITY_SHORTCUT_PREFERENCE);
}

From source file:com.android.settings.accessibility.AccessibilitySettings.java

private void updateSystemPreferences() {
    // Move color inversion and color correction preferences to Display category if device
    // supports HWC hardware-accelerated color transform.
    if (isColorTransformAccelerated(getContext())) {
        PreferenceCategory experimentalCategory = mCategoryToPrefCategoryMap.get(CATEGORY_EXPERIMENTAL);
        PreferenceCategory displayCategory = mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY);
        experimentalCategory.removePreference(mToggleInversionPreference);
        experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen);
        mToggleInversionPreference.setOrder(mToggleLargePointerIconPreference.getOrder());
        mDisplayDaltonizerPreferenceScreen.setOrder(mToggleInversionPreference.getOrder());
        mToggleInversionPreference.setSummary(R.string.summary_empty);
        displayCategory.addPreference(mToggleInversionPreference);
        displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
    }/*from   w  w  w.ja  v a  2  s . c o  m*/

    // Text contrast.
    mToggleHighTextContrastPreference.setChecked(Settings.Secure.getInt(getContentResolver(),
            Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, 0) == 1);

    // If the quick setting is enabled, the preference MUST be enabled.
    mToggleInversionPreference.setChecked(Settings.Secure.getInt(getContentResolver(),
            Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0) == 1);

    // Power button ends calls.
    if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) && Utils.isVoiceCapable(getActivity())) {
        final int incallPowerBehavior = Settings.Secure.getInt(getContentResolver(),
                Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
        final boolean powerButtonEndsCall = (incallPowerBehavior == Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP);
        mTogglePowerButtonEndsCallPreference.setChecked(powerButtonEndsCall);
    }

    // Auto-rotate screen
    updateLockScreenRotationCheckbox();

    // Large pointer icon.
    mToggleLargePointerIconPreference.setChecked(Settings.Secure.getInt(getContentResolver(),
            Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, 0) != 0);

    // Master mono
    updateMasterMono();

    // Long press timeout.
    final int longPressTimeout = Settings.Secure.getInt(getContentResolver(),
            Settings.Secure.LONG_PRESS_TIMEOUT, mLongPressTimeoutDefault);
    String value = String.valueOf(longPressTimeout);
    mSelectLongPressTimeoutPreference.setValue(value);
    mSelectLongPressTimeoutPreference.setSummary(mLongPressTimeoutValueToTitleMap.get(value));

    updateFeatureSummary(Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, mCaptioningPreferenceScreen);
    updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
            mDisplayDaltonizerPreferenceScreen);

    updateMagnificationSummary(mDisplayMagnificationPreferenceScreen);

    updateFontSizeSummary(mFontSizePreferenceScreen);

    updateAutoclickSummary(mAutoclickPreferenceScreen);

    updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen);
}

From source file:com.example.innf.newchangtu.Map.view.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    sendSMSTime = System.currentTimeMillis();/*?*/
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
            drawerLayout.closeDrawer(GravityCompat.START);
        } else {/* ww  w .j  a  v a  2  s .  c o  m*/
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            AlertDialog dialog = builder.setTitle(R.string.app_name).setIcon(R.mipmap.ic_launcher)
                    .setMessage("?")
                    .setPositiveButton("", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            finish();
                            System.exit(0);
                        }
                    }).setNegativeButton("?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    }).show();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_POWER && event.getAction() == KeyEvent.ACTION_DOWN) {
        if ((System.currentTimeMillis() - sendSMSTime) < 2000) {
            powerButtonClickTimes++;
            if (powerButtonClickTimes == 4) {
                Log.d(TAG, powerButtonClickTimes + "");
                showToast("???");
            }
        } else {
            powerButtonClickTimes = 0;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.plusot.senselib.SenseMain.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int action = event.getAction();
    final int keyCode = event.getKeyCode();
    boolean result = false;

    if ((lastAction == action && lastKeyCode == keyCode)) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_CAMERA:
            newInterval();/*  w  w  w.  j a v a 2 s  . c  om*/
            break;
        case KeyEvent.KEYCODE_POWER:
            //if (action == KeyEvent.)
            LLog.d(Globals.TAG, CLASSTAG + " Power button pressed");
            break;
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                dimScreen(true);
            }
            result = true;
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                dimScreen(false);
            }
            result = true;
            break;
        }
    } else {
        AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        switch (keyCode) {
        case KeyEvent.KEYCODE_CAMERA:
            newInterval();
            break;
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (sameActionKeyCode < 2 && lastAction == KeyEvent.ACTION_DOWN && action == KeyEvent.ACTION_UP
                    && lastKeyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                        AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
            }
            result = true;
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (sameActionKeyCode < 2 && lastAction == KeyEvent.ACTION_DOWN && action == KeyEvent.ACTION_UP
                    && lastKeyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                mgr.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                        AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
            }
            result = true;
            break;
        }
    }
    if (!result) {
        // LLog.d(Globals.TAG, CLASSTAG +
        // ".distpatchKeyEvent: Calling super with " + delta);
        result = super.dispatchKeyEvent(event);
    }
    if (lastAction == action && lastKeyCode == keyCode) {
        sameActionKeyCode++;
    } else
        sameActionKeyCode = 0;

    lastKeyCode = keyCode;
    lastAction = action;
    return result;

}