Esempio n. 1
0
 private void reflowModeSet(boolean reflow) {
   mReflow = reflow;
   mDocView.setAdapter(
       mReflow ? new MuPDFReflowAdapter(this, core) : new MuPDFPageAdapter(this, this, core));
   mReflowButton.setColorFilter(
       mReflow ? Color.argb(0xFF, 172, 114, 37) : Color.argb(0xFF, 255, 255, 255));
   setButtonEnabled(mAnnotButton, !reflow);
   setButtonEnabled(mSearchButton, !reflow);
   if (reflow) setLinkHighlight(false);
   setButtonEnabled(mLinkButton, !reflow);
   setButtonEnabled(mMoreButton, !reflow);
   mDocView.refresh(mReflow);
 }
Esempio n. 2
0
 private void search(int direction) {
   hideKeyboard();
   int displayPage = mDocView.getDisplayedViewIndex();
   SearchTaskResult r = SearchTaskResult.get();
   int searchPage = r != null ? r.pageNumber : -1;
   mSearchTask.go(mSearchText.getText().toString(), direction, displayPage, searchPage);
 }
Esempio n. 3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case OUTLINE_REQUEST:
        if (resultCode >= 0) mDocView.setDisplayedViewIndex(resultCode);
        break;
      case PRINT_REQUEST:
        if (resultCode == RESULT_CANCELED) showInfo(getString(R.string.print_failed));
        break;
      case FILEPICK_REQUEST:
        if (mFilePicker != null && resultCode == RESULT_OK) mFilePicker.onPick(data.getData());
      case PROOF_REQUEST:
        //  we're returning from a proofing activity

        if (mProofFile != null) {
          core.endProof(mProofFile);
          mProofFile = null;
        }

        //  return the top bar to default
        mTopBarMode = TopBarMode.Main;
        mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
    }

    super.onActivityResult(requestCode, resultCode, data);
  }
Esempio n. 4
0
 public void OnCancelAcceptButtonClick(View v) {
   MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
   if (pageView != null) {
     pageView.deselectText();
     pageView.cancelDraw();
   }
   mDocView.setMode(MuPDFReaderView.Mode.Viewing);
   switch (mAcceptMode) {
     case CopyText:
       mTopBarMode = TopBarMode.More;
       break;
     default:
       mTopBarMode = TopBarMode.Annot;
       break;
   }
   mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
 }
Esempio n. 5
0
 public void OnInkButtonClick(View v) {
   mTopBarMode = TopBarMode.Accept;
   mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
   mAcceptMode = AcceptMode.Ink;
   mDocView.setMode(MuPDFReaderView.Mode.Drawing);
   mAnnotTypeText.setText(R.string.ink);
   showInfo(getString(R.string.draw_annotation));
 }
Esempio n. 6
0
 public void OnStrikeOutButtonClick(View v) {
   mTopBarMode = TopBarMode.Accept;
   mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
   mAcceptMode = AcceptMode.StrikeOut;
   mDocView.setMode(MuPDFReaderView.Mode.Selecting);
   mAnnotTypeText.setText(R.string.strike_out);
   showInfo(getString(R.string.select_text));
 }
Esempio n. 7
0
 private void setLinkHighlight(boolean highlight) {
   mLinkHighlight = highlight;
   // LINK_COLOR tint
   mLinkButton.setColorFilter(
       highlight ? Color.argb(0xFF, 172, 114, 37) : Color.argb(0xFF, 255, 255, 255));
   // Inform pages of the change.
   mDocView.setLinksEnabled(highlight);
 }
Esempio n. 8
0
 //  start a proof activity with the given resolution.
 public void proofWithResolution(int resolution) {
   mProofFile = core.startProof(resolution);
   Uri uri = Uri.parse("file://" + mProofFile);
   Intent intent = new Intent(this, MuPDFActivity.class);
   intent.setAction(Intent.ACTION_VIEW);
   intent.setData(uri);
   // add the current page so it can be found when the activity is running
   intent.putExtra("startingPage", mDocView.getDisplayedViewIndex());
   startActivityForResult(intent, PROOF_REQUEST);
 }
