Java Code Examples for android.graphics.Canvas#setDrawFilter()

The following examples show how to use android.graphics.Canvas#setDrawFilter() . 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: ClearEditText.java    From AndroidUI with MIT License 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));//抗锯齿
    if (mAnimator_visible.isRunning()) {
        int x = (int) mAnimator_visible.getAnimatedValue();
        drawClear(x,canvas);
        invalidate();
    }else if (isVisible){
        drawClear(0,canvas);
    }

    if(mAnimator_gone.isRunning()){
        float scale = (float) mAnimator_gone.getAnimatedValue();
        drawClearGone(scale, canvas);
        invalidate();
    }
}
 
Example 2
Source File: MatrixFrameLayout.java    From support with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    mTransformation.clear();
    mTransformation.setTransformationType(Transformation.TYPE_MATRIX);
    Matrix matrix = mTransformation.getMatrix();
    float degree = 15;
    mCamera.save();
    mCamera.rotateY(degree);
    mCamera.getMatrix(matrix);
    mCamera.restore();

    final float centerY = getHeight() / 2f;
    matrix.preTranslate(0, -centerY);
    matrix.postTranslate(0, centerY);

    canvas.save();
    canvas.concat(mTransformation.getMatrix());
    canvas.setDrawFilter(mPaintFlagsDrawFilter);
    super.draw(canvas);
    canvas.restore();
}
 
Example 3
Source File: OldCreditSesameView.java    From CreditSesameRingView with Apache License 2.0 5 votes vote down vote up
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
  //设置画布绘图无锯齿
  canvas.setDrawFilter(mPaintFlagsDrawFilter);

  drawArc(canvas);
  drawCalibration(canvas);
  drawArcText(canvas);
  drawCenterText(canvas);
  drawBitmapProgress(canvas);
}
 
Example 4
Source File: DoubleWaveView.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //从canvas层面去除绘制时的锯齿
    canvas.setDrawFilter(mDrawFilter);
    for(int i=0,j=0,k=0;i<mTotalWidth;i++){

        if(i+mXOneOffset<mTotalWidth){//第一条波纹图形绘制
            canvas.drawLine(i,mTotalHeight-mYPositions[mXOneOffset+i]-WaveHeight,i,mTotalHeight,mWavePaint);
        }else {//大于周期值,则设置为j(与相位相关,已移动的X距离,最大值为一个周期,即控件的宽度)
            canvas.drawLine(i,mTotalHeight-mYPositions[j]-WaveHeight,i,mTotalHeight,mWavePaint);
            j++;
        }

        if(i+mXTwoOffset<mTotalWidth){//第二条波纹图形绘制
            canvas.drawLine(i,mTotalHeight-mYPositions[mXTwoOffset+i]-WaveHeight,i,mTotalHeight,mWavePaint1);
        }else {//大于周期值,则设置为k(与相位相关,已移动的X距离)
            canvas.drawLine(i,mTotalHeight-WaveHeight-mYPositions[k],i,mTotalHeight,mWavePaint1);
            k++;
        }

    }

    // 改变两条波纹的移动点
    mXOneOffset += mXOffsetSpeedOne;
    mXTwoOffset += mXOffsetSpeedTwo;

    // 如果已经移动到结尾处,则重头记录
    if (mXOneOffset >= mTotalWidth) {
        mXOneOffset = 0;
    }
    if (mXTwoOffset > mTotalWidth) {
        mXTwoOffset = 0;
    }

    // 引发view重绘,可以考虑延迟10-30ms重绘,空出时间绘制
    if (isAnim){
        new Thread(mRunnable).start();
    }
}
 
Example 5
Source File: RoundImageView.java    From CardSwipeLayout with MIT License 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    mPath.reset();
    mPath.addRoundRect(mRectF, rids, Path.Direction.CW);
    canvas.setDrawFilter(paintFlagsDrawFilter);
    canvas.save();
    canvas.clipPath(mPath);
    super.onDraw(canvas);
    canvas.restore();
}
 
