【Android源码 栏目提醒】:以下是网学会员为您推荐的Android源码 -[SearchableDictionary工程][android源码][DictionaryProvider java] - 开发文档,希望本篇文章对您学习有所帮助。
/ Copyright C 2010 The Android Open Source Project 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 com.example.android.searchabledict import android.app.SearchManager import android.content.ContentProvider import android.content.ContentResolver import android.content.ContentValues import android.content.UriMatcher import android.database.Cursor import android.net.Uri import android.provider.BaseColumns / Provides access to the dictionary database. / public class DictionaryProvider extends ContentProvider String TAG DictionaryProvider public static String AUTHORITY com.example.android.searchabledict.DictionaryProvider public static final Uri CONTENT_URI Uri.parsecontent:// AUTHORITY /dictionary // MIME types used for searching words or looking up a single definition public static final String WORDS_MIME_TYPE ContentResolver.CURSOR_DIR_BASE_TYPE /vnd.example.android.searchabledict public static final String DEFINITION_MIME_TYPE ContentResolver.CURSOR_ITEM_BASE_TYPE /vnd.example.android.searchabledict private DictionaryDatabase mDictionary // UriMatcher stuff private static final int SEARCH_WORDS 0 private static final int GET_WORD 1 private static final int SEARCH_SUGGEST 2 private static final int REFRESH_SHORTCUT 3 private static final UriMatcher sURIMatcher buildUriMatcher / Builds up a UriMatcher for search suggestion and shortcut refresh queries. / private static UriMatcher buildUriMatcher UriMatcher matcher new UriMatcherUriMatcher.NO_MATCH // to get definitions... matcher.addURIAUTHORITY dictionary SEARCH_WORDS matcher.addURIAUTHORITY dictionary/ GET_WORD // to get suggestions... matcher.addURIAUTHORITY SearchManager.SUGGEST_URI_PATH_QUERY SEARCH_SUGGEST matcher.addURIAUTHORITY SearchManager.SUGGEST_URI_PATH_QUERY / SEARCH_SUGGEST / The following are unused in this implementation but if we include link SearchManagerSUGGEST_COLUMN_SHORTCUT_ID as a column in our suggestions table we could expect to receive refresh queries when a shortcutted suggestion is displayed in Quick Search Box in which case the following Uris would be provided and we would return a cursor with a single item representing the refreshed suggestion data. / matcher.addURIAUTHORITY SearchManager.SUGGEST_URI_PATH_SHORTCUT REFRESH_SHORTCUT matcher.addURIAUTHORITY SearchManager.SUGGEST_URI_PATH_SHORTCUT / REFRESH_SHORTCUT return matcher Override public boolean onCreate mDictionary new DictionaryDatabasegetContext return true / Handles all the dictionary searches and suggestion queries from the Search Manager. When requesting a specific word the uri alone is required. When searching all of the dictionary for matches the selectionArgs argument must carry the search query as the first element. All other arguments are ignored. / Override public Cursor queryUri uri String projection String selection String selectionArgs String sortOrder // Use the UriMatcher to see what kind of query we have and format the db query accordingly switch sURIMatcher.matchuri case SEARCH_SUGGEST: if selectionArgs null throw new IllegalArgumentException selectionArgs must be provided for the Uri: uri return getSuggestionsselectionArgs0 case SEARCH_WORDS: if selectionArgs null throw new IllegalArgumentException selectionArgs must be provided for the Uri: uri return searchselectionArgs0 case GET_WORD: return getWorduri case REFRESH_SHORTCUT: return refreshShortcuturi default: throw new IllegalArgumentExceptionUnknown Uri: uri private Cursor getSuggestionsString query query query.toLowerCase String columns new String BaseColumns._ID DictionaryDatabase.KEY_WORD DictionaryDatabase.KEY_DEFINITION / SearchManager.SUGGEST_COLUMN_SHORTCUT_ID only if you want to refresh shortcuts / SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID return mDictionary.getWordMatchesquery columns private Cursor searchString query query query.toLowerCase String columns new String BaseColumns._ID DictionaryDatabase.KEY_WORD DictionaryDatabase.KEY_DEFINITION return mDictionary.getWordMatchesquery columns private Cursor getWordUri uri String rowId uri.getLastPathSegment String columns new String DictionaryDatabase.KEY_WORD DictionaryDatabase.KEY_DEFINITION return mDictionary.getWordrowId columns private Cursor refreshShortcutUri uri / This wont be called with the current implementation but if we include link SearchManagerSUGGEST_COLUMN_SHORTCUT_ID as a column in our suggestions table we could expect to receive refresh queries when a shortcutted suggestion is displayed in Quick Search Box. In which case this method will query the table for the specific word using the given item Uri and provide all the columns originally provided with the suggestion query. / String rowId uri.getLastPathSegment String columns new String BaseColumns._ID DictionaryDatabase.KEY_WORD DictionaryDatabase.KEY_DEFINITION SearchManager.SUGGEST_COLUMN_SHORTCUT_ID SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID return mDictionary.getWordrowId columns / This method is required in order to query the supported types. Its also useful in our own query method to determine the type of Uri received. / Override public String getTypeUri uri switch sURIMatcher.matchuri case SEARCH_WORDS: return WO
上一篇:
android源代码下载和编译
下一篇:
超市进销存管理系统的开发