Example usage for android.provider SearchRecentSuggestions SearchRecentSuggestions

List of usage examples for android.provider SearchRecentSuggestions SearchRecentSuggestions

Introduction

In this page you can find the example usage for android.provider SearchRecentSuggestions SearchRecentSuggestions.

Prototype

public SearchRecentSuggestions(Context context, String authority, int mode) 

Source Link

Document

Although provider utility classes are typically static, this one must be constructed because it needs to be initialized using the same values that you provided in your android.content.SearchRecentSuggestionsProvider .

Usage

From source file:fi.villel.foosquare.SearchActivity.java

@Override
public void saveRecentQuery(String query) {
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY,
            SearchSuggestionProvider.MODE);
    suggestions.saveRecentQuery(query, null);
}

From source file:com.dwdesign.tweetings.activity.SearchActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Intent intent = getIntent();
    mArguments.clear();/*from  w ww  . j av a  2  s. c  om*/
    mData = intent.getData();
    final boolean is_search_user = mData != null
            ? QUERY_PARAM_VALUE_USERS.equals(mData.getQueryParameter(QUERY_PARAM_TYPE))
            : false;
    final String query = Intent.ACTION_SEARCH.equals(intent.getAction())
            ? intent.getStringExtra(SearchManager.QUERY)
            : mData != null ? mData.getQueryParameter(QUERY_PARAM_QUERY) : null;
    int search_id = -1;
    if (mData != null && mData.getQueryParameter(QUERY_PARAM_ID) != null) {
        search_id = Integer.parseInt(mData.getQueryParameter(QUERY_PARAM_ID));
    }
    if (query == null) {
        finish();
        return;
    }
    if (savedInstanceState == null) {
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE);
        suggestions.saveRecentQuery(query, null);
    }
    mArguments.putString(INTENT_KEY_QUERY, query);
    mArguments.putInt(INTENT_KEY_ID, search_id);
    final String param_account_id = mData != null ? mData.getQueryParameter(QUERY_PARAM_ACCOUNT_ID) : null;
    if (param_account_id != null) {
        mArguments.putLong(INTENT_KEY_ACCOUNT_ID, parseLong(param_account_id));
    } else {
        final String param_account_name = mData != null ? mData.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME)
                : null;
        if (param_account_name != null) {
            mArguments.putLong(INTENT_KEY_ACCOUNT_ID, getAccountId(this, param_account_name));
        } else {
            final long account_id = getDefaultAccountId(this);
            if (isMyAccount(this, account_id)) {
                mArguments.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
            } else {
                finish();
                return;
            }
        }
    }
    mActionBar = getSupportActionBar();
    mActionBar.setCustomView(R.layout.base_tabs);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mActionBar.setDisplayShowCustomEnabled(true);
    final View view = mActionBar.getCustomView();
    mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
    mIndicator = (TabPageIndicator) view.findViewById(android.R.id.tabs);
    mAdapter = new TabsAdapter(this, getSupportFragmentManager(), mIndicator);
    mAdapter.setDisplayLabel(true);
    mAdapter.addTab(SearchTweetsFragment.class, mArguments, getString(R.string.search_tweets),
            R.drawable.ic_tab_twitter, 0);
    mAdapter.addTab(SearchUsersFragment.class, mArguments, getString(R.string.search_users),
            R.drawable.ic_tab_person, 1);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOffscreenPageLimit(1);
    mIndicator.setViewPager(mViewPager);
    mViewPager.setCurrentItem(is_search_user ? 1 : 0);
}

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  ww w .j  av a2  s  .co  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.ratebeer.android.gui.fragments.SearchFragment.java

