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:com.khmelenko.lab.travisclient.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu_main, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    mSearchView = null;//from ww w .ja  va  2 s .co m
    if (searchItem != null) {
        mSearchView = (SearchView) searchItem.getActionView();
    }
    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                boolean submitProhibited = true;
                if (query.length() > SEARCH_LIMIT) {
                    // save search query to history
                    SearchRecentSuggestions suggestionsProvider = new SearchRecentSuggestions(MainActivity.this,
                            SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
                    suggestionsProvider.saveRecentQuery(query, null);
                    submitProhibited = false;
                }
                return submitProhibited;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                reloadSearchHistoryAdapter(newText);
                return true;
            }

        });
        mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
            @Override
            public boolean onSuggestionClick(int position) {
                mSearchView.setQuery(mQueryItems.get(position), true);
                return true;
            }

            @Override
            public boolean onSuggestionSelect(int position) {
                return true;
            }
        });

        reloadSearchHistoryAdapter("");

        // restore query if it was
        if (!TextUtils.isEmpty(mSavedQuery)) {
            mSearchView.setQuery(mSavedQuery, false);
            mSearchView.setIconified(false);
        }
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.xandy.calendar.SearchActivity.java

private void search(String searchQuery, Time goToTime) {
    // save query in recent queries
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, Utils.getSearchAuthority(this),
            CalendarRecentSuggestionsProvider.MODE);
    suggestions.saveRecentQuery(searchQuery, null);

    CalendarController.EventInfo searchEventInfo = new CalendarController.EventInfo();
    searchEventInfo.eventType = CalendarController.EventType.SEARCH;
    searchEventInfo.query = searchQuery;
    searchEventInfo.viewType = CalendarController.ViewType.AGENDA;
    if (goToTime != null) {
        searchEventInfo.startTime = goToTime;
    }/*from   www.  jav  a 2s  .co m*/
    mController.sendEvent(this, searchEventInfo);
    mQuery = searchQuery;
    if (mSearchView != null) {
        mSearchView.setQuery(mQuery, false);
        mSearchView.clearFocus();
    }
}

From source file:com.android.calendar.SearchActivity.java

private void search(String searchQuery, Time goToTime) {
    // save query in recent queries
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, Utils.getSearchAuthority(this),
            CalendarRecentSuggestionsProvider.MODE);
    suggestions.saveRecentQuery(searchQuery, null);

    EventInfo searchEventInfo = new EventInfo();
    searchEventInfo.eventType = EventType.SEARCH;
    searchEventInfo.query = searchQuery;
    searchEventInfo.viewType = ViewType.AGENDA;
    if (goToTime != null) {
        searchEventInfo.startTime = goToTime;
    }/*from ww  w . jav  a  2  s . c  om*/
    mController.sendEvent(this, searchEventInfo);
    mQuery = searchQuery;
    if (mSearchView != null) {
        mSearchView.setQuery(mQuery, false);
        mSearchView.clearFocus();
    }
}

From source file:org.mariotaku.twidere.fragment.support.SearchFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);/*from  w w w.j a v  a  2  s  .co  m*/
    final Bundle args = getArguments();
    final FragmentActivity activity = getActivity();
    mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager(), null, 1);
    mPagerAdapter.addTab(StatusesSearchFragment.class, args, getString(R.string.statuses),
            R.drawable.ic_action_twitter, 0, null);
    mPagerAdapter.addTab(SearchUsersFragment.class, args, getString(R.string.users), R.drawable.ic_action_user,
            1, null);
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mPagerIndicator.setViewPager(mViewPager);
    mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
    mPagerIndicator.setOnPageChangeListener(this);
    ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator, mPagerWindowOverlay);
    ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
    ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
    ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());

    if (activity instanceof IThemedActivity) {
        final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption();
        final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
        final int actionBarAlpha = isTransparent
                ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(activity))
                : 0xFF;
        mPagerIndicator.setAlpha(actionBarAlpha / 255f);
    }
    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();
}

From source file:com.weihuoya.bboo._G.java

public static SearchRecentSuggestions getSearchSuggestions() {
    if (mSuggestions == null) {
        mSuggestions = new SearchRecentSuggestions(getContext(), BBOOSuggestionsProvider.AUTHORITY,
                BBOOSuggestionsProvider.MODE);
    }/*w w w . j  ava 2  s .c o  m*/
    return mSuggestions;
}

From source file:edu.cmu.cylab.starslinger.view.PickRecipientsActivity.java

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

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

        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                CustomSuggestionsProvider.AUTHORITY, CustomSuggestionsProvider.MODE);
        suggestions.saveRecentQuery(searchQuery, null);
        searchContacts(searchQuery);//from  www  . ja  va2s. c o  m

    }
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.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  ww. j  av  a  2s  .c  om
            suggestions.saveRecentQuery(searchQuery, null);
        }

        if (searchQuery.contains("#")) {
            // we want to add it to the userAutoComplete
            HashtagDataSource source = HashtagDataSource.getInstance(context);

            if (source != null) {
                source.deleteTag(searchQuery.replaceAll("\"", ""));
                source.createTag(searchQuery.replaceAll("\"", ""));
            }
        }

        if (!searchQuery.contains("-RT")) {
            searchQuery += " -RT";
        }
        String query = searchQuery;

        doSearch(query);
    }
}

From source file:net.vivekiyer.GAL.CorporateAddressBook.java

private void performSearch(String name) {

    if (progressdialog != null) {
        progressdialog.setMessage(getString(R.string.retrievingResults));
        progressdialog.show();//w  w  w  .  jav  a2s .c o  m
    }

    // Save search in recent list
    final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
            RecentGALSearchTermsProvider.AUTHORITY, RecentGALSearchTermsProvider.MODE);
    suggestions.saveRecentQuery(name, null);

    search = new GALSearch(activeSyncManager);
    search.onSearchCompletedListener = this;
    search.execute(name);
}

From source file:com.klinker.android.twitter.ui.drawer_activities.discover.trends.SearchedTrendsActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        searchQuery = intent.getStringExtra(SearchManager.QUERY);
        String query = searchQuery;
        doSearch(query);/*from  w w w  .  j  a  v a  2  s .  co  m*/

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

        if (searchQuery.contains("#")) {
            // we want to add it to the userAutoComplete
            Log.v("talon_hashtag", "adding: " + searchQuery.replaceAll("\"", ""));
            HashtagDataSource source = HashtagDataSource.getInstance(context);

            if (source != null) {
                source.deleteTag(searchQuery.replaceAll("\"", ""));
                source.createTag(searchQuery.replaceAll("\"", ""));
            }
        }
    }
}

From source file:com.klinker.android.twitter.activities.profile_viewer.ProfilePager.java

public void getUser() {
    Thread getUser = new Thread(new Runnable() {
        @Override// w  ww .  jav a2  s. co  m
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                thisUser = twitter.showUser(screenName);
            } catch (Exception e) {
                thisUser = null;
            }

            if (thisUser != null) {
                try {
                    FollowersDataSource.getInstance(context).createUser(thisUser,
                            sharedPrefs.getInt("current_account", 1));

                } catch (Exception e) {
                    // the user already exists. don't know if this is more efficient than querying the db or not.
                }

                final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context,
                        MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
                suggestions.saveRecentQuery("@" + thisUser.getScreenName(), null);
            }

            new GetActionBarInfo().execute();
        }
    });

    getUser.setPriority(Thread.MAX_PRIORITY);
    getUser.start();
}