Java Code Examples for android.graphics.Paint#setPathEffect()

The following examples show how to use android.graphics.Paint#setPathEffect() . 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: SegmentedButton.java    From SegmentedButton with Apache License 2.0 6 votes vote down vote up
/**
 * Set the border for the selected button
 *
 * @param width     Width of the border in pixels (default value is 0px or no border)
 * @param color     Color of the border (default color is black)
 * @param dashWidth Width of the dash for border, in pixels. Value of 0px means solid line (default is 0px)
 * @param dashGap   Width of the gap for border, in pixels.
 */
void setSelectedButtonBorder(int width, @ColorInt int color, int dashWidth, int dashGap)
{
    if (width > 0)
    {
        // Allocate Paint object for drawing border here
        // Used in onDraw to draw the border around the selected button
        selectedButtonBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        selectedButtonBorderPaint.setStyle(Paint.Style.STROKE);
        selectedButtonBorderPaint.setStrokeWidth(width);
        selectedButtonBorderPaint.setColor(color);

        if (dashWidth > 0.0f)
        {
            selectedButtonBorderPaint.setPathEffect(new DashPathEffect(new float[] {dashWidth, dashGap}, 0));
        }
    }
    else
    {
        // If the width is 0, then disable drawing border
        selectedButtonBorderPaint = null;
    }

    invalidate();
}
 
Example 2
Source File: DvbParser.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct an instance for the given subtitle and ancillary page ids.
 *
 * @param subtitlePageId The id of the subtitle page carrying the subtitle to be parsed.
 * @param ancillaryPageId The id of the ancillary page containing additional data.
 */
public DvbParser(int subtitlePageId, int ancillaryPageId) {
  defaultPaint = new Paint();
  defaultPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  defaultPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
  defaultPaint.setPathEffect(null);
  fillRegionPaint = new Paint();
  fillRegionPaint.setStyle(Paint.Style.FILL);
  fillRegionPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
  fillRegionPaint.setPathEffect(null);
  canvas = new Canvas();
  defaultDisplayDefinition = new DisplayDefinition(719, 575, 0, 719, 0, 575);
  defaultClutDefinition = new ClutDefinition(0, generateDefault2BitClutEntries(),
      generateDefault4BitClutEntries(), generateDefault8BitClutEntries());
  subtitleService = new SubtitleService(subtitlePageId, ancillaryPageId);
}
 
Example 3
Source File: ChartNetworkSeriesView.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public void setChartColor(int stroke, int fill, int fillSecondary) {
    mPaintStroke = new Paint();
    mPaintStroke.setStrokeWidth(4.0f * getResources().getDisplayMetrics().density);
    mPaintStroke.setColor(stroke);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setAntiAlias(true);

    mPaintFill = new Paint();
    mPaintFill.setColor(fill);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setAntiAlias(true);

    mPaintFillSecondary = new Paint();
    mPaintFillSecondary.setColor(fillSecondary);
    mPaintFillSecondary.setStyle(Style.FILL);
    mPaintFillSecondary.setAntiAlias(true);

    mPaintEstimate = new Paint();
    mPaintEstimate.setStrokeWidth(3.0f);
    mPaintEstimate.setColor(fillSecondary);
    mPaintEstimate.setStyle(Style.STROKE);
    mPaintEstimate.setAntiAlias(true);
    mPaintEstimate.setPathEffect(new DashPathEffect(new float[] { 10, 10 }, 1));
}
 
