Example usage for android.app SearchManager QUERY

List of usage examples for android.app SearchManager QUERY

Introduction

In this page you can find the example usage for android.app SearchManager QUERY.

Prototype

String QUERY

To view the source code for android.app SearchManager QUERY.

Click Source Link

Document

Intent extra data key: Use this key with android.content.Intent#getStringExtra content.Intent.getStringExtra() to obtain the query string from Intent.ACTION_SEARCH.

Usage

From source file:com.smedic.tubtub.Pane.java

/**
 * Options menu in action bar/*  w  w  w.jav a  2s.  co m*/
 *
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

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

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    //suggestions
    final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, suggestions, null,
            new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0);
    final List<String> suggestions = new ArrayList<>();

    searchView.setSuggestionsAdapter(suggestionAdapter);

    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            searchView.setQuery(suggestions.get(position), false);
            searchView.clearFocus();

            Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH);
            suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position));
            handleIntent(suggestionIntent);

            return true;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            return false; //if true, no new intent is started
        }

        @Override
        public boolean onQueryTextChange(final String query) {
            // check network connection. If not available, do not query.
            // this also disables onSuggestionClick triggering
            if (query.length() > 2) { //make suggestions after 3rd letter
                if (networkConf.isNetworkAvailable()) {
                    suggestionLoader(suggestions, suggestionAdapter, query).forceLoad();
                    return true;
                }
            }
            return false;
        }
    });

    return true;
}

From source file:com.todotxt.todotxttouch.TodoTxtTouch.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    currentActivityPointer = this;

    setContentView(R.layout.main);//from  ww  w.  j a  va  2s  .  c  om

    m_app = (TodoApplication) getApplication();
    m_app.m_prefs.registerOnSharedPreferenceChangeListener(this);
    this.taskBag = m_app.getTaskBag();
    m_adapter = new TaskAdapter(this, R.layout.list_item, taskBag.getTasks(), getLayoutInflater());

    // listen to the ACTION_LOGOUT intent, if heard display LoginScreen
    // and finish() current activity
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.INTENT_ACTION_ARCHIVE);
    intentFilter.addAction(Constants.INTENT_SYNC_CONFLICT);
    intentFilter.addAction(Constants.INTENT_ACTION_LOGOUT);
    intentFilter.addAction(Constants.INTENT_UPDATE_UI);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

    m_broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_ARCHIVE)) {
                // archive
                // refresh screen to remove completed tasks
                // push to remote
                //archiveTasks();
            } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_LOGOUT)) {
                taskBag.clear();
                m_app.broadcastWidgetUpdate();
                //               Intent i = new Intent(context, LoginScreen.class);
                //               startActivity(i);
                //               finish();
            } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_UPDATE_UI)) {
                updateSyncUI(intent.getBooleanExtra("redrawList", false));
            } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_SYNC_CONFLICT)) {
                handleSyncConflict();
            } else if (intent.getAction().equalsIgnoreCase(ConnectivityManager.CONNECTIVITY_ACTION)) {
                handleConnectivityChange(context);
            }

            // Taskbag might have changed, update drawer adapter
            // to reflect new/removed contexts and projects
            updateNavigationDrawer();
        }
    };

    registerReceiver(m_broadcastReceiver, intentFilter);

    setListAdapter(this.m_adapter);

    ListView lv = getListView();

    lv.setTextFilterEnabled(true);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    // Setup Navigation drawer
    m_drawerList = (ListView) findViewById(R.id.left_drawer);
    m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Set the adapter for the list view
    updateNavigationDrawer();

    SwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() {
        // Gets called whenever the user deletes an item.
        public SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) {
            m_swipeList.setEnabled(false);
            final Task task = m_adapter.getItem(position);
            m_adapter.remove(task);
            ArrayList<Task> tasks = new ArrayList<Task>();
            tasks.add(task);
            final boolean wasComplete = task.isCompleted();
            final String popupTitle = listView.getResources()
                    .getString(wasComplete ? R.string.swipe_action_unComplete : R.string.swipe_action_complete);

            if (wasComplete) {
                undoCompleteTasks(tasks, false);
            } else {
                completeTasks(tasks, false);
            }

            // Return an Undoable implementing every method
            return new SwipeDismissList.Undoable() {
                // Method is called when user undoes this deletion
                public void undo() {
                    // Reinsert item to list
                    ArrayList<Task> tasks = new ArrayList<Task>();
                    tasks.add(task);

                    if (wasComplete) {
                        completeTasks(tasks, false);
                    } else {
                        undoCompleteTasks(tasks, false);
                    }
                }

                @Override
                public String getTitle() {
                    return popupTitle;
                }
            };
        }
    };

    m_swipeList = new SwipeDismissList(lv, callback, SwipeDismissList.UndoMode.SINGLE_UNDO);
    m_swipeList.setPopupYOffset(56);
    m_swipeList.setAutoHideDelay(250);
    m_swipeList.setSwipeLayout(R.id.swipe_view);

    m_pullToRefreshAttacher = PullToRefreshAttacher.get(this);
    DefaultHeaderTransformer ht = (DefaultHeaderTransformer) m_pullToRefreshAttacher.getHeaderTransformer();
    ht.setPullText(getString(R.string.pull_to_refresh));
    ht.setRefreshingText(getString(R.string.syncing));
    m_pullToRefreshAttacher.addRefreshableView(lv, this);

    // Delegate OnTouch calls to both libraries that want to receive them
    // Don't forward swipes when swiping on the left
    lv.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            // Don't listen to gestures on the left area of the list
            // to prevent interference with the DrawerLayout
            ViewConfiguration vc = ViewConfiguration.get(view.getContext());
            int deadZoneX = vc.getScaledTouchSlop();

            if (motionEvent.getX() < deadZoneX) {
                return false;
            }

            m_pullToRefreshAttacher.onTouch(view, motionEvent);

            // Only listen to item swipes if we are not scrolling the
            // listview
            if (!mListScrolling && m_swipeList.onTouch(view, motionEvent)) {
                return false;
            }

            return false;
        }
    });

    // We must set the scrollListener after the onTouchListener,
    // otherwise it will not fire
    lv.setOnScrollListener(this);

    initializeTasks(false);

    // Show search results
    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        m_app.m_search = intent.getStringExtra(SearchManager.QUERY);
        Log.v(TAG, "Searched for " + m_app.m_search);
        m_app.storeFilters();
        setFilteredTasks(false);
    }
}

