Example usage for android.app SearchManager QUERY

List of usage examples for android.app SearchManager QUERY

Introduction

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

Prototype

String QUERY

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

Click Source Link

Document

Intent extra data key: Use this key with android.content.Intent#getStringExtra content.Intent.getStringExtra() to obtain the query string from Intent.ACTION_SEARCH.

Usage

From source file:org.tvheadend.tvhclient.SearchResultActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Quit if the search mode is not active
    if (!Intent.ACTION_SEARCH.equals(intent.getAction()) || !intent.hasExtra(SearchManager.QUERY)) {
        return;//from  w w  w .j av  a 2 s.  c o  m
    }

    // Get the possible channel
    TVHClientApplication app = (TVHClientApplication) getApplication();
    Bundle bundle = intent.getBundleExtra(SearchManager.APP_DATA);
    if (bundle != null) {
        channel = app.getChannel(bundle.getLong(Constants.BUNDLE_CHANNEL_ID));
    } else {
        channel = null;
    }

    // Create the intent with the search options 
    String query = intent.getStringExtra(SearchManager.QUERY);
    pattern = Pattern.compile(query, Pattern.CASE_INSENSITIVE);
    intent = new Intent(SearchResultActivity.this, HTSService.class);
    intent.setAction(Constants.ACTION_EPG_QUERY);
    intent.putExtra("query", query);
    if (channel != null) {
        intent.putExtra(Constants.BUNDLE_CHANNEL_ID, channel.id);
    }

    // Save the query so it can be shown again
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SuggestionProvider.AUTHORITY,
            SuggestionProvider.MODE);
    suggestions.saveRecentQuery(query, null);

    // Now call the service with the query to get results
    startService(intent);

    // Clear the previous results before adding new ones
    adapter.clear();

    // If no channel is given go through the list of programs in all
    // channels and search if the desired program exists. If a channel was
    // given search through the list of programs in the given channel. 
    if (channel == null) {
        for (Channel ch : app.getChannels()) {
            if (ch != null) {
                synchronized (ch.epg) {
                    for (Program p : ch.epg) {
                        if (p != null && p.title != null && p.title.length() > 0) {
                            // Check if the program name matches the search pattern
                            if (pattern.matcher(p.title).find()) {
                                adapter.add(p);
                                adapter.sort();
                                adapter.notifyDataSetChanged();
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (channel.epg != null) {
            synchronized (channel.epg) {
                for (Program p : channel.epg) {
                    if (p != null && p.title != null && p.title.length() > 0) {
                        // Check if the program name matches the search pattern
                        if (pattern.matcher(p.title).find()) {
                            adapter.add(p);
                            adapter.sort();
                            adapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        }
    }

    actionBar.setTitle(android.R.string.search_go);
    actionBar.setSubtitle(getString(R.string.loading));

    // Create the runnable that will initiate the update of the adapter and
    // indicates that we are done when nothing has happened after 2s. 
    updateTask = new Runnable() {
        public void run() {
            adapter.notifyDataSetChanged();
            actionBar.setSubtitle(adapter.getCount() + " " + getString(R.string.results));
        }
    };
}

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();//from  www  .j av  a  2  s. c  o m
    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:ca.rmen.android.palidamuerte.app.poem.list.PoemListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ListView listView = getListView();
    ViewGroup parent = (ViewGroup) listView.getParent();
    final View emptyListView;
    String searchTerms = getActivity().getIntent().getStringExtra(SearchManager.QUERY);
    if (!TextUtils.isEmpty(searchTerms)) {
        emptyListView = getActivity().getLayoutInflater().inflate(R.layout.empty_search_list, parent, false);
        String[] keyWords = Search.getSearchTerms(searchTerms);
        ((TextView) emptyListView.findViewById(R.id.empty_search_list_description)).setText(getResources()
                .getQuantityString(R.plurals.empty_search_list_description, keyWords.length, searchTerms));

    } else {/*  ww  w  .  ja va  2s  .  co  m*/
        emptyListView = getActivity().getLayoutInflater().inflate(R.layout.empty_favorite_list, parent, false);
    }
    TextView emptyTitle = (TextView) emptyListView.findViewById(R.id.title);
    emptyTitle.setTypeface(Font.getTypeface(getActivity()));
    parent.addView(emptyListView);
    listView.setEmptyView(emptyListView);

    // Restore the previously serialized activated item position.
    if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
        setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
    }
}

From source file:com.example.android.contactslist.ui.ContactsActivity.java

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    switch (tab.getPosition()) {
    case 0:/*from  www .  j  av  a 2  s  .com*/
        if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {

            String searchQuery = getIntent().getStringExtra(SearchManager.QUERY);
            ContactsListFragment mContactsListFragment = (ContactsListFragment) getSupportFragmentManager()
                    .findFragmentByTag(ContactsConstants.CONTACT_LIST);

            // This flag notes that the Activity is doing a search, and so the result will be
            // search results rather than all contacts. This prevents the Activity and Fragment
            // from trying to a search on search results.
            isSearchResultView = true;
            mContactsListFragment.setSearchQuery(searchQuery);

            // Set special title for search results
            String title = getString(R.string.contacts_list_search_results_title, searchQuery);
            setTitle(title);
        } else {
            ContactsListFragment mContactsListFragment = new ContactsListFragment();
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, mContactsListFragment, ContactsConstants.CONTACT_LIST)
                    .commit();
        }

        break;

    case 1:
        CallHistoryFragment mCallHistoryFragment = new CallHistoryFragment();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, mCallHistoryFragment, ContactsConstants.CALL_HISTORY)
                .commit();
        break;
    }
}

From source file:fr.cph.chicago.activity.SearchActivity.java

/**
 * Reload adapter with correct data/*www  .  jav  a  2s  . c  om*/
 * 
 * @param intent
 *            the intent
 */
private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);

        DataHolder dataHolder = DataHolder.getInstance();
        BusData busData = dataHolder.getBusData();
        TrainData trainData = dataHolder.getTrainData();

        List<Station> foundStations = new ArrayList<Station>();

        for (Entry<TrainLine, List<Station>> e : trainData.getAllStations().entrySet()) {
            for (Station station : e.getValue()) {
                boolean res = StringUtils.containsIgnoreCase(station.getName(), query.trim());
                if (res) {
                    if (!foundStations.contains(station)) {
                        foundStations.add(station);
                    }
                }
            }
        }

        List<BusRoute> foundBusRoutes = new ArrayList<BusRoute>();

        for (BusRoute busRoute : busData.getRoutes()) {
            boolean res = StringUtils.containsIgnoreCase(busRoute.getId(), query.trim())
                    || StringUtils.containsIgnoreCase(busRoute.getName(), query.trim());
            if (res) {
                if (!foundBusRoutes.contains(busRoute)) {
                    foundBusRoutes.add(busRoute);
                }
            }
        }

        List<BikeStation> foundBikeStations = new ArrayList<BikeStation>();
        if (mBikeStations != null) {
            for (BikeStation bikeStation : mBikeStations) {
                boolean res = StringUtils.containsIgnoreCase(bikeStation.getName(), query.trim())
                        || StringUtils.containsIgnoreCase(bikeStation.getStAddress1(), query.trim());
                if (res) {
                    if (!foundBikeStations.contains(bikeStation)) {
                        foundBikeStations.add(bikeStation);
                    }
                }
            }
        }
        mAdapter.updateData(foundStations, foundBusRoutes, foundBikeStations);
        mAdapter.notifyDataSetChanged();
    }
}

From source file:cm.aptoide.pt.RemoteInSearch.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    query = intent.getStringExtra(SearchManager.QUERY);
    apk_lst = db.getSearch(query, order_lst);
}

From source file:info.guardianproject.otr.app.im.app.ContactListActivity.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    LayoutInflater inflate = getLayoutInflater();

    mContactListView = (ContactListView) inflate.inflate(R.layout.contact_list_view, null);

    mFilterView = (ContactListFilterView) getLayoutInflater().inflate(R.layout.contact_list_filter_view, null);

    mFilterView.setActivity(this);

    mFilterView.getListView().setOnCreateContextMenuListener(this);

    Intent intent = getIntent();/*from   www . j a v  a 2 s .  co  m*/
    mAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1);
    if (mAccountId == -1) {
        finish();
        return;
    }

    setupActionBarList(mAccountId);

    mApp = ImApp.getApplication(this);

    initAccount();

    // Get the intent, verify the action and get the query

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (mIsFiltering) {
            String filterText = intent.getStringExtra(SearchManager.QUERY);
            mFilterView.doFilter(filterText);
        }
    }
}

From source file:dev.dworks.libs.actionbartoggle.demo.SlidingPaneLayoutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mActionBarToggle.onOptionsItemSelected(item)) {
        return true;
    }// w  ww.j  ava  2  s  .  c o m
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_websearch:
        // create intent to perform web search for this planet
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle());
        // catch event that there's no activity to handle intent
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.google.android.panoramio.ImageGrid.java

