Example usage for android.content Intent ACTION_SEARCH

List of usage examples for android.content Intent ACTION_SEARCH

Introduction

In this page you can find the example usage for android.content Intent ACTION_SEARCH.

Prototype

String ACTION_SEARCH

To view the source code for android.content Intent ACTION_SEARCH.

Click Source Link

Document

Activity Action: Perform a search.

Usage

From source file:com.dmsl.anyplace.SearchPOIActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        // get the search type
        mSearchType = (SearchTypes) intent.getSerializableExtra("searchType");
        if (mSearchType == null)
            finishSearch("No search type provided!", null);

        // get the query string
        final String query = intent.getStringExtra("query");
        double lat = intent.getDoubleExtra("lat", 0);
        double lng = intent.getDoubleExtra("lng", 0);

        AnyplaceSuggestionsTask mSuggestionsTask = new AnyplaceSuggestionsTask(
                new AnyplaceSuggestionsTask.AnyplaceSuggestionsListener() {

                    @Override/*from   w w w .java 2s  .  com*/
                    public void onSuccess(String result, List<? extends IPoisClass> pois) {

                        // we have pois to query for a match
                        mQueriedPoisStr = new ArrayList<Spanned>();
                        mQueriedPois = pois;

                        // Display part of Description Text Only
                        // Make an approximation of available space based on map size
                        final int viewWidth = (int) (findViewById(R.id.txtResultsFound).getWidth() * 2);
                        View infoWindow = getLayoutInflater()
                                .inflate(R.layout.queried_pois_item_1_searchactivity, null);
                        TextView infoSnippet = (TextView) infoWindow;
                        TextPaint paint = infoSnippet.getPaint();

                        // Regular expression
                        // ?i ignore case
                        Pattern pattern = Pattern.compile(String.format("((?i)%s)", query));

                        for (IPoisClass pm : pois) {
                            String name = "", description = "";
                            Matcher m;
                            m = pattern.matcher(pm.name());
                            // Makes matched query bold using HTML format
                            // $1 returns the regular's expression outer parenthesis value
                            name = m.replaceAll("<b>$1</b>");

                            m = pattern.matcher(pm.description());
                            if (m.find()) {
                                // Makes matched query bold using HTML format
                                // $1 returns the regular's expression outer parenthesis value
                                int startIndex = m.start();
                                description = m.replaceAll("<b>$1</b>");
                                description = AndroidUtils.fillTextBox(paint, viewWidth, description,
                                        startIndex + 3);
                            }
                            mQueriedPoisStr.add(Html.fromHtml(name + "<br>" + description));
                        }

                        ArrayAdapter<Spanned> mAdapter = new ArrayAdapter<Spanned>(
                                // getBaseContext(), R.layout.queried_pois_item_1,
                                getBaseContext(), R.layout.queried_pois_item_1_searchactivity, mQueriedPoisStr);
                        lvResultPois.setAdapter(mAdapter);
                        txtResultsFound.setText("Results found [ " + mQueriedPoisStr.size() + " ]");

                    }

                    @Override
                    public void onErrorOrCancel(String result) {
                        // no pois exist
                        finishSearch("No Points of Interest exist!", null);
                    }

                    @Override
                    public void onUpdateStatus(String string, Cursor cursor) {
                        SimpleCursorAdapter adapter = new SimpleCursorAdapter(getBaseContext(),
                                R.layout.queried_pois_item_1_searchactivity, cursor,
                                new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 },
                                new int[] { android.R.id.text1 });
                        lvResultPois.setAdapter(adapter);
                        txtResultsFound.setText("Results found [ " + cursor.getCount() + " ]");
                    }

                }, this, mSearchType, new GeoPoint(lat, lng), query);
        mSuggestionsTask.execute();

    }
}

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;// w w w  .ja  va 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:com.example.android.contactslist.ui.ContactsActivity.java

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    switch (tab.getPosition()) {
    case 0://from  w  w w  . j av a  2s . c o m
        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: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  w  w  w .  ja va 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: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 v  a  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:fr.cph.chicago.activity.SearchActivity.java

/**
 * Reload adapter with correct data/*from   ww  w.  ja va2s  .c  o  m*/
 * 
 * @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:uk.org.crimetalk.SearchActivity.java

@Override
protected void onNewIntent(Intent intent) {

    // User pressed search so start new SearchFragment
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container,
                        SearchFragment.newInstance(
                                getIntent().getExtras().getParcelableArrayList(ARG_ARTICLE_LIST_HELPER_LIST),
                                intent.getStringExtra(SearchManager.QUERY)))
                .commit();/*from ww  w. j  a v a 2  s .  c o m*/

        // Change search hint text to reflect new search
        if (getIntent().getExtras().getString(ARG_SEARCH_TEXT)
                .equals(getResources().getString(R.string.search_library))) {

            ((TextView) findViewById(R.id.search))
                    .setText(String.format(getResources().getString(R.string.searching_library_for),
                            intent.getStringExtra(SearchManager.QUERY)));

        } else {

            ((TextView) findViewById(R.id.search))
                    .setText(String.format(getResources().getString(R.string.searching_press_cuttings_for),
                            intent.getStringExtra(SearchManager.QUERY)));

        }

    }

}

From source file:org.klnusbaum.udj.EventActivity.java

protected void onNewIntent(Intent intent) {
    Log.d(TAG, "In on new intent");
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        intent.setClass(this, MusicSearchActivity.class);
        startActivityForResult(intent, 0);
    }//from   ww  w. j a  v a  2  s . co  m
}

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 {/* www .j  a  v 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.murati.oszk.audiobook.ui.BaseActivity.java

/**
 * Assuming this activity was started with a new intent, process the incoming information and
 * react accordingly./*from   ww  w.  j a v a 2 s.  c o  m*/
 * @param intent
 */
private void handleIntent(Intent intent) {
    // Special processing of the incoming intent only occurs if the if the action specified
    // by the intent is ACTION_SEARCH.
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        // SearchManager.QUERY is the key that a dsfdsSearchManager will use to send a query string
        // to an Activity.
        String query = intent.getStringExtra(SearchManager.QUERY);
        //SearchQuery = query;

        // We need to create a bundle containing the query string to send along to the
        // LoaderManager, which will be handling querying the database and returning results.
        Bundle bundle = new Bundle();
        //bundle.putString(QUERY_KEY, query);

        //ContactablesLoaderCallbacks loaderCallbacks = new ContactablesLoaderCallbacks(this);

        // Start the loader with the new query, and an object that will handle all callbacks.
        //getLoaderManager().restartLoader(CONTACT_QUERY_LOADER, bundle, loaderCallbacks);
    }
}