Example 4
Source File: ViewPagerIndicator.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
public ViewPagerIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    //获取可见的tab数量
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerIndicator);
    mVisibleTabCount = a.getInt(R.styleable.ViewPagerIndicator_visibleTabCount, 3);
    tabSelectedColor = a.getColor(R.styleable.ViewPagerIndicator_tabSelectedColor, getResources().getColor(R.color.orange_red_300));
    spaceHeight = (int) a.getDimension(R.styleable.ViewPagerIndicator_spaceHeight, 2);
    tabNormalColor = a.getColor(R.styleable.ViewPagerIndicator_tabNormalColor, getResources().getColor(R.color.black_transparency_500));
    lineHeight = (int) a.getDimension(R.styleable.ViewPagerIndicator_lineHeight, 2);
    tabTextSize = (int) a.getDimension(R.styleable.ViewPagerIndicator_tabTextSize, 14);
    margin = (int) a.getDimension(R.styleable.ViewPagerIndicator_margin, 0);
    int lineColor = a.getColor(R.styleable.ViewPagerIndicator_lineColor, getResources().getColor(R.color.orange_500));
    if (mVisibleTabCount < 0) {
        mVisibleTabCount = 3;
    }
    a.recycle();
    mPath = new Path();
    //初始化画笔
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(lineColor);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setPathEffect(new CornerPathEffect(3));
    setOrientation(HORIZONTAL);
}
 
Example 5
Source File: ScatterGraphView.java    From HzGrapher with Apache License 2.0 5 votes vote down vote up
private void setPaint()
{
	pPoint = new Paint();
	pPoint.setFlags(Paint.ANTI_ALIAS_FLAG);
	pPoint.setAntiAlias(true);
	pPoint.setFilterBitmap(true);
	pPoint.setColor(Color.BLUE);
	pPoint.setStrokeWidth(2);
	pPoint.setStyle(Style.FILL_AND_STROKE);
	
	pBaseLine = new Paint();
	pBaseLine.setFlags(Paint.ANTI_ALIAS_FLAG);
	pBaseLine.setAntiAlias(true);
	pBaseLine.setFilterBitmap(true);
	pBaseLine.setColor(Color.GRAY);
	pBaseLine.setStrokeWidth(3);
	
	pBaseLineD = new Paint();
	pBaseLineD.setFlags(Paint.ANTI_ALIAS_FLAG);
	pBaseLineD.setAntiAlias(true);
	pBaseLineD.setFilterBitmap(true);
	pBaseLineD.setColor(0xffcccccc);
	pBaseLineD.setStrokeWidth(1);
	pBaseLineD.setStyle(Style.STROKE);
	pBaseLineD.setPathEffect(new DashPathEffect(new float[] {10,5}, 0));
	
	pMarkText = new Paint();
	pMarkText.setFlags(Paint.ANTI_ALIAS_FLAG);
	pMarkText.setAntiAlias(true);
	pMarkText.setColor(Color.BLACK); 
	
}
 
Example 6
Source File: TreeView.java    From BackgroundView with Apache License 2.0 5 votes vote down vote up
private void init() {
    mPaint = new Paint();
    // 绘制贝塞尔曲线
    mPaint.setColor(mColor);
    mPaint.setStrokeWidth(8);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setTextSize(60);
    mPaint.setPathEffect(new CornerPathEffect(4));

}
 
Example 7
Source File: VoronoiView.java    From Vorolay with Apache License 2.0 5 votes vote down vote up
private void initPaint() {
    p = new Paint();
    p.setAntiAlias(true);
    p.setColor(mBorderColor);
    p.setStrokeWidth(mBorderWidth);
    p.setStyle(Paint.Style.STROKE);

    if (mRoundCornersEnabled) {
        p.setStrokeJoin(Paint.Join.ROUND);
        p.setStrokeCap(Paint.Cap.SQUARE);
        p.setPathEffect(new CornerPathEffect(15));
    }
}
 