Example 6
Source File: UICircleImageView.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	if (bitmap == null) {
		return;
	}
	if (isXfermode) {
		bitmapRect.set(0, 0, getWidth(), getHeight());
		canvas.save();
		canvas.setDrawFilter(pdf);
		path.reset();
		canvas.clipPath(path);
		path.addCircle(getWidth()/2, getWidth()/2, getHeight()/2, Path.Direction.CCW);
		canvas.clipPath(path, Region.Op.REPLACE);
		canvas.drawBitmap(bitmap, null, bitmapRect, paint);
		canvas.restore();
	}else {
		if (dstBitmap == null) {
			dstBitmap = makeDst(getWidth(), getHeight());
		}
		bitmapRect.set(0, 0, getWidth(), getHeight());
		canvas.save();
		canvas.setDrawFilter(pdf);
		canvas.drawBitmap(dstBitmap, 0, 0, paint);
		paint.setXfermode(xfermode);
		canvas.drawBitmap(bitmap, null, bitmapRect, paint);
		paint.setXfermode(null);
		canvas.restore();
	}
}
 
Example 7
Source File: RxSwipeCaptcha.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
private Bitmap getMaskBitmap(Bitmap mBitmap, Path mask) {
        //以控件宽高 create一块bitmap
        Bitmap tempBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
        Log.e(TAG, " getMaskBitmap: width:" + mBitmap.getWidth() + ",  height:" + mBitmap.getHeight());
        Log.e(TAG, " View: width:" + mWidth + ",  height:" + mHeight);
        //把创建的bitmap作为画板
        Canvas mCanvas = new Canvas(tempBitmap);
        //有锯齿 且无法解决,所以换成XFermode的方法做
        //mCanvas.clipPath(mask);
        // 抗锯齿
        mCanvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
        //绘制用于遮罩的圆形
        mCanvas.drawPath(mask, mMaskPaint);
        //设置遮罩模式(图像混合模式)
        mMaskPaint.setXfermode(mPorterDuffXfermode);
//        mMaskPaint.setShadowLayer(5, 3, 3, 0xFF0000FF);

        // 设置光源的方向
        float[] direction = new float[]{ 1, 1, 1 };
//设置环境光亮度
        float light = 1f;
// 选择要应用的反射等级
        float specular = 6;
// 向mask应用一定级别的模糊
        float blur = 3.5f;
//        EmbossMaskFilter emboss=new EmbossMaskFilter(direction,light,specular,blur);
        BlurMaskFilter maskFilter = new BlurMaskFilter(10, BlurMaskFilter.Blur.SOLID);
// 应用mask
        mMaskPaint.setMaskFilter(maskFilter);

        //★考虑到scaleType等因素,要用Matrix对Bitmap进行缩放
        mCanvas.drawBitmap(mBitmap, getImageMatrix(), mMaskPaint);
        mMaskPaint.setXfermode(null);
        return tempBitmap;
    }
 
Example 8
Source File: AvatarRectView.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected final void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);//
    this.mRect.left = ((getWidth() - this.mAvatarSize) / 2);
    this.mRect.right = ((getWidth() + this.mAvatarSize) / 2);
    this.mRect.top = ((getHeight() - this.mAvatarSize) / 2);
    this.mRect.bottom = ((getHeight() + this.mAvatarSize) / 2);

    rectArray[0].set(0, 0, mRect.left, mRect.top);
    rectArray[1].set(mRect.left, 0, mRect.right, this.mRect.top);
    rectArray[2].set(this.mRect.right, 0, getWidth(), this.mRect.top);
    rectArray[3].set(0, mRect.top, mRect.left, this.mRect.bottom);
    rectArray[4].set(mRect.right, mRect.top, getWidth(), this.mRect.bottom);
    rectArray[5].set(0, mRect.bottom, this.mRect.left, getHeight());
    rectArray[6].set(mRect.left, mRect.bottom, this.mRect.right, getHeight());
    rectArray[7].set(mRect.right, mRect.bottom, getWidth(), getHeight());

    this.mPaint.setColor(0x7f000000);
    this.mPaint.setStyle(Paint.Style.FILL);
    for (Rect rect : rectArray) {
        canvas.drawRect(rect, this.mPaint);
    }

    mPaint.reset();
    if (!centerBitmap.isRecycled()) {
        canvas.drawBitmap(centerBitmap, centerRect, mRect, mPaint);
    } else {
        Log.i(TAG, "bitmap recycle");
    }
    //centerBitmap.recycle();

}
 
