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:net.vivekiyer.GAL.CorporateAddressBook.java

@TargetApi(11)
@Override/*from   w w  w .  j  av  a  2 s. co  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    // Get the SearchView and set the searchable configuration for Honeycomb
    // and above
    if (!Utility.isPreHoneycomb()) {
        final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final ComponentName component = getComponentName();
        final SearchableInfo searchableInfo = searchManager.getSearchableInfo(component);
        searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setSearchableInfo(searchableInfo);

        //this.onSearchRequested();
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    if (isLight == true) {
        inflater.inflate(R.menu.gallery, menu);
    } else {/*  w w w. j  a  v  a  2 s .  com*/
        inflater.inflate(R.menu.gallery_dark, menu);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            search(query);
            // First image toast
            String firstResult;
            if (numSearchResults == 0) {
                firstResult = "No results found for  " + query + ".";
            } else {
                firstResult = "The first image result is titled " + tagList[0];
            }

            SpannableString s = new SpannableString(firstResult);
            s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                search("");
            }

            return true;
        }

        public void search(String query) {
            // hide keyboard
            InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            // Fetch the {@link LayoutInflater} service so that new views can be created
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            // Find the {@link GridView} that was already defined in the XML layout
            GridView gridView = (GridView) findViewById(R.id.grid);
            try {
                gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query)));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    return true;
    //return super.onCreateOptionsMenu(menu);
}

From source file:fr.cph.chicago.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    this.mMenu = menu;
    getMenuInflater().inflate(R.menu.main, menu);
    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return super.onCreateOptionsMenu(menu);
}

From source file:de.tap.easy_xkcd.Activities.SearchResultsActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from   ww w .  j  a  v a  2 s. c  o m
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (task != null) {
                task.cancel(true);
            }
            task = new searchTask();
            task.execute(newText);
            return false;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    return true;
}

From source file:edumsg.edumsg_android_app.MainActivity.java