Example 8
Source File: NightingaleRoseChart.java    From OXChart with Apache License 2.0 5 votes vote down vote up
public void init(Context context, AttributeSet attrs, int defStyleAttr) {
    dataList = new ArrayList<>();
    DisplayMetrics dm = getResources().getDisplayMetrics();
    ScrHeight = dm.heightPixels;
    ScrWidth = dm.widthPixels;

    //画笔初始化
    paintArc = new Paint();
    paintArc.setAntiAlias(true);

    paintLabel = new Paint();
    paintLabel.setAntiAlias(true);

    paintSelected = new Paint();
    paintSelected.setColor(Color.LTGRAY);
    paintSelected.setStyle(Paint.Style.STROKE);//设置空心
    paintSelected.setStrokeWidth(lineWidth*5);
    paintSelected.setAntiAlias(true);

    mLinePaint = new Paint();
    mLinePaint.setStyle(Paint.Style.FILL);
    mLinePaint.setStrokeWidth(lineWidth);
    mLinePaint.setAntiAlias(true);


    mlableLinePaint = new Paint();
    mlableLinePaint.setStyle(Paint.Style.STROKE);
    mlableLinePaint.setColor(Color.DKGRAY);
    mlableLinePaint.setStrokeWidth(3);
    // PathEffect是用来控制绘制轮廓(线条)的方式
    // 代码中的float数组,必须是偶数长度,且>=2,指定了多少长度的实线之后再画多少长度的空白
    // .如本代码中,绘制长度5的实线,再绘制长度5的空白,再绘制长度5的实线,再绘制长度5的空白,依次重复.1是偏移量,可以不用理会.
    PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);
    mlableLinePaint.setPathEffect(effects);


}
 
Example 9
Source File: PopupContainerWithArrow.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.START;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.END;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    if (Gravity.isVertical(((FrameLayout.LayoutParams) getLayoutParams()).gravity)) {
        // This is only true if there wasn't room for the container next to the icon,
        // so we centered it instead. In that case we don't want to show the arrow.
        arrowView.setVisibility(INVISIBLE);
    } else {
        ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
                width, height, !mIsAboveIcon));
        Paint arrowPaint = arrowDrawable.getPaint();
        // Note that we have to use getChildAt() instead of getItemViewAt(),
        // since the latter expects the arrow which hasn't been added yet.
        PopupItemView itemAttachedToArrow = (PopupItemView)
                (getChildAt(mIsAboveIcon ? getChildCount() - 1 : 0));
        arrowPaint.setColor(itemAttachedToArrow.getArrowColor(mIsAboveIcon));
        // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
        int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius);
        arrowPaint.setPathEffect(new CornerPathEffect(radius));
        arrowView.setBackground(arrowDrawable);
        arrowView.setElevation(getElevation());
    }
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
Example 10
Source File: ComplexAdapter.java    From RecyclerView-FlexibleDivider with Apache License 2.0 5 votes vote down vote up
@Override
public Paint dividerPaint(int position, RecyclerView parent) {
    Paint paint = new Paint();
    switch (position % 10) {
        case 0:
            paint.setColor(Color.RED);
            paint.setStrokeWidth(30);
            break;
        case 1:
            paint.setColor(Color.MAGENTA);
            paint.setStrokeWidth(10);
            break;
        default:
            if (position % 2 == 0) {
                paint.setColor(Color.BLUE);
                paint.setAntiAlias(true);
                paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0));
            } else {
                paint.setColor(Color.GREEN);

            }
            paint.setStrokeWidth(2 + position);
            break;
    }

    return paint;
}
 
Example 11
Source File: PXStroke.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a stroke {@link Paint}. Note that this method does not check into
 * the pool any Paint that may have been pulled from it. The responsibility
 * here is up to the caller.
 * 
 * @param p
 * @param useOriginal Indicate that the given {@link Paint} instance should
 *            be applied with the stroke information.
 * @return A {@link Paint} reference (a new Paint in case the useOriginal
 *         was false)
 */
public Paint getStrokedPaint(Paint p, boolean useOriginal) {
    Paint paint = useOriginal ? p : ObjectPool.paintPool.checkOut(p);
    paint.setStyle(Style.STROKE);
    paint.setStrokeWidth(width);

    if (dashArray != null && dashArray.length > 0) {
        paint.setPathEffect(new DashPathEffect(dashArray, dashOffset));
    }

    paint.setStrokeCap(this.lineCap);
    paint.setStrokeJoin(this.lineJoin);
    paint.setStrokeMiter(this.miterLimit);
    return paint;
}
 