From source file:im.ene.lab.attiq.ui.activities.SearchActivity.java

@Override
  protected void onNewIntent(Intent intent) {
      if (intent.hasExtra(SearchManager.QUERY)) {
          String query = intent.getStringExtra(SearchManager.QUERY);
          if (!TextUtils.isEmpty(query)) {
              mSearchView.setQuery(query, false);
              searchFor(query);//from   ww w  .  ja  va2s  .c o m
          }
      }
  }

From source file:com.gelakinetic.mtgfam.activities.MainActivity.java

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

    /* http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock/13180285
     * /*from   w w  w .ja  v  a  2s. co  m*/
     * Open ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter.java, go to method reserveOverflow
     * Replace the original with:
     * public static boolean reserveOverflow(Context context) { return true; }
     */
    if (DEVICE_VERSION >= DEVICE_HONEYCOMB) {
        try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
        } catch (Exception ex) {
            // Ignore
        }
    }

    mFragmentManager = getSupportFragmentManager();

    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (NameNotFoundException e) {
        pInfo = null;
    }

    if (prefAdapter == null) {
        prefAdapter = new PreferencesAdapter(this);
    }

    int lastVersion = prefAdapter.getLastVersion();
    if (pInfo.versionCode != lastVersion) {
        // Clear the robospice cache on upgrade. This way, no cached values w/o foil prices will exist
        try {
            spiceManager.removeAllDataFromCache();
        } catch (NullPointerException e) {
            // eat it. tasty
        }
        showDialogFragment(CHANGELOGDIALOG);
        prefAdapter.setLastVersion(pInfo.versionCode);
        bounceMenu = lastVersion <= 15; //Only bounce if the last version is 1.8.1 or lower (or a fresh install) 
    }

    File mtr = new File(getFilesDir(), JudgesCornerFragment.MTR_LOCAL_FILE);
    File ipg = new File(getFilesDir(), JudgesCornerFragment.IPG_LOCAL_FILE);
    if (!mtr.exists()) {
        try {
            InputStream in = getResources().openRawResource(R.raw.mtr);
            FileOutputStream fos = new FileOutputStream(mtr);
            IOUtils.copy(in, fos);
        } catch (FileNotFoundException e) {
            Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage());
        } catch (IOException e) {
            Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage());
        }
    }
    if (!ipg.exists()) {
        try {
            InputStream in = getResources().openRawResource(R.raw.ipg);
            FileOutputStream fos = new FileOutputStream(ipg);
            IOUtils.copy(in, fos);
        } catch (FileNotFoundException e) {
            Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage());
        } catch (IOException e) {
            Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage());
        }
    }

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setIcon(R.drawable.sliding_menu_icon);

    SlidingMenu slidingMenu = getSlidingMenu();
    slidingMenu.setBehindWidthRes(R.dimen.sliding_menu_width);
    slidingMenu.setBehindScrollScale(0.0f);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
    slidingMenu.setShadowDrawable(R.drawable.sliding_menu_shadow);
    setSlidingActionBarEnabled(false);
    setBehindContentView(R.layout.fragment_menu);

    me = this;

    boolean autoupdate = prefAdapter.getAutoUpdate();
    if (autoupdate) {
        // Only update the banning list if it hasn't been updated recently
        long curTime = new Date().getTime();
        int updatefrequency = Integer.valueOf(prefAdapter.getUpdateFrequency());
        int lastLegalityUpdate = prefAdapter.getLastLegalityUpdate();
        // days to ms
        if (((curTime / 1000) - lastLegalityUpdate) > (updatefrequency * 24 * 60 * 60)) {
            startService(new Intent(this, DbUpdaterService.class));
        }
    }

    timerHandler = new Handler();
    registerReceiver(endTimeReceiver, new IntentFilter(RoundTimerFragment.RESULT_FILTER));
    registerReceiver(startTimeReceiver, new IntentFilter(RoundTimerService.START_FILTER));
    registerReceiver(cancelTimeReceiver, new IntentFilter(RoundTimerService.CANCEL_FILTER));

    updatingDisplay = false;
    timeShowing = false;

    getSlidingMenu().setOnOpenedListener(new OnOpenedListener() {

        @Override
        public void onOpened() {
            // Close the keyboard if the slidingMenu is opened
            hideKeyboard();
        }
    });

    setContentView(R.layout.fragment_activity);
    getSupportFragmentManager().beginTransaction().replace(R.id.frag_menu, new MenuFragment()).commit();

    showOnePane();
    if (findViewById(R.id.middle_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present, then the
        // activity should be in two-pane mode.
        mIsATablet = true;
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mThreePane = true;
        } else {
            mThreePane = false;
        }
    } else {
        mThreePane = false;
        mIsATablet = false;
        if (findViewById(R.id.middle_container) != null) {
            findViewById(R.id.middle_container).setVisibility(View.GONE);
            findViewById(R.id.right_container).setVisibility(View.GONE);
        }
    }

    Intent intent = getIntent();

    if (savedInstanceState == null) {
        try {
            if (intent.getAction().equals(Intent.ACTION_VIEW)) { //apparently this can NPE on 4.3. because why not. if we catch it, launch the default frag
                // handles a click on a search suggestion; launches activity to show word
                Uri u = intent.getData();
                long id = Long.parseLong(u.getLastPathSegment());

                // add a fragment
                Bundle args = new Bundle();
                args.putBoolean("isSingle", true);
                args.putLong("id", id);
                CardViewFragment rlFrag = new CardViewFragment();
                rlFrag.setArguments(args);

                attachSingleFragment(rlFrag, "left_frag", false, false);
                showOnePane();
                hideKeyboard();
            } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
                boolean consolidate = prefAdapter.getConsolidateSearch();
                String query = intent.getStringExtra(SearchManager.QUERY);
                SearchCriteria sc = new SearchCriteria();
                sc.Name = query;
                sc.Set_Logic = (consolidate ? CardDbAdapter.FIRSTPRINTING : CardDbAdapter.ALLPRINTINGS);

                // add a fragment
                Bundle args = new Bundle();
                args.putBoolean(SearchViewFragment.RANDOM, false);
                args.putSerializable(SearchViewFragment.CRITERIA, sc);
                if (mIsATablet) {
                    SearchViewFragment svFrag = new SearchViewFragment();
                    svFrag.setArguments(args);
                    attachSingleFragment(svFrag, "left_frag", false, false);
                } else {
                    ResultListFragment rlFrag = new ResultListFragment();
                    rlFrag.setArguments(args);
                    attachSingleFragment(rlFrag, "left_frag", false, false);
                }
                hideKeyboard();
            } else if (intent.getAction().equals(ACTION_FULL_SEARCH)) {
                attachSingleFragment(new SearchViewFragment(), "left_frag", false, false);
                showOnePane();
            } else if (intent.getAction().equals(ACTION_WIDGET_SEARCH)) {
                attachSingleFragment(new SearchWidgetFragment(), "left_frag", false, false);
                showOnePane();
            } else if (intent.getAction().equals(ACTION_ROUND_TIMER)) {
                attachSingleFragment(new RoundTimerFragment(), "left_frag", false, false);
                showOnePane();
            } else {
                launchDefaultFragment();
            }
        } catch (NullPointerException e) {
            launchDefaultFragment();
        }
    }
}

