();
}
- if(sContactCache.containsKey(phoneNumber)) {
+ if(sContactCache.containsKey(phoneNumber)) /**查找cache中是否有phoneNumber对应的联系人信息**/{
return sContactCache.get(phoneNumber);
}
String selection = CALLER_ID_SELECTION.replace("+",
- PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
+ PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));/**toCallerIDMinMatch是安卓自带的号码匹配工具,截取查询号码的后7位作为匹配依据**/
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
- new String [] { Phone.DISPLAY_NAME },
- selection,
+ new String [] { Phone.DISPLAY_NAME },/**这个参数告诉查询要返回的列(Column),Contacts Provider提供了联系人的ID和联系人的NAME等内容,在这里,我们只需要NAME,所以提供这个参数DISPLAY_NAME**/
+ selection,/**selection,设置条件,相当于SQL语句中的where**/
new String[] { phoneNumber },
null);
- if (cursor != null && cursor.moveToFirst()) {
- try {
+ if (cursor != null && cursor.moveToFirst()) {/**若数据库存在,则游标移动到游标所表示的信息元组的第一行开始**/
+ try {/**联系人姓名,并将相关信息存入cache中**/
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;
+ return null;/**引入的util.log就是java自带的日志输出工具,而log.e则代表error,显示的颜色为红色**/
} finally {
- cursor.close();
+ cursor.close();/**关闭cursor游标**/
}
} else {
Log.d(TAG, "No contact matched with number:" + phoneNumber);
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/data/Notes.java b/src/Notes-master3/app/src/main/java/net/micode/notes/data/Notes.java
index f240604..e148c0f 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/data/Notes.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/data/Notes.java
@@ -25,10 +25,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
+ * 下面的id是系统文件夹的标识符
+ * {@link Notes#ID_ROOT_FOLDER } 是默认文件夹
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
- * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
+ * {@link Notes#ID_CALL_RECORD_FOLDER} 是存储通话记录
*/
public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1;
@@ -52,190 +52,190 @@ public class Notes {
}
/**
- * Uri to query all notes and folders
+ Uri查询所有笔记和文件夹
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
- * Uri to query data
+ * Uri用于查询数据
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
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";
/**
- * 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
+ * Note的小部件id
* Type: INTEGER (long)
*/
public static final String WIDGET_ID = "widget_id";
/**
- * Note's widget type
+ * Note的小部件类型
* 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";
/**
- * The gtask id
+ * gtask id
* Type : TEXT
*/
public static final String GTASK_ID = "gtask_id";
/**
* The version code
- * Type : INTEGER (long)
+ * * Type : INTEGER (long)
*/
public static final String VERSION = "version";
}
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}特定的,用于
+ 整数数据类型
* Type: INTEGER
*/
public static final String DATA1 = "data1";
/**
- * Generic data column, the meaning is {@link #MIMETYPE} specific, used for
- * integer data type
+ *泛型数据列,含义是{@link #MIMETYPE}特定的,用于
+ 整数数据类型
* Type: INTEGER
*/
public static final String DATA2 = "data2";
/**
- * Generic data column, the meaning is {@link #MIMETYPE} specific, used for
- * TEXT data type
+ *泛型数据列,含义是{@link #MIMETYPE}特定的,用于
+ * TEXT数据类型
* Type: TEXT
*/
public static final String DATA3 = "data3";
/**
- * Generic data column, the meaning is {@link #MIMETYPE} specific, used for
- * TEXT data type
+ *泛型数据列,含义是{@link #MIMETYPE}特定的,用于
+ * TEXT数据类型
* Type: TEXT
*/
public static final String DATA4 = "data4";
/**
- * Generic data column, the meaning is {@link #MIMETYPE} specific, used for
- * TEXT data type
+ *泛型数据列,含义是{@link #MIMETYPE}特定的,用于
+ * TEXT数据类型
* Type: TEXT
*/
public static final String DATA5 = "data5";
@@ -243,7 +243,7 @@ public class Notes {
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;
@@ -259,13 +259,13 @@ public class Notes {
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-master3/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java
index ffe5d57..2ebd68e 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java
@@ -14,7 +14,8 @@
* limitations under the License.
*/
-package net.micode.notes.data;
+package net.micode.notes.data;/**1.数据库操作,SQLOpenhelper,对一些note和文件进行数据库的操作。比如删除文件后,将文件里的note也相应删除**/
+
import android.content.ContentValues;
import android.content.Context;
@@ -27,13 +28,14 @@ import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
-public class NotesDatabaseHelper extends SQLiteOpenHelper {
- private static final String DB_NAME = "note.db";
+public class NotesDatabaseHelper extends SQLiteOpenHelper {/**2.继承于SQLiteOpenHelper的类NotesDatabaseHelper,用于实现对便签或者 文件的数据库操作,例如删除便签**/
+
+ private static final String DB_NAME = "note.db";/**2.定义数据库的名称为“note.db”**/
private static final int DB_VERSION = 4;
- public interface TABLE {
- public static final String NOTE = "note";
+ public interface TABLE {/**1.接口,分成note和data,在后面的程序里分别使用过**/
+ public static final String NOTE = "note";/**2.数据库中创建的note表信息**/
public static final String DATA = "data";
}
@@ -42,7 +44,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static NotesDatabaseHelper mInstance;
- private static final String CREATE_NOTE_TABLE_SQL =
+ private static final String CREATE_NOTE_TABLE_SQL = /**1.SQL的触发器是一个能由系统自动执行对数据库修改的语句,由文件的增加事件触发。文件夹中移入一个Note之后需要更改的数据的表格。**/
"CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
@@ -63,7 +65,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
- private static final String CREATE_DATA_TABLE_SQL =
+ private static final String CREATE_DATA_TABLE_SQL =/**3. 创建SQL的data表。下面是表头**/
"CREATE TABLE " + TABLE.DATA + "(" +
DataColumns.ID + " INTEGER PRIMARY KEY," +
DataColumns.MIME_TYPE + " TEXT NOT NULL," +
@@ -78,14 +80,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
- private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
+ private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =/**1.文件夹移除note时触发垃圾回收**/
"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
*/
- private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
+ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =/**4. 构建一条SQL语句,实现当note移动到文件夹中时,文件夹的数量增加的功能**/
"CREATE TRIGGER increase_folder_count_on_update "+
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
" BEGIN " +
@@ -95,7 +97,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * 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 +110,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * 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 +122,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * 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 +135,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * Update note's content when insert data with type {@link DataConstants#NOTE}
+ *当插入类型为{@link DataConstants# note}的数据时,更新note的内容
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
@@ -146,7 +148,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * Update note's content when data with {@link DataConstants#NOTE} type has changed
+ *当{@link DataConstants# note}类型的数据发生变化时更新note的内容
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
@@ -159,7 +161,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * Update note's content when data with {@link DataConstants#NOTE} type has deleted
+ *当{@link DataConstants# note}类型的数据被删除时,更新note的内容
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
@@ -172,7 +174,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
- * 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 +185,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 +196,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 " +
@@ -239,14 +241,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
ContentValues values = new ContentValues();
/**
- * call record foler for call notes
+ *通话记录文件夹用于通话记录
*/
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);
@@ -254,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);
@@ -262,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);
@@ -270,14 +272,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
- public void createDataTable(SQLiteDatabase db) {
- db.execSQL(CREATE_DATA_TABLE_SQL);
+ public void createDataTable(SQLiteDatabase db) {/**1.创建表格(用来存储标签内容)
+**/
+ db.execSQL(CREATE_DATA_TABLE_SQL);
reCreateDataTableTriggers(db);
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);
Log.d(TAG, "data table has been created");
}
- private void reCreateDataTableTriggers(SQLiteDatabase db) {
+ private void reCreateDataTableTriggers(SQLiteDatabase db) {/**2. 重构数据库的data表单的触发器,防止定义冲突**/
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete");
@@ -292,15 +295,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
mInstance = new NotesDatabaseHelper(context);
}
return mInstance;
- }
+ }/**1.如果NotesDatabaseHelper的实例创建失败,那就重新建一个,重新分配内从空间**/
@Override
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);
createDataTable(db);
- }
+ }/**5. 在对象生命周期开始的时候,onCreate被系统调用,所以这里重写这个函数,生成两个数据库表单,一个是便签表单,另一个是数据表单**/
- @Override
+ @Override/**1.数据库版本的更新,包括数据库内容的更改**/
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
boolean skipV2 = false;
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesProvider.java b/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesProvider.java
index edb0a60..6897999 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesProvider.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/data/NotesProvider.java
@@ -1,22 +1,5 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package net.micode.notes.data;
-
import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentUris;
@@ -33,9 +16,15 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes.DataColumns;
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 {
+ // UriMatcher用于匹配Uri
private static final UriMatcher mMatcher;
private NotesDatabaseHelper mHelper;
@@ -51,7 +40,9 @@ public class NotesProvider extends ContentProvider {
private static final int URI_SEARCH_SUGGEST = 6;
static {
+ // 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+ // 把需要匹配Uri路径全部给注册上
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
@@ -65,33 +56,40 @@ 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.
*/
+ // 声明 NOTES_SEARCH_PROJECTION
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
- + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
- + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
- + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
- + R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
- + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
- + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
-
+ + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
+ + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
+ + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
+ + R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
+ + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
+ // 声明NOTES_SNIPPET_SEARCH_QUERY
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
- + " FROM " + TABLE.NOTE
- + " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
- + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
- + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
+ + " FROM " + TABLE.NOTE
+ + " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
@Override
+ // Context只有在onCreate()中才被初始化
+ // 对mHelper进行实例化
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
@Override
+ // 查询uri在数据库中对应的位置
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
- String sortOrder) {
+ String sortOrder) {
Cursor c = null;
+ // 获取可读数据库
SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null;
+ // 匹配查找uri
switch (mMatcher.match(uri)) {
+ // 对于不同的匹配值,在数据库中查找相应的条目
case URI_NOTE:
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder);
@@ -113,6 +111,7 @@ public class NotesProvider extends ContentProvider {
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");
}
@@ -120,6 +119,8 @@ public class NotesProvider extends ContentProvider {
String searchString = null;
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
if (uri.getPathSegments().size() > 1) {
+ // getPathSegments()方法得到一个String的List,
+ // 在uri.getPathSegments().get(1)为第2个元素
searchString = uri.getPathSegments().get(1);
}
} else {
@@ -139,6 +140,7 @@ public class NotesProvider extends ContentProvider {
}
break;
default:
+ // 抛出异常
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (c != null) {
@@ -148,13 +150,17 @@ public class NotesProvider extends ContentProvider {
}
@Override
+ // 插入一个uri
public Uri insert(Uri uri, ContentValues values) {
+ // 获得可写的数据库
SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) {
+ // 新增一个条目
case URI_NOTE:
insertedId = noteId = db.insert(TABLE.NOTE, null, values);
break;
+ // 如果存在,查找NOTE_ID
case URI_DATA:
if (values.containsKey(DataColumns.NOTE_ID)) {
noteId = values.getAsLong(DataColumns.NOTE_ID);
@@ -167,6 +173,7 @@ public class NotesProvider extends ContentProvider {
throw new IllegalArgumentException("Unknown URI " + uri);
}
// Notify the note uri
+ // notifyChange获得一个ContextResolver对象并且更新里面的内容
if (noteId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
@@ -178,13 +185,17 @@ public class NotesProvider extends ContentProvider {
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
}
+ // 返回插入的uri的路径
return ContentUris.withAppendedId(uri, insertedId);
}
@Override
+ // 删除一个uri
public int delete(Uri uri, String selection, String[] selectionArgs) {
+ //Uri代表要操作的数据,Android上可用的每种资源 -包括 图像、视频片段、音频资源等都可以用Uri来表示。
int count = 0;
String id = null;
+ // 获得可写的数据库
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean deleteData = false;
switch (mMatcher.match(uri)) {
@@ -228,6 +239,7 @@ public class NotesProvider extends ContentProvider {
}
@Override
+ // 更新一个uri
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
String id = null;
@@ -267,10 +279,12 @@ public class NotesProvider extends ContentProvider {
return count;
}
+ // 将字符串解析成规定格式
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
+ //增加一个noteVersion
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@@ -293,6 +307,7 @@ public class NotesProvider extends ContentProvider {
sql.append(selectString);
}
+ // execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句
mHelper.getWritableDatabase().execSQL(sql.toString());
}
@@ -302,4 +317,4 @@ public class NotesProvider extends ContentProvider {
return null;
}
-}
+}
\ No newline at end of file
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java b/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java
index d2b4082..a8c1f2a 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java
@@ -1,119 +1,73 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package net.micode.notes.gtask.remote;
-import android.app.Activity;
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.util.Log;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.data.MetaData;
-import net.micode.notes.gtask.data.Node;
-import net.micode.notes.gtask.data.SqlNote;
-import net.micode.notes.gtask.data.Task;
-import net.micode.notes.gtask.data.TaskList;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.gtask.exception.NetworkFailureException;
-import net.micode.notes.tool.DataUtils;
-import net.micode.notes.tool.GTaskStringUtils;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-
-
public class GTaskManager {
private static final String TAG = GTaskManager.class.getSimpleName();
-
public static final int STATE_SUCCESS = 0;
-
public static final int STATE_NETWORK_ERROR = 1;
-
public static final int STATE_INTERNAL_ERROR = 2;
-
public static final int STATE_SYNC_IN_PROGRESS = 3;
-
public static final int STATE_SYNC_CANCELLED = 4;
-
private static GTaskManager mInstance = null;
private Activity mActivity;
-
private Context mContext;
-
private ContentResolver mContentResolver;
-
private boolean mSyncing;
-
private boolean mCancelled;
-
private HashMap mGTaskListHashMap;
-
private HashMap mGTaskHashMap;
-
private HashMap mMetaHashMap;
-
private TaskList mMetaList;
-
private HashSet mLocalDeleteIdMap;
-
private HashMap mGidToNid;
-
private HashMap mNidToGid;
- private GTaskManager() {
- mSyncing = false;
- mCancelled = false;
- mGTaskListHashMap = new HashMap();
+ private GTaskManager() { //对象初始化函数
+ mSyncing = false; //正在同步,flase代表未执行
+ mCancelled = false; //全局标识,flase代表可以执行
+ mGTaskListHashMap = new HashMap(); //<>代表Java的泛型,就是创建一个用类型作为参数的类。
mGTaskHashMap = new HashMap();
mMetaHashMap = new HashMap();
mMetaList = null;
mLocalDeleteIdMap = new HashSet();
- mGidToNid = new HashMap();
- mNidToGid = new HashMap();
+ mGidToNid = new HashMap(); //GoogleID to NodeID??
+ mNidToGid = new HashMap(); //NodeID to GoogleID???通过hashmap散列表建立映射
}
- public static synchronized GTaskManager getInstance() {
+ /**
+ * 包含关键字synchronized,语言级同步,指明该函数可能运行在多线程的环境下。
+ * 功能:类初始化函数
+ * @author TTS
+ * @return GtaskManger
+ */
+ public static synchronized GTaskManager getInstance() { //可能运行在多线程环境下,使用语言级同步--synchronized
if (mInstance == null) {
mInstance = new GTaskManager();
}
return mInstance;
}
+ /**
+ * 包含关键字synchronized,语言级同步,指明该函数可能运行在多线程的环境下。
+ * @author TTS
+ * @param activity
+ */
public synchronized void setActivityContext(Activity activity) {
- // used for getting authtoken
+ // used for getting auth token
mActivity = activity;
}
- public int sync(Context context, GTaskASyncTask asyncTask) {
+ /**
+ * 核心函数
+ * 功能:实现了本地同步操作和远端同步操作
+ * @author TTS
+ * @param context-----获取上下文
+ * @param asyncTask-------用于同步的异步操作类
+ * @return int
+ */
+ public int sync(Context context, GTaskASyncTask asyncTask) { //核心函数
if (mSyncing) {
- Log.d(TAG, "Sync is in progress");
+ Log.d(TAG, "Sync is in progress"); //创建日志文件(调试信息),debug
return STATE_SYNC_IN_PROGRESS;
}
mContext = context;
@@ -128,8 +82,8 @@ public class GTaskManager {
mNidToGid.clear();
try {
- GTaskClient client = GTaskClient.getInstance();
- client.resetUpdateArray();
+ GTaskClient client = GTaskClient.getInstance(); //getInstance即为创建一个实例,client--客户机
+ client.resetUpdateArray(); //JSONArray类型,reset即置为NULL
// login google task
if (!mCancelled) {
@@ -140,15 +94,15 @@ public class GTaskManager {
// get the task list from google
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
- initGTaskList();
+ initGTaskList(); //获取Google上的JSONtasklist转为本地TaskList
// do content sync work
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing));
syncContent();
- } catch (NetworkFailureException e) {
- Log.e(TAG, e.toString());
+ } catch (NetworkFailureException e) { //分为两种异常,此类异常为网络异常
+ Log.e(TAG, e.toString()); //创建日志文件(调试信息),error
return STATE_NETWORK_ERROR;
- } catch (ActionFailureException e) {
+ } catch (ActionFailureException e) { //此类异常为操作异常
Log.e(TAG, e.toString());
return STATE_INTERNAL_ERROR;
} catch (Exception e) {
@@ -168,32 +122,41 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
+ /**
+ *功能:初始化GtaskList,获取Google上的JSONtasklist转为本地TaskList。
+ *获得的数据存储在mMetaList,mGTaskListHashMap,mGTaskHashMap
+ *@author TTS
+ *@exception NetworkFailureException
+ *@return void
+ */
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
- GTaskClient client = GTaskClient.getInstance();
+ GTaskClient client = GTaskClient.getInstance(); //getInstance即为创建一个实例,client应指远端客户机
try {
- JSONArray jsTaskLists = client.getTaskLists();
+ //Json对象是Name Value对(即子元素)的无序集合,相当于一个Map对象。JsonObject类是bantouyan-json库对Json对象的抽象,提供操纵Json对象的各种方法。
+ //其格式为{"key1":value1,"key2",value2....};key 必须是字符串。
+ //因为ajax请求不刷新页面,但配合js可以实现局部刷新,因此json常常被用来作为异步请求的返回对象使用。
+ JSONArray jsTaskLists = client.getTaskLists(); //原注释为get task list------lists???
// init meta list first
- mMetaList = null;
+ mMetaList = null; //TaskList类型
for (int i = 0; i < jsTaskLists.length(); i++) {
- JSONObject object = jsTaskLists.getJSONObject(i);
+ JSONObject object = jsTaskLists.getJSONObject(i); //JSONObject与JSONArray一个为对象,一个为数组。此处取出单个JASONObject
String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
- if (name
- .equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) {
- mMetaList = new TaskList();
- mMetaList.setContentByRemoteJSON(object);
+ if (name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) {
+ mMetaList = new TaskList(); //MetaList意为元表,Tasklist类型,此处为初始化
+ mMetaList.setContentByRemoteJSON(object); //将JSON中部分数据复制到自己定义的对象中相对应的数据:name->mname...
// load meta data
- JSONArray jsMetas = client.getTaskList(gid);
+ JSONArray jsMetas = client.getTaskList(gid); //原注释为get action_list------list???
for (int j = 0; j < jsMetas.length(); j++) {
object = (JSONObject) jsMetas.getJSONObject(j);
- MetaData metaData = new MetaData();
+ MetaData metaData = new MetaData(); //继承自Node
metaData.setContentByRemoteJSON(object);
- if (metaData.isWorthSaving()) {
+ if (metaData.isWorthSaving()) { //if not worth to save,metadata将不加入mMetaList
mMetaList.addChildTask(metaData);
if (metaData.getGid() != null) {
mMetaHashMap.put(metaData.getRelatedGid(), metaData);
@@ -214,16 +177,16 @@ public class GTaskManager {
// init task list
for (int i = 0; i < jsTaskLists.length(); i++) {
JSONObject object = jsTaskLists.getJSONObject(i);
- String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
+ String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); //通过getString函数传入本地某个标志数据的名称,获取其在远端的名称。
String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX)
&& !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX
- + GTaskStringUtils.FOLDER_META)) {
- TaskList tasklist = new TaskList();
+ + GTaskStringUtils.FOLDER_META)) {
+ TaskList tasklist = new TaskList(); //继承自Node
tasklist.setContentByRemoteJSON(object);
mGTaskListHashMap.put(gid, tasklist);
- mGTaskHashMap.put(gid, tasklist);
+ mGTaskHashMap.put(gid, tasklist); //为什么加两遍???
// load tasks
JSONArray jsTasks = client.getTaskList(gid);
@@ -247,13 +210,18 @@ public class GTaskManager {
}
}
- private void syncContent() throws NetworkFailureException {
+ /**
+ * 功能:本地内容同步操作
+ * @throws NetworkFailureException
+ * @return 无返回值
+ */
+ private void syncContent() throws NetworkFailureException { //本地内容同步操作
int syncType;
- Cursor c = null;
- String gid;
- Node node;
+ Cursor c = null; //数据库指针
+ String gid; //GoogleID??
+ Node node; //Node包含Sync_Action的不同类型
- mLocalDeleteIdMap.clear();
+ mLocalDeleteIdMap.clear(); //HashSet类型
if (mCancelled) {
return;
@@ -301,8 +269,8 @@ public class GTaskManager {
node = mGTaskHashMap.get(gid);
if (node != null) {
mGTaskHashMap.remove(gid);
- mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN));
- mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid);
+ mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN)); //通过hashmap建立联系
+ mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid); //通过hashmap建立联系
syncType = node.getSyncAction(c);
} else {
if (c.getString(SqlNote.GTASK_ID_COLUMN).trim().length() == 0) {
@@ -327,14 +295,14 @@ public class GTaskManager {
}
// go through remaining items
- Iterator> iter = mGTaskHashMap.entrySet().iterator();
+ Iterator> iter = mGTaskHashMap.entrySet().iterator(); //Iterator迭代器
while (iter.hasNext()) {
Map.Entry entry = iter.next();
node = entry.getValue();
doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);
}
- // mCancelled can be set by another thread, so we neet to check one by
+ // mCancelled can be set by another thread, so we neet to check one by //thread----线程
// one
// clear local delete table
if (!mCancelled) {
@@ -351,6 +319,11 @@ public class GTaskManager {
}
+ /**
+ * 功能:
+ * @author TTS
+ * @throws NetworkFailureException
+ */
private void syncFolder() throws NetworkFailureException {
Cursor c = null;
String gid;
@@ -394,7 +367,7 @@ public class GTaskManager {
try {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, "(_id=?)",
new String[] {
- String.valueOf(Notes.ID_CALL_RECORD_FOLDER)
+ String.valueOf(Notes.ID_CALL_RECORD_FOLDER)
}, null);
if (c != null) {
if (c.moveToNext()) {
@@ -476,6 +449,14 @@ public class GTaskManager {
GTaskClient.getInstance().commitUpdate();
}
+ /**
+ * 功能:syncType分类,addLocalNode,addRemoteNode,deleteNode,updateLocalNode,updateRemoteNode
+ * @author TTS
+ * @param syncType
+ * @param node
+ * @param c
+ * @throws NetworkFailureException
+ */
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@@ -522,6 +503,12 @@ public class GTaskManager {
}
}
+ /**
+ * 功能:本地增加Node
+ * @author TTS
+ * @param node
+ * @throws NetworkFailureException
+ */
private void addLocalNode(Node node) throws NetworkFailureException {
if (mCancelled) {
return;
@@ -596,6 +583,15 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
+ /**
+ * 功能:update本地node
+ * @author TTS
+ * @param node
+ * ----同步操作的基础数据类型
+ * @param c
+ * ----Cursor
+ * @throws NetworkFailureException
+ */
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@@ -619,12 +615,22 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
+ /**
+ * 功能:远程增加Node
+ * 需要updateRemoteMeta
+ * @author TTS
+ * @param node
+ * ----同步操作的基础数据类型
+ * @param c
+ * --Cursor
+ * @throws NetworkFailureException
+ */
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
}
- SqlNote sqlNote = new SqlNote(mContext, c);
+ SqlNote sqlNote = new SqlNote(mContext, c); //从本地mContext中获取内容
Node n;
// update remotely
@@ -634,11 +640,12 @@ public class GTaskManager {
String parentGid = mNidToGid.get(sqlNote.getParentId());
if (parentGid == null) {
- Log.e(TAG, "cannot find task's parent tasklist");
+ Log.e(TAG, "cannot find task's parent tasklist"); //调试信息
throw new ActionFailureException("cannot add remote task");
}
- mGTaskListHashMap.get(parentGid).addChildTask(task);
+ mGTaskListHashMap.get(parentGid).addChildTask(task); //在本地生成的GTaskList中增加子结点
+ //登录远程服务器,创建Task
GTaskClient.getInstance().createTask(task);
n = (Node) task;
@@ -656,6 +663,7 @@ public class GTaskManager {
else
folderName += sqlNote.getSnippet();
+ //iterator迭代器,通过统一的接口迭代所有的map元素
Iterator> iter = mGTaskListHashMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = iter.next();
@@ -687,11 +695,20 @@ public class GTaskManager {
sqlNote.resetLocalModified();
sqlNote.commit(true);
- // gid-id mapping
+ // gid-id mapping //创建id间的映射
mGidToNid.put(n.getGid(), sqlNote.getId());
mNidToGid.put(sqlNote.getId(), n.getGid());
}
+ /**
+ * 功能:更新远端的Node,包含meta更新(updateRemoteMeta)
+ * @author TTS
+ * @param node
+ * ----同步操作的基础数据类型
+ * @param c
+ * --Cursor
+ * @throws NetworkFailureException
+ */
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@@ -701,7 +718,7 @@ public class GTaskManager {
// update remotely
node.setContentByLocalJSON(sqlNote.getContent());
- GTaskClient.getInstance().addUpdateNode(node);
+ GTaskClient.getInstance().addUpdateNode(node); //GTaskClient用途为从本地登陆远端服务器
// update meta
updateRemoteMeta(node.getGid(), sqlNote);
@@ -710,15 +727,19 @@ public class GTaskManager {
if (sqlNote.isNoteType()) {
Task task = (Task) node;
TaskList preParentList = task.getParent();
+ //preParentList为通过node获取的父节点列表
String curParentGid = mNidToGid.get(sqlNote.getParentId());
+ //curParentGid为通过光标在数据库中找到sqlNote的mParentId,再通过mNidToGid由long类型转为String类型的Gid
+
if (curParentGid == null) {
Log.e(TAG, "cannot find task's parent tasklist");
throw new ActionFailureException("cannot update remote task");
}
TaskList curParentList = mGTaskListHashMap.get(curParentGid);
+ //通过HashMap找到对应Gid的TaskList
- if (preParentList != curParentList) {
+ if (preParentList != curParentList) { //?????????????
preParentList.removeChildTask(task);
curParentList.addChildTask(task);
GTaskClient.getInstance().moveTask(task, preParentList, curParentList);
@@ -727,9 +748,19 @@ public class GTaskManager {
// clear local modified flag
sqlNote.resetLocalModified();
+ //commit到本地数据库
sqlNote.commit(true);
}
+ /**
+ * 功能:升级远程meta。 meta---元数据----计算机文件系统管理数据---管理数据的数据。
+ * @author TTS
+ * @param gid
+ * ---GoogleID为String类型
+ * @param sqlNote
+ * ---同步前的数据库操作,故使用类SqlNote
+ * @throws NetworkFailureException
+ */
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
if (sqlNote != null && sqlNote.isNoteType()) {
MetaData metaData = mMetaHashMap.get(gid);
@@ -746,12 +777,18 @@ public class GTaskManager {
}
}
+ /**
+ * 功能:刷新本地,给sync的ID对应上最后更改过的对象
+ * @author TTS
+ * @return void
+ * @throws NetworkFailureException
+ */
private void refreshLocalSyncId() throws NetworkFailureException {
if (mCancelled) {
return;
}
- // get the latest gtask list
+ // get the latest gtask list //获取最近的(最晚的)gtask list
mGTaskHashMap.clear();
mGTaskListHashMap.clear();
mMetaHashMap.clear();
@@ -762,16 +799,16 @@ public class GTaskManager {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
"(type<>? AND parent_id<>?)", new String[] {
String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER)
- }, NoteColumns.TYPE + " DESC");
+ }, NoteColumns.TYPE + " DESC"); //query语句:五个参数,NoteColumns.TYPE + " DESC"-----为按类型递减顺序返回查询结果。new String[] {String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER)}------为选择参数。"(type<>? AND parent_id<>?)"-------指明返回行过滤器。SqlNote.PROJECTION_NOTE--------应返回的数据列的名字。Notes.CONTENT_NOTE_URI--------contentProvider包含所有数据集所对应的uri
if (c != null) {
while (c.moveToNext()) {
String gid = c.getString(SqlNote.GTASK_ID_COLUMN);
Node node = mGTaskHashMap.get(gid);
if (node != null) {
mGTaskHashMap.remove(gid);
- ContentValues values = new ContentValues();
+ ContentValues values = new ContentValues(); //在ContentValues中创建键值对。准备通过contentResolver写入数据
values.put(NoteColumns.SYNC_ID, node.getLastModified());
- mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI,
+ mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, //进行批量更改,选择参数为NULL,应该可以用insert替换,参数分别为表名和需要更新的value对象。
c.getLong(SqlNote.ID_COLUMN)), values, null, null);
} else {
Log.e(TAG, "something is missed");
@@ -790,11 +827,20 @@ public class GTaskManager {
}
}
+ /**
+ * 功能:获取同步账号,mAccount.name
+ * @author TTS
+ * @return String
+ */
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
+ /**
+ * 功能:取消同步,置mCancelled为true
+ * @author TTS
+ */
public void cancelSync() {
mCancelled = true;
}
-}
+}
\ No newline at end of file
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java b/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java
index 6706cf6..d1f1de4 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java
@@ -1,43 +1,21 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package net.micode.notes.model;
-import android.content.ContentProviderOperation;
-import android.content.ContentProviderResult;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.OperationApplicationException;
-import android.net.Uri;
-import android.os.RemoteException;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.CallNote;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.Notes.TextNote;
-
-import java.util.ArrayList;
+import android.content.ContentProviderOperation;//批量的更新、插入、删除数据。
+import android.content.ContentProviderResult;//操作的结果
+import android.content.ContentUris;//用于添加和获取Uri后面的ID
+import android.content.ContentValues;//一种用来存储基本数据类型数据的存储机制
+import android.content.Context;//需要用该类来弄清楚调用者的实例
+import android.content.OperationApplicationException;//操作应用程序容错
+import android.net.Uri;//表示待操作的数据
+import android.os.RemoteException;//远程容错
+import android.util.Log;//输出日志,比如说出错、警告等
public class Note {
- private ContentValues mNoteDiffValues;
+ // private ContentValues mNoteDiffValues;
+ ContentValues mNoteDiffValues;//
private NoteData mNoteData;
private static final String TAG = "Note";
+
/**
* Create a new note id for adding a new note to databases
*/
@@ -49,16 +27,17 @@ public class Note {
values.put(NoteColumns.MODIFIED_DATE, createdTime);
values.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
- values.put(NoteColumns.PARENT_ID, folderId);
+ 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));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
- }
+ }//try-catch异常处理
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId);
}
@@ -68,37 +47,37 @@ public class Note {
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
- }
+ }//定义两个变量用来存储便签的数据,一个是存储便签属性、一个是存储便签内容
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
- }
+ }//设置数据库表格的标签属性数据
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
- }
+ }//设置数据库表格的标签文本内容的数据
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);
- }
+ }//得到电话号码数据的ID
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
- }
+ }//判断是否是本地修改
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
@@ -128,16 +107,16 @@ public class Note {
}
return true;
- }
+ }//判断数据是否同步
- private class NoteData {
+ private class NoteData {//定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据
private long mTextDataId;
- private ContentValues mTextDataValues;
+ private ContentValues mTextDataValues;//文本数据
private long mCallDataId;
- private ContentValues mCallDataValues;
+ private ContentValues mCallDataValues;//电话号码数据
private static final String TAG = "NoteData";
@@ -147,7 +126,7 @@ public class Note {
mTextDataId = 0;
mCallDataId = 0;
}
-
+ //下面是上述几个函数的具体实现
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
@@ -177,17 +156,17 @@ public class Note {
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
-
+ //下面函数的作用是将新的数据通过Uri的操作存储到数据库
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety
*/
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
- }
+ }//判断数据是否合法
ArrayList operationList = new ArrayList();
- ContentProviderOperation.Builder builder = null;
+ ContentProviderOperation.Builder builder = null;//数据库的操作列表
if(mTextDataValues.size() > 0) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
@@ -209,7 +188,7 @@ public class Note {
operationList.add(builder.build());
}
mTextDataValues.clear();
- }
+ }//把文本数据存入DataColumns
if(mCallDataValues.size() > 0) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
@@ -231,7 +210,7 @@ public class Note {
operationList.add(builder.build());
}
mCallDataValues.clear();
- }
+ }//把电话号码数据存入DataColumns
if (operationList.size() > 0) {
try {
@@ -246,8 +225,8 @@ public class Note {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
}
- }
+ }//存储过程中的异常处理
return null;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java
index be081e4..cbb0754 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java
@@ -1,37 +1,5 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package net.micode.notes.model;
-import android.appwidget.AppWidgetManager;
-import android.content.ContentUris;
-import android.content.Context;
-import android.database.Cursor;
-import android.text.TextUtils;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.CallNote;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.Notes.TextNote;
-import net.micode.notes.tool.ResourceParser.NoteBgResources;
-
-
public class WorkingNote {
// Note for the working note
private Note mNote;
@@ -43,17 +11,11 @@ public class WorkingNote {
private int mMode;
private long mAlertDate;
-
private long mModifiedDate;
-
private int mBgColorId;
-
private int mWidgetId;
-
private int mWidgetType;
-
private long mFolderId;
-
private Context mContext;
private static final String TAG = "WorkingNote";
@@ -62,6 +24,7 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener;
+ // 声明 DATA_PROJECTION字符串数组
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
@@ -72,6 +35,7 @@ public class WorkingNote {
DataColumns.DATA4,
};
+ // 声明 NOTE_PROJECTION字符串数组
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
@@ -82,27 +46,18 @@ public class WorkingNote {
};
private static final int DATA_ID_COLUMN = 0;
-
private static final int DATA_CONTENT_COLUMN = 1;
-
private static final int DATA_MIME_TYPE_COLUMN = 2;
-
private static final int DATA_MODE_COLUMN = 3;
-
private static final int NOTE_PARENT_ID_COLUMN = 0;
-
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
-
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
-
private static final int NOTE_WIDGET_ID_COLUMN = 3;
-
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
-
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
- private WorkingNote(Context context, long folderId) {
+ public WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
mModifiedDate = System.currentTimeMillis();
@@ -114,7 +69,9 @@ public class WorkingNote {
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
+ // WorkingNote的构造函数
// Existing note construct
+
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
@@ -124,11 +81,14 @@ public class WorkingNote {
loadNote();
}
+ // 加载Note
+ // 通过数据库调用query函数找到第一个条目
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
null, null);
+ // 若存在,储存相应信息
if (cursor != null) {
if (cursor.moveToFirst()) {
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
@@ -139,6 +99,7 @@ public class WorkingNote {
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
}
cursor.close();
+ // 若不存在,报错
} else {
Log.e(TAG, "No note with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
@@ -146,14 +107,16 @@ public class WorkingNote {
loadNoteData();
}
+ // 加载NoteData
private void loadNoteData() {
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
- String.valueOf(mNoteId)
+ String.valueOf(mNoteId)
}, null);
if (cursor != null) {
- if (cursor.moveToFirst()) {
+ // 查到信息不为空
+ if (cursor.moveToFirst()) { // 查看第一项是否存在
do {
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
if (DataConstants.NOTE.equals(type)) {
@@ -165,7 +128,7 @@ public class WorkingNote {
} else {
Log.d(TAG, "Wrong note type with type:" + type);
}
- } while (cursor.moveToNext());
+ } while (cursor.moveToNext());//查阅所有项,直到为空
}
cursor.close();
} else {
@@ -174,9 +137,12 @@ public class WorkingNote {
}
}
+ // 创建空的Note
+ // 传参:context,文件夹id,widget,背景颜色
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
- int widgetType, int defaultBgColorId) {
+ int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
+ // 设定相关属性
note.setBgColorId(defaultBgColorId);
note.setWidgetId(widgetId);
note.setWidgetType(widgetType);
@@ -187,9 +153,10 @@ public class WorkingNote {
return new WorkingNote(context, id, 0);
}
+ // 保存Note
public synchronized boolean saveNote() {
- if (isWorthSaving()) {
- if (!existInDatabase()) {
+ if (isWorthSaving()) { //是否值得保存
+ if (!existInDatabase()) { // 是否存在数据库中
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false;
@@ -212,11 +179,14 @@ public class WorkingNote {
}
}
+ // 是否在数据库中存在
public boolean existInDatabase() {
return mNoteId > 0;
}
+ // 是否值得保存
private boolean isWorthSaving() {
+ // 被删除,或(不在数据库中 内容为空),或 本地已保存过
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
return false;
@@ -225,10 +195,14 @@ public class WorkingNote {
}
}
+
+ // 设置mNoteSettingStatusListener
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
+ // 设置AlertDate
+ // 若 mAlertDate与data不同,则更改mAlertDate并设定NoteValue
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@@ -239,16 +213,20 @@ public class WorkingNote {
}
}
+ // 设定删除标记
public void markDeleted(boolean mark) {
+ // 设定标记
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
- mNoteSettingStatusListener.onWidgetChanged();
+ mNoteSettingStatusListener.onWidgetChanged();
+ // 调用mNoteSettingStatusListener的 onWidgetChanged方法
}
}
+ // 设定背景颜色
public void setBgColorId(int id) {
- if (id != mBgColorId) {
+ if (id != mBgColorId) { //设定条件 id != mBgColorId
mBgColorId = id;
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onBackgroundColorChanged();
@@ -257,8 +235,10 @@ public class WorkingNote {
}
}
+ // 设定检查列表模式
+ // 参数:mode
public void setCheckListMode(int mode) {
- if (mMode != mode) {
+ if (mMode != mode) { //设定条件 mMode != mode
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
}
@@ -267,81 +247,108 @@ public class WorkingNote {
}
}
+
+ // 设定WidgetType
+ // 参数:type
public void setWidgetType(int type) {
- if (type != mWidgetType) {
+ if (type != mWidgetType) {//设定条件 type != mWidgetType
mWidgetType = type;
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
+ // 调用Note的setNoteValue方法更改WidgetType
}
}
+ // 设定WidgetId
+ // 参数:id
public void setWidgetId(int id) {
- if (id != mWidgetId) {
+ if (id != mWidgetId) {//设定条件 id != mWidgetId
mWidgetId = id;
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
+ // 调用Note的setNoteValue方法更改WidgetId
}
}
+ // 设定WorkingTex
+ // 参数:更改的text
public void setWorkingText(String text) {
- if (!TextUtils.equals(mContent, text)) {
+ if (!TextUtils.equals(mContent, text)) {//设定条件 mContent, text内容不同
mContent = text;
mNote.setTextData(DataColumns.CONTENT, mContent);
+ // 调用Note的setTextData方法更改WorkingText
}
}
+ // 转变mNote的CallData及CallNote信息
+ // 参数:String phoneNumber, long callDate
public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
+ // 判断是否有时钟题型
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
+ // 获取Content
public String getContent() {
return mContent;
}
+ // 获取AlertDate
public long getAlertDate() {
return mAlertDate;
}
+ // 获取ModifiedDate
public long getModifiedDate() {
return mModifiedDate;
}
+ // 获取背景颜色来源id
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
+ // 获取背景颜色id
public int getBgColorId() {
return mBgColorId;
}
+ // 获取标题背景颜色id
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
+ // 获取CheckListMode
public int getCheckListMode() {
return mMode;
}
+ // 获取便签id
public long getNoteId() {
return mNoteId;
}
+ // 获取文件夹id
public long getFolderId() {
return mFolderId;
}
+ // 获取WidgetId
public int getWidgetId() {
return mWidgetId;
}
+ // 获取WidgetType
public int getWidgetType() {
return mWidgetType;
}
+ // 创建接口 NoteSettingChangedListener,便签更新监视
+ // 为NoteEditActivity提供接口
+ // 提供函数有
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
@@ -365,4 +372,4 @@ public class WorkingNote {
*/
void onCheckListModeChanged(int oldMode, int newMode);
}
-}
+}
\ No newline at end of file
diff --git a/src/Notes-master3/local.properties b/src/Notes-master3/local.properties
index 545e234..51e9b59 100644
--- a/src/Notes-master3/local.properties
+++ b/src/Notes-master3/local.properties
@@ -5,4 +5,5 @@
# For customization when using a Version Control System, please read the
# header note.
#Fri Apr 07 16:53:50 CST 2023
-sdk.dir=D\:\\androoidSDK
+sdk.dir=C\:\\Users\\13293\\AppData\\Local\\Android\\Sdk
+