Example 12
Source File: LayoutBorderView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
private void initView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.LayoutBorderView);
    boolean fill = a.getBoolean(R.styleable.LayoutBorderView_dkFill, false);
    mRectPaint = new Paint();
    if (fill) {
        mRectPaint.setStyle(Paint.Style.FILL);
        mRectPaint.setColor(Color.RED);
    } else {
        mRectPaint.setStyle(Paint.Style.STROKE);
        mRectPaint.setStrokeWidth(4);
        mRectPaint.setPathEffect(new DashPathEffect(new float[]{4, 4}, 0));
        mRectPaint.setColor(Color.RED);
    }
    a.recycle();
}
 
Example 13
Source File: Animator.java    From LineAnimation with MIT License 5 votes vote down vote up
public Animator(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
    try {
        pathColor = ta.getColor(R.styleable.Animator_pathColor, Color.BLACK);
        dashPathSize = (int) ta.getDimension(R.styleable.Animator_dashPathSize, 30f);
        dashPathGap = (int) ta.getDimension(R.styleable.Animator_dashPathGap, 30f);
        pathStrokeWidth = (int) ta.getDimension(R.styleable.Animator_pathStrokeWidth, 4f);
        drawableAnimationSpeed = ta.getInteger(R.styleable.Animator_drawableAminationSpeed, 9);
        drawable = ta.getResourceId(R.styleable.Animator_drawable, R.drawable.ic_roket);
        enableDashPath = ta.getBoolean(R.styleable.Animator_enableDashPath, true);
        repeatable = ta.getBoolean(R.styleable.Animator_enableDashPath, false);
    } finally {
        ta.recycle();
    }

    line = new Path();
    paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    if(enableDashPath){
        paint.setPathEffect(new DashPathEffect(new float[]{dashPathSize, dashPathGap}, 0));
    }

    arrow = getBitmap(drawable);

    this.context = context;

    matrix = new Matrix();

}
 
Example 14
Source File: SpanFormatter.java    From nfcard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
		int y, int bottom, Paint paint) {

	canvas.save();
	canvas.translate(x, (bottom + top) / 2 - height);

	final int c = paint.getColor();
	final float w = paint.getStrokeWidth();
	final Style s = paint.getStyle();
	final PathEffect e = paint.getPathEffect();

	paint.setColor(color);
	paint.setStyle(Paint.Style.STROKE);
	paint.setStrokeWidth(height);
	paint.setPathEffect(effe);

	path.moveTo(x, 0);
	path.lineTo(x + width, 0);

	canvas.drawPath(path, paint);

	paint.setColor(c);
	paint.setStyle(s);
	paint.setStrokeWidth(w);
	paint.setPathEffect(e);

	canvas.restore();
}
 
Example 15
Source File: DrawHelper.java    From XCL-Charts with Apache License 2.0 5 votes vote down vote up
/**
 * 绘制虚实线
 * @param startX	起始点X坐标
 * @param startY	起始点Y坐标
 * @param stopX		终止点X坐标
 * @param stopY		终止点Y坐标
 * @param canvas	画布
 * @param paint		画笔
 */
public void drawDashLine(float startX,float startY,
						 float stopX,float stopY,							 
						 Canvas canvas,
						 Paint paint)
{
	//虚实线
	//PathEffect effects = new DashPathEffect(new float[] { 4, 8, 5, 10}, 1);  
	paint.setPathEffect(getDashLineStyle());  
	canvas.drawLine(startX, startY, stopX, stopY, paint);  
	paint.setPathEffect(null);
}
 
