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.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 av  a  2s.  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.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  w w.j a va2s. c o  m
            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: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 ww  .j  a  va  2s .com*/

    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.audiokernel.euphonyrmt.SearchActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.search_results);

    final SearchResultsPagerAdapter adapter = new SearchResultsPagerAdapter();
    final ActionBar actionBar = getSupportActionBar();

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);/*from  w ww .j  a v a 2 s. co  m*/
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(final int position) {
            // When swiping between pages, select the corresponding tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mTabArtists = actionBar.newTab().setText(R.string.artists).setTabListener(this);
    actionBar.addTab(mTabArtists);

    mTabAlbums = actionBar.newTab().setText(R.string.albums).setTabListener(this);
    actionBar.addTab(mTabAlbums);

    mTabSongs = actionBar.newTab().setText(R.string.songs).setTabListener(this);
    actionBar.addTab(mTabSongs);

    mListArtistsFrame = findViewById(R.id.list_artists_frame);
    mNoResultArtistsView = mListArtistsFrame.findViewById(R.id.no_artist_result);
    mListArtists = (ListView) mListArtistsFrame.findViewById(android.R.id.list);
    mListArtists.setOnItemClickListener(this);

    mListAlbumsFrame = findViewById(R.id.list_albums_frame);
    mNoResultAlbumsView = mListAlbumsFrame.findViewById(R.id.no_album_result);
    mListAlbums = (ListView) mListAlbumsFrame.findViewById(android.R.id.list);
    mListAlbums.setOnItemClickListener(this);

    mListSongsFrame = findViewById(R.id.list_songs_frame);
    mNoResultSongsView = mListSongsFrame.findViewById(R.id.no_song_result);
    mListSongs = (ListView) mListSongsFrame.findViewById(android.R.id.list);
    mListSongs.setOnItemClickListener(this);

    mLoadingView = findViewById(R.id.loadingLayout);
    mLoadingView.setVisibility(View.VISIBLE);

    final Intent queryIntent = getIntent();
    final String queryAction = queryIntent.getAction();

    if (Intent.ACTION_SEARCH.equals(queryAction) || PLAY_SERVICES_ACTION_SEARCH.equals(queryAction)) {
        mSearchKeywords = queryIntent.getStringExtra(SearchManager.QUERY).trim();
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                SearchRecentProvider.AUTHORITY, SearchRecentProvider.MODE);
        suggestions.saveRecentQuery(mSearchKeywords, null);
    } else {
        return; // Bye !
    }

    setTitle(getTitle() + " : " + mSearchKeywords);

    registerForContextMenu(mListArtists);
    registerForContextMenu(mListAlbums);
    registerForContextMenu(mListSongs);

    updateList();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

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

private void performSearch(String name) {

    if (progressdialog != null) {
        progressdialog.setMessage(getString(R.string.retrievingResults));
        progressdialog.show();//from  w  w w .ja v a 2  s .  c  om
    }

    // 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:cl.droid.transantiago.activity.TransChooseServiceActivity.java

public void launch(final String paradero, final String description) {
    //         final String paradero = item.mTitle;
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(TransChooseServiceActivity.this,
            MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE);
    suggestions.saveRecentQuery(paradero, null);

    //         final ProgressDialog progress = ProgressDialog.show(
    //               TransChooseServiceActivity.this, TransChooseServiceActivity.this.getResources().getText(
    //                     R.string.please_wait), TransChooseServiceActivity.this.getResources().getText(
    //                           R.string.searching), true, true);
    showRefreshSpinner(true);//from w w  w.  j  av a  2s .c o  m
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (progress != null && progress.isShowing())
                try {
                    progress.dismiss();
                    //                     backgroundThreadComplete = true;
                } catch (IllegalArgumentException e) {
                    // if orientation change, thread continue but the dialog cannot be dismissed without exception
                }
            if (locations != null && locations.containsKey("names")
                    && locations.getStringArray("names").length > 0) {
                locationInfo = locations.getStringArray("info");
                locationNames = locations.getStringArray("names");
                setListAdapter(la);

                if (locations.containsKey("ads"))
                    loadImage(locations.getString("ads"), bmOptions);
                //                     Intent intent = new Intent(SatNavActivity.this,
                //                           //                        org.opensatnav.android.ServiceActivity.class);
                //                           cl.droid.transantiago.TransChooseServiceActivity.class);
                //                     intent.putExtra("fromLocation", from.toDoubleString());
                //                     intent.putExtra("locations", locations);
                //                     intent.putExtra("paradero", paradero);
                //
                //                     String urlstring = "http://m.ibus.cl/index.jsp?paradero="+paradero+"&servicio=&boton.x=0&boton.y=0";
                //                     //                  Log.i(OpenSatNavConstants.LOG_TAG, urlstring);
                //                     intent.putExtra("url", urlstring);
                //                     startActivityForResult(intent,0);

            } else if (locations != null && locations.containsKey("names")
                    && locations.getStringArray("names").length == 0)
                Toast.makeText(TransChooseServiceActivity.this,
                        String.format(TransChooseServiceActivity.this.getResources().getText(
                                //                                    R.string.could_not_find_poi
                                R.string.place_not_found).toString(), "paradero")
                //                              + " " + stringValue
                , Toast.LENGTH_LONG).show();
            if (locations == null)
                Toast.makeText(TransChooseServiceActivity.this,
                        TransChooseServiceActivity.this.getResources().getText(
                                //                           R.string.could_not_find_poi
                                R.string.error_no_server_conn).toString(),
                        Toast.LENGTH_LONG).show();

            //               TransChooseLocationServiceActivity.this.finish();
            showRefreshSpinner(false);
        }
    };
    new Thread(new Runnable() {
        public void run() {
            // put long running operations here
            TransantiagoGeoCoder geoCoder = null;

            geoCoder = new TransantiagoGeoCoder();

            //               if (selectedPoi == -1) { // text search, rank results within an area
            locations = geoCoder.queryService(paradero, from, GeoCoder.IN_AREA, 25,
                    TransChooseServiceActivity.this);
            //               }
            //               else {  //POI search, just find the nearest matching POI
            //               locations = geoCoder.queryService("", from, GeoCoder.FROM_POINT, 25,
            //                     TransChooseLocationServiceActivity.this);
            //               }
            // ok, we are done
            handler.sendEmptyMessage(0);

        }
    }).start();

}

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  .jav a 2s .  c o m*/
 * @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:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java

