Example usage for android.graphics Paint setStyle

List of usage examples for android.graphics Paint setStyle

Introduction

In this page you can find the example usage for android.graphics Paint setStyle.

Prototype

public void setStyle(Style style) 

Source Link

Document

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

Usage

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java

private static void drawPath(GoogleMap map, List<LatLng> points, int color) {
    // int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
    Paint paint = new Paint();
    paint.setColor(color);/*from w  w  w . j a v a2  s.c o m*/
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(6);

    PolylineOptions po = new PolylineOptions().addAll(points).width(6).color(color);
    Polyline pl = map.addPolyline(po);
    pl.setVisible(true);
}

From source file:Main.java

public static Bitmap getCroppedBitmap(Bitmap bmp, int radius, int border, int color) {
    Bitmap scaledBitmap;/* ww w. ja  v  a2  s .c  o  m*/
    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
        scaledBitmap = ThumbnailUtils.extractThumbnail(bmp, radius - 2, radius - 2);
    } else {
        scaledBitmap = bmp;
    }

    Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2,
            paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    final Rect rect = new Rect(0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight());
    canvas.drawBitmap(scaledBitmap, rect, rect, paint);

    if (border > 0) {
        paint.setStrokeWidth(border);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2,
                scaledBitmap.getWidth() / 2, paint);
    }

    return output;
}

From source file:im.neon.util.NotificationUtils.java

/**
 * Build a message notification./* ww w . ja  v  a  2  s  .c  om*/
 * @param context the context
 * @param from the sender
 * @param matrixId the user account id;
 * @param displayMatrixId true to display the matrix id
 * @param largeIcon the notification icon
 * @param unseenNotifiedRoomsCount the number of notified rooms
 * @param body the message body
 * @param roomId the room id
 * @param roomName the room name
 * @param shouldPlaySound true when the notification as sound.
 * @param isInvitationEvent true if it is an invitation notification
 * @return the notification
 */