Example 16
Source File: BorderShape.java    From Genius-Android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("SuspiciousNameCombination")
@Override
public void draw(Canvas canvas, Paint paint) {
    if (mBorder == null)
        return;

    float width = getWidth();
    float height = getHeight();

    if (mPathEffect == null) {

        // left
        if (mBorder.left > 0)
            canvas.drawRect(0, 0, mBorder.left, height, paint);

        // top
        if (mBorder.top > 0)
            canvas.drawRect(0, 0, width, mBorder.top, paint);

        // right
        if (mBorder.right > 0)
            canvas.drawRect(width - mBorder.right, 0, width, height, paint);

        // bottom
        if (mBorder.bottom > 0)
            canvas.drawRect(0, height - mBorder.bottom, width, height, paint);

    } else {
        if (paint.getPathEffect() != mPathEffect) {
            paint.setStyle(Paint.Style.STROKE);
            paint.setPathEffect(mPathEffect);
        }

        // left
        if (mBorder.left > 0) {
            paint.setStrokeWidth(mBorder.left);
            initPath(mBorder.left / 2, 0, mBorder.left / 2, height);
            canvas.drawPath(mPath, paint);
        }

        // top
        if (mBorder.top > 0) {
            paint.setStrokeWidth(mBorder.top);
            initPath(0, mBorder.top / 2, width, mBorder.top / 2);
            canvas.drawPath(mPath, paint);
        }

        // right
        if (mBorder.right > 0) {
            paint.setStrokeWidth(mBorder.right);
            initPath(width - mBorder.right / 2, 0, width - mBorder.right / 2, height);
            canvas.drawPath(mPath, paint);
        }

        // bottom
        if (mBorder.bottom > 0) {
            paint.setStrokeWidth(mBorder.bottom);
            initPath(0, height - mBorder.bottom / 2, width, height - mBorder.bottom / 2);
            canvas.drawPath(mPath, paint);
        }
    }
}
 
Example 17
Source File: PercentileView.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
private void drawGrid(Canvas canvas) {
    Paint myPaint = new Paint();
    myPaint.setStyle(Paint.Style.STROKE);
    myPaint.setAntiAlias(false);
    myPaint.setColor(Color.LTGRAY);
    myPaint.setStrokeWidth(dp2px(1));

    Paint myPaintText = new Paint();
    myPaintText.setStyle(Paint.Style.STROKE);
    myPaintText.setAntiAlias(false);
    myPaintText.setColor(Color.LTGRAY);
    myPaintText.setTextSize(dp2px(10));

    canvas.drawLine(dpOffset, 0, dpOffset, canvas.getHeight() - dpOffset, myPaint);
    canvas.drawLine(dpOffset, canvas.getHeight() - dpOffset, canvas.getWidth(), canvas.getHeight() - dpOffset, myPaint);

    for (int i = 0; i < 24; i++) {
        int x = (int) (dpOffset + ((canvas.getWidth() - dpOffset) / 24d) * i);
        if (i % 2 == 0) {
            canvas.drawLine(x, canvas.getHeight() - dpOffset - dp2px(2), x, canvas.getHeight() - dpOffset + dp2px(3), myPaint);
            if (i >= 10) x = x - dp2px(3);
            canvas.drawText(i + "", x - dp2px(4), canvas.getHeight() - dpOffset + dp2px(13), myPaintText);
        } else {
            canvas.drawLine(x, canvas.getHeight() - dpOffset - dp2px(2), x, canvas.getHeight() - dpOffset + dp2px(6), myPaint);
            if (i >= 10) x = x - dp2px(3);
            canvas.drawText(i + "", x - dp2px(4), canvas.getHeight() - dpOffset + dp2px(20), myPaintText);
        }
    }


    // add level markings
    myPaint.setPathEffect(new DashPathEffect(new float[]{dp2px(2), dp2px(3)}, 0));
    Path path = new Path();
    double[] levels;
    String[] labels;
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));
    if (mgdl) {
        levels = new double[]{50, 100, 150, 200, 250, 300, 350};
        labels = new String[]{"50", "100", "150", "200", "250", "300", "350"};
    } else {
        levels = new double[]{2.8, 5.5, 8.3, 11, 14, 17, 20};
        labels = new String[]{"2.8", "5.5", "8.3", "11", "14", "17", "20"};
        for (int i = 0; i < levels.length; i++) {
            levels[i] *= Constants.MMOLL_TO_MGDL;
        }
    }
    for (int i = 0; i < levels.length; i++) {
        path.moveTo(dpOffset, getYfromBG(levels[i], canvas));
        path.lineTo(canvas.getWidth(), getYfromBG(levels[i], canvas));
        canvas.drawText(labels[i], dp2px(5), getYfromBG(levels[i], canvas) + dp2px(4), myPaintText);
    }

    canvas.drawPath(path, myPaint);

}
 
