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.tlhInganHol.android.klingonassistant.FloatingWindow.java

@Override
public List<DropDownListItem> getDropDownItems(int id) {
    List<DropDownListItem> items = new ArrayList<DropDownListItem>();
    items.add(new DropDownListItem(0, "Restore", new Runnable() {

        @Override//  w  w w . j ava 2 s  . c o m
        public void run() {
            String query = mEditText.getText().toString();
            Intent intent = new Intent(FloatingWindow.this, KlingonAssistant.class);
            // This needs to be set since this is called outside of an activity.
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            // Starting as a main intent is needed to force the menudrawer to load.
            intent.setAction(Intent.ACTION_MAIN);
            startActivity(intent);
            if (!query.equals("")) {
                intent.setAction(Intent.ACTION_SEARCH);
                intent.putExtra(SearchManager.QUERY, query);
                startActivity(intent);
            }
        }
    }));
    return items;
}

From source file:org.wheelmap.android.fragment.SearchDialogFragment.java

protected Bundle createSearchBundle() {
    Bundle bundle = new Bundle();

    String keyword = mKeywordText.getText().toString();
    if (keyword.length() > 0) {
        bundle.putString(SearchManager.QUERY, keyword);
    }//www.  j av a  2  s  . co m

    return bundle;
}

From source file:com.andrew.apollo.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}/*  w  ww.ja va  2 s .  c  o  m*/
 */
@SuppressWarnings("deprecation")
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Title bar shows up in gingerbread, I'm too tired to figure out why.
    if (!ApolloUtils.hasHoneycomb()) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    // Initialze the theme resources
    mResources = new ThemeUtils(this);
    // Set the overflow style
    mResources.setOverflowStyle(this);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Theme the action bar
    final ActionBar actionBar = getSupportActionBar();
    mResources.themeActionBar(actionBar, getString(R.string.app_name));
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set the layout
    setContentView(R.layout.grid_base);

    // Give the background a little UI
    final FrameLayout background = (FrameLayout) findViewById(R.id.grid_base_container);
    background.setBackgroundDrawable(getResources().getDrawable(R.drawable.pager_background));

    // Get the query
    final String query = getIntent().getStringExtra(SearchManager.QUERY);
    mFilterString = !TextUtils.isEmpty(query) ? query : null;

    // Action bar subtitle
    mResources.setSubtitle("\"" + mFilterString + "\"");

    // Initialize the adapter
    mAdapter = new SearchAdapter(this);
    // Set the prefix
    mAdapter.setPrefix(mFilterString);
    // Initialze the list
    mGridView = (GridView) findViewById(R.id.grid_base);
    // Bind the data
    mGridView.setAdapter(mAdapter);
    // Recycle the data
    mGridView.setRecyclerListener(new RecycleHolder());
    // Seepd up scrolling
    mGridView.setOnScrollListener(this);
    mGridView.setOnItemClickListener(this);
    if (ApolloUtils.isLandscape(this)) {
        mGridView.setNumColumns(TWO);
    } else {
        mGridView.setNumColumns(ONE);
    }
    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getSupportLoaderManager().initLoader(0, null, this);
}

From source file:org.runbuddy.tomahawk.utils.MediaPlayIntentHandler.java

public void mediaPlayFromSearch(Bundle extras) {
    mWaitingGenre = null;/*from  w  ww . j a v a  2s  . c o  m*/
    mCorrespondingQueries.clear();
    mCorrespondingRequestIds.clear();
    mResolvingAlbum = null;
    mResolvingArtist = null;

    String mediaFocus = extras.getString(MediaStore.EXTRA_MEDIA_FOCUS);
    String query = extras.getString(SearchManager.QUERY);

    // Some of these extras may not be available depending on the search mode
    String album = extras.getString(MediaStore.EXTRA_MEDIA_ALBUM);
    String artist = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST);
    final String genre = extras.getString("android.intent.extra.genre");
    String playlist = extras.getString("android.intent.extra.playlist");
    String title = extras.getString(MediaStore.EXTRA_MEDIA_TITLE);
    // Determine the search mode and use the corresponding extras
    if (mediaFocus == null) {
        // 'Unstructured' search mode (backward compatible)
        Query q = Query.get(query, false);
        mCorrespondingQueries.clear();
        mCorrespondingQueries.add(PipeLine.get().resolve(q));
    } else if (mediaFocus.compareTo("vnd.android.cursor.item/*") == 0) {
        if (query != null && query.isEmpty()) {
            // 'Any' search mode
            CollectionManager.get().getUserCollection().getQueries(Collection.SORT_ALPHA)
                    .done(new DoneCallback<Playlist>() {
                        @Override
                        public void onDone(Playlist collectionTracks) {
                            playPlaylist(collectionTracks, true);
                        }
                    });
        } else {
            // 'Unstructured' search mode
            Query q = Query.get(query, false);
            mCorrespondingQueries.add(PipeLine.get().resolve(q));
        }
    } else if (mediaFocus.compareTo(MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE) == 0) {
        // 'Genre' search mode
        mWaitingGenre = genre;
        playGenre();
    } else if (mediaFocus.compareTo(MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) == 0) {
        // 'Artist' search mode
        final Artist a = Artist.get(artist);
        CollectionManager.get().getUserCollection().getArtistTracks(a).done(new DoneCallback<Playlist>() {
            @Override
            public void onDone(Playlist result) {
                if (result != null && result.size() > 0) {
                    // There are some local tracks for the requested artist available
                    playPlaylist(result, false);
                } else {
                    // Try fetching top-hits for the requested artist
                    mResolvingArtist = a;
                    mCorrespondingRequestIds.add(InfoSystem.get().resolve(a, true));
                }
            }
        });
    } else if (mediaFocus.compareTo(MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE) == 0) {
        // 'Album' search mode
        final Album a = Album.get(album, Artist.get(artist));
        CollectionManager.get().getUserCollection().getAlbumTracks(a).done(new DoneCallback<Playlist>() {
            @Override
            public void onDone(Playlist result) {
                if (result != null && result.size() > 0) {
                    // There are some local tracks for the requested album available
                    playPlaylist(result, false);
                } else {
                    // Try fetching top-hits for the requested album
                    mResolvingAlbum = a;
                    mCorrespondingRequestIds.add(InfoSystem.get().resolve(a));
                }
            }
        });
    } else if (mediaFocus.compareTo("vnd.android.cursor.item/audio") == 0) {
        // 'Song' search mode
        Query q = Query.get(title, album, artist, false);
        mCorrespondingQueries.add(PipeLine.get().resolve(q));
    } else if (mediaFocus.compareTo(MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE) == 0) {
        // 'Playlist' search mode
        Playlist bestMatch = null;
        float bestScore = 0f;
        float minScore = 0.7f;
        for (Playlist pl : DatabaseHelper.get().getPlaylists()) {
            float score = ResultScoring.calculateScore(pl.getName(), playlist);
            if (score > minScore && score > bestScore) {
                bestMatch = pl;
                bestScore = score;
            }
        }
        if (bestMatch != null) {
            playPlaylist(bestMatch, false);
        }
    }
}

