1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.quicksearchbox.tests.slow;
18
19import android.app.SearchManager;
20import android.content.ContentProvider;
21import android.content.ContentValues;
22import android.content.Intent;
23import android.database.Cursor;
24import android.database.MatrixCursor;
25import android.net.Uri;
26import android.util.Log;
27
28public class SlowSuggestionProvider extends ContentProvider {
29
30    private static final String TAG = SlowSuggestionProvider.class.getSimpleName();
31
32    private static final String[] COLUMNS = {
33        "_id",
34        SearchManager.SUGGEST_COLUMN_TEXT_1,
35        SearchManager.SUGGEST_COLUMN_TEXT_2,
36        SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
37        SearchManager.SUGGEST_COLUMN_INTENT_DATA,
38    };
39
40    @Override
41    public boolean onCreate() {
42        return true;
43    }
44
45    @Override
46    public Cursor query(Uri uri, String[] projectionIn, String selection,
47            String[] selectionArgs, String sortOrder) {
48        Log.d(TAG, "query(" + uri + ")");
49
50        try {
51            Thread.sleep(20000);
52        } catch (InterruptedException ex) {
53            Log.d(TAG, "Interrupted");
54        }
55
56        MatrixCursor cursor = new MatrixCursor(COLUMNS);
57        for (int i = 0; i < 3; i++) {
58            cursor.addRow(new Object[]{
59                i,
60                "Slow suggestion " + i,
61                "This suggestion takes a long time to appear",
62                Intent.ACTION_VIEW,
63                "content://com.android.quicksearchbox.slow/slow/" + i
64            });
65        }
66        return cursor;
67    }
68
69    @Override
70    public String getType(Uri uri) {
71        return SearchManager.SUGGEST_MIME_TYPE;
72    }
73
74    @Override
75    public Uri insert(Uri uri, ContentValues values) {
76        throw new UnsupportedOperationException();
77    }
78
79    @Override
80    public int update(Uri uri, ContentValues values, String selection,
81            String[] selectionArgs) {
82        throw new UnsupportedOperationException();
83    }
84
85    @Override
86    public int delete(Uri uri, String selection, String[] selectionArgs) {
87        throw new UnsupportedOperationException();
88    }
89
90}
91