Example usage for android.view KeyCharacterMap deviceHasKey

List of usage examples for android.view KeyCharacterMap deviceHasKey

Introduction

In this page you can find the example usage for android.view KeyCharacterMap deviceHasKey.

Prototype

public static boolean deviceHasKey(int keyCode) 

Source Link

Document

Queries the framework about whether any physical keys exist on the any keyboard attached to the device that are capable of producing the given key code.

Usage

From source file:com.rockerhieu.emojicon.EmojiconsPopup.java

/**
 * Call this function to resize the emoji popup according to your soft keyboard size
 *///from   ww w  .  ja  va 2 s  . c o  m
public void setSizeForSoftKeyboard() {
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (isOpened) {
                return;
            }
            Rect r = new Rect();
            rootView.getWindowVisibleDisplayFrame(r);

            int screenHeight = getUsableScreenHeight();
            int heightDifference = screenHeight - (r.bottom - r.top);

            Resources resources = mContext.getResources();
            int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android");

            //add support translucent status bar ???
            //            if (!((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP))) {
            //               if (statusBarId > 0) {
            //                  heightDifference -= mContext.getResources()
            //                        .getDimensionPixelSize(statusBarId);
            //                  //                        Log.e("keyboard height", "resourceId > 0" + heightDifference);
            //               }
            //            }

            if (statusBarId > 0) {
                heightDifference -= resources.getDimensionPixelSize(statusBarId);
            }
            //Resolved using http://stackoverflow.com/a/16608481/2853322
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                int navBarId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
                boolean hasMenuKey;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    hasMenuKey = ViewConfiguration.get(mContext).hasPermanentMenuKey();
                } else
                    hasMenuKey = true; //Skip has menu key below ICS
                boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

                //This is a hack for lollipop
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    hasBackKey = false;
                }

                if (navBarId > 0 && !hasMenuKey && !hasBackKey) {
                    heightDifference -= resources.getDimensionPixelSize(navBarId);
                }
            }

            //            int statusBarResourceId = mContext.getResources()
            //                  .getIdentifier("status_bar_height",
            //                        "dimen", "android");
            //            if (statusBarResourceId > 0) {
            //               heightDifference -= mContext.getResources()
            //                     .getDimensionPixelSize(statusBarResourceId);
            //            }
            //
            //            int navBarResourceId = mContext.getResources()
            //                  .getIdentifier("navigation_bar_height",
            //                        "dimen", "android");
            //            if (navBarResourceId > 0) {
            //               heightDifference -= mContext.getResources().getDimensionPixelSize(navBarResourceId);
            //            }

            if (heightDifference > 150) {
                keyBoardHeight = heightDifference;
                setSize(LayoutParams.MATCH_PARENT, keyBoardHeight);
                if (!isOpened) {
                    if (onSoftKeyboardOpenCloseListener != null)

                        onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight);
                }
                isOpened = true;
                if (pendingOpen) {
                    showAtBottom();
                    pendingOpen = false;
                }
            } else {
                isOpened = false;
                if (onSoftKeyboardOpenCloseListener != null)
                    onSoftKeyboardOpenCloseListener.onKeyboardClose();
            }
        }
    });
}

From source file:com.cleveroad.audiowidget.AudioWidget.java

private boolean hasNavigationBar() {
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
    int id = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
    return !hasBackKey && !hasHomeKey || id > 0 && context.getResources().getBoolean(id);
}

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);
    }/*from ww w. j a v a2 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 ww  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:org.getlantern.firetweet.util.Utils.java

public static boolean isComposeNowSupported() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
        return false;
    return !KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
}