package ch.pizzapp.android.helper;

import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;

import ch.pizzapp.android.R;
import ch.pizzapp.android.activity.BaseActivity;

public class DisplayHelper {

    public static int getScreenWidthInPixel(){
        DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
        return displayMetrics.widthPixels;
    }

    public static int getScreenHeightInPixel(){
        DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
        return displayMetrics.heightPixels;
    }

    public static int dpToPx(int dp) {
        DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
        return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }

    public static int pxToDp(int px) {
        DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
        return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void changeStatusColor() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            return;
        Window window = BaseActivity.currentActivity.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(BaseActivity.currentActivity, R.color.main_black));
    }
}
