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.timemachine.controller.ControllerActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String input = intent.getStringExtra(SearchManager.QUERY);
        String suggestion = (String) intent.getExtras().get("intent_extra_data_key");
        String query;//  w  w  w  .j a  v a  2s.  c  om
        // Use the query to search your data somehow
        if (suggestion == null)
            query = input;
        else
            query = suggestion;
        Geocoder geocoder = new Geocoder(ControllerActivity.this);
        try {
            List<Address> address = geocoder.getFromLocationName(query, 1);
            if (address != null && !address.isEmpty()) {
                Address location = address.get(0);
                System.out.println(location.getLatitude() + ", " + location.getLongitude());
                mMap.animateCamera(
                        CameraUpdateFactory.newLatLngZoom(
                                new LatLng(location.getLatitude(), location.getLongitude()), maxZoom),
                        animateCameraDuration, null);
            } else
                System.out.println("No address found.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.bukanir.android.activities.MoviesListActivity.java

private void handleSearchIntent(Intent intent) {
    Log.d(TAG, "handleSearchIntent");
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (Utils.isNetworkAvailable(this)) {
            Log.d(TAG, "networkAvailable");
            moviesTask = new MoviesTask();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                moviesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query, null);
            } else {
                moviesTask.execute(query, null);
            }/*from  ww w. j  a v a 2 s.c o  m*/
        } else {
            Toast.makeText(this, getString(R.string.network_not_available), Toast.LENGTH_LONG).show();
        }
    }
}

From source file:free.yhc.netmbuddy.YTSearchActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);// w  ww .jav a 2  s .c  o  m
    if (!Intent.ACTION_SEARCH.equals(intent.getAction()))
        return; // ignore unexpected intent

    final String query = intent.getStringExtra(SearchManager.QUERY);
    SearchSuggestionProvider.saveRecentQuery(query);
    disablePageIndexBar();
    Utils.getUiHandler().post(new Runnable() {
        @Override
        public void run() {
            startNewSearch(query, query);
        }
    });
}

From source file:com.gimranov.zandy.app.ItemActivity.java

private Cursor prepareCursor() {
    Cursor cursor;/* w  ww. j av  a  2 s.com*/
    // Be ready for a search
    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        query = intent.getStringExtra(SearchManager.QUERY);
        cursor = getCursor(query);
        this.setTitle(getResources().getString(R.string.search_results, query));
    } else if (query != null) {
        cursor = getCursor(query);
        this.setTitle(getResources().getString(R.string.search_results, query));
    } else if (intent.getStringExtra("com.gimranov.zandy.app.tag") != null) {
        String tag = intent.getStringExtra("com.gimranov.zandy.app.tag");
        Query q = new Query();
        q.set("tag", tag);
        cursor = getCursor(q);
        this.setTitle(getResources().getString(R.string.tag_viewing_items, tag));
    } else {
        collectionKey = intent.getStringExtra("com.gimranov.zandy.app.collectionKey");

        ItemCollection coll;

        if (collectionKey != null && (coll = ItemCollection.load(collectionKey, db)) != null) {
            cursor = getCursor(coll);
            this.setTitle(coll.getTitle());
        } else {
            cursor = getCursor();
            this.setTitle(getResources().getString(R.string.all_items));
        }
    }
    return cursor;
}

From source file:org.geometerplus.android.fbreader.QuotesFragmentActivity.java

@Override
protected void onNewIntent(Intent intent) {
    OrientationUtil.setOrientation(this, intent);

    if (!Intent.ACTION_SEARCH.equals(intent.getAction())) {
        return;/*  ww  w. ja va 2s.co m*/
    }
    String pattern = intent.getStringExtra(SearchManager.QUERY);
    myQuoteSearchPatternOption.setValue(pattern);

    final LinkedList<Quote> quotes = new LinkedList<Quote>();
    pattern = pattern.toLowerCase();
    for (Quote b : myAllBooksAdapter.quotes()) {
        if (MiscUtil.matchesIgnoreCase(b.getText(), pattern)) {
            quotes.add(b);
        }
    }
    if (!quotes.isEmpty()) {
        showSearchResultsTab(quotes);
    } else {
        UIUtil.showErrorMessage(this, "quoteNotFound");
    }
}

From source file:com.app_software.chromisstock.ProductListActivity.java

