private void showMorePopup(
      View v, final GithubComment comment, final boolean canEdit, final boolean canDelete) {
    PopupMenu menu = new PopupMenu(context, v);
    menu.inflate(R.menu.comment_popup);

    menu.getMenu().findItem(R.id.m_edit).setEnabled(canEdit);
    menu.getMenu().findItem(R.id.m_delete).setEnabled(canDelete);

    menu.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
              case R.id.m_edit:
                if (editCommentListener != null) {
                  editCommentListener.onEditComment(comment);
                }
                break;
              case R.id.m_delete:
                if (deleteCommentListener != null) {
                  deleteCommentListener.onDeleteComment(comment);
                }
                break;
            }
            return false;
          }
        });

    menu.show();
  }
 @Override
 public void onClick(View v) {
   if ((v.getId() == editProfileImageText.getId()) || (v.getId() == profileImage.getId())) {
     popupMenu = new PopupMenu(getActivity(), v);
     popupMenu
         .getMenuInflater()
         .inflate(R.menu.edit_profile_edit_picture_dropdown, popupMenu.getMenu());
     popupMenu.setOnMenuItemClickListener(
         new OnMenuItemClickListener() {
           @Override
           public boolean onMenuItemClick(MenuItem item) {
             if (item.getTitle().toString().equalsIgnoreCase("From Camera")) {
               /* TODO */
             } else if (item.getTitle().toString().equalsIgnoreCase("From Gallery")) {
               /* TODO */
             }
             popupMenu.dismiss();
             return true;
           }
         });
     popupMenu.show();
   } else if (v.getId() == submitButton.getId()) {
     if (IsValid()) {
       PostToServer();
     }
   }
 }
 @Override
 public void itemClicked(View v, final int position) {
   clickedPosition = position;
   if (v instanceof RelativeLayout) {
     String videoUrl = videoList.get(position).player;
     UrlHelper.playVideo(getActivity(), videoUrl);
   } else if (v instanceof ImageButton) {
     PopupMenu popupMenu = new PopupMenu(getActivity(), v);
     if (isMy) {
       popupMenu.inflate(R.menu.popup_menu_my_video);
     } else {
       popupMenu.inflate(R.menu.popup_menu_video);
     }
     popupMenu.setOnMenuItemClickListener(
         item -> {
           switch (item.getItemId()) {
             case R.id.add:
               AdditionRequests.addVideo(getActivity(), videoList.get(position));
               return true;
             case R.id.add_to_album:
               AdditionRequests.addVideoToAlbum(getFragmentManager(), videoList.get(position));
               return true;
             case R.id.delete:
               showDeleteDialog();
               return true;
             default:
               return false;
           }
         });
     popupMenu.show();
   }
 }
    protected void showPopup(final Experiment experiment, View v) {
      PopupMenu popup = new PopupMenu(MyExperimentsActivity.this, v);
      final Menu menu = popup.getMenu();
      popup.getMenuInflater().inflate(R.menu.experiment_popup, menu);

      if (!userCanEditAtLeastOneSchedule(experiment)) {
        menu.removeItem(R.id.editSchedule);
      }
      popup.show();
      popup.setOnMenuItemClickListener(
          new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

              switch (item.getItemId()) {
                case R.id.editSchedule:
                  launchScheduleDetailScreen(experiment);
                  break;
                case R.id.emailResearcher:
                  emailResearcher(experiment);
                  break;
                case R.id.stopExperiment:
                  deleteExperiment(experiment);
                  break;
                default:
                  break;
              }

              return true;
            }
          });
    }
 private void showFilterPopup(View v) {
   PopupMenu popup = new PopupMenu(getContext(), v);
   // Inflate the menu from xml
   popup.getMenuInflater().inflate(R.menu.popup_filter, popup.getMenu());
   // Setup menu item selection
   popup.setOnMenuItemClickListener(
       new PopupMenu.OnMenuItemClickListener() {
         public boolean onMenuItemClick(MenuItem item) {
           switch (item.getItemId()) {
             case R.id.profile:
               Intent intent = new Intent(getContext(), MyProfile.class);
               startActivity(intent);
               return true;
             case R.id.logout:
               Toast.makeText(getContext(), "LogOut", Toast.LENGTH_SHORT).show();
               return true;
             default:
               return false;
           }
         }
       });
   // Handle dismissal with: popup.setOnDismissListener(...);
   // Show the menu
   popup.show();
 }
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.instanceMore:
       final PopupMenu menu = new PopupMenu(context, v, Gravity.END);
       String[] options = context.getResources().getStringArray(R.array.queue_options_playlist);
       for (int i = 0; i < options.length; i++) {
         menu.getMenu().add(Menu.NONE, i, i, options[i]);
       }
       menu.setOnMenuItemClickListener(
           new PopupMenu.OnMenuItemClickListener() {
             @Override
             public boolean onMenuItemClick(MenuItem menuItem) {
               switch (menuItem.getItemId()) {
                 case 0: // Queue this playlist next
                   PlayerController.queueNext(Library.getPlaylistEntries(context, reference));
                   return true;
                 case 1: // Queue this playlist last
                   PlayerController.queueLast(Library.getPlaylistEntries(context, reference));
                   return true;
                 case 2: // Delete this playlist
                   Library.removePlaylist(itemView, reference);
                   return true;
               }
               return false;
             }
           });
       menu.show();
       break;
     default:
       Navigate.to(context, PlaylistActivity.class, PlaylistActivity.PLAYLIST_EXTRA, reference);
       break;
   }
 }
