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:com.supremainc.biostar2.main.HomeActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);/*from   ww  w . jav a2  s. c o  m*/
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (BuildConfig.DEBUG) {
            Log.e("search", "query:" + query);
        }
        if (query != null && query.length() > 0) {
            if (mSuggestions == null) {
                mSuggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY,
                        SearchSuggestionProvider.MODE);
            }
            mSuggestions.saveRecentQuery(query, null);
        }
        mFragment.onSearch(query);
        return;
    }

    if (BuildConfig.DEBUG) {
        Log.i(TAG, "onNewIntent:");
    }

    if (intent != null) {
        String action = intent.getAction();
        if (action != null && action.startsWith(Setting.ACTION_NOTIFICATION_START)
                && mPermissionDataProvider != null
                && mPermissionDataProvider.getPermission(PERMISSION_MODULE.DOOR, true)) {
            gotoScreen(ScreenType.ALARM_LIST, null, true);
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.main.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    if (intent == null) {
        return;//  w w  w . ja  va 2 s . com
    }
    Log.i(LOG_TAG, "Voice search intent recognized");
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

        String query = intent.getStringExtra(SearchManager.QUERY);
        Log.i(LOG_TAG, "Voice search intent recognized" + query);
        MenuItem searchItem = mMenu.findItem(R.id.action_search);

        MenuItemCompat.expandActionView(searchItem);
        mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView.setQuery(query, true);
        ResultFragmentList fragmentList = (ResultFragmentList) getSupportFragmentManager()
                .findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
        mCurFilter = query;
        fragmentList.search(mCurFilter);

    }

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Log.i(LOG_TAG, "Bundle: " + bundle);
        if (bundle.containsKey("search")) {
            mSearchVisible = bundle.getBoolean("search", false);
            if (!mSearchVisible) {

                ResultFragmentList fragmentList = (ResultFragmentList) getSupportFragmentManager()
                        .findFragmentByTag(getFragmentTag(mPager.getCurrentItem()));
                if (fragmentList != null) {
                    fragmentList.search(null);
                }
            }
        }
    }
    super.onNewIntent(intent);
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

@Override
protected void onNewIntent(@NotNull Intent intent) {
    super.onNewIntent(intent);
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        Intent currentIntent = getIntent();
        currentIntent.putExtra(SearchManager.QUERY, intent.getStringExtra(SearchManager.QUERY));
        setIntent(currentIntent);/*from  w  w  w . jav  a  2  s .  co m*/
        options_menu.findItem(R.id.search).collapseActionView();
    } else if (CalendarContract.ACTION_HANDLE_CUSTOM_EVENT.equals(intent.getAction())) {
        Uri uri = Uri.parse(intent.getStringExtra(CalendarContract.EXTRA_CUSTOM_APP_URI));
        String search = uri.getLastPathSegment();
        // TODO: activate search
    } else if (intent.getExtras() != null) {
        // Only change intent if it actually contains a filter
        setIntent(intent);
    }
    Log.v(TAG, "onNewIntent: " + intent);

}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Initialize the action bar. This is not visible to OnePaneController and
 * TwoPaneController so they cannot override this behavior.
 */// ww  w. ja v  a2  s  .c om
private void initializeActionBar() {
    final ActionBar actionBar = mActivity.getActionBar();
    if (actionBar == null) {
        return;
    }

    // be sure to inherit from the ActionBar theme when inflating
    final LayoutInflater inflater = LayoutInflater.from(actionBar.getThemedContext());
    final boolean isSearch = mActivity.getIntent() != null
            && Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction());
    mActionBarView = (MailActionBarView) inflater
            .inflate(isSearch ? R.layout.search_actionbar_view : R.layout.actionbar_view, null);
    mActionBarView.initialize(mActivity, this, actionBar);

    // init the action bar to allow the 'up' affordance.
    // any configurations that disallow 'up' should do that later.
    mActionBarView.setBackButton();
}

From source file:org.voidsink.anewjkuapp.utils.AppUtils.java

public static void showEventLocation(Context context, String location) {
    Intent intent = new Intent(context, MainActivity.class)
            .putExtra(MainActivity.ARG_SHOW_FRAGMENT_ID, R.id.nav_map)
            .putExtra(MainActivity.ARG_SAVE_LAST_FRAGMENT, false).setAction(Intent.ACTION_SEARCH)
            .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    if (!TextUtils.isEmpty(location)) {
        intent.putExtra(SearchManager.QUERY, location);
        intent.putExtra(MainActivity.ARG_EXACT_LOCATION, true);
    } else {/*from ww  w  .  j ava 2  s.com*/
        intent.putExtra(SearchManager.QUERY, "Uniteich");
    }
    context.startActivity(intent);
}