private void askCreateProduct(final String code) {

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(getResources().getString(R.string.dlg_new_barcode_title));
    alert.setMessage(getResources().getString(R.string.dlg_new_barcode_message));

    alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Bundle values = new Bundle();
            values.putString(StockProduct.CODE, code);
            Long id = DatabaseHandler.getInstance(getApplicationContext()).createProduct(values);
            onItemSelected(id);//from ww  w. ja va 2s. c o m
        }
    });

    alert.setNeutralButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Use the scanned data in a new search fragment
            Log.v(TAG, "Barcode not in system, starting search");
            Intent i = new Intent(getApplicationContext(), ProductListActivity.class);
            i.putExtra(SearchManager.QUERY, code);
            i.setAction(Intent.ACTION_SEARCH);
            startActivity(i);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });

    alert.show();
}

From source file:com.paranoid.gerrit.GerritControllerActivity.java

private void handleIntent(Intent intent) {
    String action = intent.getAction();
    if (TheApplication.PREF_CHANGE_TYPE.equals(action)) {
        onPreferenceChanged(intent.getStringExtra(TheApplication.PREF_CHANGE_KEY));
    } else if (!Intent.ACTION_SEARCH.equals(action)) {
        // Searching is already handled when the query text changes.
        init();//from   w ww . j  a  v  a 2  s. co  m
    }
}

From source file:com.audiokernel.euphonyrmt.SearchActivity.java

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

    setContentView(R.layout.search_results);

    final SearchResultsPagerAdapter adapter = new SearchResultsPagerAdapter();
    final ActionBar actionBar = getSupportActionBar();

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);/* ww  w.ja v  a 2 s.c o m*/
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(final int position) {
            // When swiping between pages, select the corresponding tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mTabArtists = actionBar.newTab().setText(R.string.artists).setTabListener(this);
    actionBar.addTab(mTabArtists);

    mTabAlbums = actionBar.newTab().setText(R.string.albums).setTabListener(this);
    actionBar.addTab(mTabAlbums);

    mTabSongs = actionBar.newTab().setText(R.string.songs).setTabListener(this);
    actionBar.addTab(mTabSongs);

    mListArtistsFrame = findViewById(R.id.list_artists_frame);
    mNoResultArtistsView = mListArtistsFrame.findViewById(R.id.no_artist_result);
    mListArtists = (ListView) mListArtistsFrame.findViewById(android.R.id.list);
    mListArtists.setOnItemClickListener(this);

    mListAlbumsFrame = findViewById(R.id.list_albums_frame);
    mNoResultAlbumsView = mListAlbumsFrame.findViewById(R.id.no_album_result);
    mListAlbums = (ListView) mListAlbumsFrame.findViewById(android.R.id.list);
    mListAlbums.setOnItemClickListener(this);

    mListSongsFrame = findViewById(R.id.list_songs_frame);
    mNoResultSongsView = mListSongsFrame.findViewById(R.id.no_song_result);
    mListSongs = (ListView) mListSongsFrame.findViewById(android.R.id.list);
    mListSongs.setOnItemClickListener(this);

    mLoadingView = findViewById(R.id.loadingLayout);
    mLoadingView.setVisibility(View.VISIBLE);

    final Intent queryIntent = getIntent();
    final String queryAction = queryIntent.getAction();

    if (Intent.ACTION_SEARCH.equals(queryAction) || PLAY_SERVICES_ACTION_SEARCH.equals(queryAction)) {
        mSearchKeywords = queryIntent.getStringExtra(SearchManager.QUERY).trim();
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                SearchRecentProvider.AUTHORITY, SearchRecentProvider.MODE);
        suggestions.saveRecentQuery(mSearchKeywords, null);
    } else {
        return; // Bye !
    }

    setTitle(getTitle() + " : " + mSearchKeywords);

    registerForContextMenu(mListArtists);
    registerForContextMenu(mListAlbums);
    registerForContextMenu(mListSongs);

    updateList();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

From source file:ru.besttuts.stockwidget.ui.SearchableQuoteActivity.java

private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        Bundle data = new Bundle();
        data.putString("query", intent.getStringExtra(SearchManager.QUERY));
        getSupportLoaderManager().restartLoader(URL_LOADER, data, this);
    }/*  ww  w . j a  va 2  s. c o  m*/
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        // Handle a suggestions click (because the suggestions all use ACTION_VIEW)
        Uri data = intent.getData();
        Result result = SymbolProvider.tempMap.get(data.getPath().substring("/symbols/".length()));
        if (null != mDataSource) {
            mDataSource.addQuoteRec(result);
        }
        LOGD(TAG, "handleIntent(Intent.ACTION_VIEW): " + data);

        searchView.setQuery("", false);
        searchView.clearFocus();
        // intent.getExtras().getString(SearchManager.EXTRA_DATA_KEY)
        //            showResult(data);
    }
}