From 6a3195b72af8d7942c33fc814c4a075ae2177f06 Mon Sep 17 00:00:00 2001 From: 19960030627 Date: Fri, 14 Apr 2023 14:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=81=BFnote=E7=B1=BB=E5=92=8Ccontact?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/net/micode/notes/data/Contact.java | 19 ++++ .../java/net/micode/notes/model/Note.java | 98 +++++++++++++++++++ local.properties | 7 +- 3 files changed, 121 insertions(+), 3 deletions(-) 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 d97ac5d..2061a61 100644 --- a/app/src/main/java/net/micode/notes/data/Contact.java +++ b/app/src/main/java/net/micode/notes/data/Contact.java @@ -25,9 +25,20 @@ import android.util.Log; import java.util.HashMap; +/** + * change + */ + + public class Contact { + /** + * 联系人 + */ private static HashMap 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 + "'" @@ -36,6 +47,13 @@ public class Contact { + " FROM phone_lookup" + " WHERE min_match = '+')"; + /** + * 获取联系人 + * @param context + * @param phoneNumber + * @return + */ + public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); @@ -47,6 +65,7 @@ public class Contact { String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); + Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, diff --git a/app/src/main/java/net/micode/notes/model/Note.java b/app/src/main/java/net/micode/notes/model/Note.java index 6706cf6..5f72ebe 100644 --- a/app/src/main/java/net/micode/notes/model/Note.java +++ b/app/src/main/java/net/micode/notes/model/Note.java @@ -35,6 +35,9 @@ import java.util.ArrayList; public class Note { + /** + *private ContentValues mNoteDiffValues; + */ private ContentValues mNoteDiffValues; private NoteData mNoteData; private static final String TAG = "Note"; @@ -50,7 +53,14 @@ public class Note { values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); values.put(NoteColumns.LOCAL_MODIFIED, 1); values.put(NoteColumns.PARENT_ID, folderId); + /** + * 将数据写入数据库表格 + */ Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); + /** + * ContentResolver()主要是实现外部应用对ContentProvider中的数据 + * 进行添加、删除、修改和查询操作 + */ long noteId = 0; try { @@ -59,6 +69,9 @@ public class Note { Log.e(TAG, "Get note id error :" + e.toString()); noteId = 0; } + /** + * try-catch异常处理 + */ if (noteId == -1) { throw new IllegalStateException("Wrong note id:" + noteId); } @@ -70,36 +83,81 @@ public class Note { mNoteData = new NoteData(); } + /** + * 定义两个变量用来存储便签的数据,一个存储便签属性,一个存储便签内容 + * @param key + * @param value + */ + public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + /** + * 设置数据库表格的标签属性数据 + * @param key + * @param value + */ + public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } + /** + * 设置数据库表格的标签文本内容的数据 + * @param id + */ + public void setTextDataId(long id) { mNoteData.setTextDataId(id); } + /** + * 设置文本数据的ID + * @return + */ + public long getTextDataId() { return mNoteData.mTextDataId; } + /** + * 得到文本数据的ID + * @param id + */ + public void setCallDataId(long id) { mNoteData.setCallDataId(id); } + /** + * 设置电话号码数据的ID + * @param key + * @param value + */ + public void setCallData(String key, String value) { mNoteData.setCallData(key, value); } + /** + * 得到电话号码数据的ID + * @return + */ + public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } + /** + * 判断是否是本地修改 + * @param context + * @param noteId + * @return + */ + public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); @@ -130,14 +188,27 @@ public class Note { return true; } + /** + * 判断数据是否同步 + */ + private class NoteData { + /** + * 定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据 + */ private long mTextDataId; private ContentValues mTextDataValues; + /** + * 文本数据 + */ private long mCallDataId; private ContentValues mCallDataValues; + /** + * 电话号码数据 + */ private static final String TAG = "NoteData"; @@ -148,6 +219,11 @@ public class Note { mCallDataId = 0; } + /** + * 下面是上述几个函数的具体实现方式 + * @return + */ + boolean isLocalModified() { return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; } @@ -178,6 +254,13 @@ public class Note { mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + /** + * 下面函数的作用是将新的数据通过Uri的操作存储到数据库 + * @param context + * @param noteId + * @return + */ + Uri pushIntoContentResolver(Context context, long noteId) { /** * Check for safety @@ -185,9 +268,15 @@ public class Note { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); } + /** + * 判断数据是否合法 + */ ArrayList operationList = new ArrayList(); ContentProviderOperation.Builder builder = null; + /** + * 数据库的操作列表 + */ if(mTextDataValues.size() > 0) { mTextDataValues.put(DataColumns.NOTE_ID, noteId); @@ -210,6 +299,9 @@ public class Note { } mTextDataValues.clear(); } + /** + * 把文本数据存入DataColums + */ if(mCallDataValues.size() > 0) { mCallDataValues.put(DataColumns.NOTE_ID, noteId); @@ -232,6 +324,9 @@ public class Note { } mCallDataValues.clear(); } + /** + * 把电话号码数据存入DataColumns + */ if (operationList.size() > 0) { try { @@ -247,6 +342,9 @@ public class Note { return null; } } + /** + * 存储过程中的异常处理 + */ return null; } } diff --git a/local.properties b/local.properties index 5356a8c..0cf8b6d 100644 --- a/local.properties +++ b/local.properties @@ -2,6 +2,7 @@ # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. -# -#Sun Mar 26 21:27:32 CST 2023 -sdk.dir=C\:\\Users\\MikkoAyaka\\AppData\\Local\\Android\\Sdk \ No newline at end of file +# For customization when using a Version Control System, please read the +# header note. +#Fri Mar 31 16:17:52 CST 2023 +sdk.dir=C\:\\Users\\13474\\AppData\\Local\\Android\\Sdk