Code example for SearchableInfo

Methods: getSuggestAuthoritygetSuggestPathgetSuggestSelectionsleep

0
    public Cursor getSuggestions(SearchableInfo searchable, String query, int limit) {
        if (searchable == null) {
            return null; 
        } 
 
        String authority = searchable.getSuggestAuthority();
        if (authority == null) {
            return null; 
        } 
 
        Uri.Builder uriBuilder = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority(authority)
                .query("")  // TODO: Remove, workaround for a bug in Uri.writeToParcel()
                .fragment("");  // TODO: Remove, workaround for a bug in Uri.writeToParcel()
 
        // if content path provided, insert it now 
        final String contentPath = searchable.getSuggestPath();
        if (contentPath != null) {
            uriBuilder.appendEncodedPath(contentPath);
        } 
 
        // append standard suggestion query path 
        uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
 
        // get the query selection, may be null 
        String selection = searchable.getSuggestSelection();
        // inject query, either as selection args or inline 
        String[] selArgs = null;
        if (selection != null) {    // use selection if provided
            selArgs = new String[] { query };
        } else {                    // no selection, use REST pattern 
            uriBuilder.appendPath(query);
        } 
 
        if (limit > 0) {
            uriBuilder.appendQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT,
                    String.valueOf(limit));
        } 
 
        Uri uri = uriBuilder.build();
 
        // finally, make the query 
        return getContentResolver().query(uri, null, selection, selArgs, null);
    } 
 
    private static String formatTime(long ns) {
        return (ns / 1000000.0d) + " ms";
    } 
 
    public void checkLiveSource(String src, ComponentName componentName, String query) {
        mExecutorService.submit(new LiveSourceCheck(src, componentName, query));
    } 
 
    private class LiveSourceCheck implements Runnable {
 
        private String mSrc;
        private SearchableInfo mSearchable;
        private String mQuery;
        private Handler mHandler = new Handler(Looper.getMainLooper());
 
        public LiveSourceCheck(String src, ComponentName componentName, String query) {
            mSrc = src;
            mSearchable = mSearchManager.getSearchableInfo(componentName);
            assert(mSearchable != null);
            assert(mSearchable.getSuggestAuthority() != null);
            mQuery = query;
        } 
 
        public void run() { 
            Cursor cursor = null;
            try { 
                final long start = System.nanoTime();
                cursor = getSuggestions(mSearchable, mQuery);
                long end = System.nanoTime();
                long elapsed = (end - start);
                if (cursor == null) {
                    Log.d(TAG, mSrc + ": null cursor in " + formatTime(elapsed)
                            + " for '" + mQuery + "'");
                } else { 
                    Log.d(TAG, mSrc + ": " + cursor.getCount() + " rows in " + formatTime(elapsed)
                            + " for '" + mQuery + "'");
                    cursor.registerContentObserver(new ChangeObserver(cursor));
                    cursor.registerDataSetObserver(new MyDataSetObserver(mSrc, start, cursor));
                    try { 
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {
                        Log.d(TAG, mSrc + ": interrupted");
                    } 
                } 
            } finally { 
Connect your IDE to all the code out there  Get Codota for Java