コード例 #1
0
ファイル: MeView.java プロジェクト: yjl136/JPush
 public void initModule() {
   UserInfo userInfo = JMessageClient.getMyInfo();
   mTitleBarTitle = (TextView) findViewById(R.id.title_bar_title);
   mTitleBarTitle.setText(mContext.getString(R.string.actionbar_me));
   mScrollView = (PullScrollView) findViewById(R.id.scroll_view);
   mContentLl = (LinearLayout) findViewById(R.id.content_list_ll);
   mAvatarIv = (ImageView) findViewById(R.id.my_avatar_iv);
   mTakePhotoBtn = (ImageButton) findViewById(R.id.take_photo_iv);
   mUserInfoRl = (RelativeLayout) findViewById(R.id.user_info_rl);
   mUserNameTv = (TextView) findViewById(R.id.user_name_tv);
   mSettingRl = (RelativeLayout) findViewById(R.id.setting_rl);
   mLogoutRl = (RelativeLayout) findViewById(R.id.logout_rl);
   mScrollView.setHeader(mAvatarIv);
   if (userInfo != null) {
     mUserNameTv.setText(userInfo.getUserName());
     File file = userInfo.getAvatar();
     if (file != null && file.isFile()) {
       Log.i("MeView", "file.getAbsolutePath() " + file.getAbsolutePath());
       DisplayMetrics dm = new DisplayMetrics();
       ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(dm);
       double density = dm.density;
       Bitmap bitmap =
           BitmapLoader.getBitmapFromFile(
               file.getAbsolutePath(), dm.widthPixels, (int) (density * 300));
       mAvatarIv.setImageBitmap(bitmap);
     } else mAvatarIv.setImageResource(R.drawable.friends_sends_pictures_no);
   }
 }
コード例 #2
0
 private void handleGroupChangeMsg(Message msg, ViewHolder holder, TextView msgTime) {
   UserInfo myInfo = JMessageClient.getMyInfo();
   GroupInfo groupInfo = (GroupInfo) msg.getTargetInfo();
   String content = ((EventNotificationContent) msg.getContent()).getEventText();
   EventNotificationContent.EventNotificationType type =
       ((EventNotificationContent) msg.getContent()).getEventNotificationType();
   switch (type) {
     case group_member_added:
       holder.groupChange.setText(content);
       holder.groupChange.setVisibility(View.VISIBLE);
       break;
     case group_member_exit:
       holder.groupChange.setVisibility(View.GONE);
       msgTime.setVisibility(View.GONE);
       break;
     case group_member_removed:
       List<String> userNames = ((EventNotificationContent) msg.getContent()).getUserNames();
       // 被删除的人显示EventNotification
       if (userNames.contains(myInfo.getNickname()) || userNames.contains(myInfo.getUserName())) {
         holder.groupChange.setText(content);
         holder.groupChange.setVisibility(View.VISIBLE);
         // 群主亦显示
       } else if (myInfo.getUserName().equals(groupInfo.getGroupOwner())) {
         holder.groupChange.setText(content);
         holder.groupChange.setVisibility(View.VISIBLE);
       } else {
         holder.groupChange.setVisibility(View.GONE);
         msgTime.setVisibility(View.GONE);
       }
       break;
   }
 }
コード例 #3
0
 public void setOnCheck(int position) {
   UserInfo userInfo = mMemberList.get(position);
   if (mSelectedList.contains(userInfo.getUserName())) {
     //            View view = getView(position, null, null);
     //            CheckBox checkBox = (CheckBox) view.findViewById(R.id.check_box_cb);
     //            checkBox.setChecked(false);
     mSelectedList.remove(position);
     mSelectMap.delete(position);
   } else {
     mSelectedList.add(userInfo.getUserName());
     mSelectMap.put(position, true);
   }
   notifyDataSetChanged();
 }