Esempio n. 9
0
 private void searchModeOff() {
   if (mTopBarMode == TopBarMode.Search) {
     mTopBarMode = TopBarMode.Main;
     hideKeyboard();
     mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
     SearchTaskResult.set(null);
     // Make the ReaderView act on the change to mSearchTaskResult
     // via overridden onChildSetup method.
     mDocView.resetupChildren();
   }
 }
Esempio n. 10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RelativeLayout mContentView = (RelativeLayout) findViewById(R.id.content_view);

    try {
      InputStream ins = getResources().getAssets().open("MuPdf.pdf");
      FileOutputStream fos = new FileOutputStream(new File(getExternalCacheDir() + "/1.pdf"));
      byte[] b = new byte[1024];
      while (ins.read(b) != -1) {
        fos.write(b);
      }
      fos.flush();
    } catch (Exception e) {
      e.printStackTrace();
    }

    Uri uri = Uri.parse(getExternalCacheDir() + "/1.pdf");
    core = openFile(uri.getPath());
    if (core != null && core.countPages() == 0) {
      core = null;
    }
    if (core == null || core.countPages() == 0 || core.countPages() == -1) {
      Log.e(TAG, "Document Not Opening");
    }
    if (core != null) {
      MuPDFReaderView mDocView =
          new MuPDFReaderView(this) {
            @Override
            protected void onMoveToChild(int i) {
              if (core == null) return;
              super.onMoveToChild(i);
            }
          };
      mDocView.setAdapter(new MuPDFPageAdapter(this, null, core));
      mContentView.addView(mDocView);
    }
  }
Esempio n. 11
0
  public void OnAcceptButtonClick(View v) {
    MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
    boolean success = false;
    switch (mAcceptMode) {
      case CopyText:
        if (pageView != null) success = pageView.copySelection();
        mTopBarMode = TopBarMode.More;
        showInfo(
            success
                ? getString(R.string.copied_to_clipboard)
                : getString(R.string.no_text_selected));
        break;

      case Highlight:
        if (pageView != null) success = pageView.markupSelection(Annotation.Type.HIGHLIGHT);
        mTopBarMode = TopBarMode.Annot;
        if (!success) showInfo(getString(R.string.no_text_selected));
        break;

      case Underline:
        if (pageView != null) success = pageView.markupSelection(Annotation.Type.UNDERLINE);
        mTopBarMode = TopBarMode.Annot;
        if (!success) showInfo(getString(R.string.no_text_selected));
        break;

      case StrikeOut:
        if (pageView != null) success = pageView.markupSelection(Annotation.Type.STRIKEOUT);
        mTopBarMode = TopBarMode.Annot;
        if (!success) showInfo(getString(R.string.no_text_selected));
        break;

      case Ink:
        if (pageView != null) success = pageView.saveDraw();
        mTopBarMode = TopBarMode.Annot;
        if (!success) showInfo(getString(R.string.nothing_to_save));
        break;
    }
    mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
    mDocView.setMode(MuPDFReaderView.Mode.Viewing);
  }
Esempio n. 12
0
  @Override
  protected void onPause() {
    super.onPause();

    if (mSearchTask != null) mSearchTask.stop();

    if (mFileName != null && mDocView != null) {
      SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
      SharedPreferences.Editor edit = prefs.edit();
      edit.putInt("page" + mFileName, mDocView.getDisplayedViewIndex());
      edit.commit();
    }
  }
Esempio n. 13
0
 public void onDestroy() {
   if (null != mDocView) {
     mDocView.applyToChildren(
         new AKReaderView.ViewMapper() {
           void applyToView(View view) {
             ((MuPDFView) view).releaseBitmaps();
           }
         });
   }
   if (core != null) core.onDestroy();
   if (mAlertTask != null) {
     mAlertTask.cancel(true);
     mAlertTask = null;
   }
   core = null;
   super.onDestroy();
 }
