Example usage for android.app SearchManager APP_DATA

List of usage examples for android.app SearchManager APP_DATA

Introduction

In this page you can find the example usage for android.app SearchManager APP_DATA.

Prototype

String APP_DATA

To view the source code for android.app SearchManager APP_DATA.

Click Source Link

Document

Intent extra data key: Use this key with Intent.ACTION_SEARCH and android.content.Intent#getBundleExtra content.Intent.getBundleExtra() to obtain any additional app-specific data that was inserted by the activity that launched the search.

Usage

From source file:com.android.soma.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *//*from w  w  w.  ja v a2s  .c  o  m*/
private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search, if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *///w w w .  j a  va  2  s .co m
private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

From source file:com.android.launcher3.Launcher.java

/**
 * Starts the global search activity. This code is a copied from SearchManager
 *///from   w  ww.j  ava 2s .  c om
public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
        Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // Set source to package name of app that starts global search if not set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}

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

/**
 * Constructs an intent from the given information and the search dialog
 * state./* ww  w .ja  v  a2 s  . c om*/
 * 
 * @param action
 *            Intent action.
 * @param data
 *            Intent data, or <code>null</code>.
 * @param extraData
 *            Data for {@link SearchManager#EXTRA_DATA_KEY} or
 *            <code>null</code>.
 * @param query
 *            Intent query, or <code>null</code>.
 * @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 The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other
    // activities
    // on top of the one we want. We don't want to do this in in-app search
    // though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    intent.setComponent(mSearchable.getSearchActivity());
    return intent;
}

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();/*from  w ww  .  j av a 2  s. c om*/
        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: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 w ww  .  j  a  v  a 2s.  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;
}