private void setZoomLayout(SharedPreferences options) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int colorMode = Options.getColorMode(options);
    int mode = ZOOM_COLOR_NORMAL;

    if (colorMode == Options.COLOR_MODE_GREEN_ON_BLACK) {
      mode = ZOOM_COLOR_GREEN;
    } else if (colorMode == Options.COLOR_MODE_RED_ON_BLACK) {
      mode = ZOOM_COLOR_RED;
    }

    // the zoom buttons
    if (zoomLayout != null) {
      activityLayout.removeView(zoomLayout);
    }

    zoomLayout = new LinearLayout(this);
    zoomLayout.setOrientation(LinearLayout.HORIZONTAL);
    zoomDownButton = new ImageButton(this);
    zoomDownButton.setImageDrawable(getResources().getDrawable(zoomDownId[mode]));
    zoomDownButton.setBackgroundColor(Color.TRANSPARENT);
    zoomLayout.addView(
        zoomDownButton,
        (int) (80 * metrics.density),
        (int) (50 * metrics.density)); // TODO: remove hardcoded values
    zoomWidthButton = new ImageButton(this);
    zoomWidthButton.setImageDrawable(getResources().getDrawable(zoomWidthId[mode]));
    zoomWidthButton.setBackgroundColor(Color.TRANSPARENT);
    zoomLayout.addView(zoomWidthButton, (int) (58 * metrics.density), (int) (50 * metrics.density));
    zoomUpButton = new ImageButton(this);
    zoomUpButton.setImageDrawable(getResources().getDrawable(zoomUpId[mode]));
    zoomUpButton.setBackgroundColor(Color.TRANSPARENT);
    zoomLayout.addView(zoomUpButton, (int) (80 * metrics.density), (int) (50 * metrics.density));
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    setZoomButtonHandlers();
    activityLayout.addView(zoomLayout, lp);
  }
 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();
 }
  @Override
  protected void onResume() {
    super.onResume();

    sensorManager = null;

    SharedPreferences options = PreferenceManager.getDefaultSharedPreferences(this);

    if (Options.setOrientation(this)) {
      sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
      if (sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() > 0) {
        gravity[0] = 0f;
        gravity[1] = -9.81f;
        gravity[2] = 0f;
        gravityAge = 0;
        sensorManager.registerListener(
            this,
            sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_NORMAL);
        this.prevOrientation =
            options.getInt(Options.PREF_PREV_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setRequestedOrientation(this.prevOrientation);
      } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      }
    }

    history = options.getBoolean(Options.PREF_HISTORY, true);
    boolean eink = options.getBoolean(Options.PREF_EINK, false);
    this.pagesView.setEink(eink);
    if (eink) this.setTheme(android.R.style.Theme_Light);
    this.pagesView.setNook2(options.getBoolean(Options.PREF_NOOK2, false));

    if (options.getBoolean(Options.PREF_KEEP_ON, false))
      this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    else this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    actions = new Actions(options);
    this.pagesView.setActions(actions);

    setZoomLayout(options);

    this.pagesView.setZoomLayout(zoomLayout);

    this.showZoomOnScroll = options.getBoolean(Options.PREF_SHOW_ZOOM_ON_SCROLL, false);
    this.pagesView.setSideMargins(
        Integer.parseInt(options.getString(Options.PREF_SIDE_MARGINS, "0")));
    this.pagesView.setTopMargin(Integer.parseInt(options.getString(Options.PREF_TOP_MARGIN, "0")));

    this.pagesView.setDoubleTap(
        Integer.parseInt(
            options.getString(Options.PREF_DOUBLE_TAP, "" + Options.DOUBLE_TAP_ZOOM_IN_OUT)));

    int newBox = Integer.parseInt(options.getString(Options.PREF_BOX, "2"));
    if (this.box != newBox) {
      saveLastPage();
      this.box = newBox;
      startPDF(options);
      this.pagesView.goToBookmark();
    }

    this.colorMode = Options.getColorMode(options);
    this.eink = options.getBoolean(Options.PREF_EINK, false);
    this.pageNumberTextView.setBackgroundColor(Options.getBackColor(colorMode));
    this.pageNumberTextView.setTextColor(Options.getForeColor(colorMode));
    this.pdfPagesProvider.setExtraCache(
        1024 * 1024 * Options.getIntFromString(options, Options.PREF_EXTRA_CACHE, 0));
    this.pdfPagesProvider.setOmitImages(options.getBoolean(Options.PREF_OMIT_IMAGES, false));
    this.pagesView.setColorMode(this.colorMode);

    this.pdfPagesProvider.setRenderAhead(options.getBoolean(Options.PREF_RENDER_AHEAD, true));
    this.pagesView.setVerticalScrollLock(
        options.getBoolean(Options.PREF_VERTICAL_SCROLL_LOCK, false));
    this.pagesView.invalidate();
    int zoomAnimNumber = Integer.parseInt(options.getString(Options.PREF_ZOOM_ANIMATION, "2"));

    if (zoomAnimNumber == Options.ZOOM_BUTTONS_DISABLED) zoomAnim = null;
    else zoomAnim = AnimationUtils.loadAnimation(this, zoomAnimations[zoomAnimNumber]);
    int pageNumberAnimNumber =
        Integer.parseInt(options.getString(Options.PREF_PAGE_ANIMATION, "3"));

    if (pageNumberAnimNumber == Options.PAGE_NUMBER_DISABLED) pageNumberAnim = null;
    else
      pageNumberAnim =
          AnimationUtils.loadAnimation(this, pageNumberAnimations[pageNumberAnimNumber]);

    fadeStartOffset = 1000 * Integer.parseInt(options.getString(Options.PREF_FADE_SPEED, "7"));

    if (options.getBoolean(Options.PREF_FULLSCREEN, false))
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    else getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.pageNumberTextView.setVisibility(pageNumberAnim == null ? View.GONE : View.VISIBLE);
    // #ifdef pro
    // 		this.zoomLayout.setVisibility((zoomAnim == null || this.textReflowMode) ? View.GONE :
    // View.VISIBLE);
    // #endif

    // #ifdef lite
    this.zoomLayout.setVisibility(zoomAnim == null ? View.GONE : View.VISIBLE);
    // #endif

    showAnimated(true);
  }