Java Code Examples for android.view.KeyCharacterMap#deviceHasKey()

The following examples show how to use android.view.KeyCharacterMap#deviceHasKey() . 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: NavigationUtils.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
public static boolean hasNavBar(Context context) {
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

    if (hasBackKey && hasHomeKey) {
        if (Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("samsung") && !Build.MODEL.toLowerCase(Locale.ENGLISH).contains("nexus")) {
            return false;
        }

        Resources resources = context.getResources();
        int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        if (id > 0) {
            return resources.getBoolean(id);
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
Example 2
Source File: ScreenUtils.java    From NewbieGuide with Apache License 2.0 6 votes vote down vote up
/**
 * 虚拟操作拦(home等)是否显示
 */
public static boolean isNavigationBarShow(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.y != size.y;
    } else {
        boolean menu = ViewConfiguration.get(activity).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        if (menu || back) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 3
Source File: ViewUtil.java    From MaterialChipsInput with Apache License 2.0 6 votes vote down vote up
public static int getNavBarHeight(Context context) {
    int result = 0;
    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

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

        int orientation = context.getResources().getConfiguration().orientation;
        int resourceId;
        if (isTablet(context)){
            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");
        }

        if (resourceId > 0) {
            return context.getResources().getDimensionPixelSize(resourceId);
        }
    }
    return result;
}
 
Example 4
Source File: DecorUtils.java    From GestureViews with Apache License 2.0 6 votes vote down vote up
private static int getNavBarHeight(Context context) {
    boolean hasMenuKey = 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 {
        return 0;
    }
}
 
Example 5
Source File: VenvyUIUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param context
 * @return 是否存在导航栏
 */
public static boolean isNavigationBarShow(Context context) {
    if (!(context instanceof Activity)) {
        return false;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = ((Activity) (context)).getWindowManager().getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.x != size.x;
    } else {
        boolean menu = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        if (menu || back) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 6
Source File: Utils.java    From Snake with Apache License 2.0 6 votes vote down vote up
/**
 * Get whether navigation bar is visible.
 *
 * @param context Context
 * @return true: visible, false: invisible
 */
public static boolean navigationBarVisible(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        Point realSize = new Point();
        display.getRealSize(realSize);

        return realSize.y != size.y;
    }else {
        boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

        if(hasMenuKey || hasBackKey) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 7
Source File: MainActivity.java    From BottomNavigationBar with Apache License 2.0 6 votes vote down vote up
private boolean hasSystemNavigationBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).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) > 0 || (realHeight - displayHeight) > 0;
    } else {
        boolean hasMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !hasMenuKey && !hasBackKey;
    }
}
 
Example 8
Source File: AudioWidget.java    From MusicBobber with MIT License 5 votes vote down vote up
/**
 * Check if device has navigation bar.
 * @return true if device has navigation bar, false otherwise.
 */
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);
}
 
Example 9
Source File: CommonUseCases.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
public boolean hasNavBar() {
    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey)
        return true;
    else
        return false;
}
 
Example 10
Source File: ViewUtil.java    From Android-AudioRecorder-App with Apache License 2.0 5 votes vote down vote up
public static boolean hasNavBar(Activity activity) {
  Resources resources = activity.getResources();
  int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
  if (id > 0) {
    return resources.getBoolean(id);
  } else {    // Check for keys
    boolean hasMenuKey = ViewConfiguration.get(activity).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    return !hasMenuKey && !hasBackKey;
  }
}
 
Example 11
Source File: Utils.java    From chips-input-layout with MIT License 5 votes vote down vote up
static int getNavBarHeight(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
        final Resources res = c.getResources();
        final Configuration config = res.getConfiguration();

        int orientation = config.orientation;
        int resourceId;

        // Check if the device is a tablet
        if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
            resourceId = res.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT
                    ? "navigation_bar_height" : "navigation_bar_height_landscape",
                    "dimen", "android");
        } else {
            resourceId = res.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT
                    ? "navigation_bar_height" : "navigation_bar_width",
                    "dimen", "android");
        }

        if (resourceId > 0) {
            return res.getDimensionPixelSize(resourceId);
        }
    }
    return result;
}
 
Example 12
Source File: DragScaleCircleView.java    From DragScaleCircleView with Apache License 2.0 5 votes vote down vote up
/**
 * Initialization obtain the screen width and height.
 */
protected void init(@NonNull Context context, @Nullable AttributeSet attrs) {
    // custom attr
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DragScaleCircleView);
    try {
        mHasGuideLine = typedArray.getBoolean(R.styleable.DragScaleCircleView_hasGuideLine, true);
        mGuideLineSize = typedArray.getFloat(R.styleable.DragScaleCircleView_guideLineSize, getResources().getDimension(R.dimen.guideline_width));
        mGuideLineColor = typedArray.getInt(R.styleable.DragScaleCircleView_guideLineColor, getResources().getColor(R.color.guideline));
        mBorderSize = typedArray.getFloat(R.styleable.DragScaleCircleView_borderSize, getResources().getDimension(R.dimen.border_width));
        mBorderColor = typedArray.getInt(R.styleable.DragScaleCircleView_borderColor, getResources().getColor(R.color.border));
    } finally {
        typedArray.recycle();
    }

    final Resources resources = context.getResources();
    mScreenWidth = resources.getDisplayMetrics().widthPixels;
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
    if (hasBackKey && hasHomeKey) {
        mScreenHeight = getResources().getDisplayMetrics().heightPixels - 40 - 128;
    } else {
        mScreenHeight = getResources().getDisplayMetrics().heightPixels - 40;
    }
    mBoarderPaint = PaintUtil.newBoarderPaint(mBorderSize, mBorderColor);
    mSurroundingAreaOverlayPaint = PaintUtil.newSurroundingAreaOverlayPaint();
    mHandlePaint = PaintUtil.newHandlerPaint(resources);
    mHandleRadius = resources.getDimension(R.dimen.corner_width);
    mGuideLinePaint = PaintUtil.newGuideLinePaint(mGuideLineSize, mGuideLineColor);
}
 
