How to Scroll pdfView automatically with button click or volume buttons

Viewed 77

I'm using barteksc pdf viewer library to load pdf in my application.

pdfView = findViewById(R.id.pdfView);
            pdfView.fromAsset(getResources().getString(R.string.pdfname))
                    .enableDoubletap(true)
                    .enableSwipe(true)
                    .defaultPage(pageNumber)
                    .onPageChange(mainreading.this)
                    .pageFitPolicy(FitPolicy.WIDTH)
                    .pageFling(true)
                    .linkHandler(null)
                    .enableAnnotationRendering(true)
                    .swipeHorizontal(true)
                    .scrollHandle(new DefaultScrollHandlenew(mainreading.this))
                    .enableAntialiasing(true)
                    .load();
        }

I want pdf to start scroll automatically when user click the button of volume up and down buttons to start stop. I tried with below code while wrapping it in the handler with handler.performClick(); but it shows blank screen while scrolling up and down.

    scrollbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pdfView.scrollTo(0, pdfView.getScrollY() + 24);
        }
    });

Example : https://play.google.com/store/apps/details?id=com.emptysheet.pdfreader_autoscroll&hl=en&gl=US

I want to make as like this. Can anyone help please.

Also tried with this. But it shows blank page after some scrolls.

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                pdfView.scrollTo(0, pdfView.getScrollY() -24);
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                pdfView.scrollTo(0, pdfView.getScrollY() + 24);
            }
            return true;
        default:
            return super.dispatchKeyEvent(event);
    }
}
0 Answers
Related