androidx.core.view.MenuItemCompat Java Examples

The following examples show how to use androidx.core.view.MenuItemCompat. 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: MainActivity.java    From media-samples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Be sure to call the super class.
    super.onCreateOptionsMenu(menu);

    // Inflate the menu and configure the media router action provider.
    getMenuInflater().inflate(R.menu.sample_media_router_menu, menu);

    MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
    MediaRouteActionProvider mediaRouteActionProvider =
            (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
    mediaRouteActionProvider.setRouteSelector(mSelector);

    // Return true to show the menu.
    return true;
}
 
Example #2
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.hadis, menu);

    mSwitch = menu.findItem(R.id.favswitch);
    mFav = menu.findItem(R.id.fav);
    setCurrentPage(mPager.getCurrentItem());

    MenuItem item = menu.findItem(R.id.menu_item_share);
    item.setOnMenuItemClickListener(item1 -> {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, mShareText);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share)));
        return true;
    });

    item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}
 
Example #3
Source File: ContactSelectionActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.group_create_menu, menu);
    menu.removeItem(R.id.Next);
    if (disableCheckBox) {
        menu.removeItem(R.id.Done);
    }
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    if (Utils.hasICS()) {
        searchItem.collapseActionView();
    }
    searchView.setOnQueryTextListener(this);
    searchView.setIconified(true);
    return super.onCreateOptionsMenu(menu);
}
 
Example #4
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    showActionBar();
    //return false;
    getMenuInflater().inflate(R.menu.mobicom_basic_menu_for_normal_message, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    if (Utils.hasICS()) {
        searchItem.collapseActionView();
    }
    searchView.setOnQueryTextListener(this);
    searchView.setSubmitButtonEnabled(true);
    searchView.setIconifiedByDefault(true);

    if (quickConversationFragment != null && !TextUtils.isEmpty(quickConversationFragment.getSearchString())) {
        searchView.setIconified(false);
        searchView.setQuery(quickConversationFragment.getSearchString(), false);
    }

    return super.onCreateOptionsMenu(menu);
}
 
Example #5
Source File: BoxBrowseActivity.java    From box-android-browse-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.box_browsesdk_fragment_container);
    mSearchViewMenuItem = menu.findItem(R.id.box_browsesdk_action_search);
    mSearchView = (BoxSearchView) MenuItemCompat.getActionView(mSearchViewMenuItem);

    if (fragment instanceof BoxSearchFragment) {
        mSearchView.setIconified(false);
        mSearchView.setSearchTerm(((BoxSearchFragment)fragment).getSearchQuery());
    }

    enableDisableRecentView();
    mSearchView.setOnBoxSearchListener(this);

    return true;
}
 
Example #6
Source File: SubsonicFragment.java    From Audinaut with GNU General Public License v3.0 6 votes vote down vote up
void onFinishSetupOptionsMenu(final Menu menu) {
    searchItem = menu.findItem(R.id.menu_global_search);
    if (searchItem != null) {
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
        SearchableInfo searchableInfo = searchManager.getSearchableInfo(context.getComponentName());
        if (searchableInfo == null) {
            Log.w(TAG, "Failed to get SearchableInfo");
        } else {
            searchView.setSearchableInfo(searchableInfo);
        }

        String currentQuery = getCurrentQuery();
        if (currentQuery != null) {
            searchView.setOnSearchClickListener(v -> searchView.setQuery(getCurrentQuery(), false));
        }
    }
}
 
Example #7
Source File: AppcompatActivity.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	super.onCreateOptionsMenu(menu);
	getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

	menu.findItem(R.id.action_previous).setEnabled(viewPager.getCurrentItem() > 0);
	//help since this attribute is ignored in the xml by api <11.  ie 2.3.3
	//but the change is should xml, use app: instead of android is the ActionBarActivity can read it. 
	//see xml 
	//MenuItemCompat.setShowAsAction(menu.findItem(R.id.action_previous),MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
	
	MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
			(viewPager.getCurrentItem() == mPagerAdapter.getCount() - 1)
			? R.string.action_finish
					: R.string.action_next);
	//item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
	MenuItemCompat.setShowAsAction(item,MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
	return true;
}
 
Example #8
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.hadis, menu);

    mSwitch = menu.findItem(R.id.favswitch);
    mFav = menu.findItem(R.id.fav);
    setCurrentPage(mPager.getCurrentItem());

    MenuItem item = menu.findItem(R.id.menu_item_share);
    item.setOnMenuItemClickListener(item1 -> {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, mShareText);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share)));
        return true;
    });

    item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}
 
Example #9
Source File: LogActivity.java    From syncthing-android with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.log_list, menu);

    MenuItem switchLog = menu.findItem(R.id.switch_logs);
    switchLog.setTitle(mSyncthingLog ? R.string.view_android_log : R.string.view_syncthing_log);

    // Add the share button
    MenuItem shareItem = menu.findItem(R.id.menu_share);
    ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    mShareIntent = new Intent();
    mShareIntent.setAction(Intent.ACTION_SEND);
    mShareIntent.setType("text/plain");
    mShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mLog.getText());
    actionProvider.setShareIntent(mShareIntent);

    return true;
}
 
Example #10
Source File: MainActivity.java    From media-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the ActionBar or options menu. The menu file defines an item for
 * the {@link android.app.MediaRouteActionProvider}, which is registered here for all
 * live video devices using {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO}.
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    getMenuInflater().inflate(R.menu.main, menu);

    // BEGIN_INCLUDE(MediaRouteActionProvider)
    // Configure the media router action provider
    MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route);

    MediaRouteActionProvider mediaRouteActionProvider =
            (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
    mediaRouteActionProvider.setRouteSelector(
            new MediaRouteSelector.Builder()
                    .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
                    .build());
    // BEGIN_INCLUDE(MediaRouteActionProvider)

    return true;
}
 
Example #11
Source File: ActionBarSearchActivity.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  inflater.inflate(R.menu.actionbar_search_actions, menu);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchItem = menu.findItem(R.id.menu_search);
  SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  searchView.setIconifiedByDefault(false);
  return super.onCreateOptionsMenu(menu);
}
 
Example #12
Source File: OverviewFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.main_toolbar, menu);

    // Create the search view
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id
        .action_search));
    setUpSearchView(mSearchView);
}
 
Example #13
Source File: BoxBrowseActivity.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
private void clearSearch() {
    if (mSearchViewMenuItem == null) {
        return;
    }

    BoxSearchView searchView = (BoxSearchView) MenuItemCompat.getActionView(mSearchViewMenuItem);
    if (!searchView.isIconified()) {
        searchView.onActionViewCollapsed();
        searchView.setIconified(true);
    }
}
 
Example #14
Source File: BoxBrowseActivity.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (mSearchViewMenuItem == null) {
        return;
    }
    BoxSearchView searchView = (BoxSearchView) MenuItemCompat.getActionView(mSearchViewMenuItem);
    outState.putBoolean(RESTORE_SEARCH, !searchView.isIconified());
    outState.putString(SEARCH_QUERY, searchView.getQuery().toString());
}
 
Example #15
Source File: SelectFileActivity.java    From turbo-editor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_select_file, menu);
    mSearchViewMenuItem = menu.findItem(R.id.im_search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchViewMenuItem);
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setSubmitButtonEnabled(false);
    return super.onCreateOptionsMenu(menu);
}
 
Example #16
Source File: MobiComKitPeopleActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_contact, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    if (Utils.hasICS()) {
        searchItem.collapseActionView();
    }
    searchView.setOnQueryTextListener(this);
    searchView.setSubmitButtonEnabled(true);
    searchView.setIconified(true);
    return super.onCreateOptionsMenu(menu);
}
 
Example #17
Source File: SelectFileActivity.java    From turbo-editor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPreExecute() {
    super.onPreExecute();
    if (mSearchView != null) {
        mSearchView.setIconified(true);
        MenuItemCompat.collapseActionView(mSearchViewMenuItem);
        mSearchView.setQuery("", false);
    }

}
 
Example #18
Source File: SearchCityFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.search, menu);
    mSearchItem = menu.findItem(R.id.menu_search);
    SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);
    mSearchView.performClick();
    mSearchView.setOnQueryTextListener(this);
}
 
