From b45742fe80cbd3093b162b24aaa0354e5427ada6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E4=B8=80=E9=98=B3?= <3262632335@qq.com> Date: Thu, 6 Apr 2023 22:36:24 +0800 Subject: [PATCH] 123 --- .../java/net/micode/notes/data/Contact.java | 32 +++++++++---------- 测试.txt | 1 - 2 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 测试.txt diff --git a/app/src/main/java/net/micode/notes/data/Contact.java b/app/src/main/java/net/micode/notes/data/Contact.java index 1954ea2..6ff77c6 100644 --- a/app/src/main/java/net/micode/notes/data/Contact.java +++ b/app/src/main/java/net/micode/notes/data/Contact.java @@ -25,14 +25,14 @@ import android.util.Log; import java.util.HashMap; -// ContactÀàÓÃÓÚ²éѯÁªÏµÈËÐÅÏ¢ +// Contact�����ڲ�ѯ��ϵ����Ϣ public class Contact { - // ÓÃÓÚ»º´æÒѲéѯµ½µÄÁªÏµÈËÃû³Æ + // ���ڻ����Ѳ�ѯ������ϵ������ private static HashMap sContactCache; - // ÈÕÖ¾±êÇ© + // ��־��ǩ private static final String TAG = "Contact"; - // ²éѯÁªÏµÈ˵ÄÑ¡ÔñÌõ¼þ + // ��ѯ��ϵ�˵�ѡ������ private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER + ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Data.RAW_CONTACT_ID + " IN " @@ -40,22 +40,22 @@ public class Contact { + " FROM phone_lookup" + " WHERE min_match = '+')"; - // ¸ù¾Ýµç»°ºÅÂë»ñÈ¡ÁªÏµÈËÃû³ÆµÄ·½·¨ + // ���ݵ绰�����ȡ��ϵ�����Ƶķ��� public static String getContact(Context context, String phoneNumber) { - // Èç¹û»º´æÎª¿Õ£¬Ôò´´½¨Ò»¸öеÄHashMap + // �������Ϊ�գ��ò´´½ï¿½Ò»ï¿½ï¿½ï¿½Âµï¿½HashMap if(sContactCache == null) { sContactCache = new HashMap(); } - // Èç¹û»º´æÖÐÒÑ´æÔڸõ绰ºÅÂëµÄÁªÏµÈË£¬ÔòÖ±½Ó·µ»ØÆäÃû³Æ + // ����������Ѵ��ڸõ绰�������ϵ�ˣ���ֱ�ӷ��������� if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } - // Ìæ»»CALLER_ID_SELECTIONÖеÄ"+"ΪphoneNumberµÄ×îСƥÅäÐÎʽ + // �滻CALLER_ID_SELECTION�е�"+"ΪphoneNumber����Сƥ����ʽ String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); - // ²éѯÁªÏµÈËÐÅÏ¢ + // ��ѯ��ϵ����Ϣ Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, @@ -63,27 +63,27 @@ public class Contact { new String[] { phoneNumber }, null); - // Èç¹û²éѯ½á¹û²»Îª¿ÕÇÒÓнá¹û£¬Ôò»ñÈ¡ÁªÏµÈËÃû³Æ + // �����ѯ�����Ϊ�����н�������ȡ��ϵ������ if (cursor != null && cursor.moveToFirst()) { try { String name = cursor.getString(0); - // ½«ÁªÏµÈËÃû³Æ´æÈ뻺´æ + // ����ϵ�����ƴ��뻺�� sContactCache.put(phoneNumber, name); - // ·µ»ØÁªÏµÈËÃû³Æ + // ������ϵ������ return name; } catch (IndexOutOfBoundsException e) { - // »ñÈ¡ÁªÏµÈËÃû³Æ³ö´í£¬¼Ç¼ÈÕÖ¾²¢·µ»Ønull + // ��ȡ��ϵ�����Ƴ�������¼��־������null Log.e(TAG, " Cursor get string error " + e.toString()); return null; } finally { - // ¹Ø±ÕÓαê + // �ر��α� cursor.close(); } } else { - // ²éѯ½á¹ûΪ¿Õ£¬¼Ç¼ÈÕÖ¾²¢·µ»Ønull + // ��ѯ���Ϊ�գ���¼��־������null Log.d(TAG, "No contact matched with number:" + phoneNumber); return null; } } } -/*Õâ¸öÀàÖ÷ÒªÓÃÓÚ¸ù¾Ýµç»°ºÅÂë²éѯÁªÏµÈËÃû³Æ¡£ÔÚ²éѯ¹ý³ÌÖУ¬»á½«²éѯµ½µÄÁªÏµÈËÃû³Æ»º´æÔÚÒ»¸öHashMapÖУ¬ÒÔ±ãÓÚÏ´βéѯʱֱ½Ó´Ó»º´æÖлñÈ¡¡£*/ \ No newline at end of file +/*�������Ҫ���ڸ��ݵ绰�����ѯ��ϵ�����ơ��ڲ�ѯ�����У��Ὣ��ѯ������ϵ�����ƻ�����һ��HashMap�У��Ա����´β�ѯʱֱ�Ӵӻ����л�ȡ��*/ \ No newline at end of file diff --git a/测试.txt b/测试.txt deleted file mode 100644 index 61de0ed..0000000 --- a/测试.txt +++ /dev/null @@ -1 +0,0 @@ -测试 \ No newline at end of file