diff --git a/Notes-master/src/net/micode/notes/tool/DataUtils.java b/Notes-master/src/net/micode/notes/tool/DataUtils.java index 52b9248..7e841b9 100644 --- a/Notes-master/src/net/micode/notes/tool/DataUtils.java +++ b/Notes-master/src/net/micode/notes/tool/DataUtils.java @@ -34,11 +34,20 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; - - - +/** + * 数据工具类,提供笔记数据的常用操作方法 + * 包括批量删除、移动、查询等功能 + * 使用ContentProvider操作笔记数据库 + */ public class DataUtils { public static final String TAG = "DataUtils"; + + /** + * 批量删除笔记 + * @param resolver ContentResolver对象 + * @param ids 要删除的笔记ID集合 + * @return 删除成功返回true,失败返回false + */ public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -49,8 +58,10 @@ public class DataUtils { return true; } + // 构建批量操作列表 ArrayList operationList = new ArrayList(); for (long id : ids) { + // 跳过系统根文件夹 if(id == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Don't delete system folder root"); continue; @@ -59,7 +70,9 @@ public class DataUtils { .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); operationList.add(builder.build()); } + try { + // 执行批量操作 ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); if (results == null || results.length == 0 || results[0] == null) { Log.d(TAG, "delete notes failed, ids:" + ids.toString()); @@ -74,6 +87,13 @@ public class DataUtils { return false; } + /** + * 将笔记移动到指定文件夹 + * @param resolver ContentResolver对象 + * @param id 笔记ID + * @param srcFolderId 源文件夹ID + * @param desFolderId 目标文件夹ID + */ public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { ContentValues values = new ContentValues(); values.put(NoteColumns.PARENT_ID, desFolderId); @@ -82,6 +102,13 @@ public class DataUtils { resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } + /** + * 批量将笔记移动到指定文件夹 + * @param resolver ContentResolver对象 + * @param ids 要移动的笔记ID集合 + * @param folderId 目标文件夹ID + * @return 移动成功返回true,失败返回false + */ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { if (ids == null) { @@ -89,6 +116,7 @@ public class DataUtils { return true; } + // 构建批量操作列表 ArrayList operationList = new ArrayList(); for (long id : ids) { ContentProviderOperation.Builder builder = ContentProviderOperation @@ -99,6 +127,7 @@ public class DataUtils { } try { + // 执行批量操作 ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); if (results == null || results.length == 0 || results[0] == null) { Log.d(TAG, "delete notes failed, ids:" + ids.toString()); @@ -114,7 +143,9 @@ public class DataUtils { } /** - * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} + * 获取用户文件夹数量(不包括系统文件夹) + * @param resolver ContentResolver对象 + * @return 用户文件夹数量 */ public static int getUserFolderCount(ContentResolver resolver) { Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, @@ -138,6 +169,13 @@ public class DataUtils { return count; } + /** + * 检查笔记是否在数据库中可见(未被删除) + * @param resolver ContentResolver对象 + * @param noteId 笔记ID + * @param type 笔记类型 + * @return 可见返回true,不可见返回false + */ public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, @@ -155,6 +193,12 @@ public class DataUtils { return exist; } + /** + * 检查笔记是否存在于数据库中 + * @param resolver ContentResolver对象 + * @param noteId 笔记ID + * @return 存在返回true,不存在返回false + */ public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, null, null, null); @@ -169,6 +213,12 @@ public class DataUtils { return exist; } + /** + * 检查数据项是否存在于数据库中 + * @param resolver ContentResolver对象 + * @param dataId 数据项ID + * @return 存在返回true,不存在返回false + */ public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null, null, null, null); @@ -183,6 +233,12 @@ public class DataUtils { return exist; } + /** + * 检查是否存在同名的可见文件夹 + * @param resolver ContentResolver对象 + * @param name 文件夹名称 + * @return 存在返回true,不存在返回false + */ public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + @@ -199,6 +255,12 @@ public class DataUtils { return exist; } + /** + * 获取文件夹下的所有笔记小部件 + * @param resolver ContentResolver对象 + * @param folderId 文件夹ID + * @return 小部件属性集合 + */ public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, @@ -226,6 +288,12 @@ public class DataUtils { return set; } + /** + * 根据笔记ID获取通话号码 + * @param resolver ContentResolver对象 + * @param noteId 笔记ID + * @return 通话号码,不存在则返回空字符串 + */ public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.PHONE_NUMBER }, @@ -245,6 +313,13 @@ public class DataUtils { return ""; } + /** + * 根据电话号码和通话日期获取笔记ID + * @param resolver ContentResolver对象 + * @param phoneNumber 电话号码 + * @param callDate 通话日期 + * @return 笔记ID,不存在则返回0 + */ public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.NOTE_ID }, @@ -266,6 +341,12 @@ public class DataUtils { return 0; } + /** + * 根据笔记ID获取摘要 + * @param resolver ContentResolver对象 + * @param noteId 笔记ID + * @return 笔记摘要 + */ public static String getSnippetById(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, new String [] { NoteColumns.SNIPPET }, @@ -284,6 +365,11 @@ public class DataUtils { throw new IllegalArgumentException("Note is not found with id: " + noteId); } + /** + * 格式化笔记摘要 + * @param snippet 原始摘要 + * @return 格式化后的摘要 + */ public static String getFormattedSnippet(String snippet) { if (snippet != null) { snippet = snippet.trim(); @@ -294,4 +380,4 @@ public class DataUtils { } return snippet; } -} +} \ No newline at end of file diff --git a/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java b/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java index 666b729..f0ea862 100644 --- a/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java +++ b/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java @@ -2,112 +2,82 @@ * 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.tool; +/** + * Google任务相关的字符串常量工具类 + * 定义了Google任务同步所需的JSON字段名、文件夹命名规范和元数据标签 + * 用于标准化Google任务与本地笔记的数据交互格式 + */ public class GTaskStringUtils { - public final static String GTASK_JSON_ACTION_ID = "action_id"; - - public final static String GTASK_JSON_ACTION_LIST = "action_list"; - - public final static String GTASK_JSON_ACTION_TYPE = "action_type"; - - public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; - - public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; - - public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; - - public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; - - public final static String GTASK_JSON_CREATOR_ID = "creator_id"; - - public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; - - public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; - - public final static String GTASK_JSON_COMPLETED = "completed"; - - public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; - - public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; - - public final static String GTASK_JSON_DELETED = "deleted"; - - public final static String GTASK_JSON_DEST_LIST = "dest_list"; - - public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; - - public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; - - public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; - - public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; - - public final static String GTASK_JSON_GET_DELETED = "get_deleted"; - - public final static String GTASK_JSON_ID = "id"; - - public final static String GTASK_JSON_INDEX = "index"; - - public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; - - public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; - - public final static String GTASK_JSON_LIST_ID = "list_id"; - - public final static String GTASK_JSON_LISTS = "lists"; - - public final static String GTASK_JSON_NAME = "name"; - - public final static String GTASK_JSON_NEW_ID = "new_id"; - - public final static String GTASK_JSON_NOTES = "notes"; - - public final static String GTASK_JSON_PARENT_ID = "parent_id"; - - public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; - - public final static String GTASK_JSON_RESULTS = "results"; - - public final static String GTASK_JSON_SOURCE_LIST = "source_list"; - - public final static String GTASK_JSON_TASKS = "tasks"; - - public final static String GTASK_JSON_TYPE = "type"; - - public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; - - public final static String GTASK_JSON_TYPE_TASK = "TASK"; - - public final static String GTASK_JSON_USER = "user"; - - public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; - - public final static String FOLDER_DEFAULT = "Default"; - - public final static String FOLDER_CALL_NOTE = "Call_Note"; - - public final static String FOLDER_META = "METADATA"; - - public final static String META_HEAD_GTASK_ID = "meta_gid"; - - public final static String META_HEAD_NOTE = "meta_note"; - - public final static String META_HEAD_DATA = "meta_data"; - - public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; - -} + // Google任务JSON协议字段 - 动作相关 + public final static String GTASK_JSON_ACTION_ID = "action_id"; // 动作唯一标识 + public final static String GTASK_JSON_ACTION_LIST = "action_list"; // 动作列表 + public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // 动作类型 + + // 支持的动作类型枚举值 + public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; // 创建动作 + public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; // 获取所有数据动作 + public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // 移动动作 + public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // 更新动作 + + // Google任务JSON协议字段 - 实体属性 + public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // 创建者ID + public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // 子实体 + public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // 客户端版本 + public final static String GTASK_JSON_COMPLETED = "completed"; // 完成状态 + public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; // 当前列表ID + public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // 默认列表ID + public final static String GTASK_JSON_DELETED = "deleted"; // 已删除标记 + public final static String GTASK_JSON_DEST_LIST = "dest_list"; // 目标列表 + public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // 目标父级 + public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // 目标父级类型 + public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; // 实体变更 + public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // 实体类型 + public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // 获取已删除项 + public final static String GTASK_JSON_ID = "id"; // 实体ID + public final static String GTASK_JSON_INDEX = "index"; // 索引位置 + public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // 最后修改时间 + public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // 最新同步点 + public final static String GTASK_JSON_LIST_ID = "list_id"; // 列表ID + public final static String GTASK_JSON_LISTS = "lists"; // 列表集合 + public final static String GTASK_JSON_NAME = "name"; // 名称 + public final static String GTASK_JSON_NEW_ID = "new_id"; // 新ID + public final static String GTASK_JSON_NOTES = "notes"; // 备注信息 + public final static String GTASK_JSON_PARENT_ID = "parent_id"; // 父级ID + public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 前一个兄弟ID + public final static String GTASK_JSON_RESULTS = "results"; // 结果集合 + public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // 源列表 + public final static String GTASK_JSON_TASKS = "tasks"; // 任务集合 + public final static String GTASK_JSON_TYPE = "type"; // 类型标识 + + // 实体类型枚举值 + public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // 分组类型 + public final static String GTASK_JSON_TYPE_TASK = "TASK"; // 任务类型 + public final static String GTASK_JSON_USER = "user"; // 用户信息 + + // 本地文件夹命名规范 - MIUI笔记专用前缀 + public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; // MIUI笔记文件夹前缀 + + // 系统默认文件夹名称 + public final static String FOLDER_DEFAULT = "Default"; // 默认文件夹 + public final static String FOLDER_CALL_NOTE = "Call_Note"; // 通话记录文件夹 + public final static String FOLDER_META = "METADATA"; // 元数据文件夹 + + // 元数据头部字段 - 用于存储Google任务关联信息 + public final static String META_HEAD_GTASK_ID = "meta_gid"; // Google任务ID元数据 + public final static String META_HEAD_NOTE = "meta_note"; // 笔记元数据 + public final static String META_HEAD_DATA = "meta_data"; // 数据元数据 + public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // 元数据笔记名称(禁止修改删除) +} \ No newline at end of file diff --git a/Notes-master/src/net/micode/notes/tool/ResourceParser.java b/Notes-master/src/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..bacf620 100644 --- a/Notes-master/src/net/micode/notes/tool/ResourceParser.java +++ b/Notes-master/src/net/micode/notes/tool/ResourceParser.java @@ -22,24 +22,38 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; +/** + * 资源解析工具类,用于管理和获取笔记应用的各种资源 + * 包括笔记背景、列表项背景、桌面小部件背景和文本样式等 + * 通过静态常量和内部类组织资源,提供统一的资源访问接口 + */ public class ResourceParser { - public static final int YELLOW = 0; - public static final int BLUE = 1; - public static final int WHITE = 2; - public static final int GREEN = 3; - public static final int RED = 4; + // 笔记背景颜色常量定义 + public static final int YELLOW = 0; // 黄色背景 + public static final int BLUE = 1; // 蓝色背景 + public static final int WHITE = 2; // 白色背景 + public static final int GREEN = 3; // 绿色背景 + public static final int RED = 4; // 红色背景 + // 默认背景颜色为黄色 public static final int BG_DEFAULT_COLOR = YELLOW; - public static final int TEXT_SMALL = 0; - public static final int TEXT_MEDIUM = 1; - public static final int TEXT_LARGE = 2; - public static final int TEXT_SUPER = 3; + // 文本大小常量定义 + public static final int TEXT_SMALL = 0; // 小号文本 + public static final int TEXT_MEDIUM = 1; // 中号文本 + public static final int TEXT_LARGE = 2; // 大号文本 + public static final int TEXT_SUPER = 3; // 超大号文本 + // 默认文本大小为中号 public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; + /** + * 笔记编辑界面背景资源内部类 + * 管理笔记编辑时的背景和标题背景资源 + */ public static class NoteBgResources { + // 笔记编辑背景资源数组,对应不同颜色 private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, R.drawable.edit_blue, @@ -48,6 +62,7 @@ public class ResourceParser { R.drawable.edit_red }; + // 笔记编辑标题背景资源数组,对应不同颜色 private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { R.drawable.edit_title_yellow, R.drawable.edit_title_blue, @@ -56,25 +71,48 @@ public class ResourceParser { R.drawable.edit_title_red }; + /** + * 获取指定颜色的笔记编辑背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } + /** + * 获取指定颜色的笔记编辑标题背景资源ID + * @param id 颜色ID + * @return 标题背景资源ID + */ public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } + /** + * 获取默认背景ID + * 根据用户偏好设置决定返回随机背景还是默认背景 + * @param context 上下文 + * @return 背景ID + */ public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { + // 如果用户开启了随机背景选项,返回随机颜色ID return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length); } else { + // 否则返回默认黄色背景ID return BG_DEFAULT_COLOR; } } + /** + * 笔记列表项背景资源内部类 + * 管理笔记在列表中显示时的各种背景资源 + */ public static class NoteItemBgResources { + // 列表首项背景资源数组,对应不同颜色 private final static int [] BG_FIRST_RESOURCES = new int [] { R.drawable.list_yellow_up, R.drawable.list_blue_up, @@ -83,6 +121,7 @@ public class ResourceParser { R.drawable.list_red_up }; + // 列表中间项背景资源数组,对应不同颜色 private final static int [] BG_NORMAL_RESOURCES = new int [] { R.drawable.list_yellow_middle, R.drawable.list_blue_middle, @@ -91,6 +130,7 @@ public class ResourceParser { R.drawable.list_red_middle }; + // 列表末项背景资源数组,对应不同颜色 private final static int [] BG_LAST_RESOURCES = new int [] { R.drawable.list_yellow_down, R.drawable.list_blue_down, @@ -99,6 +139,7 @@ public class ResourceParser { R.drawable.list_red_down, }; + // 列表单项背景资源数组,对应不同颜色 private final static int [] BG_SINGLE_RESOURCES = new int [] { R.drawable.list_yellow_single, R.drawable.list_blue_single, @@ -107,28 +148,57 @@ public class ResourceParser { R.drawable.list_red_single }; + /** + * 获取指定颜色的列表首项背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } + /** + * 获取指定颜色的列表末项背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } + /** + * 获取指定颜色的列表单项背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } + /** + * 获取指定颜色的列表中间项背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } + /** + * 获取文件夹背景资源ID + * @return 文件夹背景资源ID + */ public static int getFolderBgRes() { return R.drawable.list_folder; } } + /** + * 桌面小部件背景资源内部类 + * 管理不同尺寸桌面小部件的背景资源 + */ public static class WidgetBgResources { + // 2x尺寸小部件背景资源数组,对应不同颜色 private final static int [] BG_2X_RESOURCES = new int [] { R.drawable.widget_2x_yellow, R.drawable.widget_2x_blue, @@ -137,10 +207,16 @@ public class ResourceParser { R.drawable.widget_2x_red, }; + /** + * 获取指定颜色的2x尺寸小部件背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } + // 4x尺寸小部件背景资源数组,对应不同颜色 private final static int [] BG_4X_RESOURCES = new int [] { R.drawable.widget_4x_yellow, R.drawable.widget_4x_blue, @@ -149,12 +225,22 @@ public class ResourceParser { R.drawable.widget_4x_red }; + /** + * 获取指定颜色的4x尺寸小部件背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getWidget4xBgResource(int id) { return BG_4X_RESOURCES[id]; } } + /** + * 文本样式资源内部类 + * 管理不同文本大小的样式资源 + */ public static class TextAppearanceResources { + // 文本样式资源数组,对应不同文本大小 private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { R.style.TextAppearanceNormal, R.style.TextAppearanceMedium, @@ -162,20 +248,31 @@ public class ResourceParser { R.style.TextAppearanceSuper }; + /** + * 获取指定文本大小的样式资源ID + * 包含对异常情况的处理,防止资源ID越界 + * @param id 文本大小ID + * @return 样式资源ID + */ public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference. * The id may larger than the length of resources, in this case, * return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE} */ + // 处理可能的资源ID越界问题,当ID超出数组大小时返回默认文本大小 if (id >= TEXTAPPEARANCE_RESOURCES.length) { return BG_DEFAULT_FONT_SIZE; } return TEXTAPPEARANCE_RESOURCES[id]; } + /** + * 获取文本样式资源数组的大小 + * @return 资源数组大小 + */ public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; } } -} +} \ No newline at end of file