diff --git a/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java index 12ca11d..e9c30d2 100644 --- a/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java +++ b/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java @@ -125,7 +125,7 @@ public class BackupUtils { private String mFileName; private String mFileDirectory; - public TextExport(Context context) { + public TextExport(Context context) {//将便签内容显示 TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); mContext = context; mFileName = ""; @@ -139,7 +139,7 @@ public class BackupUtils { /** * Export the folder identified by folder id to text */ - private void exportFolderToText(String folderId, PrintStream ps) { + private void exportFolderToText(String folderId, PrintStream ps) {//寻找文件夹 // Query notes belong to this folder 通过查询parent ,id是文件夹id的note来选出制定ID文件夹下的Note Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { @@ -238,17 +238,17 @@ public class BackupUtils { + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); - if (folderCursor != null) { - if (folderCursor.moveToFirst()) { + if (folderCursor != null) {//文件夹光标指向不为空文件夹 + if (folderCursor.moveToFirst()) {//当前光标指向第一个文件夹 do { // Print folder's name String folderName = ""; - if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { + if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {//便签的内容 folderName = mContext.getString(R.string.call_record_folder_name); } else { - folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); + folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);//获取便签名 } - if (!TextUtils.isEmpty(folderName)) { + if (!TextUtils.isEmpty(folderName)) {//便签名获取失败 ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); } String folderId = folderCursor.getString(NOTE_COLUMN_ID); @@ -271,7 +271,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 + // Query data belong to this note查询数据属于本笔记 String noteId = noteCursor.getString(NOTE_COLUMN_ID); exportNoteToText(noteId, ps); } while (noteCursor.moveToNext()); @@ -284,17 +284,17 @@ public class BackupUtils { } /** - * Get a print stream pointed to the file {@generateExportedTextFile} + * Get a print stream pointed to the file {@generateExportedTextFile}获取一个指向文件{@generateExportedTextFile}的打印流 */ - private PrintStream getExportToTextPrintStream() { + private PrintStream getExportToTextPrintStream() {//打印输出流 File file = generateFileMountedOnSDcard(mContext, R.string.file_path, R.string.file_name_txt_format); - if (file == null) { + if (file == null) {//文件不存在 Log.e(TAG, "create file to exported failed"); return null; } - mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); + mFileName = file.getName();//获取文件名 + mFileDirectory = mContext.getString(R.string.file_path);//获取文件目录 PrintStream ps = null; try { FileOutputStream fos = new FileOutputStream(file); diff --git a/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java b/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java index 76cae8d..986d3b0 100644 --- a/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -37,19 +37,19 @@ import java.util.HashSet; public class DataUtils { public static final String TAG = "DataUtils"; - public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) {//直接删除多个笔记 - if (ids == null) { + public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) {//删除多个便签 + if (ids == null) { //便签id不存在 Log.d(TAG, "the ids is null"); return true; } - if (ids.size() == 0) { + if (ids.size() == 0) { //哈希表中便签ID不存在 Log.d(TAG, "no id is in the hashset"); return true; } ArrayList operationList = new ArrayList();//提供一个任务列表 for (long id : ids) { - if(id == Notes.ID_ROOT_FOLDER) {//若为根文件夹,则警告不可删除 + if(id == Notes.ID_ROOT_FOLDER) { //若为根文件夹,则警告不可删除 Log.e(TAG, "Don't delete system folder root"); continue; } @@ -59,30 +59,30 @@ public class DataUtils { } try { ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); - if (results == null || results.length == 0 || results[0] == null) { + if (results == null || results.length == 0 || results[0] == null) {//便签删除失败 Log.d(TAG, "delete notes failed, ids:" + ids.toString()); return false; } return true; - } catch (RemoteException e) { + } catch (RemoteException e) {//网络出错 Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - } catch (OperationApplicationException e) { + } catch (OperationApplicationException e) {//操作指令错误 Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } return false; } - public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { + public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {//转移笔记到其他文件夹 ContentValues values = new ContentValues(); values.put(NoteColumns.PARENT_ID, desFolderId); values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); values.put(NoteColumns.LOCAL_MODIFIED, 1); - resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); + resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);//对需要移动的便签进行数据更新,然后用update实现 } public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, - long folderId) { - if (ids == null) { + long folderId) { //一次转移多个便签 + if (ids == null) { //出现空的便签ID Log.d(TAG, "the ids is null"); return true; } @@ -97,7 +97,8 @@ public class DataUtils { } try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); + ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);//主机名(或叫Authority)用于唯一标识这个ContentProvider,外部调用者可以根据这个标识来找到它。 + //数据库事务,数据库事务是由一组数据库操作序列组成,事务作为一个整体被执行 if (results == null || results.length == 0 || results[0] == null) { Log.d(TAG, "delete notes failed, ids:" + ids.toString()); return false; @@ -119,7 +120,7 @@ public class DataUtils { new String[] { "COUNT(*)" }, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, - null); + null);//筛选条件:源文件不为trash folder int count = 0; if(cursor != null) { @@ -137,15 +138,15 @@ public class DataUtils { } public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), + Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),//通过withAppendedId方法,为该Uri加上ID null, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, new String [] {String.valueOf(type)}, - null); + null);//查询条件:type符合,且不属于垃圾文件夹 boolean exist = false; if (cursor != null) { - if (cursor.getCount() > 0) { + if (cursor.getCount() > 0) {//用getcount函数判断cursor是否为空 exist = true; } cursor.close(); @@ -186,7 +187,7 @@ public class DataUtils { NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + " AND " + NoteColumns.SNIPPET + "=?", - new String[] { name }, null); + new String[] { name }, null); //通过名字查询文件是否存在 boolean exist = false; if(cursor != null) { if(cursor.getCount() > 0) { @@ -202,7 +203,7 @@ public class DataUtils { new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, NoteColumns.PARENT_ID + "=?", new String[] { String.valueOf(folderId) }, - null); + null);//查询条件:父ID是传入的folderId; HashSet set = null; if (c != null) { @@ -211,13 +212,13 @@ public class DataUtils { do { try { AppWidgetAttribute widget = new AppWidgetAttribute(); - widget.widgetId = c.getInt(0); - widget.widgetType = c.getInt(1); + widget.widgetId = c.getInt(0);//0对应的NoteColumns.WIDGET_ID + widget.widgetType = c.getInt(1);//1对应的NoteColumns.WIDGET_TYPE set.add(widget); } catch (IndexOutOfBoundsException e) { Log.e(TAG, e.toString()); } - } while (c.moveToNext()); + } while (c.moveToNext());//查询下一条 } c.close(); } @@ -250,11 +251,11 @@ public class DataUtils { + CallNote.PHONE_NUMBER + ",?)", new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, null); - + //通过数据库操作,查询条件是(callDate和phoneNumber匹配传入参数的值) if (cursor != null) { if (cursor.moveToFirst()) { try { - return cursor.getLong(0); + return cursor.getLong(0);//0对应的CallNote.NOTE_ID } catch (IndexOutOfBoundsException e) { Log.e(TAG, "Get call note id fails " + e.toString()); } @@ -269,7 +270,7 @@ public class DataUtils { new String [] { NoteColumns.SNIPPET }, NoteColumns.ID + "=?", new String [] { String.valueOf(noteId)}, - null); + null);//查询条件:noteId if (cursor != null) { String snippet = ""; @@ -282,7 +283,7 @@ public class DataUtils { throw new IllegalArgumentException("Note is not found with id: " + noteId); } - public static String getFormattedSnippet(String snippet) { + public static String getFormattedSnippet(String snippet) {//对字符串进行格式处理,将字符串两头的空格去掉,同时将换行符去掉 if (snippet != null) { snippet = snippet.trim(); int index = snippet.indexOf('\n'); diff --git a/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java index 666b729..e69b1d3 100644 --- a/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java @@ -14,9 +14,11 @@ * limitations under the License. */ +//简介:定义了很多的静态字符串,目的就是为了提供jsonObject中相应字符串的"key"。 package net.micode.notes.tool; public class GTaskStringUtils { + //这个类就是定义了一堆static string,实际就是为jsonObject提供Key,把这些定义全部写到一个类里,方便查看管理 public final static String GTASK_JSON_ACTION_ID = "action_id"; diff --git a/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..e8e9e03 100644 --- a/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -16,6 +16,20 @@ package net.micode.notes.tool; +/*简介:字面意义是资源分析器,实际上就是获取资源并且在程序中使用,比如颜色图片等 + * 实现方法:主要利用R.java这个类,其中包括 + * R.id 组件资源引用 + * R.drawable 图片资源 (被使用) + * R.layout 布局资源 + * R.menu 菜单资源 + * R.String 文字资源 + * R.style 主题资源 (被使用) + * 在按顺序设置好相应的id后,就可以编写简单的getXXX函数获取需要的资源 + * + * 特殊的变量 : + * @BG_DEFAULT_COLOR 默认背景颜色(黄) + * BG_DEFAULT_FONT_SIZE 默认文本大小(中) + */ import android.content.Context; import android.preference.PreferenceManager; @@ -64,7 +78,7 @@ 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)) { @@ -161,7 +175,7 @@ public class ResourceParser { R.style.TextAppearanceLarge, R.style.TextAppearanceSuper }; - + //这里有一个容错的函数,防止输入的id大于资源总量,若如此,则自动返回默认的设置结果 public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference.