package com.tjzhxx.union.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.tjzhxx.union.R;
import com.tjzhxx.union.system.MyApplication;


/**
 * 描述:
 *
 * @author yanghuaxiong
 * @create 2018/6/8  下午4:29
 */
public class SessionPromptDialog extends Dialog {
    private Context context;
    public SessionPromptDialog(@NonNull final Context context) {
        super(context, R.style.cp_dialogNoTitle);
        this.context = context;
        super.setContentView(R.layout.dialog_session_timeout_prompt);
        findViewById(R.id.sure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MyApplication.getInstance().removeAllActivity();
//                Intent intent = new Intent(context,LoginActivity.class);
//                context.startActivity(intent);
            }
        });
        setCancelAble(false);
    }

    public SessionPromptDialog setCancelAble(boolean cancelAble) {
        setCancelable(cancelAble);
        return this;
    }



    @SuppressWarnings("deprecation")
    @Override
    public void show() {
        Window dialogWindow = this.getWindow();
//        dialogWindow.setWindowAnimations(R.style.cp_dialogWindowAnim);
        WindowManager windowManager = dialogWindow.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL
                | Gravity.CENTER_VERTICAL);
        lp.width = (display.getWidth() * 1);
        int height = lp.height;
        if (height > display.getWidth() * 0.9) {
            lp.height = (int) (display.getWidth() * 0.9);
        }
        dialogWindow.setAttributes(lp);
        super.show();
    }
}
