List of usage examples for android.view MenuItem getActionView
public View getActionView();
From source file:com.hybris.mobile.app.commerce.activity.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.b2b_icon_cart); if (item != null) { final TextView totalItems = (TextView) item.getActionView().findViewById(R.id.cart_total_unit_text); totalItems.setVisibility(View.VISIBLE); totalItems.setText(SessionHelper.getCartTotalUnitCount() + ""); // Updating cart item numbers OR resetting the view with the item numbers if (SessionHelper.getCartTotalUnitCount() != SessionHelper.getCartTotalUnitCountPrevious()) { // Animate the view by a scaleIn / scaleOut totalItems.animate().scaleYBy(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_FACTOR) .setDuration(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_DURATION).setListener(null); totalItems.animate().scaleXBy(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_FACTOR) .setDuration(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_DURATION) .setListener(new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { }//from w w w .j ava2 s . co m @Override public void onAnimationRepeat(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { // We scale out at the original size if (SessionHelper.getCartTotalUnitCount() > 0) { SessionHelper.syncCartTotalUnitCountPrevious(); totalItems.animate().scaleXBy(-UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_FACTOR) .setDuration(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_DURATION) .setListener(null); totalItems.animate().scaleYBy(-UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_FACTOR) .setDuration(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_DURATION) .setListener(null); } // Or if we just empty the cart, we scale out completely and hide the view else if (SessionHelper.getCartTotalUnitCountPrevious() != 0) { SessionHelper.resetCartTotalUnitCountPrevious(); totalItems.animate().scaleXBy(-1.5f) .setDuration(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_DURATION) .setListener(null); totalItems.animate().scaleYBy(-1.5f) .setDuration(UIUtils.CART_ITEM_ACTION_BAR_ICON_SCALE_DURATION) .setListener(new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { totalItems.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) { } }); } } @Override public void onAnimationCancel(Animator animation) { } }); } else if (SessionHelper.getCartTotalUnitCount() == 0) { totalItems.setVisibility(View.GONE); } } return true; }
From source file:com.khmelenko.lab.travisclient.activity.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.menu_main, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); mSearchView = null;//from w ww . j av a2 s . c o m if (searchItem != null) { mSearchView = (SearchView) searchItem.getActionView(); } if (mSearchView != null) { mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { boolean submitProhibited = true; if (query.length() > SEARCH_LIMIT) { // save search query to history SearchRecentSuggestions suggestionsProvider = new SearchRecentSuggestions(MainActivity.this, SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE); suggestionsProvider.saveRecentQuery(query, null); submitProhibited = false; } return submitProhibited; } @Override public boolean onQueryTextChange(String newText) { reloadSearchHistoryAdapter(newText); return true; } }); mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionClick(int position) { mSearchView.setQuery(mQueryItems.get(position), true); return true; } @Override public boolean onSuggestionSelect(int position) { return true; } }); reloadSearchHistoryAdapter(""); // restore query if it was if (!TextUtils.isEmpty(mSavedQuery)) { mSearchView.setQuery(mSavedQuery, false); mSearchView.setIconified(false); } } return super.onCreateOptionsMenu(menu); }
From source file:com.luorrak.ouroboros.thread.ThreadFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem goToBottomButton = menu.findItem(R.id.action_scroll_bottom); MenuItem goToTopButton = menu.findItem(R.id.action_scroll_top); MenuItem replyButton = menu.findItem(R.id.action_reply); MenuItem watchlistButton = menu.findItem(R.id.action_add_watchlist); MenuItem refreshButton = menu.findItem(R.id.action_refresh); MenuItem galleryButton = menu.findItem(R.id.action_gallery); MenuItem saveAllImagesButton = menu.findItem(R.id.action_save_all_images); MenuItem openExternalButton = menu.findItem(R.id.action_external_browser); MenuItem shareButton = menu.findItem(R.id.menu_item_share); MenuItem menuLayout = menu.findItem(R.id.action_menu_layout); MenuItem searchButton = menu.findItem(R.id.action_search); searchButton.setVisible(true);//from w w w. j a va 2s. co m final SearchView searchView = (SearchView) searchButton.getActionView(); searchView.setIconifiedByDefault(false); searchView.setSubmitButtonEnabled(false); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { threadAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { return infiniteDbHelper.searchThreadForString(constraint.toString(), resto); } }); threadAdapter.getFilter().filter(newText); return true; } }); MenuItemCompat.setOnActionExpandListener(searchButton, this); refreshButton.setVisible(true); goToBottomButton.setVisible(true); goToTopButton.setVisible(true); replyButton.setVisible(true); galleryButton.setVisible(true); saveAllImagesButton.setVisible(true); openExternalButton.setVisible(true); shareButton.setVisible(true); watchlistButton.setVisible(true); menuLayout.setVisible(true); super.onCreateOptionsMenu(menu, inflater); }
From source file:dev.vision.shopping.center.Fragments.GourmetFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //inflater.inflate(R.menu.main, menu); inflater.inflate(R.menu.offers, menu); MenuItem searchItem = menu.findItem(R.id.action_search); MenuItem expand = menu.findItem(R.id.expand); expand.setVisible(false);/*w w w .j a v a2 s. c o m*/ SearchView searchView = null; searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView == null) searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setOnQueryTextListener(this); }
From source file:com.prasanna.android.stacknetwork.QuestionActivity.java
private void setupAddComment(Menu menu) { MenuItem newCommentMenuItem = menu.findItem(R.id.menu_new_comment); newCommentMenuItem.setVisible(true); newCommentMenuItem.getActionView().setOnClickListener(new View.OnClickListener() { @Override/*w w w . j a v a 2s . c om*/ public void onClick(View v) { setupPostCommentFragment(null); } }); }
From source file:com.fjoglar.etsitnoticias.view.activities.NewsListActivity.java
private void setUpSearchView(MenuItem searchMenuItem, final MenuItem filterMenuItem) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) searchMenuItem.getActionView(); searchView.setMaxWidth(Integer.MAX_VALUE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); TextView searchText = (TextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchText.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL)); // Hide filter option when SearchView is expanded, restore it when collapsed. MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() { @Override//from ww w. j a v a2 s. c o m public boolean onMenuItemActionExpand(MenuItem item) { filterMenuItem.setVisible(false); return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { filterMenuItem.setVisible(true); return true; } }); }
From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java
private void setupCarMenu() { for (int i = 0; i < cars.size(); i++) { submenu.clear();/*from w w w . j a va 2s. c o m*/ submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString()) .setIcon(R.drawable.ic_car_black_36dp); final MenuItem item = submenu.getItem(i); Button button = new Button(this); button.setText("Remove"); button.setTextColor(ContextCompat.getColor(this, R.color.white)); item.setActionView(button); button.setBackground(getDrawable(R.drawable.button_shape)); item.getActionView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new AlertDialog.Builder(ActivityMain.this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Delete Car").setMessage("Are you sure you want to remove car?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { System.out.println("CLICKED " + item.getTitle()); cupboard().withDatabase(db).delete(Car.class, "name = ?", (String) item.getTitle()); updateSubmenu(); } }).setNegativeButton("Cancel", null).show(); } }); } }
From source file:net.sf.diningout.app.ui.FriendsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); if (!mListener.onFriendsOptionsMenu()) { return;//from ww w.j a v a2s . com } inflater.inflate(R.menu.friends, menu); if (mInit) { menu.removeItem(R.id.search); } else { MenuItem item = menu.findItem(R.id.search); mSearch = (SearchView) item.getActionView(); mSearch.setSearchableInfo(Managers.search(a).getSearchableInfo(a.getComponentName())); SearchViews.setBackground(mSearch, R.drawable.textfield_searchview); mSearch.setOnSearchClickListener(new OnClickListener() { @Override public void onClick(View v) { event("friends", "search"); } }); mSearch.setOnQueryTextListener(new SearchTextListener()); item.setOnActionExpandListener(new SearchExpandListener()); } if (!Intents.hasActivity(a, sAddIntent)) { menu.removeItem(R.id.add); } }
From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); // This is needed to remove a bug on Android 4.0.3 inflater.inflate(R.menu.entry_list, menu); MenuItem searchItem = menu.findItem(R.id.menu_search); final SearchView searchView = (SearchView) searchItem.getActionView(); if (EntryColumns.isSearchUri(mCurrentUri)) { searchItem.expandActionView();/*from w w w.ja v a 2 s . c om*/ searchView.post(new Runnable() { // Without that, it just does not work @Override public void run() { searchView.setQuery(mCurrentUri.getLastPathSegment(), false); searchView.clearFocus(); } }); } searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { setData(mOriginalUri, true); } else { setData(EntryColumns.SEARCH_URI(newText), true, true); } return false; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { setData(mOriginalUri, true); return false; } }); if (EntryColumns.FAVORITES_CONTENT_URI.equals(mCurrentUri)) { menu.findItem(R.id.menu_refresh).setVisible(false); } else { menu.findItem(R.id.menu_share_starred).setVisible(false); } super.onCreateOptionsMenu(menu, inflater); }
From source file:com.metinkale.prayerapp.hadis.Main.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MaterialMenuInflater.with(this).setDefaultColor(0xFFFFFFFF).inflate(R.menu.hadis, menu); mSwitch = menu.findItem(R.id.favswitch); mFav = menu.findItem(R.id.fav);// w ww . j a va 2s . co m setCurrentPage(mPager.getCurrentItem()); MenuItem item = menu.findItem(R.id.menu_item_share); mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item); item = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) item.getActionView(); searchView.setOnQueryTextListener(this); return true; }