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

The following examples show how to use android.graphics.Paint#setColor() . 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: CircleView.java    From AndroidDemo with MIT License 6 votes vote down vote up
public CircleView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    Log.d(TAG, "RotateView Created");
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(Color.RED);
    mPaint.setAntiAlias(true);
    mPaint.setStrokeWidth(20);

    rectF = new RectF();
    rectF.top = 200;
    rectF.left = 200;
    rectF.right = 1000;
    rectF.bottom = 1000;

    holder = getHolder();
    holder.addCallback(this);
    this.setFocusable(true);
    this.setFocusableInTouchMode(true);
    this.setKeepScreenOn(true);
}
 
Example 2
Source File: STUtils.java    From Fatigue-Detection with MIT License 6 votes vote down vote up
/**
    * Draw the face rect in the Image
    * @param canvas
    * @param face
    * @param width
    * @param height
    * @param frontCamera
    */
static public void drawFaceRect(Canvas canvas, Rect rect, int width, int height, boolean frontCamera) {

	if(canvas == null) return;

	Paint paint = new Paint(); 
	paint.setColor(Color.rgb(57, 138, 243));
	int strokeWidth = Math.max(width / 240, 2);
	paint.setStrokeWidth(strokeWidth);

	if(frontCamera) {
		int left = rect.left;
		rect.left = width - rect.right;
		rect.right = width - left;
	}

	paint.setStyle(Style.STROKE);
	canvas.drawRect(rect, paint);
}
 
Example 3
Source File: ProfileDataCache.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(
            bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.WHITE);

    final float radius =  (bitmap.getWidth() - mImageStrokePx) / 2f;
    canvas.drawCircle(bitmap.getWidth() / 2f, bitmap.getHeight() / 2f, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    paint.setColor(mImageStrokeColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC));
    paint.setStrokeWidth(mImageStrokePx);
    canvas.drawCircle(bitmap.getWidth() / 2f, bitmap.getHeight() / 2f, radius, paint);

    return output;
}
 
Example 4
Source File: DirectionView.java    From UPMiss with GNU General Public License v3.0 6 votes vote down vote up
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    ShapeDrawable drawable = new ShapeDrawable(new DirectionShape(3));
    Paint paint = drawable.getPaint();

    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.DirectionView);
    int color = a.getColor(R.styleable.DirectionView_iLineColor, Color.GRAY);
    int size = a.getDimensionPixelOffset(R.styleable.DirectionView_iLineSize, (int) (getResources().getDisplayMetrics().density * 2));
    a.recycle();

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(size);
    paint.setColor(color);

    setBackground(drawable);
}
 
Example 5
Source File: ImageManageUtil.java    From bither-bitmap-sample with Apache License 2.0 6 votes vote down vote up
public static final Bitmap getRoundCornerBitmap(Bitmap bitmap, float roundPx) {
    if (bitmap == null)
        return bitmap;
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.drawARGB(0, 0, 0, 0);
    final int color = 0xff010101;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return output;
}
 
Example 6
Source File: NLetter.java    From CoolAndroidAnim with Apache License 2.0 6 votes vote down vote up
public NLetter(int x, int y) {
    super(x, y);
    // 将坐标点调整为中心点
    mCurY += LENGTH / 2;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Config.WHITE);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(STROKE_WIDTH);
    mPath = new Path();
    mFv = mDuration / 3;
    mSv = mDuration * 2 / 3;
    // 移动到起始位置
    mMoveX = mCurX - SHIFT;
    mMoveY = mCurY;
    mPath.moveTo(mMoveX, mMoveY);
    mRectF = new RectF();
    mRectF.set(mCurX - SHIFT, mCurY - SHIFT - LEG_LENGTH, mCurX + SHIFT, mCurY + SHIFT - LEG_LENGTH);
}
 
Example 7
Source File: MonthView.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the text and style properties for painting. Override this if you
 * want to use a different paint.
 */
protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
    mMonthTitlePaint.setColor(mDayTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);

    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mTodayNumberColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

    mMonthDayLabelPaint = new Paint();
    mMonthDayLabelPaint.setAntiAlias(true);
    mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
    mMonthDayLabelPaint.setColor(mMonthDayTextColor);
    mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(),"Roboto-Medium"));
    mMonthDayLabelPaint.setStyle(Style.FILL);
    mMonthDayLabelPaint.setTextAlign(Align.CENTER);
    mMonthDayLabelPaint.setFakeBoldText(true);

    mMonthNumPaint = new Paint();
    mMonthNumPaint.setAntiAlias(true);
    mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
    mMonthNumPaint.setStyle(Style.FILL);
    mMonthNumPaint.setTextAlign(Align.CENTER);
    mMonthNumPaint.setFakeBoldText(false);
}
 
