package com.example.administrator.zhapp.weight;

import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.administrator.zhapp.R;

/**
 * Created by gzw on 2016/11/2.
 */

public class PrintSelect {
    private Context mContext;
    private AlertDialog dialog;
    private TextView tv_title;
    private Button btn_save;
    private Button btn_cancel;
    private Window mWindow;
    private RadioButton rb1;
    private RadioButton rb2;
    private RadioButton rb3;

    public PrintSelect(Context context) {
        mContext = context;
        dialog = new AlertDialog.Builder(context).create();
        dialog.setCancelable(true);
        dialog.show();
        mWindow = dialog.getWindow();
        mWindow.setContentView(R.layout.print_select);
        tv_title = (TextView) mWindow.findViewById(R.id.tv_title);
        btn_cancel = (Button) mWindow.findViewById(R.id.btn_qx);
        btn_save = (Button) mWindow.findViewById(R.id.btn_qd);
        rb1 = (RadioButton) mWindow.findViewById(R.id.rb1);
        rb2 = (RadioButton) mWindow.findViewById(R.id.rb2);
        rb3 = (RadioButton) mWindow.findViewById(R.id.rb3);
    }

    public void setSaveOnClick(View.OnClickListener listener) {
        btn_save.setOnClickListener(listener);
    }


    public void setCancelOnClick(View.OnClickListener listener) {
        btn_cancel.setOnClickListener(listener);
    }

    //如果返回TRUE，说明第一个被选中，就用第一个的ip，如果返回false，说明第二个被选中，就用第二个的ip
    public int getChecked() {

        int i = 1;
        if (rb1.isChecked()) {
            i = 1;
        } else if (rb2.isChecked()) {
            i = 2;
        } else if (rb3.isChecked()) {
            i = 3;
        }
        return i;
    }

    /**
     * 设置Title
     *
     * @param title
     */
    public void setTitle(String title) {
        tv_title.setText(title);
    }


    public void close() {
        dialog.dismiss();
    }
}
