Skip to content

Instantly share code, notes, and snippets.

@voghDev
Last active May 28, 2018 11:40
Show Gist options
  • Save voghDev/faa5036f076931c8780efe7f53e458a8 to your computer and use it in GitHub Desktop.
Save voghDev/faa5036f076931c8780efe7f53e458a8 to your computer and use it in GitHub Desktop.
Java version of the Kotlin SubsamplingPdfPagerAdapter. Requires version 1.0.4 of PdfViewPager
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.pdf.PdfRenderer;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import es.voghdev.pdfviewpager.library.R;
@SuppressWarnings("NewApi")
public class SubsamplingPdfPagerAdapter extends BasePDFPagerAdapter {
public SubsamplingPdfPagerAdapter(Context context, String pdfPath) {
super(context, pdfPath);
}
public SubsamplingPdfPagerAdapter(Context context, String pdfPath, int offScreenSize) {
super(context, pdfPath, offScreenSize);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View v = inflater.inflate(R.layout.view_pdf_page, container, false);
SubsamplingScaleImageView ssiv = (SubsamplingScaleImageView)
v.findViewById(R.id.subsamplingImageView);
if (renderer == null || getCount() < position) {
return v;
}
PdfRenderer.Page page = getPDFPage(renderer, position);
Bitmap bitmap = bitmapContainer.get(position);
page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
page.close();
ssiv.setImage(ImageSource.bitmap(bitmap));
((ViewPager) container).addView(v, 0);
return v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment