2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import android.app.SearchManager;
20 import android.content.ContentProvider;
21 import android.content.ContentValues;
22 import android.content.Intent;
23 import android.content.UriMatcher;
24 import android.database.Cursor;
25 import android.database.MatrixCursor;
26 import android.net.Uri;
28 /** Simple test provider that runs in the local process.
30 * Used by {@link SearchManagerTest}.
32 public class SuggestionProvider extends ContentProvider {
33 private static final String TAG = "SuggestionProvider";
35 private static final int SEARCH_SUGGESTIONS = 1;
37 private static final UriMatcher sURLMatcher = new UriMatcher(
41 sURLMatcher.addURI("*", SearchManager.SUGGEST_URI_PATH_QUERY,
43 sURLMatcher.addURI("*", SearchManager.SUGGEST_URI_PATH_QUERY + "/*",
47 private static final String[] COLUMNS = new String[] {
49 SearchManager.SUGGEST_COLUMN_TEXT_1,
50 SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
51 SearchManager.SUGGEST_COLUMN_QUERY
54 public SuggestionProvider() {
58 public boolean onCreate() {
63 public Cursor query(Uri url, String[] projectionIn, String selection,
64 String[] selectionArgs, String sort) {
65 int match = sURLMatcher.match(url);
67 case SEARCH_SUGGESTIONS:
68 String query = url.getLastPathSegment();
69 MatrixCursor cursor = new MatrixCursor(COLUMNS);
70 String[] suffixes = { "", "a", " foo", "XXXXXXXXXXXXXXXXX" };
71 for (String suffix : suffixes) {
72 addRow(cursor, query + suffix);
76 throw new IllegalArgumentException("Unknown URL: " + url);
80 private void addRow(MatrixCursor cursor, String string) {
81 long id = cursor.getCount();
82 cursor.newRow().add(id).add(string).add(Intent.ACTION_SEARCH).add(string);
86 public String getType(Uri url) {
87 int match = sURLMatcher.match(url);
89 case SEARCH_SUGGESTIONS:
90 return SearchManager.SUGGEST_MIME_TYPE;
92 throw new IllegalArgumentException("Unknown URL: " + url);
97 public int update(Uri url, ContentValues values, String where, String[] whereArgs) {
98 throw new UnsupportedOperationException("update not supported");
102 public Uri insert(Uri url, ContentValues initialValues) {
103 throw new UnsupportedOperationException("insert not supported");
107 public int delete(Uri url, String where, String[] whereArgs) {
108 throw new UnsupportedOperationException("delete not supported");