From ed719ab579ef93898cd1a9ff1bc37f41735f589e Mon Sep 17 00:00:00 2001 From: zcx <1078327420@qq.com> Date: Tue, 19 Dec 2023 11:47:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E8=BF=91=E6=A0=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/micode/notes/data/Contact.java | 23 ++- .../src/net/micode/notes/data/Notes.java | 103 +++++----- .../notes/data/NotesDatabaseHelper.java | 33 +-- .../net/micode/notes/data/NotesProvider.java | 16 +- .../net/micode/notes/tool/BackupUtils.java | 43 ++-- .../src/net/micode/notes/tool/DataUtils.java | 17 +- .../micode/notes/tool/GTaskStringUtils.java | 188 +++++++++--------- .../net/micode/notes/tool/ResourceParser.java | 26 ++- 8 files changed, 232 insertions(+), 217 deletions(-) diff --git a/src/Notes-master/src/net/micode/notes/data/Contact.java b/src/Notes-master/src/net/micode/notes/data/Contact.java index f2e5b72..1bf33e4 100644 --- a/src/Notes-master/src/net/micode/notes/data/Contact.java +++ b/src/Notes-master/src/net/micode/notes/data/Contact.java @@ -14,19 +14,23 @@ * limitations under the License. */ -package net.micode.notes.data; +package net.micode.notes.data;//指明包的位置 -import android.content.Context; +import android.content.Context;//引用android.content.Context -import android.database.Cursor; +import android.database.Cursor;//引用android.database.Cursor import android.provider.ContactsContract.CommonDataKinds.Phone; +//引用CommonDataKinds.Phone import android.provider.ContactsContract.Data; +//引用android.provider.ContactsContract.Data import android.telephony.PhoneNumberUtils; -import android.util.Log; +//引用android.telephony.PhoneNumberUtils +import android.util.Log;//引用android.util.Log -import java.util.HashMap; -//change -public class Contact { //联系人 +import java.util.HashMap;//引用java.util.HashMap + +//联系人 +public class Contact { private static HashMap sContactCache; private static final String TAG = "Contact"; @@ -49,6 +53,7 @@ public class Contact { // // 查找HashMap中是否已有phoneNumber信息 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); + //返回phoneNumber信息 } String selection = CALLER_ID_SELECTION.replace("+", @@ -64,14 +69,15 @@ public class Contact { // // 判定查询结果 // moveToFirst()返回第一条 if (cursor != null && cursor.moveToFirst()) { - try { // 找到相关信息 + try { String name = cursor.getString(0); sContactCache.put(phoneNumber, name); return name; // 异常处理 } catch (IndexOutOfBoundsException e) { Log.e(TAG, " Cursor get string error " + e.toString()); + //输出相关string error错误信息 return null; } finally { cursor.close(); @@ -79,6 +85,7 @@ public class Contact { // // 未找到相关信息处理 } else { Log.d(TAG, "No contact matched with number:" + phoneNumber); + //输出No contact matched错误信息 return null; } } diff --git a/src/Notes-master/src/net/micode/notes/data/Notes.java b/src/Notes-master/src/net/micode/notes/data/Notes.java index 6aad9cd..ba7b39f 100644 --- a/src/Notes-master/src/net/micode/notes/data/Notes.java +++ b/src/Notes-master/src/net/micode/notes/data/Notes.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package net.micode.notes.data; +package net.micode.notes.data;//此类在文件中的位置 -import android.content.ContentUris; -import android.net.Uri; +import android.content.ContentUris;//引用android.content.ContentUris +import android.net.Uri;//引用android.net.Uri // Notes 类中定义了很多常量,这些常量大多是int型和string型 public class Notes { + //定义两个常量 public static final String AUTHORITY = "micode_notes"; public static final String TAG = "Notes"; @@ -29,10 +30,10 @@ public class Notes { public static final int TYPE_SYSTEM = 2; /** - * Following IDs are system folders' identifiers - * {@link Notes#ID_ROOT_FOLDER } is default folder - * {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder - * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records + * 以下 ID 是系统文件夹的标识符 + * {@link Notes#ID_ROOT_FOLDER }是默认文件夹 + * {@link Notes#ID_TEMPARAY_FOLDER }是不属于文件夹的notes + * {@link Notes#ID_CALL_RECORD_FOLDER}是用于存储通话记录 */ public static final int ID_ROOT_FOLDER = 0; public static final int ID_TEMPARAY_FOLDER = -1; @@ -40,24 +41,25 @@ public class Notes { public static final int ID_TRASH_FOLER = -3; public static final String INTENT_EXTRA_ALERT_DATE = - + //定义net.micode.notes.alert_date的常量 "net.micode.notes.alert_date"; public static final String INTENT_EXTRA_BACKGROUND_ID = - + //定义net.micode.notes.background_color_id的常量 "net.micode.notes.background_color_id"; public static final String INTENT_EXTRA_WIDGET_ID = - + //定义net.micode.notes.widget_id的常量 "net.micode.notes.widget_id"; public static final String INTENT_EXTRA_WIDGET_TYPE = - + //定义net.micode.notes.widget_type的常量 "net.micode.notes.widget_type"; public static final String INTENT_EXTRA_FOLDER_ID = - + //定义net.micode.notes.folder_id的常量 "net.micode.notes.folder_id"; public static final String INTENT_EXTRA_CALL_DATE = - + //定义net.micode.notes.call_date的常量 "net.micode.notes.call_date"; +//定义使用widget挂件的常量 public static final int TYPE_WIDGET_INVALIDE = -1; public static final int TYPE_WIDGET_2X = 0; public static final int TYPE_WIDGET_4X = 1; @@ -68,16 +70,15 @@ public class Notes { } /** - * Uri to query all notes and folders + * 用于查询所有便笺和文件夹的 URI */ public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");//定义查询便签和文件夹的指针。 - -// public static final Uri my_URI = ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI , 10); + public static final Uri my_URI = ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI , 10); /** - * Uri to query data + * 用于查询数据的 URI */ public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + @@ -86,93 +87,92 @@ AUTHORITY + "/data");// // 定义NoteColumns的常量,用于后面创建数据库的表头 public interface NoteColumns { /** - * The unique ID for a row + * 行的唯一 ID *

