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; }
protected EditType buildPhoneType(int type) { return new EditType(type, Phone.getTypeLabelResource(type)); }
public void bindView(Context context, View view, Cursor c) { final RecentCallsListItemViews views = (RecentCallsListItemViews) view.getTag(); String number = c.getString(NUMBER_COLUMN_INDEX); String formattedNumber = null; String callerName = c.getString(CALLER_NAME_COLUMN_INDEX); int callerNumberType = c.getInt(CALLER_NUMBERTYPE_COLUMN_INDEX); String callerNumberLabel = c.getString(CALLER_NUMBERLABEL_COLUMN_INDEX); // Store away the number so we can call it directly if you click on the call icon views.callView.setTag(number); // Lookup contacts with this number ContactInfo info = mContactInfo.get(number); if (info == null) { // Mark it as empty and queue up a request to find the name // The db request should happen on a non-UI thread info = ContactInfo.EMPTY; mContactInfo.put(number, info); enqueueRequest(number, c.getPosition(), callerName, callerNumberType, callerNumberLabel); } else if (info != ContactInfo.EMPTY) { // Has been queried // Check if any data is different from the data cached in the // calls db. If so, queue the request so that we can update // the calls db. if (!TextUtils.equals(info.name, callerName) || info.type != callerNumberType || !TextUtils.equals(info.label, callerNumberLabel)) { // Something is amiss, so sync up. enqueueRequest(number, c.getPosition(), callerName, callerNumberType, callerNumberLabel); } // Format and cache phone number for found contact if (info.formattedNumber == null) { info.formattedNumber = formatPhoneNumber(info.number); } formattedNumber = info.formattedNumber; } String name = info.name; int ntype = info.type; String label = info.label; // If there's no name cached in our hashmap, but there's one in the // calls db, use the one in the calls db. Otherwise the name in our // hashmap is more recent, so it has precedence. if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(callerName)) { name = callerName; ntype = callerNumberType; label = callerNumberLabel; // Format the cached call_log phone number formattedNumber = formatPhoneNumber(number); } // Set the text lines and call icon. // Assumes the call back feature is on most of the // time. For private and unknown numbers: hide it. views.callView.setVisibility(View.VISIBLE); if (!TextUtils.isEmpty(name)) { views.line1View.setText(name); views.labelView.setVisibility(View.VISIBLE); // "type" and "label" are currently unused for SIP addresses. CharSequence numberLabel = null; if (!PhoneNumberUtils.isUriNumber(number)) { numberLabel = Phone.getDisplayLabel(context, ntype, label, mLabelArray); } views.numberView.setVisibility(View.VISIBLE); views.numberView.setText(formattedNumber); if (!TextUtils.isEmpty(numberLabel)) { views.labelView.setText(numberLabel); views.labelView.setVisibility(View.VISIBLE); // Zero out the numberView's left margin (see below) ViewGroup.MarginLayoutParams numberLP = (ViewGroup.MarginLayoutParams) views.numberView.getLayoutParams(); numberLP.leftMargin = 0; views.numberView.setLayoutParams(numberLP); } else { // There's nothing to display in views.labelView, so hide it. // We can't set it to View.GONE, since it's the anchor for // numberView in the RelativeLayout, so make it INVISIBLE. // Also, we need to manually *subtract* some left margin from // numberView to compensate for the right margin built in to // labelView (otherwise the number will be indented by a very // slight amount). // TODO: a cleaner fix would be to contain both the label and // number inside a LinearLayout, and then set labelView *and* // its padding to GONE when there's no label to display. views.labelView.setText(null); views.labelView.setVisibility(View.INVISIBLE); ViewGroup.MarginLayoutParams labelLP = (ViewGroup.MarginLayoutParams) views.labelView.getLayoutParams(); ViewGroup.MarginLayoutParams numberLP = (ViewGroup.MarginLayoutParams) views.numberView.getLayoutParams(); // Equivalent to setting android:layout_marginLeft in XML numberLP.leftMargin = -labelLP.rightMargin; views.numberView.setLayoutParams(numberLP); } } else { if (number.equals(CallerInfo.UNKNOWN_NUMBER)) { number = getString(R.string.unknown); views.callView.setVisibility(View.INVISIBLE); } else if (number.equals(CallerInfo.PRIVATE_NUMBER)) { number = getString(R.string.private_num); views.callView.setVisibility(View.INVISIBLE); } else if (number.equals(CallerInfo.PAYPHONE_NUMBER)) { number = getString(R.string.payphone); } else if (PhoneNumberUtils.extractNetworkPortion(number).equals(mVoiceMailNumber)) { number = getString(R.string.voicemail); } else { // Just a raw number, and no cache, so format it nicely number = formatPhoneNumber(number); } views.line1View.setText(number); views.numberView.setVisibility(View.GONE); views.labelView.setVisibility(View.GONE); } long date = c.getLong(DATE_COLUMN_INDEX); // Set the date/time field by mixing relative and absolute times. int flags = DateUtils.FORMAT_ABBREV_RELATIVE; views.dateView.setText( DateUtils.getRelativeTimeSpanString( date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags)); if (views.iconView != null) { int type = c.getInt(CALL_TYPE_COLUMN_INDEX); // Set the icon switch (type) { case Calls.INCOMING_TYPE: views.iconView.setImageDrawable(mDrawableIncoming); break; case Calls.OUTGOING_TYPE: views.iconView.setImageDrawable(mDrawableOutgoing); break; case Calls.MISSED_TYPE: views.iconView.setImageDrawable(mDrawableMissed); break; } } // Listen for the first draw if (mPreDrawListener == null) { mFirst = true; mPreDrawListener = this; view.getViewTreeObserver().addOnPreDrawListener(this); } }
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); }
/** * getCallerInfo given a Cursor. * * @param context the context used to retrieve string constants * @param contactRef the URI to attach to this CallerInfo object * @param cursor the first object in the cursor is used to build the CallerInfo object. * @return the CallerInfo which contains the caller id for the given number. The returned * CallerInfo is null if no number is supplied. */ public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor cursor) { CallerInfo info = new CallerInfo(); info.photoResource = 0; info.phoneLabel = null; info.numberType = 0; info.numberLabel = null; info.cachedPhoto = null; info.isCachedPhotoCurrent = false; info.contactExists = false; if (VDBG) Rlog.v(TAG, "getCallerInfo() based on cursor..."); if (cursor != null) { if (cursor.moveToFirst()) { // TODO: photo_id is always available but not taken // care of here. Maybe we should store it in the // CallerInfo object as well. int columnIndex; // Look for the name columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); if (columnIndex != -1) { info.name = cursor.getString(columnIndex); } // Look for the number columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER); if (columnIndex != -1) { info.phoneNumber = cursor.getString(columnIndex); } // Look for the normalized number columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER); if (columnIndex != -1) { info.normalizedNumber = cursor.getString(columnIndex); } // Look for the label/type combo columnIndex = cursor.getColumnIndex(PhoneLookup.LABEL); if (columnIndex != -1) { int typeColumnIndex = cursor.getColumnIndex(PhoneLookup.TYPE); if (typeColumnIndex != -1) { info.numberType = cursor.getInt(typeColumnIndex); info.numberLabel = cursor.getString(columnIndex); info.phoneLabel = Phone.getDisplayLabel(context, info.numberType, info.numberLabel).toString(); } } // Look for the person_id. columnIndex = getColumnIndexForPersonId(contactRef, cursor); if (columnIndex != -1) { final long contactId = cursor.getLong(columnIndex); if (contactId != 0 && !Contacts.isEnterpriseContactId(contactId)) { info.contactIdOrZero = contactId; if (VDBG) { Rlog.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero); } } } else { // No valid columnIndex, so we can't look up person_id. Rlog.w(TAG, "Couldn't find contact_id column for " + contactRef); // Watch out: this means that anything that depends on // person_id will be broken (like contact photo lookups in // the in-call UI, for example.) } // Contact lookupKey columnIndex = cursor.getColumnIndex(PhoneLookup.LOOKUP_KEY); if (columnIndex != -1) { info.lookupKey = cursor.getString(columnIndex); } // Display photo URI. columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI); if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex)); } else { info.contactDisplayPhotoUri = null; } // look for the custom ringtone, create from the string stored // in the database. columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE); if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { info.contactRingtoneUri = Uri.parse(cursor.getString(columnIndex)); } else { info.contactRingtoneUri = null; } // look for the send to voicemail flag, set it to true only // under certain circumstances. columnIndex = cursor.getColumnIndex(PhoneLookup.SEND_TO_VOICEMAIL); info.shouldSendToVoicemail = (columnIndex != -1) && ((cursor.getInt(columnIndex)) == 1); info.contactExists = true; } cursor.close(); cursor = null; } info.needUpdate = false; info.name = normalize(info.name); info.contactRefUri = contactRef; return info; }
/** * 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); }