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.tct.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 w w  . j a  v  a2  s .  co m
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 = 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;
            //TS: junwei-xu 2014-1-5 EMAIL BUGFIX_879468 ADD_S
        } else if (intent.getData() != null) {
            folderUri = intent.getData();
            //TS: junwei-xu 2014-1-5 EMAIL BUGFIX_879468 ADD_E
        } 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;
            //TS: zheng.zou 2015-03-18 EMAIL BUGFIX_744708 ADD_S
            mToastBar.hide(false, false);
            //TS: zheng.zou 2015-03-18 EMAIL BUGFIX_744708 ADD_E
            // 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();
            }
            /** TCT: init the list context for remote search, except folder. @{ */
            // use a UNINITIALIZED folder temporarily. need update when finish search load.
            Folder folder = Folder.newUnsafeInstance();
            mConvListContext = ConversationListContext.forSearchQuery(mAccount, folder, query);
            mConvListContext
                    .setSearchField(mActivity.getIntent().getStringExtra(SearchParams.BUNDLE_QUERY_FIELD));
            /** @} */
        } else {
            /** TCT: The action is search but no extra account means it's a global search. @{ */
            mGlobalSearch = true;
            LogUtils.logFeature(LogTag.SEARCH_TAG, "Handle ACTION_SEARCH , is mGlobalSearch [%s]",
                    mGlobalSearch);
            // reload conbined inbox folder if needed.
            if (mAccount != null && (mFolder == null || !mFolder.isInitialized())) {
                Bundle args = new Bundle();
                LogUtils.logFeature(LogTag.SEARCH_TAG, " GlobalSearch but without Folder, reload inbox again.");
                args.putParcelable(Utils.EXTRA_FOLDER_URI, mAccount.settings.defaultInbox);
                restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
            }
            /** @} */
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

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

/**
 * Updates controller state based on search results and shows first conversation if required.
 *///from  w  w  w.  j  ava 2 s. co  m
private void perhapsShowFirstSearchResult() {
    if (mCurrentConversation == null) {
        // Shown for search results in two-pane mode only.
        mHaveSearchResults = Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction())
                && mConversationListCursor.getCount() > 0;
        if (!shouldShowFirstConversation()) {
            return;
        }
        mConversationListCursor.moveToPosition(0);
        final Conversation conv = new Conversation(mConversationListCursor);
        conv.position = 0;
        onConversationSelected(conv, true /* checkSafeToModifyFragments */);
    }
}

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

/**
 * Updates controller state based on search results and shows first conversation if required.
 * Be sure to call the super-implementation if overriding.
 *///from  w ww  .  j av a2s.c  om
protected void perhapsShowFirstConversation() {
    mHaveSearchResults = Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction())
            && mConversationListCursor.getCount() > 0;
}