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.dmsl.anyplace.UnifiedNavigationActivity.java

private void handleIntent(Intent intent) {

    String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {

        // check what type of search we need
        SearchTypes searchType = AnyPlaceSeachingHelper.getSearchType(mMap.getCameraPosition().zoom);
        String query = intent.getStringExtra(SearchManager.QUERY);
        GeoPoint gp = userData.getLatestUserPosition();

        // manually launch the real search activity
        Intent searchIntent = new Intent(UnifiedNavigationActivity.this, SearchPOIActivity.class);
        // add query to the Intent Extras
        searchIntent.setAction(action);/*from w w w.  j  av a 2  s  .  c  o  m*/
        searchIntent.putExtra("searchType", searchType);
        searchIntent.putExtra("query", query);
        searchIntent.putExtra("lat", (gp == null) ? csLat : gp.dlat);
        searchIntent.putExtra("lng", (gp == null) ? csLon : gp.dlon);
        startActivityForResult(searchIntent, SEARCH_POI_ACTIVITY_RESULT);

    } else if (Intent.ACTION_VIEW.equals(action)) {
        String data = intent.getDataString();

        if (data != null && data.startsWith("http")) {
            final Uri uri = intent.getData();
            if (uri != null) {
                String path = uri.getPath();

                if (path != null && path.equals("/getnavigation")) {
                    String poid = uri.getQueryParameter("poid");
                    if (poid == null || poid.equals("")) {
                        // Share building
                        // http://anyplace.rayzit.com/getnavigation?buid=username_1373876832005&floor=0
                        String buid = uri.getQueryParameter("buid");
                        if (buid == null || buid.equals("")) {
                            Toast.makeText(getBaseContext(), "Buid parameter expected", Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            mAutomaticGPSBuildingSelection = false;
                            mAnyplaceCache.loadBuilding(buid, new FetchBuildingTaskListener() {

                                @Override
                                public void onSuccess(String result, final BuildingModel b) {

                                    bypassSelectBuildingActivity(b, uri.getQueryParameter("floor"), true);

                                }

                                @Override
                                public void onErrorOrCancel(String result) {
                                    Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();

                                }
                            }, UnifiedNavigationActivity.this);
                        }
                    } else {
                        // Share POI
                        // http://anyplace.rayzit.com/getnavigation?poid=username_username_1373876832005_0_35.14424091022549_33.41139659285545_1382635428093
                        mAutomaticGPSBuildingSelection = false;
                        new FetchPoiByPuidTask(new FetchPoiByPuidTask.FetchPoiListener() {

                            @Override
                            public void onSuccess(String result, final PoisModel poi) {

                                if (userData.getSelectedBuildingId() != null
                                        && userData.getSelectedBuildingId().equals(poi.buid)) {
                                    // Building is Loaded
                                    startNavigationTask(poi.puid);
                                } else {
                                    // Load Building
                                    mAnyplaceCache.loadBuilding(poi.buid, new FetchBuildingTaskListener() {

                                        @Override
                                        public void onSuccess(String result, final BuildingModel b) {

                                            bypassSelectBuildingActivity(b, poi.floor_number, true, poi);

                                        }

                                        @Override
                                        public void onErrorOrCancel(String result) {
                                            Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();

                                        }
                                    }, UnifiedNavigationActivity.this);
                                }
                            }

                            @Override
                            public void onErrorOrCancel(String result) {
                                Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();
                            }
                        }, this, poid).execute();
                    }
                }
            }
        } else {

            // Search TextBox results only

            // PoisModel or Place Class
            IPoisClass place_selected = AnyPlaceSeachingHelper.getClassfromJson(data);

            if (place_selected.id() != null) {
                // hide the search view when a navigation route is drawn
                if (searchView != null) {
                    searchView.setIconified(true);
                    searchView.clearFocus();
                }
                handleSearchPlaceSelection(place_selected);
            }

        }

    }
}

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

@Override
public void executeSearch(String query) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(ConversationListContext.EXTRA_SEARCH_QUERY, query);
    intent.putExtra(Utils.EXTRA_ACCOUNT, mAccount);
    intent.setComponent(mActivity.getComponentName());
    mActionBarView.collapseSearch();/*from   w w  w .j a v a  2  s.  com*/
    mActivity.startActivity(intent);
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

/**
 * Create and return an Intent that can launch the voice search activity,
 * perform a specific voice transcription, and forward the results to the
 * searchable activity.//from   w  w w .ja  v a  2  s  .  co m
 * 
 * @param baseIntent
 *            The voice app search intent to start from
 * @return A completely-configured intent ready to send to the voice search
 *         activity
 */
private Intent createVoiceAppSearchIntent(Intent baseIntent, SearchableInfo searchable) {
    ComponentName searchActivity = searchable.getSearchActivity();

    // create the necessary intent to set up a search-and-forward operation
    // in the voice search system. We have to keep the bundle separate,
    // because it becomes immutable once it enters the PendingIntent
    Intent queryIntent = new Intent(Intent.ACTION_SEARCH);
    queryIntent.setComponent(searchActivity);
    PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent,
            PendingIntent.FLAG_ONE_SHOT);

    // Now set up the bundle that will be inserted into the pending intent
    // when it's time to do the search. We always build it here (even if
    // empty)
    // because the voice search activity will always need to insert "QUERY"
    // into
    // it anyway.
    Bundle queryExtras = new Bundle();

    // Now build the intent to launch the voice search. Add all necessary
    // extras to launch the voice recognizer, and then all the necessary
    // extras
    // to forward the results to the searchable activity
    Intent voiceIntent = new Intent(baseIntent);

    // Add all of the configuration options supplied by the searchable's
    // metadata
    String languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
    String prompt = null;
    String language = null;
    int maxResults = 1;

    Resources resources = getResources();
    if (searchable.getVoiceLanguageModeId() != 0) {
        languageModel = resources.getString(searchable.getVoiceLanguageModeId());
    }
    if (searchable.getVoicePromptTextId() != 0) {
        prompt = resources.getString(searchable.getVoicePromptTextId());
    }
    if (searchable.getVoiceLanguageId() != 0) {
        language = resources.getString(searchable.getVoiceLanguageId());
    }
    if (searchable.getVoiceMaxResults() != 0) {
        maxResults = searchable.getVoiceMaxResults();
    }
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            searchActivity == null ? null : searchActivity.flattenToShortString());

    // Add the values that configure forwarding the results
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras);

    return voiceIntent;
}

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

