|
|
@ -33,11 +33,10 @@ import net.micode.notes.R;
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
|
|
|
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
|
|
|
//为存储和获取数据提供接口。可以在不同的应用程序之间共享数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
|
public class NotesProvider extends ContentProvider {//为存储和获取数据提供接口。可以在不同的应用程序之间共享数据
|
|
|
|
// UriMatcher用于匹配Uri
|
|
|
|
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
private static final UriMatcher mMatcher;// UriMatcher用于匹配Uri
|
|
|
|
|
|
|
|
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
|
|
|
|
|
@ -52,10 +51,8 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6;
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6;
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);// 把需要匹配Uri路径全部给注册上
|
|
|
|
// 把需要匹配Uri路径全部给注册上
|
|
|
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);
|
|
|
|
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,
|
|
|
|
* 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.
|
|
|
|
* 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 + ","
|
|
|
|
+ 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_1 + ","
|
|
|
|
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
|
|
|
|
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
|
|
|
|
+ R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
|
|
|
|
+ R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
|
|
|
|
+ "'" + 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
|
|
|
|
+ " FROM " + TABLE.NOTE
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
// Context只有在onCreate()中才被初始化
|
|
|
|
|
|
|
|
// 对mHelper进行实例化
|
|
|
|
public boolean onCreate() {// Context只有在onCreate()中才被初始化
|
|
|
|
public boolean onCreate() {
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());// 对mHelper进行实例化
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
@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) {
|
|
|
|
String sortOrder) {
|
|
|
|
Cursor c = null;
|
|
|
|
Cursor c = null;
|
|
|
|
// 获取可读数据库
|
|
|
|
SQLiteDatabase db = mHelper.getReadableDatabase();// 获取可读数据库
|
|
|
|
SQLiteDatabase db = mHelper.getReadableDatabase();
|
|
|
|
|
|
|
|
String id = null;
|
|
|
|
String id = null;
|
|
|
|
// 匹配查找uri
|
|
|
|
// 匹配查找uri
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|