public static Notification buildMessageNotification(Context context, String from, String matrixId,
        boolean displayMatrixId, Bitmap largeIcon, int unseenNotifiedRoomsCount, String body, String roomId,
        String roomName, boolean shouldPlaySound, boolean isInvitationEvent) {

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setWhen(System.currentTimeMillis());

    if (!TextUtils.isEmpty(from)) {
        // don't display the room name for 1:1 room notifications.
        if (!TextUtils.isEmpty(roomName) && !roomName.equals(from)) {
            builder.setContentTitle(from + " (" + roomName + ")");
        } else {
            builder.setContentTitle(from);
        }
    } else {
        builder.setContentTitle(roomName);
    }

    builder.setContentText(body);
    builder.setAutoCancel(true);
    builder.setSmallIcon(R.drawable.message_notification_transparent);

    if (null != largeIcon) {
        largeIcon = createSquareBitmap(largeIcon);

        // add a bubble in the top right
        if (0 != unseenNotifiedRoomsCount) {
            try {
                android.graphics.Bitmap.Config bitmapConfig = largeIcon.getConfig();

                // set default bitmap config if none
                if (bitmapConfig == null) {
                    bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
                }

                // setLargeIcon must used a 64 * 64 pixels bitmap
                // rescale to have the same text UI.
                float densityScale = context.getResources().getDisplayMetrics().density;
                int side = (int) (64 * densityScale);

                Bitmap bitmapCopy = Bitmap.createBitmap(side, side, bitmapConfig);
                Canvas canvas = new Canvas(bitmapCopy);

                // resize the bitmap to fill in size
                int bitmapWidth = largeIcon.getWidth();
                int bitmapHeight = largeIcon.getHeight();

                float scale = Math.min((float) canvas.getWidth() / (float) bitmapWidth,
                        (float) canvas.getHeight() / (float) bitmapHeight);

                int scaledWidth = (int) (bitmapWidth * scale);
                int scaledHeight = (int) (bitmapHeight * scale);

                Bitmap rescaledBitmap = Bitmap.createScaledBitmap(largeIcon, scaledWidth, scaledHeight, true);
                canvas.drawBitmap(rescaledBitmap, (side - scaledWidth) / 2, (side - scaledHeight) / 2, null);

                String text = "" + unseenNotifiedRoomsCount;

                // prepare the text drawing
                Paint textPaint = new Paint();
                textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
                textPaint.setColor(Color.WHITE);
                textPaint.setTextSize(10 * densityScale);

                // get its size
                Rect textBounds = new Rect();

                if (-1 == mUnreadBubbleWidth) {
                    textPaint.getTextBounds("99", 0, 2, textBounds);
                    mUnreadBubbleWidth = textBounds.width();
                }

                textPaint.getTextBounds(text, 0, text.length(), textBounds);

                // draw a red circle
                int radius = mUnreadBubbleWidth;
                Paint paint = new Paint();
                paint.setStyle(Paint.Style.FILL);
                paint.setColor(Color.RED);
                canvas.drawCircle(canvas.getWidth() - radius, radius, radius, paint);

                // draw the text
                canvas.drawText(text,
                        canvas.getWidth() - textBounds.width() - (radius - (textBounds.width() / 2)),
                        -textBounds.top + (radius - (-textBounds.top / 2)), textPaint);

                // get the new bitmap
                largeIcon = bitmapCopy;
            } catch (Exception e) {
                Log.e(LOG_TAG, "## buildMessageNotification(): Exception Msg=" + e.getMessage());
            }
        }

        builder.setLargeIcon(largeIcon);
    }

    String name = ": ";
    if (!TextUtils.isEmpty(roomName)) {
        name = " (" + roomName + "): ";
    }

    if (displayMatrixId) {
        from = "[" + matrixId + "]\n" + from;
    }

    builder.setTicker(from + name + body);

    TaskStackBuilder stackBuilder;
    Intent intent;

    intent = new Intent(context, VectorRoomActivity.class);
    intent.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId);

    if (null != matrixId) {
        intent.putExtra(VectorRoomActivity.EXTRA_MATRIX_ID, matrixId);
    }

    stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorRoomActivity.class)
            .addNextIntent(intent);

    // android 4.3 issue
    // use a generator for the private requestCode.
    // When using 0, the intent is not created/launched when the user taps on the notification.
    //
    PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    // display the message with more than 1 lines when the device supports it
    NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
    textStyle.bigText(from + ":" + body);
    builder.setStyle(textStyle);

    // do not offer to quick respond if the user did not dismiss the previous one
    if (!LockScreenActivity.isDisplayingALockScreenActivity()) {
        if (!isInvitationEvent) {
            // offer to type a quick answer (i.e. without launching the application)
            Intent quickReplyIntent = new Intent(context, LockScreenActivity.class);
            quickReplyIntent.putExtra(LockScreenActivity.EXTRA_ROOM_ID, roomId);
            quickReplyIntent.putExtra(LockScreenActivity.EXTRA_SENDER_NAME, from);
            quickReplyIntent.putExtra(LockScreenActivity.EXTRA_MESSAGE_BODY, body);

            if (null != matrixId) {
                quickReplyIntent.putExtra(LockScreenActivity.EXTRA_MATRIX_ID, matrixId);
            }

            // the action must be unique else the parameters are ignored
            quickReplyIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis())));
            PendingIntent pIntent = PendingIntent.getActivity(context, 0, quickReplyIntent, 0);
            builder.addAction(R.drawable.vector_notification_quick_reply,
                    context.getString(R.string.action_quick_reply), pIntent);
        } else {
            {
                // offer to type a quick reject button
                Intent leaveIntent = new Intent(context, JoinScreenActivity.class);
                leaveIntent.putExtra(JoinScreenActivity.EXTRA_ROOM_ID, roomId);
                leaveIntent.putExtra(JoinScreenActivity.EXTRA_MATRIX_ID, matrixId);
                leaveIntent.putExtra(JoinScreenActivity.EXTRA_REJECT, true);

                // the action must be unique else the parameters are ignored
                leaveIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis())));
                PendingIntent pIntent = PendingIntent.getActivity(context, 0, leaveIntent, 0);
                builder.addAction(R.drawable.vector_notification_reject_invitation,
                        context.getString(R.string.reject), pIntent);
            }

            {
                // offer to type a quick accept button
                Intent acceptIntent = new Intent(context, JoinScreenActivity.class);
                acceptIntent.putExtra(JoinScreenActivity.EXTRA_ROOM_ID, roomId);
                acceptIntent.putExtra(JoinScreenActivity.EXTRA_MATRIX_ID, matrixId);
                acceptIntent.putExtra(JoinScreenActivity.EXTRA_JOIN, true);

                // the action must be unique else the parameters are ignored
                acceptIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis())));
                PendingIntent pIntent = PendingIntent.getActivity(context, 0, acceptIntent, 0);
                builder.addAction(R.drawable.vector_notification_accept_invitation,
                        context.getString(R.string.join), pIntent);
            }
        }

        // Build the pending intent for when the notification is clicked
        Intent roomIntentTap;
        if (isInvitationEvent) {
            // for invitation the room preview must be displayed
            roomIntentTap = CommonActivityUtils.buildIntentPreviewRoom(matrixId, roomId, context,
                    VectorFakeRoomPreviewActivity.class);
        } else {
            roomIntentTap = new Intent(context, VectorRoomActivity.class);
            roomIntentTap.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId);
        }
        // the action must be unique else the parameters are ignored
        roomIntentTap.setAction(TAP_TO_VIEW_ACTION + ((int) (System.currentTimeMillis())));

        // Recreate the back stack
        TaskStackBuilder stackBuilderTap = TaskStackBuilder.create(context)
                .addParentStack(VectorRoomActivity.class).addNextIntent(roomIntentTap);

        builder.addAction(R.drawable.vector_notification_open, context.getString(R.string.action_open),
                stackBuilderTap.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    }

    //extendForCar(context, builder, roomId, roomName, from, body);

    Notification n = builder.build();
    n.flags |= Notification.FLAG_SHOW_LIGHTS;
    n.defaults |= Notification.DEFAULT_LIGHTS;

    if (shouldPlaySound) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        // some devices crash if this field is not set
        // even if it is deprecated

        // setLatestEventInfo() is deprecated on Android M, so we try to use
        // reflection at runtime, to avoid compiler error: "Cannot resolve method.."
        try {
            Method deprecatedMethod = n.getClass().getMethod("setLatestEventInfo", Context.class,
                    CharSequence.class, CharSequence.class, PendingIntent.class);
            deprecatedMethod.invoke(n, context, from, body, pendingIntent);
        } catch (Exception ex) {
            Log.e(LOG_TAG,
                    "## buildMessageNotification(): Exception - setLatestEventInfo() Msg=" + ex.getMessage());
        }
    }

    return n;
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Clips the long edge of a bitmap, if its width and height are not equal, in order to transform
 * it into a square. Additionally, the bitmap is resized to a specific size and a border will be
 * added./*from  www  .  java2s. com*/
 *
 * @param bitmap
 *         The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The
 *         bitmap may not be null
 * @param size
 *         The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The
 *         size must be at least 1
 * @param borderWidth
 *         The width of the border as an {@link Integer} value in pixels. The width must be at
 *         least 0
 * @param borderColor
 *         The color of the border as an {@link Integer} value
 * @return The clipped bitmap as an instance of the class {@link Bitmap}
 */
