package com.ifavine.pay.view;

import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.ifavine.pay.R;


public class BConfirmDialog extends android.app.Dialog implements View.OnClickListener {


    private Context mContext;
    private View view;

    private BConfirmDialog(Context context, int defStyle) {
        super(context, defStyle);
        view = getLayoutInflater().inflate(R.layout.dialog_logout, null);
        super.setContentView(view);
    }


    public BConfirmDialog(Context context, String title, View.OnClickListener okListener, String okName, View.OnClickListener cancelListener, String cancelName) {
        this(context, R.style.logout_dialog_bottom);
        this.mContext = context;
        TextView tv_ok = (TextView) view.findViewById(R.id.tv_confirm);
        TextView tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_take_photo);
        tv_title.setText(title);
        tv_cancel.setText(cancelName);
        tv_ok.setText(okName);
        if (okListener != null) {
            tv_ok.setOnClickListener(okListener);
        } else {
            tv_ok.setOnClickListener(this);
        }
        if (cancelListener != null) {
            tv_cancel.setOnClickListener(cancelListener);
        } else {
            tv_cancel.setOnClickListener(this);
        }
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().setGravity(Gravity.BOTTOM);
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = (int) (d.getWidth() * 0.95);
        getWindow().setAttributes(p);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_confirm:
                dismiss();
                break;
        }
    }

}