Example #19
Source File: SearchCityFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    if (view == mFab) {
        MenuItemCompat.collapseActionView(mSearchItem);
        MenuItemCompat.expandActionView(mSearchItem);
    }
}
 
Example #20
Source File: MainFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    mRefresh = menu.add(Menu.NONE, Menu.NONE, 1, R.string.refresh);
    mSwitch = menu.add(Menu.NONE, Menu.NONE, 0, R.string.switchCompass);
    MenuItemCompat.setShowAsAction(mRefresh, MenuItemCompat.SHOW_AS_ACTION_NEVER);
    MenuItemCompat.setShowAsAction(mSwitch, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    mSwitch.setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK).setColor(Color.WHITE)
            .setToActionbarSize().build());
}
 
Example #21
Source File: ViewTaskFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
private void setSendMenuIntent()
{
    if (mContentSet != null && mModel != null && mToolBar != null && mToolBar.getMenu() != null)
    {
        MenuItem shareItem = mToolBar.getMenu().findItem(R.id.opentasks_send_task);
        if (shareItem != null)
        {
            ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
            Intent shareIntent = new ShareIntentFactory().create(mContentSet, mModel, mAppContext);
            actionProvider.setShareIntent(shareIntent);
        }
    }
}
 
Example #22
Source File: SearchCityFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.search, menu);
    mSearchItem = menu.findItem(R.id.menu_search);
    SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);
    mSearchView.performClick();
    mSearchView.setOnQueryTextListener(this);
}
 
Example #23
Source File: SmsDragListActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.draglist_menu, menu);

        final MenuItem searchItem = menu.findItem(R.id.action_search);
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            /**
             * Not sense doing via android.widget.Filter as adapter and its data is filtered in async mode 
             */
            @Override
            public boolean onQueryTextChange(String newText) {
                cursorSource.setConstraint(newText);
                adapter.reloadAsyncSource();
                
                if (!StringUtil.isEmpty(newText)) {
                    Log.i(TAG, "filtered by `" + newText + "`");
//                    Toast.makeText(SmsDragListActivity.this, "filtered by '" + newText + "'", Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });

        final MenuItem newItem = menu.findItem(R.id.new_sms_template);
        newItem.setOnMenuItemClickListener(this::addItem);
        return true;
    }
 
Example #24
Source File: MainActivity.java    From MusicBobber with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.clear();
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem searchItem = menu.findItem(R.id.item_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    return true;
}
 
Example #25
Source File: MainActivity.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    resetItem = menu.findItem(R.id.action_reset);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            adapter.filter(viewPager.getCurrentItem(), query.toLowerCase());
            appbar.setExpanded(true);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.filter(viewPager.getCurrentItem(), newText.toLowerCase());
            appbar.setExpanded(true);
            return true;
        }
    });

    searchView.setOnCloseListener(() -> {
        adapter.filter(viewPager.getCurrentItem(), null);
        return false;
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example #26
Source File: DhikrFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater).setDefaultColorResource(R.color.white).inflate(R.menu.zikr, menu);
    
    MenuItem item = menu.findItem(R.id.menu_spinner);
    mSpinner = (Spinner) MenuItemCompat.getActionView(item);
    
    
    onChanged(mViewModel.getDhikrs().getValue());
}
 
Example #27
Source File: NamesFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.search, menu);
    MenuItem item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}
 
Example #28
Source File: MainFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    mRefresh = menu.add(Menu.NONE, Menu.NONE, 1, R.string.refresh);
    mSwitch = menu.add(Menu.NONE, Menu.NONE, 0, R.string.switchCompass);
    MenuItemCompat.setShowAsAction(mRefresh, MenuItemCompat.SHOW_AS_ACTION_NEVER);
    MenuItemCompat.setShowAsAction(mSwitch, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    mSwitch.setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK).setColor(Color.WHITE)
            .setToActionbarSize().build());
}
 
Example #29
Source File: SearchCityFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    if (view == mFab) {
        MenuItemCompat.collapseActionView(mSearchItem);
        MenuItemCompat.expandActionView(mSearchItem);
    }
}
 
Example #30
Source File: NamesFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.search, menu);
    MenuItem item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}