Example usage for android.app SearchManager SUGGEST_URI_PATH_QUERY

List of usage examples for android.app SearchManager SUGGEST_URI_PATH_QUERY

Introduction

In this page you can find the example usage for android.app SearchManager SUGGEST_URI_PATH_QUERY.

Prototype

String SUGGEST_URI_PATH_QUERY

To view the source code for android.app SearchManager SUGGEST_URI_PATH_QUERY.

Click Source Link

Document

Uri path for queried suggestions data.

Usage

From source file:fr.matthiasbosc.translucentmap.PlaceProvider.java

private static UriMatcher buildUriMatcher() {

    UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    // URI for "Go" button
    uriMatcher.addURI(AUTHORITY, "search", SEARCH);

    // URI for suggestions in Search Dialog
    uriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SUGGESTIONS);

    // URI for Details
    uriMatcher.addURI(AUTHORITY, "details", DETAILS);

    return uriMatcher;
}

From source file:com.owncloud.android.providers.UsersAndGroupsSearchProvider.java

@Override
public boolean onCreate() {
    mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH);
    return true;/*  w ww . j av  a  2s. c o m*/
}

From source file:com.google.android.demos.jamendo.app.SearchActivity.java

/** {@inheritDoc} */
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Intent intent = getIntent();/*from   w  ww  . j ava  2s. c  om*/
    String query = intent.getStringExtra(SearchManager.QUERY);

    Uri.Builder builder = JamendoContract.AUTHORITY_URI.buildUpon();
    builder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
    builder.appendPath(query);
    Uri uri = builder.build();
    String[] projection = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_ICON_2,
            SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2 };
    String selection = JamendoContract.PARAM_IMAGE_SIZE + "=" + mImageSize;
    String[] selectionArgs = null;
    String sortOrder = null;
    return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder);
}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java

@Test
public void test_Intents() {
    // Launch activity with ACTION_SEARCH intent and then trigger new ACTION_VIEW intent

    // Launch activity
    Intent intent = getNewIntent();//  w w w .  j  a va  2 s .  c om
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(SearchManager.QUERY, SEARCH_TEXT);
    createWithIntent(intent);
    // Verify onCreate() resulted in LoaderCallbacks object being created 
    assertThat(titleSearchResultsActivity.loaderCallbacks).isNotNull();
    // Verify LoaderManager restartLoader called with correct search term
    ArgumentCaptor<Bundle> arguments = ArgumentCaptor.forClass(Bundle.class);
    verify(loaderManager).restartLoader(eq(0), arguments.capture(),
            eq(titleSearchResultsActivity.loaderCallbacks));
    assertThat(arguments.getValue().containsKey("QUERY_TEXT_KEY"));
    assertThat(arguments.getValue().get("QUERY_TEXT_KEY")).isEqualTo(SEARCH_TEXT);
    // Verify setOnItemClickListener called on view
    verify(listView).setOnItemClickListener(isA(OnItemClickListener.class));
    // Verify Loader constructor arguments have correct details
    SuggestionCursorParameters params = new SuggestionCursorParameters(arguments.getValue(),
            ClassyFySearchEngine.LEX_CONTENT_URI, 50);
    assertThat(params.getUri())
            .isEqualTo(Uri.parse("content://au.com.cybersearch2.classyfy.ClassyFyProvider/lex/"
                    + SearchManager.SUGGEST_URI_PATH_QUERY));
    assertThat(params.getProjection()).isNull();
    assertThat(params.getSelection()).isEqualTo("word MATCH ?");
    assertThat(params.getSelectionArgs()).isEqualTo(new String[] { SEARCH_TEXT });
    assertThat(params.getSortOrder()).isNull();
    // Verify Loader callbacks in sequence onCreateLoader, onLoadFinished and onLoaderReset
    CursorLoader cursorLoader = (CursorLoader) titleSearchResultsActivity.loaderCallbacks.onCreateLoader(0,
            arguments.getValue());
    Cursor cursor = mock(Cursor.class);
    titleSearchResultsActivity.loaderCallbacks.onLoadFinished(cursorLoader, cursor);
    verify(simpleCursorAdapter).swapCursor(cursor);
    titleSearchResultsActivity.loaderCallbacks.onLoaderReset(cursorLoader);
    verify(simpleCursorAdapter).swapCursor(null);
    // Trigger new ACTION_VIEW intent and confirm MainActivity started with ACTION_VIEW intent
    intent = getNewIntent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri actionUri = Uri.withAppendedPath(ClassyFySearchEngine.CONTENT_URI, "44");
    intent.setData(actionUri);
    titleSearchResultsActivity.onNewIntent(intent);
    ShadowActivity shadowActivity = Robolectric.shadowOf(titleSearchResultsActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData()).isEqualTo(actionUri);
    ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName())
            .isEqualTo("au.com.cybersearch2.classyfy.MainActivity");
}

From source file:org.voidsink.anewjkuapp.fragment.MapFragment.java

private void doSearch(String query, boolean isExactLocation) {
    query = query.trim();/*  ww  w  .  j av a 2 s.  co m*/
    Log.i(TAG, "query: " + query);

    List<Poi> pois = new ArrayList<>();

    ContentResolver cr = getContext().getContentResolver();
    Uri searchUri = PoiContentContract.CONTENT_URI.buildUpon().appendPath(SearchManager.SUGGEST_URI_PATH_QUERY)
            .appendPath(query).build();
    Cursor c = cr.query(searchUri, ImportPoiTask.POI_PROJECTION, null, null, null);
    while (c.moveToNext()) {
        Poi p = new Poi(c);
        if (!isExactLocation || p.getName().equalsIgnoreCase(query)) {
            pois.add(p);
        }
    }
    c.close();

    if (pois.size() == 0) {
        Toast.makeText(getContext(), String.format(getContext().getString(R.string.map_place_not_found), query),
                Toast.LENGTH_LONG).show();
    } else if (pois.size() == 1) {
        finishSearch(pois.get(0));
    } else {
        AlertDialog.Builder poiSelector = new AlertDialog.Builder(getContext());

        poiSelector.setTitle(R.string.map_select_location);

        final PoiAdapter arrayAdapter = new PoiAdapter(getContext());
        arrayAdapter.addAll(pois);

        poiSelector.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        poiSelector.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finishSearch(arrayAdapter.getItem(which));
            }
        });
        poiSelector.show();
    }
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SuggestionsAdapter.java