Example 9
Source File: ColorPickerView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
private void drawRing(Canvas canvas) {
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    float ringWidth = ColorPickConstants.PIX_INTERVAL * 2 + 4;

    mRingPaint.setStrokeWidth(ringWidth);
    canvas.drawCircle(getWidth() / 2, getWidth() / 2, getWidth() / 2 - ringWidth / 2, mRingPaint);

    mRingPaint.setColor(getResources().getColor(R.color.dk_color_333333));
    mRingPaint.setStrokeWidth(0.5f);
    canvas.drawCircle(getWidth() / 2, getWidth() / 2, getWidth() / 2, mRingPaint);
    canvas.drawCircle(getWidth() / 2, getWidth() / 2, getWidth() / 2 - ringWidth, mRingPaint);
}
 
Example 10
Source File: BottomItemView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void drawTargetText(Canvas canvas, int alpha) {
    mTextPaint.setColor(mSelectedColor);
    mTextPaint.setAlpha(alpha);
    mTextPaint.setAntiAlias(true);
    int x = getMeasuredWidth() / 2 - mTextBound.width() / 2;
    int y = mIconLayoutRect.bottom + mIconMargin + mTextBound.height() + mText2IconHeight;

    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    canvas.drawText(mText, x, y - XIAODUI, mTextPaint);
}
 
Example 11
Source File: FrameAnimationDrawable.java    From APNG4Android with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    if (bitmap == null || bitmap.isRecycled()) {
        return;
    }
    canvas.setDrawFilter(drawFilter);
    canvas.drawBitmap(bitmap, matrix, paint);
}
 
Example 12
Source File: CircleTextView.java    From FastWaiMai with MIT License 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    canvas.setDrawFilter(FILTER);
    canvas.drawCircle(getWidth() / 2, getHeight() / 2,
            Math.max(getWidth(), getHeight()) / 2, PAINT);
    super.draw(canvas);
}
 
Example 13
Source File: BitmapUtil.java    From videocreator with Apache License 2.0 5 votes vote down vote up
/**
     * 从图片加载到另一张图片
     *
     * @param bitmap
     * @param bitmap_src
     * @return
     */
    public static Bitmap loadFromBitmap(Bitmap bitmap, Bitmap bitmap_src, boolean clearBmp) {
        if (clearBmp)
            bitmap.eraseColor(Color.TRANSPARENT);
//		bitmap_src = zoomBitmap(bitmap_src, bitmap.getWidth(), bitmap.getHeight());
//		loadFromBytes(bitmap, getBytes(bitmap_src));
        Canvas canvas = new Canvas(bitmap);
        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
        float rw = (float) bitmap.getWidth() / bitmap_src.getWidth();
        float rh = (float) bitmap.getHeight() / bitmap_src.getHeight();
        canvas.scale(rw, rh);
        canvas.drawBitmap(bitmap_src, 0, 0, null);
        return bitmap;
    }
 
Example 14
Source File: IRView.java    From Android-Application with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {

    if(filterBitmap){
        canvas.setDrawFilter(filterPaint);
    } else {
        canvas.setDrawFilter(noFilterPaint);
    }

    super.onDraw(canvas);

    canvas.setDrawFilter(null);

    if(maxMarkerEnabled) {

        float markerSize = getHeight() * maxMarkerScale;
        float x = xyMarkerVector[0];
        float y = xyMarkerVector[1];

        //draw max temp pointer
        canvas.drawLine(x, y - markerSize, x, y - markerSize / 4.0f, maxMarkerPaint);
        canvas.drawLine(x, y + markerSize, x, y + markerSize / 4.0f, maxMarkerPaint);
        canvas.drawLine(x - markerSize, y, x - markerSize / 4.0f, y, maxMarkerPaint);
        canvas.drawLine(x + markerSize, y, x + markerSize / 4.0f, y, maxMarkerPaint);

    }
    if(searchAreaEnabled){
        float yy = getHeight()/ OTC.IR_WIDTH;
        float xx = getWidth()/OTC.IR_HEIGHT;
        canvas.drawRect(xx*(OTC.IR_HEIGHT/2-searchAreaSize),yy*(OTC.IR_WIDTH/2-searchAreaSize),xx*(OTC.IR_HEIGHT/2+searchAreaSize), yy*(OTC.IR_WIDTH/2+searchAreaSize), searchAreaPaint);
    }

    //take a picture effect
    if(isFlashAnimationInProgress()){
        canvas.drawRect(effectRectangle, effectPaint);
    }

}
 