Esempio n. 7
0
 @Override
 public void onClick(View v) {
   int id = v.getId();
   switch (id) {
     case R.id.menu:
       mMenu.show();
       break;
     default:
       break;
   }
 }
  public void showMenu(View v) {
    PopupMenu popup = new PopupMenu(getActivity(), v);

    // This activity implements OnMenuItemClickListener
    popup.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            return false;
          }
        });
    popup.inflate(R.menu.share_menu);
    popup.show();
  }
Esempio n. 9
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.instanceMore:
       final PopupMenu menu = new PopupMenu(context, v, Gravity.END);
       String[] options = context.getResources().getStringArray(R.array.queue_options_genre);
       for (int i = 0; i < options.length; i++) {
         menu.getMenu().add(Menu.NONE, i, i, options[i]);
       }
       menu.setOnMenuItemClickListener(this);
       menu.show();
       break;
     default:
       Navigate.to(context, GenreActivity.class, GenreActivity.GENRE_EXTRA, reference);
       break;
   }
 }
Esempio n. 10
0
 public void showPopUp(View v, Todo todo, int position) {
   PopupMenu popup = new PopupMenu(mContext, v);
   popup.setOnMenuItemClickListener(
       new PopupMenu.OnMenuItemClickListener() {
         @Override
         public boolean onMenuItemClick(MenuItem item) {
           switch (item.getItemId()) {
             case R.id.remove_todo:
               listener.onDeleteClick(todo, position);
               return true;
             case R.id.share_todo:
               listener.onShareClick(todo);
               return true;
             default:
               return false;
           }
         }
       });
   popup.inflate(R.menu.menu_popup_todo);
   popup.show();
 }