コード例 #4
0
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   UserInfo userInfo = mMemberList.get(position);
   String userName = userInfo.getUserName();
   Intent intent = new Intent();
   if (userName.equals(JMessageClient.getMyInfo().getUserName())) {
     intent.setClass(mContext, MeInfoActivity.class);
     mContext.startActivity(intent);
   } else {
     intent.setClass(mContext, FriendInfoActivity.class);
     intent.putExtra(JChatDemoApplication.TARGET_ID, userInfo.getUserName());
     intent.putExtra(JChatDemoApplication.GROUP_ID, mGroupId);
     mContext.startActivity(intent);
   }
 }
コード例 #5
0
  public void setUserNickname(JSONArray data, CallbackContext callbackContext) {
    Log.i(TAG, "setUserNickname");
    try {
      String nickName = data.getString(0);
      Log.i(TAG, "setUserNickname" + nickName);

      UserInfo myUserInfo = JMessageClient.getMyInfo();
      myUserInfo.setNickname(nickName);
      this.setUserInfo(UserInfo.Field.nickname, myUserInfo, callbackContext);
      callbackContext.success("update userinfo ok");

    } catch (JSONException e) {
      e.printStackTrace();
      callbackContext.error("Error reading alias JSON");
    }
  }
コード例 #6
0
  public void getAllSingleConversation(JSONArray data, CallbackContext callbackContext) {
    Log.i(TAG, "  getAllSingleConversation \n" + data);

    List<Conversation> list = JMessageClient.getConversationList();

    Log.i(TAG, "JMessageGetAllSingleConversation" + list.size());

    JSONArray jsonRusult = new JSONArray();

    for (int i = 0; i < list.size(); ++i) {
      Conversation conv = list.get(i);

      if (conv.getType() == ConversationType.single) {

        UserInfo info = (UserInfo) conv.getTargetInfo();
        Message msg = conv.getLatestMessage();
        String contentText = "";
        if (msg != null) {
          switch (msg.getContentType()) {
            case text:
              {
                contentText = ((TextContent) msg.getContent()).getText();
              }
              break;
            default:
              break;
          }
        }

        JSONObject jsonItem = new JSONObject();
        try {
          jsonItem.put("username", info.getUserName());
          jsonItem.put("nickname", info.getNickname());
          // jsonItem.put("avatar", info.getAvatar());
          jsonItem.put("lastMessage", contentText);
          jsonItem.put("unreadCount", conv.getUnReadMsgCnt());

          jsonRusult.put(jsonItem);

        } catch (JSONException e) {
          e.printStackTrace();
        }
      }
    }

    callbackContext.success(jsonRusult);
  }
