From bbb310d3d0ce8a21f0d8486162ac070bb4e3dc93 Mon Sep 17 00:00:00 2001 From: gy <2293314358@qq.com> Date: Fri, 30 Jan 2026 19:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E4=BE=BF=E7=AD=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B6/=E5=8F=96=E6=B6=88=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E3=80=81=E6=92=A4=E5=9B=9E/=E5=8F=96=E6=B6=88=E6=92=A4?= =?UTF-8?q?=E5=9B=9E=E3=80=81=E8=AE=BE=E4=B8=BA=E7=A7=81=E5=AF=86/?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E7=A7=81=E5=AF=86=E5=8A=9F=E8=83=BD=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notes/data/NotesDatabaseHelper.java | 111 +++---- .../net/micode/notes/data/NotesProvider.java | 77 +---- .../net/micode/notes/gtask/data/MetaData.java | 39 --- .../src/net/micode/notes/gtask/data/Node.java | 79 ----- .../net/micode/notes/gtask/data/SqlData.java | 54 ---- .../net/micode/notes/gtask/data/SqlNote.java | 114 +------ .../src/net/micode/notes/gtask/data/Task.java | 83 ----- .../net/micode/notes/gtask/data/TaskList.java | 99 ------ .../exception/ActionFailureException.java | 17 -- .../exception/NetworkFailureException.java | 17 -- .../notes/gtask/remote/GTaskASyncTask.java | 66 +--- .../notes/gtask/remote/GTaskClient.java | 174 ++--------- .../notes/gtask/remote/GTaskManager.java | 114 ------- .../notes/gtask/remote/GTaskSyncService.java | 64 ---- .../src/net/micode/notes/model/Note.java | 119 +------- .../net/micode/notes/model/WorkingNote.java | 287 ++++++------------ 16 files changed, 186 insertions(+), 1328 deletions(-) diff --git a/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java index 9e9f86c..95b8200 100644 --- a/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java @@ -27,34 +27,21 @@ import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; -/** - * 笔记应用的数据库助手类,负责创建和管理SQLite数据库 - * 包括表结构定义、触发器创建、系统文件夹初始化和数据库版本升级 - */ public class NotesDatabaseHelper extends SQLiteOpenHelper { - // 数据库名称 private static final String DB_NAME = "note.db"; - // 数据库版本号 - private static final int DB_VERSION = 4; + private static final int DB_VERSION = 6; - /** - * 数据库表名定义接口 - */ public interface TABLE { - // 笔记表名 public static final String NOTE = "note"; - // 数据内容表名 + public static final String DATA = "data"; } - // 日志标签 private static final String TAG = "NotesDatabaseHelper"; - // 单例实例 private static NotesDatabaseHelper mInstance; - // 创建笔记表的SQL语句 private static final String CREATE_NOTE_TABLE_SQL = "CREATE TABLE " + TABLE.NOTE + "(" + NoteColumns.ID + " INTEGER PRIMARY KEY," + @@ -73,10 +60,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," + - NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.TITLE + " TEXT NOT NULL DEFAULT ''," + + NoteColumns.IS_PINNED + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.IS_PRIVATE + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.VIEW_MODE + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.CUSTOM_BG_URI + " TEXT NOT NULL DEFAULT ''," + + NoteColumns.EXPAND_1 + " TEXT NOT NULL DEFAULT ''" + ")"; - // 创建数据内容表的SQL语句 private static final String CREATE_DATA_TABLE_SQL = "CREATE TABLE " + TABLE.DATA + "(" + DataColumns.ID + " INTEGER PRIMARY KEY," + @@ -92,7 +84,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + ")"; - // 为数据内容表的note_id字段创建索引的SQL语句 private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = "CREATE INDEX IF NOT EXISTS note_id_index ON " + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; @@ -221,18 +212,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + " END"; - /** - * 构造方法 - * @param context 上下文对象 - */ public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } - /** - * 创建笔记表 - * @param db SQLite数据库对象 - */ public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); reCreateNoteTableTriggers(db); @@ -240,10 +223,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } - /** - * 重新创建笔记表的触发器 - * @param db SQLite数据库对象 - */ 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"); @@ -262,10 +241,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); } - /** - * 创建系统文件夹 - * @param db SQLite数据库对象 - */ private void createSystemFolder(SQLiteDatabase db) { ContentValues values = new ContentValues(); @@ -301,10 +276,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } - /** - * 创建数据内容表 - * @param db SQLite数据库对象 - */ public void createDataTable(SQLiteDatabase db) { db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); @@ -312,10 +283,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "data table has been created"); } - /** - * 重新创建数据内容表的触发器 - * @param db SQLite数据库对象 - */ 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"); @@ -326,11 +293,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); } - /** - * 获取单例实例 - * @param context 上下文对象 - * @return NotesDatabaseHelper实例 - */ static synchronized NotesDatabaseHelper getInstance(Context context) { if (mInstance == null) { mInstance = new NotesDatabaseHelper(context); @@ -338,22 +300,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { return mInstance; } - /** - * 创建数据库时调用 - * @param db SQLite数据库对象 - */ @Override public void onCreate(SQLiteDatabase db) { createNoteTable(db); createDataTable(db); } - /** - * 数据库版本升级时调用 - * @param db SQLite数据库对象 - * @param oldVersion 旧版本号 - * @param newVersion 新版本号 - */ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { boolean reCreateTriggers = false; @@ -361,7 +313,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { if (oldVersion == 1) { upgradeToV2(db); - skipV2 = true; // this upgrade including the upgrade from v2 to v3 + skipV2 = true; // Skip v2 upgrade since it's already done oldVersion++; } @@ -373,6 +325,19 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { if (oldVersion == 3) { upgradeToV4(db); + reCreateTriggers = true; + oldVersion++; + } + + if (oldVersion == 4) { + upgradeToV5(db); + reCreateTriggers = true; + oldVersion++; + } + + if (oldVersion == 5) { + upgradeToV6(db); + reCreateTriggers = true; oldVersion++; } @@ -387,10 +352,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } } - /** - * 升级数据库到版本2 - * @param db SQLite数据库对象 - */ + // 确保存在 V6 升级方法,防止字段缺失 + private void upgradeToV6(SQLiteDatabase db) { + // 使用 try-catch 忽略"列已存在"的错误,防止重复添加崩溃 + try { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.IS_PINNED + " INTEGER NOT NULL DEFAULT 0"); } catch(Exception e){} + try { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.IS_PRIVATE + " INTEGER NOT NULL DEFAULT 0"); } catch(Exception e){} + try { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VIEW_MODE + " INTEGER NOT NULL DEFAULT 0"); } catch(Exception e){} + try { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.CUSTOM_BG_URI + " TEXT NOT NULL DEFAULT ''"); } catch(Exception e){} + try { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.EXPAND_1 + " TEXT NOT NULL DEFAULT ''"); } catch(Exception e){} + } + private void upgradeToV2(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); @@ -398,10 +369,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { createDataTable(db); } - /** - * 升级数据库到版本3 - * @param db SQLite数据库对象 - */ private void upgradeToV3(SQLiteDatabase db) { // drop unused triggers db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert"); @@ -417,12 +384,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } - /** - * 升级数据库到版本4 - * @param db SQLite数据库对象 - */ private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); } + + private void upgradeToV5(SQLiteDatabase db) { + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.IS_PINNED + " INTEGER NOT NULL DEFAULT 0"); + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.IS_PRIVATE + " INTEGER NOT NULL DEFAULT 0"); + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VIEW_MODE + " INTEGER NOT NULL DEFAULT 0"); + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.CUSTOM_BG_URI + " TEXT NOT NULL DEFAULT ''"); + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.EXPAND_1 + " TEXT NOT NULL DEFAULT ''"); + } } diff --git a/src/Notes-master/src/net/micode/notes/data/NotesProvider.java b/src/Notes-master/src/net/micode/notes/data/NotesProvider.java index f951ad9..edb0a60 100644 --- a/src/Notes-master/src/net/micode/notes/data/NotesProvider.java +++ b/src/Notes-master/src/net/micode/notes/data/NotesProvider.java @@ -35,27 +35,20 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; -/** - * 笔记应用的ContentProvider,负责处理所有数据操作请求 - * 包括笔记和数据内容的增删改查,以及搜索功能 - */ public class NotesProvider extends ContentProvider { - // Uri匹配器,用于解析不同的请求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; // 搜索建议 + 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); @@ -72,7 +65,6 @@ public class NotesProvider extends ContentProvider { * x'0A' represents the '\n' character in sqlite. For title and content in the search result, * we will trim '\n' and white space in order to show more information. */ - // 搜索结果的投影列定义 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 + "," @@ -81,33 +73,18 @@ public class NotesProvider extends ContentProvider { + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; - // 搜索笔记内容的SQL查询语句 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; - /** - * ContentProvider创建时调用,初始化数据库助手 - * @return true表示创建成功 - */ @Override public boolean onCreate() { mHelper = NotesDatabaseHelper.getInstance(getContext()); return true; } - /** - * 查询数据 - * @param uri 请求的URI - * @param projection 返回的列 - * @param selection 选择条件 - * @param selectionArgs 选择条件的参数 - * @param sortOrder 排序方式 - * @return 查询结果的Cursor - * @throws IllegalArgumentException 当URI不合法时抛出 - */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { @@ -170,13 +147,6 @@ public class NotesProvider extends ContentProvider { return c; } - /** - * 插入数据 - * @param uri 请求的URI - * @param values 要插入的数据 - * @return 插入数据的URI - * @throws IllegalArgumentException 当URI不合法时抛出 - */ @Override public Uri insert(Uri uri, ContentValues values) { SQLiteDatabase db = mHelper.getWritableDatabase(); @@ -211,14 +181,6 @@ public class NotesProvider extends ContentProvider { return ContentUris.withAppendedId(uri, insertedId); } - /** - * 删除数据 - * @param uri 请求的URI - * @param selection 删除条件 - * @param selectionArgs 删除条件的参数 - * @return 删除的行数 - * @throws IllegalArgumentException 当URI不合法时抛出 - */ @Override public int delete(Uri uri, String selection, String[] selectionArgs) { int count = 0; @@ -265,15 +227,6 @@ public class NotesProvider extends ContentProvider { return count; } - /** - * 更新数据 - * @param uri 请求的URI - * @param values 要更新的数据 - * @param selection 更新条件 - * @param selectionArgs 更新条件的参数 - * @return 更新的行数 - * @throws IllegalArgumentException 当URI不合法时抛出 - */ @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int count = 0; @@ -314,21 +267,10 @@ public class NotesProvider extends ContentProvider { return count; } - /** - * 解析选择条件,添加到已有的条件中 - * @param selection 要解析的选择条件 - * @return 解析后的选择条件 - */ private String parseSelection(String selection) { return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } - /** - * 增加笔记版本号 - * @param id 笔记ID,-1表示所有笔记 - * @param selection 选择条件 - * @param selectionArgs 选择条件的参数 - */ private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { StringBuilder sql = new StringBuilder(120); sql.append("UPDATE "); @@ -354,11 +296,6 @@ public class NotesProvider extends ContentProvider { mHelper.getWritableDatabase().execSQL(sql.toString()); } - /** - * 获取URI对应的MIME类型 - * @param uri 请求的URI - * @return MIME类型,当前未实现 - */ @Override public String getType(Uri uri) { // TODO Auto-generated method stub diff --git a/src/Notes-master/src/net/micode/notes/gtask/data/MetaData.java b/src/Notes-master/src/net/micode/notes/gtask/data/MetaData.java index 15a13bc..3a2050b 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/MetaData.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/MetaData.java @@ -25,22 +25,11 @@ import org.json.JSONException; import org.json.JSONObject; -/** - * 元数据类,继承自Task,用于存储任务相关的元信息 - * 主要用于保存与远程Google Task相关联的本地任务元数据 - */ public class MetaData extends Task { - // 日志标签 private final static String TAG = MetaData.class.getSimpleName(); - // 关联的Google Task ID private String mRelatedGid = null; - /** - * 设置元数据信息 - * @param gid Google Task ID - * @param metaInfo 元数据JSON对象 - */ public void setMeta(String gid, JSONObject metaInfo) { try { metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); @@ -51,27 +40,15 @@ public class MetaData extends Task { setName(GTaskStringUtils.META_NOTE_NAME); } - /** - * 获取关联的Google Task ID - * @return 关联的Google Task ID - */ public String getRelatedGid() { return mRelatedGid; } - /** - * 判断元数据是否值得保存 - * @return 如果元数据不为null则返回true - */ @Override public boolean isWorthSaving() { return getNotes() != null; } - /** - * 从远程JSON设置内容 - * @param js 远程JSON对象 - */ @Override public void setContentByRemoteJSON(JSONObject js) { super.setContentByRemoteJSON(js); @@ -86,33 +63,17 @@ public class MetaData extends Task { } } - /** - * 从本地JSON设置内容,该方法不应被调用 - * @param js 本地JSON对象 - * @throws IllegalAccessError 总是抛出该异常 - */ @Override public void setContentByLocalJSON(JSONObject js) { // this function should not be called throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); } - /** - * 从内容获取本地JSON,该方法不应被调用 - * @return 本地JSON对象 - * @throws IllegalAccessError 总是抛出该异常 - */ @Override public JSONObject getLocalJSONFromContent() { throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); } - /** - * 获取同步操作类型,该方法不应被调用 - * @param c 游标 - * @return 同步操作类型 - * @throws IllegalAccessError 总是抛出该异常 - */ @Override public int getSyncAction(Cursor c) { throw new IllegalAccessError("MetaData:getSyncAction should not be called"); diff --git a/src/Notes-master/src/net/micode/notes/gtask/data/Node.java b/src/Notes-master/src/net/micode/notes/gtask/data/Node.java index aab35e3..63950e0 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/Node.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/Node.java @@ -20,53 +20,33 @@ import android.database.Cursor; import org.json.JSONObject; -/** - * 抽象同步节点类,定义了同步操作的基本结构和接口 - * 是Task和TaskList的父类,用于处理本地与远程Google Tasks的同步 - */ public abstract class Node { - // 无同步操作 public static final int SYNC_ACTION_NONE = 0; - // 向远程添加数据 public static final int SYNC_ACTION_ADD_REMOTE = 1; - // 向本地添加数据 public static final int SYNC_ACTION_ADD_LOCAL = 2; - // 从远程删除数据 public static final int SYNC_ACTION_DEL_REMOTE = 3; - // 从本地删除数据 public static final int SYNC_ACTION_DEL_LOCAL = 4; - // 更新远程数据 public static final int SYNC_ACTION_UPDATE_REMOTE = 5; - // 更新本地数据 public static final int SYNC_ACTION_UPDATE_LOCAL = 6; - // 同步冲突 public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; - // 同步错误 public static final int SYNC_ACTION_ERROR = 8; - // Google Task唯一标识符 private String mGid; - // 节点名称 private String mName; - // 最后修改时间 private long mLastModified; - // 是否已删除 private boolean mDeleted; - /** - * 构造函数,初始化节点基本属性 - */ public Node() { mGid = null; mName = ""; @@ -74,105 +54,46 @@ public abstract class Node { mDeleted = false; } - /** - * 获取创建操作的JSON对象 - * @param actionId 操作ID - * @return 创建操作的JSON对象 - */ public abstract JSONObject getCreateAction(int actionId); - /** - * 获取更新操作的JSON对象 - * @param actionId 操作ID - * @return 更新操作的JSON对象 - */ public abstract JSONObject getUpdateAction(int actionId); - /** - * 根据远程JSON对象设置内容 - * @param js 远程JSON对象 - */ public abstract void setContentByRemoteJSON(JSONObject js); - /** - * 根据本地JSON对象设置内容 - * @param js 本地JSON对象 - */ public abstract void setContentByLocalJSON(JSONObject js); - /** - * 从内容获取本地JSON对象 - * @return 本地JSON对象 - */ public abstract JSONObject getLocalJSONFromContent(); - /** - * 获取同步操作类型 - * @param c 数据库游标 - * @return 同步操作类型 - */ public abstract int getSyncAction(Cursor c); - /** - * 设置Google Task唯一标识符 - * @param gid Google Task ID - */ public void setGid(String gid) { this.mGid = gid; } - /** - * 设置节点名称 - * @param name 节点名称 - */ public void setName(String name) { this.mName = name; } - /** - * 设置最后修改时间 - * @param lastModified 最后修改时间 - */ public void setLastModified(long lastModified) { this.mLastModified = lastModified; } - /** - * 设置删除状态 - * @param deleted 是否删除 - */ public void setDeleted(boolean deleted) { this.mDeleted = deleted; } - /** - * 获取Google Task唯一标识符 - * @return Google Task ID - */ public String getGid() { return this.mGid; } - /** - * 获取节点名称 - * @return 节点名称 - */ public String getName() { return this.mName; } - /** - * 获取最后修改时间 - * @return 最后修改时间 - */ public long getLastModified() { return this.mLastModified; } - /** - * 获取删除状态 - * @return 是否已删除 - */ public boolean getDeleted() { return this.mDeleted; } diff --git a/src/Notes-master/src/net/micode/notes/gtask/data/SqlData.java b/src/Notes-master/src/net/micode/notes/gtask/data/SqlData.java index 9b645a9..d3ec3be 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/SqlData.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/SqlData.java @@ -35,66 +35,42 @@ import org.json.JSONException; import org.json.JSONObject; -/** - * 数据库数据处理类,用于管理笔记的数据部分 - * 提供与ContentResolver的交互,实现数据的创建、更新和提交 - */ public class SqlData { - // 日志标签 private static final String TAG = SqlData.class.getSimpleName(); - // 无效ID常量 private static final int INVALID_ID = -99999; - // 数据查询投影数组 public static final String[] PROJECTION_DATA = new String[] { DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.DATA3 }; - // 投影数组中ID列的索引 public static final int DATA_ID_COLUMN = 0; - // 投影数组中MIME类型列的索引 public static final int DATA_MIME_TYPE_COLUMN = 1; - // 投影数组中内容列的索引 public static final int DATA_CONTENT_COLUMN = 2; - // 投影数组中DATA1列的索引 public static final int DATA_CONTENT_DATA_1_COLUMN = 3; - // 投影数组中DATA3列的索引 public static final int DATA_CONTENT_DATA_3_COLUMN = 4; - // 内容解析器 private ContentResolver mContentResolver; - // 是否为创建操作 private boolean mIsCreate; - // 数据ID private long mDataId; - // 数据MIME类型 private String mDataMimeType; - // 数据内容 private String mDataContent; - // 数据内容DATA1字段 private long mDataContentData1; - // 数据内容DATA3字段 private String mDataContentData3; - // 差异数据值,用于记录需要更新的字段 private ContentValues mDiffDataValues; - /** - * 构造函数,创建新的数据对象 - * @param context 上下文对象 - */ public SqlData(Context context) { mContentResolver = context.getContentResolver(); mIsCreate = true; @@ -106,11 +82,6 @@ public class SqlData { mDiffDataValues = new ContentValues(); } - /** - * 构造函数,从游标创建数据对象 - * @param context 上下文对象 - * @param c 数据库游标 - */ public SqlData(Context context, Cursor c) { mContentResolver = context.getContentResolver(); mIsCreate = false; @@ -118,10 +89,6 @@ public class SqlData { mDiffDataValues = new ContentValues(); } - /** - * 从游标加载数据 - * @param c 数据库游标 - */ private void loadFromCursor(Cursor c) { mDataId = c.getLong(DATA_ID_COLUMN); mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN); @@ -130,11 +97,6 @@ public class SqlData { mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN); } - /** - * 根据JSON对象设置数据内容 - * @param js JSON对象 - * @throws JSONException JSON解析异常 - */ public void setContent(JSONObject js) throws JSONException { long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; if (mIsCreate || mDataId != dataId) { @@ -168,11 +130,6 @@ public class SqlData { mDataContentData3 = dataContentData3; } - /** - * 获取数据内容的JSON对象 - * @return JSON对象 - * @throws JSONException JSON解析异常 - */ public JSONObject getContent() throws JSONException { if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); @@ -187,13 +144,6 @@ public class SqlData { return js; } - /** - * 提交数据到数据库 - * @param noteId 笔记ID - * @param validateVersion 是否验证版本 - * @param version 版本号 - * @throws ActionFailureException 创建笔记失败时抛出 - */ public void commit(long noteId, boolean validateVersion, long version) { if (mIsCreate) { @@ -233,10 +183,6 @@ public class SqlData { mIsCreate = false; } - /** - * 获取数据ID - * @return 数据ID - */ public long getId() { return mDataId; } diff --git a/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java b/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java index 5cd4320..79a4095 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java @@ -38,18 +38,11 @@ import org.json.JSONObject; import java.util.ArrayList; -/** - * 数据库笔记处理类,用于管理笔记的完整数据结构 - * 包括笔记基本信息和关联的数据内容,提供与ContentResolver的交互 - */ public class SqlNote { - // 日志标签 private static final String TAG = SqlNote.class.getSimpleName(); - // 无效ID常量 private static final int INVALID_ID = -99999; - // 笔记查询投影数组 public static final String[] PROJECTION_NOTE = new String[] { NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, @@ -59,115 +52,76 @@ public class SqlNote { NoteColumns.VERSION }; - // 投影数组中ID列的索引 public static final int ID_COLUMN = 0; - // 投影数组中提醒日期列的索引 public static final int ALERTED_DATE_COLUMN = 1; - // 投影数组中背景颜色ID列的索引 public static final int BG_COLOR_ID_COLUMN = 2; - // 投影数组中创建日期列的索引 public static final int CREATED_DATE_COLUMN = 3; - // 投影数组中是否有附件列的索引 public static final int HAS_ATTACHMENT_COLUMN = 4; - // 投影数组中修改日期列的索引 public static final int MODIFIED_DATE_COLUMN = 5; - // 投影数组中笔记数量列的索引 public static final int NOTES_COUNT_COLUMN = 6; - // 投影数组中父ID列的索引 public static final int PARENT_ID_COLUMN = 7; - // 投影数组中摘要列的索引 public static final int SNIPPET_COLUMN = 8; - // 投影数组中类型列的索引 public static final int TYPE_COLUMN = 9; - // 投影数组中小组件ID列的索引 public static final int WIDGET_ID_COLUMN = 10; - // 投影数组中小组件类型列的索引 public static final int WIDGET_TYPE_COLUMN = 11; - // 投影数组中同步ID列的索引 public static final int SYNC_ID_COLUMN = 12; - // 投影数组中本地修改标记列的索引 public static final int LOCAL_MODIFIED_COLUMN = 13; - // 投影数组中原始父ID列的索引 public static final int ORIGIN_PARENT_ID_COLUMN = 14; - // 投影数组中Google Task ID列的索引 public static final int GTASK_ID_COLUMN = 15; - // 投影数组中版本列的索引 public static final int VERSION_COLUMN = 16; - // 上下文对象 private Context mContext; - // 内容解析器 private ContentResolver mContentResolver; - // 是否为创建操作 private boolean mIsCreate; - // 笔记ID private long mId; - // 提醒日期 private long mAlertDate; - // 背景颜色ID private int mBgColorId; - // 创建日期 private long mCreatedDate; - // 是否有附件(0:无,1:有) private int mHasAttachment; - // 修改日期 private long mModifiedDate; - // 父文件夹ID private long mParentId; - // 笔记摘要 private String mSnippet; - // 笔记类型(文件夹或笔记) private int mType; - // 小组件ID private int mWidgetId; - // 小组件类型 private int mWidgetType; - // 原始父文件夹ID private long mOriginParent; - // 版本号 private long mVersion; - // 差异笔记值,用于记录需要更新的字段 private ContentValues mDiffNoteValues; - // 数据内容列表 private ArrayList mDataList; - /** - * 构造函数,创建新的笔记对象 - * @param context 上下文对象 - */ public SqlNote(Context context) { mContext = context; mContentResolver = context.getContentResolver(); @@ -189,11 +143,6 @@ public class SqlNote { mDataList = new ArrayList(); } - /** - * 构造函数,从游标创建笔记对象 - * @param context 上下文对象 - * @param c 数据库游标 - */ public SqlNote(Context context, Cursor c) { mContext = context; mContentResolver = context.getContentResolver(); @@ -205,11 +154,6 @@ public class SqlNote { mDiffNoteValues = new ContentValues(); } - /** - * 构造函数,通过ID加载笔记对象 - * @param context 上下文对象 - * @param id 笔记ID - */ public SqlNote(Context context, long id) { mContext = context; mContentResolver = context.getContentResolver(); @@ -219,12 +163,9 @@ public class SqlNote { if (mType == Notes.TYPE_NOTE) loadDataContent(); mDiffNoteValues = new ContentValues(); + } - /** - * 通过ID从数据库加载笔记数据 - * @param id 笔记ID - */ private void loadFromCursor(long id) { Cursor c = null; try { @@ -244,10 +185,6 @@ public class SqlNote { } } - /** - * 从数据库游标加载笔记数据 - * @param c 数据库查询游标 - */ private void loadFromCursor(Cursor c) { mId = c.getLong(ID_COLUMN); mAlertDate = c.getLong(ALERTED_DATE_COLUMN); @@ -263,9 +200,6 @@ public class SqlNote { mVersion = c.getLong(VERSION_COLUMN); } - /** - * 加载笔记的关联数据内容 - */ private void loadDataContent() { Cursor c = null; mDataList.clear(); @@ -292,11 +226,6 @@ public class SqlNote { } } - /** - * 设置笔记内容,从JSON对象中解析数据 - * @param js 包含笔记信息的JSON对象 - * @return 操作是否成功 - */ public boolean setContent(JSONObject js) { try { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); @@ -430,10 +359,6 @@ public class SqlNote { return true; } - /** - * 获取笔记内容,转换为JSON对象 - * @return 包含笔记信息的JSON对象,若未创建则返回null - */ public JSONObject getContent() { try { JSONObject js = new JSONObject(); @@ -482,76 +407,39 @@ public class SqlNote { return null; } - /** - * 设置笔记的父文件夹ID - * @param id 父文件夹ID - */ public void setParentId(long id) { mParentId = id; mDiffNoteValues.put(NoteColumns.PARENT_ID, id); } - /** - * 设置Google Task ID - * @param gid Google Task ID - */ public void setGtaskId(String gid) { mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); } - /** - * 设置同步ID - * @param syncId 同步ID - */ public void setSyncId(long syncId) { mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); } - /** - * 重置本地修改标记 - */ public void resetLocalModified() { mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0); } - /** - * 获取笔记ID - * @return 笔记ID - */ public long getId() { return mId; } - /** - * 获取父文件夹ID - * @return 父文件夹ID - */ public long getParentId() { return mParentId; } - /** - * 获取笔记摘要 - * @return 笔记摘要 - */ public String getSnippet() { return mSnippet; } - /** - * 判断当前是否为笔记类型(非文件夹) - * @return 是否为笔记类型 - */ public boolean isNoteType() { return mType == Notes.TYPE_NOTE; } - /** - * 提交笔记到数据库,创建或更新记录 - * @param validateVersion 是否验证版本号 - * @throws ActionFailureException 创建笔记失败时抛出 - * @throws IllegalStateException 更新无效ID时抛出 - */ public void commit(boolean validateVersion) { if (mIsCreate) { if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { diff --git a/src/Notes-master/src/net/micode/notes/gtask/data/Task.java b/src/Notes-master/src/net/micode/notes/gtask/data/Task.java index 2b5d275..6a19454 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/Task.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/Task.java @@ -32,32 +32,19 @@ import org.json.JSONException; import org.json.JSONObject; -/** - * 表示Google Tasks中的任务项,继承自Node类 - * 用于管理任务的各种属性和操作,包括创建、更新、同步等功能 - */ public class Task extends Node { - // 日志标签 private static final String TAG = Task.class.getSimpleName(); - // 任务是否已完成 private boolean mCompleted; - // 任务的详细说明 private String mNotes; - // 任务的元信息JSON对象 private JSONObject mMetaInfo; - // 前一个兄弟任务(用于排序) private Task mPriorSibling; - // 父任务列表 private TaskList mParent; - /** - * 构造函数,初始化任务对象 - */ public Task() { super(); mCompleted = false; @@ -67,12 +54,6 @@ public class Task extends Node { mMetaInfo = null; } - /** - * 获取创建任务的JSON操作对象 - * @param actionId 操作ID - * @return 创建任务的JSON操作对象 - * @throws ActionFailureException 生成JSON对象失败时抛出 - */ public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); @@ -122,12 +103,6 @@ public class Task extends Node { return js; } - /** - * 获取更新任务的JSON操作对象 - * @param actionId 操作ID - * @return 更新任务的JSON操作对象 - * @throws ActionFailureException 生成JSON对象失败时抛出 - */ public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); @@ -160,11 +135,6 @@ public class Task extends Node { return js; } - /** - * 根据远程JSON对象设置任务内容 - * @param js 远程JSON对象 - * @throws ActionFailureException 解析JSON对象失败时抛出 - */ public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try { @@ -205,10 +175,6 @@ public class Task extends Node { } } - /** - * 根据本地JSON对象设置任务内容 - * @param js 本地JSON对象 - */ public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) { @@ -238,10 +204,6 @@ public class Task extends Node { } } - /** - * 从任务内容生成本地JSON对象 - * @return 本地JSON对象,若生成失败则返回null - */ public JSONObject getLocalJSONFromContent() { String name = getName(); try { @@ -285,10 +247,6 @@ public class Task extends Node { } } - /** - * 设置任务的元数据 - * @param metaData 元数据对象 - */ public void setMetaInfo(MetaData metaData) { if (metaData != null && metaData.getNotes() != null) { try { @@ -300,11 +258,6 @@ public class Task extends Node { } } - /** - * 获取同步操作类型 - * @param c 数据库游标 - * @return 同步操作类型(SYNC_ACTION_NONE、SYNC_ACTION_UPDATE_REMOTE等) - */ public int getSyncAction(Cursor c) { try { JSONObject noteInfo = null; @@ -358,75 +311,39 @@ public class Task extends Node { return SYNC_ACTION_ERROR; } - /** - * 判断任务是否值得保存 - * @return 是否值得保存 - */ public boolean isWorthSaving() { return mMetaInfo != null || (getName() != null && getName().trim().length() > 0) || (getNotes() != null && getNotes().trim().length() > 0); } - /** - * 设置任务的完成状态 - * @param completed 是否完成 - */ public void setCompleted(boolean completed) { this.mCompleted = completed; } - /** - * 设置任务的详细说明 - * @param notes 详细说明内容 - */ public void setNotes(String notes) { this.mNotes = notes; } - /** - * 设置前一个兄弟任务 - * @param priorSibling 前一个兄弟任务 - */ public void setPriorSibling(Task priorSibling) { this.mPriorSibling = priorSibling; } - /** - * 设置父任务列表 - * @param parent 父任务列表 - */ public void setParent(TaskList parent) { this.mParent = parent; } - /** - * 获取任务的完成状态 - * @return 是否完成 - */ public boolean getCompleted() { return this.mCompleted; } - /** - * 获取任务的详细说明 - * @return 详细说明内容 - */ public String getNotes() { return this.mNotes; } - /** - * 获取前一个兄弟任务 - * @return 前一个兄弟任务 - */ public Task getPriorSibling() { return this.mPriorSibling; } - /** - * 获取父任务列表 - * @return 父任务列表 - */ public TaskList getParent() { return this.mParent; } diff --git a/src/Notes-master/src/net/micode/notes/gtask/data/TaskList.java b/src/Notes-master/src/net/micode/notes/gtask/data/TaskList.java index 794f931..4ea21c5 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/TaskList.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/TaskList.java @@ -30,36 +30,19 @@ import org.json.JSONObject; import java.util.ArrayList; -/** - * 表示Google Tasks中的任务列表,继承自Node类 - * 用于管理任务列表的属性和操作,包括创建、更新、同步等功能 - * 同时管理列表中的任务项 - */ public class TaskList extends Node { - // 日志标签 private static final String TAG = TaskList.class.getSimpleName(); - // 任务列表的索引位置 private int mIndex; - // 任务列表中的子任务集合 private ArrayList mChildren; - /** - * 构造函数,初始化任务列表对象 - */ public TaskList() { super(); mChildren = new ArrayList(); mIndex = 1; } - /** - * 获取创建任务列表的JSON操作对象 - * @param actionId 操作ID - * @return 创建任务列表的JSON操作对象 - * @throws ActionFailureException 生成JSON对象失败时抛出 - */ public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); @@ -91,12 +74,6 @@ public class TaskList extends Node { return js; } - /** - * 获取更新任务列表的JSON操作对象 - * @param actionId 操作ID - * @return 更新任务列表的JSON操作对象 - * @throws ActionFailureException 生成JSON对象失败时抛出 - */ public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); @@ -126,11 +103,6 @@ public class TaskList extends Node { return js; } - /** - * 根据远程JSON对象设置任务列表内容 - * @param js 远程JSON对象 - * @throws ActionFailureException 解析JSON对象失败时抛出 - */ public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try { @@ -157,10 +129,6 @@ public class TaskList extends Node { } } - /** - * 根据本地JSON对象设置任务列表内容 - * @param js 本地JSON对象 - */ public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); @@ -189,10 +157,6 @@ public class TaskList extends Node { } } - /** - * 从任务列表内容生成本地JSON对象 - * @return 本地JSON对象,若生成失败则返回null - */ public JSONObject getLocalJSONFromContent() { try { JSONObject js = new JSONObject(); @@ -219,11 +183,6 @@ public class TaskList extends Node { } } - /** - * 获取同步操作类型 - * @param c 数据库游标 - * @return 同步操作类型(SYNC_ACTION_NONE、SYNC_ACTION_UPDATE_REMOTE等) - */ public int getSyncAction(Cursor c) { try { if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { @@ -257,19 +216,10 @@ public class TaskList extends Node { return SYNC_ACTION_ERROR; } - /** - * 获取子任务数量 - * @return 子任务数量 - */ public int getChildTaskCount() { return mChildren.size(); } - /** - * 添加子任务到列表末尾 - * @param task 要添加的任务 - * @return 是否添加成功 - */ public boolean addChildTask(Task task) { boolean ret = false; if (task != null && !mChildren.contains(task)) { @@ -284,12 +234,6 @@ public class TaskList extends Node { return ret; } - /** - * 在指定位置添加子任务 - * @param task 要添加的任务 - * @param index 添加位置的索引 - * @return 是否添加成功 - */ public boolean addChildTask(Task task, int index) { if (index < 0 || index > mChildren.size()) { Log.e(TAG, "add child task: invalid index"); @@ -316,11 +260,6 @@ public class TaskList extends Node { return true; } - /** - * 从列表中移除子任务 - * @param task 要移除的任务 - * @return 是否移除成功 - */ public boolean removeChildTask(Task task) { boolean ret = false; int index = mChildren.indexOf(task); @@ -342,12 +281,6 @@ public class TaskList extends Node { return ret; } - /** - * 移动子任务到指定位置 - * @param task 要移动的任务 - * @param index 目标位置的索引 - * @return 是否移动成功 - */ public boolean moveChildTask(Task task, int index) { if (index < 0 || index >= mChildren.size()) { @@ -366,11 +299,6 @@ public class TaskList extends Node { return (removeChildTask(task) && addChildTask(task, index)); } - /** - * 根据Google Task ID查找子任务 - * @param gid Google Task ID - * @return 找到的任务,若未找到则返回null - */ public Task findChildTaskByGid(String gid) { for (int i = 0; i < mChildren.size(); i++) { Task t = mChildren.get(i); @@ -381,20 +309,10 @@ public class TaskList extends Node { return null; } - /** - * 获取子任务在列表中的索引位置 - * @param task 子任务对象 - * @return 子任务的索引位置 - */ public int getChildTaskIndex(Task task) { return mChildren.indexOf(task); } - /** - * 根据索引位置获取子任务 - * @param index 子任务的索引位置 - * @return 找到的任务,若索引无效则返回null - */ public Task getChildTaskByIndex(int index) { if (index < 0 || index >= mChildren.size()) { Log.e(TAG, "getTaskByIndex: invalid index"); @@ -403,11 +321,6 @@ public class TaskList extends Node { return mChildren.get(index); } - /** - * 根据Google Task ID查找子任务(与findChildTaskByGid功能相同) - * @param gid Google Task ID - * @return 找到的任务,若未找到则返回null - */ public Task getChilTaskByGid(String gid) { for (Task task : mChildren) { if (task.getGid().equals(gid)) @@ -416,26 +329,14 @@ public class TaskList extends Node { return null; } - /** - * 获取所有子任务的列表 - * @return 子任务列表 - */ public ArrayList getChildTaskList() { return this.mChildren; } - /** - * 设置任务列表的索引位置 - * @param index 索引位置 - */ public void setIndex(int index) { this.mIndex = index; } - /** - * 获取任务列表的索引位置 - * @return 索引位置 - */ public int getIndex() { return this.mIndex; } diff --git a/src/Notes-master/src/net/micode/notes/gtask/exception/ActionFailureException.java b/src/Notes-master/src/net/micode/notes/gtask/exception/ActionFailureException.java index d60ffdd..15504be 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/exception/ActionFailureException.java +++ b/src/Notes-master/src/net/micode/notes/gtask/exception/ActionFailureException.java @@ -16,34 +16,17 @@ package net.micode.notes.gtask.exception; -/** - * Google Tasks操作失败异常类 - * 用于表示与Google Tasks服务器交互时的操作失败情况 - */ public class ActionFailureException extends RuntimeException { - // 序列化版本UID private static final long serialVersionUID = 4425249765923293627L; - /** - * 无参构造函数 - */ public ActionFailureException() { super(); } - /** - * 构造函数 - * @param paramString 异常信息 - */ public ActionFailureException(String paramString) { super(paramString); } - /** - * 构造函数 - * @param paramString 异常信息 - * @param paramThrowable 引起此异常的原因 - */ public ActionFailureException(String paramString, Throwable paramThrowable) { super(paramString, paramThrowable); } diff --git a/src/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java b/src/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java index c5e2b45..b08cfb1 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java +++ b/src/Notes-master/src/net/micode/notes/gtask/exception/NetworkFailureException.java @@ -16,34 +16,17 @@ package net.micode.notes.gtask.exception; -/** - * Google Tasks网络失败异常类 - * 用于表示与Google Tasks服务器交互时的网络连接失败情况 - */ public class NetworkFailureException extends Exception { - // 序列化版本UID private static final long serialVersionUID = 2107610287180234136L; - /** - * 无参构造函数 - */ public NetworkFailureException() { super(); } - /** - * 构造函数 - * @param paramString 异常信息 - */ public NetworkFailureException(String paramString) { super(paramString); } - /** - * 构造函数 - * @param paramString 异常信息 - * @param paramThrowable 引起此异常的原因 - */ public NetworkFailureException(String paramString, Throwable paramThrowable) { super(paramString, paramThrowable); } diff --git a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskASyncTask.java b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskASyncTask.java index e56a81e..a1deb99 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskASyncTask.java +++ b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskASyncTask.java @@ -29,44 +29,22 @@ import net.micode.notes.ui.NotesListActivity; import net.micode.notes.ui.NotesPreferenceActivity; -/** - * Google Tasks同步的异步任务类 - * 继承自AsyncTask,用于在后台执行Google Tasks的同步操作 - * 提供通知显示、进度更新和完成回调功能 - */ public class GTaskASyncTask extends AsyncTask { - // 同步通知的ID private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; - /** - * 同步完成监听器接口 - * 用于在同步任务完成时回调通知 - */ public interface OnCompleteListener { - /** - * 同步完成时调用 - */ void onComplete(); } - // 上下文对象 private Context mContext; - // 通知管理器 private NotificationManager mNotifiManager; - // Google Task管理器实例 private GTaskManager mTaskManager; - // 完成监听器 private OnCompleteListener mOnCompleteListener; - /** - * 构造函数 - * @param context 上下文对象 - * @param listener 完成监听器 - */ public GTaskASyncTask(Context context, OnCompleteListener listener) { mContext = context; mOnCompleteListener = listener; @@ -75,52 +53,36 @@ public class GTaskASyncTask extends AsyncTask { mTaskManager = GTaskManager.getInstance(); } - /** - * 取消同步任务 - */ public void cancelSync() { mTaskManager.cancelSync(); } - /** - * 发布同步进度 - * @param message 进度消息 - */ public void publishProgess(String message) { publishProgress(new String[] { message }); } - /** - * 显示同步通知 - * @param tickerId 通知标题的字符串资源ID - * @param content 通知内容 - */ private void showNotification(int tickerId, String content) { - Notification notification = new Notification(R.drawable.notification, mContext - .getString(tickerId), System.currentTimeMillis()); - notification.defaults = Notification.DEFAULT_LIGHTS; - notification.flags = Notification.FLAG_AUTO_CANCEL; PendingIntent pendingIntent; if (tickerId != R.string.ticker_success) { pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, - NotesPreferenceActivity.class), 0); - + NotesPreferenceActivity.class), PendingIntent.FLAG_IMMUTABLE); } else { pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, - NotesListActivity.class), 0); + NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE); } - notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, - pendingIntent); + Notification.Builder builder = new Notification.Builder(mContext) + .setAutoCancel(true) + .setContentTitle(mContext.getString(R.string.app_name)) + .setContentText(content) + .setContentIntent(pendingIntent) + .setWhen(System.currentTimeMillis()) + .setOngoing(true); + Notification notification=builder.getNotification(); mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); } - /** - * 在后台执行同步任务 - * @param unused 未使用的参数 - * @return 同步结果状态码 - */ @Override protected Integer doInBackground(Void... unused) { publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity @@ -128,10 +90,6 @@ public class GTaskASyncTask extends AsyncTask { return mTaskManager.sync(mContext, this); } - /** - * 更新同步进度 - * @param progress 进度消息数组 - */ @Override protected void onProgressUpdate(String... progress) { showNotification(R.string.ticker_syncing, progress[0]); @@ -140,10 +98,6 @@ public class GTaskASyncTask extends AsyncTask { } } - /** - * 同步任务完成后执行 - * @param result 同步结果状态码 - */ @Override protected void onPostExecute(Integer result) { if (result == GTaskManager.STATE_SUCCESS) { diff --git a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskClient.java b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskClient.java index 23a05a6..c67dfdf 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskClient.java +++ b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskClient.java @@ -61,58 +61,35 @@ import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; -/** - * Google Tasks客户端类 - * 负责与Google Tasks服务器进行通信,处理登录、任务创建、更新、删除等操作 - * 采用单例模式实现 - */ public class GTaskClient { - // 日志标签 private static final String TAG = GTaskClient.class.getSimpleName(); - // Google Tasks基础URL private static final String GTASK_URL = "https://mail.google.com/tasks/"; - // Google Tasks GET请求URL private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig"; - // Google Tasks POST请求URL private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig"; - // 单例实例 private static GTaskClient mInstance = null; - // HTTP客户端实例 private DefaultHttpClient mHttpClient; - // 当前使用的GET请求URL private String mGetUrl; - // 当前使用的POST请求URL private String mPostUrl; - // 客户端版本号 private long mClientVersion; - // 是否已登录 private boolean mLoggedin; - // 上次登录时间 private long mLastLoginTime; - // 操作ID计数器 private int mActionId; - // 登录的Google账户 private Account mAccount; - // 更新操作的JSON数组 private JSONArray mUpdateArray; - /** - * 私有构造函数 - * 初始化客户端参数 - */ private GTaskClient() { mHttpClient = null; mGetUrl = GTASK_GET_URL; @@ -125,10 +102,6 @@ public class GTaskClient { mUpdateArray = null; } - /** - * 获取单例实例 - * @return GTaskClient实例 - */ public static synchronized GTaskClient getInstance() { if (mInstance == null) { mInstance = new GTaskClient(); @@ -136,20 +109,15 @@ public class GTaskClient { return mInstance; } - /** - * 登录Google Tasks - * 检查是否需要重新登录,处理Google账户认证和Tasks登录 - * @param activity 调用此方法的Activity实例 - * @return 是否登录成功 - */ public boolean login(Activity activity) { - // 假设Cookie 5分钟后过期,需要重新登录 + // we suppose that the cookie would expire after 5 minutes + // then we need to re-login final long interval = 1000 * 60 * 5; if (mLastLoginTime + interval < System.currentTimeMillis()) { mLoggedin = false; } - // 切换账户后需要重新登录 + // need to re-login after account switch if (mLoggedin && !TextUtils.equals(getSyncAccount().name, NotesPreferenceActivity .getSyncAccountName(activity))) { @@ -168,7 +136,7 @@ public class GTaskClient { return false; } - // 必要时使用自定义域名登录 + // login with custom domain if necessary if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase() .endsWith("googlemail.com"))) { StringBuilder url = new StringBuilder(GTASK_URL).append("a/"); @@ -183,7 +151,7 @@ public class GTaskClient { } } - // 尝试使用Google官方URL登录 + // try to login with google official url if (!mLoggedin) { mGetUrl = GTASK_GET_URL; mPostUrl = GTASK_POST_URL; @@ -196,12 +164,6 @@ public class GTaskClient { return true; } - /** - * 登录Google账户,获取认证令牌 - * @param activity 调用此方法的Activity实例 - * @param invalidateToken 是否使现有令牌失效 - * @return 认证令牌,如果获取失败则返回null - */ private String loginGoogleAccount(Activity activity, boolean invalidateToken) { String authToken; AccountManager accountManager = AccountManager.get(activity); @@ -227,7 +189,7 @@ public class GTaskClient { return null; } - // 获取认证令牌 + // get the token now AccountManagerFuture accountManagerFuture = accountManager.getAuthToken(account, "goanna_mobile", null, activity, null, null); try { @@ -245,16 +207,10 @@ public class GTaskClient { return authToken; } - /** - * 尝试登录Google Tasks - * 如果登录失败,尝试使令牌失效并重新登录 - * @param activity 调用此方法的Activity实例 - * @param authToken Google账户认证令牌 - * @return 是否登录成功 - */ private boolean tryToLoginGtask(Activity activity, String authToken) { if (!loginGtask(authToken)) { - // 认证令牌可能已过期,使令牌失效并重新尝试 + // maybe the auth token is out of date, now let's invalidate the + // token and try again authToken = loginGoogleAccount(activity, true); if (authToken == null) { Log.e(TAG, "login google account failed"); @@ -269,12 +225,6 @@ public class GTaskClient { return true; } - /** - * 使用认证令牌登录Google Tasks - * 设置HTTP客户端,执行登录请求并获取Cookie和客户端版本 - * @param authToken Google账户认证令牌 - * @return 是否登录成功 - */ private boolean loginGtask(String authToken) { int timeoutConnection = 10000; int timeoutSocket = 15000; @@ -286,14 +236,14 @@ public class GTaskClient { mHttpClient.setCookieStore(localBasicCookieStore); HttpProtocolParams.setUseExpectContinue(mHttpClient.getParams(), false); - // 登录Google Tasks + // login gtask try { String loginUrl = mGetUrl + "?auth=" + authToken; HttpGet httpGet = new HttpGet(loginUrl); HttpResponse response = null; response = mHttpClient.execute(httpGet); - // 获取认证Cookie + // get the cookie now List cookies = mHttpClient.getCookieStore().getCookies(); boolean hasAuthCookie = false; for (Cookie cookie : cookies) { @@ -305,7 +255,7 @@ public class GTaskClient { Log.w(TAG, "it seems that there is no auth cookie"); } - // 获取客户端版本 + // get the client version String resString = getResponseContent(response.getEntity()); String jsBegin = "_setup("; String jsEnd = ")}"; @@ -322,7 +272,7 @@ public class GTaskClient { e.printStackTrace(); return false; } catch (Exception e) { - // 捕获所有异常 + // simply catch all exceptions Log.e(TAG, "httpget gtask_url failed"); return false; } @@ -330,20 +280,10 @@ public class GTaskClient { return true; } - /** - * 获取操作ID - * 自增并返回当前操作ID - * @return 唯一的操作ID - */ private int getActionId() { return mActionId++; } - /** - * 创建HTTP POST请求 - * 设置请求头和URL - * @return HttpPost实例 - */ private HttpPost createHttpPost() { HttpPost httpPost = new HttpPost(mPostUrl); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); @@ -351,13 +291,6 @@ public class GTaskClient { return httpPost; } - /** - * 获取HTTP响应内容 - * 处理不同的编码格式(gzip、deflate等) - * @param entity HTTP响应实体 - * @return 响应内容字符串 - * @throws IOException 如果读取响应内容时发生错误 - */ private String getResponseContent(HttpEntity entity) throws IOException { String contentEncoding = null; if (entity.getContentEncoding() != null) { @@ -390,13 +323,6 @@ public class GTaskClient { } } - /** - * 发送POST请求 - * 向Google Tasks服务器发送请求并返回响应 - * @param js 请求的JSON对象 - * @return 响应的JSON对象 - * @throws NetworkFailureException 如果网络请求失败 - */ private JSONObject postRequest(JSONObject js) throws NetworkFailureException { if (!mLoggedin) { Log.e(TAG, "please login first"); @@ -410,7 +336,7 @@ public class GTaskClient { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8"); httpPost.setEntity(entity); - // 执行POST请求 + // execute the post HttpResponse response = mHttpClient.execute(httpPost); String jsString = getResponseContent(response.getEntity()); return new JSONObject(jsString); @@ -434,12 +360,6 @@ public class GTaskClient { } } - /** - * 创建任务 - * 向Google Tasks服务器发送创建任务请求 - * @param task 要创建的任务对象 - * @throws NetworkFailureException 如果网络请求失败 - */ public void createTask(Task task) throws NetworkFailureException { commitUpdate(); try { @@ -453,7 +373,7 @@ public class GTaskClient { // client_version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); - // 发送请求 + // post JSONObject jsResponse = postRequest(jsPost); JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( GTaskStringUtils.GTASK_JSON_RESULTS).get(0); @@ -466,12 +386,6 @@ public class GTaskClient { } } - /** - * 创建任务列表 - * 向Google Tasks服务器发送创建任务列表请求 - * @param tasklist 要创建的任务列表对象 - * @throws NetworkFailureException 如果网络请求失败 - */ public void createTaskList(TaskList tasklist) throws NetworkFailureException { commitUpdate(); try { @@ -482,10 +396,10 @@ public class GTaskClient { actionList.put(tasklist.getCreateAction(getActionId())); jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); - // client_version + // client version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); - // 发送请求 + // post JSONObject jsResponse = postRequest(jsPost); JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( GTaskStringUtils.GTASK_JSON_RESULTS).get(0); @@ -498,11 +412,6 @@ public class GTaskClient { } } - /** - * 提交更新 - * 将待更新的操作发送到Google Tasks服务器 - * @throws NetworkFailureException 如果网络请求失败 - */ public void commitUpdate() throws NetworkFailureException { if (mUpdateArray != null) { try { @@ -524,17 +433,10 @@ public class GTaskClient { } } - /** - * 添加更新节点 - * 将节点的更新操作添加到待更新列表中 - * 如果待更新列表超过10项,则立即提交更新 - * @param node 要更新的节点 - * @throws NetworkFailureException 如果网络请求失败 - */ public void addUpdateNode(Node node) throws NetworkFailureException { if (node != null) { - // 过多的更新项可能导致错误 - // 最大设置为10项 + // too many update items may result in an error + // set max to 10 items if (mUpdateArray != null && mUpdateArray.length() > 10) { commitUpdate(); } @@ -545,14 +447,6 @@ public class GTaskClient { } } - /** - * 移动任务 - * 将任务从一个任务列表移动到另一个任务列表,或在同一任务列表内移动 - * @param task 要移动的任务 - * @param preParent 移动前的父任务列表 - * @param curParent 移动后的父任务列表 - * @throws NetworkFailureException 如果网络请求失败 - */ public void moveTask(Task task, TaskList preParent, TaskList curParent) throws NetworkFailureException { commitUpdate(); @@ -567,13 +461,14 @@ public class GTaskClient { action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid()); if (preParent == curParent && task.getPriorSibling() != null) { - // 只有在同一任务列表内移动且不是第一个任务时,才设置prior_sibling_id + // put prioring_sibing_id only if moving within the tasklist and + // it is not the first one action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling()); } action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid()); action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid()); if (preParent != curParent) { - // 只有在不同任务列表之间移动时,才设置dest_list + // put the dest_list only if moving between tasklists action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid()); } actionList.put(action); @@ -591,12 +486,6 @@ public class GTaskClient { } } - /** - * 删除节点 - * 将节点标记为已删除并发送到服务器 - * @param node 要删除的节点 - * @throws NetworkFailureException 如果网络请求失败 - */ public void deleteNode(Node node) throws NetworkFailureException { commitUpdate(); try { @@ -620,12 +509,6 @@ public class GTaskClient { } } - /** - * 获取所有任务列表 - * 从Google Tasks服务器获取用户的所有任务列表 - * @return 任务列表的JSON数组 - * @throws NetworkFailureException 如果网络请求失败 - */ public JSONArray getTaskLists() throws NetworkFailureException { if (!mLoggedin) { Log.e(TAG, "please login first"); @@ -664,13 +547,6 @@ public class GTaskClient { } } - /** - * 获取指定任务列表的任务 - * 从Google Tasks服务器获取指定任务列表中的所有任务 - * @param listGid 任务列表的GID - * @return 任务的JSON数组 - * @throws NetworkFailureException 如果网络请求失败 - */ public JSONArray getTaskList(String listGid) throws NetworkFailureException { commitUpdate(); try { @@ -699,18 +575,10 @@ public class GTaskClient { } } - /** - * 获取当前同步账户 - * @return 当前使用的Google账户 - */ public Account getSyncAccount() { return mAccount; } - /** - * 重置更新数组 - * 清空待更新的操作列表 - */ public void resetUpdateArray() { mUpdateArray = null; } diff --git a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java index 3107965..d2b4082 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java +++ b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java @@ -48,73 +48,45 @@ import java.util.Iterator; import java.util.Map; -/** - * Google Tasks同步管理器类 - * 负责处理本地笔记与Google Tasks之间的同步操作 - * 采用单例模式实现 - */ public class GTaskManager { - // 日志标签 private static final String TAG = GTaskManager.class.getSimpleName(); - // 同步状态:成功 public static final int STATE_SUCCESS = 0; - // 同步状态:网络错误 public static final int STATE_NETWORK_ERROR = 1; - // 同步状态:内部错误 public static final int STATE_INTERNAL_ERROR = 2; - // 同步状态:同步进行中 public static final int STATE_SYNC_IN_PROGRESS = 3; - // 同步状态:同步已取消 public static final int STATE_SYNC_CANCELLED = 4; - // 单例实例 private static GTaskManager mInstance = null; - // 用于获取认证令牌的Activity实例 private Activity mActivity; - // 应用上下文 private Context mContext; - // 内容解析器 private ContentResolver mContentResolver; - // 是否正在同步 private boolean mSyncing; - // 是否取消同步 private boolean mCancelled; - // Google Tasks列表映射表 private HashMap mGTaskListHashMap; - // Google Tasks节点映射表 private HashMap mGTaskHashMap; - // 元数据映射表 private HashMap mMetaHashMap; - // 元数据列表 private TaskList mMetaList; - // 本地删除ID集合 private HashSet mLocalDeleteIdMap; - // GID到本地ID的映射表 private HashMap mGidToNid; - // 本地ID到GID的映射表 private HashMap mNidToGid; - /** - * 私有构造函数 - * 初始化同步管理器的各个集合和映射表 - */ private GTaskManager() { mSyncing = false; mCancelled = false; @@ -127,10 +99,6 @@ public class GTaskManager { mNidToGid = new HashMap(); } - /** - * 获取单例实例 - * @return GTaskManager实例 - */ public static synchronized GTaskManager getInstance() { if (mInstance == null) { mInstance = new GTaskManager(); @@ -138,23 +106,11 @@ public class GTaskManager { return mInstance; } - /** - * 设置Activity上下文 - * 用于获取Google账户认证令牌 - * @param activity Activity实例 - */ public synchronized void setActivityContext(Activity activity) { // used for getting authtoken mActivity = activity; } - /** - * 执行同步操作 - * 处理本地与Google Tasks服务器之间的数据同步 - * @param context 应用上下文 - * @param asyncTask 异步任务实例,用于更新同步进度 - * @return 同步状态码 - */ public int sync(Context context, GTaskASyncTask asyncTask) { if (mSyncing) { Log.d(TAG, "Sync is in progress"); @@ -212,11 +168,6 @@ public class GTaskManager { return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS; } - /** - * 初始化Google Tasks列表 - * 从服务器获取所有任务列表和任务 - * @throws NetworkFailureException 如果网络请求失败 - */ private void initGTaskList() throws NetworkFailureException { if (mCancelled) return; @@ -296,11 +247,6 @@ public class GTaskManager { } } - /** - * 同步内容 - * 处理本地与服务器之间的内容同步 - * @throws NetworkFailureException 如果网络请求失败 - */ private void syncContent() throws NetworkFailureException { int syncType; Cursor c = null; @@ -405,11 +351,6 @@ public class GTaskManager { } - /** - * 同步文件夹 - * 处理本地与服务器之间的文件夹同步 - * @throws NetworkFailureException 如果网络请求失败 - */ private void syncFolder() throws NetworkFailureException { Cursor c = null; String gid; @@ -535,14 +476,6 @@ public class GTaskManager { GTaskClient.getInstance().commitUpdate(); } - /** - * 执行内容同步 - * 根据同步类型处理本地和服务器之间的内容同步 - * @param syncType 同步类型 - * @param node Google Tasks节点 - * @param c 本地数据库游标 - * @throws NetworkFailureException 如果网络请求失败 - */ private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -589,12 +522,6 @@ public class GTaskManager { } } - /** - * 添加本地节点 - * 将Google Tasks节点添加到本地数据库 - * @param node Google Tasks节点 - * @throws NetworkFailureException 如果网络请求失败 - */ private void addLocalNode(Node node) throws NetworkFailureException { if (mCancelled) { return; @@ -669,13 +596,6 @@ public class GTaskManager { updateRemoteMeta(node.getGid(), sqlNote); } - /** - * 更新本地节点 - * 使用Google Tasks节点更新本地数据库 - * @param node Google Tasks节点 - * @param c 本地数据库游标 - * @throws NetworkFailureException 如果网络请求失败 - */ private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -699,13 +619,6 @@ public class GTaskManager { updateRemoteMeta(node.getGid(), sqlNote); } - /** - * 添加远程节点 - * 将本地节点添加到Google Tasks服务器 - * @param node Google Tasks节点 - * @param c 本地数据库游标 - * @throws NetworkFailureException 如果网络请求失败 - */ private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -779,13 +692,6 @@ public class GTaskManager { mNidToGid.put(sqlNote.getId(), n.getGid()); } - /** - * 更新远程节点 - * 使用本地节点更新Google Tasks服务器 - * @param node Google Tasks节点 - * @param c 本地数据库游标 - * @throws NetworkFailureException 如果网络请求失败 - */ private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -824,13 +730,6 @@ public class GTaskManager { sqlNote.commit(true); } - /** - * 更新远程元数据 - * 将本地节点的元数据更新到Google Tasks服务器 - * @param gid Google Tasks节点ID - * @param sqlNote 本地笔记对象 - * @throws NetworkFailureException 如果网络请求失败 - */ private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException { if (sqlNote != null && sqlNote.isNoteType()) { MetaData metaData = mMetaHashMap.get(gid); @@ -847,11 +746,6 @@ public class GTaskManager { } } - /** - * 刷新本地同步ID - * 更新本地数据库中的同步ID,确保与服务器保持一致 - * @throws NetworkFailureException 如果网络请求失败 - */ private void refreshLocalSyncId() throws NetworkFailureException { if (mCancelled) { return; @@ -896,18 +790,10 @@ public class GTaskManager { } } - /** - * 获取当前同步账户 - * @return 同步账户的邮箱地址 - */ public String getSyncAccount() { return GTaskClient.getInstance().getSyncAccount().name; } - /** - * 取消同步 - * 设置取消标志,中断正在进行的同步操作 - */ public void cancelSync() { mCancelled = true; } diff --git a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java index 55cb3cf..cca36f7 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java +++ b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskSyncService.java @@ -23,43 +23,25 @@ import android.content.Intent; import android.os.Bundle; import android.os.IBinder; -/** - * Google Tasks同步服务类 - * 用于管理Google Tasks的同步操作,包括启动同步、取消同步等功能 - * 通过广播通知同步状态和进度 - */ public class GTaskSyncService extends Service { - // 同步操作类型的额外参数名称 public final static String ACTION_STRING_NAME = "sync_action_type"; - // 启动同步操作的类型值 public final static int ACTION_START_SYNC = 0; - // 取消同步操作的类型值 public final static int ACTION_CANCEL_SYNC = 1; - // 无效操作的类型值 public final static int ACTION_INVALID = 2; - // 同步服务广播的名称 public final static String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service"; - // 广播中同步状态的额外参数名称 public final static String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing"; - // 广播中同步进度的额外参数名称 public final static String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg"; - // 同步任务实例 private static GTaskASyncTask mSyncTask = null; - // 当前同步进度消息 private static String mSyncProgress = ""; - /** - * 启动同步任务 - * 如果当前没有同步任务在运行,则创建新的同步任务并执行 - */ private void startSync() { if (mSyncTask == null) { mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() { @@ -74,33 +56,17 @@ public class GTaskSyncService extends Service { } } - /** - * 取消同步任务 - * 如果当前有同步任务在运行,则取消该任务 - */ private void cancelSync() { if (mSyncTask != null) { mSyncTask.cancelSync(); } } - /** - * 服务创建时调用 - * 初始化同步任务实例为null - */ @Override public void onCreate() { mSyncTask = null; } - /** - * 处理服务启动命令 - * 根据意图中的操作类型执行相应的同步操作 - * @param intent 启动服务的意图 - * @param flags 启动标志 - * @param startId 服务启动ID - * @return 服务启动模式 - */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Bundle bundle = intent.getExtras(); @@ -120,10 +86,6 @@ public class GTaskSyncService extends Service { return super.onStartCommand(intent, flags, startId); } - /** - * 系统低内存时调用 - * 取消当前正在运行的同步任务以释放内存 - */ @Override public void onLowMemory() { if (mSyncTask != null) { @@ -131,20 +93,10 @@ public class GTaskSyncService extends Service { } } - /** - * 绑定服务时调用 - * 此服务不支持绑定,返回null - * @param intent 绑定服务的意图 - * @return 服务的IBinder接口实例 - */ public IBinder onBind(Intent intent) { return null; } - /** - * 发送同步状态广播 - * @param msg 同步进度消息 - */ public void sendBroadcast(String msg) { mSyncProgress = msg; Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME); @@ -153,10 +105,6 @@ public class GTaskSyncService extends Service { sendBroadcast(intent); } - /** - * 静态方法,启动同步服务 - * @param activity 调用此方法的Activity实例 - */ public static void startSync(Activity activity) { GTaskManager.getInstance().setActivityContext(activity); Intent intent = new Intent(activity, GTaskSyncService.class); @@ -164,28 +112,16 @@ public class GTaskSyncService extends Service { activity.startService(intent); } - /** - * 静态方法,取消同步服务 - * @param context 调用此方法的上下文 - */ public static void cancelSync(Context context) { Intent intent = new Intent(context, GTaskSyncService.class); intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC); context.startService(intent); } - /** - * 静态方法,检查是否正在同步 - * @return 是否已开始同步且同步任务未完成 - */ public static boolean isSyncing() { return mSyncTask != null; } - /** - * 静态方法,获取同步进度字符串 - * @return 当前同步进度消息 - */ public static String getProgressString() { return mSyncProgress; } diff --git a/src/Notes-master/src/net/micode/notes/model/Note.java b/src/Notes-master/src/net/micode/notes/model/Note.java index f150e98..6706cf6 100644 --- a/src/Notes-master/src/net/micode/notes/model/Note.java +++ b/src/Notes-master/src/net/micode/notes/model/Note.java @@ -34,25 +34,12 @@ import net.micode.notes.data.Notes.TextNote; import java.util.ArrayList; -/** - * 笔记模型类,用于管理笔记的创建、更新和同步操作 - * 支持文本笔记和通话记录笔记,通过ContentResolver与数据库交互 - */ public class Note { - // 日志标签 - private static final String TAG = "Note"; - - // 存储笔记基本信息的变更值 private ContentValues mNoteDiffValues; - - // 存储笔记数据内容的内部对象 private NoteData mNoteData; + private static final String TAG = "Note"; /** - * 为添加新笔记到数据库创建一个新的笔记ID - * @param context 上下文对象 - * @param folderId 文件夹ID,新笔记将被添加到该文件夹 - * @return 新创建的笔记ID - * @throws IllegalStateException 如果创建笔记失败 + * Create a new note id for adding a new note to databases */ public static synchronized long getNewNoteId(Context context, long folderId) { // Create a new note in the database @@ -78,82 +65,41 @@ public class Note { return noteId; } - /** - * 构造方法,初始化笔记对象 - */ public Note() { mNoteDiffValues = new ContentValues(); mNoteData = new NoteData(); } - /** - * 设置笔记的基本属性值 - * @param key 属性键名 - * @param value 属性值 - */ public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - /** - * 设置笔记的文本数据内容 - * @param key 数据键名 - * @param value 数据值 - */ public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } - /** - * 设置文本数据的ID - * @param id 文本数据ID - */ public void setTextDataId(long id) { mNoteData.setTextDataId(id); } - /** - * 获取文本数据的ID - * @return 文本数据ID - */ public long getTextDataId() { return mNoteData.mTextDataId; } - /** - * 设置通话记录数据的ID - * @param id 通话记录数据ID - */ public void setCallDataId(long id) { mNoteData.setCallDataId(id); } - /** - * 设置笔记的通话记录数据内容 - * @param key 数据键名 - * @param value 数据值 - */ public void setCallData(String key, String value) { mNoteData.setCallData(key, value); } - /** - * 检查笔记是否在本地被修改 - * @return 如果笔记被修改返回true,否则返回false - */ public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } - /** - * 将本地修改的笔记数据同步到ContentResolver - * @param context 上下文对象 - * @param noteId 要同步的笔记ID - * @return 如果同步成功返回true,否则返回false - * @throws IllegalArgumentException 如果笔记ID无效 - */ public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); @@ -164,14 +110,15 @@ public class Note { } /** - * 理论上,一旦数据改变,笔记的{@link NoteColumns#LOCAL_MODIFIED}和{@link NoteColumns#MODIFIED_DATE}字段应该被更新 - * 为了数据安全,即使更新笔记失败,我们也会更新笔记数据信息 + * In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and + * {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the + * note data info */ if (context.getContentResolver().update( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null, null) == 0) { Log.e(TAG, "Update note error, should not happen"); - // 不返回,继续执行 + // Do not return, fall through } mNoteDiffValues.clear(); @@ -183,29 +130,17 @@ public class Note { return true; } - /** - * 笔记数据内部类,用于管理笔记的具体数据内容 - * 包括文本数据和通话记录数据 - */ private class NoteData { - // 日志标签 - private static final String TAG = "NoteData"; - - // 文本数据ID private long mTextDataId; - // 文本数据内容的变更值 private ContentValues mTextDataValues; - // 通话记录数据ID private long mCallDataId; - // 通话记录数据内容的变更值 private ContentValues mCallDataValues; - /** - * 构造方法,初始化笔记数据对象 - */ + private static final String TAG = "NoteData"; + public NoteData() { mTextDataValues = new ContentValues(); mCallDataValues = new ContentValues(); @@ -213,19 +148,10 @@ public class Note { mCallDataId = 0; } - /** - * 检查笔记数据是否在本地被修改 - * @return 如果数据被修改返回true,否则返回false - */ boolean isLocalModified() { return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; } - /** - * 设置文本数据ID - * @param id 文本数据ID - * @throws IllegalArgumentException 如果ID无效 - */ void setTextDataId(long id) { if(id <= 0) { throw new IllegalArgumentException("Text data id should larger than 0"); @@ -233,11 +159,6 @@ public class Note { mTextDataId = id; } - /** - * 设置通话记录数据ID - * @param id 通话记录数据ID - * @throws IllegalArgumentException 如果ID无效 - */ void setCallDataId(long id) { if (id <= 0) { throw new IllegalArgumentException("Call data id should larger than 0"); @@ -245,38 +166,21 @@ public class Note { mCallDataId = id; } - /** - * 设置通话记录数据内容 - * @param key 数据键名 - * @param value 数据值 - */ void setCallData(String key, String value) { mCallDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - /** - * 设置文本数据内容 - * @param key 数据键名 - * @param value 数据值 - */ void setTextData(String key, String value) { mTextDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - /** - * 将笔记数据推送到ContentResolver - * @param context 上下文对象 - * @param noteId 笔记ID - * @return 如果操作成功返回笔记的Uri,否则返回null - * @throws IllegalArgumentException 如果笔记ID无效 - */ Uri pushIntoContentResolver(Context context, long noteId) { /** - * 安全检查 + * Check for safety */ if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); @@ -288,7 +192,6 @@ public class Note { if(mTextDataValues.size() > 0) { mTextDataValues.put(DataColumns.NOTE_ID, noteId); if (mTextDataId == 0) { - // 新建文本数据 mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mTextDataValues); @@ -300,7 +203,6 @@ public class Note { return null; } } else { - // 更新已有文本数据 builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mTextDataId)); builder.withValues(mTextDataValues); @@ -312,7 +214,6 @@ public class Note { if(mCallDataValues.size() > 0) { mCallDataValues.put(DataColumns.NOTE_ID, noteId); if (mCallDataId == 0) { - // 新建通话记录数据 mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mCallDataValues); @@ -324,7 +225,6 @@ public class Note { return null; } } else { - // 更新已有通话记录数据 builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mCallDataId)); builder.withValues(mCallDataValues); @@ -333,7 +233,6 @@ public class Note { mCallDataValues.clear(); } - // 执行批量操作 if (operationList.size() > 0) { try { ContentProviderResult[] results = context.getContentResolver().applyBatch( diff --git a/src/Notes-master/src/net/micode/notes/model/WorkingNote.java b/src/Notes-master/src/net/micode/notes/model/WorkingNote.java index 0964759..f3c6f53 100644 --- a/src/Notes-master/src/net/micode/notes/model/WorkingNote.java +++ b/src/Notes-master/src/net/micode/notes/model/WorkingNote.java @@ -32,57 +32,40 @@ import net.micode.notes.data.Notes.TextNote; import net.micode.notes.tool.ResourceParser.NoteBgResources; -/** - * 工作笔记类,用于处理正在编辑的笔记 - * 是Note类的包装类,提供更多功能和状态管理 - * 支持创建新笔记、加载现有笔记、保存笔记等操作 - */ public class WorkingNote { - // 日志标签 - private static final String TAG = "WorkingNote"; - - // 上下文对象 - private Context mContext; - - // 内部Note对象,用于实际数据操作 + // Note for the working note private Note mNote; - - // 笔记ID + // Note Id private long mNoteId; - - // 笔记内容 + // Note content private String mContent; - - // 笔记模式(如普通模式、检查列表模式) + // Note mode private int mMode; - // 提醒日期 private long mAlertDate; - // 最后修改日期 private long mModifiedDate; - // 背景颜色ID private int mBgColorId; + + private String mTitle; - // 小组件ID private int mWidgetId; - // 小组件类型 private int mWidgetType; - // 文件夹ID private long mFolderId; - // 是否已删除 + private Context mContext; + + private String mCustomBgUri; // [新增] + + private static final String TAG = "WorkingNote"; + private boolean mIsDeleted; - // 笔记设置变化监听器 private NoteSettingChangedListener mNoteSettingStatusListener; - /** - * 数据查询投影数组,用于获取笔记的具体数据内容 - */ public static final String[] DATA_PROJECTION = new String[] { DataColumns.ID, DataColumns.CONTENT, @@ -93,53 +76,42 @@ public class WorkingNote { DataColumns.DATA4, }; - /** - * 笔记查询投影数组,用于获取笔记的基本信息 - */ public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, - NoteColumns.MODIFIED_DATE + NoteColumns.MODIFIED_DATE, + NoteColumns.TITLE, + NoteColumns.CUSTOM_BG_URI }; - // DATA_PROJECTION中ID列的索引 private static final int DATA_ID_COLUMN = 0; - // DATA_PROJECTION中内容列的索引 private static final int DATA_CONTENT_COLUMN = 1; - // DATA_PROJECTION中MIME类型列的索引 private static final int DATA_MIME_TYPE_COLUMN = 2; - // DATA_PROJECTION中模式列的索引 private static final int DATA_MODE_COLUMN = 3; - // NOTE_PROJECTION中父ID列的索引 private static final int NOTE_PARENT_ID_COLUMN = 0; - // NOTE_PROJECTION中提醒日期列的索引 private static final int NOTE_ALERTED_DATE_COLUMN = 1; - // NOTE_PROJECTION中背景颜色ID列的索引 private static final int NOTE_BG_COLOR_ID_COLUMN = 2; - // NOTE_PROJECTION中小组件ID列的索引 private static final int NOTE_WIDGET_ID_COLUMN = 3; - // NOTE_PROJECTION中小组件类型列的索引 private static final int NOTE_WIDGET_TYPE_COLUMN = 4; - - // NOTE_PROJECTION中修改日期列的索引 + private static final int NOTE_MODIFIED_DATE_COLUMN = 5; + + private static final int NOTE_TITLE_COLUMN = 6; - /** - * 创建新笔记的构造方法 - * @param context 上下文对象 - * @param folderId 文件夹ID - */ + private static final int NOTE_CUSTOM_BG_COLUMN = 7; + + // New note construct private WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; @@ -152,12 +124,7 @@ public class WorkingNote { mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } - /** - * 加载现有笔记的构造方法 - * @param context 上下文对象 - * @param noteId 笔记ID - * @param folderId 文件夹ID - */ + // Existing note construct private WorkingNote(Context context, long noteId, long folderId) { mContext = context; mNoteId = noteId; @@ -167,10 +134,6 @@ public class WorkingNote { loadNote(); } - /** - * 从数据库加载笔记的基本信息 - * @throws IllegalArgumentException 如果找不到指定ID的笔记 - */ private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, @@ -184,6 +147,8 @@ public class WorkingNote { mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN); mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); + mTitle = cursor.getString(NOTE_TITLE_COLUMN); + mCustomBgUri = cursor.getString(NOTE_CUSTOM_BG_COLUMN); } cursor.close(); } else { @@ -193,10 +158,6 @@ public class WorkingNote { loadNoteData(); } - /** - * 从数据库加载笔记的具体数据内容 - * @throws IllegalArgumentException 如果找不到指定ID的笔记数据 - */ private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { @@ -225,15 +186,6 @@ public class WorkingNote { } } - /** - * 创建一个新的空笔记 - * @param context 上下文对象 - * @param folderId 文件夹ID - * @param widgetId 小组件ID - * @param widgetType 小组件类型 - * @param defaultBgColorId 默认背景颜色ID - * @return 创建的空笔记对象 - */ public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); @@ -243,21 +195,10 @@ public class WorkingNote { return note; } - /** - * 从数据库加载指定ID的笔记 - * @param context 上下文对象 - * @param id 笔记ID - * @return 加载的工作笔记对象 - */ public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } - /** - * 保存笔记到数据库 - * 该方法是线程安全的,确保在多线程环境下正确保存笔记 - * @return 保存成功返回true,否则返回false - */ public synchronized boolean saveNote() { if (isWorthSaving()) { if (!existInDatabase()) { @@ -267,11 +208,37 @@ public class WorkingNote { } } + // 1. 只有当标题真的为空时(比如第一次编辑新便签),才执行自动提取逻辑 + if (TextUtils.isEmpty(mTitle)) { + String plainText = getPlainText(mContent); // 使用之前提供的清洗工具 + if (!TextUtils.isEmpty(plainText)) { + String[] lines = plainText.split("\n"); + for (String line : lines) { + if (!TextUtils.isEmpty(line.trim())) { + mTitle = line.trim(); + break; + } + } + // 限制长度 + if (mTitle != null && mTitle.length() > 20) { + mTitle = mTitle.substring(0, 20); + } + } + } + + // 2. 无论标题是刚才生成的,还是以前加载的,都写入数据库更新 + // 如果用户在外部进行了“重命名”,数据库里的值会变,loadNote 会拿到新值,此处也会保留新值 + mNote.setNoteValue(NoteColumns.TITLE, mTitle); + + // 3. 摘要预览清洗(Snippet 依然随正文更新,保证预览的时效性) + String plainContent = getPlainText(mContent); + String snippet = plainContent.replace("\n", " ").trim(); + if (snippet.length() > 60) snippet = snippet.substring(0, 60); + mNote.setNoteValue(NoteColumns.SNIPPET, snippet); + + // 提交修改到数据库 mNote.syncNote(mContext, mNoteId); - /** - * Update widget content if there exist any widget of this note - */ if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { @@ -284,17 +251,32 @@ public class WorkingNote { } /** - * 检查笔记是否已存在于数据库中 - * @return 存在返回true,否则返回false + * [新增] 强力清洗 HTML 标签及特殊符号,仅保留可读文本 */ + private String getPlainText(String html) { + if (TextUtils.isEmpty(html)) return ""; + + // 1. 处理块级标签,防止文字挤在一起 + String result = html.replaceAll("(?i)", "\n") // 换行符 + .replaceAll("(?i)", "\n") // 层叠样式结束换行 + .replaceAll("(?i)

", "\n"); // 段落结束换行 + + // 2. 利用 Android 原生工具解析 HTML 实体 (如   -> 空格) + // 注意:这里使用 toString() 剥离大部分标准标签 + result = android.text.Html.fromHtml(result).toString(); + + // 3. 正则强力保底清洗 + result = result.replaceAll("<[^>]+>", "") // 删掉所有尖括号内的代码 + .replaceAll("\\uFFFC", "") // 删掉 Android 的 ImageSpan 占位符(OBJECT_REPLACEMENT_CHARACTER) + .replaceAll("&[^;]+;", ""); // 删掉残留的 HTML 实体(如 &) + + return result.trim(); + } + public boolean existInDatabase() { return mNoteId > 0; } - /** - * 判断笔记是否值得保存到数据库 - * @return 如果笔记值得保存返回true,否则返回false - */ private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { @@ -304,19 +286,10 @@ public class WorkingNote { } } - /** - * 设置笔记设置变化监听器 - * @param l 笔记设置变化监听器 - */ public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } - /** - * 设置笔记的提醒日期 - * @param date 提醒日期(时间戳) - * @param set 是否设置提醒 - */ public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -327,10 +300,6 @@ public class WorkingNote { } } - /** - * 标记笔记为已删除或未删除 - * @param mark true表示标记为已删除,false表示标记为未删除 - */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -339,13 +308,15 @@ public class WorkingNote { } } - /** - * 设置笔记的背景颜色ID - * @param id 背景颜色ID - */ + // 1. 修改 setBgColorId 方法:逻辑是“选了颜色就放弃图片” public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; + + // [新增手术:清除自定义背景] + mCustomBgUri = ""; + mNote.setNoteValue(NoteColumns.CUSTOM_BG_URI, ""); + if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onBackgroundColorChanged(); } @@ -353,10 +324,17 @@ public class WorkingNote { } } - /** - * 设置笔记的检查列表模式 - * @param mode 模式类型(0表示普通模式,1表示检查列表模式) - */ + // 2. 确保已添加 Getter/Setter + public void setCustomBgUri(String uri) { + this.mCustomBgUri = uri; + // 立即告诉数据库也要更新这个值 + mNote.setNoteValue(NoteColumns.CUSTOM_BG_URI, uri); + } + + public String getCustomBgUri() { + return mCustomBgUri; + } + public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -367,10 +345,6 @@ public class WorkingNote { } } - /** - * 设置笔记的小组件类型 - * @param type 小组件类型 - */ public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -378,10 +352,6 @@ public class WorkingNote { } } - /** - * 设置笔记的小组件ID - * @param id 小组件ID - */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -389,10 +359,6 @@ public class WorkingNote { } } - /** - * 设置笔记的工作文本内容 - * @param text 笔记内容文本 - */ public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; @@ -400,139 +366,80 @@ public class WorkingNote { } } - /** - * 将普通笔记转换为通话记录笔记 - * @param phoneNumber 电话号码 - * @param callDate 通话日期(时间戳) - */ public void convertToCallNote(String phoneNumber, long callDate) { mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); } - /** - * 检查笔记是否设置了时钟提醒 - * @return 如果设置了提醒返回true,否则返回false - */ public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } - /** - * 获取笔记的内容 - * @return 笔记内容文本 - */ public String getContent() { return mContent; } - /** - * 获取笔记的提醒日期 - * @return 提醒日期(时间戳) - */ public long getAlertDate() { return mAlertDate; } - /** - * 获取笔记的最后修改日期 - * @return 最后修改日期(时间戳) - */ public long getModifiedDate() { return mModifiedDate; } - /** - * 获取笔记背景颜色的资源ID - * @return 背景颜色资源ID - */ public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } - /** - * 获取笔记的背景颜色ID - * @return 背景颜色ID - */ public int getBgColorId() { return mBgColorId; } - /** - * 获取笔记标题背景颜色的资源ID - * @return 标题背景颜色资源ID - */ public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } - /** - * 获取笔记的检查列表模式 - * @return 模式类型(0表示普通模式,1表示检查列表模式) - */ public int getCheckListMode() { return mMode; } - /** - * 获取笔记的ID - * @return 笔记ID - */ public long getNoteId() { return mNoteId; } - /** - * 获取笔记所在的文件夹ID - * @return 文件夹ID - */ public long getFolderId() { return mFolderId; } - /** - * 获取笔记关联的小组件ID - * @return 小组件ID - */ public int getWidgetId() { return mWidgetId; } - /** - * 获取笔记关联的小组件类型 - * @return 小组件类型 - */ public int getWidgetType() { return mWidgetType; } - /** - * 笔记设置变化监听器接口 - * 用于监听笔记设置的变化,如背景颜色、提醒时间、小组件和检查列表模式等 - */ public interface NoteSettingChangedListener { /** - * 当笔记的背景颜色发生变化时调用 + * Called when the background color of current note has just changed */ void onBackgroundColorChanged(); /** - * 当用户设置或修改提醒时间时调用 - * @param date 提醒日期(时间戳) - * @param set 是否设置提醒 + * Called when user set clock */ void onClockAlertChanged(long date, boolean set); /** - * 当用户通过小组件创建或修改笔记时调用 + * Call when user create note from widget */ void onWidgetChanged(); /** - * 当笔记在检查列表模式和普通模式之间切换时调用 - * @param oldMode 切换前的模式 - * @param newMode 切换后的模式 + * Call when switch between check list mode and normal mode + * @param oldMode is previous mode before change + * @param newMode is new mode */ void onCheckListModeChanged(int oldMode, int newMode); } -- 2.34.1