Пример #1
0
  @Override
  protected void setListener() {
    try {
      Collection<HostedRoom> hostedrooms =
          MultiUserChat.getHostedRooms(conn, "conference.wanglq.com");
      hostedRooms = new ArrayList<HostedRoom>();
      for (HostedRoom hostedroom : hostedrooms) {
        Log.i(Tag, hostedroom.getJid());
        hostedRooms.add(hostedroom);
      }
      /** 为listview设置adapter */
      conferencesLV.setAdapter(
          new BaseAdapter() {

            public View getView(int position, View convertView, ViewGroup parent) {
              // TODO Auto-generated method stub
              View view = View.inflate(getApplicationContext(), R.layout.conferencelist, null);
              TextView conferenceJidTV = (TextView) view.findViewById(R.id.conferenceJidTV);
              TextView conferenceNameTV = (TextView) view.findViewById(R.id.conferenceNameTV);
              HostedRoom hostedroom = hostedRooms.get(position);
              conferenceJidTV.setText(hostedroom.getJid());
              conferenceNameTV.setText(hostedroom.getName());
              return view;
            }

            public long getItemId(int position) {
              return position;
            }

            public Object getItem(int position) {
              return hostedRooms.get(position);
            }

            public int getCount() {
              return hostedRooms.size();
            }
          });

      /** 为listview设置点击事件 */
      conferencesLV.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              Intent intent = new Intent(GroupActivity.this, conferenceActivity.class);
              intent.putExtra("jid", hostedRooms.get(position).getJid());
              startActivity(intent);
            }
          });
    } catch (XMPPException e) {
      e.printStackTrace();
    }
  }
  /**
   * 获取服务器上所有会议室
   *
   * @return
   * @throws org.jivesoftware.smack.XMPPException
   */
  public static List<FriendRooms> getConferenceRoom(ImConnection talkConnection)
      throws XMPPException {
    if (talkConnection == null) return null;
    XMPPConnection connection = talkConnection.getXMPPConnection();
    if (connection == null) return null;
    List<FriendRooms> list = new ArrayList<FriendRooms>();
    new ServiceDiscoveryManager(connection);
    if (!MultiUserChat.getHostedRooms(connection, connection.getServiceName()).isEmpty()) {
      for (HostedRoom k : MultiUserChat.getHostedRooms(connection, connection.getServiceName())) {

        for (HostedRoom j : MultiUserChat.getHostedRooms(connection, k.getJid())) {
          RoomInfo info2 = MultiUserChat.getRoomInfo(connection, j.getJid());
          if (j.getJid().indexOf("@") > 0) {
            FriendRooms friendrooms = new FriendRooms();
            friendrooms.setName(j.getName()); // 聊天室的名称
            friendrooms.setJid(j.getJid()); // 聊天室JID
            friendrooms.setOccupants(info2.getOccupantsCount()); // 聊天室中占有者数量
            friendrooms.setDescription(info2.getDescription()); // 聊天室的描述
            friendrooms.setSubject(info2.getSubject()); // 聊天室的主题
            list.add(friendrooms);
          }
        }
      }
    }
    return list;
  }