From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();

    if (mGameTitle != null && info.targetView.getTag() instanceof ViewHolder) {
        ViewHolder vh = (ViewHolder) info.targetView.getTag();

        switch (menuItem.getItemId()) {
        case R.id.menu_google_trophies:
            Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
            searchIntent.putExtra(SearchManager.QUERY,
                    getString(R.string.google_trophy_f, mGameTitle, vh.title.getText()));

            startActivity(searchIntent);
            return true;
        }//from  w  ww  .j  av a  2  s  .  co  m
    }

    return super.onContextItemSelected(menuItem);
}

From source file:com.akop.bach.fragment.xboxlive.GamesFragment.java

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();

    if (info.targetView.getTag() instanceof ViewHolder) {
        ViewHolder vh = (ViewHolder) info.targetView.getTag();

        switch (menuItem.getItemId()) {
        case R.id.menu_game_overview:

            GameOverview.actionShow(getActivity(), mAccount, vh.gameUrl);
            return true;

        case R.id.google_achievements:

            Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
            searchIntent.putExtra(SearchManager.QUERY,
                    getString(R.string.google_achievements_f, vh.title.getText()));
            startActivity(searchIntent);

            return true;

        case R.id.menu_visit_webpage:

            Intent wwwIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(vh.gameUrl));
            startActivity(wwwIntent);/*ww  w.  ja  va 2s . c o m*/

            return true;
        }
    }

    return super.onContextItemSelected(menuItem);
}

