From cc834675faf3bc6b91b7e39052d1f8c88421db63 Mon Sep 17 00:00:00 2001 From: ptjcykuav <3346320466@qq.com> Date: Fri, 29 Mar 2024 19:19:27 +0800 Subject: [PATCH 1/5] 18lwl_branch --- 新建 Text Document.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 新建 Text Document.txt diff --git a/新建 Text Document.txt b/新建 Text Document.txt new file mode 100644 index 0000000..5033170 --- /dev/null +++ b/新建 Text Document.txt @@ -0,0 +1,2 @@ +18lwl_branch +1 \ No newline at end of file From 5ad01a54feccbb461dbe8f613c7e5c05271082cd Mon Sep 17 00:00:00 2001 From: ptjcykuav <3346320466@qq.com> Date: Fri, 29 Mar 2024 19:26:37 +0800 Subject: [PATCH 2/5] 18lwl_branch --- 新建 Text Document.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 新建 Text Document.txt diff --git a/新建 Text Document.txt b/新建 Text Document.txt deleted file mode 100644 index 5033170..0000000 --- a/新建 Text Document.txt +++ /dev/null @@ -1,2 +0,0 @@ -18lwl_branch -1 \ No newline at end of file From 898a85a91e1f2af4d506550cab7ee44d4bbb74cd Mon Sep 17 00:00:00 2001 From: ptjcykuav <3346320466@qq.com> Date: Fri, 29 Mar 2024 19:30:10 +0800 Subject: [PATCH 3/5] 111 --- 121.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 121.txt diff --git a/121.txt b/121.txt new file mode 100644 index 0000000..be0ccc2 --- /dev/null +++ b/121.txt @@ -0,0 +1,3 @@ +18lwl_branch + +1 \ No newline at end of file From b333aadf95e7d18582b3bdd4a4c42e36644e848f Mon Sep 17 00:00:00 2001 From: ptjcykuav <3346320466@qq.com> Date: Fri, 19 Apr 2024 18:50:38 +0800 Subject: [PATCH 4/5] 11 --- src/widget/NoteWidgetProvider.java | 140 ++++++++++++++++++++++++++ src/widget/NoteWidgetProvider_2x.java | 53 ++++++++++ src/widget/NoteWidgetProvider_4x.java | 52 ++++++++++ 3 files changed, 245 insertions(+) create mode 100644 src/widget/NoteWidgetProvider.java create mode 100644 src/widget/NoteWidgetProvider_2x.java create mode 100644 src/widget/NoteWidgetProvider_4x.java diff --git a/src/widget/NoteWidgetProvider.java b/src/widget/NoteWidgetProvider.java new file mode 100644 index 0000000..a419452 --- /dev/null +++ b/src/widget/NoteWidgetProvider.java @@ -0,0 +1,140 @@ +/* + * 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. + */ +package net.micode.notes.widget; +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.ContentValues; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.util.Log; +import android.widget.RemoteViews; + +import net.micode.notes.R; +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.NoteColumns; +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 static final String [] PROJECTION = new String [] { + NoteColumns.ID, + NoteColumns.BG_COLOR_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) { + ContentValues values = new ContentValues(); + values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + 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])}); + } + } +//取消与任何特定笔记的关联 + private Cursor getNoteWidgetInfo(Context context, int widgetId) { + 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) { + update(context, appWidgetManager, appWidgetIds, false); + } +//更新小部件 + private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, + boolean privacyMode) { + for (int i = 0; i < appWidgetIds.length; i++) { + if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { + // 获取默认背景 ID + int bgId = ResourceParser.getDefaultBgId(context); + String snippet = ""; + Intent intent = new Intent(context, NoteEditActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]); + intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType()); + // 获取与小部件 ID 相关的笔记信息 + Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]); + if (c != null && c.moveToFirst()) { + if (c.getCount() > 1) { + // 如果存在多个具有相同小部件 ID 的消息,记录错误并返回 + Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]); + c.close(); + return; + } + 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); + } else { + // 如果没有相关笔记信息,设置默认的小部件内容 + snippet = context.getResources().getString(R.string.widget_havenot_content); + intent.setAction(Intent.ACTION_INSERT_OR_EDIT); + } + // 关闭游标 + if (c != null) { + c.close(); + } + RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId()); + rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId)); + intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId); + /** + * Generate the pending intent to start host for the widget + */ + // 创建用于启动宿主应用的待定意图 + PendingIntent pendingIntent = null; + 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); + } else { + // 否则,设置小部件文本为笔记片段,并关联相应的意图 + rv.setTextViewText(R.id.widget_text, snippet); + pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent, + PendingIntent.FLAG_UPDATE_CURRENT); + } +// 设置小部件文本的点击事件 + rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent); + // 更新小部件 + appWidgetManager.updateAppWidget(appWidgetIds[i], rv); + } + } + } + + protected abstract int getBgResourceId(int bgId); + + protected abstract int getLayoutId(); + + protected abstract int getWidgetType(); +} + + \ No newline at end of file diff --git a/src/widget/NoteWidgetProvider_2x.java b/src/widget/NoteWidgetProvider_2x.java new file mode 100644 index 0000000..8d51373 --- /dev/null +++ b/src/widget/NoteWidgetProvider_2x.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +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_2x extends NoteWidgetProvider { + //扩展了基本的 NoteWidgetProvider专门处理 2x 大小的小部件 + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + //调用超类的 update 方法来处理小部件的更新 + super.update(context, appWidgetManager, appWidgetIds); + } + + @Override + protected int getLayoutId() { + //返回 2x 小部件的布局资源 ID + return R.layout.widget_2x; + } + + @Override + protected int getBgResourceId(int bgId) { + //根据提供的 bgId 映射小部件的背景资源 ID + return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); + //检索适当的资源 + } + + @Override + protected int getWidgetType() { + //将小部件类型指定为 Notes.TYPE_WIDGET_2X + return Notes.TYPE_WIDGET_2X; + } +} diff --git a/src/widget/NoteWidgetProvider_4x.java b/src/widget/NoteWidgetProvider_4x.java new file mode 100644 index 0000000..531263b --- /dev/null +++ b/src/widget/NoteWidgetProvider_4x.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +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_4x extends NoteWidgetProvider { + //扩展了基本的 NoteWidgetProvider专门处理 4x 大小的小部件 + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + //小部件的 onUpdate 回调的重写 + super.update(context, appWidgetManager, appWidgetIds); + } + + protected int getLayoutId() { + //返回 4x 小部件的布局资源 ID + return R.layout.widget_4x; + } + + @Override + protected int getBgResourceId(int bgId) { + //映射小部件的背景资源 ID + return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); + } + + @Override + protected int getWidgetType() { + return Notes.TYPE_WIDGET_4X; + //将小部件类型指定为 Notes.TYPE_WIDGET_4X + } +} +//定义了 4x 大小笔记小部件的行为和外观