From source file:com.geecko.QuickLyric.SearchActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    String action = intent.getAction();
    if (action != null)
        switch (action) {
        case "android.intent.action.SEARCH":
            this.searchQuery = intent.getStringExtra(SearchManager.QUERY);
            this.refresh();
            break;
        }/*from www  .j  ava2  s . c  o m*/
}

From source file:org.wheelmap.android.fragment.POIsMapWorkerFragment.java

@Override
public void requestSearch(Bundle bundle) {
    if (!bundle.containsKey(SearchManager.QUERY) && !bundle.containsKey(Extra.CATEGORY)
            && !bundle.containsKey(Extra.NODETYPE) && !bundle.containsKey(Extra.WHEELCHAIR_STATE)
            && !bundle.containsKey(Extra.WHEELCHAIR_TOILET_STATE)) {
        return;/*from   ww  w  .ja  va2  s.  c o m*/
    }

    if (bundle.getInt(Extra.CATEGORY) == Extra.UNKNOWN) {
        bundle.remove(Extra.CATEGORY);
    }

    if (!bundle.containsKey(Extra.WHAT)) {
        int what;
        if (bundle.containsKey(Extra.CATEGORY) || bundle.containsKey(Extra.NODETYPE)) {
            what = What.RETRIEVE_NODES;
        } else {
            what = What.SEARCH_NODES_IN_BOX;
        }

        bundle.putInt(Extra.WHAT, what);
    }

    bundle.putParcelable(Extra.STATUS_RECEIVER, mReceiver);
    RestServiceHelper.executeRequest(getActivity(), bundle);
    setSearchModeInt(true);
}

From source file:com.thatkawaiiguy.meleehandbook.activity.SearchResultsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.searchactivity, menu);

    ComponentName cn = new ComponentName(this, SearchResultsActivity.class);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.searchview));

    searchView.onActionViewExpanded();//from   w ww .  ja va2s.  com

    if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
        searchView.setQuery(getIntent().getStringExtra(SearchManager.QUERY).replaceAll("\\s+$", ""), false);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(cn));
        searchView.clearFocus();
    }

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!query.equals(""))
                search(query);
            searchView.clearFocus();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!newText.equals(""))
                search(newText);
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.android.navigationdrawerexample.LeftDrawerActivity.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 (mHorizonDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//from   w  w  w.j  a v a2s . co  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.ksharkapps.musicnow.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}//from  w ww. j  av  a2  s. com
 */
@SuppressWarnings("deprecation")
@Override
protected void onCreate(final Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    actionBar = getSupportActionBar();
    // Fade it in
    overridePendingTransition(R.anim.swipeback_stack_right_in, R.anim.swipeback_stack_to_back);
    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Theme the action bar
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set the layout
    setContentView(R.layout.grid_base);

    // Give the background a little UI
    final FrameLayout background = (FrameLayout) findViewById(R.id.grid_base_container);
    background.setBackgroundDrawable(getResources().getDrawable(R.drawable.pager_background));

    // Get the query
    final String query = getIntent().getStringExtra(SearchManager.QUERY);
    mFilterString = !TextUtils.isEmpty(query) ? query : null;

    // Action bar subtitle
    actionBar.setSubtitle("\"" + mFilterString + "\"");

    // Initialize the adapter
    mAdapter = new SearchAdapter(this);
    // Set the prefix
    mAdapter.setPrefix(mFilterString);
    // Initialze the list
    mGridView = (GridView) findViewById(R.id.grid_base);
    // Bind the data
    mGridView.setAdapter(mAdapter);
    // Recycle the data
    mGridView.setRecyclerListener(new RecycleHolder());
    // Seepd up scrolling
    mGridView.setOnScrollListener(this);
    mGridView.setOnItemClickListener(this);
    if (ApolloUtils.isLandscape(this)) {
        mGridView.setNumColumns(TWO);
    } else {
        mGridView.setNumColumns(ONE);
    }
    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getLoaderManager().initLoader(0, null, this);
}

From source file:dev.drsoran.moloko.activities.TaskSearchResultActivity.java

private String getQueryFromIntent() {
    return getIntent().getExtras().getString(SearchManager.QUERY);
}