@AfterViews
public void init() {

    // Get and set up ListViews and the ViewPager
    pager.setAdapter(new SearchPagerAdapter());
    titles.setViewPager(pager);//from  w  w  w. ja  va2s  .  c  o m

    beersView.setOnItemClickListener(onBeerSelected);
    brewersView.setOnItemClickListener(onBrewerSelected);
    placesView.setOnItemClickListener(onPlaceSelected);
    usersView.setOnItemClickListener(onUserSelected);
    registerForContextMenu(beersView);
    registerForContextMenu(brewersView);
    registerForContextMenu(placesView);
    registerForContextMenu(usersView);

    if (beerResults != null && brewerResults != null && placeResults != null && userResults != null) {
        publishBeerResults(beerResults);
        publishBrewerResults(brewerResults);
        publishPlaceResults(placeResults);
        publishUserResults(userResults);
    } else {
        // Fresh start: save this query and perform the search
        if (query != null) {
            // Store query in search history
            SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
                    SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
            suggestions.saveRecentQuery(query, null);
        }
        performSearch();
    }

    if (startBarcodeScanner) {
        startScanner();
        // Don't start again when returning to this screen
        startBarcodeScanner = false;
    }

}

From source file:com.klinker.android.twitter.activities.search.SearchPager.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        searchQuery = intent.getStringExtra(SearchManager.QUERY);

        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionsProvider.AUTHORITY,
                MySuggestionsProvider.MODE);

        if (searchQuery.contains("#")) {
            suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
        } else {/* w w  w  .j  av  a 2s . c om*/
            suggestions.saveRecentQuery(searchQuery, null);
        }

        searchQuery += " -RT";
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        String uriString = uri.toString();
        if (uriString.contains("status/")) {
            long id;
            String replace = uriString.substring(uriString.indexOf("status")).replace("status/", "")
                    .replaceAll("photo/*", "");
            if (replace.contains("/")) {
                replace = replace.substring(0, replace.indexOf("/"));
            } else if (replace.contains("?")) {
                replace = replace.substring(0, replace.indexOf("?"));
            }
            try {
                id = Long.parseLong(replace);
            } catch (Exception e) {
                id = 0l;
            }
            searchQuery = id + "";
            onlyStatus = true;
        } else if (!uriString.contains("q=") && !uriString.contains("screen_name%3D")) {
            // going to try searching for users i guess
            String name = uriString.substring(uriString.indexOf(".com/"));
            name = name.replaceAll("/", "").replaceAll(".com", "");
            searchQuery = name;
            onlyProfile = true;
        } else if (uriString.contains("q=")) {
            try {
                String search = uri.getQueryParameter("q");

                if (search != null) {
                    searchQuery = search;
                    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                            MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);

                    if (searchQuery.contains("#")) {
                        suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
                    } else {
                        suggestions.saveRecentQuery(searchQuery, null);
                    }

                    searchQuery += " -RT";
                } else {
                    searchQuery = "";
                }

            } catch (Exception e) {

            }
        } else {
            try {
                String search = uriString;

                search = search.substring(search.indexOf("screen_name%3D") + 14);
                search = search.substring(0, search.indexOf("%"));

                if (search != null) {
                    searchQuery = search;

                    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                            MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);

                    if (searchQuery.contains("#")) {
                        suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
                    } else {
                        suggestions.saveRecentQuery(searchQuery, null);
                    }

                    searchQuery += " -RT";
                } else {
                    searchQuery = "";
                }

                onlyProfile = true;
            } catch (Exception e) {

            }
        }
    }
}

From source file:com.klinker.android.twitter.ui.search.SearchPager.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        searchQuery = intent.getStringExtra(SearchManager.QUERY);

        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionsProvider.AUTHORITY,
                MySuggestionsProvider.MODE);
        suggestions.saveRecentQuery(searchQuery, null);
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();//from   w w w.  ja  v a2s. c  o  m
        String uriString = uri.toString();
        if (uriString.contains("status/")) {
            long id;
            String replace = uriString.substring(uriString.indexOf("status")).replace("status/", "")
                    .replaceAll("photo/*", "");
            if (replace.contains("/")) {
                replace = replace.substring(0, replace.indexOf("/"));
            } else if (replace.contains("?")) {
                replace = replace.substring(0, replace.indexOf("?"));
            }
            try {
                id = Long.parseLong(replace);
            } catch (Exception e) {
                id = 0l;
            }
            searchQuery = id + "";
            onlyStatus = true;
        } else if (!uriString.contains("q=") && !uriString.contains("screen_name%3D")) { // going to try searching for users i guess
            String name = uriString.substring(uriString.indexOf(".com/"));
            name = name.replaceAll("/", "").replaceAll(".com", "");
            searchQuery = name;
            onlyProfile = true;
            Log.v("talon_searching", "only profile");
        } else if (uriString.contains("q=")) {
            try {
                String search = uri.getQueryParameter("q");

                if (search != null) {
                    searchQuery = search;
                    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                            MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
                    suggestions.saveRecentQuery(searchQuery, null);
                } else {
                    searchQuery = "";
                }

            } catch (Exception e) {

            }
        } else {
            try {
                String search = uriString;

                search = search.substring(search.indexOf("screen_name%3D") + 14);
                search = search.substring(0, search.indexOf("%"));

                if (search != null) {
                    searchQuery = search;

                    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                            MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
                    suggestions.saveRecentQuery(searchQuery, null);
                } else {
                    searchQuery = "";
                }

                onlyProfile = true;
            } catch (Exception e) {

            }
        }
    }
}

