コード例 #1
0
 private void startPDF(SharedPreferences options) {
   this.pdf = this.getPDF();
   if (!this.pdf.isValid()) {
     Log.v(TAG, "Invalid PDF");
     if (this.pdf.isInvalidPassword()) {
       Toast.makeText(this, "This file needs a password", Toast.LENGTH_SHORT).show();
     } else {
       Toast.makeText(this, "Invalid PDF file", Toast.LENGTH_SHORT).show();
     }
     return;
   }
   this.colorMode = Options.getColorMode(options);
   this.pdfPagesProvider =
       new PDFPagesProvider(
           this,
           pdf,
           options.getBoolean(Options.PREF_OMIT_IMAGES, false),
           options.getBoolean(Options.PREF_RENDER_AHEAD, true));
   pagesView.setPagesProvider(pdfPagesProvider);
   Bookmark b = new Bookmark(this.getApplicationContext()).open();
   pagesView.setStartBookmark(b, filePath);
   b.close();
 }
コード例 #2
0
  /**
   * Called when the activity is first created. TODO: initialize dialog fast, then move file loading
   * to other thread TODO: add progress bar for file load TODO: add progress icon for file rendering
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Options.setOrientation(this);
    SharedPreferences options = PreferenceManager.getDefaultSharedPreferences(this);

    this.box = Integer.parseInt(options.getString(Options.PREF_BOX, "2"));
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Get display metrics
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    // use a relative layout to stack the views
    activityLayout = new RelativeLayout(this);

    // the PDF view
    this.pagesView = new PagesView(this);
    activityLayout.addView(pagesView);
    startPDF(options);
    if (!this.pdf.isValid()) {
      finish();
    }

    // #ifdef pro
    //         /* TODO: move to separate method */
    //         LinearLayout textReflowLayout = new LinearLayout(this);
    //         this.textReflowView = textReflowLayout;
    //         textReflowLayout.setOrientation(LinearLayout.VERTICAL);
    //
    //         this.textReflowScrollView = new ScrollView(this);
    //         this.textReflowScrollView.setFillViewport(true);
    //
    //         this.textReflowTextView = new TextView(this);
    //
    //         LinearLayout textReflowButtonsLayout = new LinearLayout(this);
    //         textReflowButtonsLayout.setGravity(Gravity.CENTER);
    //         textReflowButtonsLayout.setOrientation(LinearLayout.HORIZONTAL);
    //         Button textReflowPrevPageButton = new Button(this);
    //         textReflowPrevPageButton.setText("Prev");
    //         textReflowPrevPageButton.setOnClickListener(new OnClickListener() {
    // 			public void onClick(View v) {
    // 				OpenFileActivity.this.nextPage(-1);
    // 			}
    //         });
    //         Button textReflowNextPageButton = new Button(this);
    //         textReflowNextPageButton.setText("Next");
    //         textReflowNextPageButton.setOnClickListener(new OnClickListener() {
    //         	public void onClick(View v) {
    //         		OpenFileActivity.this.nextPage(1);
    //         	}
    //         });
    //         textReflowButtonsLayout.addView(textReflowPrevPageButton);
    //         textReflowButtonsLayout.addView(textReflowNextPageButton);
    //
    //         this.textReflowScrollView.addView(this.textReflowTextView);
    //         LinearLayout.LayoutParams textReflowScrollViewLayoutParams = new
    // LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1);
    //         textReflowLayout.addView(this.textReflowScrollView,
    // textReflowScrollViewLayoutParams);
    //         textReflowLayout.addView(textReflowButtonsLayout, new
    // LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0));
    //
    //         activityLayout.addView(this.textReflowView, new
    // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
    // RelativeLayout.LayoutParams.FILL_PARENT));
    //         this.textReflowView.setVisibility(View.GONE);
    //         AndroidReflections.setScrollbarFadingEnabled(this.textReflowView, true);
    // #endif

    // the find buttons
    this.findButtonsLayout = new LinearLayout(this);
    this.findButtonsLayout.setOrientation(LinearLayout.HORIZONTAL);
    this.findButtonsLayout.setVisibility(View.GONE);
    this.findButtonsLayout.setGravity(Gravity.CENTER);
    this.findPrevButton = new Button(this);
    this.findPrevButton.setText("Prev");
    this.findButtonsLayout.addView(this.findPrevButton);
    this.findNextButton = new Button(this);
    this.findNextButton.setText("Next");
    this.findButtonsLayout.addView(this.findNextButton);
    this.findHideButton = new Button(this);
    this.findHideButton.setText("Hide");
    this.findButtonsLayout.addView(this.findHideButton);
    this.setFindButtonHandlers();
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    activityLayout.addView(this.findButtonsLayout, lp);

    this.pageNumberTextView = new TextView(this);
    this.pageNumberTextView.setTextSize(8f * metrics.density);
    lp =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    activityLayout.addView(this.pageNumberTextView, lp);

    // display this
    this.setContentView(activityLayout);

    // go to last viewed page
    //        gotoLastPage();

    // send keyboard events to this view
    pagesView.setFocusable(true);
    pagesView.setFocusableInTouchMode(true);

    this.zoomHandler = new Handler();
    this.pageHandler = new Handler();
    this.zoomRunnable =
        new Runnable() {
          public void run() {
            fadeZoom();
          }
        };
    this.pageRunnable =
        new Runnable() {
          public void run() {
            fadePage();
          }
        };
  }