Example usage for android.widget SearchView setSearchableInfo

List of usage examples for android.widget SearchView setSearchableInfo

Introduction

In this page you can find the example usage for android.widget SearchView setSearchableInfo.

Prototype

public void setSearchableInfo(SearchableInfo searchable) 

Source Link

Document

Sets the SearchableInfo for this SearchView.

Usage

From source file:com.numenta.taurus.instance.InstanceListActivity.java

private void configureSearchView(@NonNull final SearchView searchView) {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Handle query events
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//  www . j av  a 2s.com
        public boolean onQueryTextSubmit(String query) {
            // Hide Keyboard on submit
            InputMethodManager imm = (InputMethodManager) searchView.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
            }

            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Filter list as the user types
            _listFragment.applyFilter(newText);
            return true;
        }
    });

    // FIXME: Android does not support styling the search view across all versions.
    // For now, "peek" into internal API to make the appropriate changes to the SearchView.
    // In the future we should use the official android API to customize the SearchView widget.
    // See android.R.layout.search_view for the layout we are "peeking". It is no guarantee it
    // will work on all public android versions and/or OEM customizations.
    // This HACK is only valid for the POC phase. We should find a better solution before releasing
    Resources resources = searchView.getResources();

    // Style search box and text
    int searchPlateId = resources.getIdentifier("android:id/search_plate", null, null);
    View searchPlate = searchView.findViewById(searchPlateId);
    if (searchPlate != null) {
        int searchTextId = resources.getIdentifier("android:id/search_src_text", null, null);
        TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
        if (searchText != null) {
            searchPlate.setBackgroundResource(android.R.drawable.editbox_background);
            searchText.setPadding(5, 0, 0, 0);
            searchText.setTextColor(Color.BLACK);
            searchText.setHintTextColor(Color.LTGRAY);
        }
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.HomeActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*  w  ww  . j a v a 2 s . co m*/
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    mOptionsMenu = menu;
    getMenuInflater().inflate(R.menu.home, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }
    }

    return true;
}

From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void handleSearchForSdkAbove11() {

    MenuItem menuItem = menu.findItem(R.id.search);
    menuItem.setVisible(false);//w  ww  .ja  v  a2 s .c  o m

    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView();

    search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));

    search.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String query) {
            loadData(query);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String arg0) {
            return false;
        }

    });

}

From source file:com.wearapp.PickFriendsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //Log.w(TAG, "IN createing Search friends OptionsMenu");
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(new ComponentName("com.wearapp", "com.wearapp.HistoryActivity")));
    //searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setQueryHint(getResources().getString(R.string.search_friend_hint));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/*from  w  w w  . j a v  a2 s .  c o  m*/
        public boolean onQueryTextSubmit(String query) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean onQueryTextChange(String keyword) {
            // TODO Auto-generated method stub         

            selectedUsers.addAll(selectedUsers_temp1);
            //TODO need update FacebookSDK to 2.6 version 
            friendPickerFragment.setSelection(selectedUsers);

            searchterm = keyword;
            friendPickerFragment.setFilter(new GraphObjectFilter<GraphUser>() {
                @Override
                public boolean includeItem(GraphUser graphObject) {
                    // TODO Auto-generated method stub                               
                    Pattern p = Pattern.compile(searchterm, Pattern.CASE_INSENSITIVE);
                    Matcher m = p.matcher(graphObject.getName());
                    if (m.find()) {
                        return true;
                    }
                    return false;
                }
            });

            friendPickerFragment.loadData(true);

            return false;
        }

    });

    return true;
}

From source file:com.hybris.mobile.app.commerce.activity.MainActivity.java

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

    // HockeyApp feedback
    menu.findItem(R.id.menu_feedback).setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override//  w  w w.  jav a  2s  . co m
        public boolean onMenuItemClick(MenuItem item) {
            HockeyAppUtils.showFeedbackActivity(MainActivity.this);
            return true;
        }
    });

    // Sync Settings
    menu.findItem(R.id.menu_settings).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            return true;
        }
    });

    // Barcode scanner
    menu.findItem(R.id.menu_scanner).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            CommerceApplication.getScannerHelper().launch(MainActivity.this, MainActivity.this);
            return true;
        }
    });

    // Cart items
    MenuItem item = menu.findItem(R.id.b2b_icon_cart);

    if (mCartDrawer != null) {

        // Onclick to open/hide cart menu
        item.getActionView().setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mDrawerLayout != null) {
                    mDrawerLayout.closeDrawers();
                }
                if (mCartDrawer.isDrawerOpen(mCartDrawer.getChildAt(1))) {
                    mCartDrawer.closeDrawer(mCartDrawer.getChildAt(1));
                } else {
                    mCartDrawer.openDrawer(mCartDrawer.getChildAt(1));
                }
            }
        });
    } else {
        menu.removeItem(R.id.b2b_icon_cart);
    }

    // Search component
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.b2b_icon_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    return true;
}

From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void loadData(String query) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        // Load data from list to cursor
        String[] columns = new String[] { "_id", "text", "cid" };
        Object[] temp = new Object[] { 0, "name", -1l };

        MatrixCursor cursor = new MatrixCursor(columns);

        int index = 0;
        for (int i = 0; i < items.size(); i++) {
            if (query == null || items.get(i).getName().contains(query.trim())) {
                temp[0] = index;/*  w  ww .  j  a v a 2  s. c om*/
                temp[1] = items.get(i).getName();
                temp[2] = items.get(i).getId();
                cursor.addRow(temp);
                index++;
            }
        }

        temp[0] = index;
        temp[1] = "     " + " \"" + query + "\" ";
        temp[2] = query.trim();
        cursor.addRow(temp);

        SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

        final SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView();

        search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
        ActionBarSearchAdapter adapter = new ActionBarSearchAdapter(this, cursor, this, search);
        search.setSuggestionsAdapter(adapter);

    }

}

From source file:com.conferenceengineer.android.iosched.ui.tablet.SessionsSandboxMultiPaneActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }// ww w . j a v a 2 s  .  com
    }
    return true;
}

From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//from   ww  w  .  ja v  a2  s . c  o  m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.contact_list_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (isSearchResultView) {
        searchItem.setVisible(false);
    }
    if (ApiHelper.hasHoneycomb()) {
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);
        final SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                if (searchString == null && newFilter == null) {
                    return true;
                }
                if (searchString != null && searchString.equals(newFilter)) {
                    return true;
                }
                searchString = newFilter;
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (ApiHelper.hasICS()) {
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    if (!TextUtils.isEmpty(searchString)) {
                        onSelectionCleared();
                    }
                    searchString = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (searchString != null) {
            final String savedSearchTerm = searchString;

            // Expands the search menu item
            if (ApiHelper.hasICS()) {
                searchItem.expandActionView();
            }
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:ua.org.gdg.devfest.iosched.ui.HomeActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from www .j  a  v a2  s.c o  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    mOptionsMenu = menu;
    getMenuInflater().inflate(R.menu.home, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }
    }
    return true;
}

From source file:com.conferenceengineer.android.iosched.ui.HomeActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from   ww w.  j av  a 2 s .  c  om
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    mOptionsMenu = menu;
    getMenuInflater().inflate(R.menu.home, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }
    }

    if (!getResources().getBoolean(R.bool.has_conference_feedback_enabled)) {
        menu.removeItem(R.id.menu_feedback);
    }

    return true;
}