Example 13
Source File: CommonUseCases.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
public boolean hasNavBar() {
    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey)
        return true;
    else
        return false;
}
 
Example 14
Source File: WindowUtil.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 是否存在NavigationBar
 */
public static boolean hasNavigationBar(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = getWindowManager(context).getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.x != size.x || realSize.y != size.y;
    } else {
        boolean menu = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !(menu || back);
    }
}
 
Example 15
Source File: DisplayUtils.java    From NestedTouchScrollingLayout with MIT License 5 votes vote down vote up
public static boolean hasNavigationBar(final Context pContext) {
    final int id = pContext.getResources().getIdentifier("config_showNavigationBar", "bool", "android");

    if (id > 0) {
        return pContext.getResources().getBoolean(id);
    } else {
        return !ViewConfiguration.get(pContext).hasPermanentMenuKey() && !KeyCharacterMap.deviceHasKey(KeyEvent
                .KEYCODE_BACK);
    }
}
 
Example 16
Source File: CommonUtils.java    From Android_framework with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 检查手机是否会有虚拟底部navigation bar
 */
public static boolean hasNavigationBar(){
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

    if(hasBackKey && hasHomeKey) {
        return false;
    }
    return true;
}
 
Example 17
Source File: BaseUtils.java    From orz with Apache License 2.0 5 votes vote down vote up
/**
 * Check the device whether has soft navigation bar
 */
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;
    }
}
 
Example 18
Source File: AndroidJoystickJoyInput14.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<Joystick> loadJoysticks(int joyId, InputManager inputManager) {
    logger.log(Level.INFO, "loading Joystick devices");
    ArrayList<Joystick> joysticks = new ArrayList<Joystick>();
    joysticks.clear();
    joystickIndex.clear();

    ArrayList<Integer> gameControllerDeviceIds = new ArrayList<>();
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();
        logger.log(Level.FINE, "deviceId[{0}] sources: {1}", new Object[]{deviceId, sources});

        // Verify that the device has gamepad buttons, control sticks, or both.
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
                ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            // This device is a game controller. Store its device ID.
            if (!gameControllerDeviceIds.contains(deviceId)) {
                gameControllerDeviceIds.add(deviceId);
                logger.log(Level.FINE, "Attempting to create joystick for device: {0}", dev);
                // Create an AndroidJoystick and store the InputDevice so we
                // can later correspond the input from the InputDevice to the
                // appropriate jME Joystick event
                AndroidJoystick joystick = new AndroidJoystick(inputManager,
                                                            joyInput,
                                                            dev,
                                                            joyId+joysticks.size(),
                                                            dev.getName());
                joystickIndex.put(deviceId, joystick);
                joysticks.add(joystick);

                // Each analog input is reported as a MotionRange
                // The axis number corresponds to the type of axis
                // The AndroidJoystick.addAxis(MotionRange) converts the axis
                // type reported by Android into the jME Joystick axis
                List<MotionRange> motionRanges = dev.getMotionRanges();
                for (MotionRange motionRange: motionRanges) {
                    logger.log(Level.INFO, "motion range: {0}", motionRange.toString());
                    logger.log(Level.INFO, "axis: {0}", motionRange.getAxis());
                    JoystickAxis axis = joystick.addAxis(motionRange);
                    logger.log(Level.INFO, "added axis: {0}", axis);
                }

                // InputDevice has a method for determining if a keyCode is
                // supported (InputDevice  public boolean[] hasKeys (int... keys)).
                // But this method wasn't added until rev 19 (Android 4.4)
                // Therefore, we only can query the entire device and see if
                // any InputDevice supports the keyCode.  This may result in
                // buttons being configured that don't exist on the specific
                // device, but I haven't found a better way yet.
                for (int keyCode: AndroidGamepadButtons) {
                    logger.log(Level.INFO, "button[{0}]: {1}",
                            new Object[]{keyCode, KeyCharacterMap.deviceHasKey(keyCode)});
                    if (KeyCharacterMap.deviceHasKey(keyCode)) {
                        // add button even though we aren't sure if the button
                        // actually exists on this InputDevice
                        logger.log(Level.INFO, "button[{0}] exists somewhere", keyCode);
                        JoystickButton button = joystick.addButton(keyCode);
                        logger.log(Level.INFO, "added button: {0}", button);
                    }
                }

            }
        }
    }


    loaded = true;
    return joysticks;
}
 
Example 19
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
public static boolean doThisDeviceOwnNavigationBar(Context context) {
    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    return !hasMenuKey && !hasBackKey;
}
 
Example 20
Source File: ViewUtils.java    From tribbble with Apache License 2.0 4 votes vote down vote up
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;
}