public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size, final int borderWidth,
        @ColorInt final int borderColor) {
    ensureAtLeast(borderWidth, 0, "The border width must be at least 0");
    Bitmap clippedBitmap = clipSquare(bitmap, size);
    Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    float offset = borderWidth / 2.0f;
    Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight());
    RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset);
    canvas.drawBitmap(clippedBitmap, src, dst, null);

    if (borderWidth > 0 && Color.alpha(borderColor) != 0) {
        Paint paint = new Paint();
        paint.setFilterBitmap(false);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderWidth);
        paint.setColor(borderColor);
        offset = borderWidth / 2.0f;
        RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset);
        canvas.drawRect(bounds, paint);
    }

    return result;
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the
 * bitmap is resized to a specific size and a border will be added. Bitmaps, whose width and
 * height are not equal, will be clipped to a square beforehand.
 *
 * @param bitmap/*  ww w. j  a v a  2 s.c  o m*/
 *         The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The
 *         bitmap may not be null
 * @param size
 *         The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The
 *         size must be at least 1
 * @param borderWidth
 *         The width of the border as an {@link Integer} value in pixels. The width must be at
 *         least 0
 * @param borderColor
 *         The color of the border as an {@link Integer} value
 * @return The clipped bitmap as an instance of the class {@link Bitmap}
 */
public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size, final int borderWidth,
        @ColorInt final int borderColor) {
    ensureAtLeast(borderWidth, 0, "The border width must be at least 0");
    Bitmap clippedBitmap = clipCircle(bitmap, size);
    Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    float offset = borderWidth / 2.0f;
    Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight());
    RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset);
    canvas.drawBitmap(clippedBitmap, src, dst, null);

    if (borderWidth > 0 && Color.alpha(borderColor) != 0) {
        Paint paint = new Paint();
        paint.setFilterBitmap(false);
        paint.setAntiAlias(true);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderWidth);
        paint.setColor(borderColor);
        offset = borderWidth / 2.0f;
        RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset);
        canvas.drawArc(bounds, 0, COMPLETE_ARC_ANGLE, false, paint);
    }

    return result;
}

From source file:com.busdrone.android.ui.VehicleMarkerRenderer.java

private Bitmap render(int color, String text) {
    TextPaint textPaint = new TextPaint();
    textPaint.setColor(Color.WHITE);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setAntiAlias(true);/*  www .j a  va  2 s  . com*/
    textPaint.setTextSize(mTextSize);

    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    int width = mPadding + textBounds.width() + mPadding;
    int height = mPadding + textBounds.height() + mPadding;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    canvas.drawRoundRect(new RectF(0, 0, width, height), mCornerRadius, mCornerRadius, paint);

    canvas.drawText(text, (width / 2f) - (textBounds.width() / 2f), (height / 2f) + (textBounds.height() / 2f),
            textPaint);

    return bitmap;
}

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

