|
1 | 1 | /** |
2 | 2 | * Copyright 2016 Bartosz Schiller |
3 | | - * <p/> |
| 3 | + * <p> |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | | - * <p/> |
| 7 | + * <p> |
8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * <p/> |
| 9 | + * <p> |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
24 | 24 | import android.graphics.PointF; |
25 | 25 | import android.graphics.Rect; |
26 | 26 | import android.graphics.RectF; |
| 27 | +import android.net.Uri; |
27 | 28 | import android.os.AsyncTask; |
28 | 29 | import android.util.AttributeSet; |
29 | 30 | import android.util.Log; |
@@ -279,7 +280,6 @@ public PDFView(Context context, AttributeSet set) { |
279 | 280 | animationManager = new AnimationManager(this); |
280 | 281 | dragPinchManager = new DragPinchManager(this); |
281 | 282 |
|
282 | | - |
283 | 283 | paint = new Paint(); |
284 | 284 | debugPaint = new Paint(); |
285 | 285 | debugPaint.setStyle(Style.STROKE); |
@@ -352,10 +352,11 @@ void showPage(int pageNb) { |
352 | 352 |
|
353 | 353 | // Reset the zoom and center the page on the screen |
354 | 354 | resetZoom(); |
355 | | - if (swipeVertical) |
| 355 | + if (swipeVertical) { |
356 | 356 | animationManager.startYAnimation(currentYOffset, calculateCenterOffsetForPage(pageNb)); |
357 | | - else |
| 357 | + } else { |
358 | 358 | animationManager.startXAnimation(currentXOffset, calculateCenterOffsetForPage(pageNb)); |
| 359 | + } |
359 | 360 | loadPages(); |
360 | 361 |
|
361 | 362 | if (scrollBar != null) { |
@@ -410,8 +411,9 @@ public void recycle() { |
410 | 411 | if (pdfiumCore != null && pdfDocument != null) { |
411 | 412 | pdfiumCore.closeDocument(pdfDocument); |
412 | 413 | } |
413 | | - openedPages.clear(); |
414 | 414 |
|
| 415 | + openedPages.clear(); |
| 416 | + pdfDocument = null; |
415 | 417 | recycled = true; |
416 | 418 | state = State.DEFAULT; |
417 | 419 | } |
@@ -611,7 +613,7 @@ public void loadPages() { |
611 | 613 |
|
612 | 614 | /** |
613 | 615 | * Render a page, creating 1 to <i>nbOfPartsLoadable</i> page parts. <br><br> |
614 | | - * <p> |
| 616 | + * <p/> |
615 | 617 | * This is one of the trickiest method of this library. It finds |
616 | 618 | * the DocumentPage associated with the given UserPage, loads its |
617 | 619 | * thumbnail, cut this page into 256x256 blocs considering the |
@@ -959,7 +961,6 @@ public void moveTo(float offsetX, float offsetY) { |
959 | 961 | } |
960 | 962 |
|
961 | 963 | } else { |
962 | | - |
963 | 964 | float maxY = calculateCenterOffsetForPage(currentFilteredPage + 1); |
964 | 965 | float minY = calculateCenterOffsetForPage(currentFilteredPage - 1); |
965 | 966 | if (offsetY < maxY) { |
@@ -995,7 +996,6 @@ public void moveTo(float offsetX, float offsetY) { |
995 | 996 | } |
996 | 997 |
|
997 | 998 | } else { |
998 | | - |
999 | 999 | float maxX = calculateCenterOffsetForPage(currentFilteredPage + 1); |
1000 | 1000 | float minX = calculateCenterOffsetForPage(currentFilteredPage - 1); |
1001 | 1001 | if (offsetX < maxX) { |
@@ -1088,6 +1088,10 @@ public float getOptimalPageWidth() { |
1088 | 1088 | return optimalPageWidth; |
1089 | 1089 | } |
1090 | 1090 |
|
| 1091 | + public float getOptimalPageHeight() { |
| 1092 | + return optimalPageHeight; |
| 1093 | + } |
| 1094 | + |
1091 | 1095 | private void setUserWantsMinimap(boolean userWantsMinimap) { |
1092 | 1096 | this.userWantsMinimap = userWantsMinimap; |
1093 | 1097 | } |
@@ -1166,11 +1170,19 @@ public Configurator fromAsset(String assetName) { |
1166 | 1170 | * Use a file as the pdf source |
1167 | 1171 | */ |
1168 | 1172 | public Configurator fromFile(File file) { |
1169 | | - if (!file.exists()) |
1170 | | - throw new FileNotFoundException(file.getAbsolutePath() + "does not exist."); |
| 1173 | + if (!file.exists()) { |
| 1174 | + throw new FileNotFoundException(file.getAbsolutePath() + " does not exist."); |
| 1175 | + } |
1171 | 1176 | return new Configurator(file.getAbsolutePath(), false); |
1172 | 1177 | } |
1173 | 1178 |
|
| 1179 | + /** |
| 1180 | + * Use URI as the pdf source, for use with content providers |
| 1181 | + */ |
| 1182 | + public Configurator fromUri(Uri uri) { |
| 1183 | + return new Configurator(uri.toString(), false); |
| 1184 | + } |
| 1185 | + |
1174 | 1186 | private enum State {DEFAULT, LOADED, SHOWN} |
1175 | 1187 |
|
1176 | 1188 | public class Configurator { |
|
0 commit comments