/**
  * 设置hearder属性,方便通讯中对联系人按header分类显示,以及通过右侧ABCD...字母栏快速定位联系人
  *
  * @param username
  * @param user
  */
 private static void setUserHearder(String username, User user) {
   String headerName = null;
   if (!TextUtils.isEmpty(user.getNick())) {
     headerName = user.getNick();
   } else {
     headerName = user.getUsername();
   }
   if (username.equals(Constant.NEW_FRIENDS_USERNAME)) {
     user.setHeader("");
   } else if (Character.isDigit(headerName.charAt(0))) {
     user.setHeader("#");
   } else {
     user.setHeader(
         HanziToPinyin.getInstance()
             .get(headerName.substring(0, 1))
             .get(0)
             .target
             .substring(0, 1)
             .toUpperCase());
     char header = user.getHeader().toLowerCase().charAt(0);
     if (header < 'a' || header > 'z') {
       user.setHeader("#");
     }
   }
 }
Esempio n. 2
0
  /**
   * 获取好友list
   *
   * @return
   */
  public Map<String, User> getContactList() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Map<String, User> users = new HashMap<String, User>();
    if (db.isOpen()) {
      Cursor cursor = db.rawQuery("select * from " + TABLE_NAME /* + " desc" */, null);
      while (cursor.moveToNext()) {
        String username = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_ID));
        String nick = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_NICK));
        String avatar = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_AVATAR));
        User user = new User();
        user.setUsername(username);
        user.setNick(nick);
        user.setAvatar(avatar);
        String headerName = null;
        if (!TextUtils.isEmpty(user.getNick())) {
          headerName = user.getNick();
        } else {
          headerName = user.getUsername();
        }

        if (username.equals(Constant.NEW_FRIENDS_USERNAME)
            || username.equals(Constant.GROUP_USERNAME)) {
          user.setHeader("");
        } else if (Character.isDigit(headerName.charAt(0))) {
          user.setHeader("#");
        } else {
          user.setHeader(
              HanziToPinyin.getInstance()
                  .get(headerName.substring(0, 1))
                  .get(0)
                  .target
                  .substring(0, 1)
                  .toUpperCase());
          char header = user.getHeader().toLowerCase().charAt(0);
          if (header < 'a' || header > 'z') {
            user.setHeader("#");
          }
        }
        users.put(username, user);
      }
      cursor.close();
    }
    return users;
  }
 /**
  * 设置hearder属性,方便通讯中对联系人按header分类显示,以及通过右侧ABCD...字母栏快速定位联系人
  *
  * @param user
  */
 protected void setUserHearder(User user) {
   String headerName = null;
   if (!StringUtil.isEmpty(user.getNickName())) {
     headerName = user.getNickName();
   } else {
     headerName = user.getUserImId();
   }
   if (Character.isDigit(headerName.charAt(0))) {
     user.setHeader("#");
   } else {
     user.setHeader(
         HanziToPinyin.getInstance()
             .get(headerName.substring(0, 1))
             .get(0)
             .target
             .substring(0, 1)
             .toUpperCase());
     char header = user.getHeader().toLowerCase().charAt(0);
     if (header < 'a' || header > 'z') {
       user.setHeader("#");
     }
   }
 }