|
|
/*
|
|
|
* 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.data;
|
|
|
|
|
|
import android.app.SearchManager;
|
|
|
import android.content.ContentProvider;
|
|
|
import android.content.ContentUris;
|
|
|
import android.content.ContentValues;
|
|
|
import android.content.Intent;
|
|
|
import android.content.UriMatcher;
|
|
|
import android.database.Cursor;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.net.Uri;
|
|
|
import android.text.TextUtils;
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
* 笔记ContentProvider
|
|
|
*
|
|
|
* 功能概述:
|
|
|
* 1. 提供统一的数据库访问接口
|
|
|
* 2. 实现标准的CRUD操作(Create、Read、Update、Delete)
|
|
|
* 3. 支持笔记搜索功能
|
|
|
* 4. 提供搜索建议功能
|
|
|
* 5. 管理数据变更通知
|
|
|
*
|
|
|
* Content URI格式:
|
|
|
* - content://micode_notes/note : 访问所有笔记
|
|
|
* - content://micode_notes/note/# : 访问指定ID的笔记
|
|
|
* - content://micode_notes/data : 访问所有数据
|
|
|
* - content://micode_notes/data/# : 访问指定ID的数据
|
|
|
* - content://micode_notes/search : 搜索笔记
|
|
|
* - content://micode_notes/search_suggest/query : 搜索建议
|
|
|
*
|
|
|
* 架构设计:
|
|
|
* - 使用UriMatcher匹配不同的URI
|
|
|
* - 使用NotesDatabaseHelper管理数据库连接
|
|
|
* - 使用ContentResolver通知数据变更
|
|
|
*/
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
// URI匹配器,用于匹配不同的Content URI
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
|
|
// 数据库帮助类实例
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
private static final String TAG = "NotesProvider";
|
|
|
|
|
|
/**
|
|
|
* URI类型常量
|
|
|
* 用于UriMatcher匹配不同的URI模式
|
|
|
*/
|
|
|
// 访问所有笔记:content://micode_notes/note
|
|
|
private static final int URI_NOTE = 1;
|
|
|
// 访问指定笔记:content://micode_notes/note/#
|
|
|
private static final int URI_NOTE_ITEM = |