Java 类android.provider.Contacts.Phones 实例源码

项目:CSipSimple    文件:ContactsUtils3.java   
public List<Phone> getPhoneNumbers(Context ctxt, long contactId, int flags) {
    ArrayList<Phone> phones = new ArrayList<Phone>();
    if ((flags & ContactsWrapper.URI_NBR) > 0) {
        Cursor pCur = ctxt.getContentResolver().query(
                Phones.CONTENT_URI,
                null,
                Phones.PERSON_ID + " = ?",
                new String[] {
                    Long.toString(contactId)
                }, null);
        while (pCur.moveToNext()) {
            phones.add(new Phone(
                    pCur.getString(pCur.getColumnIndex(Phones.NUMBER))
                    , pCur.getString(pCur.getColumnIndex(Phones.TYPE))
                    ));
        }
        pCur.close();
    }
    return (phones);
}
项目:CSipSimple    文件:ContactsUtils3.java   
@Override
public void bindContactPhoneView(View view, Context context, Cursor cursor) {

    // Get values
    String value = cursor.getString(cursor.getColumnIndex(Phones.NUMBER));
    String displayName = cursor.getString(cursor.getColumnIndex(Phones.DISPLAY_NAME));
    Long peopleId = cursor.getLong(cursor.getColumnIndex(Phones.PERSON_ID));
    Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, peopleId);
    Bitmap bitmap = getContactPhoto(context, uri, false, R.drawable.ic_contact_picture_holo_dark);

    // Get views
    TextView tv = (TextView) view.findViewById(R.id.name);
    TextView sub = (TextView) view.findViewById(R.id.number);
    TextView label = (TextView) view.findViewById(R.id.label);
    ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo);

    // Bind
    label.setVisibility(View.GONE);
    view.setTag(value);
    tv.setText(displayName);
    sub.setText(value);
    imageView.setImageBitmap(bitmap);        
}
项目:buildAPKsApps    文件:RecipientsAdapter.java   
@Override
public final void bindView(View view, Context context, Cursor cursor) {
    TextView name = (TextView) view.findViewById(R.id.name);
    name.setText(cursor.getString(NAME_INDEX));

    TextView label = (TextView) view.findViewById(R.id.label);
    int type = cursor.getInt(TYPE_INDEX);
    if (cursor.getColumnCount() == EMAIL_COLUMN_COUNT) {
        int kind = cursor.getInt(KIND_INDEX);
        label.setText(ContactMethods.getDisplayLabel(
                mContext, kind, type, cursor.getString(LABEL_INDEX)));
    } else {
        label.setText(Phones.getDisplayLabel(mContext, type, cursor.getString(LABEL_INDEX)));
    }

    TextView number = (TextView) view.findViewById(R.id.number);
    number.setText("(" + cursor.getString(NUMBER_INDEX) + ")");
}
项目:phonty    文件:Caller.java   
boolean isExcludedType(Vector<Integer> vExTypesCode, String sNumber, Context oContext)
  {
    Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, sNumber);
    final String[] PHONES_PROJECTION = new String[] 
   {
       People.Phones.NUMBER, // 0
       People.Phones.TYPE, // 1
   };
      Cursor phonesCursor = oContext.getContentResolver().query(contactRef, PHONES_PROJECTION, null, null,
              null);
if (phonesCursor != null) 
      {                     
           while (phonesCursor.moveToNext()) 
          {                             
              final int type = phonesCursor.getInt(1);                
              if(vExTypesCode.contains(Integer.valueOf(type)))
                return true;        
          }
          phonesCursor.close();
      }
return false;
  }
