Java Code Examples for com.github.barteksc.pdfviewer.util.Util#getDP()

The following examples show how to use com.github.barteksc.pdfviewer.util.Util#getDP() . 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 vote down vote up
/**
 * 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 vote down vote up
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 vote down vote up
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 vote down vote up
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: DefaultScrollHandle.java    From AndroidPdfViewer with Apache License 2.0 5 votes vote down vote up
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 6
Source File: PDFView.java    From AndroidPdfViewerV2 with Apache License 2.0 4 votes vote down vote up
private void setSpacing(int spacing) {
    this.spacingPx = Util.getDP(getContext(), spacing);
}
 
Example 7
Source File: DefaultScrollHandle.java    From AndroidPdfViewerV2 with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: PDFView.java    From AndroidPdfViewer with Apache License 2.0 4 votes vote down vote up
private void setSpacing(int spacingDp) {
    this.spacingPx = Util.getDP(getContext(), spacingDp);
}
 
Example 9
Source File: PagesLoader.java    From AndroidPdfViewer with Apache License 2.0 4 votes vote down vote up
PagesLoader(PDFView pdfView) {
    this.pdfView = pdfView;
    this.preloadOffset = Util.getDP(pdfView.getContext(), PRELOAD_OFFSET);
}
 
Example 10
Source File: DefaultScrollHandle.java    From AndroidPdfViewer with Apache License 2.0 4 votes vote down vote up
@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;
}