From source file:aarddict.android.ArticleViewActivity.java

@Override
void onDictionaryServiceReady() {
    if (this.backItems.isEmpty()) {
        final Intent intent = getIntent();
        if (intent != null && intent.getAction() != null) {
            String action = intent.getAction();
            String _word = null;//from w w w  .ja v a2s . c o m
            if (action.equals(Intent.ACTION_SEARCH)) {
                _word = intent.getStringExtra("query");
            } else if (action.equals(Intent.ACTION_SEND)) {
                _word = intent.getStringExtra(Intent.EXTRA_TEXT);
            }

            final String word = _word;

            if (word != null) {

                if (currentTask != null) {
                    currentTask.cancel();
                }

                currentTask = new TimerTask() {
                    @Override
                    public void run() {
                        setProgress(500);
                        String currentWord = word;
                        Log.d(TAG, "intent.getDataString(): " + intent.getDataString());
                        while (currentWord.length() > 0) {
                            Iterator<Entry> results = dictionaryService.lookup(currentWord);
                            Log.d(TAG, "Looked up " + word);
                            if (results.hasNext()) {
                                currentTask = null;
                                Entry entry = results.next();
                                showArticle(entry);
                                break;
                            } else {
                                currentWord = currentWord.substring(0, currentWord.length() - 1);
                            }
                        }
                        if (currentWord.length() == 0) {
                            onSearchRequested();
                        }
                    }
                };

                try {
                    timer.schedule(currentTask, 0);
                } catch (Exception e) {
                    Log.d(TAG, "Failed to schedule task", e);
                    showError(getString(R.string.msgErrorLoadingArticle, word));
                }
            }
        } else {
            String word = intent.getStringExtra("word");
            String section = intent.getStringExtra("section");
            String volumeId = intent.getStringExtra("volumeId");
            long articlePointer = intent.getLongExtra("articlePointer", -1);
            dictionaryService.setPreferred(volumeId);
            showArticle(volumeId, articlePointer, word, section);
        }
    } else {
        showCurrentArticle();
    }
}

From source file:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java

private void searchAuthor() {
    Intent intent;// www .  ja  v  a  2s.co  m
    if (mComic == null)
        return;
    intent = new Intent(this, SearchActivity.class);
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(SearchManager.QUERY, mComic.getAuthor());
    startActivity(intent);
}

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

