androidx.appcompat.widget.Toolbar.OnMenuItemClickListener Java Examples

The following examples show how to use androidx.appcompat.widget.Toolbar.OnMenuItemClickListener. 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: ISHNewsDetailActivity.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
protected void initData() {
  setToolBar(mToolBar, "");
  tvAcgDetailLabels.setVisibility(android.view.View.GONE);
  mSHNewsPostItem = getIntent().getParcelableExtra(IntentConstant.ISH_NEWS_ITEM);
  if (mSHNewsPostItem == null) {
    showError(R.string.msg_error_unknown);
    return;
  }

  mToolBar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getItemId() == R.id.acginfo_share) {
        mPresenter.start2Share(new RxPermissions(ISHNewsDetailActivity.this));
      }
      return false;
    }
  });

  mPresenter.getNewsDetail(mSHNewsPostItem.getId());
}
 
Example #2
Source File: ZeroFiveNewsDetailActivity.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
protected void initData() {
  setToolBar(mToolBar, "");
  mZeroFiveNewsItem = getIntent().getParcelableExtra(IntentConstant.ZERO_FIVE_NEWS_ITEM);
  if (mZeroFiveNewsItem == null) {
    showError(R.string.msg_error_unknown);
    return;
  }

  mToolBar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getItemId() == R.id.acginfo_share) {
        mPresenter.start2Share(new RxPermissions(ZeroFiveNewsDetailActivity.this));
      }
      return false;
    }
  });

  mPresenter.getNewsDetail(mZeroFiveNewsItem.getContentLink());
}
 
Example #3
Source File: MainActivity.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to observe, when an item of the tab switcher's
 * toolbar has been clicked.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnMenuItemClickListener}. The listener may not be null
 */
@NonNull
private OnMenuItemClickListener createToolbarMenuListener() {
    return new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
                case R.id.remove_tab_menu_item:
                    Tab selectedTab = tabSwitcher.getSelectedTab();

                    if (selectedTab != null) {
                        tabSwitcher.removeTab(selectedTab);
                    }

                    return true;
                case R.id.add_tab_menu_item:
                    int index = tabSwitcher.getCount();
                    Tab tab = createTab(index);

                    if (tabSwitcher.isSwitcherShown()) {
                        tabSwitcher.addTab(tab, 0, createRevealAnimation());
                    } else {
                        tabSwitcher.addTab(tab, 0, createPeekAnimation());
                    }

                    return true;
                case R.id.clear_tabs_menu_item:
                    tabSwitcher.clear();
                    return true;
                case R.id.settings_menu_item:
                    Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                    startActivity(intent);
                default:
                    return false;
            }
        }

    };
}
 
Example #4
Source File: TabSwitcherModel.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public final void inflateToolbarMenu(@MenuRes final int resourceId,
                                     @Nullable final OnMenuItemClickListener listener) {
    this.toolbarMenuId = resourceId;
    this.toolbarMenuItemListener = listener;
    notifyOnToolbarMenuInflated(resourceId, listener);
}
 
Example #5
Source File: TabSwitcher.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@Override
public final void inflateToolbarMenu(@MenuRes final int resourceId,
                                     @Nullable final OnMenuItemClickListener listener) {
    model.inflateToolbarMenu(resourceId, listener);
}
 
Example #6
Source File: AbstractTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@Override
public final void onToolbarMenuInflated(@MenuRes final int resourceId,
                                        @Nullable final OnMenuItemClickListener listener) {
    inflateToolbarMenu();
}
 
Example #7
Source File: TabSwitcherModel.java    From ChromeLikeTabSwitcher with Apache License 2.0 3 votes vote down vote up
/**
 * Notifies the listeners, that the menu of the toolbar, which is shown, when the tab switcher
 * is shown, has been inflated.
 *
 * @param resourceId
 *         The resource id of the menu, which has been inflated, as an {@link Integer} value.
 *         The resource id must correspond to a valid menu resource
 * @param menuItemClickListener
 *         The listener, which has been registered to be notified, when an item of the menu has
 *         been clicked, as an instance of the type OnMenuItemClickListener or null, if no
 *         listener should be notified
 */
private void notifyOnToolbarMenuInflated(@MenuRes final int resourceId,
                                         @Nullable final OnMenuItemClickListener menuItemClickListener) {
    for (Listener listener : listeners) {
        listener.onToolbarMenuInflated(resourceId, menuItemClickListener);
    }
}
 
Example #8
Source File: Model.java    From ChromeLikeTabSwitcher with Apache License 2.0 2 votes vote down vote up
/**
 * The method, which is invoked, when the menu of the toolbar, which is shown, when the tab
 * switcher is shown, has been inflated.
 *
 * @param resourceId
 *         The resource id of the menu, which has been inflated, as an {@link Integer}
 *         value. The resource id must correspond to a valid menu resource
 * @param listener
 *         The listener, which has been registered to be notified, when an item of the menu
 *         has been clicked, as an instance of the type OnMenuItemClickListener or null, if
 *         no listener should be notified
 */
void onToolbarMenuInflated(@MenuRes int resourceId,
                           @Nullable OnMenuItemClickListener listener);
 
Example #9
Source File: Model.java    From ChromeLikeTabSwitcher with Apache License 2.0 2 votes vote down vote up
/**
 * Inflates the menu of the toolbar, which is shown, when the tab switcher is shown. When using
 * the tablet layout, the menu is inflated into the secondary toolbar. If another menu has
 * already been inflated, its items will be removed.
 *
 * @param resourceId
 *         The resource id of the menu, which should be inflated, as an {@link Integer} value.
 *         The resource id must correspond to a valid menu resource
 * @param listener
 *         The listener, which should be notified, when an menu item has been clicked, as an
 *         instance of the type OnMenuItemClickListener or null, if no listener should be
 *         notified
 */
void inflateToolbarMenu(@MenuRes int resourceId, @Nullable OnMenuItemClickListener listener);
 
Example #10
Source File: TabSwitcherModel.java    From ChromeLikeTabSwitcher with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the listener, which is notified, when an item of the menu of the toolbar, which is
 * shown, when the tab switcher is shown, has been clicked.
 *
 * @return The listener, which is notified, when an item of the menu of the toolbar, which is
 * shown, when the tab switcher is shown, has been clicked as an instance of the type
 * OnMenuItemClickListener or null, if no listener should be notified
 */
@Nullable
public final OnMenuItemClickListener getToolbarMenuItemListener() {
    return toolbarMenuItemListener;
}