Search in sources :

Example 61 with Paint

use of android.graphics.Paint in project titanium-barcode by mwaylabs.

the class ViewfinderView method onDraw.

@Override
public void onDraw(final Canvas canvas) {
    Rect frame = CameraManager.get().getFramingRect();
    if (frame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();
    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    Log.d("asdf", "0, 0, " + width + " ," + frame.top);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);
    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        paint.setAlpha(OPAQUE);
        canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
    } else {
        // Draw a two pixel solid black border inside the framing rect
        paint.setColor(frameColor);
        canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint);
        canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint);
        canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint);
        canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint);
        // Draw a red "laser scanner" line through the middle to show decoding is active
        paint.setColor(laserColor);
        paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
        scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
        int middle = frame.height() / 2 + frame.top;
        canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
        Collection<ResultPoint> currentPossible = possibleResultPoints;
        Collection<ResultPoint> currentLast = lastPossibleResultPoints;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new HashSet<ResultPoint>(5);
            lastPossibleResultPoints = currentPossible;
            paint.setAlpha(OPAQUE);
            paint.setColor(resultPointColor);
            for (ResultPoint point : currentPossible) {
                canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
            }
        }
        if (currentLast != null) {
            paint.setAlpha(OPAQUE / 2);
            paint.setColor(resultPointColor);
            for (ResultPoint point : currentLast) {
                canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);
            }
        }
        // Request another update at the animation interval, but only repaint the laser line,
        // not the entire viewfinder mask.
        postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
    }
}
Also used : Rect(android.graphics.Rect) ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint) Paint(android.graphics.Paint)

Example 62 with Paint

use of android.graphics.Paint in project SuperSaiyanScrollView by nolanlawson.

the class SuperSaiyanScrollView method draw.

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (!mThumbVisible) {
        // No need to draw the rest
        return;
    }
    final int y = mThumbY;
    final int viewWidth = getWidth();
    final SuperSaiyanScrollView.ScrollFade scrollFade = mScrollFade;
    int alpha = -1;
    if (scrollFade.mStarted) {
        alpha = scrollFade.getAlpha();
        if (alpha < ALPHA_MAX / 2) {
            mCurrentThumb.setAlpha(alpha * 2);
        }
        int left = viewWidth - (mThumbW * alpha) / ALPHA_MAX;
        mCurrentThumb.setBounds(left, 0, viewWidth, mThumbH);
        mChangedBounds = true;
    }
    canvas.translate(0, y);
    mCurrentThumb.draw(canvas);
    canvas.translate(0, -y);
    // If user is dragging the scroll bar, draw the alphabet overlay
    if (mDragging && mDrawOverlay) {
        mCurrentThumb.setState(STATE_PRESSED);
        mOverlayDrawable.draw(canvas);
        final Paint paint = mPaint;
        float descent = paint.descent();
        final RectF rectF = mOverlayPos;
        if (mSectionText.indexOf('\n') != -1) {
            // two lines
            float textY = (int) (rectF.bottom + rectF.top) / 2 + descent - (paint.getTextSize() / 2);
            for (String substring : StringUtil.split(mSectionText, '\n')) {
                canvas.drawText(substring, (int) (rectF.left + rectF.right) / 2, textY, paint);
                textY += (descent + paint.getTextSize());
            }
        } else {
            // one line
            canvas.drawText(mSectionText, (int) (rectF.left + rectF.right) / 2, (int) (rectF.bottom + rectF.top) / 2 + descent, paint);
        }
    } else if (alpha == 0) {
        mCurrentThumb.setState(STATE_UNPRESSED);
        scrollFade.mStarted = false;
        removeThumb();
    } else {
        mCurrentThumb.setState(STATE_UNPRESSED);
        invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH);
    }
}
Also used : RectF(android.graphics.RectF) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 63 with Paint

use of android.graphics.Paint in project AnimatedSvgView by jrummyapps.

the class AnimatedSvgView method init.

private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);
    mFillPaint.setStyle(Paint.Style.FILL);
    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = 0x32000000;
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);
        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_animatedSvgImageSizeX, 512);
        aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_animatedSvgImageSizeX, 512);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_animatedSvgImageSizeY, 512);
        aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_animatedSvgImageSizeY, 512);
        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_animatedSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_animatedSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_animatedSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_animatedSvgFillTime, 1000);
        int traceMarkerLength = a.getInt(R.styleable.AnimatedSvgView_animatedSvgTraceMarkerLength, 16);
        mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, traceMarkerLength, getResources().getDisplayMetrics());
        int glyphStringsId = a.getResourceId(R.styleable.AnimatedSvgView_animatedSvgGlyphStrings, 0);
        int traceResidueColorsId = a.getResourceId(R.styleable.AnimatedSvgView_animatedSvgTraceResidueColors, 0);
        int traceColorsId = a.getResourceId(R.styleable.AnimatedSvgView_animatedSvgTraceColors, 0);
        int fillColorsId = a.getResourceId(R.styleable.AnimatedSvgView_animatedSvgFillColors, 0);
        a.recycle();
        if (glyphStringsId != 0) {
            setGlyphStrings(getResources().getStringArray(glyphStringsId));
            setTraceResidueColor(Color.argb(50, 0, 0, 0));
            setTraceColor(Color.BLACK);
        }
        if (traceResidueColorsId != 0) {
            setTraceResidueColors(getResources().getIntArray(traceResidueColorsId));
        }
        if (traceColorsId != 0) {
            setTraceColors(getResources().getIntArray(traceColorsId));
        }
        if (fillColorsId != 0) {
            setFillColors(getResources().getIntArray(fillColorsId));
        }
        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }
    // heuristic based on the number and or dimensions of paths to render.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}
