Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // retrieve the position of the DecorView
- Rect visibleFrame = new Rect();
- getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleFrame);
- DisplayMetrics dm = getResources().getDisplayMetrics();
- // check if the DecorView takes the whole screen vertically or horizontally
- boolean isRightOfContent = dm.heightPixels == visibleFrame.bottom;
- boolean isBelowContent = dm.widthPixels == visibleFrame.right;
- public static boolean hasNavBar (Resources resources)
- {
- int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
- if (id > 0)
- return resources.getBoolean(id);
- else
- return false;
- }
- public static int getNavigationBarHeight (Resources resources)
- {
- if (!Utils.hasNavBar(resources))
- return 0;
- int orientation = resources.getConfiguration().orientation;
- //Only phone between 0-599 has navigationbar can move
- boolean isSmartphone = resources.getConfiguration().smallestScreenWidthDp < 600;
- if (isSmartphone && Configuration.ORIENTATION_LANDSCAPE == orientation)
- return 0;
- int id = resources
- .getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
- if (id > 0)
- return resources.getDimensionPixelSize(id);
- return 0;
- }
- public static int getNavigationBarWidth (Resources resources)
- {
- if (!Utils.hasNavBar(resources))
- return 0;
- int orientation = resources.getConfiguration().orientation;
- //Only phone between 0-599 has navigationbar can move
- boolean isSmartphone = resources.getConfiguration().smallestScreenWidthDp < 600;
- if (orientation == Configuration.ORIENTATION_LANDSCAPE && isSmartphone)
- {
- int id = resources.getIdentifier("navigation_bar_width", "dimen", "android");
- if (id > 0)
- return resources.getDimensionPixelSize(id);
- }
- return 0;
- }
- public static boolean isSystemBarOnBottom(Context ctxt) {
- Resources res=ctxt.getResources();
- Configuration cfg=res.getConfiguration();
- DisplayMetrics dm=res.getDisplayMetrics();
- boolean canMove=(dm.widthPixels != dm.heightPixels &&
- cfg.smallestScreenWidthDp < 600);
- return(!canMove || dm.widthPixels < dm.heightPixels);
- }
- ViewConfiguration.get(ctxt).hasPermanentMenuKey()
- public static boolean hasNavBar(Context context) {
- WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- Point realPoint = new Point();
- Display display = wm.getDefaultDisplay();
- display.getRealSize(realPoint);
- DisplayMetrics metrics = new DisplayMetrics();
- wm.getDefaultDisplay().getMetrics(metrics);
- return metrics.heightPixels + metrics.widthPixels != realPoint.y + realPoint.x;
- }
- public static boolean isSystemBarOnBottom(Context context) {
- WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- Point realPoint = new Point();
- Display display = wm.getDefaultDisplay();
- display.getRealSize(realPoint);
- DisplayMetrics metrics = new DisplayMetrics();
- wm.getDefaultDisplay().getMetrics(metrics);
- Configuration cfg = context.getResources().getConfiguration();
- boolean canMove = (metrics.widthPixels != metrics.heightPixels &&
- cfg.smallestScreenWidthDp < 600);
- return (!canMove || metrics.widthPixels < metrics.heightPixels);
- }
- boolean navBarOnTheBottom(){
- DisplayMetrics displaymetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
- int viewHeight = displaymetrics.heightPixels;
- if (bkg.getHeight() == viewHeight)
- {
- Log.d(TAG, "nav bar on the side");
- return false;
- }
- else{
- Log.d(TAG, "nav bar on the bottom");
- return true;
- }
- }
- @Override
- public void onWindowFocusChanged (boolean hasFocus) {
- // the height will be set at this point
- bkgHeight = bkg.getHeight();
- }
- boolean leftSideNavigationBar = Build.VERSION.SDK_INT > Build.VERSION_CODES.N
- && ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay().rotation == Surface.ROTATION_270
Add Comment
Please, Sign In to add comment