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:Main.java

public static int getNavigationBarHeight(Context c) {
    int result = 0;
    boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey) {
        //The device has a navigation bar
        Resources resources = c.getResources();

        int orientation = resources.getConfiguration().orientation;
        int resourceId;
        if (isTablet(c)) {
            resourceId = resources/*from  w w  w  .  j  a va2s  . c o m*/
                    .getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                            : "navigation_bar_height_landscape", "dimen", "android");
        } else {
            resourceId = resources
                    .getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                            : "navigation_bar_width", "dimen", "android");
        }

        if (resourceId > 0) {
            return resources.getDimensionPixelSize(resourceId);
        }
    }
    return result;
}

From source file:Main.java

public static int getNavigationBarHeight(Context context) {
    int navigationBarHeight = 0;
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
    if (!hasBackKey && !hasHomeKey) {
        // 99% sure there is a navigation bar
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            navigationBarHeight = resources.getDimensionPixelSize(resourceId);
        }//www  .  java2  s.  c  o m
    }
    return navigationBarHeight;
}

From source file:Main.java

public static boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey) {
        return true;
    }/*from ww  w. j  a v a  2 s.  c  o m*/
    return false;
}

From source file:Main.java

private static int getNavBarHeight(Context context) {
    boolean hasMenuKey = Build.VERSION.SDK_INT >= 14 && ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasNavBar = !hasMenuKey && !hasBackKey;

    if (hasNavBar) {
        boolean isPortrait = context.getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;

        boolean isTablet = (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;

        String key = isPortrait ? "navigation_bar_height"
                : (isTablet ? "navigation_bar_height_landscape" : null);

        return key == null ? 0 : getDimenSize(context, key);
    } else {/* ww  w . jav  a  2 s.co  m*/
        return 0;
    }
}

From source file:Main.java

/**
 * Check the device whether has soft navigation bar
 *//*www  .  j  a v a  2s .  c  o  m*/
public static boolean hasNavigationBar(Context context) {
    Resources resources = context.getResources();
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        return resources.getBoolean(id);
    } else { // Check for keys
        boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !hasMenuKey && !hasBackKey;
    }
}

From source file:Main.java

public static boolean hasScrollKeys() {
    return KeyCharacterMap.deviceHasKey(92) || KeyCharacterMap.deviceHasKey(93);
}

From source file:Main.java

public static boolean hasKanaAndEmojiKeys() {
    return KeyCharacterMap.deviceHasKey(94) && KeyCharacterMap.deviceHasKey(95);
}

From source file:me.selinali.tribbble.utils.ViewUtils.java

public static int getNavigationBarHeight() {
    boolean hasMenuKey = ViewConfiguration.get(TribbbleApp.context()).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    return (!hasMenuKey && !hasBackKey) ? getInternalDimension("navigation_bar_height") : 0;
}

From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java

/**
 * If there is a virtual buttons, may have a miscalculation
 *
 * @return//from w w  w . j  a  v a2 s  .c  om
 */
private boolean hasNavigationBar() {
    boolean hasMenuKey = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        hasMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = getWindowManager().getDefaultDisplay();
        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);
        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;
        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);
        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;
        return realWidth > displayWidth || realHeight > displayHeight;
    }

    boolean hasPhysicsBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasPhysicsHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
    if (hasPhysicsBackKey && hasPhysicsHomeKey) {
        return false;
    } else {
        return true;
    }
}

From source file:com.thinkman.thinkutils.view.ActionSheet.java

public int getNavBarHeight(Context c) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

        if (!hasMenuKey && !hasBackKey) {
            //The device has a navigation bar
            Resources resources = c.getResources();

            int orientation = getResources().getConfiguration().orientation;
            int resourceId;
            if (isTablet(c)) {
                resourceId = resources.getIdentifier(
                        orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                                : "navigation_bar_height_landscape",
                        "dimen", "android");
            } else {
                resourceId = resources.getIdentifier(
                        orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                                : "navigation_bar_width",
                        "dimen", "android");
            }// w  ww. ja va2  s  .  com

            if (resourceId > 0) {
                return getResources().getDimensionPixelSize(resourceId);
            }
        }
    }
    return result;
}