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.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//from w  ww .j  a  v  a  2 s.  c  om
        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.andrada.sitracker.ui.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView view = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView = view;//from   w  w w. j a  v  a 2s .  co  m
        if (view == null) {
            LOGW(TAG, "Could not set up search view, view is null.");
        } else {
            view.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            view.setIconified(false);
            view.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    view.clearFocus();
                    if (mAuthorsFragment != null) {
                        mAuthorsFragment.requestQueryUpdate(s, mCurrentSearchType);
                    }
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    mQuery = s;
                    return true;
                }
            });
            view.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    finish();
                    return false;
                }
            });

            ShowcaseView.Builder bldr = new ShowcaseView.Builder(this).setTarget(new ViewTarget(mSearchView))
                    .setContentTitle(getString(R.string.showcase_search_title))
                    .setContentText(getString(R.string.showcase_search_detail))
                    .setStyle(R.style.ShowcaseView_Base);
            if (!BuildConfig.DEBUG) {
                bldr.singleShot(Constants.SHOWCASE_ADD_AUTHORS_SEARCH_SHOT_ID);
            }
            bldr.build();

            if (!TextUtils.isEmpty(mQuery)) {
                view.setQuery(mQuery, false);
            }
        }
    }
    return true;
}

From source file:com.teocci.utubinbg.MainActivity.java

/**
 * Options menu in action bar/*  w ww .  j  a va2s  . c  o 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, R.layout.dropdown_menu, 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(String suggestion) {
            // check network connection. If not available, do not query.
            // this also disables onSuggestionClick triggering
            if (suggestion.length() > 2) { //make suggestions after 3rd letter

                if (networkConf.isNetworkAvailable()) {

                    new JsonAsyncTask(new JsonAsyncTask.AsyncResponse() {
                        @Override
                        public void processFinish(ArrayList<String> result) {
                            suggestions.clear();
                            suggestions.addAll(result);
                            String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 };
                            MatrixCursor cursor = new MatrixCursor(columns);

                            for (int i = 0; i < result.size(); i++) {
                                String[] tmp = { Integer.toString(i), result.get(i) };
                                cursor.addRow(tmp);
                            }
                            suggestionAdapter.swapCursor(cursor);

                        }
                    }).execute(suggestion);
                    return true;
                }
            }
            return false;
        }
    });

    return true;
}

From source file:ufms.br.com.ufmsapp.fragment.DisciplinasFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getActivity().getMenuInflater().inflate(R.menu.disciplina_list_menu, menu);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search_disciplina).getActionView();
    searchView.setOnQueryTextListener(this);
    searchView.setQueryHint(getString(R.string.txt_busca));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}

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;/*from w  w  w.  ja v  a  2s .  co  m*/
                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.kaszubski.kamil.emmhelper.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    if (fragmentManager.findFragmentById(R.id.container) != null) {
        switch (fragmentManager.findFragmentById(R.id.container).getTag()) {
        case Constants.FRAGMENT_SEARCH:
            longTextTitleMode(false);/* w  w w  .  j av a 2s.c  o m*/
            setTitle(getString(R.string.application_list));
            getMenuInflater().inflate(R.menu.fragment_search, menu);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryHint(getString(R.string.query_hint));

            progressDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
            progressDialog.setMessage(getString(R.string.loading_packages));
            progressDialog.setIndeterminate(true);
            progressDialog.setCancelable(false);
            progressDialog.show();

            new LoadPackages().execute();

            break;
        case Constants.FRAGMENT_IP_FIND:
            longTextTitleMode(false);
            setTitle(getString(R.string.hostname_ips));
            getMenuInflater().inflate(R.menu.fragment_ip_finder, menu);
            break;
        case Constants.FRAGMENT_EXPORT:
            longTextTitleMode(true);
            break;
        case Constants.FRAGMENT_LICENSE_CHECK:
            longTextTitleMode(false);
            setTitle(getString(R.string.check_elm_key));
            break;
        }
    }
    return true;
}

From source file:com.stoneapp.ourvlemoodle2.fragments.CourseContentFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Context context = getActivity();
        SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);

        searchitem = menu.findItem(R.id.action_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchitem); // set up search view

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

        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint("Search name"); // sets the hint text

        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override// w ww .j a  va2s. co m
            public boolean onClose() {
                searchView.setQuery("", false); // clears text from search view
                return true;
            }
        });
    }
}

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(//from  w ww . ja  va  2s .co m
            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
        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.klinker.android.twitter.activities.search.SearchPager.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_activity, menu);

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

    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) searchView.findViewById(searchImgId);
    view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light
            : R.drawable.ic_action_search_dark);

    return true;/*from  w ww . j av  a  2 s.c o  m*/
}

From source file:org.openmrs.mobile.activities.FindPatientsActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from   www .jav a2 s. c o  m
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.find_patients_menu, menu);

    mFindPatientMenuItem = menu.findItem(R.id.actionSearch);
    if (!OpenMRS.getInstance().getOnlineMode()) {
        mFindPatientMenuItem.setEnabled(false);
        mFindPatientMenuItem.getIcon().setAlpha(ApplicationConstants.DISABLED_ICON_ALPHA);
    } else {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

        SearchView findPatientView;

        if (OpenMRS.getInstance().isRunningHoneycombVersionOrHigher()) {
            findPatientView = (SearchView) mFindPatientMenuItem.getActionView();
        } else {
            findPatientView = (SearchView) MenuItemCompat.getActionView(mFindPatientMenuItem);
        }

        SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
        findPatientView.setSearchableInfo(info);
    }
    return true;
}