Example 15
Source File: AntAliasImageView.java    From BooheeScrollView with MIT License 4 votes vote down vote up
@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));
    super.dispatchDraw(canvas);
}
 
Example 16
Source File: SunLineView.java    From styT with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.setDrawFilter(mDrawFilter);
    super.onDraw(canvas);
    drawLines(canvas);
}
 
Example 17
Source File: BubbleTextView.java    From StickerView with MIT License 4 votes vote down vote up
@Override
    protected void onDraw(Canvas canvas) {
        if (mBitmap != null) {


            float[] arrayOfFloat = new float[9];
            matrix.getValues(arrayOfFloat);
            float f1 = 0.0F * arrayOfFloat[0] + 0.0F * arrayOfFloat[1] + arrayOfFloat[2];
            float f2 = 0.0F * arrayOfFloat[3] + 0.0F * arrayOfFloat[4] + arrayOfFloat[5];
            float f3 = arrayOfFloat[0] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat[1] + arrayOfFloat[2];
            float f4 = arrayOfFloat[3] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat[4] + arrayOfFloat[5];
            float f5 = 0.0F * arrayOfFloat[0] + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2];
            float f6 = 0.0F * arrayOfFloat[3] + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5];
            float f7 = arrayOfFloat[0] * this.mBitmap.getWidth() + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2];
            float f8 = arrayOfFloat[3] * this.mBitmap.getWidth() + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5];


            canvas.save();

            //先往文字上绘图
            mBitmap = originBitmap.copy(Bitmap.Config.ARGB_8888, true);
            canvasText.setBitmap(mBitmap);
            canvasText.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
            canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
            float left = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, dm);
            float scalex = arrayOfFloat[Matrix.MSCALE_X];
            float skewy = arrayOfFloat[Matrix.MSKEW_Y];
            float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy);

            float size = rScale * 0.75f * mDefultSize;
            if (size > mMaxFontSize) {
                mFontSize = mMaxFontSize;
            } else if (size < mMinFontSize) {
                mFontSize = mMinFontSize;
            } else {
                mFontSize = size;
            }
            mFontPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mFontSize, dm));
            String[] texts = autoSplit(mStr, mFontPaint, mBitmap.getWidth() - left * 3);
            float height = (texts.length * (baseline + fm.leading) + baseline);
            float top = (mBitmap.getHeight() - height) / 2;
            //基于底线开始画的
            top += baseline;
            for (String text : texts) {
                if (TextUtils.isEmpty(text)) {
                    continue;
                }
                canvasText.drawText(text, mBitmap.getWidth() / 2, top, mFontPaint);  //坐标以控件左上角为原点
                top += baseline + fm.leading; //添加字体行间距
            }
            canvas.drawBitmap(mBitmap, matrix, null);

            //删除在右上角
            dst_delete.left = (int) (f3 - deleteBitmapWidth / 2);
            dst_delete.right = (int) (f3 + deleteBitmapWidth / 2);
            dst_delete.top = (int) (f4 - deleteBitmapHeight / 2);
            dst_delete.bottom = (int) (f4 + deleteBitmapHeight / 2);
            //拉伸等操作在右下角
            dst_resize.left = (int) (f7 - resizeBitmapWidth / 2);
            dst_resize.right = (int) (f7 + resizeBitmapWidth / 2);
            dst_resize.top = (int) (f8 - resizeBitmapHeight / 2);
            dst_resize.bottom = (int) (f8 + resizeBitmapHeight / 2);
            //置顶在左上角
            dst_top.left = (int) (f1 - topBitmapWidth / 2);
            dst_top.right = (int) (f1 + topBitmapWidth / 2);
            dst_top.top = (int) (f2 - topBitmapHeight / 2);
            dst_top.bottom = (int) (f2 + topBitmapHeight / 2);
            //水平镜像在右下角
