return loaders during rendering

This commit is contained in:
contrudar 2016-10-26 12:20:16 +03:00
parent c54d55d661
commit 203c4585aa
1 changed files with 47 additions and 53 deletions

View File

@ -283,70 +283,64 @@ public class PdfViewerFragment extends Fragment {
// TODO: refactor
private void showPage(final int page) {
// on some Android getWidth() and getHeight() returns 0, so we need to wait until UI is ready
mGraphView.post(new Runnable() {
@Override
public void run() {
try {
// free memory from previous page
mGraphView.setPageBitmap(null);
mGraphView.updateImage();
try {
// free memory from previous page
mGraphView.setPageBitmap(null);
mGraphView.updateImage();
// Only load the page if it's a different page (i.e. not just changing the zoom level)
if (mPdfPage == null || mPdfPage.getPageNumber() != page) {
mPdfPage = mPdfFile.getPage(page, true);
}
// Only load the page if it's a different page (i.e. not just changing the zoom level)
if (mPdfPage == null || mPdfPage.getPageNumber() != page) {
mPdfPage = mPdfFile.getPage(page, true);
}
final int scale = 3;
final int scale = 3;
double width = mPdfPage.getWidth() * scale;
double height = mPdfPage.getHeight() * scale;
double width = mPdfPage.getWidth() * scale;
double height = mPdfPage.getHeight() * scale;
int maxWidthToPopulate = mGraphView.getWidth();
int maxHeightToPopulate = mGraphView.getHeight();
int maxWidthToPopulate = mGraphView.getWidth();
int maxHeightToPopulate = mGraphView.getHeight();
int calculatedWidth;
int calculatedHeight;
final double widthRatio = width / maxWidthToPopulate;
final double heightRatio = height / maxHeightToPopulate;
if (width < maxWidthToPopulate && height < maxHeightToPopulate) {
if (widthRatio > heightRatio) {
calculatedWidth = (int) (width / widthRatio);
calculatedHeight = (int) (height / widthRatio);
} else {
calculatedWidth = (int) (width / heightRatio);
calculatedHeight = (int) (height / heightRatio);
}
int calculatedWidth;
int calculatedHeight;
final double widthRatio = width / maxWidthToPopulate;
final double heightRatio = height / maxHeightToPopulate;
if (width < maxWidthToPopulate && height < maxHeightToPopulate) {
if (widthRatio > heightRatio) {
calculatedWidth = (int) (width / widthRatio);
calculatedHeight = (int) (height / widthRatio);
} else {
calculatedWidth = (int) (width / heightRatio);
calculatedHeight = (int) (height / heightRatio);
}
} else {
if (widthRatio > 1 && heightRatio > 1) {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
if (widthRatio > 1 && heightRatio > 1) {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
} else {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
}
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
} else {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
final Bitmap bitmap = mPdfPage.getImage(calculatedWidth, calculatedHeight, null, true, true);
mGraphView.setPageBitmap(bitmap);
mGraphView.updateImage();
} catch (Throwable e) {
Log.e(TAG, e.getMessage(), e);
}
}
});
final Bitmap bitmap = mPdfPage.getImage(calculatedWidth, calculatedHeight, null, true, true);
mGraphView.setPageBitmap(bitmap);
mGraphView.updateImage();
} catch (Throwable e) {
Log.e(TAG, e.getMessage(), e);
}
hideProgressBar();
}
private void hideProgressBar() {