Example usage for android.app SearchManager getSearchableInfo

List of usage examples for android.app SearchManager getSearchableInfo

Introduction

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

Prototype

public SearchableInfo getSearchableInfo(ComponentName componentName) 

Source Link

Document

Gets information about a searchable activity.

Usage

From source file:com.ht.app.RestaurantsActivity.java

@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);

    mMenu = menu;/*www  . j  a v  a2 s.  c  om*/

    MenuItem searchMenuItem = (MenuItem) menu.findItem(R.id.action_search);
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            // mToolbar.setIcon(android.R.color.transparent);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            return true;
        }
    });

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));

    // Assumes current activity is the searchable activity
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    mSearchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

    // Style search widget and suggestion list
    LinearLayout linearLayout1 = (LinearLayout) mSearchView.getChildAt(0);
    LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
    LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
    AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
    autoComplete.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                hideSearchWidget();
            }
        }
    });

    autoComplete.setTextColor(Color.WHITE);
    autoComplete.setHintTextColor(Color.WHITE);
    autoComplete.setDropDownBackgroundResource(R.color.app_red_color);

    return true;
}

From source file:gov.cdc.epiinfo.RecordList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = new SearchView(this);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/*from   w  w  w . j a  v  a 2 s . co  m*/
        public boolean onQueryTextSubmit(String searchTerm) {

            try {
                mDbHelper.fetchTopOne();

                String query = BuildQuery(searchTerm);

                String fieldName1;
                String fieldName2;
                String fieldName3;
                String[] from = new String[1];
                int[] to = new int[1];

                if (formMetadata.DataFields.size() > 2) {

                    fieldName1 = formMetadata.DataFields.get(0).getName();
                    fieldName2 = formMetadata.DataFields.get(1).getName();
                    fieldName3 = formMetadata.DataFields.get(2).getName();
                    mNotesCursor = mDbHelper.fetchWhere(fieldName1, fieldName2, fieldName3, query);
                    from = new String[] { "_id", "columnName1", fieldName1, "columnName2", fieldName2,
                            "columnName3", fieldName3, "_syncStatus" };
                    to = new int[] { R.id.text1, R.id.header2, R.id.text2, R.id.header3, R.id.text3,
                            R.id.header4, R.id.text4, R.id.hiddenText };
                } else if (formMetadata.DataFields.size() == 2) {
                    fieldName1 = formMetadata.DataFields.get(0).getName();
                    fieldName2 = formMetadata.DataFields.get(1).getName();
                    mNotesCursor = mDbHelper.fetchWhere(fieldName1, fieldName2, query);
                    from = new String[] { "_id", "columnName1", fieldName1, "columnName2", fieldName2,
                            "_syncStatus" };
                    to = new int[] { R.id.text1, R.id.header2, R.id.text2, R.id.header3, R.id.text3,
                            R.id.hiddenText };
                } else if (formMetadata.DataFields.size() == 1) {
                    fieldName1 = formMetadata.DataFields.get(0).getName();
                    mNotesCursor = mDbHelper.fetchWhere(fieldName1, query);
                    from = new String[] { "_id", "columnName1", fieldName1, "_syncStatus" };
                    to = new int[] { R.id.text1, R.id.header2, R.id.text2, R.id.hiddenText };
                }

                startManagingCursor(mNotesCursor);
                CustomListAdapter notes = new CustomListAdapter(self, R.layout.line_list_row, mNotesCursor,
                        from, to);
                lineListFragment.setListAdapter(notes);

            } catch (Exception ex) {
                fillData();
            }

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {

            if (newText.equals("")) {
                fillData();
            }

            return false;
        }
    });

    mnuSearch = menu.add(0, SEARCH_ID, 0, R.string.menu_search);
    mnuSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mnuSearch.setActionView(searchView);
    mnuSearch.setIcon(gov.cdc.epiinfo.R.drawable.action_search);

    MenuItem mnuQR = menu.add(0, QR_ID, 1, R.string.menu_barcode);
    mnuQR.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    mnuQR.setIcon(gov.cdc.epiinfo.R.drawable.qrcode_scan);

    MenuItem mnuCloud = menu.add(0, CLOUD_ID, 2, R.string.menu_cloud_sync);
    mnuCloud.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    MenuItem mnuSync = menu.add(0, SYNC_ID, 3, R.string.menu_sync_file);
    mnuSync.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    MenuItem mnuDeleteAll = menu.add(0, DELETE_ALL_ID, 4, R.string.menu_delete_all);
    mnuDeleteAll.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    if (fkeyGuid == null || fkeyGuid.length() == 0) {
        mnuSetDefault = menu.add(0, SET_DEFAULT_ID, 5, R.string.set_default_form);
        mnuSetDefault.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        mnuExitDefault = menu.add(0, EXIT_DEFAULT_MODE_ID, 5, R.string.exit_default_form);
        mnuExitDefault.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        if (AppManager.getDefaultForm().equals("")) {
            mnuSetDefault.setVisible(true);
            mnuExitDefault.setVisible(false);
        } else {
            mnuSetDefault.setVisible(false);
            mnuExitDefault.setVisible(true);
        }
    }

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    if (sharedPref.getString("cloud_service", "").equals("Box")) {
        mnuBoxSignin = menu.add(0, BOX_SIGNIN_ID, 6, R.string.box_signin);
        mnuBoxSignin.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        mnuBoxSignout = menu.add(0, BOX_SIGNOUT_ID, 6, R.string.box_signout);
        mnuBoxSignout.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        if (BoxClient.isAuthenticated(this)) {
            mnuBoxSignout.setVisible(true);
            mnuBoxSignin.setVisible(false);
        } else {
            mnuBoxSignout.setVisible(false);
            mnuBoxSignin.setVisible(true);
        }
    }

    MenuItem mnuHelp = menu.add(1, HELP_ID, 7, R.string.menu_help);
    mnuHelp.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return true;
}

From source file:com.inmovilizaciones.activity.ListarInmovilizacionesActivity.java

public void configurarBuscador(Menu menu) {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.menu_buscar);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(false);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        public boolean onQueryTextSubmit(String query) {
            realizarBusqueda(query);/*from ww w  .ja  v a 2  s .c  o m*/
            return true;
        }

        public boolean onQueryTextChange(final String s) {
            return false;
        }
    });
}

From source file:com.benlinskey.greekreference.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Only show items in the action bar relevant to this screen if the drawer is not showing.
    // Otherwise, let the drawer decide what to show in the action bar.
    if (mNavigationDrawerFragment.isDrawerOpen()) {
        return super.onCreateOptionsMenu(menu);
    }/*from  w w  w.  j  a  va2  s . c om*/

    // Inflate the options menu from XML. We have to handle the menu here rather than in the
    // fragment so that we can hide them when the navigation drawer is open.
    if (mMode.isLexiconMode()) {
        getMenuInflater().inflate(R.menu.lexicon_menu, menu);
        setLexiconFavoriteIcon(menu);

        // Get the SearchView and set the searchable configuration.
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
        //SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

        restoreActionBar();
        return super.onCreateOptionsMenu(menu);
    } else if (mMode.isSyntaxMode()) {
        getMenuInflater().inflate(R.menu.syntax_menu, menu);
        setSyntaxBookmarkIcon(menu);
        restoreActionBar();
        return super.onCreateOptionsMenu(menu);
    } else {
        throw new IllegalStateException("Invalid mode");
    }
}

From source file:com.svpino.longhorn.fragments.StockListFragment.java

@TargetApi(14)
@Override/*from   w  w w. j  av a2s . c o  m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_stock_list, menu);
    this.searchMenuItem = menu.findItem(R.id.menu_item_add);

    if (isIceCreamSandwichOrLater()) {
        SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
        this.searchView = (SearchView) this.searchMenuItem.getActionView();
        this.searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        this.searchView.setSubmitButtonEnabled(false);
        this.searchView.setIconifiedByDefault(true);

        final ShareActionProvider shareActionProvider = (ShareActionProvider) menu
                .findItem(R.id.menu_item_share).getActionProvider();
        shareActionProvider.setShareIntent(getDefaultShareIntent(null));
        shareActionProvider.setOnShareTargetSelectedListener(new OnShareTargetSelectedListener() {

            @Override
            public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
                Intent defaultShareIntent = getDefaultShareIntent(null);
                shareActionProvider.setShareIntent(defaultShareIntent);
                return false;
            }
        });
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from   www .j  a v a 2  s. com
    inflater.inflate(R.menu.global, menu);
    MenuItem item = menu.findItem(R.id.graph);
    MenuItem log = menu.findItem(R.id.log);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    item.setVisible(false);
    log.setVisible(true);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false);
    SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered

            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (searchMenuItem != null) {
                searchMenuItem.collapseActionView();
                // this is your adapter that will be filtered
                if (mLeDeviceListAdapter != null) {
                    searchEnabled = true;
                    searchDeviceList(query);
                }
            }
            return false;

        }
    };
    searchView.setOnQueryTextListener(textChangeListener);
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.videolan.vlc.gui.MyFragment.java

/** Create menu from XML
 *//*from   ww  w.j  a v a 2  s.  c om*/
