package com.ntels.product.chatbot.util

import android.app.Activity
import android.content.Context
import android.os.Build
import android.util.DisplayMetrics
import android.view.WindowManager


/**
 * Created by aaron on 2018-05-30
 */

class ScreenUtils {

    companion object {
        @JvmStatic fun getScreenWidth(context: Context) = DisplayMetrics().run {
                (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(this)
                return@run widthPixels
            }

        @JvmStatic fun getScreenHeight(context: Context) = DisplayMetrics().run {
            (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(this)
            return@run heightPixels
        }

        @JvmStatic fun getStatusBarHeight(context: Context) =
                context.resources.getIdentifier("status_bar_height", "dimen", "android")
                    .let { return@let if (it > 0)  context.resources.getDimensionPixelSize(it) else 0}

        @JvmStatic fun getSoftButtonBarSizePort(activity: Activity): Int {
            // getRealMetrics is only available with API 17 and +
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                val metrics = DisplayMetrics()
                activity.windowManager.defaultDisplay.getMetrics(metrics)
                val usableHeight = metrics.heightPixels
                activity.windowManager.defaultDisplay.getRealMetrics(metrics)
                val realHeight = metrics.heightPixels
                return if (realHeight > usableHeight)
                    realHeight - usableHeight - getStatusBarHeight(activity)
                else
                    0
            }
            return 0
        }
    }

}// This class is not publicly instantiable
