Disketalarni, CD- va DVD-disk
o`quvchilar o`z uylariga olib,
o`zlarining shaxsiy kompyuterlarida foydalanishlari mumkin.
Kutubxona saytida
barcha ma`lumotlar bo`limlarga bo`lingan, ular
uchun
qidiruv tizimi
ishlamoqda.
Universitet resurslarining katta qismi Internet foydalanuvchilar uchun
quyidagi manzilda mavjud:
http://library.tuit.uz
.
23
DASTUR KODI:
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.HandlerThread;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.RelativeLayout;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class PDFView extends RelativeLayout {
private static final String TAG = PDFView.class.getSimpleName();
public static final float DEFAULT_MAX_SCALE = 3.0f;
public static final float DEFAULT_MID_SCALE = 1.75f;
public static final float DEFAULT_MIN_SCALE = 1.0f;
private float minZoom = DEFAULT_MIN_SCALE;
private float midZoom = DEFAULT_MID_SCALE;
24
private float maxZoom = DEFAULT_MAX_SCALE;
enum ScrollDir {
NONE, START, END
}
private ScrollDir scrollDir = ScrollDir.NONE;
CacheManager cacheManager;
private AnimationManager animationManager;
private DragPinchManager dragPinchManager;
private int[] originalUserPages;
private int[] filteredUserPages;
private int[] filteredUserPageIndexes;
private int documentPageCount;
private int currentPage;
private int currentFilteredPage;
private int pageWidth, pageHeight;
private float optimalPageWidth, optimalPageHeight;
private float currentXOffset = 0;
private float currentYOffset = 0;
private float zoom = 1f;
private boolean recycled = true;
private State state = State.DEFAULT;
private DecodingAsyncTask decodingAsyncTask;
private final HandlerThread renderingHandlerThread;
RenderingHandler renderingHandler;
private PagesLoader pagesLoader;
private OnLoadCompleteListener onLoadCompleteListener;
private OnErrorListener onErrorListener;
private OnPageChangeListener onPageChangeListener;
private OnPageScrollListener onPageScrollListener;
25
private OnDrawListener onDrawListener;
private OnDrawListener onDrawAllListener;
private OnRenderListener onRenderListener;
private OnTapListener onTapListener;
private OnPageErrorListener onPageErrorListener;
private Paint paint;
private Paint debugPaint;
private int invalidPageColor = Color.WHITE;
private int defaultPage = 0;
private boolean swipeVertical = true;
private PdfiumCore pdfiumCore;
private PdfDocument pdfDocument;
private ScrollHandle scrollHandle;
private boolean isScrollHandleInit = false;
ScrollHandle getScrollHandle() {
return scrollHandle;
}
private boolean bestQuality = false;
private boolean annotationRendering = false;
private boolean renderDuringScale = false;
private boolean enableAntialiasing = true;
private PaintFlagsDrawFilter antialiasFilter =
new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG |
Paint.FILTER_BITMAP_FLAG);
private int spacingPx = 0;
private List onDrawPagesNums = new ArrayList<>(10);
public PDFView(Context context, AttributeSet set) {
super(context, set);
renderingHandlerThread = new HandlerThread("PDF renderer");
if (isInEditMode()) {
26
return;
}
cacheManager = new CacheManager();
animationManager = new AnimationManager(this);
dragPinchManager = new DragPinchManager(this, animationManager);
paint = new Paint();
debugPaint = new Paint();
debugPaint.setStyle(Style.STROKE);
pdfiumCore = new PdfiumCore(context);
setWillNotDraw(false);
}
private void load(DocumentSource docSource, String password, OnLoadCompleteListener
listener, OnErrorListener onErrorListener) {
load(docSource, password, listener, onErrorListener, null);
}
private void load(DocumentSource docSource, String password, OnLoadCompleteListener
onLoadCompleteListener, OnErrorListener onErrorListener, int[] userPages) {
if (!recycled) {
throw new IllegalStateException("Don't call load on a PDF View without recycling it
first.");
}
if (userPages != null) {
this.originalUserPages = userPages;
this.filteredUserPages = ArrayUtils.deleteDuplicatedPages(originalUserPages);
this.filteredUserPageIndexes =
ArrayUtils.calculateIndexesInDuplicateArray(originalUserPages);
}
this.onLoadCompleteListener = onLoadCompleteListener;
this.onErrorListener = onErrorListener;
int firstPageIdx = 0;
if (originalUserPages != null) {
27
firstPageIdx = originalUserPages[0];
}
recycled = false;
decodingAsyncTask = new DecodingAsyncTask(docSource, password, this, pdfiumCore,
firstPageIdx);
decodingAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void jumpTo(int page, boolean withAnimation) {
float offset = -calculatePageOffset(page);
if (swipeVertical) {
if (withAnimation) {
animationManager.startYAnimation(currentYOffset, offset);
} else {
moveTo(currentXOffset, offset);
}
} else {
if (withAnimation) {
animationManager.startXAnimation(currentXOffset, offset);
} else {
moveTo(offset, currentYOffset);
}
}
showPage(page);
}
public void jumpTo(int page) {
jumpTo(page, false);
}
void showPage(int pageNb) {
if (recycled) {
return;
28
}
pageNb = determineValidPageNumberFrom(pageNb);
currentPage = pageNb;
currentFilteredPage = pageNb;
if (filteredUserPageIndexes != null) {
if (pageNb >= 0 && pageNb < filteredUserPageIndexes.length) {
pageNb = filteredUserPageIndexes[pageNb];
currentFilteredPage = pageNb;
}
}
loadPages();
if (scrollHandle != null && !documentFitsView()) {
scrollHandle.setPageNum(currentPage + 1);
}
if (onPageChangeListener != null) {
onPageChangeListener.onPageChanged(currentPage, getPageCount());
}
}
public float getPositionOffset() {
float offset;
if (swipeVertical) {
offset = -currentYOffset / (calculateDocLength() - getHeight());
} else {
offset = -currentXOffset / (calculateDocLength() - getWidth());
}
return MathUtils.limit(offset, 0, 1);
}
public void setPositionOffset(float progress, boolean moveHandle) {
if (swipeVertical) {
moveTo(currentXOffset, (-calculateDocLength() + getHeight()) * progress,
moveHandle);
29
} else {
moveTo((-calculateDocLength() + getWidth()) * progress, currentYOffset,
moveHandle);
}
loadPageByOffset();
}
public void setPositionOffset(float progress) {
setPositionOffset(progress, true);
}
private float calculatePageOffset(int page) {
if (swipeVertical) {
return toCurrentScale(page * optimalPageHeight + page * spacingPx);
} else {
return toCurrentScale(page * optimalPageWidth + page * spacingPx);
}
}
float calculateDocLength() {
int pageCount = getPageCount();
if (swipeVertical) {
return toCurrentScale(pageCount * optimalPageHeight + (pageCount - 1) * spacingPx);
} else {
return toCurrentScale(pageCount * optimalPageWidth + (pageCount - 1) * spacingPx);
}
}
public void stopFling() {
animationManager.stopFling();
}
public int getPageCount() {
if (originalUserPages != null) {
return originalUserPages.length;
30
}
return documentPageCount;
}
public void enableSwipe(boolean enableSwipe) {
dragPinchManager.setSwipeEnabled(enableSwipe);
}
public void enableDoubletap(boolean enableDoubletap) {
this.dragPinchManager.enableDoubletap(enableDoubletap);
}
private void setOnPageChangeListener(OnPageChangeListener onPageChangeListener) {
this.onPageChangeListener = onPageChangeListener;
}
OnPageChangeListener getOnPageChangeListener() {
return this.onPageChangeListener;
}
private void setOnPageScrollListener(OnPageScrollListener onPageScrollListener) {
this.onPageScrollListener = onPageScrollListener;
}
OnPageScrollListener getOnPageScrollListener() {
return this.onPageScrollListener;
}
private void setOnRenderListener(OnRenderListener onRenderListener) {
this.onRenderListener = onRenderListener;
}
OnRenderListener getOnRenderListener() {
return this.onRenderListener;
}
31
private void setOnTapListener(OnTapListener onTapListener) {
this.onTapListener = onTapListener;
}
OnTapListener getOnTapListener() {
return this.onTapListener;
}
private void setOnDrawListener(OnDrawListener onDrawListener) {
this.onDrawListener = onDrawListener;
}
private void setOnDrawAllListener(OnDrawListener onDrawAllListener) {
this.onDrawAllListener = onDrawAllListener;
}
private void setOnPageErrorListener(OnPageErrorListener onPageErrorListener) {
this.onPageErrorListener = onPageErrorListener;
}
void onPageError(PageRenderingException ex) {
if (onPageErrorListener != null) {
onPageErrorListener.onPageError(ex.getPage(), ex.getCause());
} else {
Log.e(TAG, "Cannot open page " + ex.getPage(), ex.getCause());
}
}
public void recycle() {
animationManager.stopAll();
if (renderingHandler != null) {
renderingHandler.stop();
renderingHandler.removeMessages(RenderingHandler.MSG_RENDER_TASK);
}
32
if (decodingAsyncTask != null) {
decodingAsyncTask.cancel(true);
}
cacheManager.recycle();
if (scrollHandle != null && isScrollHandleInit) {
scrollHandle.destroyLayout();
}
if (pdfiumCore != null && pdfDocument != null) {
pdfiumCore.closeDocument(pdfDocument);
}
renderingHandler = null;
originalUserPages = null;
filteredUserPages = null;
filteredUserPageIndexes = null;
pdfDocument = null;
scrollHandle = null;
isScrollHandleInit = false;
currentXOffset = currentYOffset = 0;
zoom = 1f;
recycled = true;
state = State.DEFAULT;
}
public boolean isRecycled() {
return recycled;
}
@Override
public void computeScroll() {
super.computeScroll();
if (isInEditMode()) {
33
return;
}
animationManager.computeFling();
}
@Override
protected void onDetachedFromWindow() {
recycle();
super.onDetachedFromWindow();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (isInEditMode() || state != State.SHOWN) {
return;
}
animationManager.stopAll();
calculateOptimalWidthAndHeight();
if (swipeVertical) {
moveTo(currentXOffset, -calculatePageOffset(currentPage));
} else {
moveTo(-calculatePageOffset(currentPage), currentYOffset);
}
loadPageByOffset();
}
@Override
public boolean canScrollHorizontally(int direction) {
if (swipeVertical) {
if (direction < 0 && currentXOffset < 0) {
return true;
} else if (direction > 0 && currentXOffset + toCurrentScale(optimalPageWidth) >
getWidth()) {
34
return true;
}
} else {
if (direction < 0 && currentXOffset < 0) {
return true;
} else if (direction > 0 && currentXOffset + calculateDocLength() > getWidth()) {
return true;
}
}
return false;
}
@Override
public boolean canScrollVertically(int direction) {
if (swipeVertical) {
if (direction < 0 && currentYOffset < 0) {
return true;
} else if (direction > 0 && currentYOffset + calculateDocLength() > getHeight()) {
return true;
}
} else {
if (direction < 0 && currentYOffset < 0) {
return true;
} else if (direction > 0 && currentYOffset + toCurrentScale(optimalPageHeight) >
getHeight()) {
return true;
}
}
return false;
}
@Override
35
protected void onDraw(Canvas canvas) {
if (isInEditMode()) {
return;
}
if (enableAntialiasing) {
canvas.setDrawFilter(antialiasFilter);
}
Drawable bg = getBackground();
if (bg == null) {
canvas.drawColor(Color.WHITE);
} else {
bg.draw(canvas);
}
if (recycled) {
return;
}
if (state != State.SHOWN) {
return;
}
float currentXOffset = this.currentXOffset;
float currentYOffset = this.currentYOffset;
canvas.translate(currentXOffset, currentYOffset);
for (PagePart part : cacheManager.getThumbnails()) {
drawPart(canvas, part);
}
for (PagePart part : cacheManager.getPageParts()) {
drawPart(canvas, part);
if (onDrawAllListener != null && !onDrawPagesNums.contains(part.getUserPage())) {
onDrawPagesNums.add(part.getUserPage());
36
}
}
for (Integer page : onDrawPagesNums) {
drawWithListener(canvas, page, onDrawAllListener);
}
onDrawPagesNums.clear();
drawWithListener(canvas, currentPage, onDrawListener);
canvas.translate(-currentXOffset, -currentYOffset);
}
private void drawWithListener(Canvas canvas, int page, OnDrawListener listener) {
if (listener != null) {
float translateX, translateY;
if (swipeVertical) {
translateX = 0;
translateY = calculatePageOffset(page);
} else {
translateY = 0;
translateX = calculatePageOffset(page);
}
canvas.translate(translateX, translateY);
listener.onLayerDrawn(canvas,
toCurrentScale(optimalPageWidth),
toCurrentScale(optimalPageHeight),
page);
canvas.translate(-translateX, -translateY);
}
}
private void drawPart(Canvas canvas, PagePart part) {
RectF pageRelativeBounds = part.getPageRelativeBounds();
Bitmap renderedBitmap = part.getRenderedBitmap();
37
if (renderedBitmap.isRecycled()) {
return;
}
float localTranslationX = 0;
float localTranslationY = 0;
if (swipeVertical) {
localTranslationY = calculatePageOffset(part.getUserPage());
} else {
localTranslationX = calculatePageOffset(part.getUserPage());
}
canvas.translate(localTranslationX, localTranslationY);
Rect srcRect = new Rect(0, 0, renderedBitmap.getWidth(),
renderedBitmap.getHeight());
float offsetX = toCurrentScale(pageRelativeBounds.left * optimalPageWidth);
float offsetY = toCurrentScale(pageRelativeBounds.top * optimalPageHeight);
float width = toCurrentScale(pageRelativeBounds.width() * optimalPageWidth);
float height = toCurrentScale(pageRelativeBounds.height() * optimalPageHeight);
RectF dstRect = new RectF((int) offsetX, (int) offsetY,
(int) (offsetX + width),
(int) (offsetY + height));
float translationX = currentXOffset + localTranslationX;
float translationY = currentYOffset + localTranslationY;
if (translationX + dstRect.left >= getWidth() || translationX + dstRect.right <= 0 ||
translationY + dstRect.top >= getHeight() || translationY + dstRect.bottom <= 0) {
canvas.translate(-localTranslationX, -localTranslationY);
return;
}
canvas.drawBitmap(renderedBitmap, srcRect, dstRect, paint);
if (Constants.DEBUG_MODE) {
38
debugPaint.setColor(part.getUserPage() % 2 == 0 ? Color.RED : Color.BLUE);
canvas.drawRect(dstRect, debugPaint);
}
canvas.translate(-localTranslationX, -localTranslationY);
}
public void loadPages() {
if (optimalPageWidth == 0 || optimalPageHeight == 0 || renderingHandler == null) {
return;
}
renderingHandler.removeMessages(RenderingHandler.MSG_RENDER_TASK);
cacheManager.makeANewSet();
pagesLoader.loadPages();
redraw();
}
void loadComplete(PdfDocument pdfDocument, int pageWidth, int pageHeight) {
state = State.LOADED;
this.documentPageCount = pdfiumCore.getPageCount(pdfDocument);
this.pdfDocument = pdfDocument;
this.pageWidth = pageWidth;
this.pageHeight = pageHeight;
calculateOptimalWidthAndHeight();
pagesLoader = new PagesLoader(this);
if (!renderingHandlerThread.isAlive()) {
renderingHandlerThread.start();
}
renderingHandler = new RenderingHandler(renderingHandlerThread.getLooper(),
this, pdfiumCore, pdfDocument);
renderingHandler.start();
if (scrollHandle != null) {
39
scrollHandle.setupLayout(this);
isScrollHandleInit = true;
}
if (onLoadCompleteListener != null) {
onLoadCompleteListener.loadComplete(documentPageCount);
}
jumpTo(defaultPage, false);
}
void loadError(Throwable t) {
state = State.ERROR;
recycle();
invalidate();
if (this.onErrorListener != null) {
this.onErrorListener.onError(t);
} else {
Log.e("PDFView", "load pdf error", t);
}
}
void redraw() {
invalidate();
}
public void onBitmapRendered(PagePart part) {
if (state == State.LOADED) {
state = State.SHOWN;
if (onRenderListener != null) {
onRenderListener.onInitiallyRendered(getPageCount(), optimalPageWidth,
optimalPageHeight);
}
}
if (part.isThumbnail()) {
cacheManager.cacheThumbnail(part);
40
} else {
cacheManager.cachePart(part);
}
redraw();
}
private int determineValidPageNumberFrom(int userPage) {
if (userPage <= 0) {
return 0;
}
if (originalUserPages != null) {
if (userPage >= originalUserPages.length) {
return originalUserPages.length - 1;
}
} else {
if (userPage >= documentPageCount) {
return documentPageCount - 1;
}
}
return userPage;
}
private float calculateCenterOffsetForPage(int pageNb) {
if (swipeVertical) {
float imageY = -(pageNb * optimalPageHeight + pageNb * spacingPx);
imageY += getHeight() / 2 - optimalPageHeight / 2;
return imageY;
} else {
float imageX = -(pageNb * optimalPageWidth + pageNb * spacingPx);
imageX += getWidth() / 2 - optimalPageWidth / 2;
return imageX;
}
41
}
private void calculateOptimalWidthAndHeight() {
if (state == State.DEFAULT || getWidth() == 0) {
return;
}
float maxWidth = getWidth(), maxHeight = getHeight();
float w = pageWidth, h = pageHeight;
float ratio = w / h;
w = maxWidth;
h = (float) Math.floor(maxWidth / ratio);
if (h > maxHeight) {
h = maxHeight;
w = (float) Math.floor(maxHeight * ratio);
}
optimalPageWidth = w;
optimalPageHeight = h;
}
public void moveTo(float offsetX, float offsetY) {
moveTo(offsetX, offsetY, true);
}
public void moveTo(float offsetX, float offsetY, boolean moveHandle) {
if (swipeVertical) {
float scaledPageWidth = toCurrentScale(optimalPageWidth);
if (scaledPageWidth < getWidth()) {
offsetX = getWidth() / 2 - scaledPageWidth / 2;
} else {
if (offsetX > 0) {
offsetX = 0;
} else if (offsetX + scaledPageWidth < getWidth()) {
offsetX = getWidth() - scaledPageWidth;
42
}
}
float contentHeight = calculateDocLength();
if (contentHeight < getHeight()) { // whole document height visible on screen
offsetY = (getHeight() - contentHeight) / 2;
} else {
if (offsetY > 0) { // top visible
offsetY = 0;
} else if (offsetY + contentHeight < getHeight()) { // bottom visible
offsetY = -contentHeight + getHeight();
}
}
if (offsetY < currentYOffset) {
scrollDir = ScrollDir.END;
} else if (offsetY > currentYOffset) {
scrollDir = ScrollDir.START;
} else {
scrollDir = ScrollDir.NONE;
}
} else {
float scaledPageHeight = toCurrentScale(optimalPageHeight);
if (scaledPageHeight < getHeight()) {
offsetY = getHeight() / 2 - scaledPageHeight / 2;
} else {
if (offsetY > 0) {
offsetY = 0;
} else if (offsetY + scaledPageHeight < getHeight()) {
offsetY = getHeight() - scaledPageHeight;
}
}
43
float contentWidth = calculateDocLength();
if (contentWidth < getWidth()) {
offsetX = (getWidth() - contentWidth) / 2;
} else {
if (offsetX > 0) { // left visible
offsetX = 0;
} else if (offsetX + contentWidth < getWidth()) { // right visible
offsetX = -contentWidth + getWidth();
}
}
if (offsetX < currentXOffset) {
scrollDir = ScrollDir.END;
} else if (offsetX > currentXOffset) {
scrollDir = ScrollDir.START;
} else {
scrollDir = ScrollDir.NONE;
}
}
currentXOffset = offsetX;
currentYOffset = offsetY;
float positionOffset = getPositionOffset();
if (moveHandle && scrollHandle != null && !documentFitsView()) {
scrollHandle.setScroll(positionOffset);
}
if (onPageScrollListener != null) {
onPageScrollListener.onPageScrolled(getCurrentPage(), positionOffset);
}
redraw();
}
44
ScrollDir getScrollDir() {
return scrollDir;
}
void loadPageByOffset() {
if (0 == getPageCount()) {
return;
}
float offset, optimal, screenCenter;
float spacingPerPage = spacingPx - (spacingPx / getPageCount());
if (swipeVertical) {
offset = currentYOffset;
optimal = optimalPageHeight + spacingPerPage;
screenCenter = ((float) getHeight()) / 2;
} else {
offset = currentXOffset;
optimal = optimalPageWidth + spacingPerPage;
screenCenter = ((float) getWidth()) / 2;
}
int page = (int) Math.floor((Math.abs(offset) + screenCenter) / toCurrentScale(optimal));
if (page >= 0 && page <= getPageCount() - 1 && page != getCurrentPage()) {
showPage(page);
} else {
loadPages();
}
}
int[] getFilteredUserPages() {
return filteredUserPages;
}
int[] getOriginalUserPages() {
return originalUserPages;
45
}
int[] getFilteredUserPageIndexes() {
return filteredUserPageIndexes;
}
int getDocumentPageCount() {
return documentPageCount;
}
public void moveRelativeTo(float dx, float dy) {
moveTo(currentXOffset + dx, currentYOffset + dy);
}
public void zoomTo(float zoom) {
this.zoom = zoom;
}
public void zoomCenteredTo(float zoom, PointF pivot) {
float dzoom = zoom / this.zoom;
zoomTo(zoom);
float baseX = currentXOffset * dzoom;
float baseY = currentYOffset * dzoom;
baseX += (pivot.x - pivot.x * dzoom);
baseY += (pivot.y - pivot.y * dzoom);
moveTo(baseX, baseY);
}
public void zoomCenteredRelativeTo(float dzoom, PointF pivot) {
zoomCenteredTo(zoom * dzoom, pivot);
}
public boolean documentFitsView() {
int pageCount = getPageCount();
int spacing = (pageCount - 1) * spacingPx;
if (swipeVertical) {
return pageCount * optimalPageHeight + spacing < getHeight();
46
} else {
return pageCount * optimalPageWidth + spacing < getWidth();
}
}
public void fitToWidth(int page) {
if (state != State.SHOWN) {
Log.e(TAG, "Cannot fit, document not rendered yet");
return;
}
fitToWidth();
jumpTo(page);
}
public void fitToWidth() {
if (state != State.SHOWN) {
Log.e(TAG, "Cannot fit, document not rendered yet");
return;
}
zoomTo(getWidth() / optimalPageWidth);
setPositionOffset(0);
}
public int getCurrentPage() {
return currentPage;
}
public float getCurrentXOffset() {
return currentXOffset;
}
public float getCurrentYOffset() {
return currentYOffset;
}
47
public float toRealScale(float size) {
return size / zoom;
}
public float toCurrentScale(float size) {
return size * zoom;
}
public float getZoom() {
return zoom;
}
public boolean isZooming() {
return zoom != minZoom;
}
public float getOptimalPageWidth() {
return optimalPageWidth;
}
public float getOptimalPageHeight() {
return optimalPageHeight;
}
private void setDefaultPage(int defaultPage) {
this.defaultPage = defaultPage;
}
public void resetZoom() {
zoomTo(minZoom);
}
public void resetZoomWithAnimation() {
zoomWithAnimation(minZoom);
}
public void zoomWithAnimation(float centerX, float centerY, float scale) {
48
animationManager.startZoomAnimation(centerX, centerY, zoom, scale);
}
public void zoomWithAnimation(float scale) {
animationManager.startZoomAnimation(getWidth() / 2, getHeight() / 2, zoom, scale);
}
private void setScrollHandle(ScrollHandle scrollHandle) {
this.scrollHandle = scrollHandle;
}
public int getPageAtPositionOffset(float positionOffset) {
int page = (int) Math.floor(getPageCount() * positionOffset);
return page == getPageCount() ? page - 1 : page;
}
public float getMinZoom() {
return minZoom;
}
public void setMinZoom(float minZoom) {
this.minZoom = minZoom;
}
public float getMidZoom() {
return midZoom;
}
public void setMidZoom(float midZoom) {
this.midZoom = midZoom;
}
public float getMaxZoom() {
return maxZoom;
}
public void setMaxZoom(float maxZoom) {
49
this.maxZoom = maxZoom;
}
public void useBestQuality(boolean bestQuality) {
this.bestQuality = bestQuality;
}
public boolean isBestQuality() {
return bestQuality;
}
public boolean isSwipeVertical() {
return swipeVertical;
}
public void setSwipeVertical(boolean swipeVertical) {
this.swipeVertical = swipeVertical;
}
public void enableAnnotationRendering(boolean annotationRendering) {
this.annotationRendering = annotationRendering;
}
public boolean isAnnotationRendering() {
return annotationRendering;
}
public void enableRenderDuringScale(boolean renderDuringScale) {
this.renderDuringScale = renderDuringScale;
}
public boolean isAntialiasing() {
return enableAntialiasing;
}
public void enableAntialiasing(boolean enableAntialiasing) {
this.enableAntialiasing = enableAntialiasing;
}
50
int getSpacingPx() {
return spacingPx;
}
private void setSpacing(int spacing) {
this.spacingPx = Util.getDP(getContext(), spacing);
}
private void setInvalidPageColor(int invalidPageColor) {
this.invalidPageColor = invalidPageColor;
}
public int getInvalidPageColor() {
return invalidPageColor;
}
public boolean doRenderDuringScale() {
return renderDuringScale;
}
public PdfDocument.Meta getDocumentMeta() {
if (pdfDocument == null) {
return null;
}
return pdfiumCore.getDocumentMeta(pdfDocument);
}
public List
getTableOfContents() {
if (pdfDocument == null) {
return new ArrayList<>();
}
return pdfiumCore.getTableOfContents(pdfDocument);
}
public Configurator fromAsset(String assetName) {
return new Configurator(new AssetSource(assetName));
51
}
public Configurator fromFile(File file) {
return new Configurator(new FileSource(file));
}
public Configurator fromUri(Uri uri) {
return new Configurator(new UriSource(uri));
}
public Configurator fromBytes(byte[] bytes) {
return new Configurator(new ByteArraySource(bytes));
}
public Configurator fromStream(InputStream stream) {
return new Configurator(new InputStreamSource(stream));
}
public Configurator fromSource(DocumentSource docSource) {
return new Configurator(docSource);
}
private enum State {DEFAULT, LOADED, SHOWN, ERROR}
public class Configurator {
private final DocumentSource documentSource;
private int[] pageNumbers = null;
private boolean enableSwipe = true;
private boolean enableDoubletap = true;
private OnDrawListener onDrawListener;
private OnDrawListener onDrawAllListener;
private OnLoadCompleteListener onLoadCompleteListener;
private OnErrorListener onErrorListener;
private OnPageChangeListener onPageChangeListener;
private OnPageScrollListener onPageScrollListener;
private OnRenderListener onRenderListener;
52
private OnTapListener onTapListener;
private OnPageErrorListener onPageErrorListener;
private int defaultPage = 0;
private boolean swipeHorizontal = false;
private boolean annotationRendering = false;
private String password = null;
private ScrollHandle scrollHandle = null;
private boolean antialiasing = true;
private int spacing = 0;
private int invalidPageColor = Color.WHITE;
private Configurator(DocumentSource documentSource) {
this.documentSource = documentSource;
}
public Configurator pages(int... pageNumbers) {
this.pageNumbers = pageNumbers;
return this;
}
public Configurator enableSwipe(boolean enableSwipe) {
this.enableSwipe = enableSwipe;
return this;
}
public Configurator enableDoubletap(boolean enableDoubletap) {
this.enableDoubletap = enableDoubletap;
return this;
}
public Configurator enableAnnotationRendering(boolean annotationRendering) {
this.annotationRendering = annotationRendering;
return this;
}
public Configurator onDraw(OnDrawListener onDrawListener) {
53
this.onDrawListener = onDrawListener;
return this;
}
public Configurator onDrawAll(OnDrawListener onDrawAllListener) {
this.onDrawAllListener = onDrawAllListener;
return this;
}
public Configurator onLoad(OnLoadCompleteListener onLoadCompleteListener) {
this.onLoadCompleteListener = onLoadCompleteListener;
return this;
}
public Configurator onPageScroll(OnPageScrollListener onPageScrollListener) {
this.onPageScrollListener = onPageScrollListener;
return this;
}
public Configurator onError(OnErrorListener onErrorListener) {
this.onErrorListener = onErrorListener;
return this;
}
public Configurator onPageError(OnPageErrorListener onPageErrorListener) {
this.onPageErrorListener = onPageErrorListener;
return this;
}
public Configurator onPageChange(OnPageChangeListener onPageChangeListener) {
this.onPageChangeListener = onPageChangeListener;
return this;
}
public Configurator onRender(OnRenderListener onRenderListener) {
this.onRenderListener = onRenderListener;
return this;
54
}
public Configurator onTap(OnTapListener onTapListener) {
this.onTapListener = onTapListener;
return this;
}
public Configurator defaultPage(int defaultPage) {
this.defaultPage = defaultPage;
return this;
}
public Configurator swipeHorizontal(boolean swipeHorizontal) {
this.swipeHorizontal = swipeHorizontal;
return this;
}
public Configurator password(String password) {
this.password = password;
return this;
}
public Configurator scrollHandle(ScrollHandle scrollHandle) {
this.scrollHandle = scrollHandle;
return this;
}
public Configurator enableAntialiasing(boolean antialiasing) {
this.antialiasing = antialiasing;
return this;
}
public Configurator spacing(int spacing) {
this.spacing = spacing;
return this;
}
55
public Configurator invalidPageColor(int invalidPageColor) {
this.invalidPageColor = invalidPageColor;
return this;
}
public void load() {
PDFView.this.recycle();
PDFView.this.setOnDrawListener(onDrawListener);
PDFView.this.setOnDrawAllListener(onDrawAllListener);
PDFView.this.setOnPageChangeListener(onPageChangeListener);
PDFView.this.setOnPageScrollListener(onPageScrollListener);
PDFView.this.setOnRenderListener(onRenderListener);
PDFView.this.setOnTapListener(onTapListener);
PDFView.this.setOnPageErrorListener(onPageErrorListener);
PDFView.this.enableSwipe(enableSwipe);
PDFView.this.enableDoubletap(enableDoubletap);
PDFView.this.setDefaultPage(defaultPage);
PDFView.this.setSwipeVertical(!swipeHorizontal);
PDFView.this.enableAnnotationRendering(annotationRendering);
PDFView.this.setScrollHandle(scrollHandle);
PDFView.this.enableAntialiasing(antialiasing);
PDFView.this.setSpacing(spacing);
PDFView.this.setInvalidPageColor(invalidPageColor);
PDFView.this.dragPinchManager.setSwipeVertical(swipeVertical);
PDFView.this.post(new Runnable() {
@Override
public void run() {
if (pageNumbers != null) {
PDFView.this.load(documentSource, password, onLoadCompleteListener,
onErrorListener, pageNumbers);
} else {
56
PDFView.this.load(documentSource, password, onLoadCompleteListener,
onErrorListener);
}
}
}
}
}
}
57
Do'stlaringiz bilan baham: |