Example 18
Source File: FabricView.java    From FabricView with Apache License 2.0 4 votes vote down vote up
/**
 *  Constructor, sets defaut values.
 *
 * @param context the activity that containts the view
 * @param attrs   view attributes
 */
public FabricView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setWillNotDraw(false);

    setFocusable(true);
    setFocusableInTouchMode(true);
    this.setBackgroundColor(mBackgroundColor);
    mTextExpectTouch = false;

    selectionPaint = new Paint();
    selectionPaint.setAntiAlias(true);
    selectionPaint.setColor(selectionColor);
    selectionPaint.setStyle(Paint.Style.STROKE);
    selectionPaint.setStrokeJoin(Paint.Join.ROUND);
    selectionPaint.setStrokeWidth(SELECTION_LINE_WIDTH);
    selectionPaint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));

    deleteIcon = BitmapFactory.decodeResource(context.getResources(),
            android.R.drawable.ic_menu_delete);

    mScaleDetector = new ScaleRotationGestureDetector(context, new ScaleRotationGestureDetector.OnScaleRotationGestureListener() {

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            handleScaleEnd();
        }

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            return handleScaleBegin((ScaleRotationGestureDetector) detector);
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            return handleScale((ScaleRotationGestureDetector) detector);
        }

        @Override
        public boolean onRotate(ScaleRotationGestureDetector detector) {
            return handleScale((ScaleRotationGestureDetector) detector);
        }

    });
}
 
Example 19
Source File: ChartView.java    From science-journal with Apache License 2.0 4 votes vote down vote up
private void makeDashedLinePaint(Paint paint, float lineWidth, float dashSize) {
  paint.setStyle(Paint.Style.STROKE);
  paint.setStrokeWidth(lineWidth);
  paint.setPathEffect(new DashPathEffect(new float[] {dashSize, dashSize}, dashSize));
}
 