/**
 *
 * The onCreate method first retrieves the sessionId and username from the parent {@link android.content.Intent},
 * which is either created from a {@link LoginFragment} or a {@link RegisterFragment}. Afterwards,
 * it configures the action bar and performs view look-ups for the action bar buttons, followed
 * by setting the onClick listeners for the action bar buttons. Finally, it initializes the
 * properties, sets the onRefresh listener for the swipe refresh layout, and calls the method
 * {@link MainActivity#getFeed()}.//w w  w.  j  a v  a 2  s .  c  o m
 *
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sessionId = getIntent().getExtras().getString("sessionId");
    username = getIntent().getExtras().getString("username");
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_main, null);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(actionBarLayout);
    ImageButton homeButton = ButterKnife.findById(actionBarLayout, R.id.btn_home);
    final ImageButton searchButton = ButterKnife.findById(actionBarLayout, R.id.btn_search);
    ImageButton createButton = ButterKnife.findById(actionBarLayout, R.id.btn_create);
    ImageButton navButton = ButterKnife.findById(actionBarLayout, R.id.btn_nav);

    final ViewGroup searchLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_search, null);
    final SearchView searchView = ButterKnife.findById(searchLayout, R.id.search);
    final ImageButton backBtn = ButterKnife.findById(searchLayout, R.id.btn_back);

    homeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    searchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionBar.setCustomView(searchLayout);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager
                    .getSearchableInfo(new ComponentName(MainActivity.this, SearchResultsActivity.class)));
            searchView.setQuery("", false);
            searchView.setIconified(false);
            searchView.setFocusable(true);
            searchView.requestFocusFromTouch();
        }
    });

    backBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionBar.setCustomView(actionBarLayout);
            InputMethodManager imm = (InputMethodManager) getApplicationContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(
                    MainActivity.this.getWindow().getDecorView().getRootView().getWindowToken(), 0);
        }
    });

    createButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

            final EditText input = new EditText(MainActivity.this);
            input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
            input.setLines(4);
            input.setSingleLine(false);
            input.setBackgroundDrawable(null);
            builder.setView(input);
            builder.setPositiveButton("Tweet", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createTweet(input.getText().toString());
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            final AlertDialog dialog = builder.create();

            dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialogInterface) {
                    Button posBtn = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
                    posBtn.setBackgroundColor(cPrimary);
                    posBtn.setTextColor(Color.WHITE);
                    final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
                    int pixels = (int) (10 * scale + 0.5f);
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    layoutParams.setMargins(0, 0, pixels, 0);
                    posBtn.setLayoutParams(layoutParams);
                    Button negBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                    negBtn.setBackgroundColor(cPrimary);
                    negBtn.setTextColor(Color.WHITE);
                }
            });
            dialog.show();
        }
    });

    navButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment instanceof NavigationFragment)
                        return;
                }
            }
            NavigationFragment navigationFragment = new NavigationFragment();
            //                Bundle bundle = new_user Bundle();
            //                bundle.putInt("userId", userId);
            //                mainActivityFragment.setArguments(bundle);
            fragmentManager.beginTransaction().add(android.R.id.content, navigationFragment)
                    .addToBackStack("nav").commit();
            //                logout();
            //                launchMessages();
            //                Intent intent = new_user Intent(MainActivity.this, ProfileActivity.class);
            //                intent.putExtra("username", getUsername());
            //                intent.putExtra("name", getName());
            //                intent.putExtra("avatar_url", getAvatar_url());
            //                intent.putExtra("bio", getBio());
            //                intent.putExtra("creatorId", getUserId());
            //                intent.putExtra("userId", getUserId());
            //                startActivity(intent);
        }
    });

    recyclerView.setHasFixedSize(true);
    final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
    int pixels = (int) (160 * scale + 0.5f);
    Paint paint = new Paint();
    paint.setStrokeWidth(3.0f);
    paint.setColor(Color.rgb(220, 220, 220));
    paint.setAntiAlias(true);
    recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).paint(paint).build());
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    tweetObjects = new ArrayList<>();
    rvAdapter = new RVAdapter(this, tweetObjects, sessionId);
    recyclerView.setAdapter(rvAdapter);

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            tweetObjects.clear();
            getFeed();
        }
    });

    getFeed();
}

From source file:com.fastbootmobile.encore.app.MainActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()) {
        if ((mCurrentFragmentIndex + 1) != SECTION_AUTOMIX) {
            // 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.
            getMenuInflater().inflate(R.menu.main, menu);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

            mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
            mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            mSearchView.setIconifiedByDefault(true);
            mSearchView.setQueryRefinementEnabled(true);
            mSearchView.setSubmitButtonEnabled(true);

            if (mCurrentFragmentIndex + 1 == SECTION_LISTEN_NOW) {
                menu.removeItem(R.id.action_search);
            }//from   www.j  a  va2  s .  c o m

            mSearchView.setOnSearchClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    menu.findItem(R.id.action_cast).setVisible(false);
                    mNavigationDrawerFragment.setDrawerIndicatorEnabled(false);
                    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                    mSearchView.requestFocus();
                    mToolbar.setBackgroundColor(getResources().getColor(R.color.primary));
                }
            });
            mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    if (Utils.hasJellyBeanMR1()) {
                        MenuItem item = menu.findItem(R.id.action_cast);
                        if (item != null) {
                            item.setVisible(true);
                        }
                    }

                    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                    mNavigationDrawerFragment.setDrawerIndicatorEnabled(true);
                    return false;
                }
            });

            // Setup cast button on 4.2+
            MenuItem castMenu = menu.findItem(R.id.action_cast);
            if (Utils.hasJellyBeanMR1()) {
                MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat
                        .getActionProvider(castMenu);
                mediaRouteActionProvider.setRouteSelector(mCastModule.getSelector());
                castMenu.setVisible(true);
            } else {
                Log.w(TAG, "Api too low to show cast action");
                castMenu.setVisible(false);
            }

            // Offline mode
            mOfflineMenuItem = menu.findItem(R.id.action_offline_mode);
            ProviderAggregator aggregator = ProviderAggregator.getDefault();
            if (aggregator.hasNetworkConnectivity()) {
                mOfflineMenuItem.setChecked(aggregator.isOfflineMode());
            } else {
                mOfflineMenuItem.setEnabled(false);
            }
        }

        restoreActionBar();
        return true;
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar

    mMenu = menu;//  w w w.  j  a va 2  s .  c  o  m
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search_notice);
    android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu
            .findItem(R.id.search_notice).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setMaxWidth(3800);
    SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete) searchView
            .findViewById(R.id.search_src_text);
    theTextArea.setTextColor(Color.WHITE);//or any color that you want

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);

    return true;

}

From source file:com.packetsender.android.MainActivity.java

private void setupSearchView(MenuItem searchItem) {

    //searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();

        SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;/*from w  w w  . j a  va 2 s  . c o m*/
            }
        }
        mSearchView.setSearchableInfo(info);
    }

    mSearchView.setOnQueryTextListener(this);
}

From source file:itcr.gitsnes.MainActivity.java

/**
 *  Methods inflate menu options panel//from   w ww .j  av  a2 s.com
 *  Params:
 *      - [menu]
 *  Returns:
 *      - State of building [true]
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered
            // Log.i("log_tag",newText);

            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            Log.i("log_tag", query);

            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setQname(query);

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback);
            rl.setBackgroundColor(Color.parseColor("#009f28"));
            authButton.setVisibility(View.INVISIBLE);

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            return true;

        }
    };

    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.racoon.ampdroid.MainActivity.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.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;//from ww  w .  j a va  2  s .  com
}