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:org.mariotaku.twidere.activity.SearchActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(android.R.string.search_go);
    final Intent intent = getIntent();
    mArguments.clear();//from   www . ja va2  s  .com
    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;
    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);
    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.setDisplayHomeAsUpEnabled(true);
    mAdapter = new TabsAdapter(this, getSupportFragmentManager(), null);
    mAdapter.addTab(SearchTweetsFragment.class, mArguments, getString(R.string.tweets),
            R.drawable.ic_tab_twitter, 0);
    mAdapter.addTab(SearchUsersFragment.class, mArguments, getString(R.string.users), R.drawable.ic_tab_person,
            1);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setCurrentItem(is_search_user ? 1 : 0);
    mPagerTab.setTabIndicatorColorResource(R.color.holo_blue_light);
}

From source file:com.keylesspalace.tusky.SearchActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        currentQuery = intent.getStringExtra(SearchManager.QUERY);
        searchFragment.search(currentQuery);
    }//www  . ja v a2 s. c o m
}

From source file:com.fitforbusiness.contact.ContactsListActivity.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/* w w w  .  j a  v  a 2 s .  c  o  m*/
protected void onCreate(Bundle savedInstanceState) {
    /* if (BuildConfig.DEBUG) {
    Utils.enableStrictMode();
     }*/
    super.onCreate(savedInstanceState);
    try {
        if (Utils.hasHoneycomb()) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
            getActionBar().setHomeButtonEnabled(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int screenWidth = (int) (metrics.widthPixels * 0.80);
    int screenHeight = (int) (metrics.heightPixels * 0.80);
    //  getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_background));
    // getWindow().setBackgroundDrawable(null);
    //  getWindow().setLayout(screenWidth, screenHeight);

    setContentView(R.layout.activity_contact_holder);

    // Set main content view. On smaller screen devices this is a single pane view with one
    // fragment. One larger screen devices this is a two pane view with two fragments.

    // Check if two pane bool is set based on resource directories
    isTwoPaneLayout = false;// 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.
    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 = false;
        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:fi.villel.foosquare.SearchActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        mPresenter.startSearch(query, true);
    }/*from  www .j ava  2s .  c o m*/
}

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();/* ww w  .  ja  va2s . 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();
}

From source file:com.tundem.alternativefindr.AlternativefindrActivity.java

public void handleIntent(Intent intent, boolean onCreate) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        mSearchTerm = intent.getStringExtra(SearchManager.QUERY);
        startFragment = 0;/* w ww  .j a va  2s . c  o m*/

        if (!onCreate) {
            //mPager.setCurrentItem(startFragment);
            mIndicator.setCurrentItem(startFragment);
            updateCurrentListView();
        }
    } else if (Intent.ACTION_SEARCH_LONG_PRESS.equals(intent.getAction())) {
        onSearchRequested();
    }
}

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

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

    Intent intent = getIntent();//from  www .  j av  a2s  .co m

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

    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");
                app.setUsername(searchData.getString("username"));
                unread = searchData.getBoolean("unread");
            }

            query = intent.getStringExtra(SearchManager.QUERY);

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

            if (data != null) {
                feed = data.getQueryParameter("feed");

                if (data.getUserInfo() != null) {
                    app.setUsername(data.getUserInfo());
                }
            }
        } else {
            if (data != null) {
                tagname = data.getQueryParameter("tagname");
                feed = data.getQueryParameter("feed");
                unread = data.getQueryParameter("unread") != null;
                path = data.getPath();
            }
        }

        if (feed == null || feed.equals("")) {
            bookmarkFrag = new BrowseBookmarksFragment();
        } else {
            bookmarkFrag = new BrowseBookmarkFeedFragment();
        }

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

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

    if (feed == null || feed.equals("")) {
        if (query != null && !query.equals("")) {
            ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, app.getUsername(), tagname, unread);
        } else {
            ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), tagname, unread ? "unread" : null);
        }

        ((BrowseBookmarksFragment) bookmarkFrag).refresh();
    } else {
        if (query == null || query.equals("")) {
            ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), tagname, feed);
        } else {
            ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), query, feed);
        }
    }

    BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent);

    if (tagFrag != null) {
        tagFrag.setAccount(app.getUsername());
    }

    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();
}

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

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        query = intent.getStringExtra(SearchManager.QUERY).replaceAll("\\s+$", "").toLowerCase();
        queries.clear();// w  w  w.  ja  v  a  2s . c o  m
        titleTermNum = 0;
        titleNum = 0;
        termNum = 0;
        showResults();
    }
}

From source file:org.bwgz.quotation.activity.SubjectsActivity.java

@Override
public void startActivity(Intent intent) {
    Log.d(TAG, String.format("startActivity - intent: %s", intent));

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        intent.putExtra(SearchResultsActivity.EXTRA_SEARCH_TYPE, FreebaseSearch.SEARCH_TYPE_SUBJECT);
    }//from w  ww. ja va  2s.co  m

    super.startActivity(intent);
}