Example 20
Source File: DownloadProgressBar.java    From hipda with GNU General Public License v2.0 4 votes vote down vote up
public DownloadProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    super.setOnClickListener(this);

    initIndeterminateAnimator();

    mClickListeners = new ArrayList<>();

    mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBgRect = new RectF();

    mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setDither(true);
    mProgressPaint.setStrokeJoin(Paint.Join.ROUND);
    mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    mProgressPaint.setPathEffect(new CornerPathEffect(50f));

    mProgressRect = new RectF();

    Resources res = context.getResources();
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DownloadProgressBar, 0, 0);

        initBackgroundDrawableFromAttribs(res, a);

        mCurrState = a.getInt(R.styleable.DownloadProgressBar_state, STATE_IDLE);
        mCancelable = a.getBoolean(R.styleable.DownloadProgressBar_cancelable, DEF_CANCELABLE);
        mHideOnFinish = a.getBoolean(R.styleable.DownloadProgressBar_hideOnFinish, false);
        mProgressIndeterminateSweepAngle = a.getInteger(R.styleable.DownloadProgressBar_progressIndeterminateSweepAngle, DEF_PROGRESS_INDETERMINATE_WIDTH);
        mProgressDeterminateColor = a.getColor(R.styleable.DownloadProgressBar_progressDeterminateColor, DEF_DETERMINATE_COLOR);
        mProgressIndeterminateColor = a.getColor(R.styleable.DownloadProgressBar_progressIndeterminateColor, DEF_INDETERMINATE_COLOR);
        mProgressPaint.setStrokeWidth(
                a.getDimensionPixelSize(R.styleable.DownloadProgressBar_progressWidth, DEF_PROGRESS_WIDTH)
        );
        mProgressMargin = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_progressMargin, DEF_PROGRESS_MARGIN);
        mCurrProgress = a.getInteger(R.styleable.DownloadProgressBar_currentProgress, 0);
        mMaxProgress = a.getInteger(R.styleable.DownloadProgressBar_maxProgress, 100);

        int icIdleDrawableId = a.getResourceId(R.styleable.DownloadProgressBar_idleIconDrawable, R.drawable.ic_action_download);
        mIdleIcon = res.getDrawable(icIdleDrawableId);
        mIdleIconWidth = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_idleIconWidth, mIdleIcon.getMinimumWidth());
        mIdleIconHeight = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_idleIconHeight, mIdleIcon.getMinimumHeight());

        int icCancelDrawableId = a.getResourceId(R.styleable.DownloadProgressBar_cancelIconDrawable, R.drawable.ic_action_cancel);
        mCancelIcon = res.getDrawable(icCancelDrawableId);
        mCancelIconWidth = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_cancelIconWidth, mCancelIcon.getMinimumWidth());
        mCancelIconHeight = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_cancelIconHeight, mCancelIcon.getMinimumHeight());

        int icFinishDrawableId = a.getResourceId(R.styleable.DownloadProgressBar_finishIconDrawable, R.drawable.ic_action_finish);
        mFinishIcon = res.getDrawable(icFinishDrawableId);
        mFinishIconWidth = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_finishIconWidth, mFinishIcon.getMinimumWidth());
        mFinishIconHeight = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_finishIconHeight, mFinishIcon.getMinimumHeight());

        int icErrorDrawableId = a.getResourceId(R.styleable.DownloadProgressBar_errorIconDrawable, R.drawable.ic_action_refresh);
        mErrorIcon = res.getDrawable(icErrorDrawableId);
        mErrorIconWidth = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_errorIconWidth, mErrorIcon.getMinimumWidth());
        mErrorIconHeight = a.getDimensionPixelSize(R.styleable.DownloadProgressBar_errorIconHeight, mErrorIcon.getMinimumHeight());

        a.recycle();
    } else {
        mCurrState = STATE_IDLE;
        mCancelable = DEF_CANCELABLE;
        mHideOnFinish = false;
        mProgressIndeterminateSweepAngle = DEF_PROGRESS_INDETERMINATE_WIDTH;
        mProgressDeterminateColor = DEF_DETERMINATE_COLOR;
        mProgressIndeterminateColor = DEF_INDETERMINATE_COLOR;
        mProgressPaint.setStrokeWidth(DEF_PROGRESS_WIDTH);
        mProgressMargin = DEF_PROGRESS_MARGIN;
        mCurrProgress = 0;
        mMaxProgress = 100;

        mIdleBgColor = DEF_BG_COLOR;
        mFinishBgColor = DEF_BG_COLOR;
        mErrorBgColor = DEF_BG_COLOR;
        mIndeterminateBgColor = DEF_BG_COLOR;
        mDeterminateBgColor = DEF_BG_COLOR;

        mIdleIcon = res.getDrawable(R.drawable.ic_action_download);
        mIdleIconWidth = mIdleIcon.getMinimumWidth();
        mIdleIconHeight = mIdleIcon.getMinimumHeight();

        mCancelIcon = res.getDrawable(R.drawable.ic_action_cancel);
        mCancelIconWidth = mCancelIcon.getMinimumWidth();
        mCancelIconHeight = mCancelIcon.getMinimumHeight();

        mFinishIcon = res.getDrawable(R.drawable.ic_action_finish);
        mFinishIconWidth = mFinishIcon.getMinimumWidth();
        mFinishIconHeight = mFinishIcon.getMinimumHeight();

        mErrorIcon = res.getDrawable(R.drawable.ic_action_refresh);
        mErrorIconWidth = mErrorIcon.getMinimumWidth();
        mErrorIconHeight = mErrorIcon.getMinimumHeight();
    }

    if (mCurrState == STATE_INDETERMINATE)
        setIndeterminate();
    if (mCurrState == STATE_FINISHED && mHideOnFinish)
        setVisibility(GONE);
}