private void setQuickContactCursor(Cursor cursor) { if (cursor != null && cursor.moveToFirst()) { nativeContact = new QuickContactDetail(); // contact.contactId = contactId; nativeContact.numbers = new ArrayList<NmsQuickContactActivity.QuickContactPhone>(); do { String mimeType = cursor.getString(cursor.getColumnIndex(Data.MIMETYPE)); if (mimeType.equals(StructuredName.CONTENT_ITEM_TYPE)) { String name = cursor.getString(cursor.getColumnIndex(StructuredName.DISPLAY_NAME)); nativeContact.name = name; } else if (mimeType.equals(Phone.CONTENT_ITEM_TYPE)) { boolean isAdd = true; String number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER)); if (number == null) { continue; } for (int i = 0; i < nativeContact.numbers.size(); ++i) { if (number.equals(nativeContact.numbers.get(i).number)) { isAdd = false; break; } } if (!isAdd) { continue; } QuickContactPhone phone = new QuickContactPhone(); phone.number = number; String lable = Phone.getTypeLabel( getResources(), cursor.getInt(cursor.getColumnIndex(Phone.TYPE)), cursor.getString(cursor.getColumnIndex(Phone.LABEL))) .toString(); phone.isHissage = NmsIpMessageApiNative.nmsIsiSMSNumber(number); if (phone.isHissage) { phone.numberType = lable + this.getText(R.string.STR_NMS_ISMS_ENABLE).toString(); } else { phone.numberType = lable; } nativeContact.numbers.add(phone); } else if (mimeType.equals(Photo.CONTENT_ITEM_TYPE)) { byte[] photoBytes = cursor.getBlob(cursor.getColumnIndex(Photo.PHOTO)); if (photoBytes != null) { nativeContact.avatar = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length); } } } while (cursor.moveToNext()); } if (cursor != null) { cursor.close(); } updateUI(); }
protected void bindPhoneNumber(ContactListItemView view, Cursor cursor) { CharSequence label = null; if (!cursor.isNull(PHONE_TYPE_COLUMN_INDEX)) { final int type = cursor.getInt(PHONE_TYPE_COLUMN_INDEX); final String customLabel = cursor.getString(PHONE_LABEL_COLUMN_INDEX); // TODO cache label = Phone.getTypeLabel(getContext().getResources(), type, customLabel); } view.setLabel(label); view.showData(cursor, PHONE_NUMBER_COLUMN_INDEX); }
private ContactEntry createContactEntryFromCursor(Cursor cursor, int position) { // If the loader was canceled we will be given a null cursor. // In that case, show an empty list of contacts. if (cursor == null || cursor.isClosed() || cursor.getCount() <= position) return null; cursor.moveToPosition(position); long id = cursor.getLong(mIdIndex); String photoUri = cursor.getString(mPhotoUriIndex); String lookupKey = cursor.getString(mLookupIndex); ContactEntry contact = new ContactEntry(); String name = cursor.getString(mNameIndex); contact.name = (name != null) ? name : mResources.getString(R.string.missing_name); contact.status = cursor.getString(mStatusIndex); contact.photoUri = (photoUri != null ? Uri.parse(photoUri) : null); contact.lookupKey = ContentUris.withAppendedId( Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), id); // Set phone number and label if (mDisplayType == DisplayType.STREQUENT_PHONE_ONLY) { int phoneNumberType = cursor.getInt(mPhoneNumberTypeIndex); String phoneNumberCustomLabel = cursor.getString(mPhoneNumberLabelIndex); contact.phoneLabel = (String) Phone.getTypeLabel(mResources, phoneNumberType, phoneNumberCustomLabel); contact.phoneNumber = cursor.getString(mPhoneNumberIndex); } else { // Set presence icon and status message Drawable icon = null; int presence = 0; if (!cursor.isNull(mPresenceIndex)) { presence = cursor.getInt(mPresenceIndex); icon = ContactPresenceIconUtil.getPresenceIcon(mContext, presence); } contact.presenceIcon = icon; String statusMessage = null; if (mStatusIndex != 0 && !cursor.isNull(mStatusIndex)) { statusMessage = cursor.getString(mStatusIndex); } // If there is no status message from the contact, but there was a presence value, // then use the default status message string if (statusMessage == null && presence != 0) { statusMessage = ContactStatusUtil.getStatusString(mContext, presence); } contact.status = statusMessage; } return contact; }
public void refreshSubActions(Context context) { subActions.clear(); subActions.add(ActionManager.getAction(InternalActions.SpeakerphoneAction.id)); subActions.add( new Action() { @Override public String getName() { return "Voicemail"; } @Override public String bulletIcon() { return "bullet_circle.bmp"; } @Override public int performAction(Context context) { Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("voicemail:")); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return InternalApp.BUTTON_USED; } }); final String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER, }; Cursor people = context .getContentResolver() .query( ContactsContract.Contacts.CONTENT_URI, projection, "starred=?", new String[] {"1"}, ContactsContract.Contacts.TIMES_CONTACTED + " DESC"); while (people.moveToNext()) { int idFieldIndex = people.getColumnIndex(ContactsContract.Contacts._ID); final String id = people.getString(idFieldIndex); int nameFieldIndex = people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); final String contact = people.getString(nameFieldIndex); int hasNumberFieldIndex = people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER); if (Integer.parseInt(people.getString(hasNumberFieldIndex)) > 0) { Cursor personNumbers = context .getContentResolver() .query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] {id}, null); if (personNumbers == null) continue; ContainerAction personContainer = null; String prefix = contact + " "; if (personNumbers.getCount() > 1) { personContainer = new ContainerAction() { public String getName() { return contact; } }; subActions.add(personContainer); prefix = ""; } final String namePrefix = prefix; while (personNumbers.moveToNext()) { int phoneFieldIndex = personNumbers.getColumnIndex(Phone.DATA); final String number = personNumbers.getString(phoneFieldIndex); int typeFieldIndex = personNumbers.getColumnIndex(Phone.TYPE); final String type = (String) Phone.getTypeLabel( context.getResources(), personNumbers.getInt(typeFieldIndex), ""); Action numberEntry = new Action() { String title = namePrefix + type + "\n" + number; String uri = "tel:" + number; @Override public String getName() { return title; } @Override public String bulletIcon() { return "bullet_circle.bmp"; } @Override public int performAction(Context context) { Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(uri)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return InternalApp.BUTTON_USED; } }; if (personContainer != null) { personContainer.addSubAction(numberEntry); } else { subActions.add(numberEntry); } } } } people.close(); }
@Override public CharSequence getTypeLabel(Resources res, int type, CharSequence label) { return Phone.getTypeLabel(res, type, label); }
/** * Default return Phone.getTypeLabel(res, type, label); * * @param res * @param type * @param label * @param slotId * @return */ public CharSequence getTypeLabel( Resources res, int type, CharSequence label, int slotId, String commd) { return Phone.getTypeLabel(res, type, label); }