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:pwr.itapps.meetme.activity.WallActivity.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.
    Intent intent;/*from  ww  w  .  j a v  a 2  s .  c o  m*/

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_websearch:
        // create intent to perform web search for this planet
        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();
        }
        return true;
    case R.id.services_download:
        Fragment f = getActiveFragment();
        if (f instanceof FriendsFragment) {
            ((FriendsFragment) f).downloadContacs();
        } else if (f instanceof EventListFragment) {
            ((EventListFragment) f).runRefresh();
        }
        return true;
    case R.id.action_createEvent:
        // create intent to perform web search for this planet
        intent = new Intent(getApplicationContext(), CreateEventActivity.class);

        // 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.github.blalasaadri.sprinttopics.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  ww  w  .ja v  a  2  s  .  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 {
            makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:info.guardianproject.gpg.KeyListFragment.java

public void handleIntent(String action, Bundle extras) {
    // Why doesn't java have default parameters :(
    if (extras == null)
        extras = new Bundle();

    mCurrentAction = action;/*  w  w w .  j  a va 2s  .  co m*/
    mCurrentExtras = extras;

    String searchString = null;
    if (Intent.ACTION_SEARCH.equals(action)) {
        searchString = extras.getString(SearchManager.QUERY);
        if (searchString != null && searchString.trim().length() == 0) {
            searchString = null;
        }
    }

    long selectedKeyIds[] = null;
    selectedKeyIds = extras.getLongArray(Apg.EXTRA_SELECTION);

    if (selectedKeyIds == null) {
        Vector<Long> vector = new Vector<Long>();
        for (int i = 0; i < mListView.getCount(); ++i) {
            if (mListView.isItemChecked(i)) {
                vector.add(mListView.getItemIdAtPosition(i));
            }
        }
        selectedKeyIds = new long[vector.size()];
        for (int i = 0; i < vector.size(); ++i) {
            selectedKeyIds[i] = vector.get(i);
        }
    }

    if (action.equals(Action.FIND_KEYS)) {
        if (mKeyserverAdapter == null)
            mKeyserverAdapter = new KeyListKeyserverAdapter(mListView, searchString);
        setListAdapter(mKeyserverAdapter);
    } else {
        mShowKeysAdapter = new KeyListContactsAdapter(mListView, action, searchString, selectedKeyIds);
        setListAdapter(mShowKeysAdapter);
        if (selectedKeyIds != null) {
            for (int i = 0; i < mShowKeysAdapter.getCount(); ++i) {
                long keyId = mShowKeysAdapter.getItemId(i);
                for (int j = 0; j < selectedKeyIds.length; ++j) {
                    if (keyId == selectedKeyIds[j]) {
                        mListView.setItemChecked(i, true);
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.dwdesign.tweetings.activity.SearchActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Intent intent = getIntent();
    mArguments.clear();/*ww  w  . j a va2 s  .c o m*/
    mData = intent.getData();
    final boolean is_search_user = mData != null
            ? QUERY_PARAM_VALUE_USERS.equals(mData.getQueryParameter(QUERY_PARAM_TYPE))
            : false;
    final String query = Intent.ACTION_SEARCH.equals(intent.getAction())
            ? intent.getStringExtra(SearchManager.QUERY)
            : mData != null ? mData.getQueryParameter(QUERY_PARAM_QUERY) : null;
    int search_id = -1;
    if (mData != null && mData.getQueryParameter(QUERY_PARAM_ID) != null) {
        search_id = Integer.parseInt(mData.getQueryParameter(QUERY_PARAM_ID));
    }
    if (query == null) {
        finish();
        return;
    }
    if (savedInstanceState == null) {
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE);
        suggestions.saveRecentQuery(query, null);
    }
    mArguments.putString(INTENT_KEY_QUERY, query);
    mArguments.putInt(INTENT_KEY_ID, search_id);
    final String param_account_id = mData != null ? mData.getQueryParameter(QUERY_PARAM_ACCOUNT_ID) : null;
    if (param_account_id != null) {
        mArguments.putLong(INTENT_KEY_ACCOUNT_ID, parseLong(param_account_id));
    } else {
        final String param_account_name = mData != null ? mData.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME)
                : null;
        if (param_account_name != null) {
            mArguments.putLong(INTENT_KEY_ACCOUNT_ID, getAccountId(this, param_account_name));
        } else {
            final long account_id = getDefaultAccountId(this);
            if (isMyAccount(this, account_id)) {
                mArguments.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
            } else {
                finish();
                return;
            }
        }
    }
    mActionBar = getSupportActionBar();
    mActionBar.setCustomView(R.layout.base_tabs);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mActionBar.setDisplayShowCustomEnabled(true);
    final View view = mActionBar.getCustomView();
    mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
    mIndicator = (TabPageIndicator) view.findViewById(android.R.id.tabs);
    mAdapter = new TabsAdapter(this, getSupportFragmentManager(), mIndicator);
    mAdapter.setDisplayLabel(true);
    mAdapter.addTab(SearchTweetsFragment.class, mArguments, getString(R.string.search_tweets),
            R.drawable.ic_tab_twitter, 0);
    mAdapter.addTab(SearchUsersFragment.class, mArguments, getString(R.string.search_users),
            R.drawable.ic_tab_person, 1);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOffscreenPageLimit(1);
    mIndicator.setViewPager(mViewPager);
    mViewPager.setCurrentItem(is_search_user ? 1 : 0);
}

From source file:ca.rmen.android.palidamuerte.app.poem.list.PoemListActivity.java

/**
 * Callback method from {@link PoemListFragment.Callbacks} indicating that the item with the given ID was selected.
 *//*from   ww  w .ja  v  a2 s. c o m*/
@Override
public void onItemSelected(long id) {
    Log.v(TAG, "onItemSelected: id = " + id);
    if (mTwoPane) {
        // In two-pane mode, show the detail view in this activity by
        // adding or replacing the detail fragment using a
        // fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putLong(PoemDetailFragment.ARG_ITEM_ID, id);
        PoemDetailFragment fragment = new PoemDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().replace(R.id.poem_detail_container, fragment).commit();
        boolean refreshMenu = mPoemId < 0;
        mPoemId = id;
        if (mShareActionProvider != null)
            Poems.updateShareIntent(mShareActionProvider, this, mPoemId);
        if (refreshMenu)
            invalidateOptionsMenu();

    } else {
        // In single-pane mode, simply start the detail activity
        // for the selected item ID.
        Intent detailIntent = new Intent(this, PoemDetailActivity.class);
        detailIntent.setAction(getIntent().getAction());
        detailIntent.putExtra(SearchManager.QUERY, getIntent().getStringExtra(SearchManager.QUERY));
        detailIntent.putExtra(PoemDetailFragment.ARG_ITEM_ID, id);
        detailIntent.putExtra(EXTRA_CATEGORY_ID, getIntent().getLongExtra(EXTRA_CATEGORY_ID, -1));
        startActivity(detailIntent);
    }
}

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.//  ww  w .  j av a2s.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);
    }
}

From source file:com.battlelancer.seriesguide.ui.SearchActivity.java

private void handleIntent(Intent intent) {
    if (intent == null) {
        return;/*from w  ww.  j  av  a 2 s  .  c om*/
    }
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        Bundle extras = getIntent().getExtras();

        // searching episodes within a show?
        Bundle appData = extras.getBundle(SearchManager.APP_DATA);
        if (appData != null) {
            String showTitle = appData.getString(EpisodeSearchFragment.InitBundle.SHOW_TITLE);
            if (!TextUtils.isEmpty(showTitle)) {
                // change title + switch to episodes tab if show restriction was submitted
                viewPager.setCurrentItem(EPISODES_TAB_INDEX);
            }
        }

        // setting the query automatically triggers a search
        String query = extras.getString(SearchManager.QUERY);
        searchBar.setText(query);
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri data = intent.getData();
        String id = data.getLastPathSegment();
        displayEpisode(id);
        Utils.trackCustomEvent(this, TAG, "Search action", "View");
        finish();
    }
}

From source file:com.example.android.AudioArchive.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;//ww w. ja  va 2 s .c o  m
    // check if we were started from a "Play XYZ" voice search. If so, we save the extras
    // (which contain the query details) in a parameter, so we can reuse it later, when the
    // MediaSession is connected.
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query=",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else {
        if (savedInstanceState != null) {
            // If there is a saved media ID, use it
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
    }
    navigateToBrowser(mediaId);
}

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();/*  w ww  . ja va 2 s  . com*/

        // 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:com.example.android.navigationdrawerexample.ContentDrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // 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);/*from  w ww  .j a v a2 s.  c om*/
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}