コード例 #1
0
  @Override
  public void onCreateContextMenu(
      final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    if (view == cacheLimitTextView) {
      for (final SpannableString string : ContentUtils.cacheSizeStrings) {
        menu.add(string).setActionView(view);
      }
      menu.setHeaderTitle(ContentUtils.getCenteredString(setCacheSizeText));
    } else if (view.getId() == listView.getId()) {
      final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
      final ContentItem content = contentListItems.getItem(info.position).getContentItem();

      if (ContentState.REMOTE_DIRECTORY.equals(content.getContentState())) {
        menu.add(R.string.user_files_browser_context_menu_delete).setActionView(view);
      } else {
        final ContentState contentState = content.getContentState();
        final boolean isNewerVersionAvailable =
            ContentState.isCachedWithNewerVersionAvailableOrTransferring(contentState);
        final boolean isCached = contentState == ContentState.CACHED || isNewerVersionAvailable;
        final boolean isPinned = userFileManager.isContentPinned(content.getFilePath());

        // if item is downloaded
        if (isCached) {
          menu.add(getString(R.string.content_context_menu_open)).setActionView(view);
        } else {
          menu.add(R.string.content_context_menu_open_remote).setActionView(view);
          menu.add(getString(R.string.content_context_menu_download)).setActionView(view);
        }
        if (isNewerVersionAvailable) {
          menu.add(getString(R.string.content_context_menu_download_latest)).setActionView(view);
        }
        if (isCached && !isPinned) {
          menu.add(getString(R.string.content_context_menu_pin)).setActionView(view);
        }
        if (!isCached) {
          menu.add(getString(R.string.content_context_menu_download_pin)).setActionView(view);
        }
        if (isPinned) {
          menu.add(getString(R.string.content_context_menu_unpin)).setActionView(view);
        }
        if (isCached) {
          menu.add(getString(R.string.content_context_menu_delete_local)).setActionView(view);
        }
        menu.add(R.string.user_files_browser_context_menu_delete).setActionView(view);
      }
      menu.setHeaderTitle(content.getFilePath());
    }
  }
コード例 #2
0
 @Override
 public void onItemClick(
     final AdapterView<?> parent, final View view, final int position, final long id) {
   final ContentItem content = contentListItems.getItem(position).getContentItem();
   if (content.getContentState().equals(ContentState.REMOTE_DIRECTORY)) {
     changeDirectory(content.getFilePath());
   } else {
     listView.showContextMenuForChild(view);
   }
 }