//                dst_flipV.left = (int) (f5 - topBitmapWidth / 2);
//                dst_flipV.right = (int) (f5 + topBitmapWidth / 2);
//                dst_flipV.top = (int) (f6 - topBitmapHeight / 2);
//                dst_flipV.bottom = (int) (f6 + topBitmapHeight / 2);
            if (isInEdit) {

                canvas.drawLine(f1, f2, f3, f4, localPaint);
                canvas.drawLine(f3, f4, f7, f8, localPaint);
                canvas.drawLine(f5, f6, f7, f8, localPaint);
                canvas.drawLine(f5, f6, f1, f2, localPaint);

                canvas.drawBitmap(deleteBitmap, null, dst_delete, null);
                canvas.drawBitmap(resizeBitmap, null, dst_resize, null);
//                canvas.drawBitmap(flipVBitmap, null, dst_flipV, null);
                canvas.drawBitmap(topBitmap, null, dst_top, null);
            }

            canvas.restore();
        }
    }
 
Example 18
Source File: UISwitchButton.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	mPaint.setAntiAlias(true);
	canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG| Paint.FILTER_BITMAP_FLAG));
	switch (type) {
	case TYPE_ROUND:
		if (status) {
			mPaint.setColor(Color.parseColor("#C8C8C8"));
			mPaint.setStrokeWidth(1.8f);
			mPaint.setStyle(Style.STROKE);
			canvas.drawRoundRect(new RectF(DP, DP, getWidth() - DP, getHeight() - DP), getHeight()/2, getHeight()/2, mPaint);
			mPaint.setColor(Color.parseColor("#E8E8E8"));
			mPaint.setStyle(Style.FILL);
			canvas.drawRoundRect(new RectF(1.6f * DP, 1.6f * DP, getWidth() - 1.6f * DP, getHeight() - 1.6f * DP), (getHeight() - DP)/2f, (getHeight() - DP)/2f, mPaint);
			mPaint.setColor(Color.parseColor("#C8C8C8"));
			mPaint.setStrokeWidth(2f);
			mPaint.setStyle(Style.FILL);
			canvas.drawCircle(getWidth() - getHeight()/2, getHeight()/2, getHeight()/2 - 2.8f * DP, mPaint);
			mPaint.setColor(Color.parseColor("#FFFFFF"));
			mPaint.setStyle(Style.FILL);
			canvas.drawCircle(getWidth() - getHeight()/2, getHeight()/2, getHeight()/2 - 3.4f * DP, mPaint);
		}else {
			mPaint.setColor(Color.parseColor("#C8C8C8"));
			mPaint.setStrokeWidth(1.8f);
			mPaint.setStyle(Style.STROKE);
			canvas.drawRoundRect(new RectF(DP, DP, getWidth() - DP, getHeight() - DP), getHeight()/2, getHeight()/2, mPaint);
			mPaint.setColor(Color.parseColor("#FDFDFD"));
			mPaint.setStyle(Style.FILL);
			canvas.drawRoundRect(new RectF(2 * DP, 2 * DP, getWidth() - 2 * DP, getHeight() - 2 * DP), (getHeight() - DP)/2, (getHeight() - DP)/2, mPaint);
			mPaint.setColor(Color.parseColor("#C8C8C8"));
			mPaint.setStrokeWidth(2f);
			mPaint.setStyle(Style.STROKE);
			canvas.drawCircle(getHeight()/2 + 0.5f * DP, getHeight()/2, getHeight()/2 - 2.8f * DP, mPaint);
			mPaint.setColor(Color.parseColor("#D8D8D8"));
			mPaint.setStyle(Style.FILL);
			canvas.drawCircle(getHeight()/2 + 0.5f * DP, getHeight()/2, getHeight()/2 - 3.4f * DP, mPaint);
		}
		break;

	default:
		mPaint.setStrokeWidth(1.8f);
		mPaint.setStyle(Style.STROKE);
		if (status) {
			mPaint.setColor(statusTrueColor);
			canvas.drawLine(4 * DP, getHeight()/2, getWidth() - getHeight() + 4 * DP, getHeight()/2, mPaint);
			canvas.drawCircle(getWidth() - getHeight()/2, getHeight()/2, getHeight()/2 - 4 * DP, mPaint);
			mPaint.setColor(statusTrueColor);
			mPaint.setStyle(Style.FILL);
			canvas.drawCircle(getWidth() - getHeight()/2, getHeight()/2, getHeight()/2 - 4.8f * DP, mPaint);
			mPaint.setColor(statusFalseColor);
		}else {
			mPaint.setColor(statusTrueColor);
			canvas.drawLine(getHeight() - 4 * DP, getHeight()/2, getWidth() - 4 * DP, getHeight()/2, mPaint);
			canvas.drawCircle(getHeight()/2, getHeight()/2, getHeight()/2 - 4 * DP, mPaint);
			mPaint.setColor(statusFalseColor);
			mPaint.setStyle(Style.FILL);
			canvas.drawCircle(getHeight()/2, getHeight()/2, getHeight()/2 - 4.8f * DP, mPaint);
			mPaint.setColor(statusTrueColor);
		}
		break;
	}
}
 
