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

The following examples show how to use android.graphics.Paint#setAlpha() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: android-kline   File: AxisRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans, AxisBase axis) {
    super(viewPortHandler);

    this.mTrans = trans;
    this.mAxis = axis;

    if(mViewPortHandler != null) {

        mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

        mGridPaint = new Paint();
        mGridPaint.setColor(Color.GRAY);
        mGridPaint.setStrokeWidth(1f);
        mGridPaint.setStyle(Style.STROKE);
        mGridPaint.setAlpha(90);

        mAxisLinePaint = new Paint();
        mAxisLinePaint.setColor(Color.BLACK);
        mAxisLinePaint.setStrokeWidth(1f);
        mAxisLinePaint.setStyle(Style.STROKE);

        mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mLimitLinePaint.setStyle(Paint.Style.STROKE);
    }
}
 
Example 2
@Override
public void draw(Canvas canvas, Paint paint) {
    final float scale = mCurrentScale;
    if (scale > 0) {
        Rect bounds = getBounds();

        float radius = (Math.min(bounds.width(), bounds.height()) / 2.0f);
        float x = bounds.centerX();
        float y = bounds.centerY();

        // Background
        if (scale != 1f && mBackgroundAlpha > 0) {
            paint.setAlpha(mBackgroundAlpha);
            canvas.drawCircle(x, y, radius, paint);
        }

        // Ripple
        if (mRippleAlpha > 0) {
            paint.setAlpha(mRippleAlpha);
            canvas.drawCircle(x, y, radius * scale, paint);
        }
    }
}
 
Example 3
Source Project: bither-android   File: ScannerView.java    License: Apache License 2.0 6 votes vote down vote up
public ScannerView(final Context context, final AttributeSet attrs) {
	super(context, attrs);

	final Resources res = getResources();
	maskColor = res.getColor(R.color.scan_mask);
	resultColor = res.getColor(R.color.scan_result_view);
	final int laserColor = res.getColor(R.color.scan_laser);
	final int dotColor = res.getColor(R.color.scan_dot);

	maskPaint = new Paint();
	maskPaint.setStyle(Style.FILL);

	laserPaint = new Paint();
	laserPaint.setColor(laserColor);
	laserPaint.setStrokeWidth(DOT_SIZE);
	laserPaint.setStyle(Style.STROKE);

	dotPaint = new Paint();
	dotPaint.setColor(dotColor);
	dotPaint.setAlpha(DOT_OPACITY);
	dotPaint.setStyle(Style.STROKE);
	dotPaint.setStrokeWidth(DOT_SIZE);
	dotPaint.setAntiAlias(true);
}
 
Example 4
private void initJoystickView() {
    setFocusable(true);

    bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStrokeWidth(2);
    bgPaint.setStyle(Paint.Style.STROKE);

    handlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    handlePaint.setColor(Color.GRAY);
    handlePaint.setStrokeWidth(1);
    handlePaint.setAlpha(100);
    handlePaint.setStyle(Paint.Style.FILL_AND_STROKE);

    innerPadding = 10;

    setMovementRange(10);
    setMoveResolution(1.0f);
    setUserCoordinateSystem(COORDINATE_CARTESIAN);
    setAutoReturnToCenter(true);
}
 
Example 5
@Override
protected void initData(Context context) {
    super.initData(context);

    // creating animators
    mDimSelectorWheelAnimator = ObjectAnimator.ofFloat(this, PROPERTY_SELECTOR_PAINT_COEFF, 1, 0);

    mDimSeparatorsAnimator = ObjectAnimator.ofInt(this, PROPERTY_SEPARATORS_PAINT_ALPHA,
            mSelectionDividerActiveAlpha, mSelectionDividerDimmedAlpha
    );

    // creating paints
    mSeparatorsPaint = new Paint();
    mSeparatorsPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    mSeparatorsPaint.setAlpha(mSelectionDividerDimmedAlpha);

    mSelectorWheelPaint = new Paint();
    mSelectorWheelPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
}
 