Type: INTEGER (long)

*/ public static final String ID = "_id"; /** - * The parent's id for note or folder + * 便笺或文件夹的父ID *

Type: INTEGER (long)

*/ public static final String PARENT_ID = "parent_id";//为什么会有parent_id /** - * Created data for note or folder + * 为笔记或文件夹创建的数据 *

Type: INTEGER (long)

*/ public static final String CREATED_DATE = "created_date"; /** - * Latest modified date + * 最新修改日期 *

Type: INTEGER (long)

*/ public static final String MODIFIED_DATE = "modified_date"; /** - * Alert date + * 警报日期 *

Type: INTEGER (long)

*/ public static final String ALERTED_DATE = "alert_date"; /** - * Folder's name or text content of note + * 文件夹名称或注释的文本内容 *

Type: TEXT

*/ public static final String SNIPPET = "snippet"; /** - * Note's widget id + * notes的widget ID *

Type: INTEGER (long)

*/ public static final String WIDGET_ID = "widget_id"; /** - * Note's widget type + * notes的widget 类型 *

Type: INTEGER (long)

*/ public static final String WIDGET_TYPE = "widget_type"; /** - * Note's background color's id + * 笔记的背景颜色的 ID *

Type: INTEGER (long)

*/ public static final String BG_COLOR_ID = "bg_color_id"; /** - * For text note, it doesn't has attachment, for multi-media - * note, it has at least one attachment + * 对于文本笔记,它没有附件,对于多媒体笔记,它至少有一个附件 *

Type: INTEGER

*/ public static final String HAS_ATTACHMENT = "has_attachment"; /** - * Folder's count of notes + * 文件夹的笔记计数 *

Type: INTEGER (long)

*/ public static final String NOTES_COUNT = "notes_count"; /** - * The file type: folder or note + * 文件类型:文件夹或便笺 *

Type: INTEGER

*/ public static final String TYPE = "type"; /** - * The last sync id + * 最后一个同步 ID *

Type: INTEGER (long)

*/ public static final String SYNC_ID = "sync_id";//同步 /** - * Sign to indicate local modified or not + * 指示本地修改与否的标志 *

Type: INTEGER