Example 19
Source File: CircleProgressBar.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
/**
 * 编辑画布
 *
 * @param canvas 画布
 */
@SuppressLint("RtlHardcoded")
protected void editCanvas(Canvas canvas) {
    float scale = 1;
    final int paddingStart = Compat.getPaddingStart(this);
    final int paddingTop = getPaddingTop();
    final int paddingEnd = Compat.getPaddingEnd(this);
    final int paddingBottom = getPaddingBottom();
    final int widthSize = getWidth() - paddingStart - paddingEnd;
    final int heightSize = getHeight() - paddingTop - paddingBottom;
    final int minSize = widthSize < heightSize ? widthSize : heightSize;
    switch (mScaleType) {
        default:
        case ST_NONE:
            break;
        case ST_INSIDE:
            if (minSize < mItemSize) {
                scale = minSize / mItemSize;
            }
            break;
        case ST_CROP:
            if (minSize > mItemSize) {
                scale = minSize / mItemSize;
            }
            break;
        case ST_INSIDE | ST_CROP:
            scale = minSize / mItemSize;
            break;
    }
    float mBaseX;// 基准点X轴
    float mBaseY;// 基准点Y轴
    switch (mGravity) {
        default:
        case Gravity.CENTER:
            mBaseX = paddingStart + (getMeasuredWidth() - paddingStart - paddingEnd) * 0.5f;
            mBaseY = paddingTop + (getMeasuredHeight() - paddingTop - paddingBottom) * 0.5f;
            break;
        case Compat.START:
        case Gravity.LEFT:
        case Gravity.TOP:
        case Compat.START | Gravity.TOP:
        case Gravity.LEFT | Gravity.TOP:
            mBaseX = paddingStart + mItemSize * 0.5f * scale;
            mBaseY = paddingTop + mItemSize * 0.5f * scale;
            break;
        case Gravity.CENTER_HORIZONTAL:
        case Gravity.CENTER_HORIZONTAL | Gravity.TOP:
            mBaseX = paddingStart + (getMeasuredWidth() - paddingStart - paddingEnd) * 0.5f;
            mBaseY = paddingTop + mItemSize * 0.5f * scale;
            break;
        case Compat.END:
        case Gravity.RIGHT:
        case Compat.END | Gravity.TOP:
        case Gravity.RIGHT | Gravity.TOP:
            mBaseX = getMeasuredWidth() - paddingEnd - mItemSize * 0.5f * scale;
            mBaseY = paddingTop + mItemSize * 0.5f * scale;
            break;
        case Gravity.CENTER_VERTICAL:
        case Gravity.CENTER_VERTICAL | Compat.START:
        case Gravity.CENTER_VERTICAL | Gravity.LEFT:
            mBaseX = paddingStart + mItemSize * 0.5f * scale;
            mBaseY = paddingTop + (getMeasuredHeight() - paddingTop - paddingBottom) * 0.5f;
            break;
        case Gravity.CENTER_VERTICAL | Compat.END:
        case Gravity.CENTER_VERTICAL | Gravity.RIGHT:
            mBaseX = getMeasuredWidth() - paddingEnd - mItemSize * 0.5f * scale;
            mBaseY = paddingTop + (getMeasuredHeight() - paddingTop - paddingBottom) * 0.5f;
            break;
        case Gravity.BOTTOM:
        case Gravity.BOTTOM | Compat.START:
        case Gravity.BOTTOM | Gravity.LEFT:
            mBaseX = paddingStart + mItemSize * 0.5f * scale;
            mBaseY = getMeasuredHeight() - paddingBottom - mItemSize * 0.5f * scale;
            break;
        case Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL:
            mBaseX = paddingStart + (getMeasuredWidth() - paddingStart - paddingEnd) * 0.5f;
            mBaseY = getMeasuredHeight() - paddingBottom - mItemSize * 0.5f * scale;
            break;
        case Gravity.BOTTOM | Compat.END:
        case Gravity.BOTTOM | Gravity.RIGHT:
            mBaseX = getMeasuredWidth() - paddingEnd - mItemSize * 0.5f * scale;
            mBaseY = getMeasuredHeight() - paddingBottom - mItemSize * 0.5f * scale;
            break;
    }
    canvas.setDrawFilter(mDrawFilter);
    canvas.translate(mBaseX, mBaseY);
    if (scale != 1) {
        canvas.scale(scale, scale);
    }
}
 