Example 8
Source File: PuzzlePiece.java    From imsdk-android with MIT License 5 votes vote down vote up
private void draw(Canvas canvas, int alpha, boolean needClip) {
  if (drawable instanceof BitmapDrawable){
    int saved = canvas.saveLayer(null, null, Canvas.ALL_SAVE_FLAG);

    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    Paint paint= ((BitmapDrawable) drawable).getPaint();

    paint.setColor(Color.WHITE);
    paint.setAlpha(alpha);
    if (needClip) {
      canvas.drawPath(area.getAreaPath(), paint);
      paint.setXfermode(SRC_IN);
    }
    canvas.drawBitmap(bitmap,matrix,paint);
    paint.setXfermode(null);

    canvas.restoreToCount(saved);
  }else {
    canvas.save();
    if (needClip) {
      canvas.clipPath(area.getAreaPath());
    }
    canvas.concat(matrix);
    drawable.setBounds(drawableBounds);
    drawable.setAlpha(alpha);
    drawable.draw(canvas);

    canvas.restore();
  }
}
 
Example 9
Source File: PerWeekView.java    From TimetableView with MIT License 5 votes vote down vote up
public PerWeekView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initAttr(attrs);

    lightPaint=new Paint();
    lightPaint.setColor(lightColor);
    lightPaint.setAntiAlias(true);
    lightPaint.setStyle(Paint.Style.FILL);

    grayPaint=new Paint();
    grayPaint.setColor(grayColor);
    grayPaint.setAntiAlias(true);
    grayPaint.setStyle(Paint.Style.FILL);
}
 
Example 10
Source File: CircleWatchface.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
public void addIndicator(Canvas canvas, float bg, int color) {
    float convertedBg;
    convertedBg = bgToAngle(bg);
    convertedBg += 270;
    Paint paint = new Paint();
    paint.setColor(color);
    float offset = 9;
    RectF rectTemp = new RectF(PADDING + offset - CIRCLE_WIDTH / 2, PADDING + offset - CIRCLE_WIDTH / 2, (displaySize.x - PADDING - offset + CIRCLE_WIDTH / 2), (displaySize.y - PADDING - offset + CIRCLE_WIDTH / 2));
    canvas.drawArc(rectTemp, convertedBg, 2, true, paint);
}
 
Example 11
Source File: AvatarGraphics.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
public int drawCircleWithBorder(int sizePx, int borderSizePx, Canvas canvas, int color) {
    Paint transparent = new Paint();
    transparent.setAlpha(Color.TRANSPARENT);
    transparent.setColor(Color.TRANSPARENT);
    canvas.drawColor(Color.TRANSPARENT);
    canvas.drawRect(0,0, sizePx, sizePx, transparent);


    float cx = sizePx / 2.0f;
    float r = cx - (borderSizePx * 2);

    Paint background = new Paint();
    background.setColor(color);
    background.setStyle(Paint.Style.FILL);

    canvas.drawCircle(cx, cx , r, background);

    Paint border = new Paint();
    border.setColor(avatarThemesProvider.provideBorderColor());
    border.setStrokeWidth(borderSizePx);
    border.setStyle(Paint.Style.STROKE);
    border.setAntiAlias(true);

    canvas.drawCircle(cx , cx, r, border);

    return sizePx - (borderSizePx * 2);
}
 
Example 12
Source File: PageLoader.java    From NovelReader with MIT License 5 votes vote down vote up
private void initPaint() {
    // 绘制提示的画笔
    mTipPaint = new Paint();
    mTipPaint.setColor(mTextColor);
    mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    // 绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);

    // 绘制标题的画笔
    mTitlePaint = new TextPaint();
    mTitlePaint.setColor(mTextColor);
    mTitlePaint.setTextSize(mTitleSize);
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTitlePaint.setAntiAlias(true);

    // 绘制背景的画笔
    mBgPaint = new Paint();
    mBgPaint.setColor(mBgColor);

    // 绘制电池的画笔
    mBatteryPaint = new Paint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);

    // 初始化页面样式
    setNightMode(mSettingManager.isNightMode());
}
 
Example 13
Source File: RouteLayer.java    From MapView with MIT License 5 votes vote down vote up
private void initLayer() {
    this.routeWidth = 10;

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);

    routeStartBmp = BitmapFactory.decodeResource(mapView.getResources(),
            R.mipmap.start_point);
    routeEndBmp = BitmapFactory.decodeResource(mapView.getResources(),
            R.mipmap.end_point);
}
 
