bTMP = new HashMap<>();
28 |
29 | class PDocPage {
30 | final int pageIdx;
31 | final Size size;
32 | public int startY = 0;
33 | public int startX = 0;
34 | public int maxX;
35 | public int maxY;
36 | long OffsetAlongScrollAxis;
37 | final AtomicLong pid=new AtomicLong();
38 | PDocPage(int pageIdx, Size size) {
39 | this.pageIdx = pageIdx;
40 | this.size = size;
41 | }
42 |
43 | public void open() {
44 | if(pid.get()==0) {
45 | synchronized(pid) {
46 | if(pid.get()==0) {
47 | pid.set(pdfiumCore.openPage(pdfDocument, pageIdx));
48 | }
49 | }
50 | }
51 | }
52 |
53 |
54 | @Override
55 | public String toString() {
56 | return "PDocPage{" +
57 | "pageIdx=" + pageIdx +
58 | '}';
59 | }
60 |
61 | public int getHorizontalOffset() {
62 | if(size.getWidth()!=maxPageWidth) {
63 | return (maxPageWidth-size.getWidth())/2;
64 | }
65 | return 0;
66 | }
67 | }
68 |
69 | public PDocument(Context c, String path) throws IOException {
70 | this.path = path;
71 | if(pdfiumCore==null) {
72 | pdfiumCore = new PdfiumCore(c);
73 | }
74 | File f = new File(path);
75 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
76 | pdfDocument = pdfiumCore.newDocument(pfd);
77 | _num_entries = pdfiumCore.getPageCount(pdfDocument);
78 | mPDocPages = new PDocPage[_num_entries];
79 | height=0;
80 | for (int i = 0; i < _num_entries; i++) {
81 | Size size = pdfiumCore.getPageSize(pdfDocument, i);
82 | PDocPage page = new PDocPage(i, size);
83 | mPDocPages[i]=page;
84 | page.OffsetAlongScrollAxis=height;
85 | height+=size.getHeight()+60;
86 | //if(i<10) CMN.Log("mPDocPages", i, size.getWidth(), size.getHeight());
87 | maxPageWidth = Math.max(maxPageWidth, size.getWidth());
88 | maxPageHeight = Math.max(maxPageHeight, size.getHeight());
89 | }
90 | if(_num_entries>0) {
91 | PDocPage page = mPDocPages[_num_entries-1];
92 | height = page.OffsetAlongScrollAxis+page.size.getHeight();
93 | }
94 | }
95 |
96 | public Bitmap renderBitmap(PDocPage page, Bitmap bitmap, float scale) {
97 | Size size = page.size;
98 | int w = (int) (size.getWidth()*scale);
99 | int h = (int) (size.getHeight()*scale);
100 | //CMN.Log("renderBitmap", w, h, bitmap.getWidth(), bitmap.getHeight());
101 | page.open();
102 | pdfiumCore.renderPageBitmap(pdfDocument, bitmap, page.pageIdx, 0, 0, w, h ,false);
103 | return bitmap;
104 | }
105 |
106 | public Bitmap renderRegionBitmap(PDocPage page, Bitmap bitmap, int startX, int startY, int srcW, int srcH) {
107 | int w = bitmap.getWidth();
108 | int h = bitmap.getHeight();
109 | page.open();
110 | //CMN.Log("renderRegion", w, h, startX, startY, srcW, srcH);
111 | pdfiumCore.renderPageBitmap(pdfDocument, bitmap, page.pageIdx, startX, startY, srcW, srcH ,false);
112 | return bitmap;
113 | }
114 |
115 | public Bitmap drawTumbnail(Bitmap bitmap, int pageIdx, float scale) {
116 | PDocPage page = mPDocPages[pageIdx];
117 | Size size = page.size;
118 | int w = (int) (size.getWidth()*scale);
119 | int h = (int) (size.getHeight()*scale);
120 | page.open();
121 | Bitmap OneSmallStep = bitmap;
122 | boolean recreate=OneSmallStep.isRecycled();
123 | if(!recreate && (w!=OneSmallStep.getWidth()||h!=OneSmallStep.getHeight())) {
124 | if(OneSmallStep.getAllocationByteCount()>=w*h*4) {
125 | OneSmallStep.reconfigure(w, h, Bitmap.Config.ARGB_8888);
126 | } else recreate=true;
127 | }
128 | if(recreate) {
129 | OneSmallStep.recycle();
130 | OneSmallStep = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
131 | }
132 | renderBitmap(page, OneSmallStep, scale);
133 | //pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageIdx, 0, 0, w, h ,false);
134 | return bitmap;
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/RenderingHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer;
17 |
18 | import android.graphics.Bitmap;
19 | import android.graphics.Matrix;
20 | import android.graphics.Rect;
21 | import android.graphics.RectF;
22 | import android.os.Handler;
23 | import android.os.Looper;
24 | import android.os.Message;
25 | import android.util.Log;
26 |
27 | import com.knizha.PDocViewer.exception.PageRenderingException;
28 | import com.knizha.PDocViewer.model.PagePart;
29 |
30 | /**
31 | * A {@link Handler} that will process incoming {@link RenderingTask} messages
32 | * and alert {@link PDocView#onBitmapRendered(PagePart)} when the portion of the
33 | * PDF is ready to render.
34 | */
35 | class RenderingHandler extends Handler {
36 | /**
37 | * {@link Message#what} kind of message this handler processes.
38 | */
39 | static final int MSG_RENDER_TASK = 1;
40 |
41 | private static final String TAG = RenderingHandler.class.getName();
42 |
43 | private PDocView pDocView;
44 |
45 | private RectF renderBounds = new RectF();
46 | private Rect roundedRenderBounds = new Rect();
47 | private Matrix renderMatrix = new Matrix();
48 | private boolean running = false;
49 |
50 | RenderingHandler(Looper looper, PDocView pDocView) {
51 | super(looper);
52 | this.pDocView = pDocView;
53 | }
54 |
55 | void addRenderingTask(int page, float width, float height, RectF bounds, boolean thumbnail, int cacheOrder, boolean bestQuality, boolean annotationRendering) {
56 | RenderingTask task = new RenderingTask(width, height, bounds, page, thumbnail, cacheOrder, bestQuality, annotationRendering);
57 | Message msg = obtainMessage(MSG_RENDER_TASK, task);
58 | sendMessage(msg);
59 | }
60 |
61 | //仅仅一个task哎
62 | @Override
63 | public void handleMessage(Message message) {
64 | RenderingTask task = (RenderingTask) message.obj;
65 | try {
66 | final PagePart part = proceed(task);
67 | if (part != null) {
68 | if (running) {
69 | pDocView.post(new Runnable() {
70 | @Override
71 | public void run() {
72 | pDocView.onBitmapRendered(part);
73 | }
74 | });
75 | } else {
76 | part.getRenderedBitmap().recycle();
77 | }
78 | }
79 | } catch (final PageRenderingException ex) {
80 | pDocView.post(new Runnable() {
81 | @Override
82 | public void run() {
83 | pDocView.onPageError(ex);
84 | }
85 | });
86 | }
87 | }
88 |
89 | private PagePart proceed(RenderingTask threadedTask) throws PageRenderingException {
90 | PdfFile processing_docfile = pDocView.pdfFile;
91 | processing_docfile.openPage(threadedTask.page);
92 | int w = Math.round(threadedTask.width);
93 | int h = Math.round(threadedTask.height);
94 | if (w == 0 || h == 0 || processing_docfile.pageHasError(threadedTask.page)) {
95 | return null;
96 | }
97 | Bitmap render;
98 | try {
99 | render = Bitmap.createBitmap(w, h, threadedTask.bestQuality ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
100 | } catch (IllegalArgumentException e) {
101 | Log.e(TAG, "Cannot create bitmap", e);
102 | return null;
103 | }
104 | calculateBounds(w, h, threadedTask.bounds);
105 |
106 | processing_docfile.renderPageBitmap(render, threadedTask.page, roundedRenderBounds, threadedTask.annotationRendering);
107 |
108 | return new PagePart(threadedTask.page, render,
109 | threadedTask.bounds, threadedTask.thumbnail,
110 | threadedTask.cacheOrder);
111 | }
112 |
113 | private void calculateBounds(int width, int height, RectF pageSliceBounds) {
114 | renderMatrix.reset();
115 | renderMatrix.postTranslate(-pageSliceBounds.left * width, -pageSliceBounds.top * height);
116 | renderMatrix.postScale(1 / pageSliceBounds.width(), 1 / pageSliceBounds.height());
117 |
118 | renderBounds.set(0, 0, width, height);
119 | renderMatrix.mapRect(renderBounds);
120 | renderBounds.round(roundedRenderBounds);
121 | }
122 |
123 | void stop() {
124 | running = false;
125 | }
126 |
127 | void start() {
128 | running = true;
129 | }
130 |
131 | private class RenderingTask {
132 | float width, height;
133 | RectF bounds;
134 | int page;
135 | boolean thumbnail;
136 | int cacheOrder;
137 | boolean bestQuality;
138 | boolean annotationRendering;
139 | RenderingTask(float width, float height, RectF bounds, int page, boolean thumbnail, int cacheOrder, boolean bestQuality, boolean annotationRendering) {
140 | this.page = page;
141 | this.width = width;
142 | this.height = height;
143 | this.bounds = bounds;
144 | this.thumbnail = thumbnail;
145 | this.cacheOrder = cacheOrder;
146 | this.bestQuality = bestQuality;
147 | this.annotationRendering = annotationRendering;
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/exception/FileNotFoundException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.exception;
17 |
18 | @Deprecated
19 | public class FileNotFoundException extends RuntimeException {
20 |
21 | public FileNotFoundException(String detailMessage) {
22 | super(detailMessage);
23 | }
24 |
25 | public FileNotFoundException(String detailMessage, Throwable throwable) {
26 | super(detailMessage, throwable);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/exception/PageRenderingException.java:
--------------------------------------------------------------------------------
1 | package com.knizha.PDocViewer.exception;
2 |
3 | public class PageRenderingException extends Exception {
4 | private final int page;
5 |
6 | public PageRenderingException(int page, Throwable cause) {
7 | super(cause);
8 | this.page = page;
9 | }
10 |
11 | public int getPage() {
12 | return page;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/link/DefaultLinkHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.link;
17 |
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.net.Uri;
21 | import android.util.Log;
22 |
23 | import com.knizha.PDocViewer.PDocView;
24 | import com.knizha.PDocViewer.model.LinkTapEvent;
25 |
26 | public class DefaultLinkHandler implements LinkHandler {
27 |
28 | private static final String TAG = DefaultLinkHandler.class.getSimpleName();
29 |
30 | private PDocView pDocView;
31 |
32 | public DefaultLinkHandler(PDocView pDocView) {
33 | this.pDocView = pDocView;
34 | }
35 |
36 | @Override
37 | public void handleLinkEvent(LinkTapEvent event) {
38 | String uri = event.getLink().getUri();
39 | Integer page = event.getLink().getDestPageIdx();
40 | if (uri != null && !uri.isEmpty()) {
41 | handleUri(uri);
42 | } else if (page != null) {
43 | handlePage(page);
44 | }
45 | }
46 |
47 | private void handleUri(String uri) {
48 | Uri parsedUri = Uri.parse(uri);
49 | Intent intent = new Intent(Intent.ACTION_VIEW, parsedUri);
50 | Context context = pDocView.getContext();
51 | if (intent.resolveActivity(context.getPackageManager()) != null) {
52 | context.startActivity(intent);
53 | } else {
54 | Log.w(TAG, "No activity found for URI: " + uri);
55 | }
56 | }
57 |
58 | private void handlePage(int page) {
59 | pDocView.jumpTo(page);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/link/LinkHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.link;
17 |
18 | import com.knizha.PDocViewer.model.LinkTapEvent;
19 |
20 | public interface LinkHandler {
21 |
22 | /**
23 | * Called when link was tapped by user
24 | *
25 | * @param event current event
26 | */
27 | void handleLinkEvent(LinkTapEvent event);
28 | }
29 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/Callbacks.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | import android.view.MotionEvent;
19 |
20 | import com.knizha.PDocViewer.link.LinkHandler;
21 | import com.knizha.PDocViewer.model.LinkTapEvent;
22 |
23 | public class Callbacks {
24 |
25 | /**
26 | * Call back object to call when the PDF is loaded
27 | */
28 | private OnLoadCompleteListener onLoadCompleteListener;
29 |
30 | /**
31 | * Call back object to call when document loading error occurs
32 | */
33 | private OnErrorListener onErrorListener;
34 |
35 | /**
36 | * Call back object to call when the page load error occurs
37 | */
38 | private OnPageErrorListener onPageErrorListener;
39 |
40 | /**
41 | * Call back object to call when the document is initially rendered
42 | */
43 | private OnRenderListener onRenderListener;
44 |
45 | /**
46 | * Call back object to call when the page has changed
47 | */
48 | private OnPageChangeListener onPageChangeListener;
49 |
50 | /**
51 | * Call back object to call when the page is scrolled
52 | */
53 | private OnPageScrollListener onPageScrollListener;
54 |
55 | /**
56 | * Call back object to call when the above layer is to drawn
57 | */
58 | private OnDrawListener onDrawListener;
59 |
60 | private OnDrawListener onDrawAllListener;
61 |
62 | /**
63 | * Call back object to call when the user does a tap gesture
64 | */
65 | private OnTapListener onTapListener;
66 |
67 | /**
68 | * Call back object to call when the user does a long tap gesture
69 | */
70 | private OnLongPressListener onLongPressListener;
71 |
72 | /**
73 | * Call back object to call when clicking link
74 | */
75 | private LinkHandler linkHandler;
76 |
77 | public void setOnLoadComplete(OnLoadCompleteListener onLoadCompleteListener) {
78 | this.onLoadCompleteListener = onLoadCompleteListener;
79 | }
80 |
81 | public void callOnLoadComplete(int pagesCount) {
82 | if (onLoadCompleteListener != null) {
83 | onLoadCompleteListener.loadComplete(pagesCount);
84 | }
85 | }
86 |
87 | public void setOnError(OnErrorListener onErrorListener) {
88 | this.onErrorListener = onErrorListener;
89 | }
90 |
91 | public OnErrorListener getOnError() {
92 | return onErrorListener;
93 | }
94 |
95 | public void setOnPageError(OnPageErrorListener onPageErrorListener) {
96 | this.onPageErrorListener = onPageErrorListener;
97 | }
98 |
99 | public boolean callOnPageError(int page, Throwable error) {
100 | if (onPageErrorListener != null) {
101 | onPageErrorListener.onPageError(page, error);
102 | return true;
103 | }
104 | return false;
105 | }
106 |
107 | public void setOnRender(OnRenderListener onRenderListener) {
108 | this.onRenderListener = onRenderListener;
109 | }
110 |
111 | public void callOnRender(int pagesCount) {
112 | if (onRenderListener != null) {
113 | onRenderListener.onInitiallyRendered(pagesCount);
114 | }
115 | }
116 |
117 | public void setOnPageChange(OnPageChangeListener onPageChangeListener) {
118 | this.onPageChangeListener = onPageChangeListener;
119 | }
120 |
121 | public void callOnPageChange(int page, int pagesCount) {
122 | if (onPageChangeListener != null) {
123 | onPageChangeListener.onPageChanged(page, pagesCount);
124 | }
125 | }
126 |
127 | public void setOnPageScroll(OnPageScrollListener onPageScrollListener) {
128 | this.onPageScrollListener = onPageScrollListener;
129 | }
130 |
131 | public void callOnPageScroll(int currentPage, float offset) {
132 | if (onPageScrollListener != null) {
133 | onPageScrollListener.onPageScrolled(currentPage, offset);
134 | }
135 | }
136 |
137 | public void setOnDraw(OnDrawListener onDrawListener) {
138 | this.onDrawListener = onDrawListener;
139 | }
140 |
141 | public OnDrawListener getOnDraw() {
142 | return onDrawListener;
143 | }
144 |
145 | public void setOnDrawAll(OnDrawListener onDrawAllListener) {
146 | this.onDrawAllListener = onDrawAllListener;
147 | }
148 |
149 | public OnDrawListener getOnDrawAll() {
150 | return onDrawAllListener;
151 | }
152 |
153 | public void setOnTap(OnTapListener onTapListener) {
154 | this.onTapListener = onTapListener;
155 | }
156 |
157 | public boolean callOnTap(MotionEvent event) {
158 | return onTapListener != null && onTapListener.onTap(event);
159 | }
160 |
161 | public void setOnLongPress(OnLongPressListener onLongPressListener) {
162 | this.onLongPressListener = onLongPressListener;
163 | }
164 |
165 | public void callOnLongPress(MotionEvent event) {
166 | if (onLongPressListener != null) {
167 | onLongPressListener.onLongPress(event);
168 | }
169 | }
170 |
171 | public void setLinkHandler(LinkHandler linkHandler) {
172 | this.linkHandler = linkHandler;
173 | }
174 |
175 | public void callLinkHandler(LinkTapEvent event) {
176 | if (linkHandler != null) {
177 | linkHandler.handleLinkEvent(event);
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnDrawListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | import android.graphics.Canvas;
19 |
20 | /**
21 | * This interface allows an extern class to draw
22 | * something on the PDFView canvas, above all images.
23 | */
24 | public interface OnDrawListener {
25 |
26 | /**
27 | * This method is called when the PDFView is
28 | * drawing its view.
29 | *
30 | * The page is starting at (0,0)
31 | *
32 | * @param canvas The canvas on which to draw things.
33 | * @param pageWidth The width of the current page.
34 | * @param pageHeight The height of the current page.
35 | * @param displayedPage The current page index
36 | */
37 | void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage);
38 | }
39 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnErrorListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | public interface OnErrorListener {
19 |
20 | /**
21 | * Called if error occurred while opening PDF
22 | * @param t Throwable with error
23 | */
24 | void onError(Throwable t);
25 | }
26 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnLoadCompleteListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | /**
19 | * Implement this interface to receive events from PDFView
20 | * when loading is complete.
21 | */
22 | public interface OnLoadCompleteListener {
23 |
24 | /**
25 | * Called when the PDF is loaded
26 | * @param nbPages the number of pages in this PDF file
27 | */
28 | void loadComplete(int nbPages);
29 | }
30 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnLongPressListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | import android.view.MotionEvent;
19 |
20 | /**
21 | * Implement this interface to receive events from PDFView
22 | * when view has been long pressed
23 | */
24 | public interface OnLongPressListener {
25 |
26 | /**
27 | * Called when the user has a long tap gesture, before processing scroll handle toggling
28 | *
29 | * @param e MotionEvent that registered as a confirmed long press
30 | */
31 | void onLongPress(MotionEvent e);
32 | }
33 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnPageChangeListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | /**
19 | * Implements this interface to receive events from PDFView
20 | * when a page has changed through swipe
21 | */
22 | public interface OnPageChangeListener {
23 |
24 | /**
25 | * Called when the user use swipe to change page
26 | *
27 | * @param page the new page displayed, starting from 0
28 | * @param pageCount the total page count
29 | */
30 | void onPageChanged(int page, int pageCount);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnPageErrorListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | public interface OnPageErrorListener {
19 |
20 | /**
21 | * Called if error occurred while loading PDF page
22 | * @param t Throwable with error
23 | */
24 | void onPageError(int page, Throwable t);
25 | }
26 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnPageScrollListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | import com.knizha.PDocViewer.PDocView;
19 |
20 | /**
21 | * Implements this interface to receive events from PDFView
22 | * when a page has been scrolled
23 | */
24 | public interface OnPageScrollListener {
25 |
26 | /**
27 | * Called on every move while scrolling
28 | *
29 | * @param page current page index
30 | * @param positionOffset see {@link PDocView#getPositionOffset()}
31 | */
32 | void onPageScrolled(int page, float positionOffset);
33 | }
34 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnRenderListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | public interface OnRenderListener {
19 |
20 | /**
21 | * Called only once, when document is rendered
22 | * @param nbPages number of pages
23 | */
24 | void onInitiallyRendered(int nbPages);
25 | }
26 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/listener/OnTapListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.listener;
17 |
18 | import android.view.MotionEvent;
19 |
20 | /**
21 | * Implement this interface to receive events from PDFView
22 | * when view has been touched
23 | */
24 | public interface OnTapListener {
25 |
26 | /**
27 | * Called when the user has a tap gesture, before processing scroll handle toggling
28 | *
29 | * @param e MotionEvent that registered as a confirmed single tap
30 | * @return true if the single tap was handled, false to toggle scroll handle
31 | */
32 | boolean onTap(MotionEvent e);
33 | }
34 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/model/LinkTapEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.model;
17 |
18 | import android.graphics.RectF;
19 |
20 | import com.shockwave.pdfium.PdfDocument;
21 |
22 | public class LinkTapEvent {
23 | private float originalX;
24 | private float originalY;
25 | private float documentX;
26 | private float documentY;
27 | private RectF mappedLinkRect;
28 | private PdfDocument.Link link;
29 |
30 | public LinkTapEvent(float originalX, float originalY, float documentX, float documentY, RectF mappedLinkRect, PdfDocument.Link link) {
31 | this.originalX = originalX;
32 | this.originalY = originalY;
33 | this.documentX = documentX;
34 | this.documentY = documentY;
35 | this.mappedLinkRect = mappedLinkRect;
36 | this.link = link;
37 | }
38 |
39 | public float getOriginalX() {
40 | return originalX;
41 | }
42 |
43 | public float getOriginalY() {
44 | return originalY;
45 | }
46 |
47 | public float getDocumentX() {
48 | return documentX;
49 | }
50 |
51 | public float getDocumentY() {
52 | return documentY;
53 | }
54 |
55 | public RectF getMappedLinkRect() {
56 | return mappedLinkRect;
57 | }
58 |
59 | public PdfDocument.Link getLink() {
60 | return link;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/model/PagePart.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.model;
17 |
18 | import android.graphics.Bitmap;
19 | import android.graphics.RectF;
20 |
21 | public class PagePart {
22 |
23 | private int page;
24 |
25 | private Bitmap renderedBitmap;
26 |
27 | private RectF pageRelativeBounds;
28 |
29 | private boolean thumbnail;
30 |
31 | private int cacheOrder;
32 |
33 | public PagePart(int page, Bitmap renderedBitmap, RectF pageRelativeBounds, boolean thumbnail, int cacheOrder) {
34 | super();
35 | this.page = page;
36 | this.renderedBitmap = renderedBitmap;
37 | this.pageRelativeBounds = pageRelativeBounds;
38 | this.thumbnail = thumbnail;
39 | this.cacheOrder = cacheOrder;
40 | }
41 |
42 | public int getCacheOrder() {
43 | return cacheOrder;
44 | }
45 |
46 | public int getPage() {
47 | return page;
48 | }
49 |
50 | public Bitmap getRenderedBitmap() {
51 | return renderedBitmap;
52 | }
53 |
54 | public RectF getPageRelativeBounds() {
55 | return pageRelativeBounds;
56 | }
57 |
58 | public boolean isThumbnail() {
59 | return thumbnail;
60 | }
61 |
62 | public void setCacheOrder(int cacheOrder) {
63 | this.cacheOrder = cacheOrder;
64 | }
65 |
66 | @Override
67 | public boolean equals(Object obj) {
68 | if (!(obj instanceof PagePart)) {
69 | return false;
70 | }
71 |
72 | PagePart part = (PagePart) obj;
73 | return part.getPage() == page
74 | && part.getPageRelativeBounds().left == pageRelativeBounds.left
75 | && part.getPageRelativeBounds().right == pageRelativeBounds.right
76 | && part.getPageRelativeBounds().top == pageRelativeBounds.top
77 | && part.getPageRelativeBounds().bottom == pageRelativeBounds.bottom;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/scroll/ScrollHandle.java:
--------------------------------------------------------------------------------
1 | package com.knizha.PDocViewer.scroll;
2 |
3 | import com.knizha.PDocViewer.PDocView;
4 |
5 | public interface ScrollHandle {
6 |
7 | /**
8 | * Used to move the handle, called internally by PDFView
9 | *
10 | * @param position current scroll ratio between 0 and 1
11 | */
12 | void setScroll(float position);
13 |
14 | /**
15 | * Method called by PDFView after setting scroll handle.
16 | * Do not call this method manually.
17 | * For usage sample see {@link DefaultScrollHandle}
18 | *
19 | * @param pDocView PDFView instance
20 | */
21 | void setupLayout(PDocView pDocView);
22 |
23 | /**
24 | * Method called by PDFView when handle should be removed from layout
25 | * Do not call this method manually.
26 | */
27 | void destroyLayout();
28 |
29 | /**
30 | * Set page number displayed on handle
31 | *
32 | * @param pageNum page number
33 | */
34 | void setPageNum(int pageNum);
35 |
36 | /**
37 | * Get handle visibility
38 | *
39 | * @return true if handle is visible, false otherwise
40 | */
41 | boolean shown();
42 |
43 | /**
44 | * Show handle
45 | */
46 | void show();
47 |
48 | /**
49 | * Hide handle immediately
50 | */
51 | void hide();
52 |
53 | /**
54 | * Hide handle after some time (defined by implementation)
55 | */
56 | void hideDelayed();
57 | }
58 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/source/AssetSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.source;
17 |
18 |
19 | import android.content.Context;
20 | import android.os.ParcelFileDescriptor;
21 |
22 | import com.knizha.PDocViewer.util.FileUtils;
23 | import com.shockwave.pdfium.PdfDocument;
24 | import com.shockwave.pdfium.PdfiumCore;
25 |
26 | import java.io.File;
27 | import java.io.IOException;
28 |
29 | public class AssetSource implements DocumentSource {
30 |
31 | private final String assetName;
32 |
33 | public AssetSource(String assetName) {
34 | this.assetName = assetName;
35 | }
36 |
37 | @Override
38 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException {
39 | File f = FileUtils.fileFromAsset(context, assetName);
40 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
41 | return core.newDocument(pfd, password);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/source/ByteArraySource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.source;
17 |
18 | import android.content.Context;
19 |
20 | import com.shockwave.pdfium.PdfDocument;
21 | import com.shockwave.pdfium.PdfiumCore;
22 |
23 | import java.io.IOException;
24 |
25 | public class ByteArraySource implements DocumentSource {
26 |
27 | private byte[] data;
28 |
29 | public ByteArraySource(byte[] data) {
30 | this.data = data;
31 | }
32 |
33 | @Override
34 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException {
35 | return core.newDocument(data, password);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/source/DocumentSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.source;
17 |
18 | import android.content.Context;
19 |
20 | import com.shockwave.pdfium.PdfDocument;
21 | import com.shockwave.pdfium.PdfiumCore;
22 |
23 | import java.io.IOException;
24 |
25 | public interface DocumentSource {
26 | PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException;
27 | }
28 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/source/FileSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.source;
17 |
18 | import android.content.Context;
19 | import android.os.ParcelFileDescriptor;
20 |
21 | import com.shockwave.pdfium.PdfDocument;
22 | import com.shockwave.pdfium.PdfiumCore;
23 |
24 | import java.io.File;
25 | import java.io.IOException;
26 |
27 | public class FileSource implements DocumentSource {
28 |
29 | private File file;
30 |
31 | public FileSource(File file) {
32 | this.file = file;
33 | }
34 |
35 | @Override
36 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException {
37 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
38 | return core.newDocument(pfd, password);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/source/InputStreamSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.source;
17 |
18 | import android.content.Context;
19 |
20 | import com.knizha.PDocViewer.util.Util;
21 | import com.shockwave.pdfium.PdfDocument;
22 | import com.shockwave.pdfium.PdfiumCore;
23 |
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 |
27 | public class InputStreamSource implements DocumentSource {
28 |
29 | private InputStream inputStream;
30 |
31 | public InputStreamSource(InputStream inputStream) {
32 | this.inputStream = inputStream;
33 | }
34 |
35 | @Override
36 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException {
37 | return core.newDocument(Util.toByteArray(inputStream), password);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/source/UriSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.source;
17 |
18 | import android.content.Context;
19 | import android.net.Uri;
20 | import android.os.ParcelFileDescriptor;
21 |
22 | import com.shockwave.pdfium.PdfDocument;
23 | import com.shockwave.pdfium.PdfiumCore;
24 |
25 | import java.io.IOException;
26 |
27 | public class UriSource implements DocumentSource {
28 |
29 | private Uri uri;
30 |
31 | public UriSource(Uri uri) {
32 | this.uri = uri;
33 | }
34 |
35 | @Override
36 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException {
37 | ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
38 | return core.newDocument(pfd, password);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/ArrayUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | public class ArrayUtils {
22 |
23 | private ArrayUtils() {
24 | // Prevents instantiation
25 | }
26 |
27 | /** Transforms (0,1,2,2,3) to (0,1,2,3) */
28 | public static int[] deleteDuplicatedPages(int[] pages) {
29 | List result = new ArrayList<>();
30 | int lastInt = -1;
31 | for (Integer currentInt : pages) {
32 | if (lastInt != currentInt) {
33 | result.add(currentInt);
34 | }
35 | lastInt = currentInt;
36 | }
37 | int[] arrayResult = new int[result.size()];
38 | for (int i = 0; i < result.size(); i++) {
39 | arrayResult[i] = result.get(i);
40 | }
41 | return arrayResult;
42 | }
43 |
44 | /** Transforms (0, 4, 4, 6, 6, 6, 3) into (0, 1, 1, 2, 2, 2, 3) */
45 | public static int[] calculateIndexesInDuplicateArray(int[] originalUserPages) {
46 | int[] result = new int[originalUserPages.length];
47 | if (originalUserPages.length == 0) {
48 | return result;
49 | }
50 |
51 | int index = 0;
52 | result[0] = index;
53 | for (int i = 1; i < originalUserPages.length; i++) {
54 | if (originalUserPages[i] != originalUserPages[i - 1]) {
55 | index++;
56 | }
57 | result[i] = index;
58 | }
59 |
60 | return result;
61 | }
62 |
63 | public static String arrayToString(int[] array) {
64 | StringBuilder builder = new StringBuilder("[");
65 | for (int i = 0; i < array.length; i++) {
66 | builder.append(array[i]);
67 | if (i != array.length - 1) {
68 | builder.append(",");
69 | }
70 | }
71 | builder.append("]");
72 | return builder.toString();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | public class Constants {
19 |
20 | public static boolean DEBUG_MODE = false;
21 |
22 | /** Between 0 and 1, the thumbnails quality (default 0.3). Increasing this value may cause performance decrease */
23 | public static float THUMBNAIL_RATIO = 0.3f;
24 |
25 | /**
26 | * The size of the rendered parts (default 256)
27 | * Tinier : a little bit slower to have the whole page rendered but more reactive.
28 | * Bigger : user will have to wait longer to have the first visual results
29 | */
30 | public static float PART_SIZE = 256;
31 |
32 | /** Part of document above and below screen that should be preloaded, in dp */
33 | public static int PRELOAD_OFFSET = 20;
34 |
35 | public static class Cache {
36 |
37 | /** The size of the cache (number of bitmaps kept) */
38 | public static int CACHE_SIZE = 120;
39 |
40 | public static int THUMBNAILS_CACHE_SIZE = 8;
41 | }
42 |
43 | public static class Pinch {
44 |
45 | public static float MAXIMUM_ZOOM = 10;
46 |
47 | public static float MINIMUM_ZOOM = 1;
48 |
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/FileUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | import android.content.Context;
19 |
20 | import java.io.File;
21 | import java.io.FileOutputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.io.OutputStream;
25 |
26 | public class FileUtils {
27 |
28 | private FileUtils() {
29 | // Prevents instantiation
30 | }
31 |
32 | public static File fileFromAsset(Context context, String assetName) throws IOException {
33 | File outFile = new File(context.getCacheDir(), assetName + "-pdfview.pdf");
34 | if (assetName.contains("/")) {
35 | outFile.getParentFile().mkdirs();
36 | }
37 | copy(context.getAssets().open(assetName), outFile);
38 | return outFile;
39 | }
40 |
41 | public static void copy(InputStream inputStream, File output) throws IOException {
42 | OutputStream outputStream = null;
43 | try {
44 | outputStream = new FileOutputStream(output);
45 | int read = 0;
46 | byte[] bytes = new byte[1024];
47 | while ((read = inputStream.read(bytes)) != -1) {
48 | outputStream.write(bytes, 0, read);
49 | }
50 | } finally {
51 | try {
52 | if (inputStream != null) {
53 | inputStream.close();
54 | }
55 | } finally {
56 | if (outputStream != null) {
57 | outputStream.close();
58 | }
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/FitPolicy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | public enum FitPolicy {
19 | WIDTH, HEIGHT, BOTH
20 | }
21 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/MathUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | public class MathUtils {
19 |
20 | static private final int BIG_ENOUGH_INT = 16 * 1024;
21 | static private final double BIG_ENOUGH_FLOOR = BIG_ENOUGH_INT;
22 | static private final double BIG_ENOUGH_CEIL = 16384.999999999996;
23 |
24 | private MathUtils() {
25 | // Prevents instantiation
26 | }
27 |
28 | /**
29 | * Limits the given number between the other values
30 | * @param number The number to limit.
31 | * @param between The smallest value the number can take.
32 | * @param and The biggest value the number can take.
33 | * @return The limited number.
34 | */
35 | public static int limit(int number, int between, int and) {
36 | if (number <= between) {
37 | return between;
38 | }
39 | if (number >= and) {
40 | return and;
41 | }
42 | return number;
43 | }
44 |
45 | /**
46 | * Limits the given number between the other values
47 | * @param number The number to limit.
48 | * @param between The smallest value the number can take.
49 | * @param and The biggest value the number can take.
50 | * @return The limited number.
51 | */
52 | public static float limit(float number, float between, float and) {
53 | if (number <= between) {
54 | return between;
55 | }
56 | if (number >= and) {
57 | return and;
58 | }
59 | return number;
60 | }
61 |
62 | public static float max(float number, float max) {
63 | if (number > max) {
64 | return max;
65 | }
66 | return number;
67 | }
68 |
69 | public static float min(float number, float min) {
70 | if (number < min) {
71 | return min;
72 | }
73 | return number;
74 | }
75 |
76 | public static int max(int number, int max) {
77 | if (number > max) {
78 | return max;
79 | }
80 | return number;
81 | }
82 |
83 | public static int min(int number, int min) {
84 | if (number < min) {
85 | return min;
86 | }
87 | return number;
88 | }
89 |
90 | /**
91 | * Methods from libGDX - https://github.com/libgdx/libgdx
92 | */
93 |
94 | /** Returns the largest integer less than or equal to the specified float. This method will only properly floor floats from
95 | * -(2^14) to (Float.MAX_VALUE - 2^14). */
96 | static public int floor(float value) {
97 | return (int) (value + BIG_ENOUGH_FLOOR) - BIG_ENOUGH_INT;
98 | }
99 |
100 | /** Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats from
101 | * -(2^14) to (Float.MAX_VALUE - 2^14). */
102 | static public int ceil(float value) {
103 | return (int) (value + BIG_ENOUGH_CEIL) - BIG_ENOUGH_INT;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/PageSizeCalculator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | import com.shockwave.pdfium.util.Size;
19 | import com.shockwave.pdfium.util.SizeF;
20 |
21 | public class PageSizeCalculator {
22 |
23 | private FitPolicy fitPolicy;
24 | private final Size originalMaxWidthPageSize;
25 | private final Size originalMaxHeightPageSize;
26 | private final Size viewSize;
27 | private SizeF optimalMaxWidthPageSize;
28 | private SizeF optimalMaxHeightPageSize;
29 | private float widthRatio;
30 | private float heightRatio;
31 | private boolean fitEachPage;
32 |
33 | public PageSizeCalculator(FitPolicy fitPolicy, Size originalMaxWidthPageSize, Size originalMaxHeightPageSize,
34 | Size viewSize, boolean fitEachPage) {
35 | this.fitPolicy = fitPolicy;
36 | this.originalMaxWidthPageSize = originalMaxWidthPageSize;
37 | this.originalMaxHeightPageSize = originalMaxHeightPageSize;
38 | this.viewSize = viewSize;
39 | this.fitEachPage = fitEachPage;
40 | calculateMaxPages();
41 | }
42 |
43 | public SizeF calculate(Size pageSize) {
44 | if (pageSize.getWidth() <= 0 || pageSize.getHeight() <= 0) {
45 | return new SizeF(0, 0);
46 | }
47 | float maxWidth = fitEachPage ? viewSize.getWidth() : pageSize.getWidth() * widthRatio;
48 | float maxHeight = fitEachPage ? viewSize.getHeight() : pageSize.getHeight() * heightRatio;
49 | switch (fitPolicy) {
50 | case HEIGHT:
51 | return fitHeight(pageSize, maxHeight);
52 | case BOTH:
53 | return fitBoth(pageSize, maxWidth, maxHeight);
54 | default:
55 | return fitWidth(pageSize, maxWidth);
56 | }
57 | }
58 |
59 | public SizeF getOptimalMaxWidthPageSize() {
60 | return optimalMaxWidthPageSize;
61 | }
62 |
63 | public SizeF getOptimalMaxHeightPageSize() {
64 | return optimalMaxHeightPageSize;
65 | }
66 |
67 | private void calculateMaxPages() {
68 | switch (fitPolicy) {
69 | case HEIGHT:
70 | optimalMaxHeightPageSize = fitHeight(originalMaxHeightPageSize, viewSize.getHeight());
71 | heightRatio = optimalMaxHeightPageSize.getHeight() / originalMaxHeightPageSize.getHeight();
72 | optimalMaxWidthPageSize = fitHeight(originalMaxWidthPageSize, originalMaxWidthPageSize.getHeight() * heightRatio);
73 | break;
74 | case BOTH:
75 | SizeF localOptimalMaxWidth = fitBoth(originalMaxWidthPageSize, viewSize.getWidth(), viewSize.getHeight());
76 | float localWidthRatio = localOptimalMaxWidth.getWidth() / originalMaxWidthPageSize.getWidth();
77 | this.optimalMaxHeightPageSize = fitBoth(originalMaxHeightPageSize, originalMaxHeightPageSize.getWidth() * localWidthRatio,
78 | viewSize.getHeight());
79 | heightRatio = optimalMaxHeightPageSize.getHeight() / originalMaxHeightPageSize.getHeight();
80 | optimalMaxWidthPageSize = fitBoth(originalMaxWidthPageSize, viewSize.getWidth(), originalMaxWidthPageSize.getHeight() * heightRatio);
81 | widthRatio = optimalMaxWidthPageSize.getWidth() / originalMaxWidthPageSize.getWidth();
82 | break;
83 | default:
84 | optimalMaxWidthPageSize = fitWidth(originalMaxWidthPageSize, viewSize.getWidth());
85 | widthRatio = optimalMaxWidthPageSize.getWidth() / originalMaxWidthPageSize.getWidth();
86 | optimalMaxHeightPageSize = fitWidth(originalMaxHeightPageSize, originalMaxHeightPageSize.getWidth() * widthRatio);
87 | break;
88 | }
89 | }
90 |
91 | private SizeF fitWidth(Size pageSize, float maxWidth) {
92 | float w = pageSize.getWidth(), h = pageSize.getHeight();
93 | float ratio = w / h;
94 | w = maxWidth;
95 | h = (float) Math.floor(maxWidth / ratio);
96 | return new SizeF(w, h);
97 | }
98 |
99 | private SizeF fitHeight(Size pageSize, float maxHeight) {
100 | float w = pageSize.getWidth(), h = pageSize.getHeight();
101 | float ratio = h / w;
102 | h = maxHeight;
103 | w = (float) Math.floor(maxHeight / ratio);
104 | return new SizeF(w, h);
105 | }
106 |
107 | private SizeF fitBoth(Size pageSize, float maxWidth, float maxHeight) {
108 | float w = pageSize.getWidth(), h = pageSize.getHeight();
109 | float ratio = w / h;
110 | w = maxWidth;
111 | h = (float) Math.floor(maxWidth / ratio);
112 | if (h > maxHeight) {
113 | h = maxHeight;
114 | w = (float) Math.floor(maxHeight * ratio);
115 | }
116 | return new SizeF(w, h);
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/SnapEdge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Bartosz Schiller
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | public enum SnapEdge {
19 | START, CENTER, END, NONE
20 | }
21 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/java/com/knizha/PDocViewer/util/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bartosz Schiller.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.knizha.PDocViewer.util;
17 |
18 | import android.content.Context;
19 | import android.util.TypedValue;
20 |
21 | import java.io.ByteArrayOutputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 |
25 | public class Util {
26 | private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
27 |
28 | public static int getDP(Context context, int dp) {
29 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
30 | }
31 |
32 | public static byte[] toByteArray(InputStream inputStream) throws IOException {
33 | ByteArrayOutputStream os = new ByteArrayOutputStream();
34 | byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
35 | int n;
36 | while (-1 != (n = inputStream.read(buffer))) {
37 | os.write(buffer, 0, n);
38 | }
39 | return os.toByteArray();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable-hdpi/ic_open_in_browser_grey_700_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/PDocViewer/src/main/res/drawable-hdpi/ic_open_in_browser_grey_700_48dp.png
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable-mdpi/ic_open_in_browser_grey_700_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/PDocViewer/src/main/res/drawable-mdpi/ic_open_in_browser_grey_700_48dp.png
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable-xhdpi/ic_open_in_browser_grey_700_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/PDocViewer/src/main/res/drawable-xhdpi/ic_open_in_browser_grey_700_48dp.png
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable-xxhdpi/ic_open_in_browser_grey_700_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/PDocViewer/src/main/res/drawable-xxhdpi/ic_open_in_browser_grey_700_48dp.png
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable-xxxhdpi/ic_open_in_browser_grey_700_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/PDocViewer/src/main/res/drawable-xxxhdpi/ic_open_in_browser_grey_700_48dp.png
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable/default_scroll_handle_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable/default_scroll_handle_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable/default_scroll_handle_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable/default_scroll_handle_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/PDocViewer/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/menu/options.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidPdfViewer demo
3 | Pick file
4 | Unable to pick file. Check status of file manager.
5 |
--------------------------------------------------------------------------------
/PDocViewer/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Get the source code
3 | Using submodule [LibPDFium](https://github.com/KnIfER/LibPDFium), which could be compiled within 6 minutes!
4 |
5 | ```
6 | git clone --recursive --depth=1 https://github.com/KnIfER/PDFium-Android-Demo.git
7 | ```
8 |
9 | Pdfium source codes (LibPdfium/src/main/PDFIUM) are pulled from AOSP/android11-mainline-release
10 |
11 | Special Thanks:
12 | - `bash-ndk *.mk` buildscripts via [barteksc/modpdfium](https://github.com/barteksc/modpdfium)
13 |
14 | - `cmake` buildscript via [freedom10086/PdfiumAndroid](https://github.com/freedom10086/PdfiumAndroid)
15 |
16 | - `Java & Jni` via [barteksc/AndroidPdfViewer](https://github.com/barteksc/AndroidPdfViewer)
17 |
18 |
19 | # PDFium Android Demo Viewer
20 |
21 | The beheaviour of this project is just like the original Demo project : *barteksc/AndroidPdfViewer*
22 |
23 | Yet this repo contains **three** build systems :
24 |
25 | 1. **bash-ndk.**
26 | Use : Activate the LibPdfiumSep library module. Then right click on the `jni` folder and select 'Open In Ternimal' in the android studio. Run `ndk-build` and (hopefully) done !
27 | Develop : To develop the pre-compiled libpdfium.so, prepare win10 and ubuntu subsystem or a real linux system. Then run `./build.sh`.
28 |
29 | 2. **cmake.**
30 | Use / Develop : Activate LibPdfium. Then Just sync and build !
31 |
32 | 3. **visual studio.**
33 | VS project files are configured by hand.
34 |
35 | # Build libpdfium.so using Visual Studio
36 | Yes, from now on you can build libpdfium.so right in the VS 2019 !
37 | ### Build times :
38 | - 3:45 minutes, release, -O3, 5.93 MB
39 | - 3:25 minutes, debug, 10.1 MB
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | buildscript {
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:4.0.0'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | org.gradle.jvmargs=-Xmx2048M
3 | android.enableD8=true
4 | android.useAndroidX=true
5 | android.enableJetifier=false
6 | org.gradle.configureondemand = false
7 | android.injected.testOnly=false
8 |
9 | # For more details on how to configure your build environment visit
10 | # http://www.gradle.org/docs/current/userguide/build_environment.html
11 | #
12 | # Specifies the JVM arguments used for the daemon process.
13 | # The setting is particularly useful for tweaking memory settings.
14 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
15 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
16 | #
17 | # When configured, Gradle will run in incubating parallel mode.
18 | # This option should only be used with decoupled projects. More details, visit
19 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
20 | # org.gradle.parallel=true
21 |
22 | ver_compileSdkVersion=android-30
23 | ver_minsdk=19
24 | ver_aimsdk=29
25 |
26 | libs_glide=com.github.bumptech.glide:glide:4.10.0
27 |
28 | libs_compat=androidx.appcompat:appcompat:1.1.0-rc01
29 | libs_mat=com.google.android.material:material:1.1.0-alpha09
30 | libs_recycler=androidx.recyclerview:recyclerview:1.2.0-alpha04
31 | libs_docfile=androidx.documentfile:documentfile:1.0.1
32 | libs_v4=androidx.legacy:legacy-support-v4:1.0.0
33 | use_mat_official=
34 | use_compat_official=
35 | use_prefer_official=
36 |
37 | libs_appres=androidx.appcompat:appcompat-resources:1.1.0-rc01
38 | libs_drawer=androidx.drawerlayout:drawerlayout:1.1.0-alpha02
39 | libs_cursor=androidx.cursoradapter:cursoradapter:1.0.0
40 | libs_fragment=androidx.fragment:fragment:1.2.0-alpha01
41 |
42 | libs_anno=androidx.annotation:annotation:1.0.1
43 | libs_prefer=androidx.preference:preference:1.1.0-rc01
44 | libs_cardview=androidx.cardview:cardview:1.0.0
45 | libs_coordinator=androidx.coordinatorlayout:coordinatorlayout:1.1.0-beta01
46 | libs_core=androidx.core:core:1.3.0-rc01
47 | libs_collection=androidx.collection:collection:1.0.0
48 | libs_lifecycle=androidx.lifecycle:lifecycle-runtime:2.0.0
49 | libs_transition=androidx.transition:transition:1.0.1
50 | libs_vectordrawable=androidx.vectordrawable:vectordrawable:1.1.0-rc01
51 | libs_viewpager=androidx.viewpager:viewpager:1.0.0
52 | libs_viewpager2=androidx.viewpager2:viewpager2:1.0.0-beta02
53 |
54 | libs_clang=org.apache.commons:commons-lang3:3.9
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KnIfER/PDFium-Android-Demo/18455b7afe57946bd9c458aa9dba63666de0cc5b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 18 01:14:14 CEST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @REM
2 | @REM Copyright 2014 Joan Zapata
3 | @REM
4 | @REM This file is part of Android-pdfview.
5 | @REM
6 | @REM Android-pdfview is free software: you can redistribute it and/or modify
7 | @REM it under the terms of the GNU General Public License as published by
8 | @REM the Free Software Foundation, either version 3 of the License, or
9 | @REM (at your option) any later version.
10 | @REM
11 | @REM Android-pdfview is distributed in the hope that it will be useful,
12 | @REM but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | @REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | @REM GNU General Public License for more details.
15 | @REM
16 | @REM You should have received a copy of the GNU General Public License
17 | @REM along with Android-pdfview. If not, see .
18 | @REM
19 |
20 | @if "%DEBUG%" == "" @echo off
21 | @rem ##########################################################################
22 | @rem
23 | @rem Gradle startup script for Windows
24 | @rem
25 | @rem ##########################################################################
26 |
27 | @rem Set local scope for the variables with windows NT shell
28 | if "%OS%"=="Windows_NT" setlocal
29 |
30 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | set DEFAULT_JVM_OPTS=
32 |
33 | set DIRNAME=%~dp0
34 | if "%DIRNAME%" == "" set DIRNAME=.
35 | set APP_BASE_NAME=%~n0
36 | set APP_HOME=%DIRNAME%
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto init
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto init
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :init
68 | @rem Get command-line arguments, handling Windowz variants
69 |
70 | if not "%OS%" == "Windows_NT" goto win9xME_args
71 | if "%@eval[2+2]" == "4" goto 4NT_args
72 |
73 | :win9xME_args
74 | @rem Slurp the command line arguments.
75 | set CMD_LINE_ARGS=
76 | set _SKIP=2
77 |
78 | :win9xME_args_slurp
79 | if "x%~1" == "x" goto execute
80 |
81 | set CMD_LINE_ARGS=%*
82 | goto execute
83 |
84 | :4NT_args
85 | @rem Get arguments from the 4NT Shell from JP Software
86 | set CMD_LINE_ARGS=%$
87 |
88 | :execute
89 | @rem Setup the command line
90 |
91 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
92 |
93 | @rem Execute Gradle
94 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
95 |
96 | :end
97 | @rem End local scope for the variables with windows NT shell
98 | if "%ERRORLEVEL%"=="0" goto mainEnd
99 |
100 | :fail
101 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
102 | rem the _cmd.exe /c_ return code!
103 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
104 | exit /b 1
105 |
106 | :mainEnd
107 | if "%OS%"=="Windows_NT" endlocal
108 |
109 | :omega
110 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':LibPdfiumSep'
2 | include ':PDocViewer'
3 |
4 |
--------------------------------------------------------------------------------