package ai.pai.client.views;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import ai.pai.client.R;

/**
 * Created by chengzhenyu on 2016/1/13.
 */
public class InputDialog extends Dialog implements View.OnClickListener{

    private EditText inputEditText;
    private Button   okBtn;
    private Button   cancelBtn;
    private String   inputTextStr;

    public InputDialog(Context context) {
        super(context);
        init(context);
    }

    public InputDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    protected InputDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    private void init(Context context){
        this.setCanceledOnTouchOutside(true);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_input);
        inputEditText = (EditText)findViewById(R.id.et_input_text);
        okBtn = (Button)findViewById(R.id.btn_input_ok);
        cancelBtn=(Button)findViewById(R.id.btn_input_cancel);
        okBtn.setOnClickListener(this);
        cancelBtn.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        if(v.getId()== R.id.btn_input_cancel){
            cancel();
        }else if(v.getId()== R.id.btn_input_ok){
            inputTextStr = inputEditText.getText().toString();
            cancel();
        }
    }

    public String getText(){
        return inputTextStr;
    }
}
