package cn.net.caoyao.cpzshandset.ui.dialog;


import java.util.ArrayList;
import java.util.List;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;

import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.OrderFail;

public class TipsErrorDialog extends Dialog implements android.view.View.OnClickListener{
	private Button btn__tips_error_i_know;
	private ListView lv_dialog_tips_error_content;
	private List<OrderFail> fails = new ArrayList<OrderFail>();
//	private TipsErrorAdapter adapter;
	private Context context;

	public TipsErrorDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		this.context = context;
	}

	public TipsErrorDialog(Context context, int theme) {
		super(context, R.style.MyNoBgDialog);
		this.context = context;
	}

	public TipsErrorDialog(Context context) {
		super(context,R.style.MyNoBgDialog);
		this.context = context;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initDialogStyle();
		setContentView(R.layout.dialog_tips_error_layout);
		initView();
		setListener();
	}
	
	private void setListener() {
		btn__tips_error_i_know.setOnClickListener(this);
	}

	public void setData(List<OrderFail> orderFails){
		/*if (adapter != null) {
			adapter.setFails(orderFails);
			adapter.notifyDataSetChanged();
		}*/
	}
	
	private void initView() {
		btn__tips_error_i_know = (Button) this.findViewById(R.id.btn__tips_error_i_know);
		lv_dialog_tips_error_content = (ListView) this.findViewById(R.id.lv_dialog_tips_error_content);	 
		
		
//		adapter = new TipsErrorAdapter(context, fails);
//		lv_dialog_tips_error_content.setAdapter(adapter);
	}

	private void initDialogStyle() {
		Window win = this.getWindow();
		win.setBackgroundDrawableResource(R.color.transparent);
		WindowManager.LayoutParams lp = win.getAttributes();
		lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
		lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
		win.setAttributes(lp);
//		win.setWindowAnimations(R.style.dialogAnimation);
		// win.setWindowAnimations(R.style.CustomDialog);
		win.setGravity(Gravity.CENTER);
//		setFinishOnTouchOutside(false);//设置点击区域外不消失
//		this.setCanceledOnTouchOutside(false);
	}
	
	@Override
	public void dismiss() {
		try {
			if (this != null && this.isShowing()) {
				super.dismiss();
			}
		} catch (Exception e) {
		}
	}
	

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