From 515cc051ea2a8ab2d3d1533954505e6fd9d1b8c1 Mon Sep 17 00:00:00 2001 From: GenshinGanyu <1437099831@qq.com> Date: Wed, 19 Apr 2023 19:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=AF=B9Note?= =?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/model/Note.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 027ef91..8bc27c8 100644 --- a/app/src/main/java/net/micode/notes/model/Note.java +++ b/app/src/main/java/net/micode/notes/model/Note.java @@ -53,7 +53,9 @@ public class 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 { noteId = Long.valueOf(uri.getPathSegments().get(1)); @@ -67,6 +69,9 @@ public class Note { return noteId; } + /** + 用来存储便签的数据,一个是存储便签属性、一个是存储便签内容 + */ public Note() { mNoteDiffValues = new ContentValues(); mNoteData = new NoteData(); @@ -81,18 +86,30 @@ public class Note { public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } + /** + 设置文本数据的ID + */ public void setTextDataId(long id) { mNoteData.setTextDataId(id); } + /** + 得到文本数据的ID + */ public long getTextDataId() { return mNoteData.mTextDataId; } + /** + 设置电话号码数据的ID + */ public void setCallDataId(long id) { mNoteData.setCallDataId(id); } + /** + 得到电话号码数据的ID + */ public void setCallData(String key, String value) { mNoteData.setCallData(key, value); @@ -132,6 +149,9 @@ public class Note { return true; } + /** + * 定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据 + */ private class NoteData { private long mTextDataId; @@ -187,6 +207,9 @@ public class Note { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); } + /** + * 判断数据是否合法 + */ ArrayList operationList = new ArrayList(); ContentProviderOperation.Builder builder = null; @@ -212,6 +235,9 @@ public class Note { } mTextDataValues.clear(); } + /** + * 把文本数据存入DataColumns + */ if (mCallDataValues.size() > 0) { mCallDataValues.put(DataColumns.NOTE_ID, noteId);