Compare commits

..

No commits in common. 'master' and 'bowenxv_branch' have entirely different histories.

@ -1,187 +0,0 @@
/*
* 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; // 指定此类属于 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; // 导入必要的Android组件和业务逻辑接口包括处理意图、远程视图、AppWidget管理等
/*
*/
public abstract class NoteWidgetProvider extends AppWidgetProvider {
/*
IDID
*/
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"; // 日志标签
/*
WIDGET_ID
@param context
@param appWidgetIds ID
*/
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues(); // 创建ContentValues对象用于更新数据
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // 设置WIDGET_ID为无效值
for (int i = 0; i < appWidgetIds.length; i++) {
context.getContentResolver().update(Notes.CONTENT_NOTE_URI, // 更新笔记数据
values,
NoteColumns.WIDGET_ID + "=?", // 更新条件WIDGET_ID等于当前小部件ID
new String[]{String.valueOf(appWidgetIds[i])});
}
}
/*
ID
@param context
@param widgetId ID
@return Cursor
*/
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, // 查询笔记数据
PROJECTION, // 查询的字段
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?", // 查询条件WIDGET_ID等于widgetId且PARENT_ID不等于ID_TRASH_FOLDER
new String[]{String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER)}, // 查询条件的参数
null); // 不指定排序
}
/*
update
@param context
@param appWidgetManager
@param appWidgetIds ID
*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false); // 默认不启用隐私模式
}
/*
ID
@param context
@param appWidgetManager
@param appWidgetIds ID
@param privacyMode
*/
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); // 获取默认背景颜色ID
String snippet = ""; // 初始化笔记片段为空字符串
Intent intent = new Intent(context, NoteEditActivity.class); // 创建编辑笔记的Intent
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置Intent标志
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]); // 添加小部件ID到Intent
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType()); // 添加小部件类型到Intent
Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]); // 查询与小部件关联的笔记信息
if (c != null && c.moveToFirst()) {
if (c.getCount() > 1) { // 如果查询到多条记录,记录错误并返回
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); // 获取笔记背景颜色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) {
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
/*
PendingIntent
*/
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); // 创建跳转到笔记列表的PendingIntent
} else {
rv.setTextViewText(R.id.widget_text, snippet); // 设置小部件文本为笔记片段
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent, // 创建跳转到笔记编辑的PendingIntent
PendingIntent.FLAG_UPDATE_CURRENT);
}
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent); // 设置小部件点击事件
appWidgetManager.updateAppWidget(appWidgetIds[i], rv); // 更新小部件
}
}
}
/*
ID
@param bgId ID
@return ID
*/
protected abstract int getBgResourceId(int bgId);
/*
ID
@return ID
*/
protected abstract int getLayoutId();
/*
@return
*/
protected abstract int getWidgetType();
}

@ -1,73 +0,0 @@
/*
* 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; // 包路径,表示该类属于 net.micode.notes.widget 包
import android.appwidget.AppWidgetManager; // 导入 AppWidgetManager用于管理小部件
import android.content.Context; // 导入 Context用于获取应用上下文
import net.micode.notes.R; // 导入资源文件
import net.micode.notes.data.Notes; // 导入笔记数据相关的类
import net.micode.notes.tool.ResourceParser; // 导入资源解析工具类
/*
NoteWidgetProvider_2x 2x
NoteWidgetProvider
*/
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
/*
update
@param context
*param appWidgetManager
@param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds); // 调用父类的 update 方法
}
/*
ID
2x ID
@return ID
*/
@Override
protected int getLayoutId() {
return R.layout.widget_2x; // 返回 2x 大小的小部件布局资源 ID
}
/*
ID
ID 2x ID
@param bgId ID
@return ID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); // 调用工具类获取背景资源 ID
}
/*
2x
@return
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X; // 返回 2x 大小的小部件类型
}
}

@ -1,77 +0,0 @@
/*
* 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; // 包路径,表示该类属于 net.micode.notes.widget 包
import android.appwidget.AppWidgetManager; // 导入 AppWidgetManager用于管理小部件
import android.content.Context; // 导入 Context用于获取应用上下文
import net.micode.notes.R; // 导入资源文件
import net.micode.notes.data.Notes; // 导入笔记数据相关的类
import net.micode.notes.tool.ResourceParser; // 导入资源解析工具类
/*
NoteWidgetProvider_4x 4x
NoteWidgetProvider
*/
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
/*
update
@param context
@param appWidgetManager
@param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds); // 调用父类的 update 方法
}
/*
ID
4x ID
@return ID
*/
@Override
protected int getLayoutId() {
return R.layout.widget_4x; // 返回 4x 大小的小部件布局资源 ID
}
/*
ID
ID 4x ID
@param bgId ID
@return ID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); // 调用工具类获取背景资源 ID
}
/*
4x
@return
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X; // 返回 4x 大小的小部件类型
}
}
Loading…
Cancel
Save