Java Code Examples for android.graphics.Paint#ANTI_ALIAS_FLAG

The following examples show how to use android.graphics.Paint#ANTI_ALIAS_FLAG . 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: RoundTransform.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
private Bitmap roundCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int width = source.getWidth();
    int height = source.getHeight();
    rectF.set(0, 0, width, height);

    Bitmap squared = Bitmap.createBitmap(source, 0, 0, width, height);

    Bitmap result = pool.get(width, height, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
            .ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
            .TileMode.CLAMP));
    canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint);


    return result;
}
 
Example 2
Source File: PersonBarChartView.java    From loaned-android with Apache License 2.0 6 votes vote down vote up
private void init(Context c){
	Log.d(TAG, "init called");
	// Create the colour array
	mColours = new int[6];
	mColours[4] = Color.parseColor("#1bc5a4");
	mColours[1] = Color.parseColor("#9b59b6");
	mColours[0] = Color.parseColor("#2ecc71");
	mColours[2] = Color.parseColor("#e74c3c");
	mColours[3] = Color.parseColor("#3498db");

	mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPaint.setStyle(Paint.Style.FILL);

	mBarNumberPaint = new Paint();
	mBarNumberPaint.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));
	mBarNumberPaint.setColor(c.getResources().getColor(R.color.text_main));
	mBarNumberPaint.setTextSize(100);
	mBarNumberPaint.setTextAlign(Align.CENTER);

	mNameLabelPaint = new Paint();
	mNameLabelPaint.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));
	mNameLabelPaint.setColor(c.getResources().getColor(R.color.text_main));
	mNameLabelPaint.setTextAlign(Align.CENTER);
	mNameLabelPaint.setTextSize(140);
}
 
Example 3
Source File: SwitchView.java    From eBook with Apache License 2.0 6 votes vote down vote up
private void initObjects() {
    mPath = new Path();
    mSlideHandler = new SlideHandler();

    mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mStrokePaint.setStyle(Style.STROKE);
    mStrokePaint.setColor(mStrokeColor);

    mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mMaskPaint.setStyle(Style.FILL);
    mMaskPaint.setColor(mMaskColor);

    mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mButtonPaint.setStyle(Style.FILL);
    mButtonPaint.setColor(mButtonColor);


}
 
Example 4
Source File: MasterPaintView.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
private void initPaint() {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    res = getResources();
    source = BitmapFactory.decodeResource(res, R.drawable.cat);
    cover = BitmapFactory.decodeResource(res, R.drawable.circle);
    mStartColor = res.getColor(R.color.cpb_red);
    mEndColor = res.getColor(R.color.cpb_green);

    mPaint.setColor(Color.parseColor("#536DFE"));

    mbackPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mbackPaint.setStyle(Paint.Style.STROKE);
    mbackPaint.setStrokeWidth(3);
    mbackPaint.setColor(Color.WHITE);

}
 
Example 5
Source File: ScratchView.java    From AndroidDigIn with Apache License 2.0 6 votes vote down vote up
private Bitmap createBgBitmap(int w, int h, String text, int textColor) {
    Bitmap bgPicBitmap = getBitmap();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(bgPicBitmap, 0, 0, null);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.GRAY);
    canvas.drawRect(rect,paint);
    paint.setColor(textColor);
    float textSize = 150;
    paint.setTextSize(textSize);
    int cx = w / 2;
    int cy = h / 2;
    float measureText = paint.measureText(text);
    //将文字画在中间
    canvas.drawText(text, cx - measureText / 2, cy + textSize / 2, paint);
    canvas = null;
    paint = null;
    return bitmap;
}
 
Example 6
Source File: RYBDrawStrategyStateTwo.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
@Override
public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon,
                     WidthAndHeightOfView widthAndHeightOfView) {
    int centerX = widthAndHeightOfView.getWidth() / 2;
    int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
    canvas.save();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    float newFraction = (fraction - 0.65f) / 0.35f;
    paint.setColor(Color.parseColor("#e53935"));
    canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint);
    paint.setColor(Color.parseColor("#fdd835"));
    canvas.drawCircle(centerX -35, centerY + 35,100 * (1 - newFraction), paint);
    paint.setColor(Color.parseColor("#1e88e5"));
    canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint);
    canvas.restore();
    canvas.save();
    Path path = new Path();
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    Matrix matrix = new Matrix();
    matrix.postScale(1.7f, 1.7f, centerX, centerY);
    canvas.concat(matrix);
    path.addCircle(centerX, centerY, bitmap.getHeight() * 1.5f * newFraction, Path.Direction.CW);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, centerX - bitmap.getWidth() / 2, centerY - bitmap.getHeight() / 2, paint);
    canvas.restore();
}
 
