本文整理汇总了Java中android.telephony.PhoneNumberUtils.convertKeypadLettersToDigits方法的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumberUtils.convertKeypadLettersToDigits方法的具体用法?Java PhoneNumberUtils.convertKeypadLettersToDigits怎么用?Java PhoneNumberUtils.convertKeypadLettersToDigits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.PhoneNumberUtils
的用法示例。
在下文中一共展示了PhoneNumberUtils.convertKeypadLettersToDigits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCursorForRecipientFilter
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
/***
* If the code below looks shitty to you, that's because it was taken
* directly from the Android source, where shitty code is all you get.
*/
public Cursor getCursorForRecipientFilter(CharSequence constraint,
ContentResolver mContentResolver)
{
final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," +
Contacts.DISPLAY_NAME + "," +
Contacts.Data.IS_SUPER_PRIMARY + " DESC," +
Phone.TYPE;
final String[] PROJECTION_PHONE = {
Phone._ID, // 0
Phone.CONTACT_ID, // 1
Phone.TYPE, // 2
Phone.NUMBER, // 3
Phone.LABEL, // 4
Phone.DISPLAY_NAME, // 5
};
String phone = "";
String cons = null;
if (constraint != null) {
cons = constraint.toString();
if (RecipientsAdapter.usefulAsDigits(cons)) {
phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) {
phone = "";
} else {
phone = phone.trim();
}
}
}
Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
String selection = String.format("%s=%s OR %s=%s OR %s=%s",
Phone.TYPE,
Phone.TYPE_MOBILE,
Phone.TYPE,
Phone.TYPE_WORK_MOBILE,
Phone.TYPE,
Phone.TYPE_MMS);
Cursor phoneCursor = mContentResolver.query(uri,
PROJECTION_PHONE,
null,
null,
SORT_ORDER);
if (phone.length() > 0) {
ArrayList result = new ArrayList();
result.add(Integer.valueOf(-1)); // ID
result.add(Long.valueOf(-1)); // CONTACT_ID
result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE
result.add(phone); // NUMBER
/*
* The "\u00A0" keeps Phone.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 });
} else {
return phoneCursor;
}
}
示例2: runQueryOnBackgroundThread
import android.telephony.PhoneNumberUtils; //导入方法依赖的package包/类
@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*/ });
}
}