Example usage for android.graphics Path Path

List of usage examples for android.graphics Path Path

Introduction

In this page you can find the example usage for android.graphics Path Path.

Prototype

public Path() 

Source Link

Document

Create an empty path

Usage

From source file:com.knightweng.android.takemehome.presentation.view.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);/*from  w  w  w  .  j  a va  2  s.  co m*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    // dividerPaint = new Paint();
    // dividerPaint.setAntiAlias(true);
    // dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    path = new Path();

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.journeyapps.barcodescanner.WXViewfinderView.java

@SuppressLint("DrawAllocation")
@Override/*from   ww  w.j a  va  2  s  .co m*/
public void onDraw(Canvas canvas) {
    refreshSizes();
    if (framingRect == null || previewFramingRect == null) {
        return;
    }

    Rect frame = framingRect;
    Rect previewFrame = previewFramingRect;

    int width = canvas.getWidth();
    int height = canvas.getHeight();

    maskPaint.setColor(maskColor);
    canvas.drawRect(0, 0, width, frame.top, maskPaint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint);
    canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint);
    //drawable the border
    canvas.drawRect(frame.left + 1, frame.top + 1, frame.right, frame.bottom, borderPaint);
    int halfWidth = (int) (cornerWidth / 2);
    //draw four corner
    Path corner1 = new Path();
    corner1.moveTo(frame.left, frame.top + cornerLength);
    corner1.lineTo(frame.left, frame.top);
    corner1.lineTo(frame.left + cornerLength, frame.top);
    Matrix translate1 = new Matrix();
    translate1.setTranslate(halfWidth, halfWidth);
    corner1.transform(translate1);
    canvas.drawPath(corner1, cornerPaint);

    Path corner2 = new Path();
    corner2.moveTo(frame.right + 1 - cornerLength, frame.top);
    corner2.lineTo(frame.right + 1, frame.top);
    corner2.lineTo(frame.right + 1, frame.top + cornerLength);
    Matrix translate2 = new Matrix();
    translate2.setTranslate(-halfWidth, halfWidth);
    corner2.transform(translate2);
    canvas.drawPath(corner2, cornerPaint);

    Path corner3 = new Path();
    corner3.moveTo(frame.left, frame.bottom + 1 - cornerLength);
    corner3.lineTo(frame.left, frame.bottom + 1);
    corner3.lineTo(frame.left + cornerLength, frame.bottom + 1);
    Matrix translate3 = new Matrix();
    translate3.setTranslate(halfWidth, -halfWidth);
    corner3.transform(translate3);
    canvas.drawPath(corner3, cornerPaint);

    Path corner4 = new Path();
    corner4.moveTo(frame.right + 1 - cornerLength, frame.bottom + 1);
    corner4.lineTo(frame.right + 1, frame.bottom + 1);
    corner4.lineTo(frame.right + 1, frame.bottom + 1 - cornerLength);
    Matrix translate4 = new Matrix();
    translate4.setTranslate(-halfWidth, -halfWidth);
    corner4.transform(translate4);
    canvas.drawPath(corner4, cornerPaint);

    offset += speed;
    if (offset >= frame.bottom - frame.top) {
        offset = 0;
    }
    Rect rect = new Rect();
    rect.left = frame.left + 1 + laserPadding;
    rect.top = frame.top + 1 + offset;
    rect.right = frame.right - laserPadding;
    rect.bottom = frame.top + 1 + offset + 3;

    Bitmap laserBitmap = ((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.scan_laser,
            null)).getBitmap();
    canvas.drawBitmap(laserBitmap, null, rect, linePaint);

    textPaint.setTextAlign(Paint.Align.CENTER);

    canvas.drawText(statusText, (frame.right + frame.left) / 2,
            frame.bottom + statusTextPadding + statusTextSize, textPaint);

    postInvalidateDelayed(animationDelay, frame.left, frame.top, frame.right, frame.bottom);

}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

/**
 * MARK: Update drawings//from   w w w . j  a v  a2 s.c o  m
 */

