package com.partynetwork.iparty.contacts; import android.content.Context; import android.graphics.drawable.Drawable; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TextView; import com.partynetwork.dataprovider.util.ActionUtil; import com.partynetwork.iparty.R; import com.partynetwork.iparty.app.common.BitmapManager; import com.partynetwork.iparty.app.entities.CommonUser; import com.partynetwork.iparty.helper.IntentHelper; import com.partynetwork.iparty.info.ContactsInfo; import com.partynetwork.myview.myimageview.CircularImage; public class ContactsRecommendView extends LinearLayout implements OnClickListener { private Context mContext; /** * 头像 */ private CircularImage head; /** * 姓名 */ private TextView name; /** * 共同好友提示文本 */ private TextView content; /** 数据源 */ private ContactsInfo info; private BitmapManager bitmapManager; /** * * 构造函数 * * @param context */ public ContactsRecommendView(Context context,BitmapManager bitmapManager) { super(context); this.bitmapManager=bitmapManager; this.mContext = context; View.inflate(context, R.layout.contacts_recommend_item, this); init(); } /** * 数据初始化 */ private void init() { initView(); } /** * 实例化对象 */ private void initView() { head = (CircularImage) this.findViewById(R.id.head); head.setOnClickListener(this); name = (TextView) this.findViewById(R.id.name); content = (TextView) this.findViewById(R.id.content); } /** * 事件监听 * * @param view */ public void onClick(View view) { switch (view.getId()) { case R.id.head: IntentHelper.goPersonalCenterActivity(mContext, Integer.parseInt(view.getTag().toString())); break; default: break; } } /** * 设置数据源 * * @param contact */ public void setInfo(CommonUser info) { // 头像 bitmapManager.loadBitmap(info.getUserHeadUrl(), head); head.setTag(info.getUserId()); // 姓名 name.setText(info.getUserName()); // 性别 Drawable right = null; if (info.getUserSex() == ActionUtil.user.MALE) { right = mContext.getResources().getDrawable( R.drawable.sex_boy_middle_pressed); } else if (info.getUserSex() == ActionUtil.user.FEMALE) { right = mContext.getResources().getDrawable( R.drawable.sex_girl_middle_pressed); } else { right = mContext.getResources().getDrawable( R.drawable.sex_neutral_middle_pressed); } right.setBounds(0, 0, right.getMinimumWidth(), right.getMinimumHeight()); name.setCompoundDrawables(null, null, right, null); try { // 共同好友数量 this.info = (ContactsInfo) info; content.setText(this.info.getCommonUserNumber() + "个共同的i好友"); } catch (Exception e) { content.setText(info.getUserState()+" "+info.getUserAge() + " " + info.userCity); } } }