diff --git a/src/mi_note/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/mi_note/app/src/main/java/net/micode/notes/model/WorkingNote.java index 714683d..9236f2b 100644 --- a/src/mi_note/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/mi_note/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -56,10 +56,10 @@ public class WorkingNote { // 便签的背景颜色 private int mBgColorId; - // 便签的小组件ID + // 便签的小部件ID private int mWidgetId; - // 便签的小组件类型 + // 便签的小部件类型 private int mWidgetType; // 便签所处的文件夹ID @@ -461,12 +461,12 @@ public class WorkingNote { return mFolderId; } - // 获取小组件ID + // 获取小部件ID public int getWidgetId() { return mWidgetId; } - // 获取小组件类型 + // 获取小部件类型 public int getWidgetType() { return mWidgetType; } @@ -489,7 +489,7 @@ public class WorkingNote { /** * Call when user create note from widget - * 用户从小组件创建便签时被调用 + * 用户从小部件创建便签时被调用 */ void onWidgetChanged(); diff --git a/src/mi_note/app/src/main/java/net/micode/notes/tool/DataUtils.java b/src/mi_note/app/src/main/java/net/micode/notes/tool/DataUtils.java index 2a14982..28a7a9e 100644 --- a/src/mi_note/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/src/mi_note/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -34,9 +34,21 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; - +/** + * @author hzx + * 版本:1.0 + * 创建日期:2023/10/29 + * 描述:DataUtils 数据处理工具类 + */ public class DataUtils { public static final String TAG = "DataUtils"; + + /** + * 批量删除便签 + * @param resolver 内容解析器 + * @param ids 便签ID集合 + * @return 是否成功 + */ public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -47,19 +59,26 @@ public class DataUtils { return true; } + // 内容操作列表 ArrayList operationList = new ArrayList(); + // 遍历便签ID集合 for (long id : ids) { - if(id == Notes.ID_ROOT_FOLDER) { + if(id == Notes.ID_ROOT_FOLDER) { // 如果是根文件夹 + // 根文件夹不能被删除 Log.e(TAG, "Don't delete system folder root"); continue; } + // 创建一个删除操作 ContentProviderOperation.Builder builder = ContentProviderOperation .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()); return false; } @@ -67,6 +86,7 @@ public class DataUtils { } catch (RemoteException e) { Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } catch (OperationApplicationException e) { + // 执行删除操作发生错误 Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } return false; diff --git a/src/mi_note/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/src/mi_note/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java index 666b729..2ee1a07 100644 --- a/src/mi_note/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/mi_note/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java @@ -16,6 +16,12 @@ package net.micode.notes.tool; +/** + * @author hzx + * 版本:1.0 + * 创建日期:2023/10/29 + * 描述:GTaskStringUtils google账号同步的字符串工具类,封装一些字符串常量 + */ public class GTaskStringUtils { public final static String GTASK_JSON_ACTION_ID = "action_id"; diff --git a/src/mi_note/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/src/mi_note/app/src/main/java/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..b62f8eb 100644 --- a/src/mi_note/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/src/mi_note/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -22,24 +22,43 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; +/** + * @author hzx + * 版本:1.0 + * 创建日期:2023/10/29 + * 描述:ResourceParser 资源解析器 + * 封装了一些颜色和字体大小常量,能够通过颜色或字体大小ID获取资源ID + */ 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; + // 默认的颜色 黄色 0 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; + // 默认的字体大小 中等 1 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 +67,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 +76,39 @@ public class ResourceParser { R.drawable.edit_title_red }; + // 根据背景颜色ID获取便签背景资源ID public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } + // 根据背景颜色ID获取便签标题背景资源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 +117,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 +126,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 +135,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 +144,37 @@ public class ResourceParser { R.drawable.list_red_single }; + // 根据背景颜色ID获取开头背景资源ID public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } + // 根据背景颜色ID获取结尾背景资源ID public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } + // 根据背景颜色ID获取单独的背景资源ID public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } + // 根据背景颜色ID获取普通背景资源ID public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } + // 获取文件夹背景资源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 +183,12 @@ public class ResourceParser { R.drawable.widget_2x_red, }; + // 根据背景颜色ID获取小部件背景资源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 +197,17 @@ public class ResourceParser { R.drawable.widget_4x_red }; + // 根据背景颜色ID获取小部件背景资源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,18 +215,21 @@ public class ResourceParser { R.style.TextAppearanceSuper }; + // 根据字体大小ID获取字体资源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} */ + // 防止数组索引越界 if (id >= TEXTAPPEARANCE_RESOURCES.length) { return BG_DEFAULT_FONT_SIZE; } return TEXTAPPEARANCE_RESOURCES[id]; } + // 获取字体资源数组的长度 public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; } diff --git a/src/mi_note/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png b/src/mi_note/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png index bf8f580..3fb224f 100644 Binary files a/src/mi_note/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png and b/src/mi_note/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png differ