 
package com.lianxin.pubqq.activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lianxin.pubqq.R;
import com.lianxin.panqq.edit.AddFriendDialog;
import com.lianxin.panqq.edit.EditFriendPowerDialog;
import com.lianxin.panqq.edit.EditNicknameDialog;
import com.lianxin.panqq.edit.MarkUserDialog;
import com.lianxin.panqq.edit.MoneyGiveUserDialog;
import com.lianxin.panqq.edit.MyAlertDialog;
import com.lianxin.panqq.edit.SetupGuardDialog;
import com.lianxin.panqq.edit.SetupSightDialog;
//import com.lianxin.panqq.file.UserFileUtil;
import com.lianxin.panqq.client.EditClient;
import com.lianxin.panqq.client.getClient;
import com.lianxin.panqq.client.getHeadClient;
import com.lianxin.panqq.client.markClient;
import com.lianxin.panqq.client.moneyClient;
import com.lianxin.panqq.client.callback.askCallBack;
import com.lianxin.panqq.client.callback.getCallBack;
import com.lianxin.panqq.common.BaseActivity;
import com.lianxin.panqq.common.DefineChat;
import com.lianxin.panqq.common.EditResult;
import com.lianxin.panqq.common.GloableParams;
import com.lianxin.panqq.common.Utils;
import com.lianxin.panqq.list.bean.Friend;
import com.lianxin.panqq.list.bean.Member;
import com.lianxin.panqq.list.bean.UserNode;
import com.lianxin.panqq.list.utils.AddressUtils;
import com.lianxin.panqq.list.utils.FriendTypeUtils;
import com.lianxin.panqq.list.utils.FriendUtil;
import com.lianxin.panqq.list.utils.FriendUtils;
import com.lianxin.panqq.list.utils.GroupManger;
import com.lianxin.panqq.list.utils.UserUtil;
import com.lianxin.pubqq.chat.EMChatActivity;
import com.lianxin.panqq.common.DefineUser;
import com.lianxin.panqq.utils.MoneyUtil;
import com.lianxin.panqq.utils.ImagesUtils;
import com.lianxin.panqq.utils.TimeUtil;
//import com.lianxin.panqq.chat.entity.EMMessage;
import com.lianxin.panqq.common.bean.AskInfo;
import com.lianxin.panqq.common.bean.UserEditInfo;
import com.lianxin.panqq.common.bean.UserInfo;
import com.lianxin.panqq.common.utils.UserheadUtils;
// 用户信息界面
public class FriendInfoActivity extends BaseActivity implements OnClickListener {
	private TextView txt_title,txt_right;
	private ImageView img_back, img_right; 
	private ImageView img_photo;  //用户头像
	private TextView txt_userid; //用户id
	private TextView txt_username;  //用户名	
	private TextView txt_nickname; //用户昵称
	private TextView txt_sex;  //用户性别
	private TextView txt_age;  //用户年龄
	private TextView txt_address;   //用户地区
	private TextView txt_power;   //用户职业
	private TextView txt_index;   //用户签名
	private TextView txt_jointime;  //用户在哪动态

	private Button btn_satrtchat;
	private Button btn_delfriend;
//	private Button btn_toblack;
//	private Button btn_jubao;
	private Button btn_setsight;
	private Button btn_setguard;
	private Button btn_markuser;
	private Button btn_givemoney;	
	private Button btn_detail;
	private Button btn_admin;	
	private RelativeLayout lay_nickname;
	private RelativeLayout lay_power;  
	private RelativeLayout lay_index;
	
//	private String userId = null;//用户唯一id
	private int nOursId = GloableParams.m_szUserId;//用户唯一id
	private int nUserId = 10100;//用户唯一id	
	private String strUserName = "情已停机";
	private int image = 10;
	private long userHead = 0;	
	private String strNickName = "赵八方";
	private int iSex = 1;
	private String Sex = "男";	
	private int iAge = 20;
	private int iAddress = 10;
	private int iPower = 1;
	private int iIndex = 10;
	private long addTime = 0;

