package com.ym.modulecommon.base

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import com.ym.admodule.R
import com.ym.modulecommon.AppliContext
import com.ym.modulecommon.utils.PhoneUtils

/**
 * Created by gaoleichao on 2020-06-03
 */
open class BaseDialog {

    fun showBottomDialog(layout: Int, activity: Context, setHeadDialog: Dialog, animation: Int, gravity: Int): View {

        // AlertDialog setHeadDialog = new AlertDialog.Builder(activity).create();
        // setHeadDialog.show();

        val mDialogView = View.inflate(activity, layout, null)
        setHeadDialog.setContentView(mDialogView)
        val window = setHeadDialog.window
        // window.setContentView(mDialogView);
        window?.setGravity(gravity)
        window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
//        window.setWindowAnimations(R.style.AnimBottom)
        // WindowManager windowManager = activity.getWindowManager();
        // Display display = windowManager.getDefaultDisplay();
        val lp = window?.attributes
        window?.decorView?.setPadding(0, 0, 0, 0)
        // 设置宽度
        //Point size = new Point();
        //display.getSize(size);
        //lp.width = size.x;
        lp?.width = PhoneUtils.getScreenWidth(AppliContext.get())
        if (gravity == Gravity.TOP) {
            lp?.height = PhoneUtils.getScreenHeight(AppliContext.get())
        }
        //lp.width = (int) (display.getWidth()); // 设置宽度方式二: @过时
        //window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,0);
        window?.attributes = lp
        if (animation > 0)
            window?.setWindowAnimations(R.style.UpdateVersionCompatDialogTheme)//设置动画
        return mDialogView
    }
}