|
|
|
@ -33,11 +33,10 @@ 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 {
|
|
|
|
|
// UriMatcher用于匹配Uri
|
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
|
public class NotesProvider extends ContentProvider {//为存储和获取数据提供接口。可以在不同的应用程序之间共享数据
|
|
|
|
|
|
|
|
|
|
private static final UriMatcher mMatcher;// UriMatcher用于匹配Uri
|
|
|
|
|
|
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
|
|
|
@ -52,10 +51,8 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
|
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
|
// 把需要匹配Uri路径全部给注册上
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);// 把需要匹配Uri路径全部给注册上
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);
|
|
|
|
@ -68,35 +65,33 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
* x'0A' represents the '\n' character in sqlite. For title and content in the search result,
|
|
|
|
|
* we will trim '\n' and white space in order to show more information.
|
|
|
|
|
*/
|
|
|
|
|
// 声明 NOTES_SEARCH_PROJECTION
|
|
|
|
|
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
|
|
|
|
|
|
|
|
|
|
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","// 声明 NOTES_SEARCH_PROJECTION
|
|
|
|
|
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
|
|
|
|
|
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
|
|
|
|
|
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
|
|
|
|
|
+ R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
|
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
|
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
|
|
|
|
|
// 声明NOTES_SNIPPET_SEARCH_QUERY
|
|
|
|
|
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
|
|
|
|
|
|
|
|
|
|
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION// 声明NOTES_SNIPPET_SEARCH_QUERY
|
|
|
|
|
+ " FROM " + TABLE.NOTE
|
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
|
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
// Context只有在onCreate()中才被初始化
|
|
|
|
|
// 对mHelper进行实例化
|
|
|
|
|
public boolean onCreate() {
|
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());
|
|
|
|
|
|
|
|
|
|
public boolean onCreate() {// Context只有在onCreate()中才被初始化
|
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());// 对mHelper进行实例化
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
// 查询uri在数据库中对应的位置
|
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
|
|
|
|
|
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,// 查询uri在数据库中对应的位置
|
|
|
|
|
String sortOrder) {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
// 获取可读数据库
|
|
|
|
|
SQLiteDatabase db = mHelper.getReadableDatabase();
|
|
|
|
|
SQLiteDatabase db = mHelper.getReadableDatabase();// 获取可读数据库
|
|
|
|
|
String id = null;
|
|
|
|
|
// 匹配查找uri
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|