项目:CSipSimple    文件:ContactsUtils3.java   
@Override
public Cursor getContactsPhones(Context ctxt, CharSequence constraint) {
    Uri uri = Phones.CONTENT_URI;
    String selection = String.format("%s LIKE ? OR %s LIKE ?", Phones.NUMBER,
            Phones.DISPLAY_NAME);
    String[] selectionArgs = new String[] {
            constraint + "%", "%" + constraint + "%"
    };
    Cursor resCursor = ctxt.getContentResolver().query(uri, PROJECTION_PHONE, selection, selectionArgs,
            Phones.DISPLAY_NAME + " ASC");
    return resCursor;
}
项目:buildAPKsApps    文件:RecipientsAdapter.java   
@Override
public final CharSequence convertToString(Cursor cursor) {
    String name = cursor.getString(RecipientsAdapter.NAME_INDEX);
    int type = cursor.getInt(RecipientsAdapter.TYPE_INDEX);
    String number = cursor.getString(RecipientsAdapter.NUMBER_INDEX).trim();

    String label = cursor.getString(RecipientsAdapter.LABEL_INDEX);
    CharSequence displayLabel = Phones.getDisplayLabel(mContext, type, label);

    if (number.length() == 0) {
        return number;
    }

    SpannableString out = new SpannableString(RecipientList.Recipient.buildNameAndNumber(name, number));
    int len = out.length();

    if (!TextUtils.isEmpty(name)) {
        out.setSpan(new Annotation("name", name), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        out.setSpan(new Annotation("name", number), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    String person_id = cursor.getString(RecipientsAdapter.PERSON_ID_INDEX);
    out.setSpan(new Annotation("person_id", person_id), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    out.setSpan(new Annotation("label", displayLabel.toString()), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    out.setSpan(new Annotation("number", number), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return out;
}
项目:apps-for-android    文件:CreateShortcutActivity.java   
/**
 * Returns an Intent describing a direct text message shortcut.
 *
 * @param result The result from the phone number picker
 * @return an Intent describing a phone number shortcut
 */
private Intent generatePhoneShortcut(Intent result, int actionResId, String scheme, String action) {
    Uri phoneUri = result.getData();
    long personId = 0;
    String name = null;
    String number = null;
    int type;
    Cursor cursor = getContentResolver().query(phoneUri,
            new String[] { Phones.PERSON_ID, Phones.DISPLAY_NAME, Phones.NUMBER, Phones.TYPE },
            null, null, null);
    try {
        cursor.moveToFirst();
        personId = cursor.getLong(0);
        name = cursor.getString(1);
        number = cursor.getString(2);
        type = cursor.getInt(3);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    Intent intent = new Intent();
    Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, personId);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
            generatePhoneNumberIcon(personUri, type, actionResId));

    // Make the URI a direct tel: URI so that it will always continue to work
    phoneUri = Uri.fromParts(scheme, number, null);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(action, phoneUri));
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    return intent;
}
项目:AnyCut    文件:CreateShortcutActivity.java   
/**
 * Returns an Intent describing a direct text message shortcut.
 *
 * @param result The result from the phone number picker
 * @return an Intent describing a phone number shortcut
 */
private Intent generatePhoneShortcut(Intent result, int actionResId, String scheme, String action) {
    Uri phoneUri = result.getData();
    long personId = 0;
    String name = null;
    String number = null;
    int type;
    Cursor cursor = getContentResolver().query(phoneUri,
            new String[] { Phones.PERSON_ID, Phones.DISPLAY_NAME, Phones.NUMBER, Phones.TYPE },
            null, null, null);
    try {
        cursor.moveToFirst();
        personId = cursor.getLong(0);
        name = cursor.getString(1);
        number = cursor.getString(2);
        type = cursor.getInt(3);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    Intent intent = new Intent();
    Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, personId);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
            generatePhoneNumberIcon(personUri, type, actionResId));

    // Make the URI a direct tel: URI so that it will always continue to work
    phoneUri = Uri.fromParts(scheme, number, null);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(action, phoneUri));
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    return intent;
}
项目:CSipSimple    文件:ContactsUtils3.java   
@Override
public CallerInfo findCallerInfo(Context ctxt, String number) {
    Uri searchUri = Uri
            .withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(number));

    CallerInfo callerInfo = new CallerInfo();

    Cursor cursor = ctxt.getContentResolver().query(searchUri, null, null, null, null);
    if (cursor != null) {
        try {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                ContentValues cv = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(cursor, cv);
                callerInfo.contactExists = true;
                if (cv.containsKey(Phones.DISPLAY_NAME)) {
                    callerInfo.name = cv.getAsString(Phones.DISPLAY_NAME);
                }

                callerInfo.phoneNumber = cv.getAsString(Phones.NUMBER);

                if (cv.containsKey(Phones.TYPE)
                        && cv.containsKey(Phones.LABEL)) {
                    callerInfo.numberType = cv.getAsInteger(Phones.TYPE);
                    callerInfo.numberLabel = cv.getAsString(Phones.LABEL);
                    callerInfo.phoneLabel = Phones.getDisplayLabel(ctxt,
                            callerInfo.numberType, callerInfo.numberLabel)
                            .toString();
                }

                if (cv.containsKey(Phones.PERSON_ID)) {
                    callerInfo.personId = cv.getAsLong(Phones.PERSON_ID);
                    callerInfo.contactContentUri = ContentUris.withAppendedId(
                            People.CONTENT_URI, callerInfo.personId);
                }

                if (cv.containsKey(Phones.CUSTOM_RINGTONE)) {
                    String ringtoneUriString = cv.getAsString(Phones.CUSTOM_RINGTONE);
                    if (!TextUtils.isEmpty(ringtoneUriString)) {
                        callerInfo.contactRingtoneUri = Uri.parse(ringtoneUriString);
                    }
                }

                if (callerInfo.name != null && callerInfo.name.length() == 0) {
                    callerInfo.name = null;
                }

            }

        } catch (Exception e) {
            Log.e(THIS_FILE, "Exception while retrieving cursor infos", e);
        } finally {
            cursor.close();
        }

    }

    // if no query results were returned with a viable number,
    // fill in the original number value we used to query with.
    if (TextUtils.isEmpty(callerInfo.phoneNumber)) {
        callerInfo.phoneNumber = number;
    }

    return callerInfo;
}
项目:buildAPKsApps    文件:RecipientsAdapter.java   
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
    String wherePhone = null;
    String whereEmail = null;
    String phone = "";
    String cons = null;

    if (constraint != null) {
        cons = constraint.toString();

        if (usefulAsDigits(cons)) {
            phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
            if (phone.equals(cons)) {
                phone = "";
            } else {
                phone = phone.trim();
            }
        }

        String filter = DatabaseUtils.sqlEscapeString(cons + '%');
        String filterLastName = DatabaseUtils.sqlEscapeString("% " + cons + '%');

        StringBuilder s = new StringBuilder();
        s.append("((name LIKE ");
        s.append(filter);
        s.append(") OR (name LIKE ");
        s.append(filterLastName);
        s.append(") OR (REPLACE(REPLACE(REPLACE(REPLACE(number, ' ', ''), '(', ''), ')', ''), '-', '') LIKE ");
        s.append(filter);
        s.append(")) AND type = ");
        s.append(Phones.TYPE_MOBILE);
        wherePhone = s.toString();

        /*s.delete(0, s.length()); // Clear the string builder.
        s.append("((name LIKE ");
        s.append(filter);
        s.append(") OR (data LIKE ");
        s.append(filter);
        s.append(")) AND kind = ");
        s.append(Contacts.KIND_EMAIL);
        whereEmail = s.toString();*/
    }

    Cursor phoneCursor = SqliteWrapper.query(mContext, mContentResolver,
            Phones.CONTENT_URI, PROJECTION_PHONE, wherePhone, null, SORT_ORDER);
    /*Cursor emailCursor = SqliteWrapper.query(mContext, mContentResolver,
            ContactMethods.CONTENT_URI, PROJECTION_EMAIL, whereEmail, null, SORT_ORDER);*/

    if (phone.length() > 0) {
        ArrayList result = new ArrayList();
        result.add(Integer.valueOf(-1));                    // ID
        result.add(Long.valueOf(-1));                       // PERSON_ID
        result.add(Integer.valueOf(Phones.TYPE_CUSTOM));    // TYPE
        result.add(phone);                                  // NUMBER

        /*
         * The "\u00A0" keeps Phones.getDisplayLabel() from deciding
         * to display the default label ("Home") next to the transformation
         * of the letters into numbers.
         */
        result.add("\u00A0");                               // LABEL
        result.add(cons);                                   // NAME

        ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
        wrap.add(result);

        ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);

        return new MergeCursor(new Cursor[] { translated, phoneCursor/*, emailCursor*/ });
    } else {
        return new MergeCursor(new Cursor[] { phoneCursor/*, emailCursor*/ });
    }
}
项目:fnzy    文件:CursorToMessage.java   
@TargetApi(Build.VERSION_CODES.ECLAIR)
private static String[] getPhoneProjection() {
    return NEW_CONTACT_API  ?
          new String[] { Contacts._ID, Contacts.DISPLAY_NAME } :
          new String[] { Phones.PERSON_ID, People.NAME, Phones.NUMBER };
}