Esempio n. 14
0
  private void showButtons() {
    if (core == null) return;
    if (!mButtonsVisible) {
      mButtonsVisible = true;
      // Update page number text and slider
      int index = mDocView.getDisplayedViewIndex();
      updatePageNumView(index);
      mPageSlider.setMax((core.countPages() - 1) * mPageSliderRes);
      mPageSlider.setProgress(index * mPageSliderRes);
      if (mTopBarMode == TopBarMode.Search) {
        mSearchText.requestFocus();
        showKeyboard();
      }

      Animation anim = new TranslateAnimation(0, 0, -mTopBarSwitcher.getHeight(), 0);
      anim.setDuration(200);
      anim.setAnimationListener(
          new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
              mTopBarSwitcher.setVisibility(View.VISIBLE);
            }

            public void onAnimationRepeat(Animation animation) {}

            public void onAnimationEnd(Animation animation) {}
          });
      mTopBarSwitcher.startAnimation(anim);

      anim = new TranslateAnimation(0, 0, mPageSlider.getHeight(), 0);
      anim.setDuration(200);
      anim.setAnimationListener(
          new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
              mPageSlider.setVisibility(View.VISIBLE);
            }

            public void onAnimationRepeat(Animation animation) {}

            public void onAnimationEnd(Animation animation) {
              mPageNumberView.setVisibility(View.VISIBLE);
            }
          });
      mPageSlider.startAnimation(anim);
    }
  }
Esempio n. 15
0
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    if (mFileName != null && mDocView != null) {
      outState.putString("FileName", mFileName);

      // Store current page in the prefs against the file name,
      // so that we can pick it up each time the file is loaded
      // Other info is needed only for screen-orientation change,
      // so it can go in the bundle
      SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
      SharedPreferences.Editor edit = prefs.edit();
      edit.putInt("page" + mFileName, mDocView.getDisplayedViewIndex());
      edit.commit();
    }

    if (!mButtonsVisible) outState.putBoolean("ButtonsHidden", true);

    if (mTopBarMode == TopBarMode.Search) outState.putBoolean("SearchMode", true);

    if (mReflow) outState.putBoolean("ReflowMode", true);
  }