/**
 * Creates a Bitmap image that contains red on white text with a specified margin.
 * @param text Text to be displayed in the image.
 * @return A Bitmap image with the above specification.
 */// w  w  w .  j av a  2 s.  co m
private Bitmap createSampleImage(String text) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setTextSize(TEXT_SIZE);
    Rect rect = new Rect();
    paint.getTextBounds(text, 0, text.length(), rect);
    int w = 2 * MARGIN + rect.right - rect.left;
    int h = 2 * MARGIN + rect.bottom - rect.top;
    Bitmap dest = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas();
    canvas.setBitmap(dest);
    paint.setColor(Color.WHITE);
    canvas.drawPaint(paint);
    paint.setColor(Color.RED);
    canvas.drawText(text, MARGIN - rect.left, MARGIN - rect.top, paint);
    return dest;
}

From source file:com.jjoe64.graphview_demos.fragments.Styling.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    GraphView graph = (GraphView) rootView.findViewById(R.id.graph);

    DataPoint[] points = new DataPoint[30];
    for (int i = 0; i < 30; i++) {
        points[i] = new DataPoint(i, Math.sin(i * 0.5) * 20 * (Math.random() * 10 + 1));
    }/*from   w w w .j a v a 2 s  .c om*/
    LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(points);

    points = new DataPoint[15];
    for (int i = 0; i < 15; i++) {
        points[i] = new DataPoint(i * 2, Math.sin(i * 0.5) * 20 * (Math.random() * 10 + 1));
    }
    LineGraphSeries<DataPoint> series2 = new LineGraphSeries<DataPoint>(points);

    // styling grid/labels
    graph.getGridLabelRenderer().setGridColor(Color.RED);
    graph.getGridLabelRenderer().setHighlightZeroLines(false);
    graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.GREEN);
    graph.getGridLabelRenderer().setVerticalLabelsColor(Color.RED);
    graph.getGridLabelRenderer().setVerticalLabelsAlign(Paint.Align.LEFT);
    graph.getGridLabelRenderer().setLabelVerticalWidth(150);
    graph.getGridLabelRenderer().setTextSize(40);
    graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);
    graph.getGridLabelRenderer().reloadStyles();

    // styling viewport
    graph.getViewport().setBackgroundColor(Color.argb(255, 222, 222, 222));

    // styling series
    series.setTitle("Random Curve 1");
    series.setColor(Color.GREEN);
    series.setDrawDataPoints(true);
    series.setDataPointsRadius(10);
    series.setThickness(8);

    series2.setTitle("Random Curve 2");
    series2.setDrawBackground(true);
    series2.setBackgroundColor(Color.argb(100, 255, 255, 0));
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(10);
    paint.setPathEffect(new DashPathEffect(new float[] { 8, 5 }, 0));
    series2.setCustomPaint(paint);

    // styling legend
    graph.getLegendRenderer().setVisible(true);
    graph.getLegendRenderer().setTextSize(25);
    graph.getLegendRenderer().setBackgroundColor(Color.argb(150, 50, 0, 0));
    graph.getLegendRenderer().setTextColor(Color.WHITE);
    //graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);
    //graph.getLegendRenderer().setMargin(30);
    graph.getLegendRenderer().setFixedPosition(150, 0);

    graph.addSeries(series);
    graph.addSeries(series2);

    return rootView;
}

From source file:com.artioml.practice.activities.LicenseActivity.java

public BitmapDrawable drawParallelogramLine(int width) {
    Matrix matrix = new Matrix();
    Path path = new Path();
    path.addRect(0, 0, (4 * width) / 40, (4 * width) / 200, Path.Direction.CW);
    Path pathStamp = new Path();
    Paint p;
    Bitmap bitmap;//  w w  w .ja va2 s. co m

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

    bitmap = Bitmap.createBitmap(width / 4, width / 80 * 2 + (4 * width) / 200, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    p.setColor(ContextCompat.getColor(this, R.color.colorPrimaryLight));

    matrix.reset();
    matrix.setTranslate(0, 0);
    matrix.postSkew(-1f, 0.0f, 0, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    p.setColor(ContextCompat.getColor(this, R.color.colorAccent));

    matrix.reset();
    matrix.setTranslate(width / 8, 0);
    matrix.postSkew(-1f, 0.0f, width / 8, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
    bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);

    return bitmapDrawable;
}

From source file:com.richtodd.android.quiltdesign.block.Theme.java

private void draw(Canvas canvas, int width, int height) {
    canvas.drawColor(Color.WHITE);

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

    int idx = 0;//from   w  ww  .jav a  2s  .c om
    int left = 0;
    int right = 0;
    for (Swatch swatch : m_swatches) {
        idx += 1;
        left = right;
        right = width * idx / m_swatches.size();

        swatchPaint.setColor(swatch.getColor());
        canvas.drawRect(left, 0, right, height, swatchPaint);
    }
}