Example 20
Source File: TabMainView.java    From FoldingTabBar.Android with MIT License 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	canvas.setDrawFilter(paintFlagsDrawFilter);
	// //////back///////
	paint.setColor(colors[0]);
	rectF.set(leftCenterX - maxOvalR, centerY - maxOvalR, leftCenterX + maxOvalR, centerY + maxOvalR);
	canvas.drawArc(rectF, 90, 180, false, paint);
	rectF.set(rightCenterX - maxOvalR, centerY - maxOvalR, rightCenterX + maxOvalR, centerY + maxOvalR);
	canvas.drawArc(rectF, -90, 180, false, paint);
	if (leftCenterX != rightCenterX)
		canvas.drawRect(leftCenterX - 0.5f, 0, rightCenterX + 0.5f, maxOvalR * 2, paint);

	// //////Dot////////
	if (drawDot) {
		paint.setColor(colors[2]);
		float centerX = centerXs[position];
		rectF.set(centerX - dotR, dotY - dotR, centerX + dotR, dotY + dotR);
		canvas.drawArc(rectF, 0, 360, false, paint);
	}
	// //////Icons//////////

	// 绘制中心按钮
	if (mainBtnBitmap != null) {
		drawIcon(mainBtnBitmap, canvas, maxOvalR, centerXs[2], mainBtnDegrees, 2);
	}

	// 绘制菜单按钮
	for (int i = 0; i < centerBtnsBitmap.length; i++) {
		if (centerBtnsBitmap[i] != null) {
			int btn = i;
			if (i > 1)
				btn += 1;
			if (drawIcons)
				drawIcon(centerBtnsBitmap[i], canvas, maxOvalR, centerXs[btn], centerBtnsDegrees, btn);
		}
	}

	// 绘制左侧按钮
	if (leftBtnBitmap != null) {
		rectF.set(leftBtnCenterX - minOvalR, centerY - minOvalR, leftBtnCenterX + minOvalR, centerY + minOvalR);
		canvas.drawArc(rectF, 0, 360, false, paint);
		drawIcon(leftBtnBitmap, canvas, maxOvalR, leftBtnCenterX, leftBtnDegrees, 10);
	}

	// 绘制右侧按钮
	if (rightBtnBitmap != null) {
		rectF.set(rightBtnCenterX - minOvalR, centerY - minOvalR, rightBtnCenterX + minOvalR, centerY + minOvalR);
		canvas.drawArc(rectF, 0, 360, false, paint);
		drawIcon(rightBtnBitmap, canvas, maxOvalR, rightBtnCenterX, rightBtnDegrees, 11);
	}
	super.onDraw(canvas);
}