/**
 * This method is called by the underlying Activity when a search has been
 * initiated.//from  www  . jav a 2 s . c o m
 * 
 * @param searchTerm What to search for.
 */
public void onSearch(final String searchTerm) {
    if (map == null) {
        return;
    }

    final Matcher m = STOP_CODE_SEARCH_PATTERN.matcher(searchTerm);

    if (m.matches()) {
        // If the searchTerm is a stop code, then move the camera to the bus
        // stop.
        moveCameraToBusStop(searchTerm);
    } else {
        // If it's not a stop code, then do a geo search.
        final Bundle b = new Bundle();
        b.putString(LOADER_ARG_QUERY, searchTerm);

        // Save the search term as a search suggestion.
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
                MapSearchSuggestionsProvider.AUTHORITY, MapSearchSuggestionsProvider.MODE);
        suggestions.saveRecentQuery(searchTerm, null);

        // Start the search loader.
        getLoaderManager().restartLoader(LOADER_ID_GEO_SEARCH, b, this);

        callbacks.onShowSearchProgress(getString(R.string.busstopmapfragment_progress_message, searchTerm));
    }
}

From source file:com.taw.gotothere.GoToThereActivity.java

/**
 * Handle any intents passed into the activity. Currently we only deal with
 * on, ACTION_SEARCH, which means we've been given a query string to search
 * for via the quick search box. We'll also handle the case where the activity
 * is restarted due to orientation changes; in this situation we still have the 
 * intent with ACTION_SEARCH, so we check if we've already processed it; if so
 * don't bother geocoding./* www  . ja  v  a  2 s. com*/
 * 
 * @param intent The intent to process
 * @param savedInstanceState The bundle passed into the activity on (re)start
 */
private void handleIntent(Intent intent, Bundle savedInstanceState) {

    if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
        Log.d(TAG, "Started as a result of ACTION_SEARCH");
        String query = intent.getStringExtra(SearchManager.QUERY);

        SharedPreferences prefs = getPreferences(Activity.MODE_PRIVATE);
        String previousQuery = prefs.getString(PREVIOUS_QUERY, null);
        if (previousQuery == null || !previousQuery.equals(query)) {
            Log.d(TAG, "    Haven't processed this query before");
            SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                    GoToThereSuggestionProvider.AUTHORITY, GoToThereSuggestionProvider.MODE);
            suggestions.saveRecentQuery(query, null);

            geocodeResult(query);
        } // Else UI stuff set up by onRestoreInstanceState() 
    }
}

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

private void saveSearchQuery() {
    if (!TextUtils.isEmpty(mListParametersNew.mSearchQuery)) {
        // Record the query string in the recent queries
        // of the Suggestion Provider
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                TimelineSearchSuggestionsProvider.AUTHORITY, TimelineSearchSuggestionsProvider.MODE);
        suggestions.saveRecentQuery(mListParametersNew.mSearchQuery, null);

    }/*from  www . ja v  a2s. co m*/
}