Type: INTEGER (long)
@@ -72,50 +72,50 @@ public class Notes { * The parent's id for note or folder *Type: INTEGER (long)
*/ - public static final String PARENT_ID = "parent_id"; //父文件夹的id + 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"; //表示文件夹或便签创建日期 + public static final String CREATED_DATE = "created_date"; /** * Latest modified date *Type: INTEGER (long)
*/ - public static final String MODIFIED_DATE = "modified_date"; //便签的最新的修改日期 + public static final String MODIFIED_DATE = "modified_date"; /** * Alert date *Type: INTEGER (long)
*/ - public static final String ALERTED_DATE = "alert_date"; //提醒日期 + public static final String ALERTED_DATE = "alert_date"; /** * Folder's name or text content of note *Type: TEXT
*/ - public static final String SNIPPET = "snippet"; //文件夹名称或便签内容 + public static final String SNIPPET = "snippet"; /** * Note's widget id *Type: INTEGER (long)
*/ - public static final String WIDGET_ID = "widget_id"; //便签的widget的id + public static final String WIDGET_ID = "widget_id"; /** * Note's widget type *Type: INTEGER (long)
*/ - public static final String WIDGET_TYPE = "widget_type"; //便签widget的类型 + public static final String WIDGET_TYPE = "widget_type"; /** * Note's background color's id *Type: INTEGER (long)
*/ - public static final String BG_COLOR_ID = "bg_color_id"; //背景颜色代号 + public static final String BG_COLOR_ID = "bg_color_id"; /** * For text note, it doesn't has attachment, for multi-media @@ -128,31 +128,31 @@ public class Notes { * Folder's count of notes *Type: INTEGER (long)
*/ - public static final String NOTES_COUNT = "notes_count"; //文件夹内的便签数 + public static final String NOTES_COUNT = "notes_count"; /** * The file type: folder or note *Type: INTEGER
*/ - public static final String TYPE = "type"; //文件类型,是文件夹或便签 + public static final String TYPE = "type"; /** * The last sync id *Type: INTEGER (long)
*/ - public static final String SYNC_ID = "sync_id"; //最后一次同步id + 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"; //本地修改名称标识 + public static final String LOCAL_MODIFIED = "local_modified"; /** * Original parent id before moving into temporary folder *Type : INTEGER
*/ - public static final String ORIGIN_PARENT_ID = "origin_parent_id"; //移动文件时文件的前父类文件夹 + public static final String ORIGIN_PARENT_ID = "origin_parent_id"; /** * The gtask id @@ -164,10 +164,10 @@ public class Notes { * The version code *Type : INTEGER (long)
*/ - public static final String VERSION = "version"; //版本名称 + public static final String VERSION = "version"; } - public interface DataColumns { //定义数据变量接口 + public interface DataColumns { /** * The unique ID for a row *Type: INTEGER (long)
@@ -184,25 +184,25 @@ public class Notes { * The reference id to note that this data belongs to *Type: INTEGER (long)
*/ - public static final String NOTE_ID = "note_id"; //便签名称 + 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"; //创建文件夹或者便签的名称 + public static final String CREATED_DATE = "created_date"; /** * Latest modified date *Type: INTEGER (long)
*/ - public static final String MODIFIED_DATE = "modified_date"; //最后修改日期 + public static final String MODIFIED_DATE = "modified_date"; /** * Data's content *Type: TEXT
*/ - public static final String CONTENT = "content"; //便签内容数据 + public static final String CONTENT = "content"; /** @@ -210,7 +210,7 @@ public class Notes { * integer data type *Type: INTEGER
*/ - public static final String DATA1 = "data1"; //不同类型的通用数据列,用于可能的存储与查找 + public static final String DATA1 = "data1"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for @@ -244,17 +244,17 @@ 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
//1为列表检查模式,0为普通模式 + *Type: Integer 1:check list mode 0: normal mode
*/ - public static final String MODE = DATA1; //模式 + public static final String MODE = DATA1; - public static final int MODE_CHECK_LIST = 1; //列表检查模式 + public static final int MODE_CHECK_LIST = 1; public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; 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");//访问数据表uri + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); } public static final class CallNote implements DataColumns { @@ -262,18 +262,18 @@ public class Notes { * Call date for this record *Type: INTEGER (long)
*/ - public static final String CALL_DATE = DATA1; //呼叫数据 + public static final String CALL_DATE = DATA1; /** * Phone number for this record *Type: TEXT
*/ - public static final String PHONE_NUMBER = DATA3; //呼叫号码 + public static final String PHONE_NUMBER = DATA3; public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; 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");//访问电话记录uri + 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/src/data/NotesDatabaseHelper.java similarity index 63% rename from app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java rename to src/data/NotesDatabaseHelper.java index 57805ab..ffe5d57 100644 --- a/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/data/NotesDatabaseHelper.java @@ -26,23 +26,23 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; - //引入Notes中接口 -public class NotesDatabaseHelper extends SQLiteOpenHelper { //该类为便签SQL表的定义以及操作,便于进行文件夹与便签的各种操作,例如添加或删除的行为 - private static final String DB_NAME = "note.db"; //数据库名称 - private static final int DB_VERSION = 4; //数据库版本 +public class NotesDatabaseHelper extends SQLiteOpenHelper { + private static final String DB_NAME = "note.db"; - public interface TABLE { //定义一个数据库表接口 - public static final String NOTE = "note"; //便签名 + private static final int DB_VERSION = 4; - public static final String DATA = "data"; //便签数据 + public interface TABLE { + public static final String NOTE = "note"; + + public static final String DATA = "data"; } - private static final String TAG = "NotesDatabaseHelper"; //日志类型 + private static final String TAG = "NotesDatabaseHelper"; - private static NotesDatabaseHelper mInstance; //创建NotesDatabaseHelper类对象 + private static NotesDatabaseHelper mInstance; - private static final String CREATE_NOTE_TABLE_SQL = //SQL语句,创建便签表,包含ID、最后修改日期、背景颜色、便签数等在Notes类中的内容 + private static final String CREATE_NOTE_TABLE_SQL = "CREATE TABLE " + TABLE.NOTE + "(" + NoteColumns.ID + " INTEGER PRIMARY KEY," + NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + @@ -63,7 +63,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + ")"; - private static final String CREATE_DATA_TABLE_SQL = //创建数据表的SQL语句 + private static final String CREATE_DATA_TABLE_SQL = "CREATE TABLE " + TABLE.DATA + "(" + DataColumns.ID + " INTEGER PRIMARY KEY," + DataColumns.MIME_TYPE + " TEXT NOT NULL," + @@ -80,7 +80,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = "CREATE INDEX IF NOT EXISTS note_id_index ON " + - TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; //创建查询操作表索引,用于查找 + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; /** * Increase folder's note count when move note to the folder @@ -92,7 +92,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + - " END"; //创建触发器,方便进行操作,当移动便签时统计新的父文件夹内便签数量 + " END"; /** * Decrease folder's note count when move note from folder @@ -105,7 +105,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + - " END"; //与上一个方法作用相反,统计旧的父文件夹便签数量 + " END"; /** * Increase folder's note count when insert new note to the folder @@ -117,7 +117,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + - " END"; //创建便签时增加统计数量 + " END"; /** * Decrease folder's note count when delete note from the folder @@ -130,7 +130,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + " AND " + NoteColumns.NOTES_COUNT + ">0;" + - " END"; //删除时减少数量 + " END"; /** * Update note's content when insert data with type {@link DataConstants#NOTE} @@ -143,7 +143,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + - " END"; //更新便签数据时更改table表内容 + " END"; /** * Update note's content when data with {@link DataConstants#NOTE} type has changed @@ -156,7 +156,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + - " END"; //改变便签数据时更改table表内容 + " END"; /** * Update note's content when data with {@link DataConstants#NOTE} type has deleted @@ -169,7 +169,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.SNIPPET + "=''" + " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" + - " END"; //删除便签数据时改变table表内容 + " END"; /** * Delete datas belong to note which has been deleted @@ -180,7 +180,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " BEGIN" + " DELETE FROM " + TABLE.DATA + " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + - " END"; //删除便签时删除便签内容 + " END"; /** * Delete notes belong to folder which has been deleted @@ -191,7 +191,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " BEGIN" + " DELETE FROM " + TABLE.NOTE + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END"; //删除文件夹时删除内部的便签 + " END"; /** * Move notes belong to folder which has been moved to trash folder @@ -204,20 +204,20 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " UPDATE " + TABLE.NOTE + " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END"; //移动便签的父文件夹时便签也一起更改 + " END"; public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); - } //创建一个数据库 + } public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); - reCreateNoteTableTriggers(db); //重新创建触发器 - createSystemFolder(db); //创建系统文件夹 - Log.d(TAG, "note table has been created"); //创建一个新的便签表,返回日志 + reCreateNoteTableTriggers(db); + createSystemFolder(db); + Log.d(TAG, "note table has been created"); } - private void reCreateNoteTableTriggers(SQLiteDatabase db) { //数据库对象DB + 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"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete"); @@ -233,17 +233,17 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER); db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER); db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); - } //用于执行SQL语句,运行重新创建便签表触发器函数 + } - private void createSystemFolder(SQLiteDatabase db) { //创建系统级文件夹 - ContentValues values = new ContentValues(); //为字典类创建对象 + private void createSystemFolder(SQLiteDatabase db) { + 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); //为通讯便签创建记录文件夹,并添加键值对 + db.insert(TABLE.NOTE, null, values); /** * root folder which is default folder @@ -251,7 +251,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { values.clear(); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); //创建根文件夹,是默认的、最终的父文件夹 + db.insert(TABLE.NOTE, null, values); /** * temporary folder which is used for moving note @@ -259,7 +259,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { values.clear(); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); //为移动中的便签创建的临时文件夹 + db.insert(TABLE.NOTE, null, values); /** * create trash folder @@ -267,24 +267,24 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { values.clear(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); //创建垃圾桶 + db.insert(TABLE.NOTE, null, values); } - public void createDataTable(SQLiteDatabase db) { //创建数据表 - db.execSQL(CREATE_DATA_TABLE_SQL); //SQL输入保存的语句 + public void createDataTable(SQLiteDatabase db) { + db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL); - Log.d(TAG, "data table has been created"); //日志记录 + Log.d(TAG, "data table has been created"); } - private void reCreateDataTableTriggers(SQLiteDatabase db) { //为数据表重新创建触发器 + private void reCreateDataTableTriggers(SQLiteDatabase db) { 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"); //删除触发器 + db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete"); db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER); db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER); - db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); //重新创建被删除的触发器 + db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); } static synchronized NotesDatabaseHelper getInstance(Context context) { @@ -292,16 +292,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { mInstance = new NotesDatabaseHelper(context); } return mInstance; - } //静态同步方法,用于返回NotesDatabaseHelper的对象实例mInstance + } @Override public void onCreate(SQLiteDatabase db) { - createNoteTable(db); //创建便签表 - createDataTable(db); //创建数据表 - } //用于初始化表 + createNoteTable(db); + createDataTable(db); + } @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { //用于检查并升级数据库版本 + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { boolean reCreateTriggers = false; boolean skipV2 = false; @@ -309,31 +309,31 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { upgradeToV2(db); skipV2 = true; // this upgrade including the upgrade from v2 to v3 oldVersion++; - } //检测到版本为1,升级版本 + } if (oldVersion == 2 && !skipV2) { upgradeToV3(db); - reCreateTriggers = true; //重建触发器标志 - oldVersion++; //检测到版本为2,升级版本 + reCreateTriggers = true; + oldVersion++; } if (oldVersion == 3) { upgradeToV4(db); oldVersion++; - } //检测到版本为3,升级版本 + } if (reCreateTriggers) { reCreateNoteTableTriggers(db); reCreateDataTableTriggers(db); - } //进行触发器的重建 + } if (oldVersion != newVersion) { throw new IllegalStateException("Upgrade notes database to version " + newVersion - + "fails"); //版本不匹配则抛出异常 + + "fails"); } } - private void upgradeToV2(SQLiteDatabase db) { //升级版本并重建表 + private void upgradeToV2(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); createNoteTable(db); @@ -353,10 +353,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); - } //删除不用的触发器,并添加不为空的新列,添加键值对 + } private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); - } //添加新的不为空的列 + } } diff --git a/app/src/main/java/net/micode/notes/data/NotesProvider.java b/src/data/NotesProvider.java similarity index 55% rename from app/src/main/java/net/micode/notes/data/NotesProvider.java rename to src/data/NotesProvider.java index 9ae1528..edb0a60 100644 --- a/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/src/data/NotesProvider.java @@ -36,22 +36,22 @@ import net.micode.notes.data.NotesDatabaseHelper.TABLE; public class NotesProvider extends ContentProvider { - private static final UriMatcher mMatcher; //UriMatcher类用于分辨数据表 + private static final UriMatcher mMatcher; - private NotesDatabaseHelper mHelper; //建立NotesDatabaseHelper类对象 + private NotesDatabaseHelper mHelper; - private static final String TAG = "NotesProvider"; //设置类名值 + private static final String TAG = "NotesProvider"; - private static final int URI_NOTE = 1; //设置便签uri + private static final int URI_NOTE = 1; private static final int URI_NOTE_ITEM = 2; - private static final int URI_DATA = 3; //设置数据uri + private static final int URI_DATA = 3; private static final int URI_DATA_ITEM = 4; - private static final int URI_SEARCH = 5; //设置搜索uri + private static final int URI_SEARCH = 5; private static final int URI_SEARCH_SUGGEST = 6; static { - mMatcher = new UriMatcher(UriMatcher.NO_MATCH); //进行初始化 + mMatcher = new UriMatcher(UriMatcher.NO_MATCH); mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM); mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA); @@ -59,48 +59,48 @@ public class NotesProvider extends ContentProvider { mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH); mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST); mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST); - } //将不同的uri与数值相匹配 + } /** * 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. - */ //用0A代表\n,为搜索结果换行 + */ 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; //... + + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; 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; //检索便签的sql语句,在列表中搜寻。使用Notes类中的接口与变量 + + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; @Override public boolean onCreate() { mHelper = NotesDatabaseHelper.getInstance(getContext()); - return true; //创建NotesDatabaseHelper类并返回成果标识 + return true; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, - String sortOrder) { //负责查询数据,接受uri、返回烈、选择、排列方式 - Cursor c = null; //创建空游标,表示数据库操作结果集合 - SQLiteDatabase db = mHelper.getReadableDatabase(); //获取数据库对象 + String sortOrder) { + Cursor c = null; + SQLiteDatabase db = mHelper.getReadableDatabase(); String id = null; - switch (mMatcher.match(uri)) { //确定uri类型 + switch (mMatcher.match(uri)) { case URI_NOTE: c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, - sortOrder); //传参,进行标准查询 + sortOrder); break; case URI_NOTE_ITEM: id = uri.getPathSegments().get(1); c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs, null, null, sortOrder); - break; //传参,对id进行查询 + break; case URI_DATA: c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, sortOrder); @@ -112,13 +112,13 @@ public class NotesProvider extends ContentProvider { break; case URI_SEARCH: case URI_SEARCH_SUGGEST: - if (sortOrder != null || projection != null) { //检查是否指定排序方式 + if (sortOrder != null || projection != null) { throw new IllegalArgumentException( "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); } String searchString = null; - if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { //提取uri中搜索模式 + if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { if (uri.getPathSegments().size() > 1) { searchString = uri.getPathSegments().get(1); } @@ -133,43 +133,43 @@ public class NotesProvider extends ContentProvider { try { searchString = String.format("%%%s%%", searchString); c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, - new String[] { searchString }); //在Notes表进行搜索 + new String[] { searchString }); } catch (IllegalStateException ex) { - Log.e(TAG, "got exception: " + ex.toString()); //日志 + Log.e(TAG, "got exception: " + ex.toString()); } break; default: - throw new IllegalArgumentException("Unknown URI " + uri); //抛出异常 + throw new IllegalArgumentException("Unknown URI " + uri); } if (c != null) { - c.setNotificationUri(getContext().getContentResolver(), uri); //在游标查询的数据变化时进行通知 - } //通知uri是标识查询结果的uri,setNotificationUri方法可注册通知uri,与对象c相关联 + c.setNotificationUri(getContext().getContentResolver(), uri); + } return c; } @Override - public Uri insert(Uri uri, ContentValues values) { //uri表示要插入的uri,values表示要插入的数据 - SQLiteDatabase db = mHelper.getWritableDatabase(); //打开或创建一个数据库 + public Uri insert(Uri uri, ContentValues values) { + SQLiteDatabase db = mHelper.getWritableDatabase(); long dataId = 0, noteId = 0, insertedId = 0; - switch (mMatcher.match(uri)) { //匹配uri + switch (mMatcher.match(uri)) { case URI_NOTE: - insertedId = noteId = db.insert(TABLE.NOTE, null, values); //将数据插入到Notes表中 + insertedId = noteId = db.insert(TABLE.NOTE, null, values); break; case URI_DATA: - if (values.containsKey(DataColumns.NOTE_ID)) { //检查values是否含有NOTE_ID内容,返回bool值 - noteId = values.getAsLong(DataColumns.NOTE_ID); //关联noteId + if (values.containsKey(DataColumns.NOTE_ID)) { + noteId = values.getAsLong(DataColumns.NOTE_ID); } else { - Log.d(TAG, "Wrong data format without note id:" + values.toString()); //日志记录 + Log.d(TAG, "Wrong data format without note id:" + values.toString()); } - insertedId = dataId = db.insert(TABLE.DATA, null, values); //数据库插入新行的id返回到两个变量中 + insertedId = dataId = db.insert(TABLE.DATA, null, values); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // Notify the note uri - if (noteId > 0) { //不为零表示插入成功, + if (noteId > 0) { getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); //通知uri发生变化 + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); } // Notify the data uri @@ -178,22 +178,22 @@ public class NotesProvider extends ContentProvider { ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); } - return ContentUris.withAppendedId(uri, insertedId); //返回新的uri,表示插入位置 + return ContentUris.withAppendedId(uri, insertedId); } @Override - public int delete(Uri uri, String selection, String[] selectionArgs) { //表示要删除的uri、SQL中的WHERE与参数 - int count = 0; //表示删除记录数 + public int delete(Uri uri, String selection, String[] selectionArgs) { + int count = 0; String id = null; - SQLiteDatabase db = mHelper.getWritableDatabase(); //打开数据库 + SQLiteDatabase db = mHelper.getWritableDatabase(); boolean deleteData = false; - switch (mMatcher.match(uri)) { //uri匹配 + switch (mMatcher.match(uri)) { case URI_NOTE: - selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; //设置WHERE - count = db.delete(TABLE.NOTE, selection, selectionArgs); //删除,并计数 + selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; + count = db.delete(TABLE.NOTE, selection, selectionArgs); break; case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); //获取id + id = uri.getPathSegments().get(1); /** * ID that smaller than 0 is system folder which is not allowed to * trash @@ -204,45 +204,45 @@ public class NotesProvider extends ContentProvider { } count = db.delete(TABLE.NOTE, NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs); - break; //删除指定id,并计数 + break; case URI_DATA: - count = db.delete(TABLE.DATA, selection, selectionArgs); //删除,并计数 + count = db.delete(TABLE.DATA, selection, selectionArgs); deleteData = true; break; case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); //获取id + id = uri.getPathSegments().get(1); count = db.delete(TABLE.DATA, DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs); - deleteData = true; //删除指定id,并计数 + deleteData = true; break; default: - throw new IllegalArgumentException("Unknown URI " + uri); //报错 + throw new IllegalArgumentException("Unknown URI " + uri); } - if (count > 0) { //表示有删除操作,通知uri发生变化 + if (count > 0) { if (deleteData) { getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); } getContext().getContentResolver().notifyChange(uri, null); } - return count; //返回删除的记录数 + return count; } @Override - public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { //表示更新的uri、values为新的列值、where以及参数 - int count = 0; //更新条数 + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count = 0; String id = null; - SQLiteDatabase db = mHelper.getWritableDatabase(); //打开数据库 - boolean updateData = false; //设置数据表更新表示 - switch (mMatcher.match(uri)) { //匹配uri + SQLiteDatabase db = mHelper.getWritableDatabase(); + boolean updateData = false; + switch (mMatcher.match(uri)) { case URI_NOTE: - increaseNoteVersion(-1, selection, selectionArgs); //跟新便签 - count = db.update(TABLE.NOTE, values, selection, selectionArgs); //更新指定表的行,并计数 + increaseNoteVersion(-1, selection, selectionArgs); + count = db.update(TABLE.NOTE, values, selection, selectionArgs); break; case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); //提取id + id = uri.getPathSegments().get(1); increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id - + parseSelection(selection), selectionArgs); //增加指定的id条件 + + parseSelection(selection), selectionArgs); break; case URI_DATA: count = db.update(TABLE.DATA, values, selection, selectionArgs); @@ -255,50 +255,51 @@ public class NotesProvider extends ContentProvider { updateData = true; break; default: - throw new IllegalArgumentException("Unknown URI " + uri); //抛出异常 + throw new IllegalArgumentException("Unknown URI " + uri); } if (count > 0) { if (updateData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);//通知指定uri数据更改 + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); } - getContext().getContentResolver().notifyChange(uri, null); //通知uri数据更改 + getContext().getContentResolver().notifyChange(uri, null); } return count; } - private String parseSelection(String selection) { //检查selection是否为空 - return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); //为空则返回“” + private String parseSelection(String selection) { + return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } - private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { //使用数据库更新便签版本 + private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { StringBuilder sql = new StringBuilder(120); sql.append("UPDATE "); sql.append(TABLE.NOTE); sql.append(" SET "); sql.append(NoteColumns.VERSION); - sql.append("=" + NoteColumns.VERSION + "+1 "); //升级便签版本号 + sql.append("=" + NoteColumns.VERSION + "+1 "); - if (id > 0 || !TextUtils.isEmpty(selection)) { //selection不为空或存在id则增加where条件 + if (id > 0 || !TextUtils.isEmpty(selection)) { sql.append(" WHERE "); } if (id > 0) { sql.append(NoteColumns.ID + "=" + String.valueOf(id)); } if (!TextUtils.isEmpty(selection)) { - String selectString = id > 0 ? parseSelection(selection) : selection; //parseSelection将传入的参数中的占位符替换为实际的值 - for (String args : selectionArgs) { // - selectString = selectString.replaceFirst("\\?", args); //replaceFirst选择参数数组中的值替换语句中的占位符 + String selectString = id > 0 ? parseSelection(selection) : selection; + for (String args : selectionArgs) { + selectString = selectString.replaceFirst("\\?", args); } sql.append(selectString); } - mHelper.getWritableDatabase().execSQL(sql.toString()); //执行SQL语句 + mHelper.getWritableDatabase().execSQL(sql.toString()); } @Override - public String getType(Uri uri) { //获取指定uri的MIME类型 - // TODO Auto-generated method stub //表示该方法没有实现 + public String getType(Uri uri) { + // TODO Auto-generated method stub return null; } + } diff --git a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/src/gtask/data/MetaData.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/data/MetaData.java rename to src/gtask/data/MetaData.java diff --git a/app/src/main/java/net/micode/notes/gtask/data/Node.java b/src/gtask/data/Node.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/data/Node.java rename to src/gtask/data/Node.java diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/src/gtask/data/SqlData.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/data/SqlData.java rename to src/gtask/data/SqlData.java diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/src/gtask/data/SqlNote.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/data/SqlNote.java rename to src/gtask/data/SqlNote.java diff --git a/app/src/main/java/net/micode/notes/gtask/data/Task.java b/src/gtask/data/Task.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/data/Task.java rename to src/gtask/data/Task.java diff --git a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/src/gtask/data/TaskList.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/data/TaskList.java rename to src/gtask/data/TaskList.java diff --git a/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java b/src/gtask/exception/ActionFailureException.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java rename to src/gtask/exception/ActionFailureException.java diff --git a/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java b/src/gtask/exception/NetworkFailureException.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java rename to src/gtask/exception/NetworkFailureException.java diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java b/src/gtask/remote/GTaskASyncTask.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java rename to src/gtask/remote/GTaskASyncTask.java diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java b/src/gtask/remote/GTaskClient.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java rename to src/gtask/remote/GTaskClient.java diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java b/src/gtask/remote/GTaskManager.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java rename to src/gtask/remote/GTaskManager.java diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java b/src/gtask/remote/GTaskSyncService.java similarity index 100% rename from app/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java rename to src/gtask/remote/GTaskSyncService.java diff --git a/app/src/main/java/net/micode/notes/model/Note.java b/src/model/Note.java similarity index 100% rename from app/src/main/java/net/micode/notes/model/Note.java rename to src/model/Note.java diff --git a/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/model/WorkingNote.java similarity index 100% rename from app/src/main/java/net/micode/notes/model/WorkingNote.java rename to src/model/WorkingNote.java diff --git a/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/src/tool/BackupUtils.java similarity index 100% rename from app/src/main/java/net/micode/notes/tool/BackupUtils.java rename to src/tool/BackupUtils.java diff --git a/app/src/main/java/net/micode/notes/tool/DataUtils.java b/src/tool/DataUtils.java similarity index 100% rename from app/src/main/java/net/micode/notes/tool/DataUtils.java rename to src/tool/DataUtils.java diff --git a/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/src/tool/GTaskStringUtils.java similarity index 100% rename from app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java rename to src/tool/GTaskStringUtils.java diff --git a/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/src/tool/ResourceParser.java similarity index 100% rename from app/src/main/java/net/micode/notes/tool/ResourceParser.java rename to src/tool/ResourceParser.java diff --git a/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java b/src/ui/AlarmAlertActivity.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java rename to src/ui/AlarmAlertActivity.java diff --git a/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/src/ui/AlarmInitReceiver.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java rename to src/ui/AlarmInitReceiver.java diff --git a/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java b/src/ui/AlarmReceiver.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/AlarmReceiver.java rename to src/ui/AlarmReceiver.java diff --git a/app/src/main/java/net/micode/notes/ui/DateTimePicker.java b/src/ui/DateTimePicker.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/DateTimePicker.java rename to src/ui/DateTimePicker.java diff --git a/app/src/main/java/net/micode/notes/ui/DateTimePickerDialog.java b/src/ui/DateTimePickerDialog.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/DateTimePickerDialog.java rename to src/ui/DateTimePickerDialog.java diff --git a/app/src/main/java/net/micode/notes/ui/DropdownMenu.java b/src/ui/DropdownMenu.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/DropdownMenu.java rename to src/ui/DropdownMenu.java diff --git a/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java b/src/ui/FoldersListAdapter.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java rename to src/ui/FoldersListAdapter.java diff --git a/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/ui/NoteEditActivity.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NoteEditActivity.java rename to src/ui/NoteEditActivity.java diff --git a/app/src/main/java/net/micode/notes/ui/NoteEditText.java b/src/ui/NoteEditText.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NoteEditText.java rename to src/ui/NoteEditText.java diff --git a/app/src/main/java/net/micode/notes/ui/NoteItemData.java b/src/ui/NoteItemData.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NoteItemData.java rename to src/ui/NoteItemData.java diff --git a/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/ui/NotesListActivity.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NotesListActivity.java rename to src/ui/NotesListActivity.java diff --git a/app/src/main/java/net/micode/notes/ui/NotesListAdapter.java b/src/ui/NotesListAdapter.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NotesListAdapter.java rename to src/ui/NotesListAdapter.java diff --git a/app/src/main/java/net/micode/notes/ui/NotesListItem.java b/src/ui/NotesListItem.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NotesListItem.java rename to src/ui/NotesListItem.java diff --git a/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java b/src/ui/NotesPreferenceActivity.java similarity index 100% rename from app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java rename to src/ui/NotesPreferenceActivity.java diff --git a/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java b/src/widget/NoteWidgetProvider.java similarity index 100% rename from app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java rename to src/widget/NoteWidgetProvider.java diff --git a/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java b/src/widget/NoteWidgetProvider_2x.java similarity index 100% rename from app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java rename to src/widget/NoteWidgetProvider_2x.java diff --git a/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java b/src/widget/NoteWidgetProvider_4x.java similarity index 100% rename from app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java rename to src/widget/NoteWidgetProvider_4x.java