package com.prey.barcodereader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import com.prey.PreyLogger; import com.prey.barcodereader.ui.camera.GraphicOverlay; import com.google.android.gms.vision.barcode.Barcode; public class BarcodeGraphic extends GraphicOverlay.Graphic { private int mId; private static final int COLOR_CHOICES[] = { Color.BLUE, Color.CYAN, Color.GREEN }; private static int mCurrentColorIndex = 0; private Paint mRectPaint; private Paint mTextPaint; private volatile Barcode mBarcode; BarcodeGraphic(GraphicOverlay overlay) { super(overlay); mCurrentColorIndex = (mCurrentColorIndex + 1) % COLOR_CHOICES.length; final int selectedColor = COLOR_CHOICES[mCurrentColorIndex]; mRectPaint = new Paint(); mRectPaint.setColor(selectedColor); mRectPaint.setStyle(Paint.Style.STROKE); mRectPaint.setStrokeWidth(4.0f); mTextPaint = new Paint(); mTextPaint.setColor(selectedColor); mTextPaint.setTextSize(36.0f); } public int getId() { return mId; } public void setId(int id) { this.mId = id; } public Barcode getBarcode() { return mBarcode; } void updateItem(Barcode barcode) { mBarcode = barcode; postInvalidate(); } @Override public void draw(Canvas canvas) { Barcode barcode = mBarcode; if (barcode == null) { return; } RectF rect = new RectF(barcode.getBoundingBox()); rect.left = translateX(rect.left); rect.top = translateY(rect.top); rect.right = translateX(rect.right); rect.bottom = translateY(rect.bottom); canvas.drawRect(rect, mRectPaint); String barcodeValue=barcode.rawValue; if (barcodeValue.contains("prey")) barcodeValue=""; canvas.drawText(barcodeValue, rect.left, rect.bottom, mTextPaint); } }