package com.backfire.popupwindow;

import net.yeeyo.doudizhu.feiyu.R;
import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.backfire.doudizhu.ActivityBase;
import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.doudizhu.luck.LuckActivity;

public class EnterConnectPopupWindow extends BasePopupWindow{
	private View view;
	private int width;
	private int height;
	
	private EditText user_nameconnect;
	private EditText user_phoneconnect;
	private EditText user_qqconnect;
	private TextView product_desc;
	private Button submit;
	private ImageView close;
	
	private int cardID;
	private String cardName;
	private long need;
	/**
	 * @param activity
	 */
	public EnterConnectPopupWindow(ActivityBase activity,int cardId,String cardName,long need) {
		super(activity);
		this.cardID = cardId;
		this.cardName = cardName;
		this.need = need;
		this.initSetting();
	}
	private void initSetting(){
		LayoutInflater mLayoutInflater = (LayoutInflater) mActivity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		int layoutRourse = R.layout.enter_connect_pop;
		view = mLayoutInflater.inflate(layoutRourse, null);
		
		view.setFocusableInTouchMode(true);
		 
		user_nameconnect = (EditText) view.findViewById(R.id.user_nameconnect);
		user_phoneconnect = (EditText) view.findViewById(R.id.user_phoneconnect);
		user_qqconnect = (EditText) view.findViewById(R.id.user_qqconnect);
		product_desc = (TextView) view.findViewById(R.id.product_desc);
		product_desc.setText(cardName);
		submit = (Button) view.findViewById(R.id.submit);
		close = (ImageView) view.findViewById(R.id.close);
		
		
		this.setFocusable(true);
		this.setConsumeKeyEvent(true);
		ImageView popupview = (ImageView) view.findViewById(R.id.select_bg);
		width = popupview.getLayoutParams().width;
		height = popupview.getLayoutParams().height;
		this.createPopupWindow(view, width, height);
	}
	
	/**
	 * 为各组件设置监听器
	 */
	public void setListens(final LuckActivity mcontext) {
		submit.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				String name_connect = user_nameconnect.getText().toString();
				if(!(name_connect!=null && name_connect.trim().length()>0)){
					DdzApplication.getApplication().showToast("请输入真实姓名!");
					return;
				}
				String phone_connect  = user_phoneconnect.getText().toString();
				if(!(phone_connect!=null && phone_connect.trim().length()>0)){
					DdzApplication.getApplication().showToast("请输入手机号码!");
					return;
				}
				String qq_connect  = user_qqconnect.getText().toString();
				if(!(qq_connect!=null && qq_connect.trim().length()>0)){
					DdzApplication.getApplication().showToast("请输入QQ号码!");
					return;
				}
				
				CloseWindow();
				mcontext.requestParser(cardID, name_connect,phone_connect,qq_connect,cardName,need);
				
				mActivity.playBtnPressMusic();
			}
			
		});
		close.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				CloseWindow();
				
				mActivity.playBtnPressMusic();
			}
			
		});
		view.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				CloseWindow();
				return false;
			}
		});
		
	}
	
	@Override
	protected boolean popupWindowWillShow() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected void popupWindowDidShow() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void popupWindowWillDissmiss() {
		// TODO Auto-generated method stub
		
	}
}



