From 15007469276a099c210fe8db3abedbe67ee46ccb Mon Sep 17 00:00:00 2001 From: dyq <2379414960@qq.com> Date: Fri, 7 Apr 2023 11:10:05 +0800 Subject: [PATCH] 1 Signed-off-by: dyq <2379414960@qq.com> --- src/tool/BackupUtils.java | 146 +++++++++++++------------- src/tool/DataUtils.java | 89 ++++++++-------- src/tool/GTaskStringUtils.java | 90 ++++++++-------- src/tool/ResourceParser.java | 87 ++++++++------- src/widget/NoteWidgetProvider.java | 34 +++--- src/widget/NoteWidgetProvider_2x.java | 9 +- src/widget/NoteWidgetProvider_4x.java | 9 +- 7 files changed, 234 insertions(+), 230 deletions(-) diff --git a/src/tool/BackupUtils.java b/src/tool/BackupUtils.java index 39f6ec4..93ae8c8 100644 --- a/src/tool/BackupUtils.java +++ b/src/tool/BackupUtils.java @@ -33,8 +33,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintStream; - +import java.io.PrintStream;////// +//添加包。类。对象等 public class BackupUtils { private static final String TAG = "BackupUtils"; @@ -42,9 +42,9 @@ public class BackupUtils { private static BackupUtils sInstance; public static synchronized BackupUtils getInstance(Context context) { - if (sInstance == null) { + if (sInstance == null) {//如果实例为空则创建新实例 sInstance = new BackupUtils(context); - } + }//返回实例 return sInstance; } @@ -72,19 +72,19 @@ public class BackupUtils { private static boolean externalStorageAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } - +//将笔记·导出文本,返回导出时的状态码 public int exportToText() { return mTextExport.exportToText(); } - +//获取导出文本文件名 public String getExportedTextFileName() { return mTextExport.mFileName; } - +//获得到处文本文件目录 public String getExportedTextFileDir() { return mTextExport.mFileDirectory; } - +//负责将笔记导出为文本 private static class TextExport { private static final String[] NOTE_PROJECTION = { NoteColumns.ID, @@ -93,11 +93,11 @@ public class BackupUtils { NoteColumns.TYPE }; - private static final int NOTE_COLUMN_ID = 0; + private static final int NOTE_COLUMN_ID = 0;//查询结果中笔记id所在列的索引 - private static final int NOTE_COLUMN_MODIFIED_DATE = 1; + private static final int NOTE_COLUMN_MODIFIED_DATE = 1;//查询结果中笔记上次修改时间所在的索引 - private static final int NOTE_COLUMN_SNIPPET = 2; + private static final int NOTE_COLUMN_SNIPPET = 2;//查询摘要所在索引 private static final String[] DATA_PROJECTION = { DataColumns.CONTENT, @@ -106,7 +106,7 @@ public class BackupUtils { DataColumns.DATA2, DataColumns.DATA3, DataColumns.DATA4, - }; + };//定义静态不可变数据列 private static final int DATA_COLUMN_CONTENT = 0; @@ -114,24 +114,24 @@ public class BackupUtils { private static final int DATA_COLUMN_CALL_DATE = 2; - private static final int DATA_COLUMN_PHONE_NUMBER = 4; + private static final int DATA_COLUMN_PHONE_NUMBER = 4;//定义以上数据列MIME类,呼叫日期,号码的索引初始值 - private final String [] TEXT_FORMAT; - private static final int FORMAT_FOLDER_NAME = 0; + private final String [] TEXT_FORMAT;//定义带有3个元素字符串数组TEXT_FORMAT + private static final int FORMAT_FOLDER_NAME = 0;//格式化后目录名称FORMAT_FOLDER_NAME= 0 private static final int FORMAT_NOTE_DATE = 1; - private static final int FORMAT_NOTE_CONTENT = 2; + private static final int FORMAT_NOTE_CONTENT = 2;//格式化后的笔记内容索引为2 - private Context mContext; - private String mFileName; - private String mFileDirectory; + private Context mContext;//声名Context类型和字符串类型 + private String mFileName;//文件名称 + private String mFileDirectory;//文件目录路径 public TextExport(Context context) { - TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); + TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);//初始化文件名称变量为控字符串 mContext = context; mFileName = ""; mFileDirectory = ""; - } - + }//初始化文件路径mFileDirectory = ""为空 +//创建TextExport对象 private String getFormat(int id) { return TEXT_FORMAT[id]; } @@ -166,39 +166,39 @@ public class BackupUtils { * 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, + Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,//查询CONTENT_DATA_URI对应的数据表 DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { noteId }, null); - - if (dataCursor != null) { - if (dataCursor.moveToFirst()) { +//使用DataColumns.NOTE_ID是否为?限制查询条件,并查询noted对应的数据行 + if (dataCursor != null) {//若查询不为空,则执行以下代码: + if (dataCursor.moveToFirst()) {//移动游标为第一条记录并循环记录 do { - String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); + String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);//获取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); + String location = dataCursor.getString(DATA_COLUMN_CONTENT);//从记录中获取phonenumber和calldate的值并输出号码 - if (!TextUtils.isEmpty(phoneNumber)) { + if (!TextUtils.isEmpty(phoneNumber)) {//若电话号码不为空 ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - phoneNumber)); + phoneNumber));//输出电话号码输出到PrintStream实例PS中 } // Print call date ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat .format(mContext.getString(R.string.format_datetime_mdhm), - callDate))); + callDate)));//输出通话日期信息到PrintStream中 // Print call attachment location - if (!TextUtils.isEmpty(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); + }//输出位置信息到PrintStream实例PS中 + } else if (DataConstants.NOTE.equals(mimeType)) {//若数据类型为Note,则执行以下语句 + String content = dataCursor.getString(DATA_COLUMN_CONTENT);//从Cursor中获取信息 if (!TextUtils.isEmpty(content)) { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), - content)); + content));//将内容信息格式化输出rintStream实例PS中 } } } while (dataCursor.moveToNext()); @@ -210,74 +210,74 @@ public class BackupUtils { ps.write(new byte[] { Character.LINE_SEPARATOR, Character.LETTER_NUMBER }); - } catch (IOException e) { + } catch (IOException e) {//若出现IO异常,则廖永Log类的e()方法将异常信息输出日志中 Log.e(TAG, e.toString()); } } - +//使用rintStream实例PS的write()方法写入字节数组到输出流中,包括换行和字母数字 /** * Note will be exported as text which is user readable */ - public int exportToText() { + public int exportToText() {//定义exportToText(),返回值类型为整型 if (!externalStorageAvailable()) { Log.d(TAG, "Media was not mounted"); return STATE_SD_CARD_UNMOUONTED; } - - PrintStream ps = getExportToTextPrintStream(); +//若外部存储不可用,输出日记信息,返回表示Media was not mounted + PrintStream ps = getExportToTextPrintStream();//获取打印输出 if (ps == null) { Log.e(TAG, "get print stream error"); return STATE_SYSTEM_ERROR; - } + }//若获取不到打印输出,输出get print stream error",并返回错误 // First export folder and its notes - Cursor folderCursor = mContext.getContentResolver().query( + Cursor folderCursor = mContext.getContentResolver().query(//声名Cursor类的变量folder,存储调查结果 Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, + NOTE_PROJECTION,//调用getContentResolver(),查询目标为Note表中数据和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 != null) {//判断folder是否为空 if (folderCursor.moveToFirst()) { do { // Print folder's name - String folderName = ""; + String folderName = "";//遍历查询文件夹中所有文件夹记录 if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { - folderName = mContext.getString(R.string.call_record_folder_name); - } else { + folderName = mContext.getString(R.string.call_record_folder_name);//若记录对应通话记录文件夹,给folder赋值Notes.ID_CALL_RECORD_FOLDER + } else {//否则folder赋值为记录的摘要字段值 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); + String folderId = folderCursor.getString(NOTE_COLUMN_ID);//获取当前记录对应文件夹id并赋值给folder exportFolderToText(folderId, ps); - } while (folderCursor.moveToNext()); + } while (folderCursor.moveToNext());//将当前记录文件夹导出为文本形式,结果写入PS中 } folderCursor.close(); } // Export notes in root's folder - Cursor noteCursor = mContext.getContentResolver().query( - Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, + Cursor noteCursor = mContext.getContentResolver().query(//通过getContentResolver()获取resolver对象,并调用querty方法查询 + Notes.CONTENT_NOTE_URI,//查询URI + NOTE_PROJECTION,//查询列 NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID - + "=0", null, null); + + "=0", null, null);//限制查询类型为Notes.TYPE_NOTE,且父id为0的note记录 if (noteCursor != null) { - if (noteCursor.moveToFirst()) { + 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)))); + 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()); - } + }//或i去当前Note记录的id,吧id对应数据写入输出流中 noteCursor.close(); } - ps.close(); + ps.close();//关闭游标 return STATE_SUCCESS; } @@ -286,21 +286,21 @@ public class BackupUtils { * Get a print stream pointed to the file {@generateExportedTextFile} */ private PrintStream getExportToTextPrintStream() { - File file = generateFileMountedOnSDcard(mContext, R.string.file_path, + File file = generateFileMountedOnSDcard(mContext, R.string.file_path,//使用getExportToTextPrintStream()再sd卡上生成指定名称和路径的文本文件 R.string.file_name_txt_format); if (file == null) { Log.e(TAG, "create file to exported failed"); - return null; + return null;//若生成文件失败,返回null,再logcat输出错误信息 } mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); + mFileDirectory = mContext.getString(R.string.file_path);//将成功创建文件保存为FoleNAMe,路径柏村委mFileDiectory PrintStream ps = null; try { FileOutputStream fos = new FileOutputStream(file); - ps = new PrintStream(fos); - } catch (FileNotFoundException e) { + ps = new PrintStream(fos);//创建对象fos,用于写入文件 + } catch (FileNotFoundException e) {//使用fos创建PrintStream对象PS,一边向文件夹写入数据 e.printStackTrace(); - return null; + return null;//若无法找到写入目标文件,再logcat输出错误信息,并返回null } catch (NullPointerException e) { e.printStackTrace(); return null; @@ -314,28 +314,28 @@ public class BackupUtils { */ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { StringBuilder sb = new StringBuilder(); - sb.append(Environment.getExternalStorageDirectory()); + sb.append(Environment.getExternalStorageDirectory());//再strtingbuilder中添加SD卡根目录路径 sb.append(context.getString(filePathResId)); - File filedir = new File(sb.toString()); + File filedir = new File(sb.toString());//添加文件路径字符串资源id,并返回file对象表示该目录 sb.append(context.getString( fileNameFormatResId, DateFormat.format(context.getString(R.string.format_date_ymd), - System.currentTimeMillis()))); + System.currentTimeMillis())));//再StringBuilder添加文件名格式字符串资源id,并使用dateFormat替换为当前日期格式化字符串 File file = new File(sb.toString()); - +//返回表示最终创建的文件夹对象 try { if (!filedir.exists()) { filedir.mkdir(); - } + }//判断指定目录是否存在,若不存在创建 if (!file.exists()) { file.createNewFile(); - } - return file; + }//判断指定目录是否存在,若不存在创建 + return file;//返回创建对象 } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - } + }//如果不能在指定目录下创建新的文件,则抛出IOException异常 return null; } diff --git a/src/tool/DataUtils.java b/src/tool/DataUtils.java index 2a14982..665e0a2 100644 --- a/src/tool/DataUtils.java +++ b/src/tool/DataUtils.java @@ -25,18 +25,18 @@ import android.content.OperationApplicationException; import android.database.Cursor; import android.os.RemoteException; import android.util.Log; - +//导入android 包content、database等 import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.CallNote; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; - +//导入net-micode包下数据 import java.util.ArrayList; import java.util.HashSet; +//导入JAVA ArrayList和HashSet类 - -public class DataUtils { - public static final String TAG = "DataUtils"; +public class DataUtils {//对DataUtils类进行定义 + public static final String TAG = "DataUtils";//定义静态不可变字TAG符串常量"DataUtils" public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -46,69 +46,71 @@ public class DataUtils { Log.d(TAG, "no id is in the hashset"); return true; } - + //定义批量删除笔记。若ids参数为null,输出"the ids is null"并返回true;若ids参数为0,输出"no id is in the hashset"并返回true ArrayList operationList = new ArrayList(); - for (long id : ids) { + //定义操作列表,存储ContentProviderOperation对象 + for (long id : ids) {//遍历id列表 if(id == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Don't delete system folder root"); continue; - } + }//如果id为系统根目录,打印"不要删除系统根目录"并进行下一次循环 ContentProviderOperation.Builder builder = ContentProviderOperation .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); - operationList.add(builder.build()); + operationList.add(builder.build());//创造builder对象,删除指定id的ContentProviderOperation } - try { + try {//调用applybatch 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; } - return true; + return true;//若返回为空或第一个结果为null,输出删除失败返回false,否则返回true } 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())); - } + }//若remoteexeption或operationapplicationexception异常,返回false return false; } public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { - ContentValues values = new ContentValues(); - values.put(NoteColumns.PARENT_ID, desFolderId); - values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); + ContentValues values = new ContentValues();//创建contentValues对象 + values.put(NoteColumns.PARENT_ID, desFolderId);//移动笔记至目标文件夹 + values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);//更新笔记的原始父类文件夹id values.put(NoteColumns.LOCAL_MODIFIED, 1); resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); + //更新笔记 } public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, - long folderId) { + long folderId) {//若ids为空,打印log并返回true if (ids == null) { Log.d(TAG, "the ids is null"); return true; } ArrayList operationList = new ArrayList(); - for (long id : ids) { + for (long id : ids) {//遍历笔记id集合 ContentProviderOperation.Builder builder = ContentProviderOperation .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); - builder.withValue(NoteColumns.PARENT_ID, folderId); - builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); - operationList.add(builder.build()); + builder.withValue(NoteColumns.PARENT_ID, folderId);//移动笔记至目标文件夹 + builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);//添加键值对,表示本地有效 + operationList.add(builder.build());//添加操作至操作列表 } try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); - if (results == null || results.length == 0 || results[0] == null) { + ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);//应用操作列表 + if (results == null || results.length == 0 || results[0] == null) {//如果结果为空或者第一个结果为空,打印log并返回false Log.d(TAG, "delete notes failed, ids:" + ids.toString()); return false; } - return true; - } catch (RemoteException e) { + return true;//true表示操作成功 + } catch (RemoteException e) {//捕获远程异常 Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - } catch (OperationApplicationException e) { + } catch (OperationApplicationException e) {//捕获操作异常 Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } - return false; + return false;//false表示操作失败 } /** @@ -134,7 +136,7 @@ public class DataUtils { } } return count; - } + }//检查笔记是否在数据库中可见,若不可见输出"get folder count failed:" public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), @@ -152,7 +154,7 @@ public class DataUtils { } return exist; } - +//检查数据是否在数据库中存在 public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, null, null, null); @@ -166,7 +168,7 @@ public class DataUtils { } return exist; } - +//检查文件名称是否可见 public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null, null, null, null); @@ -198,6 +200,7 @@ public class DataUtils { } public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { + //查询文件夹中所有小部件id和类型 Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, NoteColumns.PARENT_ID + "=?", @@ -208,6 +211,7 @@ public class DataUtils { if (c != null) { if (c.moveToFirst()) { set = new HashSet(); + //遍历查询结果,将小部件id和类型存入hashSET中 do { try { AppWidgetAttribute widget = new AppWidgetAttribute(); @@ -220,11 +224,11 @@ public class DataUtils { } while (c.moveToNext()); } c.close(); - } + }//返回文件夹中所有小部件HashSet集合 return set; } - public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { + public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {//获取一段笔记的getCallNumberByNoteId Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.PHONE_NUMBER }, CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", @@ -234,20 +238,21 @@ public class DataUtils { if (cursor != null && cursor.moveToFirst()) { try { return cursor.getString(0); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Get call number fails " + e.toString()); + } catch (IndexOutOfBoundsException e) {//如果查询结果不为空且有数据,则返回该行的电话号码 + Log.e(TAG, "Get call number fails " + e.toString());//如果获取电话号码失败,则打印错误日志 } finally { cursor.close(); - } + } //关闭游标,释放资源 } - return ""; + return "";//如果没有查询结果,则返回空串 } public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.NOTE_ID }, + //使用ContentResover对象来查询数据,并返回Cursor对象 + Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,//查询Note id字段 + new String [] { CallNote.NOTE_ID },//通过童话日期,电话号码扽给查询 CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" - + CallNote.PHONE_NUMBER + ",?)", + + CallNote.PHONE_NUMBER + ",?)",//传入查询参数 new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, null); @@ -264,8 +269,8 @@ public class DataUtils { return 0; } - public static String getSnippetById(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, + public static String getSnippetById(ContentResolver resolver, long noteId) {//使用ContentResovler对象查询数据,返回Cursor对象 + Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,//查询snippet字段 new String [] { NoteColumns.SNIPPET }, NoteColumns.ID + "=?", new String [] { String.valueOf(noteId)}, @@ -273,14 +278,14 @@ public class DataUtils { if (cursor != null) { String snippet = ""; - if (cursor.moveToFirst()) { + if (cursor.moveToFirst()) {//获取查询结果中第0列的值,即snippet字段值 snippet = cursor.getString(0); } cursor.close(); return snippet; } throw new IllegalArgumentException("Note is not found with id: " + noteId); - } + }//通过noteld获取信息,返回字符串 public static String getFormattedSnippet(String snippet) { if (snippet != null) { diff --git a/src/tool/GTaskStringUtils.java b/src/tool/GTaskStringUtils.java index 666b729..d5dabb0 100644 --- a/src/tool/GTaskStringUtils.java +++ b/src/tool/GTaskStringUtils.java @@ -18,96 +18,96 @@ package net.micode.notes.tool; public class GTaskStringUtils { - public final static String GTASK_JSON_ACTION_ID = "action_id"; + public final static String GTASK_JSON_ACTION_ID = "action_id";//定义字符串常量,在类的外部直接访问,表示"action_id"的字符串键名 - public final static String GTASK_JSON_ACTION_LIST = "action_list"; + public final static String GTASK_JSON_ACTION_LIST = "action_list";//定义字符串常量,在类的外部直接访问,表示"action_list的字符串键名 - public final static String GTASK_JSON_ACTION_TYPE = "action_type"; + public final static String GTASK_JSON_ACTION_TYPE = "action_type";//定义字符串常量,在类的外部直接访问,表示action_type的字符串键名 - public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; + public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";//定义字符串常量,在类的外部直接访问,表示create的字符串键名 - public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; + public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";//定义字符串常量,在类的外部直接访问,表示get_all的字符串键名 - public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; + public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";//定义字符串常量,在类的外部直接访问,表示"move的字符串键名 - public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; + public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";//定义字符串常量,在类的外部直接访问,表示update的字符串键名 - public final static String GTASK_JSON_CREATOR_ID = "creator_id"; + public final static String GTASK_JSON_CREATOR_ID = "creator_id";//定义字符串常量,在类的外部直接访问,表示creator_id的字符串键名 - public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; + public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";//定义字符串常量,在类的外部直接访问,表示child_entity的字符串键名 - public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; + public final static String GTASK_JSON_CLIENT_VERSION = "client_version";//定义字符串常量,在类的外部直接访问,表示client_version的字符串键名 - public final static String GTASK_JSON_COMPLETED = "completed"; + public final static String GTASK_JSON_COMPLETED = "completed";//定义字符串常量,在类的外部直接访问,表示completed的字符串键名 public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; + //定义字符串常量,在类的外部直接访问,表示current_list_id的字符串键名 + public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";//定义字符串常量,在类的外部直接访问,表示default_list_id的字符串键名 - public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; + public final static String GTASK_JSON_DELETED = "deleted";//定义字符串常量,在类的外部直接访问,表示deleted的字符串键名 - public final static String GTASK_JSON_DELETED = "deleted"; + public final static String GTASK_JSON_DEST_LIST = "dest_list";//定义字符串常量,在类的外部直接访问,表示dest_list的字符串键名 - public final static String GTASK_JSON_DEST_LIST = "dest_list"; + public final static String GTASK_JSON_DEST_PARENT = "dest_parent";//定义字符串常量,在类的外部直接访问,表示dest_parent的字符串键名 - public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; + public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";//定义字符串常量,在类的外部直接访问,表示dest_parent_type的字符串键名 - public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; + public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";//定义字符串常量,在类的外部直接访问,表示entity_delta的字符串键名 - 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_ENTITY_TYPE = "entity_type";//定义字符串常量,在类的外部直接访问,表示entity_type的字符串键名 public final static String GTASK_JSON_GET_DELETED = "get_deleted"; + //定义字符串常量,在类的外部直接访问,表示get_deleted的字符串键名 + public final static String GTASK_JSON_ID = "id";//定义字符串常量,在类的外部直接访问,表示id的字符串键名 - public final static String GTASK_JSON_ID = "id"; - - public final static String GTASK_JSON_INDEX = "index"; + public final static String GTASK_JSON_INDEX = "index";//定义字符串常量,在类的外部直接访问,表示index的字符串键名 - public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; + public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";//定义字符串常量,在类的外部直接访问,表示last_modified的字符串键名 - public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; + public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";//定义字符串常量,在类的外部直接访问,表示latest_sync_point的字符串键名 - public final static String GTASK_JSON_LIST_ID = "list_id"; + public final static String GTASK_JSON_LIST_ID = "list_id";//定义字符串常量,在类的外部直接访问,表示list_id的字符串键名 - public final static String GTASK_JSON_LISTS = "lists"; + public final static String GTASK_JSON_LISTS = "lists";//定义字符串常量,在类的外部直接访问,表示lists的字符串键名 - public final static String GTASK_JSON_NAME = "name"; + public final static String GTASK_JSON_NAME = "name";//定义字符串常量,在类的外部直接访问,表示name的字符串键名 public final static String GTASK_JSON_NEW_ID = "new_id"; + //定义字符串常量,在类的外部直接访问,表示new_id的字符串键名 + public final static String GTASK_JSON_NOTES = "notes";//定义字符串常量,在类的外部直接访问,表示notes的字符串键名 - public final static String GTASK_JSON_NOTES = "notes"; - - public final static String GTASK_JSON_PARENT_ID = "parent_id"; + public final static String GTASK_JSON_PARENT_ID = "parent_id";//定义字符串常量,在类的外部直接访问,表示parent_id的字符串键名 - public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; + public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";//定义字符串常量,在类的外部直接访问,表示prior_sibling_id的字符串键名 - public final static String GTASK_JSON_RESULTS = "results"; + public final static String GTASK_JSON_RESULTS = "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_TASKS = "tasks";//定义字符串常量,在类的外部直接访问,表示tasks的字符串键名 - public final static String GTASK_JSON_TYPE = "type"; + public final static String GTASK_JSON_TYPE = "type";//定义字符串常量,在类的外部直接访问,表示type的字符串键名 - public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; + public final static String GTASK_JSON_TYPE_GROUP = "GROUP";//定义字符串常量,在类的外部直接访问,表示GROUP的字符串键名 - public final static String GTASK_JSON_TYPE_TASK = "TASK"; + public final static String GTASK_JSON_TYPE_TASK = "TASK";//定义字符串常量,在类的外部直接访问,表示TASK的字符串键名 - public final static String GTASK_JSON_USER = "user"; + public final static String GTASK_JSON_USER = "user";//定义字符串常量,在类的外部直接访问,表示user的字符串键名 - public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; + public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";//定义字符串常量,在类的外部直接访问,表示MIUI_Notes的字符串键名 - public final static String FOLDER_DEFAULT = "Default"; + public final static String FOLDER_DEFAULT = "Default";//定义字符串常量,在类的外部直接访问,表示Default的字符串键名 - public final static String FOLDER_CALL_NOTE = "Call_Note"; + public final static String FOLDER_CALL_NOTE = "Call_Note";//定义字符串常量,在类的外部直接访问,表示Call_Note的字符串键名 - public final static String FOLDER_META = "METADATA"; + public final static String FOLDER_META = "METADATA";//定义字符串常量,在类的外部直接访问,表示METADATA的字符串键名 - public final static String META_HEAD_GTASK_ID = "meta_gid"; + public final static String META_HEAD_GTASK_ID = "meta_gid";//定义字符串常量,在类的外部直接访问,表示meta_gid的字符串键名 - public final static String META_HEAD_NOTE = "meta_note"; + public final static String META_HEAD_NOTE = "meta_note";//定义字符串常量,在类的外部直接访问,表示meta_note的字符串键名 - public final static String META_HEAD_DATA = "meta_data"; + public final static String META_HEAD_DATA = "meta_data";//定义字符串常量,在类的外部直接访问,表示meta_data的字符串键名 - public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; + public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";//定义字符串常量,在类的外部直接访问,表示[META INFO] DON'T UPDATE AND DELETE的字符串键名 } diff --git a/src/tool/ResourceParser.java b/src/tool/ResourceParser.java index 1ad3ad6..86fab8f 100644 --- a/src/tool/ResourceParser.java +++ b/src/tool/ResourceParser.java @@ -22,22 +22,22 @@ 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 class ResourceParser { +//定义常量,用于表示颜色和字体大小 + public static final int YELLOW = 0;//黄色 + public static final int BLUE = 1;//蓝 + public static final int WHITE = 2;//bai public static final int GREEN = 3; public static final int RED = 4; - public static final int BG_DEFAULT_COLOR = YELLOW; + 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;//da + public static final int TEXT_SUPER = 3;//chaoda - public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; + public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;//默认大小为中 public static class NoteBgResources { private final static int [] BG_EDIT_RESOURCES = new int [] { @@ -46,7 +46,7 @@ public class ResourceParser { R.drawable.edit_white, R.drawable.edit_green, R.drawable.edit_red - }; + };//定义私有静态常量G_EDIT_RESOURCES ,用于储存图片资源id private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { R.drawable.edit_title_yellow, @@ -54,7 +54,7 @@ public class ResourceParser { R.drawable.edit_title_white, R.drawable.edit_title_green, R.drawable.edit_title_red - }; + };//定义另一个私有静态常量,用于储存笔记编辑页面标题背景资源id public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; @@ -63,40 +63,40 @@ public class ResourceParser { public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } - } + }//初始化编辑页面标题背景资源id - public static int getDefaultBgId(Context context) { + public static int getDefaultBgId(Context context) {//获取应用配置信息,判断用户是否自定义背景颜色 if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length); } else { - return BG_DEFAULT_COLOR; + 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, - R.drawable.list_white_up, - R.drawable.list_green_up, - R.drawable.list_red_up + private final static int [] BG_FIRST_RESOURCES = new int [] {//定义final整型数组 BG_FIRST_RESOURCES + R.drawable.list_yellow_up,//黄色背景上边框图案id + R.drawable.list_blue_up,//蓝色背景上边框图案id + R.drawable.list_white_up,//白色背景边框图案id + R.drawable.list_green_up,//绿色背景边框图案id + R.drawable.list_red_up//红色背景边框图案id }; private final static int [] BG_NORMAL_RESOURCES = new int [] { - R.drawable.list_yellow_middle, - R.drawable.list_blue_middle, - R.drawable.list_white_middle, - R.drawable.list_green_middle, - R.drawable.list_red_middle + R.drawable.list_yellow_middle,//黄色背景中间边框图案id + R.drawable.list_blue_middle,//蓝色背景中间边框图案id + R.drawable.list_white_middle,//白色背景中间边框图案id + R.drawable.list_green_middle,//绿色背景中间边框图案id + R.drawable.list_red_middle//红色背景中间边框图案id }; 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_yellow_down,//黄色背景中下间边框图案id + R.drawable.list_blue_down,//蓝色背景中下间边框图案id + R.drawable.list_white_down,//白色背景中下间边框图案id + R.drawable.list_green_down,//绿色背景中下间边框图案id + R.drawable.list_red_down,//红色背景中下间边框图案id }; private final static int [] BG_SINGLE_RESOURCES = new int [] { @@ -110,33 +110,30 @@ public class ResourceParser { public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } - +//定义getNoteBgFirstRes方法,用于返回G_FIRST_RESOURCES[id] public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } - +//定义getNoteBgLastRes方法,用于返回 BG_LAST_RESOURCES[id] public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } - + //定义getNoteBgSingleRes方法,用于返回BG_SINGLE_RESOURCES[id] public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } - - public static int getFolderBgRes() { - return R.drawable.list_folder; - } + //定义etNoteBgNormalRes方法,用于返回BG_NORMAL_RESOURCES[id] + public static int getFolderBgRes() {return R.drawable.list_folder;}//定义getFolderBgRes方法,用于返回 R.drawable.list_folder } - public static class WidgetBgResources { + public static class WidgetBgResources {//定义静态内部类WidgetBgResources 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, - }; - + };// 管理小部件2x2格式不同颜色资源图片 public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } @@ -147,20 +144,20 @@ public class ResourceParser { R.drawable.widget_4x_white, R.drawable.widget_4x_green, R.drawable.widget_4x_red - }; + };// 管理小部件4x4格式不同颜色资源图片 public static int getWidget4xBgResource(int id) { return BG_4X_RESOURCES[id]; } } - public static class TextAppearanceResources { + public static class TextAppearanceResources {//定义TextAppearanceResources 静态内部类 private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { R.style.TextAppearanceNormal, R.style.TextAppearanceMedium, R.style.TextAppearanceLarge, R.style.TextAppearanceSuper - }; + };//分别对应中等,大号,超大的文本外观样式 public static int getTexAppearanceResource(int id) { /** diff --git a/src/widget/NoteWidgetProvider.java b/src/widget/NoteWidgetProvider.java index ec6f819..4661c89 100644 --- a/src/widget/NoteWidgetProvider.java +++ b/src/widget/NoteWidgetProvider.java @@ -37,33 +37,33 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { NoteColumns.ID, NoteColumns.BG_COLOR_ID, NoteColumns.SNIPPET - }; + };//定义字符串数组PROJECTION,包含IDB G_COLOR_ID SNIPPET三个元素 public static final int COLUMN_ID = 0; public static final int COLUMN_BG_COLOR_ID = 1; - public static final int COLUMN_SNIPPET = 2; + public static final int COLUMN_SNIPPET = 2;//定义三个元素初始量 private static final String TAG = "NoteWidgetProvider"; @Override - public void onDeleted(Context context, int[] appWidgetIds) { + public void onDeleted(Context context, int[] appWidgetIds) {//创建一个ContentValues对象values存储键值对数据 ContentValues values = new ContentValues(); - values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);//将无效小部件id存储ContentValues中 for (int i = 0; i < appWidgetIds.length; i++) { context.getContentResolver().update(Notes.CONTENT_NOTE_URI, values, NoteColumns.WIDGET_ID + "=?", - new String[] { String.valueOf(appWidgetIds[i])}); + new String[] { String.valueOf(appWidgetIds[i])});//通过getcontent函数获取程序contentValues对象,用update方法更新 } } private Cursor getNoteWidgetInfo(Context context, int widgetId) { return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, - PROJECTION, + PROJECTION,//获取ContentResovler对象,并用querty方法查询数据· NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?", new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) }, null); - } + }//null表示默认排序方式 protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { update(context, appWidgetManager, appWidgetIds, false); @@ -71,12 +71,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, boolean privacyMode) { - for (int i = 0; i < appWidgetIds.length; i++) { + for (int i = 0; i < appWidgetIds.length; i++) {//判断当前小部件id是否合法,若合法才可进行操作 if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { - int bgId = ResourceParser.getDefaultBgId(context); + int bgId = ResourceParser.getDefaultBgId(context);//获取默认背景图片id,并将其作为当前部件的背景 String snippet = ""; Intent intent = new Intent(context, NoteEditActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);//创建internet对象,设置flag标志 intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]); intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType()); @@ -86,14 +86,14 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]); c.close(); return; - } + }//判断数据库查询结果c是否为空,若查询结果大于1,则记录日志错误并返回 snippet = c.getString(COLUMN_SNIPPET); bgId = c.getInt(COLUMN_BG_COLOR_ID); intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID)); - intent.setAction(Intent.ACTION_VIEW); + intent.setAction(Intent.ACTION_VIEW);//将当前记录id作为extra数据存入启动internet对象中 } else { snippet = context.getResources().getString(R.string.widget_havenot_content); - intent.setAction(Intent.ACTION_INSERT_OR_EDIT); + intent.setAction(Intent.ACTION_INSERT_OR_EDIT);//// 数据库查询结果为空或者未能成功移动到第一条记录时,将片段内容设置为默认字符串 } if (c != null) { @@ -107,16 +107,16 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { * Generate the pending intent to start host for the widget */ PendingIntent pendingIntent = null; - if (privacyMode) { + if (privacyMode) {// 判断是否处于隐私模式 rv.setTextViewText(R.id.widget_text, context.getString(R.string.widget_under_visit_mode)); pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent( - context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); + context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);// 如果是,将小部件文本设置为“访问模式下”,并创建一个PendingIntent,使点击小部件时跳转至NotesListActivity } else { rv.setTextViewText(R.id.widget_text, snippet); pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent, PendingIntent.FLAG_UPDATE_CURRENT); - } + }// 如果不是,将小部件文本设置为片段内容,并创建一个PendingIntent,使点击小部件时跳转至NoteEditActivity rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], rv); @@ -128,5 +128,5 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { protected abstract int getLayoutId(); - protected abstract int getWidgetType(); + protected abstract int getWidgetType();//获取背景资源id,布局资源id,小部件类型 } diff --git a/src/widget/NoteWidgetProvider_2x.java b/src/widget/NoteWidgetProvider_2x.java index adcb2f7..40dd783 100644 --- a/src/widget/NoteWidgetProvider_2x.java +++ b/src/widget/NoteWidgetProvider_2x.java @@ -28,20 +28,21 @@ public class NoteWidgetProvider_2x extends NoteWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.update(context, appWidgetManager, appWidgetIds); - } + }//NoteWidgetProvider_2x是一个继承自NoteWidgetProvider的小部件提供者,用于显示2x大小的便签小部件。 + //调用父类的update方法,更新小部件UI界面 @Override protected int getLayoutId() { return R.layout.widget_2x; - } + }//获取2x大小便签小部件布局资源ID,由子类具体实现 @Override protected int getBgResourceId(int bgId) { return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); - } + }//获取2x大小便签小部件背景资源ID,由子类具体实现。 @Override protected int getWidgetType() { return Notes.TYPE_WIDGET_2X; - } + }//获取小部件类型,由子类具体实现,返回值为Notes.TYPE_WIDGET_2X } diff --git a/src/widget/NoteWidgetProvider_4x.java b/src/widget/NoteWidgetProvider_4x.java index c12a02e..6a3b077 100644 --- a/src/widget/NoteWidgetProvider_4x.java +++ b/src/widget/NoteWidgetProvider_4x.java @@ -28,19 +28,20 @@ public class NoteWidgetProvider_4x extends NoteWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.update(context, appWidgetManager, appWidgetIds); - } + }//NoteWidgetProvider_4x是一个继承自NoteWidgetProvider的小部件提供者,用于显示4x大小的便签小部件。 + //调用父类的update方法,更新小部件UI界面 protected int getLayoutId() { return R.layout.widget_4x; - } + }//获取4x大小便签小部件布局资源ID,由子类具体实现 @Override protected int getBgResourceId(int bgId) { return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); - } + }//获取4x大小便签小部件背景资源ID,由子类具体实现。 @Override protected int getWidgetType() { return Notes.TYPE_WIDGET_4X; - } + }//获取小部件类型,由子类具体实现,返回值为Notes.TYPE_WIDGET_4X }