diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..69b28af --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Notes/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/src/Notes/app/src/main/java/net/micode/notes/tool/BackupUtils.java index 39f6ec4..5b82242 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/BackupUtils.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/BackupUtils.java @@ -40,7 +40,7 @@ public class BackupUtils { private static final String TAG = "BackupUtils"; // Singleton stuff private static BackupUtils sInstance; - +//如果当前备份不存在,则新声明一个 public static synchronized BackupUtils getInstance(Context context) { if (sInstance == null) { sInstance = new BackupUtils(context); @@ -51,16 +51,17 @@ public class BackupUtils { /** * Following states are signs to represents backup or restore * status + * 以下状态表示备份或恢复 */ - // Currently, the sdcard is not mounted + // Currently, the sdcard is not mounted SD卡没有被装入手机 public static final int STATE_SD_CARD_UNMOUONTED = 0; - // The backup file not exist + // The backup file not exist 备份文件不存在 public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; - // The data is not well formated, may be changed by other programs + // The data is not well formated, may be changed by other programs 数据已被破坏,可能被修改 public static final int STATE_DATA_DESTROIED = 2; - // Some run-time exception which causes restore or backup fails + // Some run-time exception which causes restore or backup fails 超时异常 public static final int STATE_SYSTEM_ERROR = 3; - // Backup or restore success + // Backup or restore success 备份或还原成功 public static final int STATE_SUCCESS = 4; private TextExport mTextExport; @@ -72,34 +73,34 @@ public class BackupUtils { private static boolean externalStorageAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } - +//判断外部存储功能是否可用 public int exportToText() { return mTextExport.exportToText(); } - +//输出至文本 public String getExportedTextFileName() { return mTextExport.mFileName; } - +//获取输出的文本文件名 public String getExportedTextFileDir() { return mTextExport.mFileDirectory; } - - private static class TextExport { +//获取输出文本文件目录 + private static class TextExport {//内部类:文本输出定义笔记ID、修改日期等,笔记、内容、日期、电话号码的数据和格式等常量 private static final String[] NOTE_PROJECTION = { NoteColumns.ID, NoteColumns.MODIFIED_DATE, NoteColumns.SNIPPET, NoteColumns.TYPE }; - + //下面几行标识数组里属性值 private static final int NOTE_COLUMN_ID = 0; private static final int NOTE_COLUMN_MODIFIED_DATE = 1; private static final int NOTE_COLUMN_SNIPPET = 2; - private static final String[] DATA_PROJECTION = { + private static final String[] DATA_PROJECTION = {//字符串储存便签的基本信息 DataColumns.CONTENT, DataColumns.MIME_TYPE, DataColumns.DATA1, @@ -107,7 +108,7 @@ public class BackupUtils { DataColumns.DATA3, DataColumns.DATA4, }; - +//标识设定:数据内容标识为0;媒体类型标识为1;访问日期标识为2;电话号码标识为4; private static final int DATA_COLUMN_CONTENT = 0; private static final int DATA_COLUMN_MIME_TYPE = 1; @@ -115,17 +116,17 @@ public class BackupUtils { private static final int DATA_COLUMN_CALL_DATE = 2; private static final int DATA_COLUMN_PHONE_NUMBER = 4; - +//文档格式标识:名称标识为0;日期标识为1;内容标识为2 private final String [] TEXT_FORMAT; private static final int FORMAT_FOLDER_NAME = 0; private static final int FORMAT_NOTE_DATE = 1; private static final int FORMAT_NOTE_CONTENT = 2; - +//定义文件名、上下文、文件夹路径三个类 private Context mContext; private String mFileName; private String mFileDirectory; - public TextExport(Context context) { + public TextExport(Context context) {//从context获取便签的信息,并给其中一些成员赋予初值 TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); mContext = context; mFileName = ""; @@ -134,12 +135,13 @@ public class BackupUtils { private String getFormat(int id) { return TEXT_FORMAT[id]; - } + }//通过ID返回文件的格式信息 /** * Export the folder identified by folder id to text */ - private void exportFolderToText(String folderId, PrintStream ps) { + private void exportFolderToText(String folderId, PrintStream ps) {// + // 通过文件ID找到该文件下的便签,并且打印出该便签最后修改的日期,并且将该便签的内容输出并显示出来。 // Query notes belong to this folder Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { @@ -166,6 +168,7 @@ public class BackupUtils { * Export note identified by id to a print stream */ private void exportNoteToText(String noteId, PrintStream ps) { + //将便签的内容以文本的形式显示在屏幕上。比如电话号码、打电话的日期等。 Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { noteId @@ -206,7 +209,7 @@ public class BackupUtils { dataCursor.close(); } // print a line separator between note - try { + try {//在note下面输出一条线 ps.write(new byte[] { Character.LINE_SEPARATOR, Character.LETTER_NUMBER }); @@ -218,26 +221,26 @@ public class BackupUtils { /** * Note will be exported as text which is user readable */ - public int exportToText() { - if (!externalStorageAvailable()) { + public int exportToText() {//将note里面的内容输出到用户的屏幕 + if (!externalStorageAvailable()) {//检查外部设备安装情况 Log.d(TAG, "Media was not mounted"); return STATE_SD_CARD_UNMOUONTED; } PrintStream ps = getExportToTextPrintStream(); if (ps == null) { - Log.e(TAG, "get print stream error"); + Log.e(TAG, "get print stream error");//先导出对应的目录,然后导出对应的便签 return STATE_SYSTEM_ERROR; } // First export folder and its notes - Cursor folderCursor = mContext.getContentResolver().query( + Cursor folderCursor = mContext.getContentResolver().query(//定位需要导出的文件夹 Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); - if (folderCursor != null) { + if (folderCursor != null) {//导出文件夹,把里面的便签导出来 if (folderCursor.moveToFirst()) { do { // Print folder's name @@ -258,13 +261,13 @@ public class BackupUtils { } // Export notes in root's folder - Cursor noteCursor = mContext.getContentResolver().query( + Cursor noteCursor = mContext.getContentResolver().query(//输出根目录下的便签 Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID + "=0", null, null); - if (noteCursor != null) { + if (noteCursor != null) {//输出修改的时间 if (noteCursor.moveToFirst()) { do { ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( @@ -285,17 +288,17 @@ public class BackupUtils { /** * Get a print stream pointed to the file {@generateExportedTextFile} */ - private PrintStream getExportToTextPrintStream() { + private PrintStream getExportToTextPrintStream() {//获取指向文件的打印流 File file = generateFileMountedOnSDcard(mContext, R.string.file_path, R.string.file_name_txt_format); if (file == null) { Log.e(TAG, "create file to exported failed"); return null; - } - mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); + }//初始化储存在SD卡中的文件,如果为空,创造失败 + mFileName = file.getName();//得到文件名 + mFileDirectory = mContext.getString(R.string.file_path);//得到文件路径 PrintStream ps = null; - try { + try {//将ps输出流输出到特定的文件,目的就是导出到文件,而不是直接输出 FileOutputStream fos = new FileOutputStream(file); ps = new PrintStream(fos); } catch (FileNotFoundException e) { @@ -313,6 +316,7 @@ public class BackupUtils { * Generate the text file to store imported data */ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { + //生成存储文件,安装在SD卡上 StringBuilder sb = new StringBuilder(); sb.append(Environment.getExternalStorageDirectory()); sb.append(context.getString(filePathResId)); @@ -323,7 +327,7 @@ public class BackupUtils { System.currentTimeMillis()))); File file = new File(sb.toString()); - try { + try {//如果这些文件不存在,则新建 if (!filedir.exists()) { filedir.mkdir(); } diff --git a/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java b/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java index 2a14982..f1b6ddc 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -35,10 +35,10 @@ import java.util.ArrayList; import java.util.HashSet; -public class DataUtils { +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) {//判断笔记是否为空 Log.d(TAG, "the ids is null"); return true; } @@ -48,23 +48,23 @@ public class DataUtils { } ArrayList operationList = new ArrayList(); - for (long id : ids) { + for (long id : ids) {//遍历便签id if(id == Notes.ID_ROOT_FOLDER) { - Log.e(TAG, "Don't delete system folder root"); + Log.e(TAG, "Don't delete system folder root");//.如果是根目录的文件夹,输出Don't delete system folder root continue; } - ContentProviderOperation.Builder builder = ContentProviderOperation + ContentProviderOperation.Builder builder = ContentProviderOperation//批量的删除对应的ID .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); operationList.add(builder.build()); } - try { + try {//返回被删除的数据,如果返回为空则删除失败返回false,打印异常信息,删除成功返回true ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); 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) { Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); @@ -73,6 +73,7 @@ public class DataUtils { } 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); @@ -80,7 +81,7 @@ public class DataUtils { resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } - public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, + public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids,//批量移动 long folderId) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -88,7 +89,7 @@ public class DataUtils { } ArrayList operationList = new ArrayList(); - for (long id : ids) { + for (long id : ids) {//遍历便签ID ContentProviderOperation.Builder builder = ContentProviderOperation .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); builder.withValue(NoteColumns.PARENT_ID, folderId); @@ -96,7 +97,7 @@ public class DataUtils { operationList.add(builder.build()); } - try { + try {//错误检测 ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); if (results == null || results.length == 0 || results[0] == null) { Log.d(TAG, "delete notes failed, ids:" + ids.toString()); @@ -114,7 +115,7 @@ public class DataUtils { /** * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} */ - public static int getUserFolderCount(ContentResolver resolver) { + public static int getUserFolderCount(ContentResolver resolver) {//得到文件夹数目 Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, new String[] { "COUNT(*)" }, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", @@ -136,14 +137,14 @@ public class DataUtils { return count; } - public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { + public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {//在数据库中是否可见 Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, new String [] {String.valueOf(type)}, null); - boolean exist = false; + boolean exist = false;//判断note是否在数据库中,并返回相应的布尔值 if (cursor != null) { if (cursor.getCount() > 0) { exist = true; @@ -153,7 +154,7 @@ public class DataUtils { return exist; } - public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { + public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {//通过便签ID搜索,判断该note是否在数据库中存在 Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, null, null, null); @@ -167,7 +168,7 @@ public class DataUtils { return exist; } - public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { + public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {//通过名字查询是否在数据库中存在 Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null, null, null, null); @@ -181,7 +182,7 @@ public class DataUtils { return exist; } - public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { + public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {//检查文件名以获取文件是否存在 Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + @@ -197,7 +198,7 @@ public class DataUtils { return exist; } - public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { + public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) {//获得文件夹窗口小部件 Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, NoteColumns.PARENT_ID + "=?", @@ -209,12 +210,12 @@ public class DataUtils { if (c.moveToFirst()) { set = new HashSet(); do { - try { + try {//把每一个条目对应的窗口id和type记录下来,放到set里面。 AppWidgetAttribute widget = new AppWidgetAttribute(); widget.widgetId = c.getInt(0); widget.widgetType = c.getInt(1); set.add(widget); - } catch (IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) {//当下标超过边界,那么返回错误 Log.e(TAG, e.toString()); } } while (c.moveToNext()); @@ -224,14 +225,14 @@ public class DataUtils { return set; } - public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { + public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {//通过笔记ID获取号码 Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.PHONE_NUMBER }, CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, null); - if (cursor != null && cursor.moveToFirst()) { + if (cursor != null && cursor.moveToFirst()) {//获取电话号码,并处理异常 try { return cursor.getString(0); } catch (IndexOutOfBoundsException e) { @@ -243,7 +244,7 @@ public class DataUtils { return ""; } - public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { + public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {//通过号码和日期获取ID Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.NOTE_ID }, CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" @@ -264,7 +265,7 @@ public class DataUtils { return 0; } - public static String getSnippetById(ContentResolver resolver, long noteId) { + public static String getSnippetById(ContentResolver resolver, long noteId) {//通过Note的Id获取Note的片段 Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, new String [] { NoteColumns.SNIPPET }, NoteColumns.ID + "=?", @@ -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/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java index 666b729..248e550 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java @@ -17,7 +17,8 @@ package net.micode.notes.tool; public class GTaskStringUtils { - +//定义了很多的静态字符串,目的就是为了提供jsonObject中相应字符串的"key" + //把这些静态的定义单独写到了一个类里面,是非常好的编程规范 public final static String GTASK_JSON_ACTION_ID = "action_id"; public final static String GTASK_JSON_ACTION_LIST = "action_list"; diff --git a/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..e5c0131 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -23,7 +23,7 @@ import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; public class ResourceParser { - +//ResourceParser类,资源分析,实际上就是获取资源并且在程序中使用,比如图片资源、布局资源、字体大小等 public static final int YELLOW = 0; public static final int BLUE = 1; public static final int WHITE = 2; @@ -39,7 +39,7 @@ public class ResourceParser { public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; - public static class NoteBgResources { + public static class NoteBgResources {//背景资源的获取 private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, R.drawable.edit_blue, @@ -59,13 +59,13 @@ public class ResourceParser { public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } - +//获取Note的背景颜色 public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } - - public static int getDefaultBgId(Context context) { +//ID可以查找到编辑框的颜色的地址 + public static int getDefaultBgId(Context context) {//直接获取默认的背景颜色 if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length); @@ -74,7 +74,7 @@ public class ResourceParser { } } - public static class NoteItemBgResources { + public static class NoteItemBgResources {//便签背景资源类 private final static int [] BG_FIRST_RESOURCES = new int [] { R.drawable.list_yellow_up, R.drawable.list_blue_up, @@ -128,8 +128,8 @@ public class ResourceParser { } } - public static class WidgetBgResources { - private final static int [] BG_2X_RESOURCES = new int [] { + public static class WidgetBgResources {//获取图片资源类 + private final static int [] BG_2X_RESOURCES = new int [] {//通过id获得2x的小窗口背景资源 R.drawable.widget_2x_yellow, R.drawable.widget_2x_blue, R.drawable.widget_2x_white, @@ -140,7 +140,7 @@ public class ResourceParser { public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } - +//通过ID获取较小的图片 private final static int [] BG_4X_RESOURCES = new int [] { R.drawable.widget_4x_yellow, R.drawable.widget_4x_blue, @@ -153,7 +153,7 @@ public class ResourceParser { return BG_4X_RESOURCES[id]; } } - +//根据ID加载BG_4X_RESOURCES数组里的颜色资源序号。 public static class TextAppearanceResources { private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { R.style.TextAppearanceNormal, @@ -161,7 +161,7 @@ public class ResourceParser { R.style.TextAppearanceLarge, R.style.TextAppearanceSuper }; - +//文本外观资源,包括默认字体,以及获取资源大小 public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference. @@ -173,9 +173,10 @@ public class ResourceParser { } return TEXTAPPEARANCE_RESOURCES[id]; } - +//防止输入的id大于资源总量,若如此,则自动返回默认的设置结果 public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; } } } +//直接返回为资源的长度 \ No newline at end of file