From source file:com.xorcode.andtweet.TweetListActivity.java

/**
 * Prepare query to the ContentProvider (to the database) and load List of Tweets with data
 * @param queryIntent/*from w w  w.j ava2 s.com*/
 * @param otherThread This method is being accessed from other thread
 * @param loadOneMorePage load one more page of tweets
 */
protected void queryListData(Intent queryIntent, boolean otherThread, boolean loadOneMorePage) {
    // The search query is provided as an "extra" string in the query intent
    // TODO maybe use mQueryString here...
    String queryString = queryIntent.getStringExtra(SearchManager.QUERY);
    Intent intent = getIntent();

    if (MyLog.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "doSearchQuery; queryString=\"" + queryString + "\"; TimelineType=" + mTimelineType);
    }

    Uri contentUri = Tweets.CONTENT_URI;

    SelectionAndArgs sa = new SelectionAndArgs();
    String sortOrder = Tweets.DEFAULT_SORT_ORDER;
    // Id of the last (oldest) tweet to retrieve 
    long lastItemId = -1;

    if (queryString != null && queryString.length() > 0) {
        // Record the query string in the recent queries suggestions
        // provider
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                TimelineSearchSuggestionProvider.AUTHORITY, TimelineSearchSuggestionProvider.MODE);
        suggestions.saveRecentQuery(queryString, null);

        contentUri = Tweets.SEARCH_URI;
        contentUri = Uri.withAppendedPath(contentUri, Uri.encode(queryString));
    }
    intent.putExtra(SearchManager.QUERY, queryString);

    if (!contentUri.equals(intent.getData())) {
        intent.setData(contentUri);
    }

    if (sa.nArgs == 0) {
        // In fact this is needed every time you want to load next page of
        // tweets.
        // So we have to duplicate here everything we set in
        // com.xorcode.andtweet.TimelineActivity.onOptionsItemSelected()
        sa.clear();
        sa.addSelection(Tweets.TWEET_TYPE + " IN (?, ?)", new String[] {
                String.valueOf(Tweets.TIMELINE_TYPE_FRIENDS), String.valueOf(Tweets.TIMELINE_TYPE_MENTIONS) });
        if (mTimelineType == Tweets.TIMELINE_TYPE_FAVORITES) {
            sa.addSelection(AndTweetDatabase.Tweets.FAVORITED + " = ?", new String[] { "1" });
        }
        if (mTimelineType == Tweets.TIMELINE_TYPE_MENTIONS) {
            sa.addSelection(Tweets.MESSAGE + " LIKE ?",
                    new String[] { "%@" + TwitterUser.getTwitterUser().getUsername() + "%" });
        }
    }

    if (!positionRestored) {
        // We have to ensure that saved position will be
        // loaded from database into the list
        lastItemId = getSavedPosition(true);
    }

    int nTweets = 0;
    if (mCursor != null && !mCursor.isClosed()) {
        if (positionRestored) {
            // If position is NOT loaded - this cursor is from other
            // timeline/search
            // and we shouldn't care how much rows are there.
            nTweets = mCursor.getCount();
        }
        if (!otherThread) {
            mCursor.close();
        }
    }

    if (lastItemId > 0) {
        if (sa.nArgs == 0) {
            sa.addSelection("AndTweetDatabase.Tweets.TWEET_TYPE" + " IN (?, ?)" + ")",
                    new String[] { String.valueOf(Tweets.TIMELINE_TYPE_FRIENDS),
                            String.valueOf(Tweets.TIMELINE_TYPE_MENTIONS) });
        }
        sa.addSelection(Tweets._ID + " >= ?", new String[] { String.valueOf(lastItemId) });
    } else {
        if (loadOneMorePage) {
            nTweets += PAGE_SIZE;
        } else if (nTweets < PAGE_SIZE) {
            nTweets = PAGE_SIZE;
        }
        sortOrder += " LIMIT 0," + nTweets;
    }

    // This is for testing pruneOldRecords
    //        try {
    //            FriendTimeline fl = new FriendTimeline(TweetListActivity.this,
    //                    AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS);
    //            fl.pruneOldRecords();
    //
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //        }

    mCursor = getContentResolver().query(contentUri, PROJECTION, sa.selection, sa.selectionArgs, sortOrder);
    if (!otherThread) {
        createAdapters();
    }

}

