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:com.rowland.movies.ui.fragments.SearchFragment.java

@Override
public Loader<List<Movie>> onCreateLoader(int id, Bundle args) {
    // Acquire the search string
    String queryString = args.getString(SearchManager.QUERY);
    // Create new loader
    ModelLoader movieLoader = new ModelLoader<>(getActivity(), Movie.class,
            new Select().from(Movie.class).where("originalTitle = ?", queryString), true);
    // Return new loader
    return movieLoader;
}

From source file:com.cerema.cloud2.ui.activity.ShareActivity.java

@Override
protected void onNewIntent(Intent intent) {
    // Verify the action and get the query
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        Log_OC.w(TAG, "Ignored Intent requesting to query for " + query);

    } else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
        Uri data = intent.getData();//from  ww  w  . ja  va  2s  . c o m
        String dataString = intent.getDataString();
        String shareWith = dataString.substring(dataString.lastIndexOf('/') + 1);
        doShareWith(shareWith, data.getAuthority());

    } else {
        Log_OC.wtf(TAG, "Unexpected intent " + intent.toString());
    }
}

From source file:com.bar.foldinglayout.sample.FoldingPaneLayoutActivity.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);/* w  ww . j  a  v a  2  s . c o m*/
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.google.samples.apps.iosched.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    mSearchView = (SearchView) findViewById(R.id.search_view);
    setupSearchView();//  ww  w  . jav a 2s.  c o  m
    mSearchResults = (ListView) findViewById(R.id.search_results);
    mResultsAdapter = new SimpleCursorAdapter(this, R.layout.list_item_search_result, null,
            new String[] { ScheduleContract.SearchTopicSessionsColumns.SEARCH_SNIPPET },
            new int[] { R.id.search_result }, 0);
    mSearchResults.setAdapter(mResultsAdapter);
    mSearchResults.setOnItemClickListener(this);
    Toolbar toolbar = getActionBarToolbar();

    Drawable up = DrawableCompat.wrap(ContextCompat.getDrawable(this, R.drawable.ic_up));
    DrawableCompat.setTint(up, getResources().getColor(R.color.app_body_text_2));
    toolbar.setNavigationIcon(up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            navigateUpOrBack(SearchActivity.this, null);
        }
    });

    String query = getIntent().getStringExtra(SearchManager.QUERY);
    query = query == null ? "" : query;
    mQuery = query;

    if (mSearchView != null) {
        mSearchView.setQuery(query, false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        doEnterAnim();
    }

    overridePendingTransition(0, 0);
}

From source file:koma.movieapp.ui.SearchActivity.java

@Override
protected void onNewIntent(Intent intent) {
    LOGD(TAG, "SearchActivity.onNewIntent: " + intent);
    setIntent(intent);/*from   w  w w  .ja  v a2 s.c o m*/
    String query = intent.getStringExtra(SearchManager.QUERY);
    Bundle args = new Bundle();
    args.putString("title", "Search");
    args.putInt("queryType", Config.SEARCH_TOKEN);
    args.putString("searchString", query);
    LOGD(TAG, "onNewIntent() now reloading sessions fragment with args: " + args);
    mMoviesFragment.reloadFromArguments(args);
}

From source file:com.rowland.movies.ui.activities.SearchActivity.java

private String getSearchQuery() {
    // The search query
    String searchQuery = "";
    // Filter the relevant Intent
    if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
        // Acquire the search query
        searchQuery = getIntent().getStringExtra(SearchManager.QUERY);
    }/*w w w. j  a  va 2 s. co m*/
    // Return the search string
    return searchQuery;
}

From source file:com.android.stockbrowser.search.OpenSearchSearchEngine.java