public Cursor getSuggestions(String query, int limit) {
    Uri.Builder uriBuilder = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).query("") // TODO: Remove, workaround for a bug in Uri.writeToParcel()
            .fragment(""); // TODO: Remove, workaround for a bug in Uri.writeToParcel()

    // append standard suggestion query path
    uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);

    // inject query, either as selection args or inline
    uriBuilder.appendPath(query);/* w ww . j  a v  a 2  s .  c om*/

    if (limit > 0) {
        uriBuilder.appendQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT, String.valueOf(limit));
    }

    Uri uri = uriBuilder.build();

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

From source file:com.actionbarsherlock.widget.SuggestionsAdapter.java

public Cursor getSuggestions(String query, int limit) {
    if (mSearchable == null) {
        return null;
    }/*from   w  w  w.  j  ava  2s .  c  o m*/

    String authority = mSearchable.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 = mSearchable.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 = mSearchable.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.tandong.sa.sherlock.widget.SuggestionsAdapter.java

public Cursor getSuggestions(String query, int limit) {
    if (mSearchable == null) {
        return null;
    }/*  w  w  w  . j  a  va 2  s . c  o m*/

    String authority = mSearchable.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 = mSearchable.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 = mSearchable.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.aboveware.sms.contacts.ContactSuggestionsAdapter.java

/**
 * Import of hidden method: SearchManager.getSuggestions(SearchableInfo, String, int).
 *///w ww .j  a va 2s  .  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:me.piebridge.bible.Bible.java

public LinkedHashMap<String, String> getOsiss(String book, int limit) {
    LinkedHashMap<String, String> osiss = new LinkedHashMap<String, String>();

    if (book != null) {
        // fix for zhcn
        book = book.replace("", "");
        book = book.replace("", "");
        book = book.replace("", "??");
        book = book.replace(SearchManager.SUGGEST_URI_PATH_QUERY, "").replace(" ", "").toLowerCase(Locale.US);
    }//from w w  w .  java 2  s.  c  o m

    Log.d(TAG, "book: " + book);

    ArrayList<Entry<String, String>> maps = new ArrayList<Entry<String, String>>();

    for (Entry<String, String> entry : searchshort.entrySet()) {
        maps.add(entry);
    }

    for (Entry<String, String> entry : searchfull.entrySet()) {
        maps.add(entry);
    }

    for (LinkedHashMap<String, String> map : getMaps(TYPE.HUMAN)) {
        for (Entry<String, String> entry : map.entrySet()) {
            maps.add(entry);
        }
    }

    for (LinkedHashMap<String, String> map : getMaps(TYPE.OSIS)) {
        for (Entry<String, String> entry : map.entrySet()) {
            maps.add(entry);
        }
    }

    if (book == null || "".equals(book)) {
        for (int i = 0; i < this.osiss.size() && i < limit; ++i) {
            osiss.put(humans.get(i), this.osiss.get(i));
        }
        return osiss;
    }

    for (Entry<String, String> entry : maps) {
        if (checkStartSuggest(osiss, entry.getValue(), entry.getValue(), book, limit)) {
            return osiss;
        }
    }

    for (Entry<String, String> entry : maps) {
        if (checkContainSuggest(osiss, entry.getValue(), entry.getValue(), book, limit)) {
            return osiss;
        }
    }

    for (Entry<String, String> entry : maps) {
        if (checkStartSuggest(osiss, entry.getKey(), entry.getValue(), book, limit)) {
            return osiss;
        }
    }

    for (Entry<String, String> entry : maps) {
        if (checkContainSuggest(osiss, entry.getKey(), entry.getValue(), book, limit)) {
            return osiss;
        }
    }

    String osis = "";
    String chapter = "";
    if (osiss.size() == 0) {
        ArrayList<OsisItem> items = OsisItem.parseSearch(book, mContext);
        if (items.size() == 1) {
            OsisItem item = items.get(0);
            osis = item.book;
            chapter = item.chapter;
        }
    } else if (osiss.size() == 1) {
        for (Entry<String, String> entry : osiss.entrySet()) {
            osis = entry.getValue();
            chapter = "0";
        }
    }

    if ("".equals(osis)) {
        return osiss;
    }

    String bookname = get(TYPE.HUMAN, bible.getPosition(TYPE.OSIS, osis));
    if (bookname == null) {
        bookname = osis;
    }
    int chapternum = 0;
    int maxchapter = 0;
    try {
        chapternum = Integer.parseInt(chapter);
    } catch (Exception e) {
    }
    try {
        maxchapter = Integer.parseInt(get(TYPE.CHAPTER, getPosition(TYPE.OSIS, osis)));
    } catch (Exception e) {
        return osiss;
    }
    if (bookname == null || "".equals(bookname)) {
        return osiss;
    }
    if (chapternum != 0) {
        osiss.put(bookname + " " + chapternum, osis + chapternum);
    }
    for (int i = 0 + chapternum * 10; i <= maxchapter && i < 10 * chapternum + 10; i++) {
        if (i != 0) {
            osiss.put(bookname + " " + i, osis + i);
        }
    }

    return osiss;
}