private void handleIntent(Intent intent) throws IOException, URISyntaxException, JSONException {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        query = intent.getStringExtra(SearchManager.QUERY);
    } else {/* w w  w  .  jav a 2 s.c  om*/
        query = intent.getStringExtra("query");
    }

    if (query == null || query.isEmpty()) {
        query = DEFAULT_QUERY;
    }
    // Start downloading
    mImageManager.load(query);
}

From source file:com.andrew.apolloMod.activities.QueryBrowserActivity.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    if (mAdapter != null) {
        getQueryCursor(mAdapter.getQueryHandler(), null);
    }//w ww  . j  a v  a 2  s.  c om

    Intent intent = getIntent();
    String action = intent != null ? intent.getAction() : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = intent.getData();
        String path = uri.toString();
        if (path.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(this, list, 0);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/artists/")) {
            intent = new Intent(Intent.ACTION_VIEW);

            Bundle bundle = new Bundle();
            bundle.putString(MIME_TYPE, Audio.Artists.CONTENT_TYPE);
            bundle.putString(ARTIST_KEY, uri.getLastPathSegment());
            bundle.putLong(BaseColumns._ID, ApolloUtils.getArtistId(uri.getLastPathSegment(), ARTIST_ID, this));

            intent.setClass(this, TracksBrowser.class);
            intent.putExtras(bundle);
            startActivity(intent);
            return;
        }
    }

    mFilterString = intent.getStringExtra(SearchManager.QUERY);
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS);
        String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
        String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
        String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (focus.equals(Audio.Albums.ENTRY_CONTENT_TYPE)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (focus.equals(Audio.Artists.ENTRY_CONTENT_TYPE)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    setContentView(R.layout.listview);
    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
    if (mAdapter == null) {
        mAdapter = new QueryListAdapter(getApplication(), this, R.layout.listview_items, null, // cursor
                new String[] {}, new int[] {}, 0);
        setListAdapter(mAdapter);
        if (TextUtils.isEmpty(mFilterString)) {
            getQueryCursor(mAdapter.getQueryHandler(), null);
        } else {
            mTrackList.setFilterText(mFilterString);
            mFilterString = null;
        }
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mQueryCursor = mAdapter.getCursor();
        if (mQueryCursor != null) {
            init(mQueryCursor);
        } else {
            getQueryCursor(mAdapter.getQueryHandler(), mFilterString);
        }
    }

    LinearLayout emptyness = (LinearLayout) findViewById(R.id.empty_view);
    emptyness.setVisibility(View.GONE);
}