Esempio n. 11
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.chat_send && keyboard.getText().toString().length() != 0) {
      Calendar cal = new GregorianCalendar();
      Date date = cal.getTime();

      SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      String dateFormat = df.format(date);

      boolean isGroup = false;

      Message message =
          new Message(keyboard.getText().toString(), dateFormat, true, toID, toID, isGroup);

      messages.add(message);

      sendMessage(message.getText());
      showMessage(message);
    } else {
      popupMenu.show();
    }
  }
  @Override
  public void onClick(View v) {
    if (v == playPauseButton) {
      PlayerController.togglePlay();
    } else if (v == skipPrevButton) {
      PlayerController.previous();
    } else if (v == skipNextButton) {
      PlayerController.skip();
    } else if (v == moreInfoButton) {
      // Song info
      final Song nowPlaying = PlayerController.getNowPlaying();

      if (nowPlaying != null) {
        final PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END);
        String[] options = getResources().getStringArray(R.array.now_playing_options);

        for (int i = 0; i < options.length; i++) {
          menu.getMenu().add(Menu.NONE, i, i, options[i]);
        }
        menu.setOnMenuItemClickListener(this);
        menu.show();
      }
    }
  }
  @SuppressLint("LongLogTag")
  @Override
  public void onClick(View v) {
    // This is an android.support.v7.widget.PopupMenu;
    PopupMenu popupMenu =
        new PopupMenu(mContext, v) {
          @Override
          public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            switch (item.getItemId()) {
              case R.id.popup_delete:
                //                        deleteAlbum(mAlbum);
                Toast.makeText(mContext, "you click delete", Toast.LENGTH_SHORT).show();
                return true;

              case R.id.popup_rename:
                //                        renameAlbum(mAlbum);
                Toast.makeText(mContext, "you click rename", Toast.LENGTH_SHORT).show();
                return true;

              case R.id.popup_lock:
                //                        lockAlbum(mAlbum);
                Toast.makeText(mContext, "you click lock", Toast.LENGTH_SHORT).show();
                return true;

              case R.id.popup_unlock:
                //                        unlockAlbum(mAlbum);
                Toast.makeText(mContext, "you click unlock", Toast.LENGTH_SHORT).show();
                return true;

              case R.id.popup_set_cover:
                //                        setAlbumCover(mAlbum);
                Toast.makeText(mContext, "you click set cover", Toast.LENGTH_SHORT).show();
                return true;

              default:
                return super.onMenuItemSelected(menu, item);
            }
          }
        };

    popupMenu.inflate(R.menu.popup_menu);

    //        if (mAlbum.isLocked()) {
    //            popupMenu.getMenu().removeItem(R.id.album_overflow_lock);
    //            popupMenu.getMenu().removeItem(R.id.album_overflow_rename);
    //            popupMenu.getMenu().removeItem(R.id.album_overflow_delete);
    //        } else {
    //            popupMenu.getMenu().removeItem(R.id.album_overflow_unlock);
    //        }

    // Force icons to show
    Object menuHelper;
    Class[] argTypes;
    try {
      // PopupMenu有一个私有变量mPopup,类型是MenuPopupHelper,有一个方法setForceShowIcon,用于显示icon
      Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
      fMenuHelper.setAccessible(true);
      menuHelper = fMenuHelper.get(popupMenu);
      argTypes = new Class[] {boolean.class};
      menuHelper
          .getClass()
          .getDeclaredMethod("setForceShowIcon", argTypes)
          .invoke(menuHelper, true);
    } catch (Exception e) {
      // Possible exceptions are NoSuchMethodError and NoSuchFieldError
      //
      // In either case, an exception indicates something is wrong with the reflection code, or the
      // structure of the PopupMenu class or its dependencies has changed.
      //
      // These exceptions should never happen since we're shipping the AppCompat library in our own
      // apk,
      // but in the case that they do, we simply can't force icons to display, so log the error and
      // show the menu normally.

      Log.w(TAG, "error forcing menu icons to show", e);
      popupMenu.show();
      return;
    }
    popupMenu.show();

    // 调整popupMenu的位置偏移量
    try {
      Field fListPopup = menuHelper.getClass().getDeclaredField("mPopup");
      fListPopup.setAccessible(true);
      Object listPopup = fListPopup.get(menuHelper);
      argTypes = new Class[] {int.class};
      Class listPopupClass = listPopup.getClass();

      // Get the width of the popup window
      int width = (Integer) listPopupClass.getDeclaredMethod("getWidth").invoke(listPopup);

      // Invoke setHorizontalOffset() with the negative width to move left by that distance
      listPopupClass
          .getDeclaredMethod("setHorizontalOffset", argTypes)
          .invoke(listPopup, -width + 100);

      // Invoke show() to update the window's position
      listPopupClass.getDeclaredMethod("show").invoke(listPopup);
    } catch (Exception e) {
      // Again, an exception here indicates a programming error rather than an exceptional condition
      // at runtime
      Log.w(TAG, "Unable to force offset", e);
    }
    FadingOutOtherItems(popupMenu);
  }
