private void FadingOutOtherItems(PopupMenu popupMenu) {
    // Dim out all the other list items if they exist
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
    int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
    for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) {
      if (i == mHolder.getLayoutPosition()) continue;
      RecyclerViewHolder viewHolder =
          (RecyclerViewHolder) mRecyclerView.findViewHolderForLayoutPosition(i);
      View itemView = viewHolder.getItemView();
      itemView.clearAnimation();
      itemView.startAnimation(mFadeOut);
    }

    // Make sure to bring them back to normal after the menu is gone
    popupMenu.setOnDismissListener(
        new PopupMenu.OnDismissListener() {
          @Override
          public void onDismiss(PopupMenu popupMenu) {
            LinearLayoutManager layoutManager =
                (LinearLayoutManager) mRecyclerView.getLayoutManager();
            int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
            int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
            for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) {
              if (i == mHolder.getLayoutPosition()) continue;
              RecyclerViewHolder viewHolder =
                  (RecyclerViewHolder) mRecyclerView.findViewHolderForLayoutPosition(i);
              View itemView = viewHolder.getItemView();
              viewHolder.getLayoutPosition();
              itemView.clearAnimation();
              itemView.startAnimation(mFadeIn);
            }
          }
        });
  }
Esempio n. 2
0
  private static void showPopupMenu(final View v, final Object context) {

    if (ActivityFactory.getMainActivity().getCurrentUser() == null) return;

    id_menu = (int) context;
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.menu_item);

    if (ActivityFactory.getMainActivity().getCurrentUser().getPost() == IUser.Posts.Адміністратар)
      popupMenu.getMenu().setGroupVisible(R.id.group_admin, true);
    else {
      // TODO:change admin menu

    }

    popupMenu.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {

          @Override
          public boolean onMenuItemClick(MenuItem item) {
            IItem iItem = ActivityFactory.getMainActivity().getItem(id_menu);
            IUser iUser = ActivityFactory.getMainActivity().getCurrentUser();
            switch (item.getItemId()) {
              case R.id.menu_item_change:
                {
                  if (iItem.getUserId() == iUser.getId()) {
                    Bundle args = new Bundle();
                    args.putInt(IItem.ITEM_PARAM, (int) v.getTag());
                    ActivityFactory.getMainActivity()
                        .openFragment(iMainActivity.Fragments.ItemAdd, true, args);
                  }
                  return true;
                }
              case R.id.menu_item_user_set:
                {
                  Bundle args = new Bundle();
                  args.putInt(IItem.ITEM_PARAM, iItem.getId());
                  ActivityFactory.getMainActivity()
                      .openFragment(iMainActivity.Fragments.Users, true, args);
                  return true;
                }
              case R.id.menu_item_status_set:
                {
                  ActivityFactory.getMainActivity().setTempItem(iItem);
                  ActivityFactory.getMainActivity()
                      .openFragment(iMainActivity.Fragments.Status, true);

                  return true;
                }
              default:
                return false;
            }
          }
        });

    popupMenu.setOnDismissListener(
        new PopupMenu.OnDismissListener() {

          @Override
          public void onDismiss(PopupMenu menu) {}
        });
    popupMenu.show();
  }