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:org.tvheadend.tvhclient.SearchResultActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Quit if the search mode is not active
    if (!Intent.ACTION_SEARCH.equals(intent.getAction()) || !intent.hasExtra(SearchManager.QUERY)) {
        return;//from   w w  w  . ja  v  a 2  s . c o m
    }

    // Get the possible channel
    TVHClientApplication app = (TVHClientApplication) getApplication();
    Bundle bundle = intent.getBundleExtra(SearchManager.APP_DATA);
    if (bundle != null) {
        channel = app.getChannel(bundle.getLong(Constants.BUNDLE_CHANNEL_ID));
    } else {
        channel = null;
    }

    // Create the intent with the search options 
    String query = intent.getStringExtra(SearchManager.QUERY);
    pattern = Pattern.compile(query, Pattern.CASE_INSENSITIVE);
    intent = new Intent(SearchResultActivity.this, HTSService.class);
    intent.setAction(Constants.ACTION_EPG_QUERY);
    intent.putExtra("query", query);
    if (channel != null) {
        intent.putExtra(Constants.BUNDLE_CHANNEL_ID, channel.id);
    }

    // Save the query so it can be shown again
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SuggestionProvider.AUTHORITY,
            SuggestionProvider.MODE);
    suggestions.saveRecentQuery(query, null);

    // Now call the service with the query to get results
    startService(intent);

    // Clear the previous results before adding new ones
    adapter.clear();

    // If no channel is given go through the list of programs in all
    // channels and search if the desired program exists. If a channel was
    // given search through the list of programs in the given channel. 
    if (channel == null) {
        for (Channel ch : app.getChannels()) {
            if (ch != null) {
                synchronized (ch.epg) {
                    for (Program p : ch.epg) {
                        if (p != null && p.title != null && p.title.length() > 0) {
                            // Check if the program name matches the search pattern
                            if (pattern.matcher(p.title).find()) {
                                adapter.add(p);
                                adapter.sort();
                                adapter.notifyDataSetChanged();
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (channel.epg != null) {
            synchronized (channel.epg) {
                for (Program p : channel.epg) {
                    if (p != null && p.title != null && p.title.length() > 0) {
                        // Check if the program name matches the search pattern
                        if (pattern.matcher(p.title).find()) {
                            adapter.add(p);
                            adapter.sort();
                            adapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        }
    }

    actionBar.setTitle(android.R.string.search_go);
    actionBar.setSubtitle(getString(R.string.loading));

    // Create the runnable that will initiate the update of the adapter and
    // indicates that we are done when nothing has happened after 2s. 
    updateTask = new Runnable() {
        public void run() {
            adapter.notifyDataSetChanged();
            actionBar.setSubtitle(adapter.getCount() + " " + getString(R.string.results));
        }
    };
}

From source file:com.battlelancer.seriesguide.ui.SearchActivity.java

private void submitSearchQuery(String query) {
    Bundle args = new Bundle();
    args.putString(SearchManager.QUERY, query);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        Bundle appData = extras.getBundle(SearchManager.APP_DATA);
        if (appData != null) {
            args.putBundle(SearchManager.APP_DATA, appData);
        }/*from   w ww .java  2s .  com*/
    }

    submitSearchQuery(args);
}

From source file:ca.spencerelliott.mercury.Changesets.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    this.requestWindowFeature(Window.FEATURE_PROGRESS);
    this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.changesets);

    //Cancel any notifications previously setup
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(1);/*  ww w . java 2s  .  c o  m*/

    //Create a new array list for the changesets
    changesets_list = new ArrayList<Map<String, ?>>();
    changesets_data = new ArrayList<Beans.ChangesetBean>();

    //Get the list view to store the changesets
    changesets_listview = (ListView) findViewById(R.id.changesets_list);

    TextView empty_text = (TextView) findViewById(R.id.changesets_empty_text);

    //Set the empty view
    changesets_listview.setEmptyView(empty_text);

    //Use a simple adapter to display the changesets based on the array list made earlier
    changesets_listview.setAdapter(new SimpleAdapter(this, changesets_list, R.layout.changeset_item,
            new String[] { COMMIT, FORMATTED_INFO },
            new int[] { R.id.changesets_commit, R.id.changesets_info }));

    //Set the on click listener
    changesets_listview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {
            Intent intent = new Intent(Changesets.this, ChangesetViewer.class);

            //Pass the changeset information to the changeset viewer
            Bundle params = new Bundle();
            params.putString("changeset_commit_text", changesets_data.get(position).getTitle());
            params.putString("changeset_changes", changesets_data.get(position).getContent());
            params.putLong("changeset_updated", changesets_data.get(position).getUpdated());
            params.putString("changeset_authors", changesets_data.get(position).getAuthor());
            params.putString("changeset_link", changesets_data.get(position).getLink());
            //params.putBoolean("is_https", is_https);

            intent.putExtras(params);

            startActivity(intent);
        }

    });

    //Register the list view for opening the context menu
    registerForContextMenu(changesets_listview);

    //Get the intent passed by the program
    if (getIntent() != null) {
        //Check to see if this is a search window
        if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
            //Change the title of the activity and the empty text of the list so it looks like a search window
            this.setTitle(R.string.search_results_label);
            empty_text.setText(R.string.search_results_empty);

            //Retrieve the query the user entered
            String query = getIntent().getStringExtra(SearchManager.QUERY);

            //Convert the query to lower case
            query = query.toLowerCase();

            //Retrieve the bundle data
            Bundle retrieved_data = getIntent().getBundleExtra(SearchManager.APP_DATA);

            //If the bundle was passed, grab the changeset data
            if (retrieved_data != null) {
                changesets_data = retrieved_data
                        .getParcelableArrayList("ca.spencerelliott.mercury.SEARCH_DATA");
            }

            //If we're missing changeset data, stop here
            if (changesets_data == null)
                return;

            //Create a new array list to store the changesets that were a match
            ArrayList<Beans.ChangesetBean> search_beans = new ArrayList<Beans.ChangesetBean>();

            //Loop through each changeset
            for (Beans.ChangesetBean b : changesets_data) {
                //Check to see if any changesets match
                if (b.getTitle().toLowerCase().contains(query)) {
                    //Get the title and date of the commit
                    String commit_text = b.getTitle();
                    Date commit_date = new Date(b.getUpdated());

                    //Add a new changeset to display in the list view
                    changesets_list.add(createChangeset(
                            (commit_text.length() > 30 ? commit_text.substring(0, 30) + "..." : commit_text),
                            b.getRevisionID() + " - " + commit_date.toLocaleString()));

                    //Add this bean to the list of found search beans
                    search_beans.add(b);
                }
            }

            //Switch the changeset data over to the changeset data that was a match
            changesets_data = search_beans;

            //Update the list in the activity
            list_handler.sendEmptyMessage(SUCCESSFUL);

            //Notify the activity that it is a search window
            is_search_window = true;

            //Stop loading here
            return;
        }

        //Get the data from the intent
        Uri data = getIntent().getData();

        if (data != null) {
            //Extract the path in the intent
            String path_string = data.getEncodedPath();

            //Split it by the forward slashes
            String[] split_path = path_string.split("/");

            //Make sure a valid path was passed
            if (split_path.length == 3) {
                //Get the repository id from the intent
                repo_id = Long.parseLong(split_path[2].toString());
            } else {
                //Notify the user if there was a problem
                Toast.makeText(this, R.string.invalid_intent, 1000).show();
            }
        }
    }

    //Retrieve the changesets
    refreshChangesets();
}

From source file:com.battlelancer.seriesguide.ui.OverviewActivity.java

private void launchSearch() {
    // refine search with the show's title
    final Series show = DBUtils.getShow(this, mShowId);
    final String showTitle = show.getTitle();

    Bundle appSearchData = new Bundle();
    appSearchData.putString(EpisodeSearchFragment.InitBundle.SHOW_TITLE, showTitle);

    Intent intent = new Intent(this, SearchActivity.class);
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    intent.setAction(Intent.ACTION_SEARCH);
    startActivity(intent);/*from w  w w  .jav  a 2 s. c  om*/
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static boolean executeSearch(String search, Context context, SessionInfo sessionInfo) {
    Intent myIntent = new Intent(Intent.ACTION_SEARCH);
    myIntent.setClass(context, MetaSearch.class);
    RemoteProfile remoteProfile = sessionInfo.getRemoteProfile();
    if (remoteProfile != null && remoteProfile.getRemoteType() == RemoteProfile.TYPE_LOOKUP) {
        Bundle bundle = new Bundle();
        bundle.putString("com.vuze.android.remote.searchsource", sessionInfo.getRpcRoot());
        if (remoteProfile.getRemoteType() == RemoteProfile.TYPE_LOOKUP) {
            bundle.putString("com.vuze.android.remote.ac", remoteProfile.getAC());
        }//from   w  w  w . j  a v a2s .c o  m
        bundle.putString(SessionInfoManager.BUNDLE_KEY, remoteProfile.getID());

        myIntent.putExtra(SearchManager.APP_DATA, bundle);
    }

    myIntent.putExtra(SearchManager.QUERY, search);

    context.startActivity(myIntent);
    return true;
}

From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java

/**
 * Method that verifies the intent passed to the activity, and checks
 * if a request is made like Search.//from  w  w w .  j  a  v  a  2  s .co m
 *
 * @param intent The intent to check
 * @hide
 */
void checkIntent(Intent intent) {
    //Search action
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        Intent searchIntent = new Intent(this, SearchActivity.class);
        searchIntent.setAction(Intent.ACTION_SEARCH);
        //- SearchActivity.EXTRA_SEARCH_DIRECTORY
        searchIntent.putExtra(SearchActivity.EXTRA_SEARCH_DIRECTORY,
                getCurrentNavigationFragment().getCurrentDir());
        //- SearchManager.APP_DATA
        if (intent.getBundleExtra(SearchManager.APP_DATA) != null) {
            Bundle bundle = new Bundle();
            bundle.putAll(intent.getBundleExtra(SearchManager.APP_DATA));
            searchIntent.putExtra(SearchManager.APP_DATA, bundle);
        }
        //-- SearchManager.QUERY
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (query != null) {
            searchIntent.putExtra(SearchManager.QUERY, query);
        }
        //- android.speech.RecognizerIntent.EXTRA_RESULTS
        ArrayList<String> extraResults = intent
                .getStringArrayListExtra(android.speech.RecognizerIntent.EXTRA_RESULTS);
        if (extraResults != null) {
            searchIntent.putStringArrayListExtra(android.speech.RecognizerIntent.EXTRA_RESULTS, extraResults);
        }
        startActivityForResult(searchIntent, INTENT_REQUEST_SEARCH);
        return;
    }

    // Navigate to the requested path
    String navigateTo = intent.getStringExtra(EXTRA_NAVIGATE_TO);
    if (navigateTo != null && navigateTo.length() >= 0) {
        getCurrentNavigationFragment().changeCurrentDir(navigateTo);
    }
}

From source file:org.andstatus.app.msg.TimelineActivity.java

private void parseAppSearchData(Intent intentNew) {
    Bundle appSearchData = intentNew.getBundleExtra(SearchManager.APP_DATA);
    if (appSearchData == null || !mListParametersNew
            .parseUri(Uri.parse(appSearchData.getString(IntentExtra.TIMELINE_URI.key, "")))) {
        return;/*from  ww w.ja  v a 2 s.  c  o m*/
    }
    /* The query itself is still from the Intent */
    mListParametersNew.mSearchQuery = TimelineListParameters
            .notNullString(intentNew.getStringExtra(SearchManager.QUERY));
    if (!TextUtils.isEmpty(mListParametersNew.mSearchQuery)
            && appSearchData.getBoolean(IntentExtra.GLOBAL_SEARCH.key, false)) {
        setSyncing("Global search: " + mListParametersNew.mSearchQuery, true);
        MyServiceManager
                .sendManualForegroundCommand(
                        CommandData
                                .searchCommand(
                                        isTimelineCombined() ? ""
                                                : MyContextHolder.get().persistentAccounts()
                                                        .getCurrentAccountName(),
                                        mListParametersNew.mSearchQuery));
    }
}

From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java

private int handleIntent(final Intent intent, final boolean firstCreate) {
    // use packge's class loader to prevent BadParcelException
    intent.setExtrasClassLoader(getClassLoader());
    // reset intent
    setIntent(new Intent(this, HomeActivity.class));
    final String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        final Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA);
        final long accountId;
        if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_ID)) {
            accountId = appSearchData.getLong(EXTRA_ACCOUNT_ID, -1);
        } else {/*from   w  ww . j av a2  s .  c o  m*/
            accountId = getDefaultAccountId(this);
        }
        openSearch(this, accountId, query);
        return -1;
    }
    final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
    final long[] refreshedIds = intent.getLongArrayExtra(EXTRA_IDS);
    if (refreshedIds != null) {
        mTwitterWrapper.refreshAll(refreshedIds);
    } else if (firstCreate && refreshOnStart) {
        mTwitterWrapper.refreshAll();
    }

    final int tab = intent.getIntExtra(EXTRA_INITIAL_TAB, -1);
    final int initialTab = tab != -1 ? tab : getAddedTabPosition(this, intent.getStringExtra(EXTRA_TAB_TYPE));
    if (initialTab != -1 && mViewPager != null) {
        // clearNotification(initial_tab);
    }
    final Intent extraIntent = intent.getParcelableExtra(EXTRA_EXTRA_INTENT);
    if (extraIntent != null && firstCreate) {
        extraIntent.setExtrasClassLoader(getClassLoader());
        SwipebackActivityUtils.startSwipebackActivity(this, extraIntent);
    }
    return initialTab;
}