Example 14
Source File: SVBar.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {
	final TypedArray a = getContext().obtainStyledAttributes(attrs,
			R.styleable.ColorBars, defStyle, 0);
	final Resources b = getContext().getResources();

	mBarThickness = a.getDimensionPixelSize(
			R.styleable.ColorBars_bar_thickness,
			b.getDimensionPixelSize(R.dimen.bar_thickness));
	mBarLength = a.getDimensionPixelSize(R.styleable.ColorBars_bar_length,
			b.getDimensionPixelSize(R.dimen.bar_length));
	mPreferredBarLength = mBarLength;
	mBarPointerRadius = a.getDimensionPixelSize(
			R.styleable.ColorBars_bar_pointer_radius,
			b.getDimensionPixelSize(R.dimen.bar_pointer_radius));
	mBarPointerHaloRadius = a.getDimensionPixelSize(
			R.styleable.ColorBars_bar_pointer_halo_radius,
			b.getDimensionPixelSize(R.dimen.bar_pointer_halo_radius));
	mOrientation = a.getBoolean(
			R.styleable.ColorBars_bar_orientation_horizontal, ORIENTATION_DEFAULT);

	a.recycle();

	mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPaint.setShader(shader);

	mBarPointerPosition = (mBarLength / 2) + mBarPointerHaloRadius;

	mBarPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPointerHaloPaint.setColor(Color.BLACK);
	mBarPointerHaloPaint.setAlpha(0x50);

	mBarPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPointerPaint.setColor(0xff81ff00);

	mPosToSVFactor = 1 / ((float) mBarLength / 2);
	mSVToPosFactor = ((float) mBarLength / 2) / 1;
}
 
Example 15
Source File: BarView.java    From SlidePager with MIT License 5 votes vote down vote up
/**
 * Initializes the paints used for the bars
 */
private void initializePainters() {
    mBarFillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBarFillPaint.setColor(mBarColor);
    mBarFillPaint.setAntiAlias(true);
    mBarFillPaint.setStrokeWidth(0);
    mBarFillPaint.setStyle(Paint.Style.FILL);
}
 
Example 16
Source File: InputWindow.java    From Chimee with MIT License 5 votes vote down vote up
private void colorBackground(Canvas canvas) {
    int color = DEFAULT_BACKGROUND_COLOR;
    Drawable background = getBackground();
    if (background instanceof ColorDrawable)
        color = ((ColorDrawable) background).getColor();
    Paint paint = new Paint();
    paint.setColor(color);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawPaint(paint);
}
 
Example 17
Source File: GooView.java    From android-gooview with MIT License 4 votes vote down vote up
private void init() {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // mPaint.setAntiAlias(true);
    mPaint.setColor(Color.RED);
    mPath = new Path();
}
 
Example 18
Source File: HorTaperChart.java    From WidgetCase with Apache License 2.0 4 votes vote down vote up
private void init(Context context) {
        mContext = context;
        mOffBtm = DensityUtil.dp2px(18);
        mQuadOffset = DensityUtil.dp2px(5);
        mInterSpace = DensityUtil.dp2px(24);
        mLabelWidth = DensityUtil.dp2px(98);
        mLeftAxisLabelMargin = DensityUtil.dp2px(4f);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setARGB(153, 255, 196, 0);
        mPaint.setStrokeWidth(6);

        mAxisPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mAxisPaint.setColor(Color.rgb(149, 199, 255));
        mAxisPaint.setStrokeWidth(DensityUtil.dp2px(0.5f));

        mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint.setColor(Color.rgb(153, 153, 153));
        mTextPaint.setTextSize(DensityUtil.sp2px(mContext, 10));
//        mTextPaint.setTextAlign(Paint.Align.LEFT);

        mNullPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mNullPaint.setColor(Color.rgb(200, 200, 200));
        mNullPaint.setTextSize(DensityUtil.sp2px(mContext, 12f));

        mPointPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPointPaint.setColor(Color.RED);
        mPointPaint.setStrokeWidth(10);
        mPointPaint.setStyle(Paint.Style.FILL_AND_STROKE);

        mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mLinePaint.setStyle(Paint.Style.FILL);
        mLinePaint.setStrokeWidth(DensityUtil.dp2px(0.5f));
        mLinePaint.setColor(Color.RED);

        mYAxisList = new ArrayList<>(6);
        mList = new ArrayList<>(6);
        mXValues = new ArrayList<>(6);
        mYValues = new ArrayList<>(6);

        final ViewConfiguration vc = ViewConfiguration.get(mContext);
        mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
        mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();

        mScroller = new OverScroller(getContext(), interpolator);
    }
 
Example 19
Source File: WidgetLegacy.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
static void updateSilenter(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Resources r = context.getResources();
    float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());

    Theme theme = WidgetUtils.getTheme(widgetId);
    WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1f);
    int s = size.width;
    if (s <= 0)
        return;
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    Intent i = new Intent(context, SilenterPrompt.class);
    remoteViews.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    Bitmap bmp = Bitmap.createBitmap(s, s, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, s / 2f, s / 2f);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, s, s, paint);

    paint.setColor(theme.textcolor);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    paint.setColor(theme.hovercolor);

    paint.setColor(theme.textcolor);

    paint.setTextSize((s * 25) / 100f);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText("Sessize", s / 2f, (s * 125) / 300f, paint);
    canvas.drawText("al", s / 2f, (s * 25) / 30f, paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(dp);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, s, s, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}
 
Example 20
Source File: SeparatorView.java    From android-material-motion with Apache License 2.0 4 votes vote down vote up
private void init() {
  linePaint = new Paint();
  linePaint.setAlpha(50);
  linePaint.setColor(Color.BLACK);
  linePaint.setStrokeWidth(10);
}