コード例 #7
0
 public void getUserInfo(JSONArray data, CallbackContext callbackContext) {
   Log.i(TAG, " getUserInfo \n" + data);
   UserInfo info = JMessageClient.getMyInfo();
   try {
     if (info != null && info.getUserName() != null) {
       JSONObject jsonItem = new JSONObject();
       jsonItem.put("username", info.getUserName());
       jsonItem.put("nickname", info.getNickname());
       jsonItem.put("gender", "unknow");
       callbackContext.success(jsonItem);
     } else {
       JSONObject jsonItem = new JSONObject();
       jsonItem.put("errorCode", 863004);
       jsonItem.put("errorDscription", "not found");
       callbackContext.error(jsonItem);
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
コード例 #8
0
  public void setUserGender(JSONArray data, CallbackContext callbackContext) {

    try {

      String genderString = data.getString(0);
      UserInfo.Gender gender = UserInfo.Gender.unknown;
      if (genderString.equals("male")) {
        gender = UserInfo.Gender.male;
      } else if (genderString.equals("female")) {
        gender = UserInfo.Gender.female;
      }

      UserInfo myUserInfo = JMessageClient.getMyInfo();
      myUserInfo.setGender(gender);
      this.setUserInfo(UserInfo.Field.gender, myUserInfo, callbackContext);

    } catch (JSONException e) {
      e.printStackTrace();
      callbackContext.error("Error reading alias JSON");
    }
  }
コード例 #9
0
  private JSONObject getJSonFormMessage(Message msg) {
    String contentText = "";
    String msgType = ""; // 上传给js 层的类型,请和ios 保持一致

    switch (msg.getContentType()) {
      case text:
        contentText = ((TextContent) msg.getContent()).getText();
        msgType = "text";
        break;
      default:
        break;
    }
    Log.i(TAG, "msg " + contentText);

    JSONObject jsonItem = new JSONObject();
    try {
      MessageContent content = msg.getContent();
      UserInfo targetUser = (UserInfo) msg.getTargetInfo();
      UserInfo fromUser = (UserInfo) msg.getFromUser();

      jsonItem.put("target_type", "single");
      jsonItem.put("target_id", targetUser.getUserName());
      jsonItem.put("target_name", targetUser.getNickname());
      jsonItem.put("from_id", fromUser.getUserName());
      // jsonItem.put("from_name", fromUser.getNickname());
      jsonItem.put("from_name", msg.getFromName());
      jsonItem.put("create_time", msg.getCreateTime());
      jsonItem.put("msg_type", msgType);
      // jsonItem.put("text", contentText);

      JSONObject contentBody = new JSONObject();
      contentBody.put("text", contentText);
      jsonItem.put("msg_body", contentBody);

    } catch (JSONException e) {
      e.printStackTrace();
    }
    return jsonItem;
  }
コード例 #10
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.return_btn:
       mContext.setResultAndFinish();
       break;
     case R.id.nick_name_rl:
       mContext.startModifyNickNameActivity();
       break;
     case R.id.sex_rl:
       UserInfo userInfo = JMessageClient.getMyInfo();
       UserInfo.Gender gender = userInfo.getGender();
       mContext.showSexDialog(gender);
       break;
     case R.id.location_rl:
       mContext.startSelectAreaActivity();
       break;
     case R.id.sign_rl:
       mContext.startModifySignatureActivity();
       break;
   }
 }
コード例 #11
0
 public MsgListAdapter(Context context, String targetId) {
   initData(context);
   this.mTargetId = targetId;
   this.mConv = JMessageClient.getSingleConversation(mTargetId);
   this.mMsgList = mConv.getMessagesFromNewest(0, mOffset);
   reverse(mMsgList);
   mStart = mOffset;
   UserInfo userInfo = (UserInfo) mConv.getTargetInfo();
   if (!TextUtils.isEmpty(userInfo.getAvatar())) {
     userInfo.getAvatarBitmap(
         new GetAvatarBitmapCallback() {
           @Override
           public void gotResult(int status, String desc, Bitmap bitmap) {
             if (status == 0) {
               notifyDataSetChanged();
             } else {
               HandleResponseCode.onHandle(mContext, status, false);
             }
           }
         });
   }
   checkSendingImgMsg();
 }
コード例 #12
0
  /**
   * 接收消息类事件
   *
   * @param event 消息事件
   */
  public void onEvent(MessageEvent event) {
    final Message msg = event.getMessage();
    // 若为群聊相关事件,如添加、删除群成员
    Log.i(TAG, event.getMessage().toString());
    if (msg.getContentType() == ContentType.eventNotification) {
      GroupInfo groupInfo = (GroupInfo) msg.getTargetInfo();
      long groupID = groupInfo.getGroupID();
      UserInfo myInfo = JMessageClient.getMyInfo();
      EventNotificationContent.EventNotificationType type =
          ((EventNotificationContent) msg.getContent()).getEventNotificationType();
      if (groupID == mChatController.getGroupId()) {
        switch (type) {
          case group_member_added:
            // 添加群成员事件
            List<String> userNames = ((EventNotificationContent) msg.getContent()).getUserNames();
            // 群主把当前用户添加到群聊,则显示聊天详情按钮
            refreshGroupNum();
            if (userNames.contains(myInfo.getNickname())
                || userNames.contains(myInfo.getUserName())) {
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      mChatView.showRightBtn();
                    }
                  });
            }

            break;
          case group_member_removed:
            // 删除群成员事件
            userNames = ((EventNotificationContent) msg.getContent()).getUserNames();
            // 群主删除了当前用户,则隐藏聊天详情按钮
            if (userNames.contains(myInfo.getNickname())
                || userNames.contains(myInfo.getUserName())) {
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      mChatView.dismissRightBtn();
                      GroupInfo groupInfo =
                          (GroupInfo) mChatController.getConversation().getTargetInfo();
                      if (TextUtils.isEmpty(groupInfo.getGroupName())) {
                        mChatView.setChatTitle(ChatActivity.this.getString(R.string.group));
                      } else {
                        mChatView.setChatTitle(groupInfo.getGroupName());
                      }
                      mChatView.dismissGroupNum();
                    }
                  });
            } else {
              refreshGroupNum();
            }

            break;
          case group_member_exit:
            refreshGroupNum();
            break;
        }
      }
    }
    // 刷新消息
    runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // 收到消息的类型为单聊
            if (msg.getTargetType().equals(ConversationType.single)) {
              String targetID = ((UserInfo) msg.getTargetInfo()).getUserName();
              // 判断消息是否在当前会话中
              if (!mChatController.isGroup() && targetID.equals(mChatController.getTargetId())) {
                Message lastMsg = mChatController.getAdapter().getLastMsg();
                if (lastMsg == null || msg.getId() != lastMsg.getId()) {
                  mChatController.getAdapter().addMsgToList(msg);
                } else {
                  mChatController.getAdapter().notifyDataSetChanged();
                }
              }
            } else {
              long groupID = ((GroupInfo) msg.getTargetInfo()).getGroupID();
              if (mChatController.isGroup() && groupID == mChatController.getGroupId()) {
                Message lastMsg = mChatController.getAdapter().getLastMsg();
                if (lastMsg == null || msg.getId() != lastMsg.getId()) {
                  mChatController.getAdapter().addMsgToList(msg);
                } else {
                  mChatController.getAdapter().notifyDataSetChanged();
                }
              }
            }
          }
        });
  }
