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:ru.lizaalert.common.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.action_clear_history:
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionProvider.AUTHORITY,
                MySuggestionProvider.MODE);
        suggestions.clearHistory();// w  ww. j a  v  a  2  s  .com
        return true;
    case R.id.action_search:
        onSearchRequested();
        return true;
    case R.id.action_about:
        startActivity(new Intent(this, About.class));
        return true;
    case R.id.action_update_yp:
        YellowPagesLoader.getInstance(this).fetchDataAsync();
        return true;
    }
    return (super.onOptionsItemSelected(menuItem));
}

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;/*  www.j  a v  a2s  . c o  m*/
    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:net.vivekiyer.GAL.CorporateAddressBook.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_search:
        return this.onSearchRequested();
    case R.id.settings:
        CorporateAddressBook.showConfiguration(this);
        return true;
    case R.id.clearSearchHistory:
        final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                RecentGALSearchTermsProvider.AUTHORITY, RecentGALSearchTermsProvider.MODE);
        suggestions.clearHistory();/*  w  ww .j av a 2s.  c o m*/
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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);/* w w  w . j av a2  s .c o  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:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java

/**
 * This method is called by the underlying Activity when a search has been
 * initiated./*from   w  ww  .  j  av  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: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   ww  w  .j  ava 2s  .  com*/
    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.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.//from  w  w w. j av a  2s. c o m
 * 
 * @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:com.supremainc.biostar2.main.HomeActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);//  w w w. j  av  a 2  s  .  c  o m
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (BuildConfig.DEBUG) {
            Log.e("search", "query:" + query);
        }
        if (query != null && query.length() > 0) {
            if (mSuggestions == null) {
                mSuggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY,
                        SearchSuggestionProvider.MODE);
            }
            mSuggestions.saveRecentQuery(query, null);
        }
        mFragment.onSearch(query);
        return;
    }

    if (BuildConfig.DEBUG) {
        Log.i(TAG, "onNewIntent:");
    }

    if (intent != null) {
        String action = intent.getAction();
        if (action != null && action.startsWith(Setting.ACTION_NOTIFICATION_START)
                && mPermissionDataProvider != null
                && mPermissionDataProvider.getPermission(PERMISSION_MODULE.DOOR, true)) {
            gotoScreen(ScreenType.ALARM_LIST, null, true);
        }
    }
}

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  w  w  w  .  j  a v a  2  s. c  o m
}

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

private void logoutFromTwitter() {

    context.sendBroadcast(new Intent("com.daiv.android.STOP_PUSH_SERVICE"));

    int currentAccount = sharedPrefs.getInt("current_account", 1);
    boolean login1 = sharedPrefs.getBoolean("is_logged_in_1", false);
    boolean login2 = sharedPrefs.getBoolean("is_logged_in_2", false);

    // Delete the data for the logged out account
    SharedPreferences.Editor e = sharedPrefs.edit();
    e.remove("authentication_token_" + currentAccount);
    e.remove("authentication_token_secret_" + currentAccount);
    e.remove("is_logged_in_" + currentAccount);
    e.remove("new_notification");
    e.remove("new_retweets");
    e.remove("new_favorites");
    e.remove("new_follows");
    e.remove("current_position_" + currentAccount);
    e.remove("last_activity_refresh_" + currentAccount);
    e.remove("original_activity_refresh_" + currentAccount);
    e.remove("activity_follower_count_" + currentAccount);
    e.remove("activity_latest_followers_" + currentAccount);
    e.commit();/*from  www.  j  a  v  a 2 s . c o m*/

    HomeDataSource homeSources = HomeDataSource.getInstance(context);
    homeSources.deleteAllTweets(currentAccount);

    MentionsDataSource mentionsSources = MentionsDataSource.getInstance(context);
    mentionsSources.deleteAllTweets(currentAccount);

    DMDataSource dmSource = DMDataSource.getInstance(context);
    dmSource.deleteAllTweets(currentAccount);

    FavoriteUsersDataSource favs = FavoriteUsersDataSource.getInstance(context);
    favs.deleteAllUsers(currentAccount);

    InteractionsDataSource inters = InteractionsDataSource.getInstance(context);
    inters.deleteAllInteractions(currentAccount);

    ActivityDataSource activity = ActivityDataSource.getInstance(context);
    activity.deleteAll(currentAccount);

    FavoriteTweetsDataSource favTweets = FavoriteTweetsDataSource.getInstance(context);
    favTweets.deleteAllTweets(currentAccount);

    try {
        long account1List1 = sharedPrefs.getLong("account_" + currentAccount + "_list_1", 0l);
        long account1List2 = sharedPrefs.getLong("account_" + currentAccount + "_list_2", 0l);

        ListDataSource list = ListDataSource.getInstance(context);
        list.deleteAllTweets(account1List1);
        list.deleteAllTweets(account1List2);
    } catch (Exception x) {

    }

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

    AppSettings.invalidate();

    if (currentAccount == 1 && login2) {
        e.putInt("current_account", 2).commit();
        finish();
        Intent next = new Intent(context, MainActivity.class);
        startActivity(next);
    } else if (currentAccount == 2 && login1) {
        e.putInt("current_account", 1).commit();
        finish();
        Intent next = new Intent(context, MainActivity.class);
        startActivity(next);
    } else { // only the one account
        e.putInt("current_account", 1).commit();
        finish();
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
    }

}