com.github.barteksc.pdfviewer.util.Util Java Examples
The following examples show how to use
com.github.barteksc.pdfviewer.util.Util.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScrollBarPageIndicator.java From AndroidPdfViewerV1 with Apache License 2.0 | 6 votes |
/** * Used by the ScrollBar to move the indicator with the handle * * @param pos Position to which the indicator should move. */ void setScroll(float pos) { if (getVisibility() == VISIBLE) { int indicatorSize, viewSize; if (!scrollBar.isHorizontal()) { indicatorSize = INDICATOR_HEIGHT; viewSize = scrollBar.getHeight(); } else { indicatorSize = INDICATOR_WIDTH; viewSize = scrollBar.getWidth(); } pos -= Util.getDP(getContext(), indicatorSize / 2) - scrollBar.getHandlerHeight() / 2; if (pos < 5) { pos = 5; } else if (pos > viewSize - Util.getDP(getContext(), indicatorSize)) { pos = viewSize - Util.getDP(getContext(), indicatorSize); } if (!scrollBar.isHorizontal()) { setY(pos); } else { setX(pos); } } }
Example #2
Source File: DefaultScrollHandle.java From AndroidPdfViewerV2 with Apache License 2.0 | 5 votes |
private void setPosition(float pos) { if (Float.isInfinite(pos) || Float.isNaN(pos)) { return; } float pdfViewSize; if (pdfView.isSwipeVertical()) { pdfViewSize = pdfView.getHeight(); } else { pdfViewSize = pdfView.getWidth(); } pos -= relativeHandlerMiddle; if (pos < 0) { pos = 0; } else if (pos > pdfViewSize - Util.getDP(context, HANDLE_SHORT)) { pos = pdfViewSize - Util.getDP(context, HANDLE_SHORT); } if (pdfView.isSwipeVertical()) { setY(pos); } else { setX(pos); } calculateMiddle(); invalidate(); }
Example #3
Source File: ScrollBarPageIndicator.java From AndroidPdfViewerV1 with Apache License 2.0 | 5 votes |
void addToScrollBar(ScrollBar scrollBar) { //determine ScrollBar's position LayoutParams lp = new LayoutParams(Util.getDP(getContext(), INDICATOR_WIDTH), Util.getDP(getContext(), INDICATOR_HEIGHT)); int align, left = 0, top = 0, right = 0, bottom = 0, margin = Util.getDP(getContext(), 15); View parent = (View) scrollBar.getParent(); if (!scrollBar.isHorizontal()) { if (scrollBar.getX() > parent.getWidth() - scrollBar.getX() + scrollBar.getWidth()) { //scrollbar to the right right = margin + scrollBar.getWidth(); align = ALIGN_RIGHT; } else { //scrollBar to the left left = margin + scrollBar.getWidth(); align = ALIGN_LEFT; } } else { if (scrollBar.getY() > parent.getHeight() - scrollBar.getY() + scrollBar.getHeight()) { //scrollbar to the bottom bottom = margin + scrollBar.getHeight(); align = ALIGN_BOTTOM; } else { //scrollbar to the top top = margin + scrollBar.getHeight(); align = ALIGN_TOP; } } lp.setMargins(left, top, right, bottom); lp.addRule(align, scrollBar.getId()); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, INDICATOR_TEXT_SIZE); LayoutParams tvlp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); addView(textView, tvlp); ((ViewGroup) scrollBar.getParent()).addView(this, lp); this.scrollBar = scrollBar; }
Example #4
Source File: ScrollBar.java From AndroidPdfViewerV1 with Apache License 2.0 | 5 votes |
private void init() { indicator = new ScrollBarPageIndicator(getContext()); setIndicatorPage(currentPage); indicator.setBackgroundColor(indicatorColor); indicator.setTextColor(indicatorTextColor); addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { indicator.addToScrollBar(ScrollBar.this); ScrollBar.this.removeOnLayoutChangeListener(this); } }); handlerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); handlerPaint.setStyle(Paint.Style.FILL); handlerPaint.setColor(handlerColor); if (getBackground() == null) { setBackgroundColor(Color.LTGRAY); } handlerPos = new PointF(0, 0); viewWidth = Util.getDP(getContext(), 30); }
Example #5
Source File: ScrollBar.java From AndroidPdfViewerV1 with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode()) { if (!horizontal) { canvas.drawRect(0, 0, getWidth(), Util.getDP(getContext(), 40), handlerPaint); } else { canvas.drawRect(0, 0, Util.getDP(getContext(), 40), getHeight(), handlerPaint); } return; } else if (!isPDFViewReady()) { return; } if (Float.isNaN(getHandlerPos()) || Float.isInfinite(getHandlerPos())) { calculateHandlerPosByPage(currentPage); } if (!horizontal) { canvas.drawRect(handlerPos.x, handlerPos.y, getWidth(), getHandlerPos() + handlerHeight, handlerPaint); } else { canvas.drawRect(handlerPos.x, handlerPos.y, getHandlerPos() + handlerHeight, getHeight(), handlerPaint); } }
Example #6
Source File: DefaultScrollHandle.java From AndroidPdfViewer with Apache License 2.0 | 5 votes |
private void setPosition(float pos) { if (Float.isInfinite(pos) || Float.isNaN(pos)) { return; } float pdfViewSize; if (pdfView.isSwipeVertical()) { pdfViewSize = pdfView.getHeight(); } else { pdfViewSize = pdfView.getWidth(); } pos -= relativeHandlerMiddle; if (pos < 0) { pos = 0; } else if (pos > pdfViewSize - Util.getDP(context, HANDLE_SHORT)) { pos = pdfViewSize - Util.getDP(context, HANDLE_SHORT); } if (pdfView.isSwipeVertical()) { setY(pos); } else { setX(pos); } calculateMiddle(); invalidate(); }
Example #7
Source File: PDFView.java From AndroidPdfViewerV2 with Apache License 2.0 | 4 votes |
private void setSpacing(int spacing) { this.spacingPx = Util.getDP(getContext(), spacing); }
Example #8
Source File: InputStreamSource.java From AndroidPdfViewerV2 with Apache License 2.0 | 4 votes |
@Override public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { return core.newDocument(Util.toByteArray(inputStream), password); }
Example #9
Source File: DefaultScrollHandle.java From AndroidPdfViewerV2 with Apache License 2.0 | 4 votes |
@Override public void setupLayout(PDFView pdfView) { int align, width, height; Drawable background; // determine handler position, default is right (when scrolling vertically) or bottom (when scrolling horizontally) if (pdfView.isSwipeVertical()) { width = HANDLE_LONG; height = HANDLE_SHORT; if (inverted) { // left align = ALIGN_PARENT_LEFT; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_left); } else { // right align = ALIGN_PARENT_RIGHT; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_right); } } else { width = HANDLE_SHORT; height = HANDLE_LONG; if (inverted) { // top align = ALIGN_PARENT_TOP; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_top); } else { // bottom align = ALIGN_PARENT_BOTTOM; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_bottom); } } if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { setBackgroundDrawable(background); } else { setBackground(background); } LayoutParams lp = new LayoutParams(Util.getDP(context, width), Util.getDP(context, height)); lp.setMargins(0, 0, 0, 0); LayoutParams tvlp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); addView(textView, tvlp); lp.addRule(align); pdfView.addView(this, lp); this.pdfView = pdfView; }
Example #10
Source File: ScrollBarPageIndicator.java From AndroidPdfViewerV1 with Apache License 2.0 | 4 votes |
public void setSize(int size) { LayoutParams lp = (LayoutParams) getLayoutParams(); lp.setMargins(0, 0, size + Util.getDP(getContext(), 10), 0); setLayoutParams(lp); }
Example #11
Source File: InputStreamSource.java From AndroidPdfViewerV1 with Apache License 2.0 | 4 votes |
@Override public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { return core.newDocument(Util.toByteArray(inputStream), password); }
Example #12
Source File: PDFView.java From AndroidPdfViewer with Apache License 2.0 | 4 votes |
private void setSpacing(int spacingDp) { this.spacingPx = Util.getDP(getContext(), spacingDp); }
Example #13
Source File: PagesLoader.java From AndroidPdfViewer with Apache License 2.0 | 4 votes |
PagesLoader(PDFView pdfView) { this.pdfView = pdfView; this.preloadOffset = Util.getDP(pdfView.getContext(), PRELOAD_OFFSET); }
Example #14
Source File: InputStreamSource.java From AndroidPdfViewer with Apache License 2.0 | 4 votes |
@Override public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { return core.newDocument(Util.toByteArray(inputStream), password); }
Example #15
Source File: DefaultScrollHandle.java From AndroidPdfViewer with Apache License 2.0 | 4 votes |
@Override public void setupLayout(PDFView pdfView) { int align, width, height; Drawable background; // determine handler position, default is right (when scrolling vertically) or bottom (when scrolling horizontally) if (pdfView.isSwipeVertical()) { width = HANDLE_LONG; height = HANDLE_SHORT; if (inverted) { // left align = ALIGN_PARENT_LEFT; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_left); } else { // right align = ALIGN_PARENT_RIGHT; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_right); } } else { width = HANDLE_SHORT; height = HANDLE_LONG; if (inverted) { // top align = ALIGN_PARENT_TOP; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_top); } else { // bottom align = ALIGN_PARENT_BOTTOM; background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_bottom); } } if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { setBackgroundDrawable(background); } else { setBackground(background); } LayoutParams lp = new LayoutParams(Util.getDP(context, width), Util.getDP(context, height)); lp.setMargins(0, 0, 0, 0); LayoutParams tvlp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); addView(textView, tvlp); lp.addRule(align); pdfView.addView(this, lp); this.pdfView = pdfView; }