Example 6
Source Project: memoir   File: ValueBar.java    License: Apache License 2.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 = 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);

    mPosToSatFactor = 1 / ((float) mBarLength);
    mSatToPosFactor = ((float) mBarLength) / 1;
}
 
Example 7
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 = 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);

	mPosToSatFactor = 1 / ((float) mBarLength);
	mSatToPosFactor = ((float) mBarLength) / 1;
}
 
Example 8
/**
 * Changes the paint color to the specified value.
 *
 * @param paint the object to mutate with the new color
 * @param argb a 32-bit integer with eight bits for alpha, red, green, and blue,
 *        respectively
 */
public static void changePaint(Paint paint, int argb) {
  // TODO(user): can the following two lines can be replaced by:
  // paint.setColor(argb)?
  paint.setColor(argb & 0x00FFFFFF);
  paint.setAlpha((argb >> 24) & 0xFF);
  paint.setXfermode(null);
}
 
Example 9
Source Project: PullToRefresh   File: RocketRefreshView.java    License: MIT License 5 votes vote down vote up
private void drawSmallFire(final Canvas canvas, Bitmap bitmap, float fireOffsetX, float fireOffsetY, float scaleY,
                           float pivotX, float pivotY) {
    final Matrix matrix = mMatrix;
    matrix.reset();

    matrix.postTranslate(fireOffsetX, fireOffsetY);
    float fireMinScale = 0.9f;
    matrix.postScale(Math.max(fireMinScale, scaleY), Math.max(fireMinScale, scaleY), pivotX, pivotY);
    Paint paint = new Paint();
    float alpha = (Math.max(0.5f, mFireScale)) * 255;
    paint.setAlpha((int) alpha);
    canvas.drawBitmap(bitmap, matrix, paint);
}
 
Example 10
@Override
public void draw(Canvas canvas) {
	Paint paint = this.paint;
	Rect bounds = getBounds();
	float t;
	if (view != null) {
		if (animator == null) {
			animator = ValueAnimator.ofFloat(0f, 1f);
			animator.setInterpolator(AnimationUtils.ACCELERATE_INTERPOLATOR);
			animator.setDuration(300);
			animator.start();
			view.getLocationOnScreen(location);
		}
		t = (float) animator.getAnimatedValue();
	} else {
		t = 1f;
	}
	if (t >= 1f) {
		paint.setAlpha(alpha);
		canvas.drawRect(bounds, paint);
	} else {
		int width = bounds.width();
		int height = bounds.height();
		float cx = AnimationUtils.lerp(centerX - location[0], bounds.left + width / 2f, t / 2f);
		float cy = AnimationUtils.lerp(centerY - location[1], bounds.top + height / 2f, t / 2f);
		float radius = AnimationUtils.lerp(0f, (float) Math.sqrt(width * width + height * height), t);
		paint.setAlpha(((int) (0xff * t)));
		canvas.drawRect(bounds, paint);
		paint.setAlpha(((int) (0xff * (1f - t) / 2f)));
		canvas.drawCircle(cx, cy, radius, paint);
		invalidateSelf();
	}
}
 
Example 11
Source Project: Carbon   File: RippleBackground.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean drawSoftware(Canvas c, Paint p) {
    boolean hasContent = false;

    final int origAlpha = p.getAlpha();
    final int alpha = (int) (origAlpha * mOpacity + 0.5f);
    if (alpha > 0) {
        p.setAlpha(alpha);
        c.drawCircle(0, 0, mTargetRadius, p);
        p.setAlpha(origAlpha);
        hasContent = true;
    }

    return hasContent;
}
 
Example 12
private static Paint getPaint(Style style, int color, int alpha) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(style);
    paint.setColor(color);
    paint.setAlpha(alpha);
    return paint;
}
 
Example 13
private Drawable createOuterStrokeDrawable(float strokeWidth) {
  ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());

  final Paint paint = shapeDrawable.getPaint();
  paint.setAntiAlias(true);
  paint.setStrokeWidth(strokeWidth);
  paint.setStyle(Style.STROKE);
  paint.setColor(Color.BLACK);
  paint.setAlpha(opacityToAlpha(0.02f));

  return shapeDrawable;
}
 