Example 7
Source File: VectorView.java    From SVG-Android with Apache License 2.0 5 votes vote down vote up
public void setVectorArrays(String[] vectors) {
    if (vectors == null) {
        return;
    }
    mPathPaints = new Paint[vectors.length];
    mPaths = new Path[vectors.length];
    for (int i = 0; i < vectors.length; i++) {
        mPaths[i] = VectorPathParser.createPathFromPathData(vectors[i]);
        mPathPaints[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
    }
    requestLayout();
    invalidate();
}
 
Example 8
Source File: PigeonholeView.java    From PigeonholeView with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this view.
 *
 * @param context
 */
private void init(Context context) {
    this.context = context;

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(Color.BLACK);
    textPaint.setTextSize(60);

    dropTargetView = new ImageView(context);
    dropTargetView.setImageResource(R.drawable.placeholder);
    dropTargetView.setScaleType(ImageView.ScaleType.FIT_XY);
    dropTargetView.setVisibility(View.GONE);
    addView(dropTargetView);

    swapTargetView = new ImageView(context);
    swapTargetView.setImageResource(R.drawable.swap_candidate);
    swapTargetView.setScaleType(ImageView.ScaleType.FIT_XY);
    swapTargetView.setVisibility(View.GONE);
    addView(swapTargetView);

    LayoutInflater inflater = LayoutInflater.from(context);

    // Drop area
    editDropAreaView = inflater.inflate(R.layout.drop_area, this, false);
    addView(editDropAreaView);

    if (editDropAreaText != null) {  // Use custom text for drop area
        TextView dropAreaTextView = (TextView) editDropAreaView.findViewById(R.id.drop_area__label);
        dropAreaTextView.setText(editDropAreaText);
    }
}
 
Example 9
Source File: IconCache.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
private ContentValues newContentValues(Bitmap icon, String label, int lowResBackgroundColor) {
    ContentValues values = new ContentValues();
    values.put(IconDB.COLUMN_ICON, Utilities.flattenBitmap(icon));

    values.put(IconDB.COLUMN_LABEL, label);
    values.put(IconDB.COLUMN_SYSTEM_STATE, mSystemState);

    if (lowResBackgroundColor == Color.TRANSPARENT) {
      values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(
      Bitmap.createScaledBitmap(icon,
              icon.getWidth() / LOW_RES_SCALE_FACTOR,
              icon.getHeight() / LOW_RES_SCALE_FACTOR, true)));
    } else {
        synchronized (this) {
            if (mLowResBitmap == null) {
                mLowResBitmap = Bitmap.createBitmap(icon.getWidth() / LOW_RES_SCALE_FACTOR,
                        icon.getHeight() / LOW_RES_SCALE_FACTOR, Bitmap.Config.RGB_565);
                mLowResCanvas = new Canvas(mLowResBitmap);
                mLowResPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
            }
            mLowResCanvas.drawColor(lowResBackgroundColor);
            mLowResCanvas.drawBitmap(icon, new Rect(0, 0, icon.getWidth(), icon.getHeight()),
                    new Rect(0, 0, mLowResBitmap.getWidth(), mLowResBitmap.getHeight()),
                    mLowResPaint);
            values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(mLowResBitmap));
        }
    }
    return values;
}
 
Example 10
Source File: ViewFeedItem.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
static
Paint configurePaint(Resources resources, int dimenResource, int colorResource)
{
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(resources.getDimension(dimenResource));
    paint.setColor(resources.getColor(colorResource));
    paint.setHinting(Paint.HINTING_ON);
    return paint;
}
 
Example 11
Source File: AbsRoundImageView.java    From RoundImageView with Apache License 2.0 5 votes vote down vote up
private void init() {
    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    roundPath = new Path();
    borderPath = new Path();

    borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    borderPaint.setStrokeWidth(borderWidth);

    setScaleType(ScaleType.CENTER_CROP);
}
 
Example 12
Source File: DynamicPageIndicator2.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
public DynamicPageIndicator2(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final int density = (int) context.getResources().getDisplayMetrics().density;

    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.DynamicPageIndicator2, defStyle, 0);

    dotDiameter = a.getDimensionPixelSize(R.styleable.DynamicPageIndicator2_ads_dotDiameter,
            DEFAULT_DOT_SIZE * density);
    dotRadius = dotDiameter / 2;
    halfDotRadius = dotRadius / 2;
    gap = a.getDimensionPixelSize(R.styleable.DynamicPageIndicator2_ads_dotGap,
            DEFAULT_GAP * density);
    animDuration = (long) a.getInteger(R.styleable.DynamicPageIndicator2_ads_animationDuration,
            DEFAULT_ANIM_DURATION);
    animHalfDuration = animDuration / 2;
    unselectedColour = a.getColor( R.styleable.DynamicPageIndicator2_ads_pageIndicatorColor,
            DEFAULT_UNSELECTED_COLOUR);
    selectedColour = a.getColor( R.styleable.DynamicPageIndicator2_ads_currentPageIndicatorColor,
            DEFAULT_SELECTED_COLOUR);

    a.recycle();

    unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    unselectedPaint.setColor(unselectedColour);
    selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    selectedPaint.setColor(selectedColour);
    interpolator = new FastOutSlowInInterpolator();

    // create paths & rect now – reuse & rewind later
    combinedUnselectedPath = new Path();
    unselectedDotPath = new Path();
    unselectedDotLeftPath = new Path();
    unselectedDotRightPath = new Path();
    rectF = new RectF();

    addOnAttachStateChangeListener(this);
}
 