Also used : TypedArray(android.content.res.TypedArray) PointF(android.graphics.PointF) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 64 with Paint

use of android.graphics.Paint in project UltimateAndroid by cymcsg.

the class SlidingLayout method dimChildView.

private void dimChildView(View v, float mag, int fadeColor) {
    final LayoutParams lp = (LayoutParams) v.getLayoutParams();
    if (mag > 0 && fadeColor != 0) {
        final int baseAlpha = (fadeColor & 0xff000000) >>> 24;
        int imag = (int) (baseAlpha * mag);
        int color = imag << 24 | (fadeColor & 0xffffff);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) {
            ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        final DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
Also used : PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 65 with Paint

use of android.graphics.Paint in project UltimateAndroid by cymcsg.

the class BaseFoldingLayout method prepareFold.

/**
     * This method is called in order to update the fold's orientation, anchor
     * point and number of folds. This creates the necessary setup in order to
     * prepare the layout for a fold with the specified parameters. Some of the
     * dimensions required for the folding transformation are also acquired
     * here.
     * <p/>
     * After this method is called, it will be in a completely unfolded state by
     * default.
     */
private void prepareFold(Orientation orientation, float anchorFactor, int numberOfFolds) {
    mSrc = new float[NUM_OF_POLY_POINTS];
    mDst = new float[NUM_OF_POLY_POINTS];
    mDstRect = new Rect();
    mFoldFactor = 0;
    mPreviousFoldFactor = 0;
    mIsFoldPrepared = false;
    mSolidShadow = new Paint();
    mGradientShadow = new Paint();
    mOrientation = orientation;
    mIsHorizontal = (orientation == Orientation.HORIZONTAL);
    if (mIsHorizontal) {
        mShadowLinearGradient = new LinearGradient(0, 0, SHADING_FACTOR, 0, Color.BLACK, Color.TRANSPARENT, TileMode.CLAMP);
    } else {
        mShadowLinearGradient = new LinearGradient(0, 0, 0, SHADING_FACTOR, Color.BLACK, Color.TRANSPARENT, TileMode.CLAMP);
    }
    mGradientShadow.setStyle(Style.FILL);
    mGradientShadow.setShader(mShadowLinearGradient);
    mShadowGradientMatrix = new Matrix();
    mAnchorFactor = anchorFactor;
    mNumberOfFolds = numberOfFolds;
    mOriginalWidth = getMeasuredWidth();
    mOriginalHeight = getMeasuredHeight();
    mFoldRectArray = new Rect[mNumberOfFolds];
    mMatrix = new Matrix[mNumberOfFolds];
    for (int x = 0; x < mNumberOfFolds; x++) {
        mMatrix[x] = new Matrix();
    }
    int h = mOriginalHeight;
    int w = mOriginalWidth;
    if (Util.IS_JBMR2 && h != 0 && w != 0) {
        mFullBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(mFullBitmap);
        getChildAt(0).draw(canvas);
    }
    int delta = Math.round(mIsHorizontal ? ((float) w) / ((float) mNumberOfFolds) : ((float) h) / ((float) mNumberOfFolds));
    /*
         * Loops through the number of folds and segments the full layout into a
		 * number of smaller equal components. If the number of folds is odd,
		 * then one of the components will be smaller than all the rest. Note
		 * that deltap below handles the calculation for an odd number of folds.
		 */
    for (int x = 0; x < mNumberOfFolds; x++) {
        if (mIsHorizontal) {
            int deltap = (x + 1) * delta > w ? w - x * delta : delta;
            mFoldRectArray[x] = new Rect(x * delta, 0, x * delta + deltap, h);
        } else {
            int deltap = (x + 1) * delta > h ? h - x * delta : delta;
            mFoldRectArray[x] = new Rect(0, x * delta, w, x * delta + deltap);
        }
    }
    if (mIsHorizontal) {
        mFoldMaxHeight = h;
        mFoldMaxWidth = delta;
    } else {
        mFoldMaxHeight = delta;
        mFoldMaxWidth = w;
    }
    mIsFoldPrepared = true;
}
Also used : LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)3611 Canvas (android.graphics.Canvas)815 Bitmap (android.graphics.Bitmap)735 RectF (android.graphics.RectF)484 Rect (android.graphics.Rect)400 Path (android.graphics.Path)281 TextPaint (android.text.TextPaint)269 PorterDuffXfermode (android.graphics.PorterDuffXfermode)232 Matrix (android.graphics.Matrix)173 SuppressLint (android.annotation.SuppressLint)148 Point (android.graphics.Point)147 TypedArray (android.content.res.TypedArray)134 BitmapShader (android.graphics.BitmapShader)117 View (android.view.View)103 Drawable (android.graphics.drawable.Drawable)99 BitmapDrawable (android.graphics.drawable.BitmapDrawable)92 ColorMatrix (android.graphics.ColorMatrix)76 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)66 Resources (android.content.res.Resources)65 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)57