From source file:net.eledge.android.europeana.gui.activity.SearchActivity.java

private void handleIntent(Intent intent) {
    String query = null;/*w  ww.j a v  a  2s .  c o  m*/
    String[] qf = null;
    if (intent != null) {

        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            query = intent.getStringExtra(SearchManager.QUERY);
            qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY));
        } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage msg = (NdefMessage) parcelables[0];
            Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload()));
            query = uri.getQueryParameter("query");
            qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            query = intent.getDataString();
            if (!TextUtils.isEmpty(query)) {
                if (StringUtils.contains(query, "europeana.eu/")) {
                    Uri uri = Uri.parse(query);
                    query = uri.getQueryParameter("query");
                    qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
                }
            }
        } else {
            // no search action recognized? end this activity...
            closeSearchActivity();
        }
        if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) {
            runningSearch = query;
            if (StringArrayUtils.isNotBlank(qf)) {
                searchController.newSearch(this, query, qf);
            } else {
                searchController.newSearch(this, query);
            }
            getSupportActionBar().setTitle(searchController.getSearchTitle(this));
        }
    }
}

From source file:com.tt.jobtracker.MainActivity.java

private void handleIntent(Intent intent) {
    setContentView(R.layout.activity_main);
    SetNavigationDrawer();/*from  w  w  w  . j av  a 2 s.  c  o  m*/

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        SearchText = intent.getStringExtra(SearchManager.QUERY);
    } else {
        SearchText = "";
    }
}

From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java

/**
 * @param title/*from  w  w w .ja  va  2  s  . com*/
 *            The program title to find similar programs for
 */
public void openSimilar(String title) {
    Log.e("dreamDroid", "title: " + title);
    Intent intent = new Intent(this, SearchEpgActivity.class);
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(SearchManager.QUERY, title);
    startActivity(intent);
}

From source file:com.necisstudio.highlightgoal.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        searchview.setQuery(query, false);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        iddrawer = 20;/*w  ww .ja  v a  2  s .  co m*/
        imgLogo.setImageResource(0);
        txtTitle.setText(searchview.getQuery().toString());
        fList = new ArrayList<Fragment>();
        List<Fragment> fragments = getFragments(
                HighlightLatestFragment.newInstance(searchview.getQuery().toString()),
                KlasementLigaFragment.newInstance("inggris"),
                ScheduleLigaLatestFragment.newInstance(searchview.getQuery().toString()));
        adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
        final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        tabHost = (TabLayout) findViewById(R.id.materialTabHost);
        pager.setAdapter(adapter_viewPager);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        tabHost.setupWithViewPager(pager);
        tabHost.getTabAt(0).setText("Highlight");
        tabHost.getTabAt(1).setText("Schedule");
    }
}