Example 13
Source File: CaptionMapObject.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
public CaptionMapObject(Object id, Drawable drawable, Point position,
		Point pivotPoint, boolean isTouchable, boolean isScalable) {
	super(id, drawable, position, pivotPoint, isTouchable, isScalable);
	
	paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	paint.setColor(Color.WHITE);
	paint.setTextAlign(Align.CENTER);
	paint.setTextSize(14);
	paint.setTypeface(Typeface.SANS_SERIF);
	paint.setFakeBoldText(true);
	paint.setShadowLayer(1, 0, 0, Color.BLACK);
}
 
Example 14
Source File: ILetter.java    From CoolAndroidAnim with Apache License 2.0 5 votes vote down vote up
public ILetter(int x, int y) {
    super(x, y);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Config.WHITE);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setStrokeWidth(20);
    mCurY += LENGTH / 2;
}
 
Example 15
Source File: WaveView.java    From AndroidDigIn with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    singleWaveWidth = context.getResources().getDimensionPixelSize(R.dimen.wave_width);
    singleWaveWidth_fix = singleWaveWidth;
    singleWaveHeightDeltaY = context.getResources().getDimensionPixelSize(R.dimen.wave_height);
    singleWaveHeightDeltaY_fix = singleWaveHeightDeltaY;
    color = context.getResources().getColor(R.color.wave_color);
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(color);
}
 
Example 16
Source File: PieChart.java    From WaveHeartRate with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    // piechart has no offsets
    mOffsetTop = 0;
    mOffsetBottom = 0;
    mOffsetLeft = 0;
    mOffsetRight = 0;

    mShift = Utils.convertDpToPixel(mShift);

    mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHolePaint.setColor(Color.WHITE);

    mCenterTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCenterTextPaint.setColor(mColorDarkBlue);
    mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
    mCenterTextPaint.setTextAlign(Align.CENTER);

    mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
    mValuePaint.setColor(Color.WHITE);
    mValuePaint.setTextAlign(Align.CENTER);

    mListener = new PieChartTouchListener(this);

    // for the piechart, drawing values is enabled
    mDrawYValues = true;
}
 
Example 17
Source File: RecordButtonProgressBar.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private void init() {

        //
        // set up paint components
        //

        float scale = getContext().getResources().getDisplayMetrics().density;
        // formula from framework: px = (int) (dps * scale + 0.5f)
        ringWidth = (int) (7 * scale + 0.5f);

        endPercentProgress = 0;
        int startSweep = 0;
        endSweep = 0;
        currentSweep = startSweep;

        int progressColor = ContextCompat.getColor(getContext(), R.color.record_highlight);

        progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        progressPaint.setStyle(Paint.Style.STROKE);
        progressPaint.setColor(progressColor);
        progressPaint.setStrokeWidth(ringWidth);
        progressPaint.setStrokeCap(Paint.Cap.ROUND);

        circle = new RectF(0, 0, getWidth(), getHeight());

        progressPath = new Path();

    }
 
Example 18
Source File: ShapeBackgroundSpan.java    From md2tv with MIT License 5 votes vote down vote up
public ShapeBackgroundSpan(int color, Shape shape, boolean stroke){
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(color);

    this.shape = shape;

    if(stroke){
        paint.setStyle(Paint.Style.STROKE);
    }else{
        paint.setStyle(Paint.Style.FILL);
    }

}
 
Example 19
Source File: MultiTouchPaintView.java    From Android_UE with Apache License 2.0 5 votes vote down vote up
private void init() {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStrokeWidth(4);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStyle(Paint.Style.STROKE);
    mPath = new LinkedHashMap<>();
}
 
Example 20
Source File: RecycleViewDivider.java    From LLApp with Apache License 2.0 3 votes vote down vote up
/**
 * 自定义分割线
 *
 * @param context
 * @param orientation   列表方向
 * @param dividerHeight 分割线高度
 * @param dividerColor  分割线颜色
 */
public RecycleViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) {
    this(context, orientation);
    mDividerHeight = dividerHeight;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(dividerColor);
    mPaint.setStyle(Paint.Style.FILL);
}