diff --git a/Desktop/xiaomi1/doc/王心懿小米便签博客.docx b/Desktop/xiaomi1/doc/王心懿小米便签博客.docx new file mode 100644 index 0000000..d53c34d Binary files /dev/null and b/Desktop/xiaomi1/doc/王心懿小米便签博客.docx differ diff --git a/Desktop/xiaomi1/doc/王心懿,马忠秀小米便签开源代码的泛读报告.docx b/Desktop/xiaomi1/doc/王心懿,马忠秀小米便签开源代码的泛读报告.docx new file mode 100644 index 0000000..7da3a46 Binary files /dev/null and b/Desktop/xiaomi1/doc/王心懿,马忠秀小米便签开源代码的泛读报告.docx differ diff --git a/Desktop/xiaomi1/doc/运行结果.docx b/Desktop/xiaomi1/doc/运行结果.docx new file mode 100644 index 0000000..6e494a7 Binary files /dev/null and b/Desktop/xiaomi1/doc/运行结果.docx differ diff --git a/Desktop/xiaomi1/doc/马忠秀博客.docx b/Desktop/xiaomi1/doc/马忠秀博客.docx new file mode 100644 index 0000000..a955832 Binary files /dev/null and b/Desktop/xiaomi1/doc/马忠秀博客.docx differ diff --git a/Desktop/xiaomi1/src/model/Note.java b/Desktop/xiaomi1/src/model/Note.java new file mode 100644 index 0000000..2d20433 --- /dev/null +++ b/Desktop/xiaomi1/src/model/Note.java @@ -0,0 +1,49 @@ +// 版权声明 +Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + +// 许可证声明 +Licensed under the Apache License, Version 2.0 (the "License"); +// 你必须遵守该许可证的条款才能使用这段代码 +you may not use this file except in compliance with the License. +// 你可以通过以下链接获取许可证的副本 +You may obtain a copy of the License at + +// 许可证链接 +http://www.apache.org/licenses/LICENSE-2.0 + +// 许可证条款 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +// 以下是代码部分 + +// 调用ContentResolver的applyBatch方法,传入Authority和操作列表 +// Notes.AUTHORITY是内容提供者的Authority +// operationList是包含要执行的操作的列表 +// 如果操作结果为空、长度为0或第一个结果为空,则返回null,否则返回带有ID的笔记URI +return (results == null || results.length == 0 || results[0] == null) ? null + : ContentUris.withAppendedId(Notes.CONTENTNOTEURI, noteId); + +// 捕获远程异常 +catch (RemoteException e) { + // 记录远程异常错误日志 + // TAG是日志的标签,e.toString()是异常的字符串表示,e.getMessage()是异常的消息 + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + // 返回null,表示操作失败 + return null; +} + +// 捕获操作应用异常 +catch (OperationApplicationException e) { + // 记录操作应用异常错误日志 + // TAG是日志的标签,e.toString()是异常的字符串表示,e.getMessage()是异常的消息 + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + // 返回null,表示操作失败 + return null; +} + +// 如果没有操作要应用,则返回null +return null; diff --git a/Desktop/xiaomi1/src/model/WorkingNote.java b/Desktop/xiaomi1/src/model/WorkingNote.java new file mode 100644 index 0000000..e9c41e0 --- /dev/null +++ b/Desktop/xiaomi1/src/model/WorkingNote.java @@ -0,0 +1,425 @@ + +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *//* + * 版权声明,声明这段代码的版权属于MiCode开源社区,网址为www.micode.net + */ +/* + * 许可证声明,声明这段代码遵循Apache许可证2.0版本 + * 你不能使用这个文件,除非你遵守许可证。 + * 你可以在以下网址获得许可证的副本: + */ +/* + * 除非适用法律要求或书面同意,否则根据许可证分发的软件将按原样”基础分发, + * 不提供任何明示或暗示的保证或条件。 + * 请参阅许可证以获取特定语言的权限和限制。 + */ + +package net.micode.notes.model; + +// 导入AppWidgetManager类,用于管理AppWidget +import android.appwidget.AppWidgetManager; +// 导入ContentUris类,用于操作内容URI +import android.content.ContentUris; +// 导入Context类,用于获取应用程序环境 +import android.content.Context; +// 导入Cursor类,用于数据库查询结果 +import android.database.Cursor; +// 导入TextUtils类,用于字符串操作 +import android.text.TextUtils; +// 导入Log类,用于日志记录 +import android.util.Log; + +// 导入Notes类,用于操作笔记数据 +import net.micode.notes.data.Notes; +// 导入Notes.CallNote类,用于操作电话笔记数据 +import net.micode.notes.data.Notes.CallNote; +// 导入Notes.DataColumns类,用于操作笔记数据列 +import net.micode.notes.data.Notes.DataColumns; +// 导入Notes.DataConstants类,用于操作笔记数据常量 +import net.micode.notes.data.Notes.DataConstants; +// 导入Notes.NoteColumns类,用于操作笔记列 +import net.micode.notes.data.Notes.NoteColumns; +// 导入Notes.TextNote类,用于操作文本笔记数据 +import net.micode.notes.data.Notes.TextNote; +// 导入ResourceParser.NoteBgResources类,用于获取笔记背景资源 +import net.micode.notes.tool.ResourceParser.NoteBgResources; + +// 定义WorkingNote类,用于操作工作笔记 +public class WorkingNote { + // 工作笔记的Note对象 + private Note mNote; + // 工作笔记的ID + private long mNoteId; + // 工作笔记的内容 + private String mContent; + // 工作笔记的模式 + private int mMode; + + private long mAlertDate; + + private long mModifiedDate; + + private int mBgColorId; + + private int mWidgetId; + + private int mWidgetType; + + private long mFolderId; + + private Context mContext; + + private static final String TAG = "WorkingNote"; + + private boolean mIsDeleted; + + private NoteSettingChangedListener mNoteSettingStatusListener; + + // 定义数据列投影数组,用于查询数据列 + public static final String[] DATA_PROJECTION = new String[] { + DataColumns.ID, + DataColumns.CONTENT, + DataColumns.MIME_TYPE, + DataColumns.DATA1, + DataColumns.DATA2, + DataColumns.DATA3, + DataColumns.DATA4, + }; + + // 定义笔记列投影数组,用于查询笔记列 + public static final String[] NOTE_PROJECTION = new String[] { + NoteColumns.PARENT_ID, + NoteColumns.ALERTED_DATE, + NoteColumns.BG_COLOR_ID, + NoteColumns.WIDGET_ID, + NoteColumns.WIDGET_TYPE, + NoteColumns.MODIFIED_DATE + }; + + private static final int DATA_ID_COLUMN = 0; + + private static final int DATA_CONTENT_COLUMN = 1; + + private static final int DATA_MIME_TYPE_COLUMN = 2; + + private static final int DATA_MODE_COLUMN = 3; + + private static final int NOTE_PARENT_ID_COLUMN = 0; + + private static final int NOTE_ALERTED_DATE_COLUMN = 1; + + private static final int NOTE_BG_COLOR_ID_COLUMN = 2; + + private static final int NOTE_WIDGET_ID_COLUMN = 3; + + private static final int NOTE_WIDGET_TYPE_COLUMN = 4; + + private static final int NOTE_MODIFIED_DATE_COLUMN = 5; + + // 新笔记构造函数 + private WorkingNote(Context context, long folderId) { + mContext = context; + mAlertDate = 0; + mModifiedDate = System.currentTimeMillis(); + mFolderId = folderId; + mNote = new Note(); + mNoteId = 0; + mIsDeleted = false; + mMode = 0; + mWidgetType = Notes.TYPE_WIDGET_INVALIDE; + } + + // 现有笔记构造函数 + private WorkingNote(Context context, long noteId, long folderId) { + mContext = context; + mNoteId = noteId; + mFolderId = folderId; + mIsDeleted = false; + mNote = new Note(); + loadNote(); + } + + // 加载笔记 + private void loadNote() { + Cursor cursor = mContext.getContentResolver().query( + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, + null, null); + + if (cursor != null) { + if (cursor.moveToFirst()) { + mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN); + mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN); + mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN); + mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN); + mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); + mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); + } + cursor.close(); + } else { + Log.e(TAG, "No note with id:" + mNoteId); + throw new IllegalArgumentException("Unable to find note with id " + mNoteId); + } + loadNoteData(); + } + + // 加载笔记数据 + private void loadNoteData() { + Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, + DataColumns.NOTE_ID + "=?", new String[] { + String.valueOf(mNoteId) + }, null); + + if (cursor != null) { + if (cursor.moveToFirst()) { + do { + String type = cursor.getString(DATA_MIME_TYPE_COLUMN); + if (DataConstants.NOTE.equals(type)) { + mContent = cursor.getString(DATA_CONTENT_COLUMN); + mMode = cursor.getInt(DATA_MODE_COLUMN); + mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN)); + } else if (DataConstants.CALL_NOTE.equals(type)) { + mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN)); + } else { + Log.d(TAG, "Wrong note type with type:" + type); + } + } while (cursor.moveToNext()); + } + cursor.close(); + } else { + Log.e(TAG, "No data with id:" + mNoteId); + throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId); + } + } + + // 创建空笔记 + public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, + int widgetType, int defaultBgColorId) { + WorkingNote note = new WorkingNote(context, folderId); + note.setBgColorId(defaultBgColorId); + note.setWidgetId(widgetId); + note.setWidgetType(widgetType); + return note; + } + + // 加载笔记 + public static WorkingNote load(Context context, long id) { + return new WorkingNote(context, id, 0); + } + + // 保存笔记 + public synchronized boolean saveNote() { + if (isWorthSaving()) { + if (!existInDatabase()) { + if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { + Log.e(TAG, "Create new note fail with id:" + mNoteId); + return false; + } + } + + mNote.syncNote(mContext, mNoteId); + + /** + * 更新小部件内容(如果存在此笔记的小部件) + */ + if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID + && mWidgetType != Notes.TYPE_WIDGET_INVALIDE + && mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onWidgetChanged(); + } + return true; + } else { + return false; + } + } + + // 检查笔记是否存在于数据库中 + public boolean existInDatabase() { + return mNoteId > 0; + } + + // 检查笔记是否值得保存 + private boolean isWorthSaving() { + if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) + || (existInDatabase() && !mNote.isLocalModified())) { + return false; + } else { + return true; + } + } + + // 设置设置状态更改监听器 + public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { + mNoteSettingStatusListener = l; + } + + // 设置提醒日期 + public void setAlertDate(long date, boolean set) { + if (date != mAlertDate) { + mAlertDate = date; + mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate)); + } + if (mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onClockAlertChanged(date, set); + } + } + + // 标记删除 + public void markDeleted(boolean mark) { + mIsDeleted = mark; + if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID + && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onWidgetChanged(); + } + } + + // 设置背景颜色ID + public void setBgColorId(int id) { + if (id != mBgColorId) { + mBgColorId = id; + if (mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onBackgroundColorChanged(); + } + mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); + } + } + + // 设置检查列表模式 + public void setCheckListMode(int mode) { + if (mMode != mode) { + if (mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); + } + mMode = mode; + mNote.setTextData(TextNote.MODE, String.valueOf(mMode)); + } + } + + // 设置小部件类型 + public void setWidgetType(int type) { + if (type != mWidgetType) { + mWidgetType = type; + mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); + } + } + + // 设置小部件ID + public void setWidgetId(int id) { + if (id != mWidgetId) { + mWidgetId = id; + mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); + } + } + + // 设置工作文本 + public void setWorkingText(String text) { + if (!TextUtils.equals(mContent, text)) { + mContent = text; + mNote.setTextData(DataColumns.CONTENT, mContent); + } + } + + // 转换为电话笔记 + public void convertToCallNote(String phoneNumber, long callDate) { + mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); + mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); + mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); + } + + // 检查是否有闹钟提醒 + public boolean hasClockAlert() { + return (mAlertDate > 0 ? true : false); + } + + // 获取内容 + public String getContent() { + return mContent; + } + + // 获取提醒日期 + public long getAlertDate() { + return mAlertDate; + } + + // 获取修改日期 + public long getModifiedDate() { + return mModifiedDate; + } + + // 获取背景颜色资源ID + public int getBgColorResId() { + return NoteBgResources.getNoteBgResource(mBgColorId); + } + + // 获取背景颜色ID + public int getBgColorId() { + return mBgColorId; + } + + // 获取标题背景资源ID + public int getTitleBgResId() { + return NoteBgResources.getNoteTitleBgResource(mBgColorId); + } + + // 获取检查列表模式 + public int getCheckListMode() { + return mMode; + } + + // 获取笔记ID + public long getNoteId() { + return mNoteId; + } + + // 获取文件夹ID + public long getFolderId() { + return mFolderId; + } + + // 获取小部件ID + public int getWidgetId() { + return mWidgetId; + } + + // 获取小部件类型 + public int getWidgetType() { + return mWidgetType; + } + + // 定义设置状态更改监听器接口 + public interface NoteSettingChangedListener { + /** + * 当当前笔记的背景颜色刚刚改变时调用 + */ + void onBackgroundColorChanged(); + + /** + * 当用户设置闹钟时调用 + */ + void onClockAlertChanged(long date, boolean set); + + /** + * 当用户从小部件创建笔记时调用 + */ + void onWidgetChanged(); + + /** + * 在检查列表模式和正常模式之间切换时调用 + * @param oldMode 是更改前的模式 + * @param newMode 是新模式 + */ + void onCheckListModeChanged(int oldMode, int newMode); + } +} diff --git a/Desktop/xiaomi1/src/widget/NoteWidgetProvider.java b/Desktop/xiaomi1/src/widget/NoteWidgetProvider.java new file mode 100644 index 0000000..d55da72 --- /dev/null +++ b/Desktop/xiaomi1/src/widget/NoteWidgetProvider.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * 版权声明,声明这段代码的版权属于MiCode开源社区,网址为www.micode.net + * + * 许可证声明,声明这段代码遵循Apache许可证2.0版本 + * 你不能使用这个文件,除非你遵守许可证。 + * 你可以在以下网址获取许可证的副本: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 除非适用法律要求或书面同意,否则根据许可证分发的软件 + * 是以原样”为基础分发的,没有任何明示或暗示的保证。 + * 请参阅许可证以获取特定的语言管理权限和 + * 许可证下的限制。 + */ +package net.micode.notes.widget; // 定义包名,表示这个类属于net.micode.notes.widget包 + +import android.app.PendingIntent; // 导入PendingIntent类,用于创建延迟执行的操作 +import android.appwidget.AppWidgetManager; // 导入AppWidgetManager类,用于管理App Widget +import android.appwidget.AppWidgetProvider; // 导入AppWidgetProvider类,提供App Widget的基本功能 +import android.content.ContentValues; // 导入ContentValues类,用于存储键值对数据 +import android.content.Context; // 导入Context类,提供对应用环境的访问 +import android.content.Intent; // 导入Intent类,用于启动活动或服务 +import android.database.Cursor; // 导入Cursor类,用于遍历查询结果 +import android.util.Log; // 导入Log类,用于日志记录 +import android.widget.RemoteViews; // 导入RemoteViews类,用于在App Widget中显示视图 + +import net.micode.notes.R; // 导入R类,包含应用的所有资源ID +import net.micode.notes.data.Notes; // 导入Notes类,包含笔记数据的相关操作 +import net.micode.notes.data.Notes.NoteColumns; // 导入NoteColumns类,包含笔记数据的列定义 +import net.micode.notes.tool.ResourceParser; // 导入ResourceParser类,用于解析资源 +import net.micode.notes.ui.NoteEditActivity; // 导入NoteEditActivity类,用于编辑笔记 +import net.micode.notes.ui.NotesListActivity; // 导入NotesListActivity类,用于显示笔记列表 + +public abstract class NoteWidgetProvider extends AppWidgetProvider { // 定义NoteWidgetProvider类,继承自AppWidgetProvider + public static final String [] PROJECTION = new String [] { // 定义一个字符串数组,用于查询笔记数据 + NoteColumns.ID, // 笔记ID + NoteColumns.BG_COLOR_ID, // 背景颜色ID + NoteColumns.SNIPPET // 笔记摘要 + }; + + public static final int COLUMN_ID = 0; // 定义常量,表示ID列的索引 + public static final int COLUMN_BG_COLOR_ID = 1; // 定义常量,表示背景颜色ID列的索引 + public static final int COLUMN_SNIPPET = 2; // 定义常量,表示摘要列的索引 + + private static final String TAG = "NoteWidgetProvider"; // 定义日志标签 + + @Override + public void onDeleted(Context context, int[] appWidgetIds) { // 重写onDeleted方法,当App Widget被删除时调用 + ContentValues values = new ContentValues(); // 创建ContentValues对象,用于存储更新数据 + values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // 设置Widget ID为无效值 + for (int i = 0; i < appWidgetIds.length; i++) { // 遍历所有被删除的App Widget ID + context.getContentResolver().update(Notes.CONTENT_NOTE_URI, // 更新笔记数据 + values, // 更新数据 + NoteColumns.WIDGET_ID + "=?", // 更新条件 + new String[] { String.valueOf(appWidgetIds[i])}); // 更新条件参数 + } + } + + private Cursor getNoteWidgetInfo(Context context, int widgetId) { // 定义方法,获取指定Widget的笔记信息 + return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, // 查询笔记数据 + PROJECTION, // 查询列 + NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?", // 查询条件 + new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) }, // 查询条件参数 + null); // 排序条件 + } + + protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // 定义方法,更新App Widget + update(context, appWidgetManager, appWidgetIds, false); // 调用重载方法,默认不启用隐私模式 + } + + private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, + boolean privacyMode) { // 定义方法,更新App Widget,支持隐私模式 + for (int i = 0; i < appWidgetIds.length; i++) { // 遍历所有App Widget ID + if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { // 检查Widget ID是否有效 + int bgId = ResourceParser.getDefaultBgId(context); // 获取默认背景颜色ID + String snippet = ""; // 初始化笔记摘要 + Intent intent = new Intent(context, NoteEditActivity.class); // 创建Intent,用于启动NoteEditActivity + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置Intent标志,确保只启动一个实例 + intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]); // 添加Widget ID到Intent + intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType()); // 添加Widget类型到Intent + + Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]); // 获取指定Widget的笔记信息 + if (c != null && c.moveToFirst()) { // 检查Cursor是否有效并移动到第一行 + if (c.getCount() > 1) { // 检查是否有多个笔记 + Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]); // 记录错误日志 + c.close(); // 关闭Cursor + return; // 返回 + } + snippet = c.getString(COLUMN_SNIPPET); // 获取笔记摘要 + bgId = c.getInt(COLUMN_BG_COLOR_ID); // 获取背景颜色ID + intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID)); // 添加笔记ID到Intent + intent.setAction(Intent.ACTION_VIEW); // 设置Intent动作 + } else { + snippet = context.getResources().getString(R.string.widget_havenot_content); // 获取默认摘要 + intent.setAction(Intent.ACTION_INSERT_OR_EDIT); // 设置Intent动作 + } + + if (c != null) { // 检查Cursor是否有效 + c.close(); // 关闭Cursor + } + + RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId()); // 创建RemoteViews对象 + rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId)); // 设置背景图片资源 + intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId); // 添加背景颜色ID到Intent + /** + * 生成启动宿主Activity的PendingIntent + */ + PendingIntent pendingIntent = null; // 初始化PendingIntent + if (privacyMode) { // 检查是否启用隐私模式 + rv.setTextViewText(R.id.widget_text, // 设置文本视图文本 + context.getString(R.string.widget_under_visit_mode)); // 获取隐私模式文本 + pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent( // 创建PendingIntent + context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); // 启动NotesListActivity + } else { + rv.setTextViewText(R.id.widget_text, snippet); // 设置文本视图文本为笔记摘要 + pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent, // 创建PendingIntent + PendingIntent.FLAG_UPDATE_CURRENT); // 启动NoteEditActivity + } + + rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent); // 设置点击事件 + appWidgetManager.updateAppWidget(appWidgetIds[i], rv); // 更新App Widget + } + } + } + + protected abstract int getBgResourceId(int bgId); // 定义抽象方法,获取背景资源ID + + protected abstract int getLayoutId(); // 定义抽象方法,获取布局资源ID + + protected abstract int getWidgetType(); // 定义抽象方法,获取Widget类型 +} diff --git a/Desktop/xiaomi1/src/widget/NoteWidgetProvider_2x.java b/Desktop/xiaomi1/src/widget/NoteWidgetProvider_2x.java new file mode 100644 index 0000000..aa537fe --- /dev/null +++ b/Desktop/xiaomi1/src/widget/NoteWidgetProvider_2x.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * 版权声明,声明这段代码的版权属于MiCode开源社区,网址为www.micode.net + */ +/* + * 许可证声明,声明这段代码遵循Apache许可证2.0版本 + * 你不能使用这个文件,除非你遵守许可证。 + * 你可以在以下网址获取许可证的副本: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 除非适用法律要求或书面同意,否则根据许可证分发的软件 + * 是以“原样”为基础分发的,没有任何明示或暗示的保证。 + * 请参阅许可证以获取特定的语言管理权限和 + * 许可证下的限制。 + */ +package net.micode.notes.widget; // 定义包名,表示这个类属于net.micode.notes.widget包 + +import android.appwidget.AppWidgetManager; // 导入AppWidgetManager类,用于管理App Widget +import android.content.Context; // 导入Context类,提供对应用环境的访问 + +import net.micode.notes.R; // 导入R类,包含应用的所有资源ID +import net.micode.notes.data.Notes; // 导入Notes类,用于处理笔记数据 +import net.micode.notes.tool.ResourceParser; // 导入ResourceParser类,用于解析资源 + +public class NoteWidgetProvider_2x extends NoteWidgetProvider { // 定义NoteWidgetProvider_2x类,继承自NoteWidgetProvider + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + // 重写onUpdate方法,当App Widget需要更新时调用 + super.update(context, appWidgetManager, appWidgetIds); // 调用父类的update方法进行更新 + } + + @Override + protected int getLayoutId() { + // 重写getLayoutId方法,返回布局资源的ID + return R.layout.widget_2x; // 返回widget_2x布局资源的ID + } + + @Override + protected int getBgResourceId(int bgId) { + // 重写getBgResourceId方法,根据传入的背景ID返回对应的背景资源ID + return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); // 使用ResourceParser获取2x尺寸的背景资源 + } + + @Override + protected int getWidgetType() { + // 重写getWidgetType方法,返回Widget的类型 + return Notes.TYPE_WIDGET_2X; // 返回Notes.TYPE_WIDGET_2X,表示这是一个2x尺寸的Widget + } +} diff --git a/Desktop/xiaomi1/src/widget/NoteWidgetProvider_4x.java b/Desktop/xiaomi1/src/widget/NoteWidgetProvider_4x.java new file mode 100644 index 0000000..7424af4 --- /dev/null +++ b/Desktop/xiaomi1/src/widget/NoteWidgetProvider_4x.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * 版权声明,声明这段代码的版权属于MiCode开源社区,网址为www.micode.net + * + * 许可证声明,声明这段代码遵循Apache许可证2.0版本 + * 你不能使用这个文件,除非你遵守许可证。 + * 你可以在以下网址获取许可证的副本: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 除非适用法律要求或书面同意,否则根据许可证分发的软件 + * 是以原样”为基础分发的,没有任何明示或暗示的保证。 + * 请参阅许可证以获取特定的语言管理权限和 + * 许可证下的限制。 + */ +package net.micode.notes.widget; // 定义包名,表示这个类属于net.micode.notes.widget包 + +import android.appwidget.AppWidgetManager; // 导入AppWidgetManager类,用于管理App Widget +import android.content.Context; // 导入Context类,提供对应用环境的访问 + +import net.micode.notes.R; // 导入R类,包含应用的所有资源ID +import net.micode.notes.data.Notes; // 导入Notes类,可能包含笔记相关的数据和方法 +import net.micode.notes.tool.ResourceParser; // 导入ResourceParser类,用于解析资源 + + +public class NoteWidgetProvider_4x extends NoteWidgetProvider { // 定义NoteWidgetProvider_4x类,继承自NoteWidgetProvider + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // 重写onUpdate方法,用于更新App Widget + super.update(context, appWidgetManager, appWidgetIds); // 调用父类的update方法,进行实际的更新操作 + } + + protected int getLayoutId() { // 定义getLayoutId方法,用于获取布局资源的ID + return R.layout.widget_4x; // 返回4x尺寸Widget的布局资源ID + } + + @Override + protected int getBgResourceId(int bgId) { // 重写getBgResourceId方法,根据传入的背景ID返回对应的背景资源ID + return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); // 调用ResourceParser的getWidget4xBgResource方法,获取4x尺寸Widget的背景资源ID + } + + @Override + protected int getWidgetType() { // 重写getWidgetType方法,返回Widget的类型 + return Notes.TYPE_WIDGET_4X; // 返回4x尺寸Widget的类型 + } +}