|
|
|
@ -975,4 +975,97 @@ protected void update(Context context, AppWidgetManager appWidgetManager, int[]
|
|
|
|
|
使用 for 循环遍历小部件 ID 数组。
|
|
|
|
|
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
|
|
|
|
检查当前小部件 ID 是否有效(不等于无效小部件 ID)。
|
|
|
|
|
int bgId = ResourceParser.getDefaultBgId(context);
|
|
|
|
|
int bgId = ResourceParser.getDefaultBgId(context);
|
|
|
|
|
package net.micode.notes.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入SearchManager类,用于管理搜索功能
|
|
|
|
|
import android.app.SearchManager;
|
|
|
|
|
|
|
|
|
|
// 导入ContentProvider类,用于实现数据的访问接口
|
|
|
|
|
import android.content.ContentProvider;
|
|
|
|
|
|
|
|
|
|
// 导入ContentUris类,提供了一些用于处理URI的方法
|
|
|
|
|
import android.content.ContentUris;
|
|
|
|
|
|
|
|
|
|
// 导入ContentValues类,用于存储键值对,通常用于插入或更新数据库记录
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
|
|
|
|
|
// 导入Intent类,用于启动Activity、Service或发送广播
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
|
|
// 导入UriMatcher类,用于匹配URI,以便根据不同的URI执行不同的操作
|
|
|
|
|
import android.content.UriMatcher;
|
|
|
|
|
|
|
|
|
|
// 导入Cursor类,用于从数据库查询结果集中获取数据
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
|
|
// 导入SQLiteDatabase类,用于访问SQLite数据库
|
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
|
|
|
|
|
|
// 导入Uri类,用于表示统一资源标识符
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
|
|
// 导入TextUtils类,提供了一些文本处理的工具方法
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
// 导入Log类,用于日志输出
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
// 导入应用资源引用类
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
|
|
|
|
|
// 导入数据表的列名定义
|
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
|
|
|
|
|
|
// 导入笔记表的列名定义
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
// 导入数据库表名的定义
|
|
|
|
|
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
|
|
//NotesProvider的主要功能是作为一个内容提供者,为其他应用程序或组件提供对“Notes”数据的访问。
|
|
|
|
|
//它允许其他应用程序查询、插入、更新或删除标签数据。
|
|
|
|
|
//通过URI匹配,NotesProvider能够区分对哪种数据类型的请求(例如,单独的标签、标签的数据、文件夹操作等),并执行相应的操作。
|
|
|
|
|
|
|
|
|
|
//用于匹配不同URI的UriMatcher对象,通常用于解析传入的URI,并确定应该执行哪种操作。
|
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
|
|
|
|
|
|
//NotesDatabaseHelper实类,用来操作SQLite数据库,负责创建、更新和查询数据库。
|
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
|
|
|
|
//标签,输出日志时用来表示是该类发出的消息
|
|
|
|
|
private static final String TAG = "NotesProvider";
|
|
|
|
|
|
|
|
|
|
//6个URI的匹配码,用于区分不同的URI类型
|
|
|
|
|
private static final int URI_NOTE = 1;
|
|
|
|
|
private static final int URI_NOTE_ITEM = 2;
|
|
|
|
|
private static final int URI_DATA = 3;
|
|
|
|
|
private static final int URI_DATA_ITEM = 4;
|
|
|
|
|
|
|
|
|
|
private static final int URI_SEARCH = 5;
|
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6;
|
|
|
|
|
|
|
|
|
|
//进一步定义了URI匹配规则和搜索查询的投影
|
|
|
|
|
//功能概述:
|
|
|
|
|
//初始化了一个UriMatcher对象mMatcher,并添加了一系列的URI匹配规则。
|
|
|
|
|
//解读:
|
|
|
|
|
static {
|
|
|
|
|
//创建了一个UriMatcher实例,并设置默认匹配码为NO_MATCH,表示如果没有任何URI匹配,则返回这个码。
|
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
|
//添加规则,当URI的authority为Notes.AUTHORITY,路径为note时,返回匹配码URI_NOTE。
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
|
//添加规则,当URI的authority为Notes.AUTHORITY,路径为note/后跟一个数字(#代表数字)时,返回匹配码URI_NOTE_ITEM。
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
|
|
//和上面两句同理,但用于匹配数据相关的URI
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);
|
|
|
|
|
//用于匹配搜索相关的URI
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);
|
|
|
|
|
//这两行用于匹配搜索建议相关的URI
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);
|
|
|
|
|
}
|
|
|
|
|