private void makePathBlack() {

    if (mPathBlack == null) {
        mPathBlack = new Path();
    }

    Path p = new Path();
    p.moveTo(Math.max(getPaddingLeft(), mProgress * mWidth / 100), mHeight / 2 + calculateDeltaY());
    p.lineTo(mWidth, mHeight / 2);

    mPathBlack.set(p);
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

private void onClearSign() {
    if (mNotInitialized)
        mNotInitialized = false;/*from ww w  .  ja  v a  2s .c  o m*/

    mPaths.clear();
    mPath = new Path();
    mPaths.add(mPath);

    postInvalidate();
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

private void makePathWhite() {

    if (mPathWhite == null) {
        mPathWhite = new Path();
    }//from   w w w . j ava  2 s. c  om

    Path p = new Path();
    p.moveTo(getPaddingLeft(), mHeight / 2);
    p.lineTo(Math.max(getPaddingLeft(), mProgress * mWidth / 100), mHeight / 2 + calculateDeltaY());

    mPathWhite.set(p);
}

From source file:com.daitu_liang.study.mytest.svg.AnimatedSvgView.java

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override/*from ww  w.j a v  a  2s .  c  o  m*/
        protected float transformX(float x) {
            return x * mWidth / mViewport.x;
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / mViewport.y;
        }
    };

    Log.i(TAG, "---mWidth = " + mWidth + "---mViewport.x = " + mViewport.x);
    if (mGlyphStrings != null) {
        mGlyphData = new GlyphData[mGlyphStrings.length];
    }
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]);
        } catch (ParseException e) {
            mGlyphData[i].path = new Path();
            Log.e(TAG, "Couldn't parse path", e);
        }
        PathMeasure pm = new PathMeasure(mGlyphData[i].path, true);
        while (true) {
            mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength());
            if (!pm.nextContour()) {
                break;
            }
        }
        mGlyphData[i].paint = new Paint();
        mGlyphData[i].paint.setStyle(Paint.Style.STROKE);
        mGlyphData[i].paint.setAntiAlias(true);
        mGlyphData[i].paint.setColor(Color.WHITE);
        mGlyphData[i].paint.setStrokeWidth(
                TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    }
}

From source file:cc.kenai.common.AnimatedSvgView.java

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override/*from   w  w  w  .  j a  va2s . c o  m*/
        protected float transformX(float x) {
            return x * mWidth / mViewport.x;
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / mViewport.y;
        }
    };

    Log.i(TAG, "---mWidth = " + mWidth + "---mViewport.x = " + mViewport.x);
    Log.i(TAG, "mGlyphStrings.length = " + mGlyphStrings.length);
    mGlyphData = new GlyphData[mGlyphStrings.length];
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]);
        } catch (ParseException e) {
            mGlyphData[i].path = new Path();
            Log.e(TAG, "Couldn't parse path", e);
        }
        PathMeasure pm = new PathMeasure(mGlyphData[i].path, true);
        while (true) {
            mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength());
            if (!pm.nextContour()) {
                break;
            }
        }
        mGlyphData[i].paint = new Paint();
        mGlyphData[i].paint.setStyle(Paint.Style.STROKE);
        mGlyphData[i].paint.setAntiAlias(true);
        mGlyphData[i].paint.setColor(Color.WHITE);
        mGlyphData[i].paint.setStrokeWidth(
                TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    }
}

From source file:com.justwayward.reader.view.RVPIndicator.java

/**
 * (?view)/* www.j  a  v  a  2s.c  om*/
 */