コード例 #13
0
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    final Message msg = mMsgList.get(position);
    final UserInfo userInfo = msg.getFromUser();
    final ViewHolder holder;
    if (convertView == null) {
      holder = new ViewHolder();
      convertView = createViewByType(msg, position);
      switch (msg.getContentType()) {
        case text:
          holder.headIcon = (CircleImageView) convertView.findViewById(R.id.avatar_iv);
          holder.displayName = (TextView) convertView.findViewById(R.id.display_name_tv);
          holder.txtContent = (TextView) convertView.findViewById(R.id.msg_content);
          holder.sendingIv = (ImageView) convertView.findViewById(R.id.sending_iv);
          holder.resend = (ImageButton) convertView.findViewById(R.id.fail_resend_ib);
          holder.groupChange = (TextView) convertView.findViewById(R.id.group_content);
          break;
        case image:
          holder.headIcon = (CircleImageView) convertView.findViewById(R.id.avatar_iv);
          holder.displayName = (TextView) convertView.findViewById(R.id.display_name_tv);
          holder.picture = (ImageView) convertView.findViewById(R.id.picture_iv);
          holder.sendingIv = (ImageView) convertView.findViewById(R.id.sending_iv);
          holder.progressTv = (TextView) convertView.findViewById((R.id.progress_tv));
          holder.resend = (ImageButton) convertView.findViewById(R.id.fail_resend_ib);
          break;
        case voice:
          holder.headIcon = (CircleImageView) convertView.findViewById(R.id.avatar_iv);
          holder.displayName = (TextView) convertView.findViewById(R.id.display_name_tv);
          holder.txtContent = (TextView) convertView.findViewById(R.id.msg_content);
          holder.voice = ((ImageView) convertView.findViewById(R.id.voice_iv));
          holder.sendingIv = (ImageView) convertView.findViewById(R.id.sending_iv);
          holder.voiceLength = (TextView) convertView.findViewById(R.id.voice_length_tv);
          holder.readStatus = (ImageView) convertView.findViewById(R.id.read_status_iv);
          holder.resend = (ImageButton) convertView.findViewById(R.id.fail_resend_ib);
          break;
        case location:
          holder.headIcon = (CircleImageView) convertView.findViewById(R.id.avatar_iv);
          holder.displayName = (TextView) convertView.findViewById(R.id.display_name_tv);
          holder.txtContent = (TextView) convertView.findViewById(R.id.msg_content);
          holder.sendingIv = (ImageView) convertView.findViewById(R.id.sending_iv);
          holder.resend = (ImageButton) convertView.findViewById(R.id.fail_resend_ib);
          break;
        case eventNotification:
          holder.groupChange = (TextView) convertView.findViewById(R.id.group_content);
          break;
        default:
          holder.groupChange = (TextView) convertView.findViewById(R.id.group_content);
      }
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    // 显示时间
    TextView msgTime = (TextView) convertView.findViewById(R.id.send_time_txt);
    long nowDate = msg.getCreateTime();
    if (mOffset == 18) {
      if (position == 0 || position % 18 == 0) {
        TimeFormat timeFormat = new TimeFormat(mContext, nowDate);
        msgTime.setText(timeFormat.getDetailTime());
        msgTime.setVisibility(View.VISIBLE);
      } else {
        long lastDate = mMsgList.get(position - 1).getCreateTime();
        // 如果两条消息之间的间隔超过十分钟则显示时间
        if (nowDate - lastDate > 600000) {
          TimeFormat timeFormat = new TimeFormat(mContext, nowDate);
          msgTime.setText(timeFormat.getDetailTime());
          msgTime.setVisibility(View.VISIBLE);
        } else {
          msgTime.setVisibility(View.GONE);
        }
      }
    } else {
      if (position == 0 || position == mOffset || (position - mOffset) % 18 == 0) {
        TimeFormat timeFormat = new TimeFormat(mContext, nowDate);

        msgTime.setText(timeFormat.getDetailTime());
        msgTime.setVisibility(View.VISIBLE);
      } else {
        long lastDate = mMsgList.get(position - 1).getCreateTime();
        // 如果两条消息之间的间隔超过十分钟则显示时间
        if (nowDate - lastDate > 600000) {
          TimeFormat timeFormat = new TimeFormat(mContext, nowDate);
          msgTime.setText(timeFormat.getDetailTime());
          msgTime.setVisibility(View.VISIBLE);
        } else {
          msgTime.setVisibility(View.GONE);
        }
      }
    }

    // 显示头像
    if (holder.headIcon != null) {
      if (userInfo != null && !TextUtils.isEmpty(userInfo.getAvatar())) {
        userInfo.getAvatarBitmap(
            new GetAvatarBitmapCallback() {
              @Override
              public void gotResult(int status, String desc, Bitmap bitmap) {
                if (status == 0) {
                  holder.headIcon.setImageBitmap(bitmap);
                } else {
                  holder.headIcon.setImageResource(R.drawable.jmui_head_icon);
                  HandleResponseCode.onHandle(mContext, status, false);
                }
              }
            });
      } else {
        holder.headIcon.setImageResource(R.drawable.jmui_head_icon);
      }

      // TODO 点击头像事件

    }

    OnLongClickListener longClickListener =
        new OnLongClickListener() {
          @Override
          public boolean onLongClick(View arg0) {
            // 长按文本弹出菜单
            String name = userInfo.getUserName();
            OnClickListener listener =
                new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    switch (v.getId()) {
                      case R.id.copy_msg_btn:
                        if (msg.getContentType() == ContentType.text) {
                          final String content = ((TextContent) msg.getContent()).getText();
                          if (Build.VERSION.SDK_INT > 11) {
                            ClipboardManager clipboard =
                                (ClipboardManager)
                                    mContext.getSystemService(mContext.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("Simple text", content);
                            clipboard.setPrimaryClip(clip);
                          } else {
                            ClipboardManager clipboard =
                                (ClipboardManager)
                                    mContext.getSystemService(mContext.CLIPBOARD_SERVICE);
                            clipboard.setText(content); // 设置Clipboard 的内容
                            if (clipboard.hasText()) {
                              clipboard.getText();
                            }
                          }

                          Toast.makeText(
                                  mContext,
                                  mContext.getString(R.string.copy_toast),
                                  Toast.LENGTH_SHORT)
                              .show();
                          mDialog.dismiss();
                        }
                        break;
                      case R.id.forward_msg_btn:
                        mDialog.dismiss();
                        break;
                      case R.id.delete_msg_btn:
                        mConv.deleteMessage(msg.getId());
                        mMsgList.remove(position);
                        notifyDataSetChanged();
                        mDialog.dismiss();
                        break;
                    }
                  }
                };
            boolean hide = msg.getContentType() == ContentType.voice;
            mDialog = DialogCreator.createLongPressMessageDialog(mContext, name, hide, listener);
            mDialog.show();
            mDialog
                .getWindow()
                .setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
            return true;
          }
        };

    switch (msg.getContentType()) {
      case text:
        handleTextMsg(msg, holder, longClickListener);
        break;
      case image:
        handleImgMsg(msg, holder, position);
        break;
      case voice:
        handleVoiceMsg(msg, holder, position, longClickListener);
        break;
      case eventNotification:
        handleGroupChangeMsg(msg, holder, msgTime);
        break;
      default:
        handleCustomMsg(msg, holder);
    }

    return convertView;
  }