*/ public static final String LOCAL_MODIFIED = "local_modified"; /** - * Original parent id before moving into temporary folder + * 移动到临时文件夹之前的原始父 ID *

Type : INTEGER

*/ public static final String ORIGIN_PARENT_ID = "origin_parent_id"; @@ -193,77 +193,72 @@ AUTHORITY + "/data");// // 定义DataColumns的常量,用于后面创建数据库的表头 public interface DataColumns { /** - * The unique ID for a row + * 行的唯一 ID *

Type: INTEGER (long)

*/ public static final String ID = "_id"; /** - * The MIME type of the item represented by this row. + * 此行表示的项的 MIME 类型。 *

Type: Text

*/ public static final String MIME_TYPE = "mime_type"; /** - * The reference id to note that this data belongs to + * 此数据所属的引用 ID *

Type: INTEGER (long)

*/ public static final String NOTE_ID = "note_id"; /** - * Created data for note or folder + * 为笔记或文件夹创建的数据 *

Type: INTEGER (long)

*/ public static final String CREATED_DATE = "created_date"; /** - * Latest modified date + * 最新修改日期 *

Type: INTEGER (long)

*/ public static final String MODIFIED_DATE = "modified_date"; /** - * Data's content + * 数据内容 *

Type: TEXT

*/ public static final String CONTENT = "content"; /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, -used for - * integer data type + * 通用数据列,含义是 {@link #MIMETYPE} 特定的,用于 + * Integer 数据类型 *

Type: INTEGER

*/ public static final String DATA1 = "data1"; /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, -used for - * integer data type + * 通用数据列,含义是 {@link #MIMETYPE} 特定的,用于 + * Integer 数据类型 *

Type: INTEGER

*/ public static final String DATA2 = "data2"; /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, -used for + * 通用数据列,含义是 {@link #MIMETYPE} 特定的,用于 * TEXT data type *

Type: TEXT

*/ public static final String DATA3 = "data3"; /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, -used for + * 通用数据列,含义是 {@link #MIMETYPE} 特定的,用于 * TEXT data type *

Type: TEXT

*/ public static final String DATA4 = "data4"; /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, -used for + * 通用数据列,含义是 {@link #MIMETYPE} 特定的,用于 * TEXT data type *

Type: TEXT

*/ @@ -271,7 +266,7 @@ used for }//主要是定义存储便签内容数据的 public static final class TextNote implements DataColumns { /** - * Mode to indicate the text in check list mode or not + * 指示文本是否处于核对列表模式的模式 *

Type: Integer 1:check list mode 0: normal mode

*/ public static final String MODE = DATA1; @@ -293,13 +288,13 @@ AUTHORITY + "/text_note"); public static final class CallNote implements DataColumns { /** - * Call date for this record + * 此记录的调用日期 *

Type: INTEGER (long)

*/ public static final String CALL_DATE = DATA1; /** - * Phone number for this record + * 此记录的电话号码 *

Type: TEXT

*/ public static final String PHONE_NUMBER = DATA3; diff --git a/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java index 4e41fb6..978e900 100644 --- a/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java @@ -38,6 +38,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { public static final String DATA = "data"; } +//定义数据库中需要的常量 private static final String TAG = "NotesDatabaseHelper"; private static NotesDatabaseHelper mInstance; @@ -83,7 +84,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";//存储便签编号的一个数据表格 /** - * Increase folder's note count when move note to the folder + * 将笔记移动到文件夹时增加文件夹的笔记计数 */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER increase_folder_count_on_update "+ @@ -95,7 +96,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//在文件夹中移入一个Note之后需要更改的数据的表格。 /** - * Decrease folder's note count when move note from folder + * 从文件夹移动笔记时减少文件夹的笔记计数 */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_update " + @@ -108,7 +109,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//在文件夹中移出一个Note之后需要更改的数据的表格。 /** - * Increase folder's note count when insert new note to the folder + * 在文件夹插入新笔记时增加文件夹的笔记计数 */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = "CREATE TRIGGER increase_folder_count_on_insert " + @@ -120,7 +121,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//在文件夹中插入一个Note之后需要更改的数据的表格。 /** - * Decrease folder's note count when delete note from the folder + * 从文件夹中删除笔记时减少文件夹的笔记计数 */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_delete " + @@ -133,7 +134,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//在文件夹中删除一个Note之后需要更改的数据的表格。 /** - * Update note's content when insert data with type {@link DataConstants#NOTE} + * 插入类型为 {@link DataConstants#NOTE} 的数据时更新注释的内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + @@ -146,7 +147,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//在文件夹中对一个Note导入新的数据之后需要更改的数据的表格。 /** - * Update note's content when data with {@link DataConstants#NOTE} type has changed + * 当 {@link DataConstants#NOTE} 类型的数据发生更改时更新注释的内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + @@ -159,7 +160,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//Note数据被修改后需要更改的数据的表格。 /** - * Update note's content when data with {@link DataConstants#NOTE} type has deleted + * 删除 {@link DataConstants#NOTE} 类型的数据时更新注释内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + @@ -172,7 +173,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//Note数据被删除后需要更改的数据的表格。 /** - * Delete datas belong to note which has been deleted + * 删除属于已删除的注意事项的数据 */ private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = "CREATE TRIGGER delete_data_on_delete " + @@ -183,7 +184,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//删除已删除的便签的数据后需要更改的数据的表格。 /** - * Delete notes belong to folder which has been deleted + * 删除已删除的文件夹的便签后需要更改的数据的表格 */ private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = "CREATE TRIGGER folder_delete_notes_on_delete " + @@ -194,7 +195,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END";//删除已删除的文件夹的便签后需要更改的数据的表格。 /** - * Move notes belong to folder which has been moved to trash folder + * 还原垃圾桶中便签后需要更改的数据的表格 */ private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = "CREATE TRIGGER folder_move_notes_on_trash " + @@ -204,7 +205,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END";//还原垃圾桶中便签后需要更改的数据的表格。 + " END";。 public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); @@ -240,14 +241,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { ContentValues values = new ContentValues(); /** - * call record foler for call notes + * 通话记录 Foler,用于通话记录 */ values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); /** - * root folder which is default folder + * 根文件夹,即默认文件夹 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); @@ -255,7 +256,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); /** - * temporary folder which is used for moving note + * 用于移动笔记的临时文件夹 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); @@ -263,7 +264,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); /** - * create trash folder + * 创建垃圾桶文件夹 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); @@ -310,7 +311,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { if (oldVersion == 1) { upgradeToV2(db); - skipV2 = true; // this upgrade including the upgrade from v2 to v3 + skipV2 = true; // 此升级包括从 v2 到 v3 的升级 oldVersion++; } diff --git a/src/Notes-master/src/net/micode/notes/data/NotesProvider.java b/src/Notes-master/src/net/micode/notes/data/NotesProvider.java index b67144b..b5a1d08 100644 --- a/src/Notes-master/src/net/micode/notes/data/NotesProvider.java +++ b/src/Notes-master/src/net/micode/notes/data/NotesProvider.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package net.micode.notes.data; +package net.micode.notes.data;//此类所在位置 +//以下为引用的各种工具 import android.app.SearchManager; import android.content.ContentProvider; import android.content.ContentUris; @@ -69,8 +70,8 @@ public class NotesProvider extends ContentProvider { } /** - * x'0A' represents the '\n' character in sqlite. For title and content in the search result, - * we will trim '\n' and white space in order to show more information. + * x'0A' 表示 sqlite 中的 'n' 字符。对于搜索结果中的标题和内容, + * 去掉“n”和空白以显示更多信息. */ // 声明 NOTES_SEARCH_PROJECTION private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," @@ -188,14 +189,14 @@ public class NotesProvider extends ContentProvider { default: throw new IllegalArgumentException("Unknown URI " + uri); } - // Notify the note uri + // 通知注释 uri // notifyChange获得一个ContextResolver对象并且更新里面的内容 if (noteId > 0) { getContext().getContentResolver().notifyChange( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); } - // Notify the data uri + // 通知数据 URI if (dataId > 0) { getContext().getContentResolver().notifyChange( ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); @@ -222,8 +223,7 @@ public class NotesProvider extends ContentProvider { case URI_NOTE_ITEM: id = uri.getPathSegments().get(1); /** - * ID that smaller than 0 is system folder which is not allowed to - * trash + * 小于 0 的 ID 是不允许回收的系统文件夹 */ long noteId = Long.valueOf(id); if (noteId <= 0) { @@ -329,7 +329,7 @@ public class NotesProvider extends ContentProvider { @Override public String getType(Uri uri) { - // TODO Auto-generated method stub + // TODO 自动生成的方法存根 return null; } diff --git a/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java b/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java index 740fdbb..444d9dc 100644 --- a/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java +++ b/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java @@ -19,7 +19,7 @@ package net.micode.notes.tool; public class BackupUtils { private static final String TAG = "BackupUtils"; // Singleton stuff - private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象? + private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象 public static synchronized BackupUtils getInstance(Context context) { //ynchronized 关键字,代表这个方法加锁,相当于不管哪一个线程(例如线程A) @@ -33,8 +33,7 @@ public class BackupUtils { } /** - * Following states are signs to represents backup or restore - * status + * 以下状态是表示备份或还原状态的标志 */ // Currently, the sdcard is not mounted SD卡没有被装入手机 public static final int STATE_SD_CARD_UNMOUONTED = 0; @@ -49,11 +48,13 @@ public class BackupUtils { private TextExport mTextExport; - private BackupUtils(Context context) { //初始化函数 +//初始化函数 + private BackupUtils(Context context) { mTextExport = new TextExport(context); } - private static boolean externalStorageAvailable() { //外部存储功能是否可用 +//外部存储功能是否可用 + private static boolean externalStorageAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } @@ -69,6 +70,7 @@ public class BackupUtils { return mTextExport.mFileDirectory; } +//TextExport方法 private static class TextExport { private static final String[] NOTE_PROJECTION = { NoteColumns.ID, @@ -92,6 +94,7 @@ public class BackupUtils { DataColumns.DATA4, }; +//定义数据类型的常量 private static final int DATA_COLUMN_CONTENT = 0; private static final int DATA_COLUMN_MIME_TYPE = 1; @@ -116,12 +119,13 @@ public class BackupUtils { mFileDirectory = ""; } - private String getFormat(int id) { //获取文本的组成部分 +//获取文本的组成部分 + private String getFormat(int id) { return TEXT_FORMAT[id]; } /** - * Export the folder identified by folder id to text + * 将文件夹 ID 标识的文件夹导出为文本 */ private void exportFolderToText(String folderId, PrintStream ps) { // Query notes belong to this folder 通过查询parent id是文件夹id的note来选出制定ID文件夹下的Note @@ -137,7 +141,7 @@ public class BackupUtils { ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( mContext.getString(R.string.format_datetime_mdhm), notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note + // 查询属于此说明数据 String noteId = notesCursor.getString(NOTE_COLUMN_ID); exportNoteToText(noteId, ps); //将文件导出到text } while (notesCursor.moveToNext()); @@ -147,7 +151,7 @@ public class BackupUtils { } /** - * Export note identified by id to a print stream + * 将由 id 标识的注释导出到打印流 */ private void exportNoteToText(String noteId, PrintStream ps) { Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, @@ -169,11 +173,11 @@ public class BackupUtils { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), phoneNumber)); } - // Print call date + // 打印通话日期 ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat .format(mContext.getString(R.string.format_datetime_mdhm), callDate))); - // Print call attachment location + // 打印使用附件位置 if (!TextUtils.isEmpty(location)) { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), location)); @@ -189,7 +193,7 @@ public class BackupUtils { } dataCursor.close(); } - // print a line separator between note + // 在注释之间打印行分隔符 try { ps.write(new byte[] { Character.LINE_SEPARATOR, Character.LETTER_NUMBER @@ -200,7 +204,7 @@ public class BackupUtils { } /** - * Note will be exported as text which is user readable + * 注释将导出为用户可读的文本 */ public int exportToText() { //总函数,调用上面的exportFolder和exportNote if (!externalStorageAvailable()) { @@ -213,7 +217,7 @@ public class BackupUtils { Log.e(TAG, "get print stream error"); return STATE_SYSTEM_ERROR; } - // First export folder and its notes 导出文件夹,就是导出里面包含的便签 + //导出文件夹,就是导出里面包含的便签 Cursor folderCursor = mContext.getContentResolver().query( Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, @@ -241,7 +245,7 @@ public class BackupUtils { folderCursor.close(); } - // Export notes in root's folder 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出) + // 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出) Cursor noteCursor = mContext.getContentResolver().query( Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, @@ -254,7 +258,7 @@ public class BackupUtils { ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( mContext.getString(R.string.format_datetime_mdhm), noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note + // 查询数据属于此说明 String noteId = noteCursor.getString(NOTE_COLUMN_ID); exportNoteToText(noteId, ps); } while (noteCursor.moveToNext()); @@ -267,7 +271,7 @@ public class BackupUtils { } /** - * Get a print stream pointed to the file {@generateExportedTextFile} + * 获取指向文件 {@generateExportedTextFile} 的打印流 */ private PrintStream getExportToTextPrintStream() { File file = generateFileMountedOnSDcard(mContext, R.string.file_path, @@ -281,7 +285,8 @@ public class BackupUtils { PrintStream ps = null; try { FileOutputStream fos = new FileOutputStream(file); - ps = new PrintStream(fos); //将ps输出流输出到特定的文件,目的就是导出到文件,而不是直接输出 + ps = new PrintStream(fos); + //将ps输出流输出到特定的文件,目的就是导出到文件,而不是直接输出 } catch (FileNotFoundException e) { e.printStackTrace(); return null; @@ -294,7 +299,7 @@ public class BackupUtils { } /** - * Generate the text file to store imported data + * 生成文本文件以存储导入的数据 */ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { StringBuilder sb = new StringBuilder(); diff --git a/src/Notes-master/src/net/micode/notes/tool/DataUtils.java b/src/Notes-master/src/net/micode/notes/tool/DataUtils.java index e591b68..2886c5f 100644 --- a/src/Notes-master/src/net/micode/notes/tool/DataUtils.java +++ b/src/Notes-master/src/net/micode/notes/tool/DataUtils.java @@ -1,4 +1,4 @@ -package net.micode.notes.tool; +package net.micode.notes.tool;//此类所在位置 public class DataUtils { public static final String TAG = "DataUtils"; @@ -78,7 +78,7 @@ public class DataUtils { } /** - * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} + * 获取除系统文件夹 {@link Notes#TYPE_SYSTEM}} 之外的所有文件夹计数 */ public static int getUserFolderCount(ContentResolver resolver) { Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, @@ -94,6 +94,7 @@ public class DataUtils { count = cursor.getInt(0); } catch (IndexOutOfBoundsException e) { Log.e(TAG, "get folder count failed:" + e.toString()); +//get folder count failed报错 } finally { cursor.close(); } @@ -119,7 +120,8 @@ public class DataUtils { return exist; } - public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { +// 检查给定的noteId是否存在于笔记数据库中 + public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {// 构建查询笔记数据的Uri,使用ContentUris.withAppendedId()方法将noteId添加到笔记Uri中 Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, null, null, null); @@ -139,10 +141,10 @@ public class DataUtils { boolean exist = false; if (cursor != null) { - if (cursor.getCount() > 0) { + if (cursor.getCount() > 0) {// 如果count中有数据,则说明noteId存在于笔记数据库中 exist = true; } - cursor.close(); + cursor.close();//释放资源 } return exist; } @@ -191,7 +193,8 @@ public class DataUtils { return set; } - public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { +//根据给定的noteId从笔记数据库中获取电话号码 + public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {// 构建查询条件,返回值为String类型,表示根据noteId获取到的电话号码,如果获取失败则返回空字符串 Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.PHONE_NUMBER }, CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", @@ -200,7 +203,7 @@ public class DataUtils { if (cursor != null && cursor.moveToFirst()) { try { - return cursor.getString(0); + return cursor.getString(0);// 获取第一列的电话号码数据 } catch (IndexOutOfBoundsException e) { Log.e(TAG, "Get call number fails " + e.toString()); } finally { diff --git a/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java b/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java index dfc1ac6..5825486 100644 --- a/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java @@ -14,102 +14,96 @@ * limitations under the License. */ -//简介:定义了很多的静态字符串,目的就是为了提供jsonObject中相应字符串的"key"。把这些静态的定义单独写到了一个类里面,这是非常好的编程规范 -package net.micode.notes.tool; - -//这个类就是定义了一堆static string,实际就是为jsonObject提供Key,把这些定义全部写到一个类里,方便查看管理,是一个非常好的编程习惯 -public class GTaskStringUtils { - - public final static String GTASK_JSON_ACTION_ID = "action_id"; - - public final static String GTASK_JSON_ACTION_LIST = "action_list"; - - public final static String GTASK_JSON_ACTION_TYPE = "action_type"; - - public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; - - public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; - - public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; - - public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; - - public final static String GTASK_JSON_CREATOR_ID = "creator_id"; - - public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; - - public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; - - public final static String GTASK_JSON_COMPLETED = "completed"; - - public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; - - public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; - - public final static String GTASK_JSON_DELETED = "deleted"; - - public final static String GTASK_JSON_DEST_LIST = "dest_list"; - - public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; - - public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; - - public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; - - public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; - - public final static String GTASK_JSON_GET_DELETED = "get_deleted"; - - public final static String GTASK_JSON_ID = "id"; - - public final static String GTASK_JSON_INDEX = "index"; - - public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; - - public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; - - public final static String GTASK_JSON_LIST_ID = "list_id"; - - public final static String GTASK_JSON_LISTS = "lists"; - - public final static String GTASK_JSON_NAME = "name"; - - public final static String GTASK_JSON_NEW_ID = "new_id"; - - public final static String GTASK_JSON_NOTES = "notes"; - - public final static String GTASK_JSON_PARENT_ID = "parent_id"; - - public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; - - public final static String GTASK_JSON_RESULTS = "results"; - - public final static String GTASK_JSON_SOURCE_LIST = "source_list"; - - public final static String GTASK_JSON_TASKS = "tasks"; - - public final static String GTASK_JSON_TYPE = "type"; - - public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; - - public final static String GTASK_JSON_TYPE_TASK = "TASK"; - - public final static String GTASK_JSON_USER = "user"; - - public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; - - public final static String FOLDER_DEFAULT = "Default"; - - public final static String FOLDER_CALL_NOTE = "Call_Note"; - - public final static String FOLDER_META = "METADATA"; - - public final static String META_HEAD_GTASK_ID = "meta_gid"; - - public final static String META_HEAD_NOTE = "meta_note"; - - public final static String META_HEAD_DATA = "meta_data"; - - public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; +//定义了很多的静态字符串,目的就是为了提供jsonObject中相应字符串的"key"。把这些静态的定义单独写到了一个类里面 +package net.micode.notes.tool;//定位此类 +//这个类定义了一些static string,实际就是为jsonObject提供Key,把这些定义全部写到一个类里,方便查看管理 +public class GTaskStringUtils { + +// 动作相关常量 +public final static String GTASK_JSON_ACTION_ID = "action_id"; // 动作ID +public final static String GTASK_JSON_ACTION_LIST = "action_list"; // 动作列表 +public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // 动作类型 +public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; // 创建动作类型 +public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; // 获取所有动作类型 +public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // 移动动作类型 +public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // 更新动作类型 + +public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // 创建者ID + +public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // 子实体 + +public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // 客户端版本 + +public final static String GTASK_JSON_COMPLETED = "completed"; // 完成状态 + +public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; // 当前列表ID + +public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // 默认列表ID + +public final static String GTASK_JSON_DELETED = "deleted"; // 删除状态 + +public final static String GTASK_JSON_DEST_LIST = "dest_list"; // 目标列表 + +public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // 目标父级 + +public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // 目标父级类型 + +public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; // 实体增量 + +public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // 实体类型 + +public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // 获取已删除项 + +public final static String GTASK_JSON_ID = "id"; // ID + +public final static String GTASK_JSON_INDEX = "index"; // 索引 + +public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // 最后修改时间 + +public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // 最新同步点 + +public final static String GTASK_JSON_LIST_ID = "list_id"; // 列表ID + +public final static String GTASK_JSON_LISTS = "lists"; // 列表 + +public final static String GTASK_JSON_NAME = "name"; // 名称 + +public final static String GTASK_JSON_NEW_ID = "new_id"; // 新ID + +public final static String GTASK_JSON_NOTES = "notes"; // 备注 + +public final static String GTASK_JSON_PARENT_ID = "parent_id"; // 父级ID + +public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 上一个兄弟节点ID + +public final static String GTASK_JSON_RESULTS = "results"; // 结果 + +public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // 源列表 + +public final static String GTASK_JSON_TASKS = "tasks"; // 任务 + +// 类型相关常量 +public final static String GTASK_JSON_TYPE = "type"; // 类型 +public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // 分组类型 +public final static String GTASK_JSON_TYPE_TASK = "TASK"; // 任务类型 + +public final static String GTASK_JSON_USER = "user"; // 用户 + +public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; // MIUI文件夹前缀 + +public final static String FOLDER_DEFAULT = "Default"; // 默认文件夹 + +public final static String FOLDER_CALL_NOTE = "Call_Note"; // 电话备注文件夹 + +public final static String FOLDER_META = "METADATA"; // 元数据文件夹 + +public final static String META_HEAD_GTASK_ID = "meta_gid"; // 元信息任务ID + +public final static String META_HEAD_NOTE = "meta_note"; // 元信息备注 + +public final static String META_HEAD_DATA = "meta_data"; // 元信息数据 + +public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // 元信息备注名称 + } \ No newline at end of file diff --git a/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java b/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java index e1846a3..f0e8b41 100644 --- a/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java +++ b/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package net.micode.notes.tool; +package net.micode.notes.tool;//此类位置 -/*简介:字面意义是资源分析器,实际上就是获取资源并且在程序中使用,比如颜色图片等 +/*资源分析器,实际上就是获取资源并且在程序中使用,比如颜色图片等 * 实现方法:主要利用R.java这个类,其中包括 * R.id 组件资源引用 * R.drawable 图片资源 (被使用) @@ -31,6 +31,7 @@ package net.micode.notes.tool; * BG_DEFAULT_FONT_SIZE 默认文本大小(中) */ +//字体大小和颜色 public class ResourceParser { public static final int YELLOW = 0; @@ -48,6 +49,7 @@ public class ResourceParser { public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; +//便签颜色 public static class NoteBgResources { private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, @@ -57,6 +59,7 @@ public class ResourceParser { R.drawable.edit_red }; +//标题颜色 private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { R.drawable.edit_title_yellow, R.drawable.edit_title_blue, @@ -73,7 +76,8 @@ public class ResourceParser { return BG_EDIT_TITLE_RESOURCES[id]; } } - //直接获取默认的背景颜色。看不太懂,这个PREFERENCE_SET_BG_COLOR_KEY是个final string,也就是说getBoolean肯定执行else,为什么要这么写 + + //直接获取默认的背景颜色。 public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { @@ -82,7 +86,8 @@ public class ResourceParser { return BG_DEFAULT_COLOR; } } - + + //用于存储不同类型笔记的第一个笔记的背景资源ID public static class NoteItemBgResources { private final static int [] BG_FIRST_RESOURCES = new int [] { R.drawable.list_yellow_up, @@ -92,6 +97,7 @@ public class ResourceParser { R.drawable.list_red_up }; +//用于存储不同类型笔记的中间笔记的背景资源ID private final static int [] BG_NORMAL_RESOURCES = new int [] { R.drawable.list_yellow_middle, R.drawable.list_blue_middle, @@ -100,6 +106,7 @@ public class ResourceParser { R.drawable.list_red_middle }; +//用于存储不同类型笔记的最后笔记的背景资源ID private final static int [] BG_LAST_RESOURCES = new int [] { R.drawable.list_yellow_down, R.drawable.list_blue_down, @@ -108,6 +115,7 @@ public class ResourceParser { R.drawable.list_red_down, }; +//定义了NoteItemBgResources内部类中的一个静态数组BG_SINGLE_RESOURCES,用于存储不同类型笔记只有一个笔记时的背景资源ID。 private final static int [] BG_SINGLE_RESOURCES = new int [] { R.drawable.list_yellow_single, R.drawable.list_blue_single, @@ -115,19 +123,23 @@ public class ResourceParser { R.drawable.list_green_single, R.drawable.list_red_single }; - + + //用于获取特定id对应的第一个笔记的背景资源ID。 public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } +//用于获取特定id对应的最后一个笔记的背景资源ID public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } +//用于获取特定id对应的只有一个笔记时的背景资源ID public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } +//用于获取特定id对应的中间笔记的背景资源ID public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } @@ -174,9 +186,7 @@ public class ResourceParser { //这里有一个容错的函数,防止输入的id大于资源总量,若如此,则自动返回默认的设置结果 public static int getTexAppearanceResource(int id) { /** - * HACKME: Fix bug of store the resource id in shared preference. - * The id may larger than the length of resources, in this case, - * return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE} + * HACKME:修复将资源 ID 存储在共享首选项中的错误。id 可能大于资源的 长度,在本例中,返回 {@link ResourceParser#BG_DEFAULT_FONT_SIZE} */ if (id >= TEXTAPPEARANCE_RESOURCES.length) { return BG_DEFAULT_FONT_SIZE;