diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..69b28af --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/doc/小米便签开源代码的泛读报告.docx b/doc/小米便签开源代码的泛读报告.docx index 9b26d39..2a5d451 100644 Binary files a/doc/小米便签开源代码的泛读报告.docx and b/doc/小米便签开源代码的泛读报告.docx differ diff --git a/model/小米便签总览.png b/model/小米便签总览.png new file mode 100644 index 0000000..b742a09 Binary files /dev/null and b/model/小米便签总览.png differ diff --git a/model/类图示例.png b/model/类图示例.png deleted file mode 100644 index 1a0137c..0000000 Binary files a/model/类图示例.png and /dev/null differ diff --git a/other/1.txt b/other/1.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/Notes/.gradle/7.5/executionHistory/executionHistory.bin b/src/Notes/.gradle/7.5/executionHistory/executionHistory.bin index 22a8c0e..e173240 100644 Binary files a/src/Notes/.gradle/7.5/executionHistory/executionHistory.bin and b/src/Notes/.gradle/7.5/executionHistory/executionHistory.bin differ diff --git a/src/Notes/.gradle/7.5/executionHistory/executionHistory.lock b/src/Notes/.gradle/7.5/executionHistory/executionHistory.lock index e89f9cc..bd146c4 100644 Binary files a/src/Notes/.gradle/7.5/executionHistory/executionHistory.lock and b/src/Notes/.gradle/7.5/executionHistory/executionHistory.lock differ diff --git a/src/Notes/.gradle/7.5/fileHashes/fileHashes.bin b/src/Notes/.gradle/7.5/fileHashes/fileHashes.bin index 5583ae3..7804106 100644 Binary files a/src/Notes/.gradle/7.5/fileHashes/fileHashes.bin and b/src/Notes/.gradle/7.5/fileHashes/fileHashes.bin differ diff --git a/src/Notes/.gradle/7.5/fileHashes/fileHashes.lock b/src/Notes/.gradle/7.5/fileHashes/fileHashes.lock index 3472fbd..8ab4c64 100644 Binary files a/src/Notes/.gradle/7.5/fileHashes/fileHashes.lock and b/src/Notes/.gradle/7.5/fileHashes/fileHashes.lock differ diff --git a/src/Notes/.gradle/7.5/fileHashes/resourceHashesCache.bin b/src/Notes/.gradle/7.5/fileHashes/resourceHashesCache.bin index 320f5e4..3707989 100644 Binary files a/src/Notes/.gradle/7.5/fileHashes/resourceHashesCache.bin and b/src/Notes/.gradle/7.5/fileHashes/resourceHashesCache.bin differ diff --git a/src/Notes/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/src/Notes/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 14ff06a..954fdfe 100644 Binary files a/src/Notes/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/src/Notes/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/Notes/.gradle/buildOutputCleanup/outputFiles.bin b/src/Notes/.gradle/buildOutputCleanup/outputFiles.bin index 49619d2..1d2c594 100644 Binary files a/src/Notes/.gradle/buildOutputCleanup/outputFiles.bin and b/src/Notes/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/src/Notes/.gradle/file-system.probe b/src/Notes/.gradle/file-system.probe index 5d8fbb8..efea422 100644 Binary files a/src/Notes/.gradle/file-system.probe and b/src/Notes/.gradle/file-system.probe differ diff --git a/src/Notes/app/src/main/AndroidManifest.xml b/src/Notes/app/src/main/AndroidManifest.xml index 0313cd1..41511bc 100644 --- a/src/Notes/app/src/main/AndroidManifest.xml +++ b/src/Notes/app/src/main/AndroidManifest.xml @@ -21,7 +21,6 @@ android:versionCode="1" android:versionName="0.1" > - @@ -40,8 +39,6 @@ android:icon="@drawable/icon_app" android:label="@string/app_name" > - - @@ -60,9 +57,6 @@ - - - - - - - - - - - - - @@ -158,9 +142,6 @@ android:process=":remote" > - - - " + Notes.ID_TRASH_FOLER + ") OR " + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); - if (folderCursor != null) { + if (folderCursor != null) {//导出文件夹,把里面的便签导出来 if (folderCursor.moveToFirst()) { do { // Print folder's name @@ -258,13 +261,13 @@ public class BackupUtils { } // Export notes in root's folder - Cursor noteCursor = mContext.getContentResolver().query( + 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 != null) {//输出修改的时间 if (noteCursor.moveToFirst()) { do { ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( @@ -285,17 +288,17 @@ public class BackupUtils { /** * Get a print stream pointed to the file {@generateExportedTextFile} */ - private PrintStream getExportToTextPrintStream() { + 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); + }//初始化储存在SD卡中的文件,如果为空,创造失败 + mFileName = file.getName();//得到文件名 + mFileDirectory = mContext.getString(R.string.file_path);//得到文件路径 PrintStream ps = null; - try { + try {//将ps输出流输出到特定的文件,目的就是导出到文件,而不是直接输出 FileOutputStream fos = new FileOutputStream(file); ps = new PrintStream(fos); } catch (FileNotFoundException e) { @@ -313,6 +316,7 @@ public class BackupUtils { * Generate the text file to store imported data */ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { + //生成存储文件,安装在SD卡上 StringBuilder sb = new StringBuilder(); sb.append(Environment.getExternalStorageDirectory()); sb.append(context.getString(filePathResId)); @@ -323,7 +327,7 @@ public class BackupUtils { System.currentTimeMillis()))); File file = new File(sb.toString()); - try { + try {//如果这些文件不存在,则新建 if (!filedir.exists()) { filedir.mkdir(); } diff --git a/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java b/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java index 2a14982..f1b6ddc 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -35,10 +35,10 @@ import java.util.ArrayList; import java.util.HashSet; -public class DataUtils { +public class DataUtils {//定义便签的处理工具类 public static final String TAG = "DataUtils"; - public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { - if (ids == null) { + public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) {//一个处理批量删除便签的方法 + if (ids == null) {//判断笔记是否为空 Log.d(TAG, "the ids is null"); return true; } @@ -48,23 +48,23 @@ public class DataUtils { } ArrayList operationList = new ArrayList(); - for (long id : ids) { + for (long id : ids) {//遍历便签id if(id == Notes.ID_ROOT_FOLDER) { - Log.e(TAG, "Don't delete system folder root"); + Log.e(TAG, "Don't delete system folder root");//.如果是根目录的文件夹,输出Don't delete system folder root continue; } - ContentProviderOperation.Builder builder = ContentProviderOperation + ContentProviderOperation.Builder builder = ContentProviderOperation//批量的删除对应的ID .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); operationList.add(builder.build()); } - try { + try {//返回被删除的数据,如果返回为空则删除失败返回false,打印异常信息,删除成功返回true 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; - } catch (RemoteException e) { + } 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())); @@ -73,6 +73,7 @@ public class DataUtils { } 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); @@ -80,7 +81,7 @@ public class DataUtils { resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } - public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, + public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids,//批量移动 long folderId) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -88,7 +89,7 @@ public class DataUtils { } 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); @@ -96,7 +97,7 @@ public class DataUtils { operationList.add(builder.build()); } - try { + try {//错误检测 ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); if (results == null || results.length == 0 || results[0] == null) { Log.d(TAG, "delete notes failed, ids:" + ids.toString()); @@ -114,7 +115,7 @@ public class DataUtils { /** * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} */ - public static int getUserFolderCount(ContentResolver resolver) { + public static int getUserFolderCount(ContentResolver resolver) {//得到文件夹数目 Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, new String[] { "COUNT(*)" }, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", @@ -136,14 +137,14 @@ public class DataUtils { return count; } - public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { + 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); - boolean exist = false; + boolean exist = false;//判断note是否在数据库中,并返回相应的布尔值 if (cursor != null) { if (cursor.getCount() > 0) { exist = true; @@ -153,7 +154,7 @@ public class DataUtils { return exist; } - public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { + public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {//通过便签ID搜索,判断该note是否在数据库中存在 Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, null, null, null); @@ -167,7 +168,7 @@ public class DataUtils { return exist; } - public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { + public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {//通过名字查询是否在数据库中存在 Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null, null, null, null); @@ -181,7 +182,7 @@ public class DataUtils { return exist; } - public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { + 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 + @@ -197,7 +198,7 @@ public class DataUtils { return exist; } - public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { + 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 + "=?", @@ -209,12 +210,12 @@ public class DataUtils { if (c.moveToFirst()) { set = new HashSet(); do { - try { + try {//把每一个条目对应的窗口id和type记录下来,放到set里面。 AppWidgetAttribute widget = new AppWidgetAttribute(); widget.widgetId = c.getInt(0); widget.widgetType = c.getInt(1); set.add(widget); - } catch (IndexOutOfBoundsException e) { + } catch (IndexOutOfBoundsException e) {//当下标超过边界,那么返回错误 Log.e(TAG, e.toString()); } } while (c.moveToNext()); @@ -224,14 +225,14 @@ public class DataUtils { return set; } - public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { + public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {//通过笔记ID获取号码 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); - if (cursor != null && cursor.moveToFirst()) { + if (cursor != null && cursor.moveToFirst()) {//获取电话号码,并处理异常 try { return cursor.getString(0); } catch (IndexOutOfBoundsException e) { @@ -243,7 +244,7 @@ public class DataUtils { return ""; } - public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { + public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {//通过号码和日期获取ID Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.NOTE_ID }, CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" @@ -264,7 +265,7 @@ public class DataUtils { return 0; } - public static String getSnippetById(ContentResolver resolver, long noteId) { + public static String getSnippetById(ContentResolver resolver, long noteId) {//通过Note的Id获取Note的片段 Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, new String [] { NoteColumns.SNIPPET }, NoteColumns.ID + "=?", @@ -282,7 +283,7 @@ public class DataUtils { throw new IllegalArgumentException("Note is not found with id: " + noteId); } - public static String getFormattedSnippet(String snippet) { + public static String getFormattedSnippet(String snippet) {//格式化,对字符串进行格式处理,将字符串两头的空格去掉,同时将换行符去掉 if (snippet != null) { snippet = snippet.trim(); int index = snippet.indexOf('\n'); diff --git a/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java index 666b729..248e550 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java @@ -17,7 +17,8 @@ package net.micode.notes.tool; public class GTaskStringUtils { - +//定义了很多的静态字符串,目的就是为了提供jsonObject中相应字符串的"key" + //把这些静态的定义单独写到了一个类里面,是非常好的编程规范 public final static String GTASK_JSON_ACTION_ID = "action_id"; public final static String GTASK_JSON_ACTION_LIST = "action_list"; diff --git a/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..e5c0131 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/src/Notes/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -23,7 +23,7 @@ import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; public class ResourceParser { - +//ResourceParser类,资源分析,实际上就是获取资源并且在程序中使用,比如图片资源、布局资源、字体大小等 public static final int YELLOW = 0; public static final int BLUE = 1; public static final int WHITE = 2; @@ -39,7 +39,7 @@ public class ResourceParser { public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; - public static class NoteBgResources { + public static class NoteBgResources {//背景资源的获取 private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, R.drawable.edit_blue, @@ -59,13 +59,13 @@ public class ResourceParser { public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } - +//获取Note的背景颜色 public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } - - public static int getDefaultBgId(Context context) { +//ID可以查找到编辑框的颜色的地址 + 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); @@ -74,7 +74,7 @@ public class ResourceParser { } } - public static class NoteItemBgResources { + public static class NoteItemBgResources {//便签背景资源类 private final static int [] BG_FIRST_RESOURCES = new int [] { R.drawable.list_yellow_up, R.drawable.list_blue_up, @@ -128,8 +128,8 @@ public class ResourceParser { } } - public static class WidgetBgResources { - private final static int [] BG_2X_RESOURCES = new int [] { + public static class WidgetBgResources {//获取图片资源类 + private final static int [] BG_2X_RESOURCES = new int [] {//通过id获得2x的小窗口背景资源 R.drawable.widget_2x_yellow, R.drawable.widget_2x_blue, R.drawable.widget_2x_white, @@ -140,7 +140,7 @@ public class ResourceParser { public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } - +//通过ID获取较小的图片 private final static int [] BG_4X_RESOURCES = new int [] { R.drawable.widget_4x_yellow, R.drawable.widget_4x_blue, @@ -153,7 +153,7 @@ public class ResourceParser { return BG_4X_RESOURCES[id]; } } - +//根据ID加载BG_4X_RESOURCES数组里的颜色资源序号。 public static class TextAppearanceResources { private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { R.style.TextAppearanceNormal, @@ -161,7 +161,7 @@ public class ResourceParser { R.style.TextAppearanceLarge, R.style.TextAppearanceSuper }; - +//文本外观资源,包括默认字体,以及获取资源大小 public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference. @@ -173,9 +173,10 @@ public class ResourceParser { } return TEXTAPPEARANCE_RESOURCES[id]; } - +//防止输入的id大于资源总量,若如此,则自动返回默认的设置结果 public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; } } } +//直接返回为资源的长度 \ No newline at end of file diff --git a/src/Notes/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/Notes/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..387c03a 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/Notes/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -63,6 +63,7 @@ import net.micode.notes.tool.ResourceParser.TextAppearanceResources; import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener; import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener; import net.micode.notes.widget.NoteWidgetProvider_2x; +import net.micode.notes.widget.NoteWidgetProvider_3x; import net.micode.notes.widget.NoteWidgetProvider_4x; import java.util.HashMap; @@ -412,8 +413,10 @@ public class NoteEditActivity extends Activity implements OnClickListener, intent.setClass(this, NoteWidgetProvider_2x.class); } else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) { intent.setClass(this, NoteWidgetProvider_4x.class); + } else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_3X) { + intent.setClass(this, NoteWidgetProvider_3x.class); } else { - Log.e(TAG, "Unspported widget type"); + Log.e(TAG, "Unsupported widget type"); return; } @@ -430,7 +433,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, if (id == R.id.btn_set_bg_color) { mNoteBgColorSelector.setVisibility(View.VISIBLE); findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( - - View.VISIBLE); + View.VISIBLE); } else if (sBgSelectorBtnsMap.containsKey(id)) { findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( View.GONE); diff --git a/src/Notes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/Notes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java index e843aec..c00449e 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/src/Notes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -70,6 +70,7 @@ import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import net.micode.notes.widget.NoteWidgetProvider_2x; +import net.micode.notes.widget.NoteWidgetProvider_3x; import net.micode.notes.widget.NoteWidgetProvider_4x; import java.io.BufferedReader; @@ -141,7 +142,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt setContentView(R.layout.note_list); initResources(); - /** + /* * Insert an introduction when user firstly use this application */ setAppInfoFromRawRes(); @@ -694,6 +695,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt intent.setClass(this, NoteWidgetProvider_2x.class); } else if (appWidgetType == Notes.TYPE_WIDGET_4X) { intent.setClass(this, NoteWidgetProvider_4x.class); + } else if (appWidgetType == Notes.TYPE_WIDGET_3X) { + intent.setClass(this, NoteWidgetProvider_3x.class); } else { Log.e(TAG, "Unspported widget type"); return; diff --git a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java index ec6f819..b27c0e6 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java +++ b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java @@ -32,7 +32,8 @@ import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListActivity; -public abstract class NoteWidgetProvider extends AppWidgetProvider { +// 该类实现了桌面中的窗口小部件 +public abstract class NoteWidgetProvider extends AppWidgetProvider { // 小米便签窗口小部件 public static final String [] PROJECTION = new String [] { NoteColumns.ID, NoteColumns.BG_COLOR_ID, @@ -46,7 +47,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { private static final String TAG = "NoteWidgetProvider"; @Override - public void onDeleted(Context context, int[] appWidgetIds) { + public void onDeleted(Context context, int[] appWidgetIds) { // 重写删除窗口小部件函数 ContentValues values = new ContentValues(); values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); for (int i = 0; i < appWidgetIds.length; i++) { @@ -57,7 +58,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { } } - private Cursor getNoteWidgetInfo(Context context, int widgetId) { + private Cursor getNoteWidgetInfo(Context context, int widgetId) { // 获取窗口小部件宽度信息 return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?", @@ -70,7 +71,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { } private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, - boolean privacyMode) { + boolean privacyMode) { // 更新窗口小部件中的内容 for (int i = 0; i < appWidgetIds.length; i++) { if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { int bgId = ResourceParser.getDefaultBgId(context); @@ -124,9 +125,9 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { } } - protected abstract int getBgResourceId(int bgId); + protected abstract int getBgResourceId(int bgId); // 从背景资源中获取当前应用ID - protected abstract int getLayoutId(); + protected abstract int getLayoutId(); // 获取布局ID - protected abstract int getWidgetType(); + protected abstract int getWidgetType(); // 获取窗口小部件的类型,即2x2型或者4x4型 } diff --git a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java index adcb2f7..2cff856 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java +++ b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java @@ -24,23 +24,23 @@ import net.micode.notes.data.Notes; import net.micode.notes.tool.ResourceParser; -public class NoteWidgetProvider_2x extends NoteWidgetProvider { - @Override +public class NoteWidgetProvider_2x extends NoteWidgetProvider { // 2x2大小的窗口小部件 + @Override // 重写窗口小部件中的更新函数 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.update(context, appWidgetManager, appWidgetIds); } - @Override + @Override // 重写窗口小部件中的获取布局ID函数 protected int getLayoutId() { return R.layout.widget_2x; } - @Override + @Override // 重写窗口小部件中的获取资源ID函数 protected int getBgResourceId(int bgId) { return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); } - @Override + @Override // 重写窗口小部件中的获取宽度类型函数 protected int getWidgetType() { return Notes.TYPE_WIDGET_2X; } diff --git a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_3x.java b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_3x.java new file mode 100644 index 0000000..9626f78 --- /dev/null +++ b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_3x.java @@ -0,0 +1,31 @@ +package net.micode.notes.widget; + +import android.appwidget.AppWidgetManager; +import android.content.Context; + +import net.micode.notes.R; +import net.micode.notes.data.Notes; +import net.micode.notes.tool.ResourceParser; + +public class NoteWidgetProvider_3x extends NoteWidgetProvider{ // 3x3大小的窗口小部件 + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + super.update(context, appWidgetManager, appWidgetIds); + } + + @Override // 重写窗口小部件中的获取布局ID函数 + protected int getLayoutId() { + return R.layout.widget_3x; + } + + @Override // 重写窗口小部件中的获取资源ID函数 + protected int getBgResourceId(int bgId) { + return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); + } + + @Override // 重写窗口小部件中的获取宽度类型函数 + protected int getWidgetType() { + return Notes.TYPE_WIDGET_3X; + } +} diff --git a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java index c12a02e..280efd3 100644 --- a/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java +++ b/src/Notes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java @@ -24,22 +24,23 @@ import net.micode.notes.data.Notes; import net.micode.notes.tool.ResourceParser; -public class NoteWidgetProvider_4x extends NoteWidgetProvider { - @Override +public class NoteWidgetProvider_4x extends NoteWidgetProvider { // 4x4大小的窗口小部件 + @Override // 重写窗口小部件中的更新函数 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.update(context, appWidgetManager, appWidgetIds); } + @Override // 重写窗口小部件中的获取布局ID函数 protected int getLayoutId() { return R.layout.widget_4x; } - @Override + @Override // 重写窗口小部件中的获取资源ID函数 protected int getBgResourceId(int bgId) { return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); } - @Override + @Override // 重写窗口小部件中的获取宽度类型函数 protected int getWidgetType() { return Notes.TYPE_WIDGET_4X; } diff --git a/src/Notes/app/src/main/res/layout/widget_3x.xml b/src/Notes/app/src/main/res/layout/widget_3x.xml new file mode 100644 index 0000000..fe359f8 --- /dev/null +++ b/src/Notes/app/src/main/res/layout/widget_3x.xml @@ -0,0 +1,22 @@ + + + + + +