コード例 #14
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ItemViewTag viewTag;
    Bitmap bitmap;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.group_grid_view_item, null);
      viewTag =
          new ItemViewTag(
              (CircleImageView) convertView.findViewById(R.id.grid_avatar),
              (TextView) convertView.findViewById(R.id.grid_name),
              (ImageView) convertView.findViewById(R.id.grid_delete_icon));
      convertView.setTag(viewTag);
    } else {
      viewTag = (ItemViewTag) convertView.getTag();
    }

    if (position < mCurrentNum) {
      UserInfo userInfo = mMemberList.get(position);
      viewTag = (ItemViewTag) convertView.getTag();
      viewTag.icon.setVisibility(View.VISIBLE);
      viewTag.name.setVisibility(View.VISIBLE);
      bitmap = NativeImageLoader.getInstance().getBitmapFromMemCache(userInfo.getUserName());
      if (bitmap != null) viewTag.icon.setImageBitmap(bitmap);
      else {
        // 如果mediaID为空,表明用户没有设置过头像,用默认头像
        if (TextUtils.isEmpty(userInfo.getAvatar())) {
          viewTag.icon.setImageResource(R.drawable.head_icon);
        } else {
          File file = userInfo.getAvatarFile();
          // 如果本地存在头像
          if (file != null && file.isFile()) {
            bitmap =
                BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), mDefaultSize, mDefaultSize);
            NativeImageLoader.getInstance().updateBitmapFromCache(userInfo.getUserName(), bitmap);
            viewTag.icon.setImageBitmap(bitmap);
            // 从网上拿头像
          } else {
            viewTag.icon.setImageResource(R.drawable.head_icon);
            final String userName = userInfo.getUserName();
            userInfo.getAvatarFileAsync(
                new DownloadAvatarCallback() {
                  @Override
                  public void gotResult(int status, String desc, File file) {
                    if (status == 0) {
                      Bitmap bitmap =
                          BitmapLoader.getBitmapFromFile(
                              file.getAbsolutePath(), mDefaultSize, mDefaultSize);
                      NativeImageLoader.getInstance().updateBitmapFromCache(userName, bitmap);
                      notifyDataSetChanged();
                    }
                  }
                });
          }
        }
      }

      if (TextUtils.isEmpty(userInfo.getNickname())) {
        viewTag.name.setText(userInfo.getUserName());
      } else {
        viewTag.name.setText(userInfo.getNickname());
      }
    }
    // 是Delete状态
    if (mIsShowDelete) {
      if (position < mCurrentNum) {
        UserInfo userInfo = mMemberList.get(position);
        // 群主不能删除自己
        if (userInfo.getUserName().equals(JMessageClient.getMyInfo().getUserName()))
          viewTag.deleteIcon.setVisibility(View.GONE);
        else viewTag.deleteIcon.setVisibility(View.VISIBLE);

      } else {
        viewTag.deleteIcon.setVisibility(View.INVISIBLE);
        viewTag.icon.setVisibility(View.INVISIBLE);
        viewTag.name.setVisibility(View.INVISIBLE);
      }
      // 非Delete状态
    } else {
      viewTag.deleteIcon.setVisibility(View.INVISIBLE);
      if (position < mCurrentNum) {
        viewTag.icon.setVisibility(View.VISIBLE);
        viewTag.name.setVisibility(View.VISIBLE);
      } else if (position == mCurrentNum) {
        viewTag = (ItemViewTag) convertView.getTag();
        viewTag.icon.setImageResource(R.drawable.chat_detail_add);
        viewTag.icon.setVisibility(View.VISIBLE);
        viewTag.name.setVisibility(View.INVISIBLE);

        // 设置删除群成员按钮
      } else if (position == mCurrentNum + 1) {
        if (mIsCreator && mCurrentNum > 1) {
          viewTag = (ItemViewTag) convertView.getTag();
          viewTag.icon.setImageResource(R.drawable.chat_detail_del);
          viewTag.icon.setVisibility(View.VISIBLE);
          viewTag.name.setVisibility(View.INVISIBLE);
        } else {
          viewTag = (ItemViewTag) convertView.getTag();
          viewTag.icon.setVisibility(View.GONE);
          viewTag.name.setVisibility(View.GONE);
        }
        // 空白项
      } else {
        viewTag = (ItemViewTag) convertView.getTag();
        viewTag.icon.setVisibility(View.INVISIBLE);
        viewTag.name.setVisibility(View.INVISIBLE);
      }
    }

    return convertView;
  }
