package com.dahe.mylibrary.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.dahe.mylibrary.R;


/**
 * Dialog 基类 基类  基类
 * <p>
 * 以后再写Dialog，都要继承这个
 *
 * @Description:
 * @Author: tao
 * @CreateDate: 2018/7/26 10:29
 */
public class MyBaseDialog extends Dialog {


    public MyBaseDialog(@NonNull Context context) {
        super(context, R.style.MyBaseDialog);
        init(context);
    }

    public void init(@NonNull Context context) {
        Window window = getWindow();
        window.setWindowAnimations(R.style.BottomAnim);
        window.setGravity(Gravity.CENTER);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度,由dialog的布局自己来决定实际显示宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCancelable(isCancelAble());
        setCanceledOnTouchOutside(isCancelAble());
    }

    public boolean isCancelAble() {
        return false;
    }

}
