Example usage for android.provider SearchRecentSuggestions saveRecentQuery

List of usage examples for android.provider SearchRecentSuggestions saveRecentQuery

Introduction

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

Prototype

public void saveRecentQuery(final String queryString, final String line2) 

Source Link

Document

Add a query to the recent queries list.

Usage

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;
    }/* w w w .  j av  a2s  .c o  m*/
    mController.sendEvent(this, searchEventInfo);
    mQuery = searchQuery;
    if (mSearchView != null) {
        mSearchView.setQuery(mQuery, false);
        mSearchView.clearFocus();
    }
}

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;
    }/*w w  w . j a  v  a 2 s . com*/
    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);// w w w .  ja  v a2  s  .c  o  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: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;/*w ww. 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.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 w w  w.j  a  v a  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:io.github.hidroh.materialistic.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (getIntent().hasExtra(SearchManager.QUERY)) {
        mQuery = getIntent().getStringExtra(SearchManager.QUERY);
    }// w  w  w.j a va  2s .c  o m
    super.onCreate(savedInstanceState);
    if (!TextUtils.isEmpty(mQuery)) {
        getSupportActionBar().setSubtitle(mQuery);
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                SearchRecentSuggestionsProvider.PROVIDER_AUTHORITY, SearchRecentSuggestionsProvider.MODE) {
            @Override
            public void saveRecentQuery(String queryString, String line2) {
                truncateHistory(getContentResolver(), MAX_RECENT_SUGGESTIONS - 1);
                super.saveRecentQuery(queryString, line2);
            }
        };
        suggestions.saveRecentQuery(mQuery, null);
    }
}

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 www.  java2s .  co  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: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);// www  .  j  a  v  a  2  s  . com

    }
}

From source file:net.grobas.blizzardleaderboards.app.ui.MainActivity.java

@Override
public boolean onQueryTextSubmit(String query) {
    //Avoid bug: this is called twice in some devices (ACTION_UP and ACTION_DOWN)
    long actualSearchTime = Calendar.getInstance().getTimeInMillis();
    if (actualSearchTime < lastSearchTime + 1000)
        return true;

    lastSearchTime = actualSearchTime;/*from w ww .j  a v  a 2s  .com*/
    if (TextUtils.isEmpty(query)) {
        mAdapter.clearAll();
    } else {
        lastQuery = query;
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, RecentSearchProvider.AUTHORITY,
                RecentSearchProvider.MODE);
        suggestions.saveRecentQuery(query, null);
        mAdapter.getFilter().filter(query);
    }
    return true;
}

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 ava2  s.  co m*/
            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) {

            }
        }
    }
}