SearchableSource.java revision 0484fb4d652bfa9d5c7fb238a7cec1a6f2244e44
13e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/*
23e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Copyright (C) 2009 The Android Open Source Project
33e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
43e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
53e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * you may not use this file except in compliance with the License.
63e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * You may obtain a copy of the License at
73e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
83e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *      http://www.apache.org/licenses/LICENSE-2.0
93e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * See the License for the specific language governing permissions and
143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * limitations under the License.
153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */
163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpackage com.android.quicksearchbox;
183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
193e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.app.SearchManager;
20227180196cf8d92172cbb62f8ddaacf864be28e7Bjorn Bringertimport android.app.SearchableInfo;
213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.ComponentName;
223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.ContentResolver;
233e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.Context;
243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.pm.ActivityInfo;
253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.pm.PackageManager;
263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.pm.PackageManager.NameNotFoundException;
273e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.database.Cursor;
283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.graphics.drawable.Drawable;
293e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.net.Uri;
303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.util.Log;
313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
32227180196cf8d92172cbb62f8ddaacf864be28e7Bjorn Bringertimport java.util.Arrays;
33227180196cf8d92172cbb62f8ddaacf864be28e7Bjorn Bringert
343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/**
353e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Represents a single suggestion source, e.g. Contacts.
363e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
373e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */
383e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpublic class SearchableSource implements Source {
393e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
403e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static final boolean DBG = true;
410484fb4d652bfa9d5c7fb238a7cec1a6f2244e44Bjorn Bringert    private static final String TAG = "QSB.SearchableSource";
423e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
433e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private final Context mContext;
443e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
453e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private final SearchableInfo mSearchable;
463e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
473e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private final ActivityInfo mActivityInfo;
483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
493e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    // Cached label for the activity
503e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private CharSequence mLabel = null;
513e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
523e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    // Cached icon for the activity
533e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private Drawable.ConstantState mSourceIcon = null;
543e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
553e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private final boolean mIsWebSuggestionSource;
563e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
573e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private final IconLoader mIconLoader;
583e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
593e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public SearchableSource(Context context, SearchableInfo searchable)
603e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            throws NameNotFoundException {
613e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        this(context, searchable, false);
623e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
633e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
643e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public SearchableSource(Context context, SearchableInfo searchable,
653e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            boolean isWebSuggestionSource) throws NameNotFoundException {
663e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        ComponentName componentName = searchable.getSearchActivity();
673e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mContext = context;
683e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mSearchable = searchable;
693e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mActivityInfo = context.getPackageManager().getActivityInfo(componentName, 0);
703e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mIsWebSuggestionSource = isWebSuggestionSource;
713e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
723e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        Context activityContext = searchable.getActivityContext(context);
733e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        Context providerContext = searchable.getProviderContext(context, activityContext);
743e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        mIconLoader = new CachingIconLoader(new PackageIconLoader(providerContext));
753e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
763e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
773e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public ComponentName getComponentName() {
783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.getSearchActivity();
793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public Drawable getIcon(String drawableId) {
823e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mIconLoader.getIcon(drawableId);
833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
853e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public Uri getIconUri(String drawableId) {
863e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mIconLoader.getIconUri(drawableId);
873e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
883e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
893e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public CharSequence getLabel() {
903e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (mLabel == null) {
913e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            // Load label lazily
923e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            mLabel = mActivityInfo.loadLabel(mContext.getPackageManager());
933e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
943e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mLabel;
953e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
963e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
973e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public int getQueryThreshold() {
983e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.getSuggestThreshold();
993e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1003e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1013e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public String getSettingsDescription() {
1023e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.getSettingsDescription();
1033e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1043e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1053e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public Drawable getSourceIcon() {
1063e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (mSourceIcon == null) {
1073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            // Load icon lazily
1083e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            int iconRes = getSourceIconResource();
1093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            PackageManager pm = mContext.getPackageManager();
1103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            Drawable icon = pm.getDrawable(mActivityInfo.packageName, iconRes,
1113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert                    mActivityInfo.applicationInfo);
1123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            // Can't share Drawable instances, save constant state instead.
1133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            mSourceIcon = (icon != null) ? icon.getConstantState() : null;
1143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            // Optimization, return the Drawable the first time
1153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            return icon;
1163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return (mSourceIcon != null) ? mSourceIcon.newDrawable() : null;
1183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1193e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1203e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public Uri getSourceIconUri() {
1213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mIconLoader.getIconUri(String.valueOf(getSourceIconResource()));
1223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1233e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private int getSourceIconResource() {
1253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        int icon = mActivityInfo.getIconResource();
1263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return (icon != 0) ? icon : android.R.drawable.sym_def_app_icon;
1273e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1293e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public SuggestionCursor getSuggestions(String query, int queryLimit) {
1303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        try {
1313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            Cursor cursor = getSuggestions(mContext, mSearchable, query, queryLimit);
1323e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            if (DBG) Log.d(TAG, toString() + "[" + query + "] returned.");
1333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            return new SourceResult(this, query, cursor);
1343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        } catch (RuntimeException ex) {
1353e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            Log.e(TAG, toString() + "[" + query + "] failed", ex);
1363e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            return new SourceResult(this, query);
1373e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1383e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1393e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1403e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
1413e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     * This is a copy of {@link SearchManager#getSuggestions(SearchableInfo, String)}.
1423e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
1433e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    private static Cursor getSuggestions(Context context, SearchableInfo searchable, String query,
1443e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            int queryLimit) {
1453e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (searchable == null) {
1463e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            return null;
1473e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1493e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        String authority = searchable.getSuggestAuthority();
1503e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (authority == null) {
1513e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            return null;
1523e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1533e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1543e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        Uri.Builder uriBuilder = new Uri.Builder()
1553e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert                .scheme(ContentResolver.SCHEME_CONTENT)
1563e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert                .authority(authority);
1573e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1583e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        // if content path provided, insert it now
1593e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        final String contentPath = searchable.getSuggestPath();
1603e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (contentPath != null) {
1613e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            uriBuilder.appendEncodedPath(contentPath);
1623e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1633e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1643e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        // append standard suggestion query path
1653e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
1663e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1673e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        // get the query selection, may be null
1683e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        String selection = searchable.getSuggestSelection();
1693e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        // inject query, either as selection args or inline
1703e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        String[] selArgs = null;
1713e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (selection != null) {    // use selection if provided
1723e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            selArgs = new String[] { query };
1733e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        } else {                    // no selection, use REST pattern
1743e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            uriBuilder.appendPath(query);
1753e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1763e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1773e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        uriBuilder.appendQueryParameter("limit", String.valueOf(queryLimit));
1783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        Uri uri = uriBuilder.build();
1803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        // finally, make the query
1823e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        if (DBG) {
1833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert            Log.d(TAG, "query(" + uri + ",null," + selection + ","
1843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert                    + Arrays.toString(selArgs) + ",null)");
1853e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        }
1863e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return context.getContentResolver().query(uri, null, selection, selArgs, null);
1873e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1883e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1893e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public boolean isWebSuggestionSource() {
1903e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mIsWebSuggestionSource;
1913e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1923e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1933e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public boolean queryAfterZeroResults() {
1943e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.queryAfterZeroResults();
1953e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
1963e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
1973e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public boolean shouldRewriteQueryFromData() {
1983e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.shouldRewriteQueryFromData();
1993e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2003e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2013e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public boolean shouldRewriteQueryFromText() {
2023e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.shouldRewriteQueryFromText();
2033e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2043e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2053e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    @Override
2063e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public String toString() {
2073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return "SearchableSource{component=" + getComponentName().flattenToShortString() + "}";
2083e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public String getDefaultIntentAction() {
2113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.getSuggestIntentAction();
2123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public String getDefaultIntentData() {
2153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.getSuggestIntentData();
2163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
2183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    public ComponentName getSearchActivity() {
2193e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert        return mSearchable.getSearchActivity();
2203e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    }
2213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
222782dd228e78e9294692d639597f96c26283968bbBjorn Bringert    public String getSuggestActionMsg(int keyCode) {
223782dd228e78e9294692d639597f96c26283968bbBjorn Bringert        SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
224782dd228e78e9294692d639597f96c26283968bbBjorn Bringert        if (actionKey == null) return null;
225782dd228e78e9294692d639597f96c26283968bbBjorn Bringert        return actionKey.getSuggestActionMsg();
226782dd228e78e9294692d639597f96c26283968bbBjorn Bringert    }
227782dd228e78e9294692d639597f96c26283968bbBjorn Bringert
228782dd228e78e9294692d639597f96c26283968bbBjorn Bringert    public String getSuggestActionMsgColumn(int keyCode) {
229782dd228e78e9294692d639597f96c26283968bbBjorn Bringert        SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
230782dd228e78e9294692d639597f96c26283968bbBjorn Bringert        if (actionKey == null) return null;
231782dd228e78e9294692d639597f96c26283968bbBjorn Bringert        return actionKey.getSuggestActionMsgColumn();
232782dd228e78e9294692d639597f96c26283968bbBjorn Bringert    }
233782dd228e78e9294692d639597f96c26283968bbBjorn Bringert
2343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert}
235