Example 14
Source Project: RichEditorView   File: LuBottomMenu.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (needLine) {
        mPaint = new Paint();
        mPaint.setAlpha(127);
    }
}
 
Example 15
private Drawable createOuterStrokeDrawable(float strokeWidth)
{
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());

    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(strokeWidth);
    paint.setStyle(Style.STROKE);
    paint.setColor(Color.BLACK);
    paint.setAlpha(opacityToAlpha(0.02f));

    return shapeDrawable;
}
 
Example 16
Source Project: android-kline   File: PieChart.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the color the transparent-circle should have.
 *
 * @param color
 */
public void setTransparentCircleColor(int color) {

    Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle();
    int alpha = p.getAlpha();
    p.setColor(color);
    p.setAlpha(alpha);
}
 
Example 17
Source Project: arcusandroid   File: ComboSeekBarSlider.java    License: Apache License 2.0 4 votes vote down vote up
public ComboSeekBarSlider(Drawable base, ComboSeekBar slider, float thumbRadius, List<Dot> dots, int color, int textSize, boolean isMultiline, int selectedStrokeWidth, int unselectedStrokeWidth, int unselectedLineAlpha, int unselectedDotAlpha) {
	mIsMultiline = isMultiline;
	mySlider = slider;
	myBase = base;
	mDots = dots;
	int mTextSize = textSize;
	textUnselected = new Paint(Paint.ANTI_ALIAS_FLAG);
	textUnselected.setColor(color);
	textUnselected.setAlpha(255);

	textSelected = new Paint(Paint.ANTI_ALIAS_FLAG);
	textSelected.setTypeface(Typeface.DEFAULT_BOLD);
	textSelected.setColor(color);
	textSelected.setAlpha(255);

	mThumbRadius = thumbRadius;

	unselectLinePaint = new Paint();
	unselectLinePaint.setColor(color);
	unselectLinePaint.setAlpha(unselectedLineAlpha);
	unselectLinePaint.setStrokeWidth(toPix(unselectedStrokeWidth));

	selectLinePaint = new Paint();
	selectLinePaint.setColor(color);
	selectLinePaint.setStrokeWidth(toPix(selectedStrokeWidth));

	unselectedCircleLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	unselectedCircleLinePaint.setColor(color);
	unselectedCircleLinePaint.setAlpha(unselectedDotAlpha);

	selectedCircleLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	selectedCircleLinePaint.setColor(color);

	Rect textBounds = new Rect();
	textSelected.setTextSize(mTextSize * 2);
	textSelected.getTextBounds("M", 0, 1, textBounds);

	textUnselected.setTextSize(mTextSize);
	textSelected.setTextSize(mTextSize);

	mTextHeight = textBounds.height();
	mDotRadius = toPix(5);
	mTextMargin = toPix(10);
}
 
Example 18
Source Project: OverWatchLoading   File: OWLoadingView.java    License: Apache License 2.0 4 votes vote down vote up
public void drawHexagon(Canvas canvas, Paint paint) {
    paint.setAlpha(alpha);
    canvas.drawPath(getPath(), paint);
}
 
