阅读Contact和Notes并添加注释

pull/2/head
HZXhuang 2 years ago
parent 7f634ec7d8
commit 74a663ea95

@ -1 +0,0 @@
Subproject commit d48acec0b0cae90d95d289c02545fcac5e7a1485

@ -25,8 +25,14 @@ import android.util.Log;
import java.util.HashMap;
/**
* @author hzx
* 1.0
* 2023/10/28
* Contact
*/
public class Contact {
private static HashMap<String, String> sContactCache;
private static HashMap<String, String> sContactCache; // 缓存联系人号码和姓名的映射关系
private static final String TAG = "Contact";
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
@ -34,19 +40,29 @@ public class Contact {
+ " AND " + Data.RAW_CONTACT_ID + " IN "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
+ " WHERE min_match = '+')"; // 查询条件
/**
*
* @param context
* @param phoneNumber
* @return
*/
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
// 初始化map缓存
sContactCache = new HashMap<String, String>();
}
if(sContactCache.containsKey(phoneNumber)) {
// 如果map缓存中的键包含要查询的电话号码直接从缓存中读取
return sContactCache.get(phoneNumber);
}
// 获取电话号码的min-match然后替换原始查询条件中的“+”
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 从联系人内容提供者中查询联系人信息
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
@ -54,18 +70,22 @@ 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) {
// 数组越界异常从cursor取不到指定字段输出日志信息
Log.e(TAG, " Cursor get string error " + e.toString());
return null;
} finally {
cursor.close();
}
} else {
// 查询结果为空,输出日志信息
Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null;
}

@ -17,12 +17,19 @@
package net.micode.notes.data;
import android.net.Uri;
/**
* @author hzx
* 1.0
* 2023/10/28
* Notes 便便
*/
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2;
public static final int TYPE_NOTE = 0; // 便签标识
public static final int TYPE_FOLDER = 1; // 文件夹标识
public static final int TYPE_SYSTEM = 2; // 系统标识
/**
* Following IDs are system folders' identifiers
@ -30,10 +37,10 @@ public class Notes {
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
*/
public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1;
public static final int ID_CALL_RECORD_FOLDER = -2;
public static final int ID_TRASH_FOLER = -3;
public static final int ID_ROOT_FOLDER = 0; // 默认的文件夹
public static final int ID_TEMPARAY_FOLDER = -1; // 临时文件夹
public static final int ID_CALL_RECORD_FOLDER = -2; // 调用记录文件夹
public static final int ID_TRASH_FOLER = -3; // 垃圾文件夹
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";
public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id";
@ -46,42 +53,51 @@ public class Notes {
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
/**
*
*/
public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
}
/**
* Uri to query all notes and folders
* 便Uri
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
* Uri to query data
* Uri
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
/**
* 便
*/
public interface NoteColumns {
/**
* The unique ID for a row
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String ID = "_id";
/**
* The parent's id for note or folder
* 便ID
* <P> Type: INTEGER (long) </P>
*/
public static final String PARENT_ID = "parent_id";
/**
* Created data for note or folder
* 便
* <P> Type: INTEGER (long) </P>
*/
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
*
* <P> Type: INTEGER (long) </P>
*/
public static final String MODIFIED_DATE = "modified_date";
@ -95,24 +111,28 @@ public class Notes {
/**
* Folder's name or text content of note
* 便
* <P> Type: TEXT </P>
*/
public static final String SNIPPET = "snippet";
/**
* Note's widget id
* 便ID
* <P> Type: INTEGER (long) </P>
*/
public static final String WIDGET_ID = "widget_id";
/**
* Note's widget type
* 便
* <P> Type: INTEGER (long) </P>
*/
public static final String WIDGET_TYPE = "widget_type";
/**
* Note's background color's id
* 便ID
* <P> Type: INTEGER (long) </P>
*/
public static final String BG_COLOR_ID = "bg_color_id";
@ -120,127 +140,149 @@ public class Notes {
/**
* For text note, it doesn't has attachment, for multi-media
* note, it has at least one attachment
*
* <P> Type: INTEGER </P>
*/
public static final String HAS_ATTACHMENT = "has_attachment";
/**
* Folder's count of notes
* 便
* <P> Type: INTEGER (long) </P>
*/
public static final String NOTES_COUNT = "notes_count";
/**
* The file type: folder or note
* 便
* <P> Type: INTEGER </P>
*/
public static final String TYPE = "type";
/**
* The last sync id
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String SYNC_ID = "sync_id";
/**
* Sign to indicate local modified or not
*
* <P> Type: INTEGER </P>
*/
public static final String LOCAL_MODIFIED = "local_modified";
/**
* Original parent id before moving into temporary folder
* 便ID
* <P> Type : INTEGER </P>
*/
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/**
* The gtask id
* ID
* <P> Type : TEXT </P>
*/
public static final String GTASK_ID = "gtask_id";
/**
* The version code
*
* <P> Type : INTEGER (long) </P>
*/
public static final String VERSION = "version";
}
/**
*
*/
public interface DataColumns {
/**
* The unique ID for a row
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String ID = "_id";
/**
* The MIME type of the item represented by this row.
* MIME
* <P> Type: Text </P>
*/
public static final String MIME_TYPE = "mime_type";
/**
* The reference id to note that this data belongs to
* 便ID
* <P> Type: INTEGER (long) </P>
*/
public static final String NOTE_ID = "note_id";
/**
* Created data for note or folder
*
* <P> Type: INTEGER (long) </P>
*/
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
*
* <P> Type: INTEGER (long) </P>
*/
public static final String MODIFIED_DATE = "modified_date";
/**
* Data's content
*
* <P> Type: TEXT </P>
*/
public static final String CONTENT = "content";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* integer data type
*
* <P> Type: INTEGER </P>
*/
public static final String DATA1 = "data1";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* integer data type
* <P> Type: INTEGER </P>
*/
public static final String DATA2 = "data2";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* TEXT data type
*
* <P> Type: TEXT </P>
*/
public static final String DATA3 = "data3";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* TEXT data type
* <P> Type: TEXT </P>
*/
public static final String DATA4 = "data4";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* TEXT data type
* <P> Type: TEXT </P>
*/
public static final String DATA5 = "data5";
}
/**
* 便
*/
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
@ -250,16 +292,29 @@ public class Notes {
public static final int MODE_CHECK_LIST = 1;
/**
*
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
/**
*
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
/**
* Uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
/**
* 便
*/
public static final class CallNote implements DataColumns {
/**
* Call date for this record
*
* <P> Type: INTEGER (long) </P>
*/
public static final String CALL_DATE = DATA1;
@ -270,10 +325,19 @@ public class Notes {
*/
public static final String PHONE_NUMBER = DATA3;
/**
*
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";
/**
*
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
/**
* Uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
}
}

Loading…
Cancel
Save