public void startSearch(Context context, String query, Bundle appData, String extraData) {
    String uri = mSearchEngineInfo.getSearchUriForQuery(query);
    if (uri == null) {
        Log.e(TAG, "Unable to get search URI for " + mSearchEngineInfo);
    } else {/*from w  w  w .java  2 s .co  m*/
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        // Make sure the intent goes to the StockBrowser itself
        intent.setPackage(context.getPackageName());
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.putExtra(SearchManager.QUERY, query);
        if (appData != null) {
            intent.putExtra(SearchManager.APP_DATA, appData);
        }
        if (extraData != null) {
            intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(intent);
    }
}

From source file:com.radar.niyo.contacts.ContactsListActivity.java

private void showContacts() {
    Log.d(LOG_TAG, "showContacts started");
    // Check if two pane bool is set based on resource directories
    isTwoPaneLayout = getResources().getBoolean(R.bool.has_two_panes);

    // Check if this activity instance has been triggered as a result of a search query. This
    // will only happen on pre-HC OS versions as from HC onward search is carried out using
    // an ActionBar SearchView which carries out the search in-line without loading a new
    // Activity./*  w w  w  .j av a 2s. c  o m*/
    if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {

        // Fetch query from intent and notify the fragment that it should display search
        // results instead of all contacts.
        String searchQuery = getIntent().getStringExtra(SearchManager.QUERY);
        ContactsListFragment mContactsListFragment = (ContactsListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.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);
    }

    if (isTwoPaneLayout) {
        // If two pane layout, locate the contact detail fragment
        mContactDetailFragment = (ContactDetailFragment) getSupportFragmentManager()
                .findFragmentById(R.id.contact_detail);
    }
}

From source file:com.android.browser.search.OpenSearchSearchEngine.java

public void startSearch(Context context, String query, Bundle appData, String extraData) {
    String uri = mSearchEngineInfo.getSearchUriForQuery(query);
    if (uri == null) {
        Log.e(TAG, "Unable to get search URI for " + mSearchEngineInfo);
    } else {//from  w  w  w  .j  a v  a 2  s  .  co  m
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        // Make sure the intent goes to the Browser itself
        intent.setPackage(context.getPackageName());
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.putExtra(SearchManager.QUERY, query);
        if (appData != null) {
            intent.putExtra(SearchManager.APP_DATA, appData);
        }
        if (extraData != null) {
            intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(intent);
    }
}

From source file:com.deliciousdroid.activity.BrowseBookmarks.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_bookmarks);

    Intent intent = getIntent();//w w w  . jav  a  2 s.c  o m

    Uri data = intent.getData();
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction t = fm.beginTransaction();

    Fragment bookmarkFrag;

    if (fm.findFragmentById(R.id.listcontent) == null) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA);

            if (searchData != null) {
                tagname = searchData.getString("tagname");
                username = searchData.getString("username");
                unread = searchData.getBoolean("unread");
            }

            query = intent.getStringExtra(SearchManager.QUERY);

            if (intent.hasExtra("username")) {
                username = intent.getStringExtra("username");
            }

            if (data != null && data.getUserInfo() != null) {
                username = data.getUserInfo();
            }
        } else {
            if (data != null) {
                if (data.getUserInfo() != "") {
                    username = data.getUserInfo();
                } else
                    username = mAccount.name;
                tagname = data.getQueryParameter("tagname");
                unread = data.getQueryParameter("unread") != null;
                path = data.getPath();
            }
        }

        if (isMyself()) {
            bookmarkFrag = new BrowseBookmarksFragment();
        } else {
            bookmarkFrag = new BrowseBookmarkFeedFragment();
        }

        t.add(R.id.listcontent, bookmarkFrag);
    } else {
        if (savedInstanceState != null) {
            username = savedInstanceState.getString(STATE_USERNAME);
            tagname = savedInstanceState.getString(STATE_TAGNAME);
            unread = savedInstanceState.getBoolean(STATE_UNREAD);
            query = savedInstanceState.getString(STATE_QUERY);
            path = savedInstanceState.getString(STATE_PATH);
        }

        bookmarkFrag = fm.findFragmentById(R.id.listcontent);
    }

    if (isMyself()) {
        if (query != null && !query.equals("")) {
            ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, username, tagname, unread);
        } else {
            ((BrowseBookmarksFragment) bookmarkFrag).setQuery(username, tagname, unread);
        }
    } else {
        if (query != null && !query.equals("")) {
            ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, tagname);
        } else {
            ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, query);
        }
    }

    BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent);
    if (tagFrag != null) {
        tagFrag.setAccount(username);
    }

    if (path != null && path.contains("tags")) {
        t.hide(fm.findFragmentById(R.id.maincontent));
        findViewById(R.id.panel_collapse_button).setVisibility(View.GONE);
    } else {
        if (tagFrag != null) {
            t.hide(tagFrag);
        }
    }

    Fragment addFrag = fm.findFragmentById(R.id.addcontent);
    if (addFrag != null) {
        t.hide(addFrag);
    }

    t.commit();
}