Example 19
Source Project: android_9.0.0_r45   File: Magnifier.java    License: Apache License 2.0 4 votes vote down vote up
private void doDraw() {
    final ThreadedRenderer.FrameDrawingCallback callback;

    // Draw the current bitmap to the surface, and prepare the callback which updates the
    // surface position. These have to be in the same synchronized block, in order to
    // guarantee the consistency between the bitmap content and the surface position.
    synchronized (mLock) {
        if (!mSurface.isValid()) {
            // Probably #destroy() was called for the current instance, so we skip the draw.
            return;
        }

        final DisplayListCanvas canvas =
                mBitmapRenderNode.start(mContentWidth, mContentHeight);
        try {
            canvas.drawColor(Color.WHITE);

            final Rect srcRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
            final Rect dstRect = new Rect(0, 0, mContentWidth, mContentHeight);
            final Paint paint = new Paint();
            paint.setFilterBitmap(true);
            paint.setAlpha(CONTENT_BITMAP_ALPHA);
            canvas.drawBitmap(mBitmap, srcRect, dstRect, paint);
        } finally {
            mBitmapRenderNode.end(canvas);
        }

        if (mPendingWindowPositionUpdate || mFirstDraw) {
            // If the window has to be shown or moved, defer this until the next draw.
            final boolean firstDraw = mFirstDraw;
            mFirstDraw = false;
            final boolean updateWindowPosition = mPendingWindowPositionUpdate;
            mPendingWindowPositionUpdate = false;
            final int pendingX = mWindowPositionX;
            final int pendingY = mWindowPositionY;

            callback = frame -> {
                synchronized (mDestroyLock) {
                    if (!mSurface.isValid()) {
                        return;
                    }
                    synchronized (mLock) {
                        mRenderer.setLightCenter(mDisplay, pendingX, pendingY);
                        // Show or move the window at the content draw frame.
                        SurfaceControl.openTransaction();
                        mSurfaceControl.deferTransactionUntil(mSurface, frame);
                        if (updateWindowPosition) {
                            mSurfaceControl.setPosition(pendingX, pendingY);
                        }
                        if (firstDraw) {
                            mSurfaceControl.setLayer(SURFACE_Z);
                            mSurfaceControl.show();
                        }
                        SurfaceControl.closeTransaction();
                    }
                }
            };
        } else {
            callback = null;
        }

        mLastDrawContentPositionX = mWindowPositionX + mOffsetX;
        mLastDrawContentPositionY = mWindowPositionY + mOffsetY;
        mFrameDrawScheduled = false;
    }

    mRenderer.draw(callback);
    if (mCallback != null) {
        mCallback.onOperationComplete();
    }
}
 
Example 20
Source Project: Chart   File: LineChart.java    License: Apache License 2.0 4 votes vote down vote up
private void drawLine(Canvas canvas){
    //如果没有设置x轴数据
    if (xData == null){
        throw new NullPointerException("x轴数据源不能为空!");
    }
    //如果没有设置y轴数据
    if (yData == null){
        throw new NullPointerException("y轴数据源不能为空!");
    }
    //折线画笔
    Paint linePaint = new Paint();
    linePaint.setColor(line_color);
    linePaint.setAntiAlias(true);
    linePaint.setStyle(line_path_style == 0 ? Paint.Style.STROKE : Paint.Style.FILL);
    linePaint.setStrokeWidth(line_width);
    //折点画笔
    Paint pointPaint = new Paint();
    pointPaint.setColor(point_color);
    pointPaint.setAntiAlias(true);
    pointPaint.setStyle(Paint.Style.FILL);
    pointPaint.setStrokeWidth(point_size);
    //画折点和折线
    Path path = new Path();
    path.moveTo(oX,oY);
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(point_text_size);
    textPaint.setColor(point_text_color);
    DecimalFormat formater = new DecimalFormat("0.000");
    for (int i=0;i<xpCount;i++){
        //float dataX = oX+xCoordinates[i];
        //float dataY = oY-yData[i]/yMax*yCoordinates[yCoordinates.length-1];
        int alpha = anims[i].getAlpha();
        linePaint.setAlpha(alpha);
        pointPaint.setAlpha(alpha);
        textPaint.setAlpha(alpha);
        canvas.drawPoint(anims[i].getFinalX(),anims[i].getCurrentY(),pointPaint);
        //画折点上文字
        String text = formater.format(yData[i]);
        int[] textSize = getTextSize(text,textPaint);
        int textX = textSize[0];
        int textY = textSize[1];
        canvas.drawText(text,anims[i].getFinalX()-textX/2,anims[i].getCurrentY()-textY,textPaint);
        path.lineTo(anims[i].getFinalX(),anims[i].getCurrentY());
    }
    switch (line_path_style){
        case 0:
            canvas.drawPath(path,linePaint);
            break;
        case 1:
            linePaint.setStyle(Paint.Style.FILL);
            path.close();
            canvas.drawPath(path,linePaint);
            break;
        default:
            canvas.drawPath(path,linePaint);
            break;
    }
}