|
|
|
@ -1,22 +1,19 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
* 版权所有 (c) 2010-2011, MiCode 开源社区 (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
|
|
|
|
|
* 本文件授权使用 Apache License, Version 2.0(以下简称“许可证”);
|
|
|
|
|
* 除非符合许可证规定,否则不得使用此文件。
|
|
|
|
|
* 您可以从以下网址获取许可证副本:
|
|
|
|
|
*
|
|
|
|
|
* 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.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.SearchManager;
|
|
|
|
|
import android.content.ContentProvider;
|
|
|
|
|
import android.content.ContentUris;
|
|
|
|
@ -33,29 +30,31 @@ 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;
|
|
|
|
|
package net.micode.notes.data;
|
|
|
|
|
|
|
|
|
|
import android.content.ContentProvider;
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
import android.content.UriMatcher;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.provider.SearchManager;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NotesProvider 类是一个 ContentProvider,用于管理便签应用的数据。
|
|
|
|
|
* 它提供了对便签和数据表的查询、插入、删除和更新操作。
|
|
|
|
|
* 该类通过 UriMatcher 匹配不同的 URI,以处理各种数据操作请求。
|
|
|
|
|
*/
|
|
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
|
|
/**
|
|
|
|
|
* 用于匹配 URI 的 UriMatcher 对象。
|
|
|
|
|
*/
|
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据库帮助类 NotesDatabaseHelper 的实例。
|
|
|
|
|
*/
|
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日志标签。
|
|
|
|
|
*/
|
|
|
|
|
private static final String TAG = "NotesProvider";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 不同的 URI 类型常量。
|
|
|
|
|
*/
|
|
|
|
|
private static final int URI_NOTE = 1; // 便签表的 URI
|
|
|
|
|
private static final int URI_NOTE_ITEM = 2; // 便签表中单个便签的 URI
|
|
|
|
|
private static final int URI_DATA = 3; // 数据表的 URI
|
|
|
|
@ -63,6 +62,9 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
private static final int URI_SEARCH = 5; // 搜索 URI
|
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6; // 搜索建议 URI
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 静态初始化块,初始化 UriMatcher,添加不同的 URI 匹配规则。
|
|
|
|
|
*/
|
|
|
|
|
static {
|
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
@ -74,6 +76,9 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搜索建议的投影字符串。
|
|
|
|
|
*/
|
|
|
|
|
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
|
|
|
|
|
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
|
|
|
|
|
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
|
|
|
|
@ -82,18 +87,35 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
|
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搜索便签摘要的 SQL 查询语句。
|
|
|
|
|
*/
|
|
|
|
|
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
|
|
|
|
|
+ " FROM " + TABLE.NOTE
|
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLDER
|
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化 NotesDatabaseHelper 实例。
|
|
|
|
|
* @return true 表示初始化成功。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreate() {
|
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理不同的 URI 类型,执行查询操作并返回游标。
|
|
|
|
|
* 支持便签表、便签项、数据表、数据项、搜索和搜索建议的查询。
|
|
|
|
|
* @param uri 查询的 URI。
|
|
|
|
|
* @param projection 查询的列。
|
|
|
|
|
* @param selection 查询的条件。
|
|
|
|
|
* @param selectionArgs 查询条件的参数。
|
|
|
|
|
* @param sortOrder 查询结果的排序。
|
|
|
|
|
* @return 查询结果的游标。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
|
|
|
|
String sortOrder) {
|
|
|
|
@ -156,6 +178,14 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理不同的 URI 类型,执行插入操作并返回新插入的 URI。
|
|
|
|
|
* 支持便签表和数据表的插入操作。
|
|
|
|
|
* 通知相关 URI 的变化。
|
|
|
|
|
* @param uri 插入的 URI。
|
|
|
|
|
* @param values 插入的数据。
|
|
|
|
|
* @return 新插入的 URI。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Uri insert(Uri uri, ContentValues values) {
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
@ -190,159 +220,173 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
return ContentUris.withAppendedId(uri, insertedId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
boolean deleteData = false;
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
|
|
|
|
|
count = db.delete(TABLE.NOTE, selection, selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
/**
|
|
|
|
|
* ID that smaller than 0 is system folder which is not allowed to
|
|
|
|
|
* trash
|
|
|
|
|
*/
|
|
|
|
|
long noteId = Long.valueOf(id);
|
|
|
|
|
if (noteId <= 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
count = db.delete(TABLE.NOTE,
|
|
|
|
|
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
count = db.delete(TABLE.DATA, selection, selectionArgs);
|
|
|
|
|
deleteData = true;
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
count = db.delete(TABLE.DATA,
|
|
|
|
|
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
|
deleteData = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
if (deleteData) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
|
}
|
|
|
|
|
getContext().getContentResolver().notifyChange(uri, null);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 处理不同的 URI 类型,
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
boolean updateData = false;
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
increaseNoteVersion(-1, selection, selectionArgs);
|
|
|
|
|
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
|
|
|
|
|
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
count = db.update(TABLE.DATA, values, selection, selectionArgs);
|
|
|
|
|
updateData = true;
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
|
updateData = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 处理不同的 URI 类型,执行删除操作并返回删除的行数。
|
|
|
|
|
* 支持便签表、便签项、数据表和数据项的删除操作。
|
|
|
|
|
* 通知相关 URI 的变化。
|
|
|
|
|
* @param uri 删除的 URI。
|
|
|
|
|
* @param selection 删除的条件。
|
|
|
|
|
* @param selectionArgs 删除条件的参数。
|
|
|
|
|
* @return 删除的行数。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
boolean deleteData = false;
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
// 删除便签表中的记录,确保 ID 大于 0
|
|
|
|
|
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
|
|
|
|
|
count = db.delete(TABLE.NOTE, selection, selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
// 删除便签表中的单个记录
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
long noteId = Long.valueOf(id);
|
|
|
|
|
// ID 小于等于 0 的是系统文件夹,不允许删除
|
|
|
|
|
if (noteId <= 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
count = db.delete(TABLE.NOTE,
|
|
|
|
|
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
// 删除数据表中的记录
|
|
|
|
|
count = db.delete(TABLE.DATA, selection, selectionArgs);
|
|
|
|
|
deleteData = true;
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
// 删除数据表中的单个记录
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
count = db.delete(TABLE.DATA,
|
|
|
|
|
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
|
deleteData = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// 未知 URI 抛出异常
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
// 如果删除成功,通知相关 URI 的变化
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
if (deleteData) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
|
}
|
|
|
|
|
getContext().getContentResolver().notifyChange(uri, null);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理不同的 URI 类型,执行更新操作并返回更新的行数。
|
|
|
|
|
* 支持便签表、便签项、数据表和数据项的更新操作。
|
|
|
|
|
* 通知相关 URI 的变化。
|
|
|
|
|
* @param uri 更新的 URI。
|
|
|
|
|
* @param values 更新的数据。
|
|
|
|
|
* @param selection 更新的条件。
|
|
|
|
|
* @param selectionArgs 更新条件的参数。
|
|
|
|
|
* @return 更新的行数。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
boolean updateData = false;
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
// 更新便签表中的记录,增加版本号
|
|
|
|
|
increaseNoteVersion(-1, selection, selectionArgs);
|
|
|
|
|
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
// 更新便签表中的单个记录,增加版本号
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
|
|
|
|
|
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
// 更新数据表中的记录
|
|
|
|
|
count = db.update(TABLE.DATA, values, selection, selectionArgs);
|
|
|
|
|
updateData = true;
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
// 更新数据表中的单个记录
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
|
updateData = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// 未知 URI 抛出异常
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
// 如果更新成功,通知相关 URI 的变化
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
if (updateData) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
|
}
|
|
|
|
|
getContext().getContentResolver().notifyChange(uri, null);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解析选择条件字符串。
|
|
|
|
|
* @param selection 选择条件字符串。
|
|
|
|
|
* @return 解析后的选择条件字符串。
|
|
|
|
|
*/
|
|
|
|
|
private String parseSelection(String selection) {
|
|
|
|
|
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 增加便签的版本号。
|
|
|
|
|
* @param id 便签 ID,-1 表示更新所有便签。
|
|
|
|
|
* @param selection 选择条件字符串。
|
|
|
|
|
* @param selectionArgs 选择条件的参数。
|
|
|
|
|
*/
|
|
|
|
|
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
|
|
|
|
|
StringBuilder sql = new StringBuilder(120);
|
|
|
|
|
sql.append("UPDATE ");
|
|
|
|
|
sql.append(TABLE.NOTE);
|
|
|
|
|
sql.append(" SET ");
|
|
|
|
|
sql.append(NoteColumns.VERSION);
|
|
|
|
|
sql.append("=" + NoteColumns.VERSION + "+1 ");
|
|
|
|
|
|
|
|
|
|
if (id > 0 || !TextUtils.isEmpty(selection)) {
|
|
|
|
|
sql.append(" WHERE ");
|
|
|
|
|
}
|
|
|
|
|
if (id > 0) {
|
|
|
|
|
sql.append(NoteColumns.ID + "=" + String.valueOf(id));
|
|
|
|
|
}
|
|
|
|
|
if (!TextUtils.isEmpty(selection)) {
|
|
|
|
|
String selectString = id > 0 ? parseSelection(selection) : selection;
|
|
|
|
|
for (String args : selectionArgs) {
|
|
|
|
|
selectString = selectString.replaceFirst("\\?", args);
|
|
|
|
|
}
|
|
|
|
|
sql.append(selectString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mHelper.getWritableDatabase().execSQL(sql.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回 URI 的 MIME 类型(当前未实现)。
|
|
|
|
|
* @param uri 查询的 URI。
|
|
|
|
|
* @return URI 的 MIME 类型。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getType(Uri uri) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
if (updateData) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
|
}
|
|
|
|
|
getContext().getContentResolver().notifyChange(uri, null);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String parseSelection(String selection) {
|
|
|
|
|
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
|
|
|
|
|
StringBuilder sql = new StringBuilder(120);
|
|
|
|
|
sql.append("UPDATE ");
|
|
|
|
|
sql.append(TABLE.NOTE);
|
|
|
|
|
sql.append(" SET ");
|
|
|
|
|
sql.append(NoteColumns.VERSION);
|
|
|
|
|
sql.append("=" + NoteColumns.VERSION + "+1 ");
|
|
|
|
|
|
|
|
|
|
if (id > 0 || !TextUtils.isEmpty(selection)) {
|
|
|
|
|
sql.append(" WHERE ");
|
|
|
|
|
}
|
|
|
|
|
if (id > 0) {
|
|
|
|
|
sql.append(NoteColumns.ID + "=" + String.valueOf(id));
|
|
|
|
|
}
|
|
|
|
|
if (!TextUtils.isEmpty(selection)) {
|
|
|
|
|
String selectString = id > 0 ? parseSelection(selection) : selection;
|
|
|
|
|
for (String args : selectionArgs) {
|
|
|
|
|
selectString = selectString.replaceFirst("\\?", args);
|
|
|
|
|
}
|
|
|
|
|
sql.append(selectString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mHelper.getWritableDatabase().execSQL(sql.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getType(Uri uri) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 类注释
|
|
|
|
|
NotesProvider 类是一个 ContentProvider,用于管理便签应用的数据。它提供了对便签和数据表的查询、插入、删除和更新操作。
|
|
|
|
|
常量定义
|
|
|
|
|
mMatcher:用于匹配 URI 的 UriMatcher 对象。
|
|
|
|
|
mHelper:数据库帮助类 NotesDatabaseHelper 的实例。
|
|
|
|
|
TAG:日志标签。
|
|
|
|
|
URI_*:不同的 URI 类型常量。
|
|
|
|
|
NOTES_SEARCH_PROJECTION:搜索建议的投影字符串。
|
|
|
|
|
NOTES_SNIPPET_SEARCH_QUERY:搜索便签摘要的 SQL 查询语句。
|
|
|
|
|
静态初始化块
|
|
|
|
|
初始化 UriMatcher,添加不同的 URI 匹配规则。
|
|
|
|
|
onCreate 方法
|
|
|
|
|
初始化 NotesDatabaseHelper 实例。
|
|
|
|
|
query 方法
|
|
|
|
|
处理不同的 URI 类型,执行查询操作并返回游标。
|
|
|
|
|
支持便签表、便签项、数据表、数据项、搜索和搜索建议的查询。
|
|
|
|
|
insert 方法
|
|
|
|
|
处理不同的 URI 类型,执行插入操作并返回新插入的 URI。
|
|
|
|
|
支持便签表和数据表的插入操作。
|
|
|
|
|
通知相关 URI 的变化。
|
|
|
|
|
delete 方法
|
|
|
|
|
处理不同的 URI 类型,执行删除操作并返回删除的行数。
|
|
|
|
|
支持便签表、便签项、数据表和数据项的删除操作。
|
|
|
|
|
通知相关 URI 的变化。
|
|
|
|
|
update 方法
|
|
|
|
|
处理不同的 URI 类型,执行更新操作并返回更新的行数。
|
|
|
|
|
支持便签表、便签项、数据表和数据项的更新操作。
|
|
|
|
|
通知相关 URI 的变化。
|
|
|
|
|
辅助方法
|
|
|
|
|
parseSelection:解析选择条件字符串。
|
|
|
|
|
increaseNoteVersion:增加便签的版本号。
|
|
|
|
|
getType 方法
|
|
|
|
|
返回 URI 的 MIME 类型(当前未实现)。
|
|
|
|
|
*/
|