From source file:org.getlantern.firetweet.activity.support.HomeActivity.java

private int handleIntent(final Intent intent, final boolean firstCreate) {
    // use packge's class loader to prevent BadParcelException
    intent.setExtrasClassLoader(getClassLoader());
    // reset intent
    setIntent(new Intent(this, HomeActivity.class));
    final String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        final Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA);
        final long accountId;
        if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_ID)) {
            accountId = appSearchData.getLong(EXTRA_ACCOUNT_ID, -1);
        } else {/*from www . j a v a2s. c o m*/
            accountId = getDefaultAccountId(this);
        }
        openSearch(this, accountId, query);
        return -1;
    }
    final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
    final long[] refreshedIds = intent.getLongArrayExtra(EXTRA_REFRESH_IDS);
    if (refreshedIds != null) {
        mTwitterWrapper.refreshAll(refreshedIds);
    } else if (firstCreate && refreshOnStart) {
        mTwitterWrapper.refreshAll();
    }

    final Uri uri = intent.getData();
    final String tabType = uri != null ? Utils.matchTabType(uri) : null;
    int initialTab = -1;
    if (tabType != null) {
        final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID));
        for (int i = mPagerAdapter.getCount() - 1; i > -1; i--) {
            final SupportTabSpec tab = mPagerAdapter.getTab(i);
            if (tabType.equals(tab.type)) {
                initialTab = i;
                if (hasAccountId(tab.args, accountId)) {
                    break;
                }
            }
        }
    }
    if (initialTab != -1 && mViewPager != null) {
        // clearNotification(initial_tab);
    }
    final Intent extraIntent = intent.getParcelableExtra(EXTRA_EXTRA_INTENT);
    if (extraIntent != null && firstCreate) {
        extraIntent.setExtrasClassLoader(getClassLoader());
        startActivity(extraIntent);
    }
    return initialTab;
}

