extends SearchRecentSuggestionsProvider : SearchRecentSuggestionsProvider « Core Class « Android






extends SearchRecentSuggestionsProvider

   
package app.test;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.content.SearchRecentSuggestionsProvider;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

class SimpleSuggestionProvider extends SearchRecentSuggestionsProvider {
    final static String AUTHORITY = "app.test.SimpleSuggestionProvider";
    final static int MODE = DATABASE_MODE_2LINES | DATABASE_MODE_QUERIES;
    public SimpleSuggestionProvider() {
        super();
        setupSuggestions(AUTHORITY, MODE);
    }
}
class SearchActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.row);
      this.setDefaultKeyMode(Activity.DEFAULT_KEYS_SEARCH_LOCAL);
        final Intent queryIntent = getIntent();
        final String queryAction = queryIntent.getAction();
        if (Intent.ACTION_SEARCH.equals(queryAction)) 
        {
          this.doSearchQuery(queryIntent);
        }
        return;
    }
    
    @Override
    public void onNewIntent(final Intent newIntent) 
    {
        super.onNewIntent(newIntent);
        
        final Intent queryIntent = getIntent();
        final String queryAction = queryIntent.getAction();
        if (Intent.ACTION_SEARCH.equals(queryAction)) 
        {
          this.doSearchQuery(queryIntent);
        }
    }
    private void doSearchQuery(final Intent queryIntent) 
    {
        final String queryString = queryIntent.getStringExtra(SearchManager.QUERY);
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, 
            SimpleSuggestionProvider.AUTHORITY, 
            SimpleSuggestionProvider.MODE);
        suggestions.saveRecentQuery(queryString, "SSSP");
    }
}
    

public class Test extends Activity 
{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
      super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.my_menu, menu);
      return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
      if (item.getItemId() == R.id.mid_reset_suggestions)
      {
            SearchRecentSuggestions suggestions = 
              new SearchRecentSuggestions(this, 
                SimpleSuggestionProvider.AUTHORITY, 
                SimpleSuggestionProvider.MODE);
            suggestions.clearHistory();
      }
      return true;
    }
    
}

   
    
    
  








Related examples in the same category