private boolean processIntent(Intent intent) {
    boolean isDeepLink = false;

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        /* Do a search by name, launched from the quick search */
        String query = intent.getStringExtra(SearchManager.QUERY);
        Bundle args = new Bundle();
        SearchCriteria sc = new SearchCriteria();
        sc.name = query;/*from  w w w. j  a v a  2s.c om*/
        args.putSerializable(SearchViewFragment.CRITERIA, sc);
        selectItem(R.string.main_card_search, args, false,
                true); /* Don't clear backstack, do force the intent */

    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        boolean shouldSelectItem = true;

        Uri data = intent.getData();
        Bundle args = new Bundle();
        assert data != null;

        boolean shouldClearFragmentStack = true; /* Clear backstack for deep links */
        if (data.getAuthority().toLowerCase().contains("gatherer.wizards")) {
            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                String queryParam;
                if ((queryParam = data.getQueryParameter("multiverseid")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByMultiverseId(Long.parseLong(queryParam),
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else if ((queryParam = data.getQueryParameter("name")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByName(queryParam,
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            true, database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else {
                    throw new Exception("Not Found");
                }
            } catch (Exception e) {
                /* empty cursor, just return */
                ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                this.finish();
                shouldSelectItem = false;
            } finally {
                DatabaseManager.getInstance(this, false).closeDatabase(false);
            }
        } else if (data.getAuthority().contains("CardSearchProvider")) {
            /* User clicked a card in the quick search autocomplete, jump right to it */
            args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                    new long[] { Long.parseLong(data.getLastPathSegment()) });
            shouldClearFragmentStack = false; /* Don't clear backstack for search intents */
        } else {
            /* User clicked a deep link, jump to the card(s) */
            isDeepLink = true;

            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                Cursor cursor = null;
                boolean screenLaunched = false;
                if (data.getScheme().toLowerCase().equals("card")
                        && data.getAuthority().toLowerCase().equals("multiverseid")) {
                    if (data.getLastPathSegment() == null) {
                        /* Home screen deep link */
                        launchHomeScreen();
                        screenLaunched = true;
                        shouldSelectItem = false;
                    } else {
                        try {
                            /* Don't clear the fragment stack for internal links (thanks Meld cards) */
                            if (data.getPathSegments().contains("internal")) {
                                shouldClearFragmentStack = false;
                            }
                            cursor = CardDbAdapter.fetchCardByMultiverseId(
                                    Long.parseLong(data.getLastPathSegment()),
                                    new String[] {
                                            CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                                    database);
                        } catch (NumberFormatException e) {
                            cursor = null;
                        }
                    }
                }

                if (cursor != null) {
                    if (cursor.getCount() != 0) {
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    } else {
                        /* empty cursor, just return */
                        ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                        this.finish();
                        shouldSelectItem = false;
                    }
                    cursor.close();
                } else if (!screenLaunched) {
                    /* null cursor, just return */
                    ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                    this.finish();
                    shouldSelectItem = false;
                }
            } catch (FamiliarDbException e) {
                e.printStackTrace();
            }
            DatabaseManager.getInstance(this, false).closeDatabase(false);
        }
        args.putInt(CardViewPagerFragment.STARTING_CARD_POSITION, 0);
        if (shouldSelectItem) {
            selectItem(R.string.main_card_search, args, shouldClearFragmentStack, true);
        }
    } else if (ACTION_ROUND_TIMER.equals(intent.getAction())) {
        selectItem(R.string.main_timer, null, true, false);
    } else if (ACTION_CARD_SEARCH.equals(intent.getAction())) {
        selectItem(R.string.main_card_search, null, true, false);
    } else if (ACTION_LIFE.equals(intent.getAction())) {
        selectItem(R.string.main_life_counter, null, true, false);
    } else if (ACTION_DICE.equals(intent.getAction())) {
        selectItem(R.string.main_dice, null, true, false);
    } else if (ACTION_TRADE.equals(intent.getAction())) {
        selectItem(R.string.main_trade, null, true, false);
    } else if (ACTION_MANA.equals(intent.getAction())) {
        selectItem(R.string.main_mana_pool, null, true, false);
    } else if (ACTION_WISH.equals(intent.getAction())) {
        selectItem(R.string.main_wishlist, null, true, false);
    } else if (ACTION_RULES.equals(intent.getAction())) {
        selectItem(R.string.main_rules, null, true, false);
    } else if (ACTION_JUDGE.equals(intent.getAction())) {
        selectItem(R.string.main_judges_corner, null, true, false);
    } else if (ACTION_MOJHOSTO.equals(intent.getAction())) {
        selectItem(R.string.main_mojhosto, null, true, false);
    } else if (ACTION_PROFILE.equals(intent.getAction())) {
        selectItem(R.string.main_profile, null, true, false);
    } else if (ACTION_DECKLIST.equals(intent.getAction())) {
        selectItem(R.string.main_decklist, null, true, false);
    } else if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        /* App launched as regular, show the default fragment if there isn't one already */
        if (getSupportFragmentManager().getFragments() == null) {
            launchHomeScreen();
        }
    } else {
        /* Some unknown intent, just finish */
        finish();
    }

    mDrawerList.setItemChecked(mCurrentFrag, true);
    return isDeepLink;
}

From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java

private void handleIntent(Intent intent) {

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        // Use the query to search your data somehow
        searchField = intent.getStringExtra(SearchManager.QUERY);

        // Autorefresh
        refreshCurrent();//from www .  j a v a  2s.  c  o  m
    }

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        if (token == null || cookie == null) {
            // Get token and cookie and then
            // get intent from the intent filter and Add URL torrent
            //            Log.d("Debug", "MainActivity - 2");
            new torrentTokenByIntent().execute(getIntent());

        } else {

            // Add torrent (file, url or magnet)
            addTorrentByIntent(intent);
        }
        // // Activity is visble
        activityIsVisible = true;

        // Autorefresh
        refreshCurrent();

    }

    try {
        if (intent.getStringExtra("from").equals("NotifierService")) {

            //                drawerList.setItemChecked(2, true);
            mRecyclerView.findViewHolderForAdapterPosition(3).itemView.performClick();
            setTitle(navigationDrawerItemTitles[2]);
            refresh("completed");

        }

        if (intent.getStringExtra("from").equals("RSSItemActivity")) {

            // Add torrent (file, url or magnet)
            addTorrentByIntent(intent);

            // // Activity is visble
            activityIsVisible = true;

            // Autorefresh
            refreshCurrent();
        }

    } catch (NullPointerException npe) {

    }
}