Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. // retrieve the position of the DecorView
  2. Rect visibleFrame = new Rect();
  3. getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleFrame);
  4.  
  5. DisplayMetrics dm = getResources().getDisplayMetrics();
  6. // check if the DecorView takes the whole screen vertically or horizontally
  7. boolean isRightOfContent = dm.heightPixels == visibleFrame.bottom;
  8. boolean isBelowContent = dm.widthPixels == visibleFrame.right;
  9.  
  10. public static boolean hasNavBar (Resources resources)
  11. {
  12. int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
  13. if (id > 0)
  14. return resources.getBoolean(id);
  15. else
  16. return false;
  17. }
  18.  
  19. public static int getNavigationBarHeight (Resources resources)
  20. {
  21. if (!Utils.hasNavBar(resources))
  22. return 0;
  23.  
  24. int orientation = resources.getConfiguration().orientation;
  25.  
  26. //Only phone between 0-599 has navigationbar can move
  27. boolean isSmartphone = resources.getConfiguration().smallestScreenWidthDp < 600;
  28. if (isSmartphone && Configuration.ORIENTATION_LANDSCAPE == orientation)
  29. return 0;
  30.  
  31. int id = resources
  32. .getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
  33. if (id > 0)
  34. return resources.getDimensionPixelSize(id);
  35.  
  36. return 0;
  37. }
  38.  
  39. public static int getNavigationBarWidth (Resources resources)
  40. {
  41. if (!Utils.hasNavBar(resources))
  42. return 0;
  43.  
  44. int orientation = resources.getConfiguration().orientation;
  45.  
  46. //Only phone between 0-599 has navigationbar can move
  47. boolean isSmartphone = resources.getConfiguration().smallestScreenWidthDp < 600;
  48.  
  49. if (orientation == Configuration.ORIENTATION_LANDSCAPE && isSmartphone)
  50. {
  51. int id = resources.getIdentifier("navigation_bar_width", "dimen", "android");
  52. if (id > 0)
  53. return resources.getDimensionPixelSize(id);
  54. }
  55.  
  56. return 0;
  57. }
  58.  
  59. public static boolean isSystemBarOnBottom(Context ctxt) {
  60. Resources res=ctxt.getResources();
  61. Configuration cfg=res.getConfiguration();
  62. DisplayMetrics dm=res.getDisplayMetrics();
  63. boolean canMove=(dm.widthPixels != dm.heightPixels &&
  64. cfg.smallestScreenWidthDp < 600);
  65.  
  66. return(!canMove || dm.widthPixels < dm.heightPixels);
  67. }
  68.  
  69. ViewConfiguration.get(ctxt).hasPermanentMenuKey()
  70.  
  71. public static boolean hasNavBar(Context context) {
  72. WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  73. Point realPoint = new Point();
  74. Display display = wm.getDefaultDisplay();
  75. display.getRealSize(realPoint);
  76. DisplayMetrics metrics = new DisplayMetrics();
  77. wm.getDefaultDisplay().getMetrics(metrics);
  78. return metrics.heightPixels + metrics.widthPixels != realPoint.y + realPoint.x;
  79. }
  80.  
  81. public static boolean isSystemBarOnBottom(Context context) {
  82. WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  83. Point realPoint = new Point();
  84. Display display = wm.getDefaultDisplay();
  85. display.getRealSize(realPoint);
  86. DisplayMetrics metrics = new DisplayMetrics();
  87. wm.getDefaultDisplay().getMetrics(metrics);
  88. Configuration cfg = context.getResources().getConfiguration();
  89. boolean canMove = (metrics.widthPixels != metrics.heightPixels &&
  90. cfg.smallestScreenWidthDp < 600);
  91.  
  92. return (!canMove || metrics.widthPixels < metrics.heightPixels);
  93. }
  94.  
  95. boolean navBarOnTheBottom(){
  96. DisplayMetrics displaymetrics = new DisplayMetrics();
  97. getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  98. int viewHeight = displaymetrics.heightPixels;
  99. if (bkg.getHeight() == viewHeight)
  100. {
  101. Log.d(TAG, "nav bar on the side");
  102. return false;
  103. }
  104. else{
  105. Log.d(TAG, "nav bar on the bottom");
  106. return true;
  107. }
  108. }
  109.  
  110. @Override
  111. public void onWindowFocusChanged (boolean hasFocus) {
  112. // the height will be set at this point
  113. bkgHeight = bkg.getHeight();
  114. }
  115.  
  116. boolean leftSideNavigationBar = Build.VERSION.SDK_INT > Build.VERSION_CODES.N
  117. && ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
  118. .getDefaultDisplay().rotation == Surface.ROTATION_270
Add Comment
Please, Sign In to add comment