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.ImageView;
import android.widget.TextView;

import com.backfire.doudizhu.ActivityBase;
import com.backfire.doudizhu.userinfo.UserMessageCenter;

public class OtherInfoPop extends BasePopupWindow{
	private View view;
	private int width;
	private int height;
	
	private TextView user_nick;
	private TextView user_sex;
	private TextView user_money;
	private TextView user_win_count;
	private TextView user_sign;
	
	private TextView user_lottery;
	
	private ImageView info_icon;
	private ImageView info_close;
	private ImageView vip_level;
	
	/**
	 * @param activity
	 */
	public OtherInfoPop(ActivityBase activity,long uid,int icon,String nick,int sex,long money,long winCount,long lottery,String sign) {
		super(activity);
		this.initSetting(uid,icon,nick,sex,money,winCount,lottery,sign);
	}
	private void initSetting(long uid,int icon,String nick,int sex,long money,long winCount,long lottery,String sign){
		LayoutInflater mLayoutInflater = (LayoutInflater) mActivity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		int layoutRourse = R.layout.otherinfo_pop;
		view = mLayoutInflater.inflate(layoutRourse, null);
		
		view.setFocusableInTouchMode(true);
		 
		user_nick = (TextView) view.findViewById(R.id.user_nick);
		user_money = (TextView) view.findViewById(R.id.user_money);
		user_sex = (TextView) view.findViewById(R.id.user_sex);
		user_win_count = (TextView) view.findViewById(R.id.user_win_count);
		user_sign = (TextView) view.findViewById(R.id.user_sign);
		
		info_icon = (ImageView) view.findViewById(R.id.info_icon);
		vip_level = (ImageView) view.findViewById(R.id.vip_level);
		info_close= (ImageView) view.findViewById(R.id.info_close);
		
		user_lottery = (TextView) view.findViewById(R.id.user_lottery);
		
		vip_level.setBackgroundResource(R.drawable.vip_has);
//		user_uid.setText("UID:"+uid);
		if(nick!=null && nick.trim().length()>0){
			user_nick.setText("昵称："+nick);
		}else{
			user_nick.setText("昵称：未知");
		}
		user_money.setText("金币 : "+UserMessageCenter.getLobbyMoney(money));

		info_icon.setImageResource(icon);
		
		if(sex==2){
			user_sex.setText("性别：女");
		}else{
			user_sex.setText("性别：男");
		}
		
		user_win_count.setText("战绩："+winCount+"胜");
		
		if(sign!=null && sign.trim().length()>0){
			user_sign.setText("个性签名："+sign);
		}else{
			user_sign.setText("个性签名：这家伙很屌丝，什么都没留下！");
		}
		user_lottery.setText("彩券 : "+UserMessageCenter.getLobbyMoney(lottery));
		
		this.setFocusable(true);
		this.setConsumeKeyEvent(true);
		ImageView popupview = (ImageView) view.findViewById(R.id.info_bg);
		width = popupview.getLayoutParams().width;
		height = popupview.getLayoutParams().height;
		this.createPopupWindow(view, width, height);
	}
	
	/**
	 * 为各组件设置监听器
	 */
	public void setListens() {
		view.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				CloseWindow();
				return false;
			}
		});
		view.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				CloseWindow();
			}
		});
		info_close.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				CloseWindow();
				
				mActivity.playBtnPressMusic();
			}
			
		});
	}
	
	@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
		
	}

}

