Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
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);
    }
  }