data/Contact.java和data/Notes.java的注释

YuSuhan
2642023818@qq.com 3 years ago
parent ab97a899ba
commit cf538b3af7

@ -25,46 +25,51 @@ import android.util.Log;
import java.util.HashMap;
public class Contact {
public class Contact {//联系人
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
//定义字符串CALLER_ID_SELECTION
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 "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
//获取联系人
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
//查找HasMap中是否有phoneNumber信息
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
//查找数据库中phoneNumber的信息
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
selection,
new String[] { phoneNumber },
null);
//判定查询结果
//moveToFirst()返回第一条
if (cursor != null && cursor.moveToFirst()) {
try {
//找到相关信息
String name = cursor.getString(0);
sContactCache.put(phoneNumber, name);
return name;
//异常
} catch (IndexOutOfBoundsException e) {
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,9 +17,11 @@
package net.micode.notes.data;
import android.net.Uri;
//Notes 类中定义了很多变量这些常量大多都是int型和string型
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
//以下三个常量对NoteColumns.TYPE的值进行设置时会用到
public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2;
@ -54,13 +56,15 @@ public class Notes {
/**
* Uri to query all notes and folders
*/
//定义查询便签和文件夹的指针
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
* Uri to query data
*/
//定义查找数据的指针
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
//定义NoteColumns的常量用于后面创建数据库的表头
public interface NoteColumns {
/**
* The unique ID for a row
@ -166,7 +170,7 @@ public class Notes {
*/
public static final String VERSION = "version";
}
//定义DateColumns的常量用于后面创建数据库的表头
public interface DataColumns {
/**
* The unique ID for a row
@ -239,7 +243,7 @@ public class Notes {
* <P> Type: TEXT </P>
*/
public static final String DATA5 = "data5";
}
} //主要是定义存储便签内容数据的
public static final class TextNote implements DataColumns {
/**
@ -255,7 +259,7 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
}//文本内容的数据结构
public static final class CallNote implements DataColumns {
/**
@ -275,5 +279,5 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
}
}//电话内容的数据结构
}

Loading…
Cancel
Save