@TargetApi(Build.VERSION_CODES.FROYO)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mMenu = menu;
    /* Note: on Android 3.0+ with an action bar this method
     * is called while the view is created. This can happen
     * any time after onCreate.
     */
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.media_library, menu);

    if (AndroidUtil.isFroyoOrLater()) {
        SearchManager searchManager = (SearchManager) VLCApplication.getAppContext()
                .getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setQueryHint(getString(R.string.search_hint));
        SearchSuggestionsAdapter searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, null);
        searchSuggestionsAdapter.setFilterQueryProvider(this);
        //  mSearchView.setIconifiedByDefault(false);//(?ture)
        //mSearchView.setSearchViewBackground(mSearchView);
        //setSearchViewBackground(mSearchView);
        mSearchView.setSuggestionsAdapter(searchSuggestionsAdapter);
    } else
        menu.findItem(R.id.ml_menu_search).setVisible(false);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.hangulo.powercontact.ContactsListFragment.java

void setupSearchView() {

    // Retrieves the system search manager service
    final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    // Retrieves the SearchView from the search menu item

    if (mSearchView == null)
        return;//from  w  w w.jav a  2  s.co  m

    // Assign searchable info to SearchView

    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    //      mSearchView.setSubmitButtonEnabled(true); // enable subit button
    mSearchView.setIconifiedByDefault(false);
    mSearchView.setIconified(false);
    mSearchView.setFocusable(false);
    mSearchView.clearFocus();

    // text focus ...
    mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                if (!mTwoPane && !mCallback.isExpandedListViewFragment())
                    mCallback.launchSearchFragment(true); // ?  . ? ? .
            } else {
                if (!mTwoPane & mCallback.isExpandedListViewFragment()) {
                    mCallback.launchSearchFragment(false); // ? ?
                }
            }
        }
    });

    // Set listeners for SearchView
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String queryText) {
            mSearchView.clearFocus();

            if (!mTwoPane & mCallback.isExpandedListViewFragment()) {
                mCallback.launchSearchFragment(false); // ? ?
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Updates
            // the search filter, and restarts the loader to do a new query
            // using the new search string.
            //    isSearchMode=true;

            // if first String starts with "@@Search:" then wait until input complete
            //  ? @@Search: ...  ? .
            // @@Search:198.20123232,-111.20232323  ? .
            //
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

            // Don't do anything if the filter is empty
            if (mSearchKeyword == null && newFilter == null) {
                return true;
            }
            // Don't do anything if the new filter is the same as the current filter
            if (mSearchKeyword != null && mSearchKeyword.equals(newFilter)) {
                return true;
            }

            // Updates current filter to new filter
            //                mPreviousSearchKeyword = mSearchKeyword; // ? ...... ?  ? ??   ?  .

            if (mSearchKeyword != null && mSearchKeyword.startsWith("@@")) //  @@ , @@ ??...
                if (!mSearchKeyword.endsWith("@@"))
                    return true;

            // ?  . @@  ?  .  ?  String search .
            mSearchKeyword = newFilter; //  ...? ?.
            getActivity().getSupportLoaderManager().restartLoader(Constants.CONTACTLIST_LOADER, null,
                    ContactsListFragment.this);

            return true;
        }
    });

}

From source file:org.awesomeapp.messenger.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));

    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setIconifiedByDefault(false);

        SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
            public boolean onQueryTextChange(String query) {
                mConversationList.doSearch(query);
                return true;
            }//  www.  j ava  2s.c om

            public boolean onQueryTextSubmit(String query) {
                mConversationList.doSearch(query);

                return true;
            }
        };

        mSearchView.setOnQueryTextListener(queryTextListener);

        mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                mConversationList.doSearch(null);
                return false;
            }
        });
    }

    MenuItem mItem = menu.findItem(R.id.menu_lock_reset);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    if (!settings.contains(ImApp.PREFERENCE_KEY_TEMP_PASS))
        mItem.setVisible(true);

    return true;
}

From source file:de.fhb.mi.paperfly.user.FriendListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (menu != null) {
        inflater.inflate(R.menu.user_friends, menu);
    }//www  .  j  a v  a2  s. c  om

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search_user).getActionView();

    // Get the menu item from the action bar
    MenuItem menuItem = menu.findItem(R.id.action_search_user);
    menuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            Log.d(TAG, "Search deactivated. Unlocking drawers.");
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            Log.d(TAG, "Search activated. Locking drawers.");
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            return true;
        }
    });
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}