From 2c9401767f76562d07935330c56c841b937893a4 Mon Sep 17 00:00:00 2001 From: liuyuxia <13337357913@qq.com> Date: Fri, 10 Jan 2025 09:01:41 +0800 Subject: [PATCH] liuyuxia --- .../net/micode/notes/tool/BackupUtils.java | 589 ++---------------- src/java/net/micode/notes/tool/DataUtils.java | 477 +------------- .../micode/notes/tool/GTaskStringUtils.java | 212 +++++-- .../net/micode/notes/tool/ResourceParser.java | 370 ++++------- 4 files changed, 327 insertions(+), 1321 deletions(-) diff --git a/src/java/net/micode/notes/tool/BackupUtils.java b/src/java/net/micode/notes/tool/BackupUtils.java index 8aaa2d8..a86eca1 100644 --- a/src/java/net/micode/notes/tool/BackupUtils.java +++ b/src/java/net/micode/notes/tool/BackupUtils.java @@ -14,468 +14,7 @@ * limitations under the License. */ -<<<<<<< HEAD package net.micode.notes.tool; -======= - -/** - * - * @ProjectName: minode - * @Package: net.micode.notes.data - * @ClassName: BackupUtils - * @Description: 该类用于备份笔记数据到文本文件。它定义了备份状态码、单例模 - 式的实现、外部存储可用性检查、导出到文本文件的方法等。通过该类, - 可以方便地将笔记数据备份到外部存储的文本文件中。 - * @Author: 齐景熙 - */ - - - package net.micode.notes.tool; - - public class BackupUtils { - private static final String TAG = "BackupUtils"; - // Singleton stuff - private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象? - - - /** - * @method getInstance - * @description 获取 BackupUtils 的单例实例。如果实例不存在,则创建一个新的实例;否则,返回已存在的实例。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -返回值:BackupUtils 的单例实例。 */ - - public static synchronized BackupUtils getInstance(Context context) { - //ynchronized 关键字,代表这个方法加锁,相当于不管哪一个线程(例如线程A) - //运行到这个方法时,都要检查有没有其它线程B(或者C、 D等)正在用这个方法(或者该类的其他同步方法),有的话要等正在使用synchronized方法的线程B(或者C 、D)运行完这个方法后再运行此线程A,没有的话,锁定调用者,然后直接运行。 - //它包括两种用法:synchronized 方法和 synchronized 块。 - if (sInstance == null) { - //如果当前备份不存在,则新声明一个 - sInstance = new BackupUtils(context); - } - return sInstance; - } - - /** - * Following states are signs to represents backup or restore - * status - */ - // Currently, the sdcard is not mounted SD卡没有被装入手机 - public static final int STATE_SD_CARD_UNMOUONTED = 0; - // The backup file not exist 备份文件夹不存在 - public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; - // The data is not well formated, may be changed by other programs 数据已被破坏,可能被修改 - public static final int STATE_DATA_DESTROIED = 2; - // Some run-time exception which causes restore or backup fails 超时异常 - public static final int STATE_SYSTEM_ERROR = 3; - // Backup or restore success 成功存储 - public static final int STATE_SUCCESS = 4; - - private TextExport mTextExport; - - private BackupUtils(Context context) { //初始化函数 - mTextExport = new TextExport(context); - } - -/** - * @method externalStorageAvailable - * @description 检查外部存储是否可用。通过比较外部存储状态与 Environment.MEDIA_MOUNTED,判断外部存储是否已挂载。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -返回值:BackupUtils 的单例实例。 -功能介绍:检查外部存储是否可用。通过比较外部存储状态与 Environment.MEDIA_MOUNTED,判断外部存储是否已挂载。 -返回值:true 表示外部存储可用,false 表示不可用。 */ - - private static boolean externalStorageAvailable() { //外部存储功能是否可用 - return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); - } - - /** - * @method exportToText - * @description 导出笔记数据到文本文件。调用 TextExport 类的 exportToText 方法,将笔记数据导出到文本文件,并返回导出状态码。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -返回值:BackupUtils 的单例实例。 -功能介绍:导出笔记数据到文本文件。调用 TextExport 类的 exportToText 方法,将笔记数据导出到文本文件,并返回导出状态码。 -返回值:导出状态码,如 STATE_SUCCESS 表示成功,STATE_SD_CARD_UNMOUONTED 表示外部存储未挂载等。*/ - - public int exportToText() { - return mTextExport.exportToText(); - } - - /** - * @method getExportedTextFileName - * @description 获取导出的文本文件名。返回 TextExport 类中保存的导出文本文件名。 - 导出笔记数据到文本文件。调用 TextExport 类的 exportToText 方法,将笔记数据导出到文本文件,并返回导出状态码。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -返回值:BackupUtils 的单例实例。 -功能介绍:导出笔记数据到文本文件。调用 TextExport 类的 exportToText 方法,将笔记数据导出到文本文件,并返回导出状态码。 -返回值:导出状态码,如 STATE_SUCCESS 表示成功,STATE_SD_CARD_UNMOUONTED 表示外部存储未挂载等。 -功能介绍:获取导出的文本文件名。返回 TextExport 类中保存的导出文本文件名。 -返回值:导出的文本文件名。*/ - - public String getExportedTextFileName() { - return mTextExport.mFileName; - } - - /** - * @method getExportedTextFileDir - * @description 获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 - 导出笔记数据到文本文件。调用 TextExport 类的 exportToText 方法,将笔记数据导出到文本文件,并返回导出状态码。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -功能介绍:获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 -返回值:导出的文本文件目录。 -返回值:导出状态码,如 STATE_SUCCESS 表示成功,STATE_SD_CARD_UNMOUONTED 表示外部存储未挂载等。 -功能介绍:获取导出的文本文件名。返回 TextExport 类中保存的导出文本文件名。 -返回值:导出的文本文件名。*/ - public String getExportedTextFileDir() { - return mTextExport.mFileDirectory; - } - - private static class TextExport { - private static final String[] NOTE_PROJECTION = { - NoteColumns.ID, - NoteColumns.MODIFIED_DATE, - NoteColumns.SNIPPET, - NoteColumns.TYPE - }; - - private static final int NOTE_COLUMN_ID = 0; - - private static final int NOTE_COLUMN_MODIFIED_DATE = 1; - - private static final int NOTE_COLUMN_SNIPPET = 2; - - private static final String[] DATA_PROJECTION = { - DataColumns.CONTENT, - DataColumns.MIME_TYPE, - DataColumns.DATA1, - DataColumns.DATA2, - DataColumns.DATA3, - DataColumns.DATA4, - }; - - private static final int DATA_COLUMN_CONTENT = 0; - - private static final int DATA_COLUMN_MIME_TYPE = 1; - - private static final int DATA_COLUMN_CALL_DATE = 2; - - private static final int DATA_COLUMN_PHONE_NUMBER = 4; - - private final String [] TEXT_FORMAT; - private static final int FORMAT_FOLDER_NAME = 0; - private static final int FORMAT_NOTE_DATE = 1; - private static final int FORMAT_NOTE_CONTENT = 2; - - private Context mContext; - private String mFileName; - private String mFileDirectory; - - - /** - * @method getExportedTextFileDir - * @description 该内部类用于将笔记数据导出到文本文件。它定义了导出所需的列、格式、文件名、文件目录等,并实现了导出笔记数据到文本文件的具体逻辑。 - 获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 - 导出笔记数据到文本文件。调用 TextExport 类的 exportToText 方法,将笔记数据导出到文本文件,并返回导出状态码。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -功能介绍:获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 -返回值:导出的文本文件目录。 -返回值:导出状态码,如 STATE_SUCCESS 表示成功,STATE_SD_CARD_UNMOUONTED 表示外部存储未挂载等。 -该内部类用于将笔记数据导出到文本文件。它定义了导出所需的列、格式、文件名、文件目录等,并实现了导出笔记数据到文本文件的具体逻辑。*/ - public TextExport(Context context) { - TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); - mContext = context; - mFileName = ""; //为什么为空? - mFileDirectory = ""; - } - - /** - * @method getFormat - * @description 获取导出格式字符串。根据传入的格式 ID,从 TEXT_FORMAT 数组中获取对应的格式字符串 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -功能介绍:获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 -返回值:导出的文本文件目录。 -功能介绍:获取导出格式字符串。根据传入的格式 ID,从 TEXT_FORMAT 数组中获取对应的格式字符串。 -参数: -id:格式 ID。 -返回值:对应的格式字符串。 -返回值:导出状态码,如 STATE_SUCCESS 表示成功,STATE_SD_CARD_UNMOUONTED 表示外部存储未挂载等。 -该内部类用于将笔记数据导出到文本文件。它定义了导出所需的列、格式、文件名、文件目录等,并实现了导出笔记数据到文本文件的具体逻辑。*/ - private String getFormat(int id) { //获取文本的组成部分 - return TEXT_FORMAT[id]; - } - - /** - * Export the folder identified by folder id to text - */ - private void exportFolderToText(String folderId, PrintStream ps) { - // Query notes belong to this folder 通过查询parent id是文件夹id的note来选出制定ID文件夹下的Note - Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { - folderId - }, null); - - if (notesCursor != null) { - if (notesCursor.moveToFirst()) { - do { - // Print note's last modified date ps里面保存有这份note的日期 - ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( - mContext.getString(R.string.format_datetime_mdhm), - notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note - String noteId = notesCursor.getString(NOTE_COLUMN_ID); - exportNoteToText(noteId, ps); //将文件导出到text - } while (notesCursor.moveToNext()); - } - notesCursor.close(); - } - } - - /** - * Export note identified by id to a print stream - */ - private void exportNoteToText(String noteId, PrintStream ps) { - Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, - DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { - noteId - }, null); - - if (dataCursor != null) { //利用光标来扫描内容,区别为callnote和note两种,靠ps.printline输出 - if (dataCursor.moveToFirst()) { - do { - String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); - if (DataConstants.CALL_NOTE.equals(mimeType)) { - // Print phone number - String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); - long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); - String location = dataCursor.getString(DATA_COLUMN_CONTENT); - - if (!TextUtils.isEmpty(phoneNumber)) { //判断是否为空字符 - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - phoneNumber)); - } - // Print call date - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat - .format(mContext.getString(R.string.format_datetime_mdhm), - callDate))); - // Print call attachment location - if (!TextUtils.isEmpty(location)) { - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - location)); - } - } else if (DataConstants.NOTE.equals(mimeType)) { - String content = dataCursor.getString(DATA_COLUMN_CONTENT); - if (!TextUtils.isEmpty(content)) { - ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - content)); - } - } - } while (dataCursor.moveToNext()); - } - dataCursor.close(); - } - // print a line separator between note - try { - ps.write(new byte[] { - Character.LINE_SEPARATOR, Character.LETTER_NUMBER - }); - } catch (IOException e) { - Log.e(TAG, e.toString()); - } - } - - /** - * Note will be exported as text which is user readable - */ - -/** - * @method exportToText - * @description 导出指定笔记到文本文件。查询属于该笔记的数据,根据数据的 MIME 类型,将数据内容(如电话号码、通话日期、文本内容等)格式化后输出到文本文件。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -功能介绍:获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 -功能介绍:导出笔记数据到文本文件。检查外部存储是否可用,然后获取打印流,依次导出文件夹和笔记到文本文件。 -返回值:导出状态码 -noteId:笔记 ID。 -ps:打印流,用于输出到文本文件。 -返回值:导出状态码,如 STATE_SUCCESS 表示成功,STATE_SD_CARD_UNMOUONTED 表示外部存储未挂载等。 -该内部类用于将笔记数据导出到文本文件。它定义了导出所需的列、格式、文件名、文件目录等,并实现了导出笔记数据到文本文件的具体逻辑。*/ - public int exportToText() { //总函数,调用上面的exportFolder和exportNote - if (!externalStorageAvailable()) { - Log.d(TAG, "Media was not mounted"); - return STATE_SD_CARD_UNMOUONTED; - } - - PrintStream ps = getExportToTextPrintStream(); - if (ps == null) { - Log.e(TAG, "get print stream error"); - return STATE_SYSTEM_ERROR; - } - // First export folder and its notes 导出文件夹,就是导出里面包含的便签 - Cursor folderCursor = mContext.getContentResolver().query( - Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, - "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " - + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " - + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); - - if (folderCursor != null) { - if (folderCursor.moveToFirst()) { - do { - // Print folder's name - String folderName = ""; - if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { - folderName = mContext.getString(R.string.call_record_folder_name); - } else { - folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); - } - if (!TextUtils.isEmpty(folderName)) { - ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); - } - String folderId = folderCursor.getString(NOTE_COLUMN_ID); - exportFolderToText(folderId, ps); - } while (folderCursor.moveToNext()); - } - folderCursor.close(); - } - - // Export notes in root's folder 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出) - Cursor noteCursor = mContext.getContentResolver().query( - Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, - NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID - + "=0", null, null); - - if (noteCursor != null) { - if (noteCursor.moveToFirst()) { - do { - ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( - mContext.getString(R.string.format_datetime_mdhm), - noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note - String noteId = noteCursor.getString(NOTE_COLUMN_ID); - exportNoteToText(noteId, ps); - } while (noteCursor.moveToNext()); - } - noteCursor.close(); - } - ps.close(); - - return STATE_SUCCESS; - } - - /** - * Get a print stream pointed to the file {@generateExportedTextFile} - */ - - - -/** - * @method getExportToTextPrintStream - * @description 获取指向导出文本文件的打印流。生成导出文本文件,然后创建指向该文件的打印流。 - * @author: 齐景熙 - */ - /*参数: -context:上下文对象,用于访问应用程序的资源和功能。 -功能介绍:获取导出的文本文件目录。返回 TextExport 类中保存的导出文本文件目录。 -功能介绍:导出笔记数据到文本文件。检查外部存储是否可用,然后获取打印流,依次导出文件夹和笔记到文本文件。 -返回值:导出状态码 -noteId:笔记 ID。 -ps:打印流,用于输出到文本文件。 -功能介绍:获取指向导出文本文件的打印流。生成导出文本文件,然后创建指向该文件的打印流。 -返回值:打印流,用于输出到文本文件。*/ - - private PrintStream getExportToTextPrintStream() { - File file = generateFileMountedOnSDcard(mContext, R.string.file_path, - R.string.file_name_txt_format); - if (file == null) { - Log.e(TAG, "create file to exported failed"); - return null; - } - mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); - PrintStream ps = null; - try { - FileOutputStream fos = new FileOutputStream(file); - ps = new PrintStream(fos); //将ps输出流输出到特定的文件,目的就是导出到文件,而不是直接输出 - } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; - } catch (NullPointerException e) { - e.printStackTrace(); - return null; - } - return ps; - } - } - - /** - * Generate the text file to store imported data - */ - -/** - * @method generateFileMountedOnSDcard - * @description 生成导出文本文件。根据传入的文件路径和文件名格式资源 ID,生成导出文本文件的完整路径,并创建该文件。 - * @author: 齐景熙 - */ - /*参数: -功能介绍:生成导出文本文件。根据传入的文件路径和文件名格式资源 ID,生成导出文本文件的完整路径,并创建该文件。 -参数: -context:上下文对象,用于访问应用程序的资源。 -filePathResId:文件路径资源 ID。 -fileNameFormatResId:文件名格式资源 ID。 -返回值:生成的导出文本文件对象。*/ - private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { - StringBuilder sb = new StringBuilder(); - sb.append(Environment.getExternalStorageDirectory()); //外部(SD卡)的存储路径 - sb.append(context.getString(filePathResId)); //文件的存储路径 - File filedir = new File(sb.toString()); //filedir应该就是用来存储路径信息 - sb.append(context.getString( - fileNameFormatResId, - DateFormat.format(context.getString(R.string.format_date_ymd), - System.currentTimeMillis()))); - File file = new File(sb.toString()); - - try { //如果这些文件不存在,则新建 - if (!filedir.exists()) { - filedir.mkdir(); - } - if (!file.exists()) { - file.createNewFile(); - } - return file; - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - // try catch 异常处理 - return null; - } - } - ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 import android.content.Context; import android.database.Cursor; @@ -727,7 +266,7 @@ public class BackupUtils { + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); if (folderCursor != null) { - if (folderCursor.moveToFirst( ) { + if (folderCursor.moveToFirst()) { do { // 打印文件夹名称 String folderName = ""; @@ -759,78 +298,78 @@ public class BackupUtils { ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( mContext.getString(R.string.format_datetime_mdhm), noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // 查询属于该便签的数据 + // 查询 + // 属于该便签的数据 String noteId = noteCursor.getString(NOTE_COLUMN_ID); exportNoteToText(noteId, ps); - } while (noteCursor.moveToNext()); - } - noteCursor.close(); - } - ps.close(); - - return STATE_SUCCESS; - } + } while (noteCursor.moveToNext()); + } + noteCursor.close(); + } + ps.close(); - /** - * 获取指向导出文本文件的输出流。 - * @return 输出流 - */ - private PrintStream getExportToTextPrintStream() { - File file = generateFileMountedOnSDcard(mContext, R.string.file_path, - R.string.file_name_txt_format); - if (file == null) { - Log.e(TAG, "create file to exported failed"); - return null; - } - mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); - PrintStream ps = null; - try { - FileOutputStream fos = new FileOutputStream(file); - ps = new PrintStream(fos); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; - } catch (NullPointerException e) { - e.printStackTrace(); - return null; - } - return ps; - } + return STATE_SUCCESS; } /** - * 在SD卡上生成用于存储导出数据的文本文件。 - * @param context 上下文 - * @param filePathResId 文件路径资源ID - * @param fileNameFormatResId 文件名格式资源ID - * @return 文件对象 + * 获取指向导出文本文件的输出流。 + * @return 输出流 */ - private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { - StringBuilder sb = new StringBuilder(); - sb.append(Environment.getExternalStorageDirectory()); // 外部(SD卡)的存储路径 - sb.append(context.getString(filePathResId)); // 文件的存储路径 - File filedir = new File(sb.toString()); // filedir用于存储路径信息 - sb.append(context.getString( - fileNameFormatResId, - DateFormat.format(context.getString(R.string.format_date_ymd), - System.currentTimeMillis()))); - File file = new File(sb.toString()); - - try { // 如果这些文件不存在,则新建 - if (!filedir.exists()) { - filedir.mkdir(); - } - if (!file.exists()) { - file.createNewFile(); - } - return file; - } catch (SecurityException e) { + private PrintStream getExportToTextPrintStream() { + File file = generateFileMountedOnSDcard(mContext, R.string.file_path, + R.string.file_name_txt_format); + if (file == null) { + Log.e(TAG, "create file to exported failed"); + return null; + } + mFileName = file.getName(); + mFileDirectory = mContext.getString(R.string.file_path); + PrintStream ps = null; + try { + FileOutputStream fos = new FileOutputStream(file); + ps = new PrintStream(fos); + } catch (FileNotFoundException e) { e.printStackTrace(); - } catch (IOException e) { + return null; + } catch (NullPointerException e) { e.printStackTrace(); + return null; + } + return ps; + } +} + +/** + * 在SD卡上生成用于存储导出数据的文本文件。 + * @param context 上下文 + * @param filePathResId 文件路径资源ID + * @param fileNameFormatResId 文件名格式资源ID + * @return 文件对象 + */ +private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { + StringBuilder sb = new StringBuilder(); + sb.append(Environment.getExternalStorageDirectory()); // 外部(SD卡)的存储路径 + sb.append(context.getString(filePathResId)); // 文件的存储路径 + File filedir = new File(sb.toString()); // filedir用于存储路径信息 + sb.append(context.getString( + fileNameFormatResId, + DateFormat.format(context.getString(R.string.format_date_ymd), + System.currentTimeMillis()))); // 构建文件名,包含日期信息 + File file = new File(sb.toString()); + + try { // 如果这些文件不存在,则新建 + if (!filedir.exists()) { + filedir.mkdir(); + } + if (!file.exists()) { + file.createNewFile(); } - // 异常处理 - return null; + return file; + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); } + // 异常处理 + return null; } \ No newline at end of file diff --git a/src/java/net/micode/notes/tool/DataUtils.java b/src/java/net/micode/notes/tool/DataUtils.java index b9ea655..ebce19a 100644 --- a/src/java/net/micode/notes/tool/DataUtils.java +++ b/src/java/net/micode/notes/tool/DataUtils.java @@ -13,33 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -<<<<<<< HEAD -======= -/*该类定义在 net.micode.notes.tool 包下,并导入了Android和Java的一些核心类。这些导入的类提供了对内容提供者操作、日志记录、游标以及存储值的支持。 */ - - - - - /** - * - * @ProjectName: minode - * @Package: net.micode.notes.data - * @ClassName: DataUtils - * @Description: 该类提供了一系列与笔记数据操作相关的工具方法。它包含了批量删除笔记、移动笔记到文件夹、 - 获取用户文件夹数量、检查笔记或数据是否存在、获取通话记录号码、获取笔记摘要等功能。通过 - 这些方法,可以方便地对笔记数据进行批量操作和查询。 - * @Author: 齐景熙 - */ - -/*主要成员变量和常量: -DB_NAME:数据库的名称。 -DB_VERSION:数据库的版本号。 -TABLE:定义了数据库表名的接口。 -TAG:用于日志记录的标签。 -mInstance:用于实现单例模式的静态实例变量。 -CREATE_NOTE_TABLE_SQL、CREATE_DATA_TABLE_SQL 等:创建笔记表和数据表的 SQL 语句。 -NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER 等:定义了数据库触发器的 SQL 语句,用于在特定操作后自动更新数据。 */ ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 package net.micode.notes.tool; import android.content.ContentProviderOperation; @@ -60,38 +33,16 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; -<<<<<<< HEAD /** * DataUtils 类提供了一系列用于操作便签数据的工具方法。 * 包括批量删除便签、移动便签、查询便签等。 */ -======= -/*这个方法实现了根据一组ID批量删除笔记的功能。 -它首先检查ID集合是否为空,并创建一个操作列表。 -通过 ContentResolver 执行删除操作,成功后返回 true,失败则返回 false。 */ - - /** - * @method batchDeleteNotes - * @description 批量删除笔记。根据传入的笔记 ID 集合,构建批量删除操 - 作的 ContentProviderOperation 列表,然后通过 ContentResolver - 的 applyBatch 方法执行批量删除操作。如果删除操作成功,返回 true;否则,返回 false。 - * @author: 齐景熙 - */ - -/* -功能介绍:批量删除笔记。根据传入的笔记 ID 集合,构建批量删除操作的 ContentProviderOperation 列表,然后通过 ContentResolver -的 applyBatch 方法执行批量删除操作。如果删除操作成功,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -ids:要删除的笔记 ID 集合。 -返回值:true 表示删除成功,false 表示删除失败。 */ ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 public class DataUtils { public static final String TAG = "DataUtils"; /** * 批量删除便签。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param ids 需要删除的便签ID集合 * @return 删除成功返回true,否则返回false */ @@ -129,40 +80,14 @@ public class DataUtils { } return false; } -<<<<<<< HEAD /** * 将便签移动到指定文件夹。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param id 便签ID * @param srcFolderId 源文件夹ID * @param desFolderId 目标文件夹ID */ -======= -/*此方法将指定的笔记移动到目标文件夹。 -更新笔记的父文件夹ID并标记为本地修改。 */ -/*查询非系统文件夹的数量。异常处理用于确保在查询失败时释放游标资源。 */ - -/*这个方法实现了根据一组ID批量删除笔记的功能。 -它首先检查ID集合是否为空,并创建一个操作列表。 -通过 ContentResolver 执行删除操作,成功后返回 true,失败则返回 false。 */ - - /** - * @method moveNoteToFoler - * @description 将笔记移动到指定文件夹。根据传入的笔记 ID、源文件夹 ID 和目标文件夹 ID,更新笔记的父 ID、原始父 ID - 和本地修改标志。通过 ContentResolver 的 update 方法执行更新操作。 - * @author: 齐景熙 - */ - -/* -功能介绍:将笔记移动到指定文件夹。根据传入的笔记 ID、源文件夹 ID 和目标文件夹 ID,更新笔记的父 ID、原始父 ID -和本地修改标志。通过 ContentResolver 的 update 方法执行更新操作。 -参数: -resolver:内容解析器,用于访问内容提供者。 -id:要移动的笔记 ID。 -srcFolderId:源文件夹 ID。 -desFolderId:目标文件夹 ID*/ ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { ContentValues values = new ContentValues(); values.put(NoteColumns.PARENT_ID, desFolderId); @@ -171,10 +96,9 @@ desFolderId:目标文件夹 ID*/ resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } -<<<<<<< HEAD /** * 批量将便签移动到指定文件夹。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param ids 需要移动的便签ID集合 * @param folderId 目标文件夹ID * @return 移动成功返回true,否则返回false @@ -184,29 +108,6 @@ desFolderId:目标文件夹 ID*/ Log.d(TAG, "the ids is null"); return true; } -======= - - /** - * @method batchMoveToFolder - * @description 批量移动笔记到指定文件夹。根据传入的笔记 ID 集合和目标文件夹 ID,构建批量更新操作的 ContentProviderOperation - 列表,然后通过 ContentResolver 的 applyBatch 方法执行批量更新操作。如果移动操作成功,返回 true;否则,返回 false。 - * @author: 齐景熙 - */ - -/* -功能介绍:批量移动笔记到指定文件夹。根据传入的笔记 ID 集合和目标文件夹 ID,构建批量更新操作的 ContentProviderOperation -列表,然后通过 ContentResolver 的 applyBatch 方法执行批量更新操作。如果移动操作成功,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -ids:要移动的笔记 ID 集合。 -folderId:目标文件夹 ID。 -返回值:true 表示移动成功,false 表示移动失败。*/ -public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { - if (ids == null) { - Log.d(TAG, "the ids is null"); - return true; - } ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 ArrayList operationList = new ArrayList(); for (long id : ids) { @@ -232,10 +133,9 @@ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet return false; } -<<<<<<< HEAD /** * 获取用户文件夹的数量(不包括系统文件夹)。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @return 用户文件夹的数量 */ public static int getUserFolderCount(ContentResolver resolver) { @@ -244,32 +144,6 @@ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLDER)}, null); -======= -/** - * 获取用户文件夹的数量(不包括系统文件夹) - * @param resolver ContentResolver对象 - * @return 用户文件夹的数量 - */ - - /** - * @method getUserFolderCount - * @description 获取用户文件夹数量。查询笔记表,统计类型为文件夹且父 ID 不等于回收站文件夹 ID 的笔记数量。返回查询结果中的数量。 - * @author: 齐景熙 - */ - -/* -方法 getUserFolderCount(ContentResolver resolver) -功能介绍:获取用户文件夹数量。查询笔记表,统计类型为文件夹且父 ID 不等于回收站文件夹 ID 的笔记数量。返回查询结果中的数量。 -参数: -resolver:内容解析器,用于访问内容提供者。 -返回值:用户文件夹数量。*/ -public static int getUserFolderCount(ContentResolver resolver) { - Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, - new String[] { "COUNT(*)" }, - NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", - new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, - null); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 int count = 0; if(cursor != null) { @@ -286,10 +160,9 @@ public static int getUserFolderCount(ContentResolver resolver) { return count; } -<<<<<<< HEAD /** * 检查数据库中是否存在指定ID和类型的便签。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param noteId 便签ID * @param type 便签类型 * @return 存在返回true,否则返回false @@ -300,35 +173,6 @@ public static int getUserFolderCount(ContentResolver resolver) { NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLDER, new String [] {String.valueOf(type)}, null); -======= -/** - * 检查数据库中是否存在指定ID和类型的便签 - * @param resolver ContentResolver对象 - * @param noteId 便签ID - * @param type 便签类型 - * @return 是否存在 - */ - - /** - * @method visibleInNoteDatabase - * @description 检查指定类型的笔记是否存在。根据传入的笔记 ID 和类型,查询笔记表,检查是否存在符合条件的笔记。如果存在,返回 true;否则,返回 false。 - * @author: 齐景熙 - */ - -/* -功能介绍:检查指定类型的笔记是否存在。根据传入的笔记 ID 和类型,查询笔记表,检查是否存在符合条件的笔记。如果存在,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -noteId:要检查的笔记 ID。 -type:笔记类型。 -返回值:true 表示笔记存在,false 表示笔记不存在。*/ -public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), - null, - NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, - new String [] {String.valueOf(type)}, - null); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 boolean exist = false; if (cursor != null) { @@ -340,42 +184,15 @@ public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteI return exist; } -<<<<<<< HEAD /** * 检查数据库中是否存在指定ID的便签。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @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); -======= -/** - * 检查数据库中是否存在指定ID的便签 - * @param resolver ContentResolver对象 - * @param noteId 便签ID - * @return 是否存在 - */ - - - - /** - * @method existInNoteDatabase - * @description 检查笔记是否存在。根据传入的笔记 ID,查询笔记表,检查是否存在该笔记。如果存在,返回 true;否则,返回 false。 - * @author: 齐景熙 - */ - -/* -功能介绍:检查笔记是否存在。根据传入的笔记 ID,查询笔记表,检查是否存在该笔记。如果存在,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -noteId:要检查的笔记 ID。 -返回值: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); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 boolean exist = false; if (cursor != null) { @@ -387,42 +204,15 @@ public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) return exist; } -<<<<<<< HEAD /** * 检查数据库中是否存在指定ID的数据。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @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); -======= -/** - * 检查数据库中是否存在指定ID的数据 - * @param resolver ContentResolver对象 - * @param dataId 数据ID - * @return 是否存在 - */ - - /** - * @method existInNoteDatabase - * @description 检查数据是否存在。根据传入的数据 ID,查询数据表,检查是否存在该数据。如果存在,返回 true;否则,返回 false。 - * @author: 齐景熙 - */ - -/* -功能介绍:检查数据是否存在。根据传入的数据 ID,查询数据表,检查是否存在该数据。如果存在,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -dataId:要检查的数据 ID。 -返回值: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); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 boolean exist = false; if (cursor != null) { @@ -434,10 +224,9 @@ public static boolean existInDataDatabase(ContentResolver resolver, long dataId) return exist; } -<<<<<<< HEAD /** * 检查数据库中是否存在指定名称的可见文件夹。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param name 文件夹名称 * @return 存在返回true,否则返回false */ @@ -450,55 +239,16 @@ public static boolean existInDataDatabase(ContentResolver resolver, long dataId) boolean exist = false; if(cursor != null) { if(cursor.getCount() > 0) { - - exist = true; + exist = true; } cursor.close(); -======= -/** - * 检查数据库中是否存在指定名称的可见文件夹 - * @param resolver ContentResolver对象 - * @param name 文件夹名称 - * @return 是否存在 - */ - - - /** - * @method checkVisibleFolderName - * @description 检查数据是否存在。根据传入的数据 ID,查询数据表,检查是否存在该数据。如果存在,返回 true;否则,返回 false。 - * @author: 齐景熙 - */ - -/* -功能介绍:检查数据是否存在。根据传入的数据 ID,查询数据表,检查是否存在该数据。如果存在,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -dataId:要检查的数据 ID。 -返回值:true 表示数据存在,false 表示数据不存在。功能介绍:检查可见文件夹名称是否存在。根据传入的文件夹名称,查询笔记表,检查是否存在类型为文件夹、父 ID 不等于回收站文件夹 ID 且名称等于指定名称的文件夹。如果存在,返回 true;否则,返回 false。 -参数: -resolver:内容解析器,用于访问内容提供者。 -name:要检查的文件夹名称。 -返回值:true 表示文件夹名称存在,false 表示文件夹名称不存在。 -*/ -public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, - NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + - " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + - " AND " + NoteColumns.SNIPPET + "=?", - new String[] { name }, null); - boolean exist = false; - if(cursor != null) { - if(cursor.getCount() > 0) { - exist = true; ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 } return exist; } -<<<<<<< HEAD /** * 获取指定文件夹中的小部件属性集合。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param folderId 文件夹ID * @return 小部件属性集合 */ @@ -508,37 +258,6 @@ public static boolean checkVisibleFolderName(ContentResolver resolver, String na NoteColumns.PARENT_ID + "=?", new String[] { String.valueOf(folderId) }, null); -======= -/** - * 获取指定文件夹中的小部件属性集合 - * @param resolver ContentResolver对象 - * @param folderId 文件夹ID - * @return 小部件属性集合 - */ - - /** - * @method getFolderNoteWidget - * @description 获取指定文件夹的笔记小部件属性。根据传入的文件夹 ID,查询笔记表,获取该文件夹下所有笔记的小部件 ID 和类型, - 并将它们封装成 AppWidgetAttribute 对象,存入 HashSet 中返回。 - * @author: 齐景熙 - */ - -/* -功能介绍:获取指定文件夹的笔记小部件属性。根据传入的文件夹 ID,查询笔记表,获取该文件夹下所有笔记的小部件 ID 和类型, -并将它们封装成 AppWidgetAttribute 对象,存入 HashSet 中返回。 -参数: -resolver:内容解析器,用于访问内容提供者。 -folderId:文件夹 ID。 -返回值:包含笔记小部件属性的 HashSet。 -*/ - -public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { - Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, - new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, - NoteColumns.PARENT_ID + "=?", - new String[] { String.valueOf(folderId) }, - null); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 HashSet set = null; if (c != null) { @@ -560,10 +279,9 @@ public static HashSet getFolderNoteWidget(ContentResolver re return set; } -<<<<<<< HEAD /** * 根据便签ID获取电话号码。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param noteId 便签ID * @return 电话号码 */ @@ -573,43 +291,6 @@ public static HashSet getFolderNoteWidget(ContentResolver re CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, null); -======= -/** - * 根据便签ID获取电话号码 - * @param resolver ContentResolver对象 - * @param noteId 便签ID - * @return 电话号码 - */ - - /** - * @method getCallNumberByNoteId - * @description 根据笔记 ID 获取通话记录号码。根据传入的笔记 ID,查询数据表,获取该笔记对应的通话记录号码。 - 如果查询成功且存在号码,返回号码字符串;否则,返回空字符串。 - * @author: 齐景熙 - */ - -/* -功能介绍:获取指定文件夹的笔记小部件属性。根据传入的文件夹 ID,查询笔记表,获取该文件夹下所有笔记的小部件 ID 和类型, -并将它们封装成 AppWidgetAttribute 对象,存入 HashSet 中返回。 -功能介绍:根据笔记 ID 获取通话记录号码。根据传入的笔记 ID,查询数据表,获取该笔记对应的通话记录号码。如果查询成功且存 -在号码,返回号码字符串;否则,返回空字符串。 -参数: -resolver:内容解析器,用于访问内容提供者。 -noteId:笔记 ID。 -返回值:通话记录号码字符串。 -参数: -resolver:内容解析器,用于访问内容提供者。 -folderId:文件夹 ID。 -返回值:包含笔记小部件属性的 HashSet。 -*/ - -public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.PHONE_NUMBER }, - CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", - new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, - null); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 if (cursor != null && cursor.moveToFirst()) { try { @@ -623,10 +304,9 @@ public static String getCallNumberByNoteId(ContentResolver resolver, long noteId return ""; } -<<<<<<< HEAD /** * 根据电话号码和通话日期获取便签ID。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param phoneNumber 电话号码 * @param callDate 通话日期 * @return 便签ID @@ -638,40 +318,6 @@ public static String getCallNumberByNoteId(ContentResolver resolver, long noteId + CallNote.PHONE_NUMBER + ",?)", new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, null); -======= -/** - * 根据电话号码和通话日期获取便签ID - * @param resolver ContentResolver对象 - * @param phoneNumber 电话号码 - * @param callDate 通话日期 - * @return 便签ID - */ - - /** - * @method getNoteIdByPhoneNumberAndCallDate - * @description 根据电话号码和通话日期获取笔记 ID。根据传入的电话号码和通话日期,查询数据表,获取匹配的笔记 ID。如果查询成功 - 且存在笔记 ID,返回笔记 ID;否则,返回 0。 - * @author: 齐景熙 - */ - -/* -功能介绍: -根据电话号码和通话日期获取笔记 ID。根据传入的电话号码和通话日期,查询数据表,获取匹配的笔记 ID。如果查询成功 -且存在笔记 ID,返回笔记 ID;否则,返回 0。 -参数: -resolver:内容解析器,用于访问内容提供者。 -phoneNumber:电话号码。 -callDate:通话日期。 -返回值:笔记 ID。 -*/ -public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.NOTE_ID }, - CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" - + CallNote.PHONE_NUMBER + ",?)", - new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, - null); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 if (cursor != null) { if (cursor.moveToFirst()) { @@ -686,10 +332,9 @@ public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, S return 0; } -<<<<<<< HEAD /** * 根据便签ID获取便签摘要。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param noteId 便签ID * @return 便签摘要 */ @@ -699,40 +344,6 @@ public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, S NoteColumns.ID + "=?", new String [] { String.valueOf(noteId)}, null); -======= -/** - * 根据便签ID获取便签摘要 - * @param resolver ContentResolver对象 - * @param noteId 便签ID - * @return 便签摘要 - */ - - - /** - * @method getSnippetById - * @description 根据笔记 ID 获取笔记摘要。根据传入的笔记 ID,查询笔记表,获取该笔记的摘要字符串。如果查询成功且存在摘要, - 返回摘要字符串;否则,抛出 IllegalArgumentException 异常。 - * @author: 齐景熙 - */ - -/* -功能介绍: -根据电话号码和通话日期获取笔记 ID。根据传入的电话号码和通话日期,查询数据表,获取匹配的笔记 ID。如果查询成功 -且存在笔记 ID,返回笔记 ID;否则,返回 0。 -功能介绍:根据笔记 ID 获取笔记摘要。根据传入的笔记 ID,查询笔记表,获取该笔记的摘要字符串。如果查询成功且存在摘要, -返回摘要字符串;否则,抛出 IllegalArgumentException 异常。 -参数: -resolver:内容解析器,用于访问内容提供者。 -noteId:笔记 ID。 -返回值:笔记摘要字符串。 -*/ -public static String getSnippetById(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, - new String [] { NoteColumns.SNIPPET }, - NoteColumns.ID + "=?", - new String [] { String.valueOf(noteId)}, - null); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 if (cursor != null) { String snippet = ""; @@ -745,7 +356,6 @@ public static String getSnippetById(ContentResolver resolver, long noteId) { throw new IllegalArgumentException("Note is not found with id: " + noteId); } -<<<<<<< HEAD /** * 格式化便签摘要。 * @param snippet 便签摘要 @@ -758,42 +368,13 @@ public static String getSnippetById(ContentResolver resolver, long noteId) { if (index != -1) { snippet = snippet.substring(0, index); } -======= -/** - * 格式化便签摘要 - * @param snippet 便签摘要 - * @return 格式化后的便签摘要 - */ - - /** - * @method getFormattedSnippet - * @description 格式化笔记摘要。根据传入的笔记摘要字符串,去除首尾空白字符,然后查找第一个换行符,如果存在换行符,则截取换行符之 - 前的内容作为格式化后的摘要。 - * @author: 齐景熙 - */ - -/* -功能介绍:格式化笔记摘要。根据传入的笔记摘要字符串,去除首尾空白字符,然后查找第一个换行符,如果存在换行符,则截取换行符之 -前的内容作为格式化后的摘要。 -参数: -snippet:笔记摘要字符串。 -返回值:格式化后的笔记摘要字符串。 -*/ -public static String getFormattedSnippet(String snippet) { - if (snippet != null) { - snippet = snippet.trim(); - int index = snippet.indexOf('\n'); - if (index != -1) { - snippet = snippet.substring(0, index); ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 } return snippet; } -<<<<<<< HEAD /** * 在数据库中搜索包含指定查询内容的便签。 - * @param resolver ContentResolver对象 + * @param resolver ContentResolver对象,用于与ContentProvider交互 * @param query 查询内容 * @return 包含查询结果的Cursor对象 */ @@ -805,34 +386,4 @@ public static String getFormattedSnippet(String snippet) { null); return cursor; } -======= -/** - * 在数据库中搜索包含指定查询内容的便签 - * @param resolver ContentResolver对象 - * @param query 查询内容 - * @return 包含查询结果的Cursor对象 - */ - - /** - * @method searchInNoteDatabase - * @description 在笔记数据库中搜索。根据传入的查询字符串,查询数据表,获取内容包含查询字符串的笔记 ID。返回查询结果的 Cursor 对象。 - * @author: 齐景熙 - */ - -/* -功能介绍:在笔记数据库中搜索。根据传入的查询字符串,查询数据表,获取内容包含查询字符串的笔记 ID。返回查询结果的 Cursor 对象。 -参数: -resolver:内容解析器,用于访问内容提供者。 -query:查询字符串。 -返回值:查询结果的 Cursor 对象。 -*/ - -public static Cursor searchInNoteDatabase(ContentResolver resolver, String query) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String[]{NoteColumns.ID}, - Notes.DataColumns.CONTENT + " LIKE'%" + query +"%'", - null, - null); - return cursor; ->>>>>>> 623b8465a7bfcf05a3ca2ec250315ad6977a9eb0 } \ No newline at end of file diff --git a/src/java/net/micode/notes/tool/GTaskStringUtils.java b/src/java/net/micode/notes/tool/GTaskStringUtils.java index db8e0a5..8e73488 100644 --- a/src/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/java/net/micode/notes/tool/GTaskStringUtils.java @@ -14,169 +14,245 @@ * limitations under the License. */ -/** - * - * @ProjectName: minode - * @Package: net.micode.notes.data - * @ClassName: GTaskStringUtils - * @Author: 齐景熙 - */ - /* - 文件中包含了一系列的静态常量字符串。这些常量字符串主要用于表示与 GTask(Google Tasks)相关的 JSON 键和 - 一些特定的字符串前缀。以下是对这些常量的详细功能介绍: - - 常量介绍 -GTASK JSON 键 -GTASK_JSON_ACTION_ID:用于表示 GTask 操作的 ID。 -GTASK_JSON_ACTION_LIST:用于表示 GTask 操作的列表。 -GTASK_JSON_ACTION_TYPE:用于表示 GTask 操作的类型。 -GTASK_JSON_ACTION_TYPE_CREATE:创建操作类型。 -GTASK_JSON_ACTION_TYPE_GETALL:获取全部操作类型。 -GTASK_JSON_ACTION_TYPE_MOVE:移动操作类型。 -GTASK_JSON_ACTION_TYPE_UPDATE:更新操作类型。 -GTASK_JSON_CREATOR_ID:用于表示创建者的 ID。 -GTASK_JSON_CHILD_ENTITY:用于表示子实体。 -GTASK_JSON_CLIENT_VERSION:用于表示客户端版本。 -GTASK_JSON_COMPLETED:用于表示任务是否已完成。 -GTASK_JSON_CURRENT_LIST_ID:用于表示当前列表的 ID。 -GTASK_JSON_DEFAULT_LIST_ID:用于表示默认列表的 ID。 -GTASK_JSON_DELETED:用于表示实体是否已被删除。 -GTASK_JSON_DEST_LIST:用于表示目标列表。 -GTASK_JSON_DEST_PARENT:用于表示目标父实体。 -GTASK_JSON_DEST_PARENT_TYPE:用于表示目标父实体的类型。 -GTASK_JSON_ENTITY_DELTA:用于表示实体的变更信息。 -GTASK_JSON_ENTITY_TYPE:用于表示实体的类型。 -GTASK_JSON_GET_DELETED:用于表示是否获取已删除的实体。 -GTASK_JSON_ID:用于表示实体的 ID。 -GTASK_JSON_INDEX:用于表示实体的索引。 -GTASK_JSON_LAST_MODIFIED:用于表示实体最后修改的时间。 -GTASK_JSON_LATEST_SYNC_POINT:用于表示最新的同步点。 -GTASK_JSON_LIST_ID:用于表示列表的 ID。 -GTASK_JSON_LISTS:用于表示列表的集合。 -GTASK_JSON_NAME:用于表示实体的名称。 -GTASK_JSON_NEW_ID:用于表示新实体的 ID。 -GTASK_JSON_NOTES:用于表示笔记信息。 -GTASK_JSON_PARENT_ID:用于表示父实体的 ID。 -GTASK_JSON_PRIOR_SIBLING_ID:用于表示前一个兄弟实体的 ID。 -GTASK_JSON_RESULTS:用于表示操作的结果。 -GTASK_JSON_SOURCE_LIST:用于表示源列表。 -GTASK_JSON_TASKS:用于表示任务的集合。 -GTASK_JSON_TYPE:用于表示实体的类型。 -GTASK_JSON_TYPE_GROUP:组类型。 -GTASK_JSON_TYPE_TASK:任务类型。 -GTASK_JSON_USER:用于表示用户信息。 - -其他字符串常量 -MIUI_FOLDER_PREFFIX:用于表示 MIUI 笔记文件夹的前缀。 -FOLDER_DEFAULT:用于表示默认文件夹。 -FOLDER_CALL_NOTE:用于表示通话记录笔记文件夹。 -FOLDER_META:用于表示元数据文件夹。 -META_HEAD_GTASK_ID:用于表示 GTask ID 的元数据头部。 -META_HEAD_NOTE:用于表示笔记的元数据头部。 -META_HEAD_DATA:用于表示数据的元数据头部。 -META_NOTE_NAME:用于表示元数据笔记的名称,提示不要更新和删除。 - - -这些常量字符串在处理与 GTask 相关的 JSON 数据时非常有用,可以方便地获取和设置 JSON 对象中的各种属性。 -同时,它们也用于定义一些特定的文件夹名称和元数据头部,以便在笔记应用中进行相应的处理和标识。 - */ + + package net.micode.notes.tool; -// 该类用于定义 Google 任务相关的 JSON 字段常量 +/** + * GTaskStringUtils 类用于定义 Google 任务相关的 JSON 字段常量。 + * 这些常量用于在与 Google 任务 API 交互时标识不同的 JSON 字段。 + */ public class GTaskStringUtils { + /** + * JSON 字段:操作ID。 + */ public final static String GTASK_JSON_ACTION_ID = "action_id"; + /** + * JSON 字段:操作列表。 + */ public final static String GTASK_JSON_ACTION_LIST = "action_list"; + /** + * JSON 字段:操作类型。 + */ public final static String GTASK_JSON_ACTION_TYPE = "action_type"; + /** + * JSON 字段:创建操作类型。 + */ public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; + /** + * JSON 字段:获取所有操作类型。 + */ public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; + /** + * JSON 字段:移动操作类型。 + */ public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; + /** + * JSON 字段:更新操作类型。 + */ public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; + /** + * JSON 字段:创建者ID。 + */ public final static String GTASK_JSON_CREATOR_ID = "creator_id"; + /** + * JSON 字段:子实体。 + */ public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; + /** + * JSON 字段:客户端版本。 + */ public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; + /** + * JSON 字段:任务完成状态。 + */ public final static String GTASK_JSON_COMPLETED = "completed"; + /** + * JSON 字段:当前列表ID。 + */ public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; + /** + * JSON 字段:默认列表ID。 + */ public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; + /** + * JSON 字段:任务删除状态。 + */ public final static String GTASK_JSON_DELETED = "deleted"; + /** + * JSON 字段:目标列表。 + */ public final static String GTASK_JSON_DEST_LIST = "dest_list"; + /** + * JSON 字段:目标父实体。 + */ public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; + /** + * JSON 字段:目标父实体类型。 + */ public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; + /** + * JSON 字段:实体变更。 + */ public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; + /** + * JSON 字段:实体类型。 + */ public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; + /** + * JSON 字段:获取已删除的任务。 + */ public final static String GTASK_JSON_GET_DELETED = "get_deleted"; + /** + * JSON 字段:任务ID。 + */ public final static String GTASK_JSON_ID = "id"; + /** + * JSON 字段:任务索引。 + */ public final static String GTASK_JSON_INDEX = "index"; + /** + * JSON 字段:最后修改时间。 + */ public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; + /** + * JSON 字段:最新同步点。 + */ public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; + /** + * JSON 字段:列表ID。 + */ public final static String GTASK_JSON_LIST_ID = "list_id"; + /** + * JSON 字段:列表集合。 + */ public final static String GTASK_JSON_LISTS = "lists"; + /** + * JSON 字段:任务名称。 + */ public final static String GTASK_JSON_NAME = "name"; + /** + * JSON 字段:新ID。 + */ public final static String GTASK_JSON_NEW_ID = "new_id"; + /** + * JSON 字段:便签内容。 + */ public final static String GTASK_JSON_NOTES = "notes"; + /** + * JSON 字段:父实体ID。 + */ public final static String GTASK_JSON_PARENT_ID = "parent_id"; + /** + * JSON 字段:前一个兄弟实体ID。 + */ public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; + /** + * JSON 字段:操作结果。 + */ public final static String GTASK_JSON_RESULTS = "results"; + /** + * JSON 字段:源列表。 + */ public final static String GTASK_JSON_SOURCE_LIST = "source_list"; + /** + * JSON 字段:任务集合。 + */ public final static String GTASK_JSON_TASKS = "tasks"; + /** + * JSON 字段:类型。 + */ public final static String GTASK_JSON_TYPE = "type"; + /** + * JSON 字段:组类型。 + */ public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; + /** + * JSON 字段:任务类型。 + */ public final static String GTASK_JSON_TYPE_TASK = "TASK"; + /** + * JSON 字段:用户信息。 + */ public final static String GTASK_JSON_USER = "user"; + /** + * MIUI 文件夹前缀。 + */ 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"; + /** + * 元数据头部:Google 任务ID。 + */ 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"; - } \ No newline at end of file diff --git a/src/java/net/micode/notes/tool/ResourceParser.java b/src/java/net/micode/notes/tool/ResourceParser.java index 8784e5f..bd83149 100644 --- a/src/java/net/micode/notes/tool/ResourceParser.java +++ b/src/java/net/micode/notes/tool/ResourceParser.java @@ -15,16 +15,7 @@ */ - /** - * - * @ProjectName: minode - * @Package: net.micode.notes.data - * @ClassName: ResourceParser - * @Description: 该类用于解析和获取应用中的资源。它定义了多种资源的常量和静态方法,用于获取笔记背景、笔记项 - 背景、小部件背景和文本样式等资源。通过这些方法,可以方便地根据不同的条件获取相应的资源 ID, - 从而在应用中使用这些资源。 - * @Author: 齐景熙 - */ + package net.micode.notes.tool; import android.content.Context; @@ -33,40 +24,43 @@ 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; // 红色 + /** + * 默认背景颜色ID。 + */ 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; // 超大 + /** + * 默认字体大小ID。 + */ public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; - // 备忘录背景资源类 - /** - * @method NoteBgResources - * @description 该内部类用于获取笔记编辑背景和标题背景的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:该内部类用于获取笔记编辑背景和标题背景的资源 ID。 -成员变量: -BG_EDIT_RESOURCES:存储不同颜色的笔记编辑背景资源 ID 的数组。 -BG_EDIT_TITLE_RESOURCES:存储不同颜色的笔记编辑标题背景资源 ID 的数组。 */ - + * 便签背景资源类,提供便签编辑页面的背景资源。 + */ public static class NoteBgResources { - private final static int [] BG_EDIT_RESOURCES = new int [] { + private final static int[] BG_EDIT_RESOURCES = new int[]{ R.drawable.edit_yellow, R.drawable.edit_blue, R.drawable.edit_white, @@ -74,7 +68,7 @@ BG_EDIT_TITLE_RESOURCES:存储不同颜色的笔记编辑标题背景资源 ID R.drawable.edit_red }; - private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { + private final static int[] BG_EDIT_TITLE_RESOURCES = new int[]{ R.drawable.edit_title_yellow, R.drawable.edit_title_blue, R.drawable.edit_title_white, @@ -82,57 +76,30 @@ BG_EDIT_TITLE_RESOURCES:存储不同颜色的笔记编辑标题背景资源 ID R.drawable.edit_title_red }; - // 获取备忘录背景资源 - - /** - * @method getNoteBgResource - * @description 根据传入的 ID 获取笔记编辑背景的资源 ID。通过索引访问 BG_EDIT_RESOURCES 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取笔记编辑背景的资源 ID。通过索引访问 BG_EDIT_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:笔记背景颜色的 ID。 -返回值:笔记编辑背景的资源 ID。 - */ - + /** + * 获取便签背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } - // 获取备忘录标题背景资源 - - /** - * @method getNoteTitleBgResource - * @description 根据传入的 ID 获取笔记编辑标题背景的资源 ID。通过索引访问 BG_EDIT_TITLE_RESOURCES 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取笔记编辑标题背景的资源 ID。通过索引访问 BG_EDIT_TITLE_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:笔记背景颜色的 ID。 -返回值:笔记编辑标题背景的资源 ID。 - */ - + /** + * 获取便签标题背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } - // 获取默认背景ID - - /** - * @method getDefaultBgId - * @description 获取默认的笔记背景颜色 ID。首先检查是否设置了背景颜色的偏好设置,如果设置了,则随机生成一个背 - 景颜色 ID;否则,返回默认的背景颜色 ID(黄色)。 - * @author: 齐景熙 - */ - /* -功能介绍:获取默认的笔记背景颜色 ID。首先检查是否设置了背景颜色的偏好设置,如果设置了,则随机生成一个背景颜色 ID;否则,返回默认的背景颜色 ID(黄色)。 -参数: -context:上下文对象,用于访问偏好设置。 -返回值:默认的笔记背景颜色 ID。 - */ + /** + * 获取默认背景颜色ID。 + * @param context 上下文 + * @return 背景颜色ID + */ public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { @@ -142,24 +109,11 @@ context:上下文对象,用于访问偏好设置。 } } - // 备忘录项目背景资源类 - - /** - * @method NoteItemBgResources - * @description 该内部类用于获取笔记项背景的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:该内部类用于获取笔记项背景的资源 ID。 -成员变量: -BG_FIRST_RESOURCES:存储不同颜色的笔记项第一个背景资源 ID 的数组。 -BG_NORMAL_RESOURCES:存储不同颜色的笔记项普通背景资源 ID 的数组。 -BG_LAST_RESOURCES:存储不同颜色的笔记项最后一个背景资源 ID 的数组。 -BG_SINGLE_RESOURCES:存储不同颜色的笔记项单个背景资源 ID 的数组。 - */ - + /** + * 便签项背景资源类,提供便签列表项的背景资源。 + */ public static class NoteItemBgResources { - private final static int [] BG_FIRST_RESOURCES = new int [] { + private final static int[] BG_FIRST_RESOURCES = new int[]{ R.drawable.list_yellow_up, R.drawable.list_blue_up, R.drawable.list_white_up, @@ -167,7 +121,7 @@ BG_SINGLE_RESOURCES:存储不同颜色的笔记项单个背景资源 ID 的数 R.drawable.list_red_up }; - private final static int [] BG_NORMAL_RESOURCES = new int [] { + private final static int[] BG_NORMAL_RESOURCES = new int[]{ R.drawable.list_yellow_middle, R.drawable.list_blue_middle, R.drawable.list_white_middle, @@ -175,15 +129,15 @@ BG_SINGLE_RESOURCES:存储不同颜色的笔记项单个背景资源 ID 的数 R.drawable.list_red_middle }; - private final static int [] BG_LAST_RESOURCES = new int [] { + private final static int[] BG_LAST_RESOURCES = new int[]{ R.drawable.list_yellow_down, R.drawable.list_blue_down, R.drawable.list_white_down, R.drawable.list_green_down, - R.drawable.list_red_down, + R.drawable.list_red_down }; - private final static int [] BG_SINGLE_RESOURCES = new int [] { + private final static int[] BG_SINGLE_RESOURCES = new int[]{ R.drawable.list_yellow_single, R.drawable.list_blue_single, R.drawable.list_white_single, @@ -191,144 +145,73 @@ BG_SINGLE_RESOURCES:存储不同颜色的笔记项单个背景资源 ID 的数 R.drawable.list_red_single }; - // 获取备忘录第一个背景资源 - - /** - * @method getNoteBgFirstRes - * @description 该内部类用于获取笔记项背景的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:该内部类用于获取笔记项背景的资源 ID。 -成员变量: -参数: -id:笔记背景颜色的 ID。 -返回值:笔记项第一个背景的资源 ID。 - */ - + /** + * 获取便签列表项首行背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } - // 获取备忘录最后一个背景资源 - - /** - * @method getNoteBgLastRes - * @description 根据传入的 ID 获取笔记项第一个背景的资源 ID。通过索引访问 BG_FIRST_RESOURCES - 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取笔记项第一个背景的资源 ID。通过索引访问 BG_FIRST_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:笔记背景颜色的 ID。 -返回值:笔记项第一个背景的资源 ID。 - */ - + /** + * 获取便签列表项末行背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } - // 获取备忘录单独背景资源 - /** - * @method getNoteBgSingleRes - * @description 根据传入的 ID 获取笔记项第一个背景的资源 ID。通过索引访问 BG_FIRST_RESOURCES - 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取笔记项最后一个背景的资源 ID。通过索引访问 BG_LAST_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:笔记背景颜色的 ID。 -返回值:笔记项最后一个背景的资源 ID。 - */ + * 获取便签列表项单行背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } - // 获取备忘录正常背景资源 - - /** - * @method getNoteBgNormalRes - * @description 根据传入的 ID 获取笔记项第一个背景的资源 ID。通过索引访问 BG_FIRST_RESOURCES - 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取笔记项单个背景的资源 ID。通过索引访问 BG_SINGLE_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:笔记背景颜色的 ID。 -返回值:笔记项单个背景的资源 ID。 - */ - + /** + * 获取便签列表项普通行背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } - // 获取文件夹背景资源 - /** - * @method getFolderBgRes - * @description 根据传入的 ID 获取笔记项第一个背景的资源 ID。通过索引访问 BG_FIRST_RESOURCES - 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取笔记项普通背景的资源 ID。通过索引访问 BG_NORMAL_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:笔记背景颜色的 ID。 -返回值:笔记项普通背景的资源 ID。 - */ + /** + * 获取文件夹背景资源ID。 + * @return 资源ID + */ public static int getFolderBgRes() { return R.drawable.list_folder; } } - // 小部件背景资源类 - - /** - * - * @ProjectName: minode - * @Package: net.micode.notes.data - * @ClassName: WidgetBgResources - * @Description: 该内部类用于获取小部件背景的资源 ID。 - * @Author: 齐景熙 - */ - - /* -功能介绍:该内部类用于获取小部件背景的资源 ID。 -成员变量: -BG_2X_RESOURCES:存储不同颜色的 2x 小部件背景资源 ID 的数组。 -BG_4X_RESOURCES:存储不同颜色的 4x 小部件背景资源 ID 的数组。 -*/ - + /** + * 小部件背景资源类,提供小部件的背景资源。 + */ public static class WidgetBgResources { - private final static int [] BG_2X_RESOURCES = new int [] { + private final static int[] BG_2X_RESOURCES = new int[]{ R.drawable.widget_2x_yellow, R.drawable.widget_2x_blue, R.drawable.widget_2x_white, R.drawable.widget_2x_green, - R.drawable.widget_2x_red, + R.drawable.widget_2x_red }; - // 获取2x小部件背景资源 - - /** - * @method getWidget2xBgResource - * @description 根据传入的 ID 获取 2x 小部件背景的资源 ID。通过索引访问 BG_2X_RESOURCES 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取 2x 小部件背景的资源 ID。通过索引访问 BG_2X_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:小部件背景颜色的 ID。 -返回值:2x 小部件背景的资源 ID。 - */ + /** + * 获取2x小部件背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } - private final static int [] BG_4X_RESOURCES = new int [] { + private final static int[] BG_4X_RESOURCES = new int[]{ R.drawable.widget_4x_yellow, R.drawable.widget_4x_blue, R.drawable.widget_4x_white, @@ -336,86 +219,43 @@ id:小部件背景颜色的 ID。 R.drawable.widget_4x_red }; - // 获取4x小部件背景资源 - - /** - * @method getWidget4xBgResource - * @description 根据传入的 ID 获取 4x 小部件背景的资源 ID。通过索引访问 BG_4X_RESOURCES 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取 4x 小部件背景的资源 ID。通过索引访问 BG_4X_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:小部件背景颜色的 ID。 -返回值:4x 小部件背景的资源 ID。 - */ + /** + * 获取4x小部件背景资源ID。 + * @param id 背景颜色ID + * @return 资源ID + */ public static int getWidget4xBgResource(int id) { return BG_4X_RESOURCES[id]; } } - // 文本外观资源类 - - /** - * - * @ProjectName: minode - * @Package: net.micode.notes.data - * @ClassName: TextAppearanceResources - * @Description: 该内部类用于获取文本样式的资源 ID。 - * @Author: 齐景熙 - */ - - /* -功能介绍:该内部类用于获取文本样式的资源 ID。 -成员变量: -TEXTAPPEARANCE_RESOURCES:存储不同大小的文本样式资源 ID 的数组。 -*/ + /** + * 文本外观资源类,提供不同字体大小的文本外观资源。 + */ public static class TextAppearanceResources { - private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { + private final static int[] TEXTAPPEARANCE_RESOURCES = new int[]{ R.style.TextAppearanceNormal, R.style.TextAppearanceMedium, R.style.TextAppearanceLarge, R.style.TextAppearanceSuper }; - // 获取文本外观资源 - - /** - * @method getTexAppearanceResource - * @description 根据传入的 ID 获取文本样式的资源 ID。首先检查 ID 是否超出数组长度,如果超出,则返回默认的文本样式 ID; - 否则,通过索引访问 TEXTAPPEARANCE_RESOURCES 数组,返回对应的资源 ID。 - * @author: 齐景熙 - */ - /* -功能介绍:根据传入的 ID 获取文本样式的资源 ID。首先检查 ID 是否超出数组长度,如果超出,则返回默认的文本样式 ID; -否则,通过索引访问 TEXTAPPEARANCE_RESOURCES 数组,返回对应的资源 ID。 -参数: -id:文本样式大小的 ID。 -返回值:文本样式的资源 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} - */ if (id >= TEXTAPPEARANCE_RESOURCES.length) { - return BG_DEFAULT_FONT_SIZE; + return TEXTAPPEARANCE_RESOURCES[BG_DEFAULT_FONT_SIZE]; } return TEXTAPPEARANCE_RESOURCES[id]; } - // 获取资源大小 - - /** - * @method getResourcesSize - * @description 获取文本样式资源的大小。返回 TEXTAPPEARANCE_RESOURCES 数组的长度。 - * @author: 齐景熙 - */ - /* -功能介绍:获取文本样式资源的大小。返回 TEXTAPPEARANCE_RESOURCES 数组的长度。 -返回值:文本样式资源的大小。 - */ + /** + * 获取文本外观资源数量。 + * @return 资源数量 + */ public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; }