@Override
public void executeSearch(String query) {
    AnalyticsTimer.getInstance().trackStart(AnalyticsTimer.SEARCH_TO_LIST);
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(ConversationListContext.EXTRA_SEARCH_QUERY, query);
    intent.putExtra(Utils.EXTRA_ACCOUNT, mAccount);
    intent.setComponent(mActivity.getComponentName());
    mSearchViewController.showSearchActionBar(MaterialSearchViewController.SEARCH_VIEW_STATE_GONE);
    // Call startActivityForResult here so we can tell if we have navigated to a different folder
    // or account from search results.
    mActivity.startActivityForResult(intent, CHANGE_NAVIGATION_REQUEST_CODE);
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

private boolean decodeExtras(Intent intent) {
    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null) {
        Uri uri = intent.getData();// w w  w  .  ja v a 2  s  .co  m
        List<String> segmentList = uri.getPathSegments();

        String accountId = segmentList.get(0);
        Collection<Account> accounts = Preferences.getPreferences(this).getAvailableAccounts();
        for (Account account : accounts) {
            if (String.valueOf(account.getAccountNumber()).equals(accountId)) {
                mMessageReference = new MessageReference();
                mMessageReference.accountUuid = account.getUuid();
                mMessageReference.folderName = segmentList.get(1);
                mMessageReference.uid = segmentList.get(2);
                break;
            }
        }
    } else if (ACTION_SHORTCUT.equals(action)) {
        // Handle shortcut intents
        String specialFolder = intent.getStringExtra(EXTRA_SPECIAL_FOLDER);
        if (SearchAccount.UNIFIED_INBOX.equals(specialFolder)) {
            mSearch = SearchAccount.createUnifiedInboxAccount(this).getRelatedSearch();
        } else if (SearchAccount.ALL_MESSAGES.equals(specialFolder)) {
            mSearch = SearchAccount.createAllMessagesAccount(this).getRelatedSearch();
        }
    } else if (intent.getStringExtra(SearchManager.QUERY) != null) {
        // check if this intent comes from the system search ( remote )
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            // Query was received from Search Dialog
            String query = intent.getStringExtra(SearchManager.QUERY);

            mSearch = new LocalSearch(getString(R.string.search_results));
            mSearch.setManualSearch(true);
            mNoThreading = true;

            mSearch.or(new SearchCondition(Searchfield.SENDER, Attribute.CONTAINS, query));
            mSearch.or(new SearchCondition(Searchfield.SUBJECT, Attribute.CONTAINS, query));
            mSearch.or(new SearchCondition(Searchfield.MESSAGE_CONTENTS, Attribute.CONTAINS, query));

            Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
            if (appData != null) {
                mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT));
                // searches started from a folder list activity will provide
                // an account, but no folder
                if (appData.getString(EXTRA_SEARCH_FOLDER) != null) {
                    mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER));
                }
            } else {
                mSearch.addAccountUuid(SearchSpecification.ALL_ACCOUNTS);
            }
        }
    } else {
        // regular LocalSearch object was passed
        mSearch = intent.getParcelableExtra(EXTRA_SEARCH);
        mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false);
    }

    if (mMessageReference == null) {
        mMessageReference = intent.getParcelableExtra(EXTRA_MESSAGE_REFERENCE);
    }

    if (mMessageReference != null) {
        mSearch = new LocalSearch();
        mSearch.addAccountUuid(mMessageReference.accountUuid);
        mSearch.addAllowedFolder(mMessageReference.folderName);
    }

    if (mSearch == null) {
        // We've most likely been started by an old unread widget
        String accountUuid = intent.getStringExtra("account");
        String folderName = intent.getStringExtra("folder");

        mSearch = new LocalSearch(folderName);
        mSearch.addAccountUuid((accountUuid == null) ? "invalid" : accountUuid);
        if (folderName != null) {
            mSearch.addAllowedFolder(folderName);
        }
    }

    Preferences prefs = Preferences.getPreferences(getApplicationContext());

    String[] accountUuids = mSearch.getAccountUuids();
    if (mSearch.searchAllAccounts()) {
        Account[] accounts = prefs.getAccounts();
        mSingleAccountMode = (accounts.length == 1);
        if (mSingleAccountMode) {
            mAccount = accounts[0];
        }
    } else {
        mSingleAccountMode = (accountUuids.length == 1);
        if (mSingleAccountMode) {
            mAccount = prefs.getAccount(accountUuids[0]);
        }
    }
    mSingleFolderMode = mSingleAccountMode && (mSearch.getFolderNames().size() == 1);

    if (mSingleAccountMode && (mAccount == null || !mAccount.isAvailable(this))) {
        Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account");
        onAccountUnavailable();
        return false;
    }

    if (mSingleFolderMode) {
        mFolderName = mSearch.getFolderNames().get(0);
    }

    // now we know if we are in single account mode and need a subtitle
    mActionBarSubTitle.setVisibility((!mSingleFolderMode) ? View.GONE : View.VISIBLE);

    return true;
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