From source file:com.zzolta.android.gfrecipes.fragments.RecipeDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_detail, menu);

    final MenuItem share = menu.findItem(R.id.action_share);
    RecipeDetailShareActionProvider.getInstance()
            .setShareActionProvider((ShareActionProvider) MenuItemCompat.getActionProvider(share));

    final MenuItem clearSearchHistory = menu.findItem(R.id.action_clear_search_history);
    clearSearchHistory.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override//  ww  w.  ja  v  a 2s.c o m
        public boolean onMenuItemClick(MenuItem item) {
            new Builder(getActivity()).setTitle(getString(R.string.action_clear_search_history))
                    .setMessage(getString(R.string.confirmation_clear_search_history))
                    .setIcon(drawable.ic_dialog_alert).setPositiveButton(string.yes, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(
                                    getActivity(), RecipeSearchRecentSuggestionsProvider.AUTHORITY,
                                    RecipeSearchRecentSuggestionsProvider.MODE);
                            suggestions.clearHistory();
                        }
                    }).setNegativeButton(string.no, null).show();
            return true;
        }
    });

    final MenuItem addToMyRecipes = menu.findItem(R.id.action_add_to_my_recipes);
    addToMyRecipes.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            myRecipeHandler(true);
            return true;
        }
    });

    final MenuItem removeFromMyRecipes = menu.findItem(R.id.action_remove_from_my_recipes);
    removeFromMyRecipes.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            myRecipeHandler(false);
            return true;
        }
    });
}

From source file:com.ratebeer.android.gui.fragments.SearchFragment.java

@OptionsItem(R.id.menu_clearhistory)
protected void onClearHistory() {
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
            SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
    suggestions.clearHistory();/*from  w  ww.j a  va 2 s .  c om*/
}

From source file:org.getlantern.firetweet.fragment.support.SearchFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);/*from  w  w w .  jav a  2s .  c  om*/
    final Bundle args = getArguments();
    final FragmentActivity activity = getActivity();
    mAdapter = new SupportTabsAdapter(activity, getChildFragmentManager(), null, 1);
    mAdapter.addTab(StatusesSearchFragment.class, args, getString(R.string.statuses),
            R.drawable.ic_action_twitter, 0, null);
    mAdapter.addTab(SearchUsersFragment.class, args, getString(R.string.users), R.drawable.ic_action_user, 1,
            null);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mPagerIndicator.setViewPager(mViewPager);
    mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
    mPagerIndicator.setOnPageChangeListener(this);
    ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator);
    ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
    if (savedInstanceState == null && args != null && args.containsKey(EXTRA_QUERY)) {
        final String query = args.getString(EXTRA_QUERY);
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
                RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE);
        suggestions.saveRecentQuery(query, null);
        final ContentResolver cr = getContentResolver();
        final ContentValues values = new ContentValues();
        values.put(SearchHistory.QUERY, query);
        cr.insert(SearchHistory.CONTENT_URI, values);
        if (activity instanceof LinkHandlerActivity) {
            final ActionBar ab = activity.getActionBar();
            if (ab != null) {
                ab.setSubtitle(query);
            }
        }
    }
    updateTabOffset();
}