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 9c6fa62..b132d43 100644 --- a/app/src/main/java/net/micode/notes/data/Contact.java +++ b/app/src/main/java/net/micode/notes/data/Contact.java @@ -36,15 +36,23 @@ public class Contact { + " FROM phone_lookup" + " WHERE min_match = '+')"; + + /** + * 判断是否存在映射关系 + * 若不存在,创建并存储在哈希表中 + */ public static String getContact(Context context, String phoneNumber) { if (sContactCache == null) { sContactCache = new HashMap(); } - + // 查找HashMap中是否已有phoneNumber信息,如果存在则返回phoneNumber信息 if (sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } + /** + * 查找数据库中phoneNumber的信息 + */ String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); Cursor cursor = context.getContentResolver().query( @@ -54,12 +62,22 @@ public class Contact { new String[]{phoneNumber}, null); + /** + * 判定查询结果,若不为空,moveToFirst()返回第一条;否则返回空 + */ if (cursor != null && cursor.moveToFirst()) { + /** + * 找到相关情况时 + */ try { String name = cursor.getString(0); sContactCache.put(phoneNumber, name); return name; - } catch (IndexOutOfBoundsException e) { + } + /** + * 异常 + */ + catch (IndexOutOfBoundsException e) { Log.e(TAG, " Cursor get string error " + e.toString()); return null; } finally { diff --git a/app/src/main/java/net/micode/notes/data/Notes.java b/app/src/main/java/net/micode/notes/data/Notes.java index 87e60c3..af04c10 100644 --- a/app/src/main/java/net/micode/notes/data/Notes.java +++ b/app/src/main/java/net/micode/notes/data/Notes.java @@ -67,6 +67,9 @@ public class Notes { */ public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); + /** + * 定义了NoteColumns中的常量,将用于后面创建数据库的表头 + */ public interface NoteColumns { /** * The unique ID for a row @@ -172,6 +175,9 @@ public class Notes { */ public static final String VERSION = "version"; } + /** + * 以上这些常量主要是用于定义便签的属性 + */ public interface DataColumns { /** @@ -245,7 +251,9 @@ public class Notes { *

Type: TEXT

*/ public static final String DATA5 = "data5"; - } + }/** + * 以上DATA主要是定义存储便签内容数据 + */ public static final class TextNote implements DataColumns { /** @@ -261,7 +269,9 @@ public class Notes { public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); - } + }/** + * 文本内容的数据结构 + */ public static final class CallNote implements DataColumns { /** @@ -281,5 +291,7 @@ public class Notes { public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); - } + }/** + * 电话内容的数据结构 + */ } diff --git a/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java index c7d668e..ef7bb4e 100644 --- a/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -26,7 +26,9 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; - +/** + *数据库操作,对一些note和文件进行数据库的操作。 + */ public class NotesDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "note.db"; @@ -42,6 +44,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { private static NotesDatabaseHelper mInstance; + /** + * 创建数据库中需要存储的项目的名称 + */ private static final String CREATE_NOTE_TABLE_SQL = "CREATE TABLE " + TABLE.NOTE + "(" + NoteColumns.ID + " INTEGER PRIMARY KEY," + @@ -63,6 +68,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + ")"; + /** + * 功能同上,但存储的项目类型不同 + */ private static final String CREATE_DATA_TABLE_SQL = "CREATE TABLE " + TABLE.DATA + "(" + DataColumns.ID + " INTEGER PRIMARY KEY," + @@ -78,12 +86,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + ")"; + /** + * 创建用来存储便签编号的数据表格 + */ private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = "CREATE INDEX IF NOT EXISTS note_id_index ON " + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; /** * Increase folder's note count when move note to the folder + * 在文件夹中移入一个Note之后需要更改的数据的表格。 */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER increase_folder_count_on_update " + @@ -96,6 +108,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when move note from folder + * 在文件夹中移出一个Note之后需要更改的数据的表格。 */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_update " + @@ -109,6 +122,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Increase folder's note count when insert new note to the folder + * 在文件夹中插入一个Note之后需要更改的数据的表格。 */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = "CREATE TRIGGER increase_folder_count_on_insert " + @@ -121,6 +135,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when delete note from the folder + * 在文件夹中删除一个Note之后需要更改的数据的表格。 */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_delete " + @@ -134,6 +149,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when insert data with type {@link DataConstants#NOTE} + * 在文件夹中对一个Note导入新的数据之后需要更改的数据的表格。 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + @@ -147,6 +163,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when data with {@link DataConstants#NOTE} type has changed + * Note数据被修改后需要更改的数据的表格。 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + @@ -160,6 +177,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when data with {@link DataConstants#NOTE} type has deleted + * Note数据被删除后需要更改的数据的表格 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + @@ -173,6 +191,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * 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 " + @@ -184,6 +203,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * 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 " + @@ -208,8 +228,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); - } + }/**构造函数,传入数据库的名称和版本*/ + /** + *创建表格(用来存储标签属性) + */ public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); reCreateNoteTableTriggers(db); @@ -217,6 +240,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } + /** + * 用来重新创建上述定义的表格用的,先删除原来有的数据库的触发器再重新创建新的数据库 + */ private void reCreateNoteTableTriggers(SQLiteDatabase db) { db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update"); @@ -294,6 +320,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { return mInstance; } + /** + * 实现上面创建的两个表格 + */ @Override public void onCreate(SQLiteDatabase db) { createNoteTable(db); diff --git a/app/src/main/java/net/micode/notes/data/NotesProvider.java b/app/src/main/java/net/micode/notes/data/NotesProvider.java index 51d2ff9..b0f43a0 100644 --- a/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/app/src/main/java/net/micode/notes/data/NotesProvider.java @@ -35,6 +35,15 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; +/** + * 为存储和获取数据提供接口。可以在不同的应用程序之间共享数据 + * ContentProvider提供的方法 + * query:查询 + * insert:插入 + * update:更新 + * delete:删除 + * getType:得到数据类型 + */ public class NotesProvider extends ContentProvider { private static final UriMatcher mMatcher; @@ -79,12 +88,19 @@ public class NotesProvider extends ContentProvider { + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; + /** + * 只在onCreate()中初始化Context + * 对mHelper进行实例化 + */ @Override public boolean onCreate() { mHelper = NotesDatabaseHelper.getInstance(getContext()); return true; } + /** + *查询uri在数据库中对应的位置 + */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { @@ -112,6 +128,9 @@ public class NotesProvider extends ContentProvider { break; case URI_SEARCH: case URI_SEARCH_SUGGEST: + /** + * 不合法的参数异常 + */ if (sortOrder != null || projection != null) { throw new IllegalArgumentException( "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); @@ -147,6 +166,9 @@ public class NotesProvider extends ContentProvider { return c; } + /** + * 插入一个uri + */ @Override public Uri insert(Uri uri, ContentValues values) { SQLiteDatabase db = mHelper.getWritableDatabase(); @@ -181,6 +203,9 @@ public class NotesProvider extends ContentProvider { return ContentUris.withAppendedId(uri, insertedId); } + /** + * 删除一个uri + */ @Override public int delete(Uri uri, String selection, String[] selectionArgs) { int count = 0; @@ -227,6 +252,9 @@ public class NotesProvider extends ContentProvider { return count; } + /** + * 更新一个uri + */ @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int count = 0; @@ -267,6 +295,9 @@ public class NotesProvider extends ContentProvider { return count; } + /** + *将字符串解析成规定格式 + */ private String parseSelection(String selection) { return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } @@ -292,7 +323,7 @@ public class NotesProvider extends ContentProvider { } sql.append(selectString); } - + /** execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 */ mHelper.getWritableDatabase().execSQL(sql.toString()); } diff --git a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/app/src/main/java/net/micode/notes/gtask/data/MetaData.java index fc75821..2fb1601 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java +++ b/app/src/main/java/net/micode/notes/gtask/data/MetaData.java @@ -27,7 +27,7 @@ import org.json.JSONObject; public class MetaData extends Task { /* - * 功能:得到类的简写名称存入字符串TAG中 + * 功能:得到类的简称存入字符串TAG中 * 过程:调用getSimpleName ()函数 */ private final static String TAG = MetaData.class.getSimpleName(); diff --git a/app/src/main/java/net/micode/notes/gtask/data/Node.java b/app/src/main/java/net/micode/notes/gtask/data/Node.java index 63950e0..31f5be8 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Node.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Node.java @@ -20,6 +20,9 @@ import android.database.Cursor; import org.json.JSONObject; +/** + * 定义了一些有关同步操作的常量,Node为同步操作的基础类 + */ public abstract class Node { public static final int SYNC_ACTION_NONE = 0; diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/app/src/main/java/net/micode/notes/gtask/data/SqlData.java index 211eba2..72871ea 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java +++ b/app/src/main/java/net/micode/notes/gtask/data/SqlData.java @@ -34,7 +34,9 @@ import net.micode.notes.gtask.exception.ActionFailureException; import org.json.JSONException; import org.json.JSONObject; - +/** + * 功能:支持最底层的数据库操作,在逻辑关系上是Sqldata是Node类的子集 + */ public class SqlData { private static final String TAG = SqlData.class.getSimpleName(); diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java index 3ff745e..202b72a 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java +++ b/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java @@ -37,7 +37,9 @@ import org.json.JSONObject; import java.util.ArrayList; - +/** + * 功能:支持最底层的数据库操作,从SqlData中具体出的便签类数据,是真正意义上的便签数据 + */ public class SqlNote { private static final String TAG = SqlNote.class.getSimpleName(); diff --git a/app/src/main/java/net/micode/notes/gtask/data/Task.java b/app/src/main/java/net/micode/notes/gtask/data/Task.java index 6a19454..6207612 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Task.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Task.java @@ -31,7 +31,9 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; - +/** + * 与Node是父子关系,继承了原有的属性和方法,并在此基础上定义更加具体的功能 + */ public class Task extends Node { private static final String TAG = Task.class.getSimpleName(); diff --git a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/app/src/main/java/net/micode/notes/gtask/data/TaskList.java index 4ea21c5..0f5dbe9 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java +++ b/app/src/main/java/net/micode/notes/gtask/data/TaskList.java @@ -29,12 +29,16 @@ import org.json.JSONObject; import java.util.ArrayList; - +/** + * 继承自Node,拓展了一些有关Task列表的基础操作 + */ public class TaskList extends Node { private static final String TAG = TaskList.class.getSimpleName(); private int mIndex; - + /* + * 创建一个以Task为基本元素的ArrayList + */ private ArrayList mChildren; public TaskList() { 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); diff --git a/app/src/main/java/net/micode/notes/model/WorkingNote.java b/app/src/main/java/net/micode/notes/model/WorkingNote.java index 12079de..e999d6a 100644 --- a/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -62,6 +62,9 @@ public class WorkingNote { private NoteSettingChangedListener mNoteSettingStatusListener; + /** + * 声明 DATA_PROJECTION字符串数组 + */ public static final String[] DATA_PROJECTION = new String[]{ DataColumns.ID, DataColumns.CONTENT, @@ -102,6 +105,10 @@ public class WorkingNote { private static final int NOTE_MODIFIED_DATE_COLUMN = 5; // New note construct + + /** + * WorkingNote的构造函数 + * */ private WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; @@ -124,6 +131,9 @@ public class WorkingNote { loadNote(); } + /** + * 通过数据库调用query函数找到第一个条目 + */ private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, @@ -151,7 +161,9 @@ public class WorkingNote { DataColumns.NOTE_ID + "=?", new String[]{ String.valueOf(mNoteId) }, null); - +/** + * 查看第一项是否存在 + */ if (cursor != null) { if (cursor.moveToFirst()) { do { @@ -174,6 +186,9 @@ public class WorkingNote { } } + /** + * 创建空的Note 传参:context,文件夹id,widget,背景颜色 + */ public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); @@ -229,6 +244,10 @@ public class WorkingNote { mNoteSettingStatusListener = l; } + /** + * 设置AlertDate + * 若 mAlertDate与data不同,则更改mAlertDate并设定NoteValue + */ public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -239,6 +258,9 @@ public class WorkingNote { } } + /** + * 设定删除标记 + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -247,6 +269,9 @@ public class WorkingNote { } } + /** + *设定背景颜色 + */ public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -257,6 +282,9 @@ public class WorkingNote { } } + /** + *设定检查列表模式 + */ public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -267,6 +295,9 @@ public class WorkingNote { } } + /** + *设定WidgetType + */ public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -274,6 +305,9 @@ public class WorkingNote { } } + /** + *设定WidgetId + */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -281,6 +315,9 @@ public class WorkingNote { } } + /** + *设定setWorkingText + */ public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; diff --git a/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/app/src/main/java/net/micode/notes/tool/BackupUtils.java index d2f3d68..6d8ea0a 100644 --- a/app/src/main/java/net/micode/notes/tool/BackupUtils.java +++ b/app/src/main/java/net/micode/notes/tool/BackupUtils.java @@ -40,9 +40,13 @@ public class BackupUtils { private static final String TAG = "BackupUtils"; // Singleton stuff private static BackupUtils sInstance; - + /* + * synchronized关键字代表该方法加锁: + * 任何一个线程运行到该方法都得检测是否在其它线程运用到了该方法 + */ public static synchronized BackupUtils getInstance(Context context) { if (sInstance == null) { + //如果当前备份缺失,则重新定义一个 sInstance = new BackupUtils(context); } return sInstance; @@ -67,12 +71,16 @@ public class BackupUtils { private BackupUtils(Context context) { mTextExport = new TextExport(context); - } - + }//构造函数 + /* + * 判断外部存储功能是否可用 + */ private static boolean externalStorageAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } - + /* + * 获取有关文本的一些信息 + */ public int exportToText() { return mTextExport.exportToText(); } @@ -322,7 +330,9 @@ public class BackupUtils { DateFormat.format(context.getString(R.string.format_date_ymd), System.currentTimeMillis()))); File file = new File(sb.toString()); - + /* + * 如果文件不存在则抛出异常 + */ try { if (!filedir.exists()) { filedir.mkdir(); diff --git a/app/src/main/java/net/micode/notes/tool/DataUtils.java b/app/src/main/java/net/micode/notes/tool/DataUtils.java index 378bfb2..18701dc 100644 --- a/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -34,10 +34,16 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; +/** + * 数据工具包 + * 功能:定义了一些用来处理便签数据的方法(包括删除、转移、计数、查找、校验)以及异常处理 + */ public class DataUtils { public static final String TAG = "DataUtils"; - + /* + * 此方法用于批删除便签(包括一些特殊情况的处理) + */ public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -50,6 +56,7 @@ public class DataUtils { ArrayList operationList = new ArrayList(); for (long id : ids) { + //若发现是根文件则跳过此执行语句 if (id == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Don't delete system folder root"); continue; @@ -73,6 +80,9 @@ public class DataUtils { return false; } + /** + * 移动便签到文件夹 + */ public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { ContentValues values = new ContentValues(); values.put(NoteColumns.PARENT_ID, desFolderId); @@ -81,6 +91,9 @@ public class DataUtils { resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } + /** + * 脚本移动到文件夹中 + */ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { if (ids == null) { @@ -96,7 +109,7 @@ public class DataUtils { builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); operationList.add(builder.build()); } - + //异常捕获 try { ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); if (results == null || results.length == 0 || results[0] == null) { diff --git a/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java index 666b729..a9e2f17 100644 --- a/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java @@ -16,6 +16,9 @@ package net.micode.notes.tool; +/** + * 定义了一些静态字符串常量,为jsonObject提供了键,是一种编程规范 + */ public class GTaskStringUtils { public final static String GTASK_JSON_ACTION_ID = "action_id"; diff --git a/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/app/src/main/java/net/micode/notes/tool/ResourceParser.java index ea5fc30..09c8fb8 100644 --- a/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -22,6 +22,10 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.activities.NotesPreferenceActivity; +/** + * 资源分析器 + * 功能:获取资源并将其应用的进程中 + */ public class ResourceParser { public static final int YELLOW = 0; diff --git a/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java index 779ca0f..008dab6 100644 --- a/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java +++ b/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java @@ -34,6 +34,9 @@ import net.micode.notes.data.Notes.NoteColumns; public class AlarmInitReceiver extends BroadcastReceiver { // 数据格式封包 + /** + * 对数据库的操作,调用标签ID和闹钟时间 + */ private static final String[] PROJECTION = new String[]{ NoteColumns.ID, NoteColumns.ALERTED_DATE @@ -46,11 +49,21 @@ public class AlarmInitReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { long currentDate = System.currentTimeMillis(); + /** + * System.currentTimeMillis()产生一个当前的毫秒 + * 这个毫秒其实就是自1970年1月1日0时起的毫秒数 + */ Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE, new String[]{String.valueOf(currentDate)}, + /** + * 将long变量currentDate转化为字符串 + */ null); + /** + * Cursor在这里的作用是通过查找数据库中的标签内容,找到和当前系统时间相等的标签 + */ if (c != null) { if (c.moveToFirst()) { @@ -66,5 +79,10 @@ public class AlarmInitReceiver extends BroadcastReceiver { } c.close(); } + /** + * 然而通过网上查找资料发现,对于闹钟机制的启动,通常需要上面的几个步骤 + * 如新建Intent、PendingIntent以及AlarmManager等 + * 这里就是根据数据库里的闹钟时间创建一个闹钟机制 + */ } } diff --git a/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java b/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java index 27cefef..27db98e 100644 --- a/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java +++ b/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java @@ -30,7 +30,18 @@ public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { intent.setClass(context, AlarmAlertActivity.class); + /** + * 启动AlarmAlertActivity + */ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + /** + * activity要存在于activity的栈中,而非activity的途径启动activity时必然不存在一个activity的栈 + * 所以要新起一个栈装入启动的activity + */ context.startActivity(intent); } } +/** + * 这是实现alarm这个功能最接近用户层的包,基于上面的两个包, + * 作用还需要深究但是对于setClass和addFlags的 + */ \ No newline at end of file diff --git a/app/src/main/java/net/micode/notes/ui/DateTimePicker.java b/app/src/main/java/net/micode/notes/ui/DateTimePicker.java index a189109..0461b24 100644 --- a/app/src/main/java/net/micode/notes/ui/DateTimePicker.java +++ b/app/src/main/java/net/micode/notes/ui/DateTimePicker.java @@ -32,7 +32,10 @@ import android.widget.NumberPicker; * 日期选择器,是 [FrameLayout] 的子类 */ public class DateTimePicker extends FrameLayout { - + /** + * FrameLayout是布局模板之一 + * 所有的子元素全部在屏幕的右上方 + */ private static final boolean DEFAULT_ENABLE_STATE = true; /** @@ -73,6 +76,10 @@ public class DateTimePicker extends FrameLayout { /** * 日期实例对象 */ + /** + * NumberPicker是数字选择器 + * 这里定义的四个变量全部是在设置闹钟时需要选择的变量(如日期、时、分、上午或者下午) + */ private Calendar mDate; /** * 日期显示的数值 @@ -120,6 +127,10 @@ public class DateTimePicker extends FrameLayout { * 在数值改变时传入选择器对象和操作前与操作后的数值 * 对数值进行具体的分析 */ + /** + * OnValueChangeListener,这是时间改变监听器,这里主要是对日期的监听 + * 将现在日期的值传递给mDate;updateDateControl是同步操作 + */ private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { diff --git a/local.properties b/local.properties index 9c9a286..d595b42 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Fri Apr 14 13:58:58 CST 2023 -sdk.dir=C\:\\Users\\MikkoAyaka\\AppData\\Local\\Android\\Sdk +#Fri Mar 31 16:29:58 CST 2023 +sdk.dir=D\:\\android studio SDK