Esempio n. 16
0
  public void createUI(Bundle savedInstanceState) {
    if (core == null) return;

    // Now create the UI.
    // First create the document view
    mDocView =
        new MuPDFReaderView(this) {
          @Override
          protected void onMoveToChild(int i) {
            if (core == null) return;

            mPageNumberView.setText(String.format("%d / %d", i + 1, core.countPages()));
            mPageSlider.setMax((core.countPages() - 1) * mPageSliderRes);
            mPageSlider.setProgress(i * mPageSliderRes);
            super.onMoveToChild(i);
          }

          @Override
          protected void onTapMainDocArea() {
            if (!mButtonsVisible) {
              showButtons();
            } else {
              if (mTopBarMode == TopBarMode.Main) hideButtons();
            }
          }

          @Override
          protected void onDocMotion() {
            hideButtons();
          }

          @Override
          protected void onHit(Hit item) {
            switch (mTopBarMode) {
              case Annot:
                if (item == Hit.Annotation) {
                  showButtons();
                  mTopBarMode = TopBarMode.Delete;
                  mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
                }
                break;
              case Delete:
                mTopBarMode = TopBarMode.Annot;
                mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
                // fall through
              default:
                // Not in annotation editing mode, but the pageview will
                // still select and highlight hit annotations, so
                // deselect just in case.
                MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
                if (pageView != null) pageView.deselectAnnotation();
                break;
            }
          }
        };
    mDocView.setAdapter(new MuPDFPageAdapter(this, this, core));

    mSearchTask =
        new SearchTask(this, core) {
          @Override
          protected void onTextFound(SearchTaskResult result) {
            SearchTaskResult.set(result);
            // Ask the ReaderView to move to the resulting page
            mDocView.setDisplayedViewIndex(result.pageNumber);
            // Make the ReaderView act on the change to SearchTaskResult
            // via overridden onChildSetup method.
            mDocView.resetupChildren();
          }
        };

    // Make the buttons overlay, and store all its
    // controls in variables
    makeButtonsView();

    // Set up the page slider
    int smax = Math.max(core.countPages() - 1, 1);
    mPageSliderRes = ((10 + smax - 1) / smax) * 2;

    // Set the file-name text
    mFilenameView.setText(mFileName);

    // Activate the seekbar
    mPageSlider.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          public void onStopTrackingTouch(SeekBar seekBar) {
            mDocView.setDisplayedViewIndex(
                (seekBar.getProgress() + mPageSliderRes / 2) / mPageSliderRes);
          }

          public void onStartTrackingTouch(SeekBar seekBar) {}

          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updatePageNumView((progress + mPageSliderRes / 2) / mPageSliderRes);
          }
        });

    // Activate the search-preparing button
    mSearchButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            searchModeOn();
          }
        });

    // Activate the reflow button
    mReflowButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            toggleReflow();
          }
        });

    if (core.fileFormat().startsWith("PDF")
        && core.isUnencryptedPDF()
        && !core.wasOpenedFromBuffer()) {
      mAnnotButton.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              mTopBarMode = TopBarMode.Annot;
              mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
            }
          });
    } else {
      mAnnotButton.setVisibility(View.GONE);
    }

    // Search invoking buttons are disabled while there is no text specified
    mSearchBack.setEnabled(false);
    mSearchFwd.setEnabled(false);
    mSearchBack.setColorFilter(Color.argb(255, 128, 128, 128));
    mSearchFwd.setColorFilter(Color.argb(255, 128, 128, 128));

    // React to interaction with the text widget
    mSearchText.addTextChangedListener(
        new TextWatcher() {

          public void afterTextChanged(Editable s) {
            boolean haveText = s.toString().length() > 0;
            setButtonEnabled(mSearchBack, haveText);
            setButtonEnabled(mSearchFwd, haveText);

            // Remove any previous search results
            if (SearchTaskResult.get() != null
                && !mSearchText.getText().toString().equals(SearchTaskResult.get().txt)) {
              SearchTaskResult.set(null);
              mDocView.resetupChildren();
            }
          }

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });

    // React to Done button on keyboard
    mSearchText.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) search(1);
            return false;
          }
        });

    mSearchText.setOnKeyListener(
        new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER)
              search(1);
            return false;
          }
        });

    // Activate search invoking buttons
    mSearchBack.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            search(-1);
          }
        });
    mSearchFwd.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            search(1);
          }
        });

    mLinkButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            setLinkHighlight(!mLinkHighlight);
          }
        });

    if (core.hasOutline()) {
      mOutlineButton.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              OutlineItem outline[] = core.getOutline();
              if (outline != null) {
                OutlineActivityData.get().items = outline;
                Intent intent = new Intent(MuPDFActivity.this, OutlineActivity.class);
                intent.putExtra("cp", mDocView.getDisplayedViewIndex());
                startActivityForResult(intent, OUTLINE_REQUEST);
              }
            }
          });
    } else {
      mOutlineButton.setVisibility(View.GONE);
    }

    // Reenstate last state if it was recorded
    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    mDocView.setDisplayedViewIndex(prefs.getInt("page" + mFileName, 0));

    if (savedInstanceState == null || !savedInstanceState.getBoolean("ButtonsHidden", false))
      showButtons();

    if (savedInstanceState != null && savedInstanceState.getBoolean("SearchMode", false))
      searchModeOn();

    if (savedInstanceState != null && savedInstanceState.getBoolean("ReflowMode", false))
      reflowModeSet(true);

    // Stick the document view and the buttons overlay into a parent view
    RelativeLayout layout = new RelativeLayout(this);
    layout.addView(mDocView);
    layout.addView(mButtonsView);
    setContentView(layout);

    if (isProofing()) {
      //  go to the current page
      int currentPage = getIntent().getIntExtra("startingPage", 0);
      mDocView.setDisplayedViewIndex(currentPage);
    }
  }
