@Override
 public String getSort() {
   // TODO Auto-generated method stub
   CharacterParser chp = getCharacter();
   if (getSortContent() == null || getSortContent().length() == 0) {
     return "#";
   }
   String phead = chp.getSelling(getSortContent()).substring(0, 1).toUpperCase();
   if (phead.matches("[A-Z]")) {
     return phead;
   }
   return "#";
 }
Esempio n. 2
0
 /**
  * 联系人的适配器,联系人列表和名片功能会用到,isContact来区分
  *
  * @param context
  * @param isContact
  */
 public ContactAdapter(Context context, boolean isContact) {
   mContext = context;
   mIsContact = isContact;
   mContentResolver = context.getContentResolver();
   //	mIsShowOffline = PreferenceUtils.getPrefBoolean(mContext, PreferenceConstants.SHOW_OFFLINE,
   // true);
   mCharacterParser = CharacterParser.getInstance();
   mContactList = queryData("friends");
 }
Esempio n. 3
0
  private List<ContactSortModel> queryData(String groupname) {
    // mSortList = new ArrayList<SortModel>();
    if (mContactList == null) {
      mContactList = new ArrayList<ContactSortModel>();
    } else {
      mContactList.clear();
    }

    List<Roster> rosters = getRosters(groupname);

    if (mIsContact) {
      ContactSortModel sm1 = new ContactSortModel();
      Roster roster = new Roster();
      roster.setAlias("添加好友");
      sm1.setRoster(roster);
      sm1.setSortLetters("@");
      mContactList.add(sm1);

      ContactSortModel sm2 = new ContactSortModel();
      Roster roster2 = new Roster();
      roster2.setAlias("新朋友");
      sm2.setRoster(roster2);
      sm2.setSortLetters("@");
      mContactList.add(sm2);
    }

    for (int i = 0; i < rosters.size(); i++) {
      ContactSortModel sortModel = new ContactSortModel();

      sortModel.setRoster(rosters.get(i));
      // 取roster的alias昵称,并将汉字转换成拼音
      String pinyin = mCharacterParser.getSelling(rosters.get(i).getAlias());
      String sortString = pinyin.substring(0, 1).toUpperCase();

      // 正则表达式,判断首字母是否是英文字母
      if (sortString.matches("[A-Z]")) {
        sortModel.setSortLetters(sortString.toUpperCase());
      } else {
        sortModel.setSortLetters("#");
      }

      mContactList.add(sortModel);
    }

    return filterData(mFilterString, mContactList);
  }
Esempio n. 4
0
  /**
   * 根据输入框中的值来过滤数据并更新ListView
   *
   * @param filterStr
   */
  private List<ContactSortModel> filterData(String filterStr, List<ContactSortModel> contactList) {
    List<ContactSortModel> filterContactList = new ArrayList<ContactSortModel>();

    if (TextUtils.isEmpty(filterStr)) {
      filterContactList = contactList;
    } else {
      filterContactList.clear();
      for (ContactSortModel sortModel : contactList) {
        String alias = sortModel.getRoster().getAlias();
        if (alias.indexOf(filterStr.toString()) != -1
            || mCharacterParser.getSelling(alias).startsWith(filterStr.toString())) {
          filterContactList.add(sortModel);
        }
      }
    }

    // 根据a-z进行排序
    Collections.sort(filterContactList, new PinyinComparator());
    return filterContactList;
    // this.updateListView(filterDateList);
  }