From source file:org.andstatus.app.TimelineActivity.java

private void parseAppSearchData(Intent intentNew) {
    Bundle appSearchData = intentNew.getBundleExtra(SearchManager.APP_DATA);
    if (appSearchData != null) {
        // We use other packaging of the same parameters in onSearchRequested
        mListParametersNew.setTimelineType(
                TimelineTypeEnum.load(appSearchData.getString(IntentExtra.EXTRA_TIMELINE_TYPE.key)));
        if (mListParametersNew.getTimelineType() != TimelineTypeEnum.UNKNOWN) {
            mListParametersNew.setTimelineCombined(appSearchData.getBoolean(
                    IntentExtra.EXTRA_TIMELINE_IS_COMBINED.key, mListParametersNew.isTimelineCombined()));
            /* The query itself is still from the Intent */
            mListParametersNew.mSearchQuery = TimelineListParameters
                    .notNullString(intentNew.getStringExtra(SearchManager.QUERY));
            mListParametersNew.mSelectedUserId = appSearchData.getLong(IntentExtra.EXTRA_SELECTEDUSERID.key,
                    mListParametersNew.mSelectedUserId);
            if (!TextUtils.isEmpty(mListParametersNew.mSearchQuery)
                    && appSearchData.getBoolean(IntentExtra.EXTRA_GLOBAL_SEARCH.key, false)) {
                setSyncing("Global search: " + mListParametersNew.mSearchQuery, true);
                MyServiceManager//from   ww w .j a va  2  s  .com
                        .sendForegroundCommand(
                                CommandData.searchCommand(
                                        isTimelineCombined() ? ""
                                                : MyContextHolder.get().persistentAccounts()
                                                        .getCurrentAccountName(),
                                        mListParametersNew.mSearchQuery));
            }
        }
    }
}