コード例 #15
0
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder viewHolder;
    if (convertView == null) {
      LayoutInflater inflater = LayoutInflater.from(mContext);
      convertView = inflater.inflate(R.layout.all_member_item, null);
      viewHolder =
          new ViewHolder(
              (CircleImageView) convertView.findViewById(R.id.icon_iv),
              (TextView) convertView.findViewById(R.id.name),
              (CheckBox) convertView.findViewById(R.id.check_box_cb));
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    final UserInfo userInfo = mMemberList.get(position);
    if (mIsDeleteMode) {
      if (position > 0) {
        viewHolder.checkBox.setVisibility(View.VISIBLE);
        viewHolder.checkBox.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (viewHolder.checkBox.isChecked()) {
                  mSelectedList.add(userInfo.getUserName());
                  mSelectMap.put(position, true);
                  addAnimation(viewHolder.checkBox);
                } else {
                  mSelectedList.remove(userInfo.getUserName());
                  mSelectMap.delete(position);
                }
              }
            });
        viewHolder.checkBox.setChecked(mSelectMap.get(position));
      } else {
        viewHolder.checkBox.setVisibility(View.INVISIBLE);
      }

    } else {
      viewHolder.checkBox.setVisibility(View.GONE);
    }

    if (!TextUtils.isEmpty(userInfo.getAvatar())) {
      userInfo.getAvatarBitmap(
          new GetAvatarBitmapCallback() {
            @Override
            public void gotResult(int status, String desc, Bitmap bitmap) {
              if (status == 0) {
                viewHolder.icon.setImageBitmap(bitmap);
              } else {
                viewHolder.icon.setImageResource(R.drawable.head_icon);
                HandleResponseCode.onHandle(mContext, status, false);
              }
            }
          });
    } else {
      viewHolder.icon.setImageResource(R.drawable.head_icon);
    }
    String displayName = userInfo.getNickname();
    if (TextUtils.isEmpty(displayName)) {
      viewHolder.displayName.setText(userInfo.getUserName());
    } else {
      viewHolder.displayName.setText(displayName);
    }

    return convertView;
  }