Example usage for android.app SearchableInfo getSuggestAuthority

List of usage examples for android.app SearchableInfo getSuggestAuthority

Introduction

In this page you can find the example usage for android.app SearchableInfo getSuggestAuthority.

Prototype

public String getSuggestAuthority() 

Source Link

Document

Gets the search suggestion content provider authority.

Usage

From source file:com.packetsender.android.MainActivity.java

private void setupSearchView(MenuItem searchItem) {

    //searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();

        SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;//from  ww w.  jav a 2 s . c  o  m
            }
        }
        mSearchView.setSearchableInfo(info);
    }

    mSearchView.setOnQueryTextListener(this);
}

From source file:com.aboveware.sms.contacts.ContactSuggestionsAdapter.java

/**
 * Import of hidden method: SearchManager.getSuggestions(SearchableInfo, String, int).
 *///w w w  .  j  a  v  a 2 s  .  c o  m
Cursor getSearchManagerSuggestions(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("limit", String.valueOf(limit));
    }

    Uri uri = uriBuilder.build();

    // finally, make the query
    return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
}

From source file:android.support.v7.widget.SuggestionsAdapter.java

/**
 * Import of hidden method: SearchManager.getSuggestions(SearchableInfo, String, int).
 *///from  w  w  w .j  av  a 2 s. c  om
Cursor getSearchManagerSuggestions(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("limit", String.valueOf(limit));
    }

    Uri uri = uriBuilder.build();

    // finally, make the query
    return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
}

From source file:com.tct.mail.ui.ActionBarController.java

public boolean onCreateOptionsMenu(Menu menu) {
    mEmptyTrashItem = menu.findItem(R.id.empty_trash);
    mEmptySpamItem = menu.findItem(R.id.empty_spam);
    mSearch = menu.findItem(R.id.search);
    //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S
    mStarSwitch = menu.findItem(R.id.menu_star_toggle);
    if (mStarSwitch != null) {
        mSwitch = (Switch) mStarSwitch.getActionView().findViewById(R.id.star_toggle);
        mSwitch.setOnCheckedChangeListener(mController);
    }/*from   w w  w  .  j a  v a 2  s  . c  o m*/
    //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E

    if (mSearch != null) {
        mSearchWidget = (SearchView) MenuItemCompat.getActionView(mSearch);
        MenuItemCompat.setOnActionExpandListener(mSearch, this);
        SearchManager searchManager = (SearchManager) mActivity.getActivityContext()
                .getSystemService(Context.SEARCH_SERVICE);
        if (searchManager != null && mSearchWidget != null) {
            SearchableInfo info = searchManager.getSearchableInfo(mActivity.getComponentName());
            /// TCT: The SearchableInfo may be customized by Email, and we need checking its validation.
            final String authority = getContext().getString(R.string.suggestions_authority);
            if (info != null && authority.equals(info.getSuggestAuthority())) {
                mSearchWidget.setSearchableInfo(info);
                mSearchWidget.setOnSuggestionListener(this);
            }
            //TS: Gantao 2016-01-25 EMAIL BUGFIX-1489887 ADD-S
            //Set focusable false in case always show the search suggestion
            mSearchWidget.setFocusable(false);
            //TS: Gantao 2016-01-25 EMAIL BUGFIX-1489887 ADD-E
            mSearchWidget.setOnQueryTextListener(this);
            //                mSearchWidget.setOnSuggestionListener(this);
            mSearchWidget.setIconifiedByDefault(true);
        }
    }
    //[FEATURE]-Add-BEGIN by CDTS.zhonghua.tuo,05/21/2014,FR 670064
    mLocalSearchItem = menu.findItem(R.id.local_search);
    mServiceSearchItem = menu.findItem(R.id.service_search);
    //[FEATURE]-Add-END by CDTS.zhonghua.tuo

    // the menu should be displayed if the mode is known
    return getMode() != ViewMode.UNKNOWN;
}