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.geometerplus.android.fbreader.FBReader.java

@Override
protected void onNewIntent(final Intent intent) {
    final String action = intent.getAction();
    final Uri data = intent.getData();

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
        super.onNewIntent(intent);
    } else if (Intent.ACTION_VIEW.equals(action) && data != null
            && "fbreader-action".equals(data.getScheme())) {
        myFBReaderApp.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
    } else if (Intent.ACTION_VIEW.equals(action) || FBReaderIntents.Action.VIEW.equals(action)) {
        myOpenBookIntent = intent;/*from w  w w.j  av a2s . c o  m*/
        if (myFBReaderApp.Model == null && myFBReaderApp.ExternalBook != null) {
            final ExternalFormatPlugin plugin = (ExternalFormatPlugin) myFBReaderApp.ExternalBook
                    .getPluginOrNull();
            try {
                startActivity(PluginUtil.createIntent(plugin, PluginUtil.ACTION_KILL));
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
            }
        }
    } else if (FBReaderIntents.Action.PLUGIN.equals(action)) {
        new RunPluginAction(this, myFBReaderApp, data).run();
    } else if (Intent.ACTION_SEARCH.equals(action)) {
        final String pattern = intent.getStringExtra(SearchManager.QUERY);
        final Runnable runnable = new Runnable() {
            public void run() {
                final TextSearchPopup popup = (TextSearchPopup) myFBReaderApp.getPopupById(TextSearchPopup.ID);
                popup.initPosition();
                myFBReaderApp.MiscOptions.TextSearchPattern.setValue(pattern);
                if (myFBReaderApp.getTextView().search(pattern, true, false, false, false) != 0) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            myFBReaderApp.showPopup(popup.getId());
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            UIUtil.showErrorMessage(FBReader.this, "textNotFound");
                            popup.StartPosition = null;
                        }
                    });
                }
            }
        };
        UIUtil.wait("search", runnable, this);
    } else if (FBReaderIntents.Action.CLOSE.equals(intent.getAction())) {
        myCancelIntent = intent;
        myOpenBookIntent = null;
    } else if (FBReaderIntents.Action.PLUGIN_CRASH.equals(intent.getAction())) {
        final Book book = FBReaderIntents.getBookExtra(intent);
        myFBReaderApp.ExternalBook = null;
        myOpenBookIntent = null;
        getCollection().bindToService(this, new Runnable() {
            public void run() {
                Book b = myFBReaderApp.Collection.getRecentBook(0);
                if (b.equals(book)) {
                    b = myFBReaderApp.Collection.getRecentBook(1);
                }
                myFBReaderApp.openBook(b, null, null, FBReader.this);
            }
        });
    } else {
        super.onNewIntent(intent);
    }
}

From source file:com.example.android.navigationdrawerexample.MainActivity.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 (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*from   w w w .j a  v  a  2 s  .c  om*/
    // 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, getActionBar().getTitle());
        // catch event that there's no activity to handle intent
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            makeText(this, R.string.app_not_available, LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.yammp.app.TrackFragment.java

private void doSearch() {

    CharSequence title = null;//www  .  j av a2 s. com
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = mCurrentTrackName;
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
        query = mCurrentTrackName;
    } else {
        query = mCurrentArtistNameForAlbum + " " + mCurrentTrackName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
    }
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentAlbumName)) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:com.contralabs.inmap.activities.MainActivity.java

private boolean verifyIntentSearch(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        EasyTracker.getTracker().sendEvent("UserAction", "Search", query, 0l);
        if (query.length() > 2 && query.endsWith("s")) // To search plurals as singular (pt)
            query = query.substring(0, query.length() - 1);
        mStoreListFragment.setStoreParameters(new StoreParameters().setText(query));
        if (!isLeftMenuShowing())
            toggleList();//from ww  w  .jav  a  2s  .c  om
        if (!isShowingStoreList)
            showStoreList();
        mDbAdapter.open();
        try {
            mDbAdapter.saveSearchPerformed(null, query); // FIXME Get facebook id if logged in
        } finally {
            mDbAdapter.close();
        }
        return true;
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        // Handle a suggestions click (because the suggestions all use ACTION_VIEW)
        long id = Long.parseLong(intent.getDataString());
        Store store;
        mDbAdapter.open();
        try {
            store = mDbAdapter.getStore(id);
        } finally {
            mDbAdapter.close();
        }
        onStoreSelected(store);
        return true;
    } else if (intent.getBooleanExtra(SHOW_SEARCH, false)) {
        onSearchClicked();
        return true;
    }
    return false;
}

From source file:com.android.app.MediaPlaybackActivity.java