@Override
protected void dispatchDraw(Canvas canvas) {
    // ?
    canvas.save();

    switch (mIndicatorStyle) {

    case STYLE_BITMAP:

        canvas.translate(mTranslationX, 0);
        canvas.drawBitmap(mBitmap, null, mRectF, mPaint);

        break;
    case STYLE_LINE:

        canvas.translate(mTranslationX, getHeight() - mIndicatorHeight);
        canvas.drawRect(mRectF, mPaint);

        break;
    case STYLE_SQUARE:

        canvas.translate(mTranslationX, 0);
        canvas.drawRect(mRectF, mPaint);

        break;
    case STYLE_TRIANGLE:

        canvas.translate(mTranslationX, 0);
        // 
        // mPaint.setPathEffect(new CornerPathEffect(10));
        mPath = new Path();
        int midOfTab = getWidth() / mTabVisibleCount / 2;
        mPath.moveTo(midOfTab, getHeight() - mIndicatorHeight);
        mPath.lineTo(midOfTab - mIndicatorWidth / 2, getHeight());
        mPath.lineTo(midOfTab + mIndicatorWidth / 2, getHeight());
        mPath.close();
        canvas.drawPath(mPath, mPaint);

        break;
    }

    // ??
    canvas.restore();
    super.dispatchDraw(canvas);
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

private void makePathBubble() {

    if (mPathBubble == null) {
        mPathBubble = new Path();
    }//from ww w  .  ja  v  a 2  s  . c  om

    int width = mBubbleWidth;
    int height = mBubbleHeight;
    int arrowWidth = width / 3;

    //Rect r = new Rect(Math.max(getPaddingLeft()-width/2-arrowWidth/4, mProgress*mWidth/100-width/2-arrowWidth/4), mHeight/2-height + calculatedeltaY(), Math.max(getPaddingLeft()+width/2-arrowWidth/4, mProgress*mWidth/100+width/2-arrowWidth/4), mHeight/2+height-height + calculatedeltaY());
    Rect r = new Rect((int) (Math.max(getPaddingLeft() - width / 2, mProgress * mWidth / 100 - width / 2)),
            (int) (mHeight / 2 - height + calculateDeltaY()),
            (int) (Math.max(getPaddingLeft() + width / 2, mProgress * mWidth / 100 + width / 2)),
            (int) (mHeight / 2 + height - height + calculateDeltaY()));
    int arrowHeight = (int) (arrowWidth / 1.5f);
    int radius = 8;

    Path path = new Path();

    // Down arrow
    path.moveTo(r.left + r.width() / 2 - arrowWidth / 2, r.top + r.height() - arrowHeight);
    bubbleAnchorX = r.left + r.width() / 2;
    bubbleAnchorY = r.top + r.height();
    path.lineTo(bubbleAnchorX, bubbleAnchorY);
    path.lineTo(r.left + r.width() / 2 + arrowWidth / 2, r.top + r.height() - arrowHeight);

    // Go to bottom-right
    path.lineTo(r.left + r.width() - radius, r.top + r.height() - arrowHeight);

    // Bottom-right arc
    path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top + r.height() - arrowHeight - 2 * radius,
            r.left + r.width(), r.top + r.height() - arrowHeight), 90, -90);

    // Go to upper-right
    path.lineTo(r.left + r.width(), r.top + arrowHeight);

    // Upper-right arc
    path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top, r.right, r.top + 2 * radius), 0, -90);

    // Go to upper-left
    path.lineTo(r.left + radius, r.top);

    // Upper-left arc
    path.arcTo(new RectF(r.left, r.top, r.left + 2 * radius, r.top + 2 * radius), 270, -90);

    // Go to bottom-left
    path.lineTo(r.left, r.top + r.height() - arrowHeight - radius);

    // Bottom-left arc
    path.arcTo(new RectF(r.left, r.top + r.height() - arrowHeight - 2 * radius, r.left + 2 * radius,
            r.top + r.height() - arrowHeight), 180, -90);

    path.close();

    mPathBubble.set(path);
}

From source file:com.donsen.svg.ui.common.AnimatedSvgView.java

private void rebuildGlyphData() {
    SvgPathParser parser = new SvgPathParser() {
        @Override//from w ww. j  a  v  a 2 s .c om
        protected float transformX(float x) {
            return x * mWidth / mViewport.x;
        }

        @Override
        protected float transformY(float y) {
            return y * mHeight / mViewport.y;
        }
    };

    mGlyphData = new GlyphData[mGlyphStrings.length];
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]);
        } catch (ParseException e) {
            mGlyphData[i].path = new Path();
            Log.e(TAG, "Couldn't parse path", e);
        }
        PathMeasure pm = new PathMeasure(mGlyphData[i].path, true);
        while (true) {
            mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength());
            if (!pm.nextContour()) {
                break;
            }
        }
        mGlyphData[i].paint = new Paint();
        mGlyphData[i].paint.setStyle(Paint.Style.STROKE);
        mGlyphData[i].paint.setAntiAlias(true);
        mGlyphData[i].paint.setColor(Color.WHITE);
        mGlyphData[i].paint.setStrokeWidth(
                TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    }
}