Java Code Examples for android.view.MenuItem#setShowAsActionFlags()

The following examples show how to use android.view.MenuItem#setShowAsActionFlags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideosListFragment.java    From screenrecorder with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem refresh = menu.add("Refresh");
    refresh.setIcon(R.drawable.ic_refresh_white_24dp);
    refresh.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
    refresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            // Prevent repeated refresh requests
            if (swipeRefreshLayout.isRefreshing())
                    return false;
            videosList.clear();
            checkPermission();
            Log.d(Const.TAG, "Refreshing");
            return false;
        }
    });
}
 
Example 2
Source File: SearchViewActionBar.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private void setupSearchView(MenuItem searchItem) {

        if (isAlwaysExpanded()) {
            mSearchView.setIconifiedByDefault(false);
        } else {
            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();

            // Try to use the "applications" global search provider
            SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
            for (SearchableInfo inf : searchables) {
                if (inf.getSuggestAuthority() != null
                        && inf.getSuggestAuthority().startsWith("applications")) {
                    info = inf;
                }
            }
            mSearchView.setSearchableInfo(info);
        }

        mSearchView.setOnQueryTextListener(this);
    }
 
Example 3
Source File: Notifications.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onPrepareOptionsMenu(Menu menu)
{
	super.onPrepareOptionsMenu(menu);
	
	if (unreadCount > 0 && menu.findItem(R.id.menu_dismiss) == null)
	{
		MenuItem item = menu.add(Menu.NONE, R.id.menu_dismiss, 1, "Dismiss");
		item.setIcon(AttrUtil.getResourceId(getActivity(), R.attr.dismissNotificationsIcon));
		item.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
	}
}
 
Example 4
Source File: MainActivity.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
	Log.d("MainActivity", "onCreateOptionsMenu: ");

	if (loggedIn)
	{
		boolean shouldAddMenuItem = false;
		
		if (KlyphDevice.isPortraitMode())
			shouldAddMenuItem = slidingPane.isOpen();
		else
			shouldAddMenuItem = selectionFragment != null && !selectionFragment.isVisible();

		if (shouldAddMenuItem)
		{
			MenuItem item = menu.add(Menu.NONE, R.id.menu_add, Menu.NONE, R.string.menu_new_conversation);
			item.setIcon(AttrUtil.getResourceId(this, R.attr.addIcon));
			item.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
		}

		if (menu.findItem(R.id.menu_faq) == null)
		{
			menu.add(Menu.NONE, R.id.menu_faq, Menu.NONE, R.string.menu_faq).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
		}

		if (menu.findItem(R.id.menu_buy_pro) == null && MessengerApplication.PRO_VERSION_CHECKED && !MessengerApplication.IS_PRO_VERSION)
		{
			menu.add(Menu.NONE, R.id.menu_buy_pro, Menu.NONE, R.string.menu_buy_pro).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
		}
	}
	

	return super.onCreateOptionsMenu(menu);
}
 
Example 5
Source File: AnnounceFragment.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
private void addSearchOnPageItem(Menu menu) {
    toolbar.inflateMenu(R.menu.theme_search_menu);
    MenuItem searchOnPageMenuItem = menu.findItem(R.id.action_search);
    searchOnPageMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
    SearchView searchView = (SearchView) searchOnPageMenuItem.getActionView();
    searchView.setTag(searchViewTag);

    searchView.setOnSearchClickListener(v -> {
        if (searchView.getTag().equals(searchViewTag)) {
            ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
            if (searchClose != null)
                ((ViewGroup) searchClose.getParent()).removeView(searchClose);

            ViewGroup.LayoutParams navButtonsParams = new ViewGroup.LayoutParams(App.px48, App.px48);
            TypedValue outValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.actionBarItemBackground, outValue, true);

            AppCompatImageButton btnNext = new AppCompatImageButton(searchView.getContext());
            btnNext.setImageDrawable(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_search_next));
            btnNext.setBackgroundResource(outValue.resourceId);

            AppCompatImageButton btnPrev = new AppCompatImageButton(searchView.getContext());
            btnPrev.setImageDrawable(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_search_prev));
            btnPrev.setBackgroundResource(outValue.resourceId);

            ((LinearLayout) searchView.getChildAt(0)).addView(btnPrev, navButtonsParams);
            ((LinearLayout) searchView.getChildAt(0)).addView(btnNext, navButtonsParams);

            btnNext.setOnClickListener(v1 -> findNext(true));
            btnPrev.setOnClickListener(v1 -> findNext(false));
            searchViewTag++;
        }
    });

    SearchManager searchManager = (SearchManager) getMainActivity().getSystemService(Context.SEARCH_SERVICE);
    if (null != searchManager) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getMainActivity().getComponentName()));
    }

    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            findText(newText);
            return false;
        }
    });
}
 
Example 6
Source File: ForumRulesFragment.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
private void addSearchOnPageItem(Menu menu) {
    toolbar.inflateMenu(R.menu.theme_search_menu);
    MenuItem searchOnPageMenuItem = menu.findItem(R.id.action_search);
    searchOnPageMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
    /*MenuItemCompat.setOnActionExpandListener(searchOnPageMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            toggleMessagePanelItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            toggleMessagePanelItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER);
            return true;
        }
    });*/
    SearchView searchView = (SearchView) searchOnPageMenuItem.getActionView();
    searchView.setTag(searchViewTag);

    searchView.setOnSearchClickListener(v -> {
        if (searchView.getTag().equals(searchViewTag)) {
            ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
            if (searchClose != null)
                ((ViewGroup) searchClose.getParent()).removeView(searchClose);

            ViewGroup.LayoutParams navButtonsParams = new ViewGroup.LayoutParams(App.px48, App.px48);
            TypedValue outValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.actionBarItemBackground, outValue, true);

            AppCompatImageButton btnNext = new AppCompatImageButton(searchView.getContext());
            btnNext.setImageDrawable(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_search_next));
            btnNext.setBackgroundResource(outValue.resourceId);

            AppCompatImageButton btnPrev = new AppCompatImageButton(searchView.getContext());
            btnPrev.setImageDrawable(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_search_prev));
            btnPrev.setBackgroundResource(outValue.resourceId);

            ((LinearLayout) searchView.getChildAt(0)).addView(btnPrev, navButtonsParams);
            ((LinearLayout) searchView.getChildAt(0)).addView(btnNext, navButtonsParams);

            btnNext.setOnClickListener(v1 -> findNext(true));
            btnPrev.setOnClickListener(v1 -> findNext(false));
            searchViewTag++;
        }
    });

    SearchManager searchManager = (SearchManager) getMainActivity().getSystemService(Context.SEARCH_SERVICE);
    if (null != searchManager) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getMainActivity().getComponentName()));
    }

    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            findText(newText);
            return false;
        }
    });
}