public boolean onLongClick(View view) {

    CharSequence title = null;/*from www  . java2s . c o m*/
    String mime = null;
    String query = null;
    String artist;
    String album;
    String song;
    long audioid;

    try {
        artist = mService.getArtistName();
        album = mService.getAlbumName();
        song = mService.getTrackName();
        audioid = mService.getAudioId();
    } catch (RemoteException ex) {
        return true;
    } catch (NullPointerException ex) {
        // we might not actually have the service yet
        return true;
    }

    if (MediaStore.UNKNOWN_STRING.equals(album) && MediaStore.UNKNOWN_STRING.equals(artist) && song != null
            && song.startsWith("recording")) {
        // not music
        return false;
    }

    if (audioid < 0) {
        return false;
    }

    Cursor c = MusicUtils.query(this,
            ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioid),
            new String[] { MediaStore.Audio.Media.IS_MUSIC }, null, null, null);
    boolean ismusic = true;
    if (c != null) {
        if (c.moveToFirst()) {
            ismusic = c.getInt(0) != 0;
        }
        c.close();
    }
    if (!ismusic) {
        return false;
    }

    boolean knownartist = (artist != null) && !MediaStore.UNKNOWN_STRING.equals(artist);

    boolean knownalbum = (album != null) && !MediaStore.UNKNOWN_STRING.equals(album);

    if (knownartist && view.equals(mArtistName.getParent())) {
        title = artist;
        query = artist;
        mime = MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE;
    } else if (knownalbum && view.equals(mAlbumName.getParent())) {
        title = album;
        if (knownartist) {
            query = artist + " " + album;
        } else {
            query = album;
        }
        mime = MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE;
    } else if (view.equals(mTrackName.getParent()) || !knownartist || !knownalbum) {
        if ((song == null) || MediaStore.UNKNOWN_STRING.equals(song)) {
            // A popup of the form "Search for null/'' using ..." is pretty
            // unhelpful, plus, we won't find any way to buy it anyway.
            return true;
        }

        title = song;
        if (knownartist) {
            query = artist + " " + song;
        } else {
            query = song;
        }
        mime = "audio/*"; // the specific type doesn't matter, so don't bother retrieving it
    } else {
        throw new RuntimeException("shouldn't be here");
    }
    title = getString(R.string.mediasearch, title);

    Intent i = new Intent();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.putExtra(SearchManager.QUERY, query);
    if (knownartist) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    if (knownalbum) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, song);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, mime);

    startActivity(Intent.createChooser(i, title));
    return true;
}

From source file:com.example.volunteerhandbook.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (noDrawYet)
        return true;
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*from   w w  w .jav  a  2s  .c o  m*/
    // Handle action buttons
    closeSpeaker();
    ListRecordBase record = (ListRecordBase) mCurrentFragment;
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.action_new:
    case R.id.action_modify:
    case R.id.action_delete:
    case R.id.action_check:
    case R.id.action_save:
        record.getArguments().putInt(ListRecordBase.ACTION_TYPE, itemId);
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.main_content_frame, mCurrentFragment).commit();
        break;
    case R.id.action_join:
        break;
    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, getActionBar().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();
    default:
        super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static boolean executeSearch(String search, Context context, SessionInfo sessionInfo) {
    Intent myIntent = new Intent(Intent.ACTION_SEARCH);
    myIntent.setClass(context, MetaSearch.class);
    RemoteProfile remoteProfile = sessionInfo.getRemoteProfile();
    if (remoteProfile != null && remoteProfile.getRemoteType() == RemoteProfile.TYPE_LOOKUP) {
        Bundle bundle = new Bundle();
        bundle.putString("com.vuze.android.remote.searchsource", sessionInfo.getRpcRoot());
        if (remoteProfile.getRemoteType() == RemoteProfile.TYPE_LOOKUP) {
            bundle.putString("com.vuze.android.remote.ac", remoteProfile.getAC());
        }//  w w  w .  j a v a 2s . co m
        bundle.putString(SessionInfoManager.BUNDLE_KEY, remoteProfile.getID());

        myIntent.putExtra(SearchManager.APP_DATA, bundle);
    }

    myIntent.putExtra(SearchManager.QUERY, search);

    context.startActivity(myIntent);
    return true;
}

From source file:com.tt.jobtracker.MainActivity.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 (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }// www. ja  va  2 s  . co m
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_logout:
        // 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_name, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.visva.voicerecorder.view.fragments.FragmentContact.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (!TextUtils.isEmpty(mSearchTerm)) {
        // Saves the current search string
        outState.putString(SearchManager.QUERY, mSearchTerm);

        // Saves the currently selected contact
        outState.putInt(STATE_PREVIOUSLY_SELECTED_KEY, mListContact.getCheckedItemPosition());
    }//from  www.  j a v  a  2 s . c  o m
}

From source file:gc.david.dfm.ui.activity.MainActivity.java

private void handleSearchIntent(final Intent intent) {
    DFMLogger.logMessage(TAG, "handleSearchIntent");

    // Para controlar instancias nicas, no queremos que cada vez que
    // busquemos nos inicie una nueva instancia de la aplicacin
    final String query = intent.getStringExtra(SearchManager.QUERY);
    if (currentLocation != null) {
        addressPresenter.searchPositionByName(query);
        searchMenuItem.collapseActionView();
    }// w  ww  .j  a v a  2 s  . c  o  m
    if (searchMenuItem != null) {
        searchMenuItem.collapseActionView();
    }
}