package com.joanfuentes.hintcase.utils;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class DimenUtils {
    public static int getStatusBarHeight(Context context) {
        int statusBarHeight = 0;
        Resources resources = context.getResources();
        int id = resources.getIdentifier("status_bar_height", "dimen", "android");
        if (id > 0) {
            statusBarHeight = resources.getDimensionPixelSize(id);
        }
        return statusBarHeight;
    }

    public static int getActionBarHeight(Context context) {
        int actionBarHeight = 0;
        TypedValue tv = new TypedValue();
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    context.getResources().getDisplayMetrics());
        }
        return actionBarHeight;
    }

    public static int dipToPixels(Context context, float valueInDP) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, valueInDP, displayMetrics);
    }

    public static Point getNavigationBarSizeIfExistAtTheBottom(Context context) {
        Point appUsableSize = getAppUsableScreenSize(context);
        Point realScreenSize = getRealScreenSize(context);
        Point navigationPoint;
        boolean navigationBarIsPresent = appUsableSize.y < realScreenSize.y;
        if (navigationBarIsPresent) {
            navigationPoint = new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
        } else {
            navigationPoint = new Point();
        }
        return navigationPoint;
    }

    public static Point getNavigationBarSizeIfExistOnTheRight(Context context) {
        Point appUsableSize = getAppUsableScreenSize(context);
        Point realScreenSize = getRealScreenSize(context);
        Point navigationPoint;
        boolean navigationBarIsPresent = appUsableSize.x < realScreenSize.x;
        if (navigationBarIsPresent) {
            navigationPoint =  new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
        } else {
            navigationPoint =  new Point();
        }
        return navigationPoint;
    }

    public static Point getAppUsableScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size;
    }

    public static Point getRealScreenSize(Context context) {
        View decorView = ((Activity)context).getWindow().getDecorView();
        Point size = new Point();
        size.x = decorView.getWidth();
        size.y = decorView.getHeight();
        return size;
    }
}

@@ -164,16 +164,41 @@
 .Point;%0A
+import android.os.Build;%0A
 import a
@@ -2929,107 +2929,406 @@
     
-View decorView = ((Activity)
+Point size = new Point();%0A        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.M) %7B%0A            WindowManager windowManager = (WindowManager) 
 context
-)
 .get
-Window().getDecorView();%0A        Point size = new Point();%0A
+SystemService(Context.WINDOW_SERVICE);%0A            Display display = windowManager.getDefaultDisplay();%0A            display.getRealSize(size);%0A        %7D else %7B%0A            View decorView = ((Activity)context).getWindow().getDecorView();%0A    
     
@@ -3366,24 +3366,28 @@
 ();%0A        
+   
+ 
 size.y = dec
@@ -3402,24 +3402,34 @@
 etHeight();%0A
+        %7D%0A
         retu

fix Crash with Android N Beta