예제 #1
0
파일: BookmarksDlg.java 프로젝트: pesgh/cr3
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   MenuInflater inflater = mCoolReader.getMenuInflater();
   menu.clear();
   inflater.inflate(
       mList.isShortcutMode()
           ? R.menu.cr3_bookmark_shortcut_context_menu
           : R.menu.cr3_bookmark_context_menu,
       menu);
   AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
   if (mi != null) selectedItem = mi.position;
   Bookmark bm = mList.getSelectedBookmark();
   menu.setHeaderTitle(getContext().getString(R.string.context_menu_title_bookmark));
   for (int i = 0; i < menu.size(); i++) {
     MenuItem menuItem = menu.getItem(i);
     if (menuItem.getItemId() == R.id.bookmark_shortcut_goto
         || menuItem.getItemId() == R.id.bookmark_edit
         || menuItem.getItemId() == R.id.bookmark_delete) menuItem.setEnabled(bm != null);
     if (menuItem.getItemId() == R.id.bookmark_edit)
       menuItem.setEnabled(
           bm != null
               && (bm.getType() == Bookmark.TYPE_COMMENT
                   || bm.getType() == Bookmark.TYPE_CORRECTION));
     menuItem.setOnMenuItemClickListener(
         new OnMenuItemClickListener() {
           public boolean onMenuItemClick(MenuItem item) {
             onContextItemSelected(item);
             return true;
           }
         });
   }
 }
예제 #2
0
파일: BookmarksDlg.java 프로젝트: pesgh/cr3
  @Override
  public boolean onContextItemSelected(MenuItem item) {

    int shortcut = selectedItem; // mList.getSelectedItemPosition();
    Bookmark bm = mList.getSelectedBookmark();
    if (mList.isShortcutMode()) {
      if (shortcut >= 0 && shortcut < SHORTCUT_COUNT) {
        switch (item.getItemId()) {
          case R.id.bookmark_shortcut_add:
            mReaderView.addBookmark(shortcut + 1);
            listUpdated();
            dismiss();
            return true;
          case R.id.bookmark_delete:
            if (mReaderView.removeBookmark(bm) != null) listUpdated();
            return true;
          case R.id.bookmark_shortcut_goto:
            mReaderView.goToBookmark(shortcut + 1);
            dismiss();
            return true;
        }
      }
      return super.onContextItemSelected(item);
    }
    switch (item.getItemId()) {
      case R.id.bookmark_add:
        mReaderView.addBookmark(0);
        listUpdated();
        dismiss();
        return true;
      case R.id.bookmark_delete:
        if (mReaderView.removeBookmark(bm) != null) listUpdated();
        return true;
      case R.id.bookmark_goto:
        if (bm != null) mReaderView.goToBookmark(bm);
        dismiss();
        return true;
      case R.id.bookmark_edit:
        if (bm != null
            && (bm.getType() == Bookmark.TYPE_COMMENT
                || bm.getType() == Bookmark.TYPE_CORRECTION)) {
          BookmarkEditDialog dlg = new BookmarkEditDialog(mCoolReader, mReaderView, bm, false);
          dlg.show();
        }
        dismiss();
        return true;
      case R.id.bookmark_export:
        if (mBookInfo.getBookmarkCount() > 0) {
          FileInfo fi = mBookInfo.getFileInfo();
          String s = fi.getPathName();
          s = s.replace(FileInfo.ARC_SEPARATOR, "_");
          s = s + ".bmk.txt";
          if (mBookInfo.exportBookmarks(s))
            mCoolReader.showToast(
                getContext().getString(R.string.toast_bookmark_export_ok) + " " + s);
          else
            mCoolReader.showToast(
                getContext().getString(R.string.toast_bookmark_export_failed) + " " + s);
        }
        dismiss();
        return true;
      case R.id.bookmark_send:
        if (mBookInfo.getBookmarkCount() > 0) {
          String s = mBookInfo.getBookmarksExportText();
          mCoolReader.sendBookFragment(mBookInfo, s);
        }
        dismiss();
        return true;
    }
    return super.onContextItemSelected(item);
  }
예제 #3
0
파일: BookmarksDlg.java 프로젝트: pesgh/cr3
 private void listUpdated() {
   mList.setShortcutMode(mList.isShortcutMode());
 }