diff --git a/Dome b/Dome new file mode 160000 index 0000000..85ad4e7 --- /dev/null +++ b/Dome @@ -0,0 +1 @@ +Subproject commit 85ad4e7b6c62b539ad3bffcdf964e05becfa0bba diff --git a/doc/2406李应龙结果图.jpg b/doc/2406李应龙结果图.jpg new file mode 100644 index 0000000..9cb4797 Binary files /dev/null and b/doc/2406李应龙结果图.jpg differ diff --git a/src/net/micode/notes/data/Notes.java b/src/net/micode/notes/data/Notes.java deleted file mode 100644 index f240604..0000000 --- a/src/net/micode/notes/data/Notes.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * 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.net.Uri; -public class Notes { - public static final String AUTHORITY = "micode_notes"; - public static final String TAG = "Notes"; - public static final int TYPE_NOTE = 0; - public static final int TYPE_FOLDER = 1; - public static final int TYPE_SYSTEM = 2; - - /** - * Following IDs are system folders' identifiers - * {@link Notes#ID_ROOT_FOLDER } is default folder - * {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder - * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records - */ - public static final int ID_ROOT_FOLDER = 0; - public static final int ID_TEMPARAY_FOLDER = -1; - public static final int ID_CALL_RECORD_FOLDER = -2; - public static final int ID_TRASH_FOLER = -3; - - public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; - public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id"; - public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id"; - public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type"; - public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; - public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; - - public static final int TYPE_WIDGET_INVALIDE = -1; - public static final int TYPE_WIDGET_2X = 0; - public static final int TYPE_WIDGET_4X = 1; - - public static class DataConstants { - public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; - public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; - } - - /** - * Uri to query all notes and folders - */ - public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); - - /** - * Uri to query data - */ - public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); - - public interface NoteColumns { - /** - * The unique ID for a row - *
Type: INTEGER (long)
- */ - public static final String ID = "_id"; - - /** - * The parent's id for note or folder - *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 - *Type: INTEGER (long)
- */ - public static final String WIDGET_ID = "widget_id"; - - /** - * Note's widget type - *Type: INTEGER (long)
- */ - 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"; - - /** - * 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 - *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 - *Type : INTEGER
- */ - public static final String ORIGIN_PARENT_ID = "origin_parent_id"; - - /** - * The gtask id - *Type : TEXT
- */ - public static final String GTASK_ID = "gtask_id"; - - /** - * The version code - *Type : INTEGER (long)
- */ - public static final String VERSION = "version"; - } - - public interface DataColumns { - /** - * The unique ID for a row - *Type: INTEGER (long)
- */ - public static final String ID = "_id"; - - /** - * The MIME type of the item represented by this row. - *Type: Text
- */ - public static final String MIME_TYPE = "mime_type"; - - /** - * The reference id to note that this data belongs to - *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 - *Type: INTEGER
- */ - public static final String DATA1 = "data1"; - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * integer data type - *Type: INTEGER
- */ - public static final String DATA2 = "data2"; - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * TEXT data type - *Type: TEXT
- */ - public static final String DATA3 = "data3"; - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * TEXT data type - *Type: TEXT
- */ - public static final String DATA4 = "data4"; - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * TEXT data type - *Type: TEXT
- */ - public static final String DATA5 = "data5"; - } - - 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; - - 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"); - } - - 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; - - 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"); - } -} diff --git a/src/net/micode/notes/data/NotesProvider.java b/src/net/micode/notes/data/NotesProvider.java deleted file mode 100644 index edb0a60..0000000 --- a/src/net/micode/notes/data/NotesProvider.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * 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; -import android.content.ContentValues; -import android.content.Intent; -import android.content.UriMatcher; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; - -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; - - -public class NotesProvider extends ContentProvider { - private static final UriMatcher mMatcher; - - private NotesDatabaseHelper mHelper; - - private static final String TAG = "NotesProvider"; - - private static final int URI_NOTE = 1; - private static final int URI_NOTE_ITEM = 2; - private static final int URI_DATA = 3; - private static final int URI_DATA_ITEM = 4; - - private static final int URI_SEARCH = 5; - private static final int URI_SEARCH_SUGGEST = 6; - - static { - 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); - mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM); - 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); - } - - /** - * 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. - */ - 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; - - 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; - - @Override - public boolean onCreate() { - mHelper = NotesDatabaseHelper.getInstance(getContext()); - return true; - } - - @Override - public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, - String sortOrder) { - Cursor c = null; - SQLiteDatabase db = mHelper.getReadableDatabase(); - String id = null; - switch (mMatcher.match(uri)) { - case URI_NOTE: - c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, - 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; - case URI_DATA: - c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, - sortOrder); - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); - c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id - + parseSelection(selection), selectionArgs, null, null, sortOrder); - break; - case URI_SEARCH: - case URI_SEARCH_SUGGEST: - if (sortOrder != null || projection != null) { - throw new IllegalArgumentException( - "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); - } - - String searchString = null; - if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { - if (uri.getPathSegments().size() > 1) { - searchString = uri.getPathSegments().get(1); - } - } else { - searchString = uri.getQueryParameter("pattern"); - } - - if (TextUtils.isEmpty(searchString)) { - return null; - } - - try { - searchString = String.format("%%%s%%", searchString); - c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, - new String[] { searchString }); - } catch (IllegalStateException ex) { - Log.e(TAG, "got exception: " + ex.toString()); - } - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - if (c != null) { - c.setNotificationUri(getContext().getContentResolver(), uri); - } - return c; - } - - @Override - 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; - case URI_DATA: - if (values.containsKey(DataColumns.NOTE_ID)) { - noteId = values.getAsLong(DataColumns.NOTE_ID); - } else { - Log.d(TAG, "Wrong data format without note id:" + values.toString()); - } - insertedId = dataId = db.insert(TABLE.DATA, null, values); - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - // Notify the note uri - if (noteId > 0) { - getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); - } - - // Notify the data uri - if (dataId > 0) { - getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); - } - - return ContentUris.withAppendedId(uri, insertedId); - } - - @Override - public int delete(Uri uri, String selection, String[] selectionArgs) { - int count = 0; - String id = null; - SQLiteDatabase db = mHelper.getWritableDatabase(); - boolean deleteData = false; - switch (mMatcher.match(uri)) { - case URI_NOTE: - selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; - count = db.delete(TABLE.NOTE, selection, selectionArgs); - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); - /** - * ID that smaller than 0 is system folder which is not allowed to - * trash - */ - long noteId = Long.valueOf(id); - if (noteId <= 0) { - break; - } - count = db.delete(TABLE.NOTE, - NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs); - break; - case URI_DATA: - count = db.delete(TABLE.DATA, selection, selectionArgs); - deleteData = true; - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); - count = db.delete(TABLE.DATA, - DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs); - deleteData = true; - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - if (count > 0) { - if (deleteData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); - } - getContext().getContentResolver().notifyChange(uri, null); - } - return count; - } - - @Override - 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)) { - case URI_NOTE: - increaseNoteVersion(-1, selection, selectionArgs); - count = db.update(TABLE.NOTE, values, selection, selectionArgs); - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); - increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); - count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id - + parseSelection(selection), selectionArgs); - break; - case URI_DATA: - count = db.update(TABLE.DATA, values, selection, selectionArgs); - updateData = true; - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); - count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id - + parseSelection(selection), selectionArgs); - updateData = true; - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - - if (count > 0) { - if (updateData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); - } - getContext().getContentResolver().notifyChange(uri, null); - } - return count; - } - - private String parseSelection(String selection) { - return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); - } - - 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 "); - - 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; - for (String args : selectionArgs) { - selectString = selectString.replaceFirst("\\?", args); - } - sql.append(selectString); - } - - mHelper.getWritableDatabase().execSQL(sql.toString()); - } - - @Override - public String getType(Uri uri) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/src/net/micode/notes/data/Contact.java b/src1/net/micode/notes/data/Contact.java similarity index 100% rename from src/net/micode/notes/data/Contact.java rename to src1/net/micode/notes/data/Contact.java diff --git a/src1/net/micode/notes/data/Notes.java b/src1/net/micode/notes/data/Notes.java new file mode 100644 index 0000000..820295d --- /dev/null +++ b/src1/net/micode/notes/data/Notes.java @@ -0,0 +1,100 @@ +package net.micode.notes.data; // 定义包名 + +import android.content.ContentUris; // 用于操作URI,如添加ID到URI中 +import android.net.Uri; // 用于表示URI的类 + +// Notes 类定义了与便签应用相关的常量,包括URI、类型、ID等 +public class Notes { + public static final String AUTHORITY = "micode_notes"; // 内容提供者的权限标识 + public static final String TAG = "Notes"; // 日志标签 + + // 定义笔记、文件夹和系统类型的常量 + public static final int TYPE_NOTE = 0; // 笔记类型 + public static final int TYPE_FOLDER = 1; // 文件夹类型 + public static final int TYPE_SYSTEM = 2; // 系统类型 + + // 系统文件夹的ID常量 + public static final int ID_ROOT_FOLDER = 0; // 根文件夹ID + public static final int ID_TEMPARAY_FOLDER = -1; // 临时文件夹ID + public static final int ID_CALL_RECORD_FOLDER = -2; // 电话记录文件夹ID + public static final int ID_TRASH_FOLER = -3; // 垃圾桶文件夹ID + + // 意图(Intent)中使用的额外数据键 + public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; // 警告日期 + public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id"; // 背景颜色ID + public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id"; // 小部件ID + public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type"; // 小部件类型 + public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; // 文件夹ID + public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; // 电话日期 + + // 小部件类型的常量 + public static final int TYPE_WIDGET_INVALIDE = -1; // 无效的小部件类型 + public static final int TYPE_WIDGET_2X = 0; // 2x2小部件 + public static final int TYPE_WIDGET_4X = 1; // 4x4小部件 + + // 数据常量类,包含笔记和电话记录的MIME类型 + public static class DataConstants { + public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; // 文本笔记MIME类型 + public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; // 电话记录MIME类型 + } + + // 查询所有笔记和文件夹的URI + public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); + + // 查询数据的URI + public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); + + // NoteColumns接口定义了笔记相关字段 + public interface NoteColumns { + public static final String ID = "_id"; // 唯一ID + public static final String PARENT_ID = "parent_id"; // 父ID,用于文件夹结构 + public static final String CREATED_DATE = "created_date"; // 创建日期 + public static final String MODIFIED_DATE = "modified_date"; // 修改日期 + public static final String ALERTED_DATE = "alert_date"; // 警告日期 + public static final String SNIPPET = "snippet"; // 文件夹名或笔记内容摘要 + public static final String WIDGET_ID = "widget_id"; // 小部件ID + public static final String WIDGET_TYPE = "widget_type"; // 小部件类型 + public static final String BG_COLOR_ID = "bg_color_id"; // 背景颜色ID + public static final String HAS_ATTACHMENT = "has_attachment"; // 是否有附件 + public static final String NOTES_COUNT = "notes_count"; // 文件夹中的笔记数量 + public static final String TYPE = "type"; // 类型(笔记或文件夹) + public static final String SYNC_ID = "sync_id"; // 同步ID + public static final String LOCAL_MODIFIED = "local_modified"; // 本地修改标志 + public static final String ORIGIN_PARENT_ID = "origin_parent_id"; // 原始父ID + public static final String GTASK_ID = "gtask_id"; // Google任务ID + public static final String VERSION = "version"; // 版本号 + } + + // DataColumns接口定义了数据表相关字段 + public interface DataColumns { + public static final String ID = "_id"; // 唯一ID + public static final String MIME_TYPE = "mime_type"; // MIME类型 + public static final String NOTE_ID = "note_id"; // 对应的笔记ID + public static final String CREATED_DATE = "created_date"; // 创建日期 + public static final String MODIFIED_DATE = "modified_date"; // 修改日期 + public static final String CONTENT = "content"; // 数据内容 + public static final String DATA1 = "data1"; // 通用数据列1 + public static final String DATA2 = "data2"; // 通用数据列2 + public static final String DATA3 = "data3"; // 通用数据列3 + public static final String DATA4 = "data4"; // 通用数据列4 + public static final String DATA5 = "data5"; // 通用数据列5 + } + + // TextNote类定义了文本笔记相关的常量 + public static final class TextNote implements DataColumns { + public static final String MODE = DATA1; // 模式,检查列表模式或普通模式 + public static final int MODE_CHECK_LIST = 1; // 检查列表模式值 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; // 目录MIME类型 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; // 项目MIME类型 + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); // 文本笔记URI + } + + // CallNote类定义了电话记录相关的常量 + public static final class CallNote implements DataColumns { + public static final String CALL_DATE = DATA1; // 电话日期 + public static final String PHONE_NUMBER = DATA3; // 电话号码 + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; // 目录MIME类型 + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; // 项目MIME类型 + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); // 电话记录URI + } +} diff --git a/src/net/micode/notes/data/NotesDatabaseHelper.java b/src1/net/micode/notes/data/NotesDatabaseHelper.java similarity index 100% rename from src/net/micode/notes/data/NotesDatabaseHelper.java rename to src1/net/micode/notes/data/NotesDatabaseHelper.java diff --git a/src1/net/micode/notes/data/NotesProvider.java b/src1/net/micode/notes/data/NotesProvider.java new file mode 100644 index 0000000..cf445c0 --- /dev/null +++ b/src1/net/micode/notes/data/NotesProvider.java @@ -0,0 +1,323 @@ +package net.micode.notes.data; // 定义包名 +import android.app.SearchManager; // 搜索管理器,用于处理搜索建议等 +import android.content.ContentProvider; // Android内容提供者基类 +import android.content.ContentUris; // 用于操作URI,如添加ID到URI中 +import android.content.ContentValues; // 用于存储数据的键值对,便于数据库操作 +import android.content.Intent; // 用于应用程序之间传递数据的意图 +import android.content.UriMatcher; // 用于匹配URI +import android.database.Cursor; // 用于数据库查询结果集的迭代 +import android.database.sqlite.SQLiteDatabase; // 用于执行SQL语句和进行数据库操作 +import android.net.Uri; // 用于表示URI的类 +import android.text.TextUtils; // 文本操作工具类 +import android.util.Log; // 用于日志输出 +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; // 数据表名称常量 + +// NotesProvider类继承自ContentProvider,用于提供数据共享接口 +public class NotesProvider extends ContentProvider { + // UriMatcher用于匹配URI + private static final UriMatcher mMatcher; + + private NotesDatabaseHelper mHelper; // 数据库帮助类实例 + + private static final String TAG = "NotesProvider"; // 日志标签 + + // 定义匹配URI的常量 + private static final int URI_NOTE = 1;//用于标识笔记资源 + private static final int URI_NOTE_ITEM = 2;//用于标识单个笔记资源 + private static final int URI_DATA = 3;//用于标识数据资源 + private static final int URI_DATA_ITEM = 4;//用于标识单个数据资源 + private static final int URI_SEARCH = 5;//搜索功能 + 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);//数据表 + mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);//数据表中的某条数据 + 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);//搜索建议 + } + + // 声明搜索结果的投影 + private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","//笔记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;//意图数据类型 + + // 声明搜索查询 + 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;//笔记类型 + + @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) { + 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); + 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; + case URI_DATA: + c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, + sortOrder); + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1); + c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id + + parseSelection(selection), selectionArgs, null, null, sortOrder); + break; + case URI_SEARCH: + case URI_SEARCH_SUGGEST: + if (sortOrder != null || projection != null) { + // 不合法的参数异常 + throw new IllegalArgumentException( + "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); + } + + 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 { + searchString = uri.getQueryParameter("pattern"); + } + + if (TextUtils.isEmpty(searchString)) { + return null; + } + + try { + searchString = String.format("%%%s%%", searchString); + c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, + new String[] { searchString }); + } catch (IllegalStateException ex) { + Log.e(TAG, "got exception: " + ex.toString()); + } + break; + default: + // 抛出异常 + throw new IllegalArgumentException("Unknown URI " + uri); + } + if (c != null) { + c.setNotificationUri(getContext().getContentResolver(), uri); + } + return c; + } + + @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); + } else { + Log.d(TAG, "Wrong data format without note id:" + values.toString()); + } + insertedId = dataId = db.insert(TABLE.DATA, null, values); + break; + default: + 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); + } + + // Notify the data uri + if (dataId > 0) { + getContext().getContentResolver().notifyChange( + 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)) { + case URI_NOTE: + selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; + count = db.delete(TABLE.NOTE, selection, selectionArgs); + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1); + /** + * ID that smaller than 0 is system folder which is not allowed to + * trash + */ + long noteId = Long.valueOf(id); + if (noteId <= 0) { + break; + } + count = db.delete(TABLE.NOTE, + NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs); + break; + case URI_DATA: + count = db.delete(TABLE.DATA, selection, selectionArgs); + deleteData = true; + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1); + count = db.delete(TABLE.DATA, + DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs); + deleteData = true; + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + if (count > 0) { + if (deleteData) { + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); + } + getContext().getContentResolver().notifyChange(uri, null); + } + return count; + } + + @Override +// 更新一个uri +public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count = 0; // 记录更新的行数 + String id = null; // 用于存储URI中的ID部分 + SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写的数据库实例 + boolean updateData = false; // 标记是否需要更新数据表 + + // 根据URI匹配不同的操作 + switch (mMatcher.match(uri)) { + case URI_NOTE: + // 更新笔记表中的多条记录 + increaseNoteVersion(-1, selection, selectionArgs); // 增加笔记版本号 + count = db.update(TABLE.NOTE, values, selection, selectionArgs); // 执行更新操作 + break; + case URI_NOTE_ITEM: + // 更新笔记表中的单条记录 + id = uri.getPathSegments().get(1); // 从URI中获取ID + increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); // 增加指定笔记的版本号 + count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id + + parseSelection(selection), selectionArgs); // 执行更新操作 + break; + case URI_DATA: + // 更新数据表中的多条记录 + count = db.update(TABLE.DATA, values, selection, selectionArgs); // 执行更新操作 + updateData = true; // 设置更新数据表的标记为true + break; + case URI_DATA_ITEM: + // 更新数据表中的单条记录 + id = uri.getPathSegments().get(1); // 从URI中获取ID + count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id + + parseSelection(selection), selectionArgs); // 执行更新操作 + updateData = true; // 设置更新数据表的标记为true + break; + default: + // 如果URI不匹配任何已知类型,则抛出异常 + throw new IllegalArgumentException("Unknown URI " + uri); + } + + // 如果有行被更新,则通知相关URI的监听器 + if (count > 0) { + if (updateData) { + // 如果更新了数据表,则通知笔记表的URI + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); + } + // 通知当前URI的监听器 + getContext().getContentResolver().notifyChange(uri, null); + } + return count; // 返回更新的行数 +} + +/// 将字符串解析成规定格式 +private String parseSelection(String selection) { + // 如果传入的选择字符串不为空,则在 selection 前后添加 " AND (" 和 ")",否则返回空字符串 + return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); +} + +// 增加一个noteVersion +private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { + // 创建StringBuilder对象,用于构建SQL语句 + StringBuilder sql = new StringBuilder(120); + sql.append("UPDATE "); // 添加UPDATE关键字 + sql.append(TABLE.NOTE); // 添加表名NOTE + sql.append(" SET "); // 添加SET关键字 + sql.append(NoteColumns.VERSION); // 添加版本号列名 + sql.append("=" + NoteColumns.VERSION + "+1 "); // 版本号列值加1 + + // 如果ID大于0或者选择字符串不为空,则添加WHERE关键字 + if (id > 0 || !TextUtils.isEmpty(selection)) { + sql.append(" WHERE "); + } + // 如果ID大于0,则添加ID等于指定值的条件 + if (id > 0) { + sql.append(NoteColumns.ID + "=" + String.valueOf(id)); + } + // 如果选择字符串不为空,则添加解析后的选择字符串作为条件 + if (!TextUtils.isEmpty(selection)) { + String selectString = id > 0 ? parseSelection(selection) : selection; + // 将选择字符串中的占位符替换为实际的参数值 + for (String args : selectionArgs) { + selectString = selectString.replaceFirst("\\?", args); + } + sql.append(selectString); + } + + // 使用execSQL方法执行构建的SQL语句 + mHelper.getWritableDatabase().execSQL(sql.toString()); +} + +@Override +public String getType(Uri uri) { + // TODO: 需要实现该方法来返回给定URI的MIME类型,暂时返回null + return null; +} diff --git a/src/net/micode/notes/gtask/data/MetaData.java b/src1/net/micode/notes/gtask/data/MetaData.java similarity index 100% rename from src/net/micode/notes/gtask/data/MetaData.java rename to src1/net/micode/notes/gtask/data/MetaData.java diff --git a/src/net/micode/notes/gtask/data/Node.java b/src1/net/micode/notes/gtask/data/Node.java similarity index 100% rename from src/net/micode/notes/gtask/data/Node.java rename to src1/net/micode/notes/gtask/data/Node.java diff --git a/src/net/micode/notes/gtask/data/SqlData.java b/src1/net/micode/notes/gtask/data/SqlData.java similarity index 100% rename from src/net/micode/notes/gtask/data/SqlData.java rename to src1/net/micode/notes/gtask/data/SqlData.java diff --git a/src/net/micode/notes/gtask/data/SqlNote.java b/src1/net/micode/notes/gtask/data/SqlNote.java similarity index 100% rename from src/net/micode/notes/gtask/data/SqlNote.java rename to src1/net/micode/notes/gtask/data/SqlNote.java diff --git a/src/net/micode/notes/gtask/data/Task.java b/src1/net/micode/notes/gtask/data/Task.java similarity index 100% rename from src/net/micode/notes/gtask/data/Task.java rename to src1/net/micode/notes/gtask/data/Task.java diff --git a/src/net/micode/notes/gtask/data/TaskList.java b/src1/net/micode/notes/gtask/data/TaskList.java similarity index 100% rename from src/net/micode/notes/gtask/data/TaskList.java rename to src1/net/micode/notes/gtask/data/TaskList.java diff --git a/src/net/micode/notes/gtask/exception/ActionFailureException.java b/src1/net/micode/notes/gtask/exception/ActionFailureException.java similarity index 100% rename from src/net/micode/notes/gtask/exception/ActionFailureException.java rename to src1/net/micode/notes/gtask/exception/ActionFailureException.java diff --git a/src/net/micode/notes/gtask/exception/NetworkFailureException.java b/src1/net/micode/notes/gtask/exception/NetworkFailureException.java similarity index 100% rename from src/net/micode/notes/gtask/exception/NetworkFailureException.java rename to src1/net/micode/notes/gtask/exception/NetworkFailureException.java diff --git a/src/net/micode/notes/gtask/remote/GTaskASyncTask.java b/src1/net/micode/notes/gtask/remote/GTaskASyncTask.java similarity index 100% rename from src/net/micode/notes/gtask/remote/GTaskASyncTask.java rename to src1/net/micode/notes/gtask/remote/GTaskASyncTask.java diff --git a/src/net/micode/notes/gtask/remote/GTaskClient.java b/src1/net/micode/notes/gtask/remote/GTaskClient.java similarity index 100% rename from src/net/micode/notes/gtask/remote/GTaskClient.java rename to src1/net/micode/notes/gtask/remote/GTaskClient.java diff --git a/src/net/micode/notes/gtask/remote/GTaskManager.java b/src1/net/micode/notes/gtask/remote/GTaskManager.java similarity index 100% rename from src/net/micode/notes/gtask/remote/GTaskManager.java rename to src1/net/micode/notes/gtask/remote/GTaskManager.java diff --git a/src/net/micode/notes/gtask/remote/GTaskSyncService.java b/src1/net/micode/notes/gtask/remote/GTaskSyncService.java similarity index 100% rename from src/net/micode/notes/gtask/remote/GTaskSyncService.java rename to src1/net/micode/notes/gtask/remote/GTaskSyncService.java diff --git a/src/net/micode/notes/model/Note.java b/src1/net/micode/notes/model/Note.java similarity index 100% rename from src/net/micode/notes/model/Note.java rename to src1/net/micode/notes/model/Note.java diff --git a/src/net/micode/notes/model/WorkingNote.java b/src1/net/micode/notes/model/WorkingNote.java similarity index 100% rename from src/net/micode/notes/model/WorkingNote.java rename to src1/net/micode/notes/model/WorkingNote.java diff --git a/src/net/micode/notes/tool/BackupUtils.java b/src1/net/micode/notes/tool/BackupUtils.java similarity index 100% rename from src/net/micode/notes/tool/BackupUtils.java rename to src1/net/micode/notes/tool/BackupUtils.java diff --git a/src/net/micode/notes/tool/DataUtils.java b/src1/net/micode/notes/tool/DataUtils.java similarity index 100% rename from src/net/micode/notes/tool/DataUtils.java rename to src1/net/micode/notes/tool/DataUtils.java diff --git a/src/net/micode/notes/tool/GTaskStringUtils.java b/src1/net/micode/notes/tool/GTaskStringUtils.java similarity index 100% rename from src/net/micode/notes/tool/GTaskStringUtils.java rename to src1/net/micode/notes/tool/GTaskStringUtils.java diff --git a/src/net/micode/notes/tool/ResourceParser.java b/src1/net/micode/notes/tool/ResourceParser.java similarity index 100% rename from src/net/micode/notes/tool/ResourceParser.java rename to src1/net/micode/notes/tool/ResourceParser.java diff --git a/src/net/micode/notes/ui/AlarmAlertActivity.java b/src1/net/micode/notes/ui/AlarmAlertActivity.java similarity index 100% rename from src/net/micode/notes/ui/AlarmAlertActivity.java rename to src1/net/micode/notes/ui/AlarmAlertActivity.java diff --git a/src/net/micode/notes/ui/AlarmInitReceiver.java b/src1/net/micode/notes/ui/AlarmInitReceiver.java similarity index 74% rename from src/net/micode/notes/ui/AlarmInitReceiver.java rename to src1/net/micode/notes/ui/AlarmInitReceiver.java index f221202..220c8ad 100644 --- a/src/net/micode/notes/ui/AlarmInitReceiver.java +++ b/src1/net/micode/notes/ui/AlarmInitReceiver.java @@ -28,37 +28,52 @@ import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; +// 定义一个名为AlarmInitReceiver的类,继承自BroadcastReceiver public class AlarmInitReceiver extends BroadcastReceiver { + // 定义一个字符串数组,包含NoteColumns中的ID和ALERTED_DATE private static final String [] PROJECTION = new String [] { NoteColumns.ID, NoteColumns.ALERTED_DATE }; + // 定义两个常量,分别表示ID和ALERTED_DATE的列索引 private static final int COLUMN_ID = 0; private static final int COLUMN_ALERTED_DATE = 1; @Override public void onReceive(Context context, Intent intent) { + // 获取当前时间 long currentDate = System.currentTimeMillis(); + // 查询数据库,获取所有未提醒的笔记 Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE, new String[] { String.valueOf(currentDate) }, null); + // 如果c不为空 if (c != null) { + // 如果c可以移动到第一行 if (c.moveToFirst()) { + // 循环遍历c do { + // 获取提醒日期 long alertDate = c.getLong(COLUMN_ALERTED_DATE); + // 创建一个Intent,指向AlarmReceiver类 Intent sender = new Intent(context, AlarmReceiver.class); + // 设置Intent的数据,指向Notes.CONTENT_NOTE_URI,并添加c.getLong(COLUMN_ID)作为参数 sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID))); + // 创建一个PendingIntent,用于发送广播 PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0); + // 获取AlarmManager服务 AlarmManager alermManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); + // 设置闹钟,在alertDate时间点唤醒设备,并发送广播 alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); } while (c.moveToNext()); } + // 关闭c c.close(); } } diff --git a/src/net/micode/notes/ui/AlarmReceiver.java b/src1/net/micode/notes/ui/AlarmReceiver.java similarity index 100% rename from src/net/micode/notes/ui/AlarmReceiver.java rename to src1/net/micode/notes/ui/AlarmReceiver.java diff --git a/src/net/micode/notes/ui/DateTimePicker.java b/src1/net/micode/notes/ui/DateTimePicker.java similarity index 70% rename from src/net/micode/notes/ui/DateTimePicker.java rename to src1/net/micode/notes/ui/DateTimePicker.java index 496b0cd..468294e 100644 --- a/src/net/micode/notes/ui/DateTimePicker.java +++ b/src1/net/micode/notes/ui/DateTimePicker.java @@ -67,8 +67,11 @@ public class DateTimePicker extends FrameLayout { private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { + // 将日期增加或减少指定的天数 mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal); + // 更新日期控件 updateDateControl(); + // 日期时间改变时调用 onDateTimeChanged(); } }; @@ -76,37 +79,52 @@ public class DateTimePicker extends FrameLayout { private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { + // 判断是否日期改变 boolean isDateChanged = false; + // 获取当前时间 Calendar cal = Calendar.getInstance(); + // 判断是否为24小时制 if (!mIs24HourView) { + // 判断是否为上午 if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) { + // 如果当前时间是上午11点,并且选择的时间是下午12点,则日期加1天 cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, 1); isDateChanged = true; } else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) { + // 如果当前时间是下午12点,并且选择的时间是上午11点,则日期减1天 cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, -1); isDateChanged = true; } + // 判断是否跨过12点 if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY || oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) { + // 跨过12点,则上午和下午互换 mIsAm = !mIsAm; updateAmPmControl(); } } else { + // 判断是否跨过24点 if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) { + // 如果当前时间是23点,并且选择的时间是0点,则日期加1天 cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, 1); isDateChanged = true; } else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) { + // 如果当前时间是0点,并且选择的时间是23点,则日期减1天 cal.setTimeInMillis(mDate.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, -1); isDateChanged = true; } } + // 计算新的小时数 int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY); + // 设置新的小时数 mDate.set(Calendar.HOUR_OF_DAY, newHour); + // 通知时间改变 onDateTimeChanged(); + // 如果日期改变,则更新日期 if (isDateChanged) { setCurrentYear(cal.get(Calendar.YEAR)); setCurrentMonth(cal.get(Calendar.MONTH)); @@ -118,84 +136,120 @@ public class DateTimePicker extends FrameLayout { private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { + // 获取分钟选择器的最小值和最大值 int minValue = mMinuteSpinner.getMinValue(); int maxValue = mMinuteSpinner.getMaxValue(); int offset = 0; + // 如果旧值等于最大值且新值等于最小值,则偏移量为1 if (oldVal == maxValue && newVal == minValue) { offset += 1; + // 如果旧值等于最小值且新值等于最大值,则偏移量为-1 } else if (oldVal == minValue && newVal == maxValue) { offset -= 1; } + // 如果偏移量不为0,则更新日期和时间 if (offset != 0) { mDate.add(Calendar.HOUR_OF_DAY, offset); mHourSpinner.setValue(getCurrentHour()); updateDateControl(); int newHour = getCurrentHourOfDay(); + // 如果新小时数大于等于半天的小时数,则更新上午/下午控制 if (newHour >= HOURS_IN_HALF_DAY) { mIsAm = false; updateAmPmControl(); + // 否则,更新上午/下午控制 } else { mIsAm = true; updateAmPmControl(); } } + // 设置新分钟值 mDate.set(Calendar.MINUTE, newVal); + // 日期时间改变 onDateTimeChanged(); } }; +// 定义一个NumberPicker的值改变监听器 private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { + // 切换AM/PM mIsAm = !mIsAm; + // 如果是AM,则将时间减去12小时 if (mIsAm) { mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY); + // 如果是PM,则将时间加上12小时 } else { mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY); } + // 更新AM/PM控制 updateAmPmControl(); + // 日期时间改变 onDateTimeChanged(); } }; public interface OnDateTimeChangedListener { + // 当日期时间改变时调用的方法 void onDateTimeChanged(DateTimePicker view, int year, int month, int dayOfMonth, int hourOfDay, int minute); } + // 构造方法,使用当前时间作为日期时间 public DateTimePicker(Context context) { this(context, System.currentTimeMillis()); } + // 构造方法,使用指定时间作为日期时间 public DateTimePicker(Context context, long date) { this(context, date, DateFormat.is24HourFormat(context)); } public DateTimePicker(Context context, long date, boolean is24HourView) { super(context); + // 获取当前日期 mDate = Calendar.getInstance(); mInitialising = true; + // 判断当前小时是否大于等于12 mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY; + // 加载布局文件 inflate(context, R.layout.datetime_picker, this); + // 获取日期选择器 mDateSpinner = (NumberPicker) findViewById(R.id.date); + // 设置日期选择器的最小值 mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL); + // 设置日期选择器的最大值 mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL); + // 设置日期选择器的值改变监听器 mDateSpinner.setOnValueChangedListener(mOnDateChangedListener); + // 获取小时选择器 mHourSpinner = (NumberPicker) findViewById(R.id.hour); + // 设置小时选择器的值改变监听器 mHourSpinner.setOnValueChangedListener(mOnHourChangedListener); + // 获取分钟选择器 mMinuteSpinner = (NumberPicker) findViewById(R.id.minute); + // 设置分钟选择器的最小值 mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL); + // 设置分钟选择器的最大值 mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL); + // 设置分钟选择器的长按更新间隔 mMinuteSpinner.setOnLongPressUpdateInterval(100); + // 设置分钟选择器的值改变监听器 mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener); + // 获取上午下午选择器 String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings(); mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm); + // 设置上午下午选择器的最小值 mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL); + // 设置上午下午选择器的最大值 mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL); + // 设置上午下午选择器的显示值 mAmPmSpinner.setDisplayedValues(stringsForAmPm); + // 设置上午下午选择器的值改变监听器 mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener); // update controls to initial state @@ -215,20 +269,29 @@ public class DateTimePicker extends FrameLayout { } @Override + // 重写setEnabled方法 public void setEnabled(boolean enabled) { + // 如果当前状态和传入的状态相同,则直接返回 if (mIsEnabled == enabled) { return; } + // 调用父类的setEnabled方法 super.setEnabled(enabled); + // 设置日期选择器是否可用 mDateSpinner.setEnabled(enabled); + // 设置分钟选择器是否可用 mMinuteSpinner.setEnabled(enabled); + // 设置小时选择器是否可用 mHourSpinner.setEnabled(enabled); + // 设置上午/下午选择器是否可用 mAmPmSpinner.setEnabled(enabled); + // 更新当前状态 mIsEnabled = enabled; } @Override public boolean isEnabled() { + // 返回mIsEnabled的值 return mIsEnabled; } @@ -247,8 +310,11 @@ public class DateTimePicker extends FrameLayout { * @param date The current date in millis */ public void setCurrentDate(long date) { + // 获取当前日期 Calendar cal = Calendar.getInstance(); + // 将传入的日期转换为毫秒 cal.setTimeInMillis(date); + // 设置当前日期 setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)); } @@ -264,10 +330,15 @@ public class DateTimePicker extends FrameLayout { */ public void setCurrentDate(int year, int month, int dayOfMonth, int hourOfDay, int minute) { + // 设置当前年份 setCurrentYear(year); + // 设置当前月份 setCurrentMonth(month); + // 设置当前日期 setCurrentDay(dayOfMonth); + // 设置当前小时 setCurrentHour(hourOfDay); + // 设置当前分钟 setCurrentMinute(minute); } @@ -277,6 +348,7 @@ public class DateTimePicker extends FrameLayout { * @return The current year */ public int getCurrentYear() { + // 获取当前年份 return mDate.get(Calendar.YEAR); } @@ -286,11 +358,15 @@ public class DateTimePicker extends FrameLayout { * @param year The current year */ public void setCurrentYear(int year) { + // 如果当前年份与传入的年份相同,则不进行任何操作 if (!mInitialising && year == getCurrentYear()) { return; } + // 设置当前年份 mDate.set(Calendar.YEAR, year); + // 更新日期控件 updateDateControl(); + // 日期时间改变 onDateTimeChanged(); } @@ -300,6 +376,7 @@ public class DateTimePicker extends FrameLayout { * @return The current month in the year */ public int getCurrentMonth() { + // 获取当前月份 return mDate.get(Calendar.MONTH); } @@ -309,11 +386,15 @@ public class DateTimePicker extends FrameLayout { * @param month The month in the year */ public void setCurrentMonth(int month) { + // 如果当前月份和要设置的月份相同,则不进行设置 if (!mInitialising && month == getCurrentMonth()) { return; } + // 设置当前月份 mDate.set(Calendar.MONTH, month); + // 更新日期控件 updateDateControl(); + // 日期改变回调 onDateTimeChanged(); } @@ -322,7 +403,9 @@ public class DateTimePicker extends FrameLayout { * * @return The day of the month */ + // 获取当前日期 public int getCurrentDay() { + // 获取当前日期的日 return mDate.get(Calendar.DAY_OF_MONTH); } @@ -332,11 +415,15 @@ public class DateTimePicker extends FrameLayout { * @param dayOfMonth The day of the month */ public void setCurrentDay(int dayOfMonth) { + // 如果当前不在初始化状态,并且传入的日期与当前日期相同,则直接返回 if (!mInitialising && dayOfMonth == getCurrentDay()) { return; } + // 设置当前日期 mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); + // 更新日期控件 updateDateControl(); + // 日期改变时触发 onDateTimeChanged(); } @@ -344,18 +431,26 @@ public class DateTimePicker extends FrameLayout { * Get current hour in 24 hour mode, in the range (0~23) * @return The current hour in 24 hour mode */ + // 获取当前小时 public int getCurrentHourOfDay() { return mDate.get(Calendar.HOUR_OF_DAY); } +// 获取当前小时 private int getCurrentHour() { + // 如果是24小时制 if (mIs24HourView){ + // 获取当前小时 return getCurrentHourOfDay(); } else { + // 获取当前小时 int hour = getCurrentHourOfDay(); + // 如果当前小时大于12 if (hour > HOURS_IN_HALF_DAY) { + // 返回当前小时减去12 return hour - HOURS_IN_HALF_DAY; } else { + // 如果当前小时等于0,返回12 return hour == 0 ? HOURS_IN_HALF_DAY : hour; } } @@ -366,26 +461,40 @@ public class DateTimePicker extends FrameLayout { * * @param hourOfDay */ + // 设置当前小时 public void setCurrentHour(int hourOfDay) { + // 如果当前正在初始化,或者当前小时和要设置的小时相同,则直接返回 if (!mInitialising && hourOfDay == getCurrentHourOfDay()) { return; } + // 设置当前小时 mDate.set(Calendar.HOUR_OF_DAY, hourOfDay); + // 如果不是24小时制 if (!mIs24HourView) { + // 如果当前小时大于等于12 if (hourOfDay >= HOURS_IN_HALF_DAY) { + // 设置为下午 mIsAm = false; + // 如果当前小时大于12 if (hourOfDay > HOURS_IN_HALF_DAY) { + // 当前小时减去12 hourOfDay -= HOURS_IN_HALF_DAY; } } else { + // 设置为上午 mIsAm = true; + // 如果当前小时为0 if (hourOfDay == 0) { + // 当前小时设置为12 hourOfDay = HOURS_IN_HALF_DAY; } } + // 更新上午/下午控制 updateAmPmControl(); } + // 设置小时选择器的值 mHourSpinner.setValue(hourOfDay); + // 日期时间改变 onDateTimeChanged(); } @@ -394,6 +503,7 @@ public class DateTimePicker extends FrameLayout { * * @return The Current Minute */ + // 获取当前分钟 public int getCurrentMinute() { return mDate.get(Calendar.MINUTE); } @@ -402,17 +512,22 @@ public class DateTimePicker extends FrameLayout { * Set current minute */ public void setCurrentMinute(int minute) { + // 如果mInitialising为false且minute等于getCurrentMinute(),则直接返回 if (!mInitialising && minute == getCurrentMinute()) { return; } + // 设置mMinuteSpinner的值为minute mMinuteSpinner.setValue(minute); + // 设置mDate的分钟为minute mDate.set(Calendar.MINUTE, minute); + // 调用onDateTimeChanged()方法 onDateTimeChanged(); } /** * @return true if this is in 24 hour view else false. */ + // 判断是否为24小时制 public boolean is24HourView () { return mIs24HourView; } @@ -423,47 +538,73 @@ public class DateTimePicker extends FrameLayout { * @param is24HourView True for 24 hour mode. False for AM/PM mode. */ public void set24HourView(boolean is24HourView) { + // 如果当前时间格式和传入的时间格式相同,则直接返回 if (mIs24HourView == is24HourView) { return; } + // 更新时间格式 mIs24HourView = is24HourView; + // 如果是24小时制,则隐藏上午/下午选择器 mAmPmSpinner.setVisibility(is24HourView ? View.GONE : View.VISIBLE); + // 获取当前小时数 int hour = getCurrentHourOfDay(); + // 更新小时选择器 updateHourControl(); + // 设置当前小时数 setCurrentHour(hour); + // 更新上午/下午选择器 updateAmPmControl(); } private void updateDateControl() { + // 获取当前日期 Calendar cal = Calendar.getInstance(); + // 将当前日期设置为mDate的时间 cal.setTimeInMillis(mDate.getTimeInMillis()); + // 将当前日期向前推DAYS_IN_ALL_WEEK / 2 - 1天 cal.add(Calendar.DAY_OF_YEAR, -DAYS_IN_ALL_WEEK / 2 - 1); + // 清空mDateSpinner的显示值 mDateSpinner.setDisplayedValues(null); + // 循环DAYS_IN_ALL_WEEK次 for (int i = 0; i < DAYS_IN_ALL_WEEK; ++i) { + // 将当前日期加1天 cal.add(Calendar.DAY_OF_YEAR, 1); + // 将当前日期格式化为"MM.dd EEEE"的字符串 mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE", cal); } + // 将mDateSpinner的显示值设置为mDateDisplayValues mDateSpinner.setDisplayedValues(mDateDisplayValues); + // 将mDateSpinner的值设置为DAYS_IN_ALL_WEEK / 2 mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2); + // 使mDateSpinner无效 mDateSpinner.invalidate(); } private void updateAmPmControl() { + // 如果是24小时制,则隐藏上午/下午选择器 if (mIs24HourView) { mAmPmSpinner.setVisibility(View.GONE); } else { + // 如果是上午,则选择上午,否则选择下午 int index = mIsAm ? Calendar.AM : Calendar.PM; mAmPmSpinner.setValue(index); + // 显示上午/下午选择器 mAmPmSpinner.setVisibility(View.VISIBLE); } } + // 更新小时控件 private void updateHourControl() { + // 如果是24小时制 if (mIs24HourView) { + // 设置小时选择器的最小值为24小时制最小值 mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW); + // 设置小时选择器的最大值为24小时制最大值 mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW); } else { + // 设置小时选择器的最小值为12小时制最小值 mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW); + // 设置小时选择器的最大值为12小时制最大值 mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW); } } @@ -472,12 +613,16 @@ public class DateTimePicker extends FrameLayout { * Set the callback that indicates the 'Set' button has been pressed. * @param callback the callback, if null will do nothing */ + // 设置日期时间改变监听器 public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) { mOnDateTimeChangedListener = callback; } + // 日期时间改变时调用 private void onDateTimeChanged() { + // 如果日期时间改变监听器不为空 if (mOnDateTimeChangedListener != null) { + // 调用日期时间改变监听器的onDateTimeChanged方法,并传入当前日期时间 mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(), getCurrentMonth(), getCurrentDay(), getCurrentHourOfDay(), getCurrentMinute()); } diff --git a/src/net/micode/notes/ui/DateTimePickerDialog.java b/src1/net/micode/notes/ui/DateTimePickerDialog.java similarity index 73% rename from src/net/micode/notes/ui/DateTimePickerDialog.java rename to src1/net/micode/notes/ui/DateTimePickerDialog.java index 2c47ba4..b70b7d9 100644 --- a/src/net/micode/notes/ui/DateTimePickerDialog.java +++ b/src1/net/micode/notes/ui/DateTimePickerDialog.java @@ -31,57 +31,83 @@ import android.text.format.DateUtils; public class DateTimePickerDialog extends AlertDialog implements OnClickListener { + // 定义一个Calendar对象,用于存储日期和时间 private Calendar mDate = Calendar.getInstance(); + // 定义一个布尔变量,用于判断是否为24小时制 private boolean mIs24HourView; + // 定义一个OnDateTimeSetListener对象,用于监听日期时间的设置 private OnDateTimeSetListener mOnDateTimeSetListener; + // 定义一个DateTimePicker对象,用于显示日期时间选择器 private DateTimePicker mDateTimePicker; + // 定义一个接口,用于监听日期时间设置 public interface OnDateTimeSetListener { + // 当日期时间设置时,调用此方法 void OnDateTimeSet(AlertDialog dialog, long date); } +// 定义一个DateTimePickerDialog类,传入Context和long类型的date参数 public DateTimePickerDialog(Context context, long date) { + // 调用父类的构造方法 super(context); + // 创建一个DateTimePicker对象 mDateTimePicker = new DateTimePicker(context); + // 设置视图 setView(mDateTimePicker); + // 设置DateTimePicker的监听器 mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() { public void onDateTimeChanged(DateTimePicker view, int year, int month, int dayOfMonth, int hourOfDay, int minute) { + // 设置日期 mDate.set(Calendar.YEAR, year); mDate.set(Calendar.MONTH, month); mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); mDate.set(Calendar.HOUR_OF_DAY, hourOfDay); mDate.set(Calendar.MINUTE, minute); + // 更新标题 updateTitle(mDate.getTimeInMillis()); } }); + // 设置日期 mDate.setTimeInMillis(date); mDate.set(Calendar.SECOND, 0); + // 设置当前日期 mDateTimePicker.setCurrentDate(mDate.getTimeInMillis()); + // 设置按钮 setButton(context.getString(R.string.datetime_dialog_ok), this); setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null); + // 设置24小时制 set24HourView(DateFormat.is24HourFormat(this.getContext())); + // 更新标题 updateTitle(mDate.getTimeInMillis()); } + // 设置是否为24小时制 public void set24HourView(boolean is24HourView) { mIs24HourView = is24HourView; } +// 设置日期时间设置监听器 public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) { + // 将传入的监听器赋值给成员变量 mOnDateTimeSetListener = callBack; } + // 更新标题 private void updateTitle(long date) { + // 设置日期格式 int flag = DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME; + // 如果是24小时制,则设置格式为24小时制 flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR; + // 格式化日期并设置标题 setTitle(DateUtils.formatDateTime(this.getContext(), date, flag)); } public void onClick(DialogInterface arg0, int arg1) { + // 如果mOnDateTimeSetListener不为空,则调用其OnDateTimeSet方法,传入当前对象和mDate的时间戳 if (mOnDateTimeSetListener != null) { mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis()); } diff --git a/src/net/micode/notes/ui/DropdownMenu.java b/src1/net/micode/notes/ui/DropdownMenu.java similarity index 100% rename from src/net/micode/notes/ui/DropdownMenu.java rename to src1/net/micode/notes/ui/DropdownMenu.java diff --git a/src/net/micode/notes/ui/FoldersListAdapter.java b/src1/net/micode/notes/ui/FoldersListAdapter.java similarity index 67% rename from src/net/micode/notes/ui/FoldersListAdapter.java rename to src1/net/micode/notes/ui/FoldersListAdapter.java index 96b77da..7e9e215 100644 --- a/src/net/micode/notes/ui/FoldersListAdapter.java +++ b/src1/net/micode/notes/ui/FoldersListAdapter.java @@ -30,49 +30,68 @@ import net.micode.notes.data.Notes.NoteColumns; public class FoldersListAdapter extends CursorAdapter { + // 定义一个静态常量,用于存储查询结果的列名 public static final String [] PROJECTION = { - NoteColumns.ID, - NoteColumns.SNIPPET + NoteColumns.ID, // 存储笔记的ID + NoteColumns.SNIPPET // 存储笔记的摘要 }; + // 定义ID列的常量 public static final int ID_COLUMN = 0; + // 定义名称列的常量 public static final int NAME_COLUMN = 1; + // 构造函数,用于初始化FoldersListAdapter对象 public FoldersListAdapter(Context context, Cursor c) { super(context, c); // TODO Auto-generated constructor stub } @Override + // 重写newView方法,用于创建新的视图 public View newView(Context context, Cursor cursor, ViewGroup parent) { + // 创建一个新的FolderListItem视图 return new FolderListItem(context); } @Override public void bindView(View view, Context context, Cursor cursor) { + // 判断view是否为FolderListItem类型 if (view instanceof FolderListItem) { + // 获取文件夹名称 String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); + // 绑定文件夹名称 ((FolderListItem) view).bind(folderName); } } + // 根据位置获取文件夹名称 public String getFolderName(Context context, int position) { + // 获取指定位置的Cursor对象 Cursor cursor = (Cursor) getItem(position); + // 如果Cursor对象的ID列的值为Notes.ID_ROOT_FOLDER,则返回菜单移动到父文件夹的字符串,否则返回Cursor对象的NAME列的值 return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); } +// 定义一个内部类FolderListItem,继承自LinearLayout private class FolderListItem extends LinearLayout { + // 定义一个TextView变量mName private TextView mName; + // 构造方法,传入Context参数 public FolderListItem(Context context) { super(context); + // 使用inflate方法加载布局文件R.layout.folder_list_item,并将布局文件添加到当前LinearLayout中 inflate(context, R.layout.folder_list_item, this); + // 通过findViewById方法获取布局文件中的TextView控件,并赋值给mName变量 mName = (TextView) findViewById(R.id.tv_folder_name); } + // 绑定方法,传入一个String参数name public void bind(String name) { + // 将传入的name参数设置给mName控件的文本 mName.setText(name); } } diff --git a/src/net/micode/notes/ui/NoteEditActivity.java b/src1/net/micode/notes/ui/NoteEditActivity.java similarity index 71% rename from src/net/micode/notes/ui/NoteEditActivity.java rename to src1/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..21477bf 100644 --- a/src/net/micode/notes/ui/NoteEditActivity.java +++ b/src1/net/micode/notes/ui/NoteEditActivity.java @@ -74,18 +74,26 @@ import java.util.regex.Pattern; public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { + // 定义一个内部类HeadViewHolder,用于保存头部视图的控件 private class HeadViewHolder { + // 保存修改日期的TextView public TextView tvModified; + // 保存提醒图标的ImageView public ImageView ivAlertIcon; + // 保存提醒日期的TextView public TextView tvAlertDate; + // 保存设置背景颜色的ImageView public ImageView ibSetBgColor; } +// 定义一个静态的Map,用于存储背景选择按钮的ID和对应的颜色值 private static final Map