	private LinearLayout lay_right;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_friendinfo);
		
		initControl();
		initView();
		initData();
		setListener();	
		
		//reSetData();	
		getRemoteFriendInfo();	
	}

	protected void initControl() {
		txt_title = (TextView) findViewById(R.id.txt_title);
		//txt_title.setText("用户查找");
		img_back = (ImageView) findViewById(R.id.img_back);
		img_back.setVisibility(View.VISIBLE);	
		txt_userid = (TextView)findViewById(R.id.tv_user_userid);
		txt_username = (TextView)findViewById(R.id.tv_user_username);		
		img_photo = (ImageView)findViewById(R.id.iv_user_image);
		txt_nickname = (TextView)findViewById(R.id.tv_user_nickname);
		txt_sex = (TextView)findViewById(R.id.tv_user_sex);
		txt_age = (TextView)findViewById(R.id.tv_user_age);
		txt_address = (TextView)findViewById(R.id.tv_user_address);
		txt_power = (TextView)findViewById(R.id.tv_user_power);
		txt_index = (TextView)findViewById(R.id.tv_user_index);		
		txt_jointime = (TextView)findViewById(R.id.tv_user_jointime);

		lay_nickname = (RelativeLayout) findViewById(R.id.rl_user_nickname);
		lay_power = (RelativeLayout) findViewById(R.id.rl_user_power);
		lay_index = (RelativeLayout) findViewById(R.id.rl_user_index);		
		btn_satrtchat = (Button)findViewById(R.id.btn_startchat);
		btn_delfriend = (Button)findViewById(R.id.btn_delfriend);
		btn_setsight = (Button)findViewById(R.id.btn_setsight);
		btn_setguard = (Button)findViewById(R.id.btn_setguard);
		btn_markuser = (Button)findViewById(R.id.btn_markuser);
		btn_givemoney = (Button)findViewById(R.id.btn_givemoney);
		btn_detail = (Button)findViewById(R.id.btn_detail);
		btn_admin = (Button)findViewById(R.id.btn_admin);
		
		lay_right = (LinearLayout)findViewById(R.id.layout_right);
		txt_right = (TextView)findViewById(R.id.tv_right);
	}

	protected void initView() {
		nUserId = getIntent().getIntExtra("Info_UserId", 10010);
		//判断是否是自己				
		if(nUserId == GloableParams.m_szUserId){
			txt_right.setText("我的故事");

		}
		//判断是否是好友，如果是就把加好友隐藏		
		if(FriendUtils.getFriendList(nUserId)>0){
			//btn_addfriend.setVisibility(View.GONE);
		}

	}
	
	protected void initData() {

		nUserId = getIntent().getIntExtra("Info_UserId", 10010);		
		strUserName = getIntent().getStringExtra("Info_NickName");
		strNickName = getIntent().getStringExtra("Info_NickName");		
		image = getIntent().getIntExtra("Info_Image", 23);		

		Friend friend = FriendUtil.getFriend( nUserId );
		if(friend!=null)
		{
		image = friend.imageid;
		userHead = friend.userhead;			
		iAge = friend.age;
		iAddress = friend.address;
		Sex = friend.sex;	
		iPower = friend.getPower();
		iIndex = friend.index;	
		}
		//如果是本地数据，则读取本地文件
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){		
		    UserNode thisUser = UserUtil.readOneUser(FriendInfoActivity.this, nUserId);	
		    if(thisUser!=null){
			strUserName = thisUser.getName();
			iAge = thisUser.age;
			iAddress = thisUser.address;
			//strAddress = thisUser.straddress;				
			image = thisUser.imageid;
			Sex = thisUser.sex;	
		    }
		}		
		txt_userid.setText(""+nUserId); 
		txt_username.setText(strUserName);	
		txt_nickname.setText(strNickName);		
        if(image<0) image = -image;		
        if(image>80) image = image%80;
        img_photo.setImageResource(ImagesUtils.images[image]);	
 
		txt_address.setText(AddressUtils.getAddress(iAddress));        
      //  txt_power.setText(""+iPower); 
        txt_power.setText(FriendTypeUtils.getTypeName(iPower));       
        txt_index.setText(""+iIndex);
	}	

	protected void reSetData() {
			
		txt_username.setText(strUserName);	
		txt_nickname.setText(strNickName);		
        if(image<0) image = -image;		
        if(image>80) image = image%80;
        img_photo.setImageResource(ImagesUtils.images[image]);	
  
		txt_address.setText(AddressUtils.getAddress(iAddress));         
        txt_power.setText(FriendTypeUtils.getTypeName(iPower));       
        txt_index.setText(""+iIndex);
        txt_sex.setText(Sex);
        txt_age.setText(""+iAge);        
        //TimeUtil.getMinTime(addTime); 
        if(addTime>1000000)
        txt_jointime.setText(TimeUtil.getMinTime(addTime*1000)); 
        //txt_jointime.setText(""+addTime); 
        if(userHead > 0x10000){
        	int mode = UserheadUtils.showUserHead(nUserId,userHead,img_photo);
        	if(mode>1)
        	getRemoteUserHead();
        }
	}	

	protected void setListener() {
		img_back.setOnClickListener(this);		
		lay_right.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
		//	startActivity(new Intent(Userinfo.this , UserActivity.class).putExtra("userId", userId));
			}
		});
		btn_satrtchat.setOnClickListener(this);
		btn_delfriend.setOnClickListener(this); 
		btn_setsight.setOnClickListener(this);
		btn_setguard.setOnClickListener(this);	
		btn_markuser.setOnClickListener(this);
		btn_givemoney.setOnClickListener(this);
		btn_detail.setOnClickListener(this);
		btn_admin.setOnClickListener(this);		
		lay_nickname.setOnClickListener(this); 
		lay_power.setOnClickListener(this);
		lay_index.setOnClickListener(this); 	
	}	
	
	@Override
	public void onClick(View arg0) {
		Intent intent1 = new Intent();
		int id = arg0.getId();
		if (id == R.id.img_back) {
			Utils.finish(FriendInfoActivity.this);
			//finish();
			//finish(FriendInfoActivity.this);
		} else if (id == R.id.btn_startchat) {
			Intent intent = new Intent(this, EMChatActivity.class);
			intent.putExtra("Chat_ID", nUserId);
			intent.putExtra("Chat_Type", DefineChat.ChatType_USER);
			String str = strNickName;
			if (TextUtils.isEmpty(str))
				str = strUserName;
			intent.putExtra("Chat_Name", str);
			startActivity(intent);
		} else if (id == R.id.btn_addfriend) {
			AskInfo uinfo = new AskInfo(nUserId, strNickName, image);
			new AddFriendDialog(FriendInfoActivity.this, uinfo,
					new AddFriendDialog.OnSetListener() {
						@Override
						public void onSelect(AskInfo askInfo) {
							//addFriend(askInfo);
						}
					}).show();
		} else if (id == R.id.btn_delfriend) {
			new MyAlertDialog(FriendInfoActivity.this, "删除好友？",
					"你确定要从好友列表中删除该好友吗？",
					new MyAlertDialog.OnSetListener() {
						@Override
						public void onSelect(int comm) {
							//addFriend(askInfo);
							UserInfo uinfo = new UserInfo(nUserId, nUserId, strNickName, image, iPower, iIndex);
							deleteFriend(uinfo);
						}
					}).show();
		} else if (id == R.id.btn_setsight) {//intent1.setClass(FriendInfoActivity.this, SightActivity.class);
			//startActivity(intent1);
			int admin = 0x2828;
			new SetupSightDialog(FriendInfoActivity.this, DefineUser.TYPE_FRIEND, admin,
					new SetupSightDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							setSight(option);
							//txt_power.setText(""+admin);
						}
					}).show();
		} else if (id == R.id.btn_setguard) {
			int admin1 = 0x2828;
			new SetupGuardDialog(FriendInfoActivity.this, DefineUser.TYPE_FRIEND, admin1,
					new SetupGuardDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							setGuard(option);
							// txt_power.setText(""+admin);
						}
					}).show();
		} else if (id == R.id.btn_markuser) {
			new MarkUserDialog(FriendInfoActivity.this, nUserId, strNickName,
					new MarkUserDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							MarkUser(option);
							// txt_power.setText(""+admin);
						}

						@Override
						public void onSelect(int count, int max) {
							String str = "投票成功。\n你今天已经投票" + count + "次，";
							int sub = max - count;
							if (count < max)
								str += "\n还可以投票" + sub + "次\n";
							else
								str += "\n每天的投票最大次数为20+金钻等级。\n超过的每次投票花费0.2个PQ币。\n";
							Utils.showLongToast(FriendInfoActivity.this, str);
						}
					}).show();
		} else if (id == R.id.btn_givemoney) {
			new MoneyGiveUserDialog(FriendInfoActivity.this, nUserId, strNickName,
					new MoneyGiveUserDialog.OnSetListener() {
						@Override
						public void onSelect(int option, int money) {
							if (option < 0 || option > 4) {
								String str = "你没有选中赠送类别！";
								Utils.showLongToast(FriendInfoActivity.this, str);
							} else if (option == 0)
								GiveMoney(option);
							else
								GiveDiamond(option, money);
							// txt_power.setText(""+admin);
						}
					}).show();
		} else if (id == R.id.btn_detail) {
			Intent intent3 = new Intent(FriendInfoActivity.this, UserDetailInfoActivity.class);
			intent3.putExtra("Info_UserId", nUserId);
			intent3.putExtra("Info_UserName", strUserName);
			intent3.putExtra("Info_Age", iAge);
			intent3.putExtra("Info_Address", iAddress);
			intent3.putExtra("Info_Image", image);
			intent3.putExtra("Info_Sex", Sex);
			startActivity(intent3);
		} else if (id == R.id.btn_admin) {
			Intent intent4 = new Intent(FriendInfoActivity.this, UserSuperInfoActivity.class);
			intent4.putExtra("Info_UserId", nUserId);
			intent4.putExtra("Info_UserName", strUserName);
			intent4.putExtra("Info_Age", iAge);
			intent4.putExtra("Info_Address", iAddress);
			intent4.putExtra("Info_Image", image);
			intent4.putExtra("Info_Sex", Sex);
			startActivity(intent4);
		} else if (id == R.id.rl_user_nickname) {//好友编辑中,userid是朋友id。type是类别。
			UserInfo uinfo3 = new UserInfo(nOursId, nUserId, strNickName, image, iPower, iIndex);
			new EditNicknameDialog(FriendInfoActivity.this, uinfo3, strUserName, iIndex,
					new EditNicknameDialog.OnSetListener() {
						@Override
						public void onSelect(UserInfo uinfo) {
							String strname = uinfo.nickname;
							txt_nickname.setText(strname);
							txt_index.setText("" + uinfo.index);
							editNickname(uinfo);
						}
					}).show();
		} else if (id == R.id.rl_user_power) {//	AskInfo uinfo2 = new AskInfo(nUserId,strNickName,image);
			UserInfo uinfo2 = new UserInfo(nOursId, nUserId, strNickName, image, iPower, iIndex);
			new EditFriendPowerDialog(FriendInfoActivity.this, uinfo2, iPower,
					new EditFriendPowerDialog.OnSetListener() {
						@Override
						public void onSelect(UserInfo uinfo) {
							//   txt_power.setText(""+uinfo.power);
							txt_power.setText(FriendTypeUtils.getTypeName(uinfo.power));
							editPower(uinfo);
						}
					}).show();
		} else if (id == R.id.rl_user_index) {
			UserInfo uinfo4 = new UserInfo(nOursId, nUserId, strNickName, image, iPower, iIndex);
			new EditNicknameDialog(FriendInfoActivity.this, uinfo4, strUserName, iIndex,
					new EditNicknameDialog.OnSetListener() {
						@Override
						public void onSelect(UserInfo uinfo) {
							String strname = uinfo.nickname;
							txt_nickname.setText(strname);
							txt_index.setText("" + uinfo.index);
							editNickname(uinfo);
						}
					}).show();
		}
	} 

	private void getRemoteFriendInfo(){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			UserNode userNode = UserUtil.readOneUser( FriendInfoActivity.this,nUserId );
			if(userNode!=null){
			    strUserName = userNode.username;						
			    iAddress = userNode.address;
			    iAge = userNode.age;
			    Sex = userNode.sex;						
			    image = userNode.imageid;						      
                reSetData();
			}			
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在刷新数据...").show();	
		getClient.GetEditUser(DefineUser.TYPE_FRIEND,nUserId,nOursId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				//SearUserList searlist = new SearUserList(recvBuf);	
				final UserEditInfo userInfo = new UserEditInfo(recvBuf);				
				//final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新数据...").dismiss();					
						strUserName = userInfo.username;						
						strNickName = userInfo.nickname;
						iAddress = userInfo.address;
						iAge = userInfo.age;
						Sex = userInfo.sex;
						image = userInfo.imageid;	
						userHead = userInfo.userhead;					
						iPower = userInfo.power;
						iIndex = userInfo.index;
						addTime = userInfo.jointime;						
						reSetData();					
						//Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新数据...").dismiss();						
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 		
	
	}	

	private void getRemoteUserHead(){

		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器		
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在刷新头像...").show();	
		getHeadClient.GetUserHead(1,nUserId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {

				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新头像...").dismiss();					
						UserheadUtils.showUserHead(nUserId,userHead,img_photo);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {

				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新头像...").dismiss();						
					}
				});	
			}
		});	 		
	
	}	
	
	public void editNickname(UserInfo uinfo){
		int nDestid = uinfo.destid;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.EditMemberName(DefineUser.TYPE_FRIEND,uinfo); //修改本地数据				
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();	
		//EditClient.EditMemberName(DefineUser.TYPE_FRIEND,uinfo,new askCallBack(){			
		EditClient.EditFriend(uinfo,DefineUser.ASK_FRIEND_EDITUSER,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	public void editPower(UserInfo uinfo){
		int nDestid = uinfo.destid;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.EditMemberType(DefineUser.TYPE_FRIEND,uinfo); //修改本地数据			
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();	
		//EditClient.EditMemberPower(DefineUser.TYPE_FRIEND,uinfo,new askCallBack(){		
		EditClient.EditFriend(uinfo,DefineUser.ASK_FRIEND_EDITUSER,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	public void deleteFriend(UserInfo uinfo){
		int nDestid = uinfo.destid;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.DeleteMember(DefineUser.TYPE_FRIEND,uinfo); //修改本地数据			
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();	
		//EditClient.EditMemberName(DefineUser.TYPE_FRIEND,uinfo,new askCallBack(){			
		EditClient.EditFriend(uinfo,DefineUser.ASK_FRIEND_DELETEUSER,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void setSight( int sight ){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在修改设置...").show();		
		markClient.setSightOption(DefineUser.TYPE_FRIEND,nUserId,sight,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();					
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(FriendInfoActivity.this, "服务器修改成功!");					
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void setGuard( int guard ){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在修改设置...").show();		
		markClient.setGuardOption(DefineUser.TYPE_FRIEND,nUserId,guard,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();					
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();	
						Utils.showLongToast(FriendInfoActivity.this, "服务器修改成功!");												
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void MarkUser( int option ){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在投票中...").show();		
		markClient.putMarkVote(DefineUser.TYPE_FRIEND,nUserId,option,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				//final int count = recvBuf[4];	
				//final int max = recvBuf[8];	
				int temp = recvBuf[4];	
				if(temp<0) temp += 0x100;				
				final int count = temp;	
				temp = recvBuf[8];	
				if(temp<0) temp += 0x100;				
				final int max = temp;				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在投票中...").dismiss();
						String str = "投票成功。\n你今天已经投票"+count+"次，";
						int sub = max - count;
						if(count<max)
							str += "\n还可以投票"+sub +"次\n";
						else
							str += "\n每天的投票最大次数为20+金钻等级。\n超过的每次投票花费0.2个PQ币。\n";						
						Utils.showLongToast(FriendInfoActivity.this, str);
						
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在正在投票中...").dismiss();							
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void GiveMoney( int option ){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在赠送中...").show();		
		moneyClient.putMoneyLift(DefineUser.TYPE_FRIEND,nDestid,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//final int money = (recvBuf[4]+recvBuf[5]*0x100+recvBuf[6]*0x10000)/100;	
				//final int excharge = (recvBuf[8]+recvBuf[9]*0x100+recvBuf[10]*0x10000)/100;	
				final int money = (MoneyUtil.ByteArrayToInt(recvBuf[4],recvBuf[5],recvBuf[6],recvBuf[7])+50)/100;
				final int excharge = (MoneyUtil.ByteArrayToInt(recvBuf[8],recvBuf[9],recvBuf[10],recvBuf[11])+50)/100;				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在赠送中...").dismiss();
						String str = "成功赠送PQ币。\n自己金钱:"+money+"\n对方金钱:"+excharge;										
						Utils.showLongToast(FriendInfoActivity.this, str);
						
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在赠送中...").dismiss();							
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void GiveDiamond( final int option,int money ){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(FriendInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在赠送中...").show();		
		moneyClient.putMoneyDiamond(DefineUser.TYPE_FRIEND,nDestid,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				//final int money = (recvBuf[4]+recvBuf[5]*0x100+recvBuf[6]*0x10000)/100;	
				final String strDiamond = ""+recvBuf[8]+":"+recvBuf[9]+":"+recvBuf[10]+":"+recvBuf[11];		
				final int money = (MoneyUtil.ByteArrayToInt(recvBuf[4],recvBuf[5],recvBuf[6],recvBuf[7])+50)/100;				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在赠送中...").dismiss();
						String strType = "";
						if( option == 0)
							strType = "绿卡";
						else if( option == 1)
							strType = "蓝盾";
						else if( option == 2)
							strType = "红运";
						else if( option == 3)
							strType = "金钻";						
						String str = "成功赠送"+strType+"。\n自己金钱余额:"+money+"\n对方钻石:"+strDiamond;						
						
						Utils.showLongToast(FriendInfoActivity.this, str);
						
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在赠送中...").dismiss();							
						Utils.showLongToast(FriendInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
}