Esempio n. 14
0
  protected void contextMenu(
      View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) {
    final PopupMenu optionsMenu = new PopupMenu(context, v);
    MenuItem item;

    final File fl = indexItem.getTargetFile(context.getMyApplication());
    if (fl.exists()) {
      item =
          optionsMenu
              .getMenu()
              .add(R.string.shared_string_remove)
              .setIcon(
                  context
                      .getMyApplication()
                      .getIconsCache()
                      .getThemedIcon(R.drawable.ic_action_remove_dark));
      item.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
              LocalIndexType tp = LocalIndexType.MAP_DATA;
              if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
                tp = LocalIndexType.TILES_DATA;
              } else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
                tp = LocalIndexType.MAP_DATA;
              } else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
                tp = LocalIndexType.SRTM_DATA;
              } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
                tp = LocalIndexType.MAP_DATA;
              } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
                tp =
                    indexItem.getBasename().contains("tts")
                        ? LocalIndexType.TTS_VOICE_DATA
                        : LocalIndexType.VOICE_DATA;
              }
              final LocalIndexInfo info =
                  new LocalIndexInfo(tp, fl, false, context.getMyApplication());
              AlertDialog.Builder confirm = new AlertDialog.Builder(context);
              confirm.setPositiveButton(
                  R.string.shared_string_yes,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      new LocalIndexOperationTask(
                              context, null, LocalIndexOperationTask.DELETE_OPERATION)
                          .execute(info);
                    }
                  });
              confirm.setNegativeButton(R.string.shared_string_no, null);
              String fn =
                  FileNameTranslationHelper.getFileName(
                      context,
                      context.getMyApplication().getRegions(),
                      indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
              confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn));
              confirm.show();
              return true;
            }
          });
    }
    item =
        optionsMenu
            .getMenu()
            .add(R.string.shared_string_download)
            .setIcon(
                context
                    .getMyApplication()
                    .getIconsCache()
                    .getThemedIcon(R.drawable.ic_action_import));
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            download(indexItem, parentOptional);
            return true;
          }
        });

    optionsMenu.show();
  }
  @Override
  public void onClick(View v) {
    if (v.getId() == tv_fullname.getId() || v.getId() == tv_username.getId()) {
      // GOTO PROFILE WHEN NAME OR USERNAME IS CLICKED
      Intent i = new Intent(context, ProfileActivity.class);
      i.putExtra("UserId", userId);
      context.startActivity(i);
    } else if (v.getId() == R.id.pt_commentBtn) {
      Intent i = new Intent(context, CommentActivity.class);
      i.putExtra("PostId", postId);
      i.putExtra("FullName", tv_fullname.getText().toString());
      i.putExtra("isOwned", owned);
      context.startActivity(i);
      ((Activity) context).overridePendingTransition(R.animator.animate3, R.animator.animate2);
    } else if (v.getId() == R.id.pt_shareBtn) {
      Intent i = new Intent(context, ShareActivity.class);
      if (share_postId.equals("")) i.putExtra("PostId", postId);
      else i.putExtra("PostId", share_postId);
      i.putExtra("OwnerId", schoolId);
      context.startActivity(i);
      ((Activity) context).overridePendingTransition(R.animator.animate3, R.animator.animate2);
    } else if (v.getId() == upvote.getId()) {
      upvote.setVisibility(View.INVISIBLE);
      upvote2.setVisibility(View.VISIBLE);
      Intent intent = new Intent(context, UpvoteService.class);
      intent.putExtra("userId", schoolId);
      intent.putExtra("postId", postId);
      context.startService(intent);
    } else if (v.getId() == upvote2.getId()) {
      upvote2.setVisibility(View.INVISIBLE);
      upvote.setVisibility(View.VISIBLE);

      Intent intent = new Intent(context, UpvoteService.class);
      intent.putExtra("userId", schoolId);
      intent.putExtra("postId", postId);
      context.startService(intent);
    } else if (v.getId() == options.getId()) {
      // Creating the instance of PopupMenu
      PopupMenu popup = new PopupMenu(context, options);
      // Inflating the Popup using xml file
      if (owned) {
        popup.getMenuInflater().inflate(R.menu.menu_options, popup.getMenu());
      } else {
        popup.getMenuInflater().inflate(R.menu.menu_options2, popup.getMenu());
      }

      // registering popup with OnMenuItemClickListener
      popup.setOnMenuItemClickListener(
          new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
              if (item.getTitle().equals("Report")) {
                Intent i = new Intent(context, ReportActivity.class);
                i.putExtra("PostId", postId);
                i.putExtra("ReporterId", schoolId);
                i.putExtra("ReferenceTable", "post");
                context.startActivity(i);
              } else if (item.getTitle().equals("Edit")) {
                Intent i = new Intent(context, EditPostActivity.class);
                i.putExtra("PostId", postId);
                context.startActivity(i);
              } else {
                Intent i = new Intent(context, DeleteService.class);
                i.putExtra("PostId", postId);
                i.putExtra("Action", "post");
                context.startService(i);
              }
              return true;
            }
          });

      popup.show(); // showing popup menu
    } else if (v.getId() == fileCV.getId()) {
      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(fileUrl));
      context.startActivity(browserIntent);

    } else if (v.getId() == share_file_name.getId()) {
      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(shareFileUrl));
      context.startActivity(browserIntent);
    } else {
      // GOTO VIEW POST
      Intent i = new Intent(context, PostViewActivity.class);
      i.putExtra("PostId", postId);
      context.startActivity(i);
    }
  }
Esempio n. 16
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();
  }