/**
 * When a particular suggestion has been selected, perform the various
 * lookups required to use the suggestion. This includes checking the cursor
 * for suggestion-specific data, and/or falling back to the XML for
 * defaults; It also creates REST style Uri data when the suggestion
 * includes a data id./*from   w w  w.  j  av  a2 s . c om*/
 * 
 * @param c
 *            The suggestions cursor, moved to the row of the user's
 *            selection
 * @param actionKey
 *            The key code of the action key that was pressed, or
 *            {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg
 *            The message for the action key that was pressed, or
 *            <code>null</code> if none.
 * @return An intent for the suggestion at the cursor's position.
 */
private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) {
    try {
        // use specific action if supplied, or default action if supplied,
        // or fixed default
        String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION);

        if (action == null) {
            action = mSearchable.getSuggestIntentAction();
        }
        if (action == null) {
            action = Intent.ACTION_SEARCH;
        }

        // use specific data if supplied, or default data if supplied
        String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (data == null) {
            data = mSearchable.getSuggestIntentData();
        }
        // then, if an ID was provided, append it.
        if (data != null) {
            String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
            if (id != null) {
                data = data + "/" + Uri.encode(id);
            }
        }
        Uri dataUri = (data == null) ? null : Uri.parse(data);

        String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY);
        String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);

        return createIntent(action, dataUri, extraData, query, actionKey, actionMsg);
    } catch (RuntimeException e) {
        int rowNum;
        try { // be really paranoid now
            rowNum = c.getPosition();
        } catch (RuntimeException e2) {
            rowNum = -1;
        }
        Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e);
        return null;
    }
}

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

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 */// w  w  w  . ja  v  a 2s.  c om
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newinstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setCustomDimension(Analytics.CD_INDEX_ACCOUNT_TYPE,
                    AnalyticsUtils.getAccountTypeForAccount(mAccount.getEmailAddress()));
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = (Uri) intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            // Save this search query for future suggestions.
            final String query = intent.getStringExtra(SearchManager.QUERY);
            final String authority = mContext.getString(R.string.suggestions_authority);
            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mContext, authority,
                    SuggestionsProvider.MODE);
            suggestions.saveRecentQuery(query, null);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
        } else {
            LogUtils.e(LOG_TAG, "Missing account extra from search intent.  Finishing");
            mActivity.finish();
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //Logger.LogVerbose("OpenExplorer.onPrepareOptionsMenu");

    if (getClipboard() != null) {
        MenuUtils.setMenuChecked(menu, getClipboard().isMultiselect(), R.id.menu_multi);
        MenuUtils.setMenuVisible(menu, getClipboard().size() > 0, R.id.content_paste);
    } else//from  ww  w  .ja va 2  s . c  o  m
        MenuUtils.setMenuVisible(menu, false, R.id.content_paste);

    MenuUtils.setMenuVisible(menu, IS_DEBUG_BUILD && !isBlackBerry(), R.id.menu_debug);

    if (!BEFORE_HONEYCOMB && USE_ACTION_BAR) {
        //MenuUtils.setMenuVisible(menu, false, R.id.title_menu);
        if (menu.findItem(R.id.menu_search) != null) {
            if (mSearchView == null)
                mSearchView = SearchViewCompat.newSearchView(this);
            MenuItem item = menu.findItem(R.id.menu_search);
            MenuItemCompat.setShowAsAction(item,
                    MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            MenuItemCompat.setActionView(item, mSearchView);
            if (mSearchView != null)
                SearchViewCompat.setOnQueryTextListener(mSearchView,
                        new SearchViewCompat.OnQueryTextListenerCompat() {
                            public boolean onQueryTextSubmit(String query) {
                                mSearchView.clearFocus();
                                Intent intent = new Intent();
                                intent.setAction(Intent.ACTION_SEARCH);
                                Bundle appData = new Bundle();
                                appData.putString("path", getDirContentFragment(false).getPath().getPath());
                                intent.putExtra(SearchManager.APP_DATA, appData);
                                intent.putExtra(SearchManager.QUERY, query);
                                handleIntent(intent);
                                return true;
                            }

                            public boolean onQueryTextChange(String newText) {
                                return false;
                            }
                        });
        }
    }

    MenuUtils.setMenuChecked(menu, USE_SPLIT_ACTION_BAR, R.id.menu_view_split);
    //MenuUtils.setMenuChecked(menu, mLogFragment != null && mLogFragment.isVisible(), R.id.menu_view_logview);
    MenuUtils.setMenuChecked(menu, getPreferences().getBoolean("global", "pref_fullscreen", false),
            R.id.menu_view_fullscreen);
    if (!getResources().getBoolean(R.bool.allow_fullscreen))
        MenuUtils.setMenuVisible(menu, false, R.id.menu_view_fullscreen);
    else
        MenuUtils.setMenuChecked(menu, IS_FULL_SCREEN, R.id.menu_view_fullscreen);
    if (getWindowWidth() < 500 && Build.VERSION.SDK_INT < 14) // ICS can split the actionbar
    {
        MenuUtils.setMenuShowAsAction(menu, 0 // Never
                , R.id.menu_sort, R.id.menu_view, R.id.menu_new_folder);
        MenuUtils.setMenuVisible(menu, true, R.id.menu_more);
    }

    //if(BEFORE_HONEYCOMB)
    {
        OpenFragment f = getSelectedFragment();
        if (f != null && f.hasOptionsMenu() && !f.isDetached() && f.isVisible())
            f.onPrepareOptionsMenu(menu);
    }

    if (menu != null && menu.findItem(R.id.content_paste) != null && getClipboard() != null
            && getClipboard().size() > 0) {
        SubMenu sub = menu.findItem(R.id.content_paste).getSubMenu();
        if (sub != null) {
            int i = 0;
            for (final OpenPath item : getClipboard().getAll()) {
                sub.add(Menu.CATEGORY_CONTAINER, i++, i, item.getName()).setCheckable(true).setChecked(true)
                        .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                            @Override
                            public boolean onMenuItemClick(MenuItem menuitem) {
                                getClipboard().remove(item);
                                return true;
                            }
                        }).setIcon(ThumbnailCreator.getDefaultResourceId(item, 32, 32));
            }
        }
    }

    if (!CAN_DO_CAROUSEL)
        MenuUtils.setMenuVisible(menu, false, R.id.menu_view_carousel);

    //if(BEFORE_HONEYCOMB)
    //   setupBaseBarButtons(menu, false);

    return true;
}

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

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 *///from  w ww.  j a v a 2s  .  c  om
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newInstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setEmail(mAccount.getEmailAddress(), mAccount.getType());
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        // Check if we should load all conversations instead of using
        // the default behavior which loads an initial subset.
        mIgnoreInitialConversationLimit = intent.getBooleanExtra(Utils.EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT,
                false);

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            // Save this search query for future suggestions
            final String query = intent.getStringExtra(SearchManager.QUERY);
            mSearchViewController.saveRecentQuery(query);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
        } else {
            LogUtils.e(LOG_TAG, "Missing account extra from search intent.  Finishing");
            mActivity.finish();
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

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

/**
 * TCT: This will launch a new activity with a new controller to do remote search.
 *//*  w  w w. j a  v  a 2  s . c o m*/
@Override
public void executeSearch(String query) {
    AnalyticsTimer.getInstance().trackStart(AnalyticsTimer.SEARCH_TO_LIST);
    /// TCT: add search field for remote search. @{
    String searchFiled = null;
    if (mConvListContext != null) {
        searchFiled = mConvListContext.getSearchField();
    }
    if (TextUtils.isEmpty(searchFiled)) {
        LogUtils.d(LOG_TAG, "set search field as ALL, if user not set search field");
        searchFiled = SearchParams.SEARCH_FIELD_ALL;
    }
    /// @}
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(ConversationListContext.EXTRA_SEARCH_QUERY, query);
    /// TCT: add search field for remote search. @{
    intent.putExtra(SearchParams.BUNDLE_QUERY_FIELD, searchFiled);
    /// @}
    intent.putExtra(Utils.EXTRA_ACCOUNT, mAccount);
    intent.setComponent(mActivity.getComponentName());
    /// TCT: It's better to stay at local search UI when back from remote search.
    //        mActionBarController.collapseSearch();
    // Call startActivityForResult here so we can tell if we have navigated to a different folder
    // or account from search results.
    mActivity.startActivityForResult(intent, CHANGE_NAVIGATION_REQUEST_CODE);
}