Esempio n. 17
0
  public void OnSepsButtonClick(final View v) {
    if (isProofing()) {

      //  get the current page
      final int currentPage = mDocView.getDisplayedViewIndex();

      //  buid a popup menu based on the given separations
      final PopupMenu menu = new PopupMenu(this, v);

      //  This makes the popup menu display icons, which by default it does not do.
      //  I worry that this relies on the internals of PopupMenu, which could change.
      try {
        Field[] fields = menu.getClass().getDeclaredFields();
        for (Field field : fields) {
          if ("mPopup".equals(field.getName())) {
            field.setAccessible(true);
            Object menuPopupHelper = field.get(menu);
            Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
            Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
            setForceIcons.invoke(menuPopupHelper, true);
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      //  get the maximum number of seps on any page.
      //  We use this to dimension an array further down
      int maxSeps = 0;
      int numPages = core.countPages();
      for (int page = 0; page < numPages; page++) {
        int numSeps = core.getNumSepsOnPage(page);
        if (numSeps > maxSeps) maxSeps = numSeps;
      }

      //  if this is the first time, create the "enabled" array
      if (mSepEnabled == null) {
        mSepEnabled = new boolean[numPages][maxSeps];
        for (int page = 0; page < numPages; page++) {
          for (int i = 0; i < maxSeps; i++) mSepEnabled[page][i] = true;
        }
      }

      //  count the seps on this page
      int numSeps = core.getNumSepsOnPage(currentPage);

      //  for each sep,
      for (int i = 0; i < numSeps; i++) {

        //				//  Robin use this to skip separations
        //				if (i==12)
        //					break;

        //  get the name
        Separation sep = core.getSep(currentPage, i);
        String name = sep.name;

        //  make a checkable menu item with that name
        //  and the separation index as the id
        MenuItem item = menu.getMenu().add(0, i, 0, name + "    ");
        item.setCheckable(true);

        //  set an icon that's the right color
        int iconSize = 48;
        int alpha = (sep.rgba >> 24) & 0xFF;
        int red = (sep.rgba >> 16) & 0xFF;
        int green = (sep.rgba >> 8) & 0xFF;
        int blue = (sep.rgba >> 0) & 0xFF;
        int color = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

        ShapeDrawable swatch = new ShapeDrawable(new RectShape());
        swatch.setIntrinsicHeight(iconSize);
        swatch.setIntrinsicWidth(iconSize);
        swatch.setBounds(new Rect(0, 0, iconSize, iconSize));
        swatch.getPaint().setColor(color);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        item.setIcon(swatch);

        //  check it (or not)
        item.setChecked(mSepEnabled[currentPage][i]);

        //  establishing a menu item listener
        item.setOnMenuItemClickListener(
            new OnMenuItemClickListener() {
              @Override
              public boolean onMenuItemClick(MenuItem item) {
                //  someone tapped a menu item.  get the ID
                int sep = item.getItemId();

                //  toggle the sep
                mSepEnabled[currentPage][sep] = !mSepEnabled[currentPage][sep];
                item.setChecked(mSepEnabled[currentPage][sep]);
                core.controlSepOnPage(currentPage, sep, !mSepEnabled[currentPage][sep]);

                //  prevent the menu from being dismissed by these items
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
                item.setActionView(new View(v.getContext()));
                item.setOnActionExpandListener(
                    new MenuItem.OnActionExpandListener() {
                      @Override
                      public boolean onMenuItemActionExpand(MenuItem item) {
                        return false;
                      }

                      @Override
                      public boolean onMenuItemActionCollapse(MenuItem item) {
                        return false;
                      }
                    });
                return false;
              }
            });

        //  tell core to enable or disable each sep as appropriate
        //  but don't refresh the page yet.
        core.controlSepOnPage(currentPage, i, !mSepEnabled[currentPage][i]);
      }

      //  add one for done
      MenuItem itemDone = menu.getMenu().add(0, 0, 0, "Done");
      itemDone.setOnMenuItemClickListener(
          new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
              //  refresh the view
              mDocView.refresh(false);
              return true;
            }
          });

      //  show the menu
      menu.show();
    }
  }
Esempio n. 18
0
 public void OnCancelDeleteButtonClick(View v) {
   MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
   if (pageView != null) pageView.deselectAnnotation();
   mTopBarMode = TopBarMode.Annot;
   mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
 }