package com.wdkl.app.ncs.callingbed.helper;

import android.app.Activity;
import android.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.wdkl.app.ncs.callingbed.R;


public class WarningDialogHelper {
    private static AlertDialog dialog;

    public static void showDialog(final Activity activity) {
        if (dialog != null && dialog.isShowing()) {
            return;
        }

        View contentView = LayoutInflater.from(activity).inflate(R.layout.warning_dialog_lay, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setView(contentView);
        Button button = contentView.findViewById(R.id.cancel_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppUpdateHelper.reboot(activity);
            }
        });

        dialog = builder.create();
        //dialog.setCanceledOnTouchOutside(false);
        //dialog.setCancelable(false);
        dialog.show();

        //设置dialog宽高及位置
        try {
            Window window = dialog.getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.width = 600;
            lp.height = 240;
            lp.gravity = Gravity.CENTER;
            window.setAttributes(lp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
