Example usage for android.graphics Canvas drawColor

List of usage examples for android.graphics Canvas drawColor

Introduction

In this page you can find the example usage for android.graphics Canvas drawColor.

Prototype

public void drawColor(@ColorInt int color) 

Source Link

Document

Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, using srcover porterduff mode.

Usage

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 w  w .  j  av  a  2 s .  c  o  m
    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);
    }
}

From source file:com.savvasdalkitsis.betwixt.demo.InterpolatorView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.WHITE);
    int inset = (getHeight() - rectHeight()) / 2;
    canvas.drawRect(getPaddingLeft(), getPaddingTop() + inset, getWidth() - getPaddingRight(),
            getHeight() - inset - getPaddingBottom(), rectPaint);
    float x = 0;/*w  ww.ja va 2 s .c o  m*/
    float y = 0;
    for (int i = 0; i < STEPS; i++) {
        float newX = i / (float) STEPS;
        float newY = interpolator.getInterpolation(newX);
        if (i == 0) {
            x = newX;
            y = newY;
        }
        canvas.drawLine(x(x), y(y), x(newX), y(newY), paint);
        x = newX;
        y = newY;
    }
    canvas.drawText(description, getPaddingLeft() + textPaddingLeft, getHeight() - textHeight, textPaint);
    if (animating) {
        canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
                getHeight() - getPaddingBottom(), dim);
        int areaWidth = getWidth() - getPaddingLeft() - getPaddingRight() - animationInset * 2;
        float circleX = getPaddingLeft() + animationInset + areaWidth * progress;
        linePath.reset();
        linePath.moveTo(getPaddingLeft() + animationInset, getPaddingTop());
        linePath.lineTo(getPaddingLeft() + animationInset, getHeight() - getPaddingBottom());
        linePath.moveTo(getWidth() - getPaddingRight() - animationInset, getPaddingTop());
        linePath.lineTo(getWidth() - getPaddingRight() - animationInset, getHeight() - getPaddingBottom());
        canvas.drawPath(linePath, linePaint);
        canvas.drawCircle(circleX, getHeight() / 2, radius, circlePaint);
    }
}

From source file:net.simno.dmach.ui.view.SequencerView.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawColor(background);
    for (int i = 0; i < sequence.size(); ++i) {
        Step step = sequence.get(i);/*  ww w  . jav a2 s.c  o m*/
        if (step.checked) {
            canvas.drawRect(step.rect, checked);
        } else {
            if ((i % 8) < 4) {
                canvas.drawRect(step.rect, uncheckedLight);
            } else {
                canvas.drawRect(step.rect, uncheckedDark);
            }
        }
    }
}

From source file:net.yanzm.actionbarprogress.MaterialIndeterminateProgressDrawable.java

@Override
public void draw(Canvas canvas) {
    final int level = getLevel();
    final float input = level / 10000f;

    canvas.drawColor(trackColor);

    canvas.save();//from  w w w.j  a v  a2  s .  c o  m
    canvas.translate(canvas.getWidth() / 2f, 0);
    canvas.scale(canvas.getWidth() / 360f, 1);

    paint.setColor(accentColor);

    {
        final int saveCount = canvas.save();

        float translateX2 = translateInterpolator2.getInterpolation(input);
        canvas.translate(-197.60001f + translateX2 * 620.20002f, 0);

        float x = scaleInterpolator2.getInterpolation(input);
        float scaleX = 1.6199005127f * -Math.abs(x - 0.5f) + 0.909950256348f;
        rect2.set(-144f * scaleX, 0, 144f * scaleX, canvas.getHeight());
        canvas.drawRect(rect2, paint);

        canvas.restoreToCount(saveCount);
    }
    {
        final int saveCount = canvas.save();

        float translateX1 = translateInterpolator1.getInterpolation(input);
        canvas.translate(-522.59998f + translateX1 * 722.19999f, 0);

        float x = scaleInterpolator1.getInterpolation(input);
        float scaleX = 1.45369842529f * -Math.abs(x - 0.5f) + 0.826849212646f;
        rect1.set(-144f * scaleX, 0, 144f * scaleX, canvas.getHeight());
        canvas.drawRect(rect1, paint);

        canvas.restoreToCount(saveCount);
    }

    canvas.restore();
}

From source file:at.flack.receiver.EMailReceiver.java

public Bitmap convertToBitmap(String name, Drawable drawable, int widthPixels, int heightPixels) {
    Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mutableBitmap);

    drawable.setBounds(0, 0, widthPixels, heightPixels);
    canvas.drawColor(ContactAdapter.colors[Math.abs(ContactAdapter.betterHashCode(name))
            % ContactAdapter.colors.length]);
    drawable.draw(canvas);//from w ww . j a  v  a 2  s.  co  m

    return RoundedImageView.getCroppedBitmap(mutableBitmap, 300);
}

From source file:com.ichi2.anki.Whiteboard.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(0);
    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    canvas.drawPath(mPath, mPaint);/*from  ww w  .  j a v  a 2s  .  co  m*/
}

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

public void draw(Bitmap bitmap, RenderOptions renderOptions) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.BLACK);
    draw(canvas, renderOptions);/*from  ww  w.  ja v  a2s.c om*/
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

protected void drawSign(Canvas canvas, int bkColor, Paint paint) {
    canvas.drawColor(bkColor);

    for (Path path : mPaths)
        canvas.drawPath(path, paint);/*from  w  w w. j  a v  a  2  s .co  m*/
}

From source file:com.odoo.core.utils.notification.ONotificationBuilder.java

private void init() {
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setContentTitle(title);
    mNotificationBuilder.setContentText(text);
    if (bigText == null)
        mNotificationBuilder.setContentInfo(text);
    if (withLargeIcon()) {
        mNotificationBuilder.setSmallIcon(small_icon);
        Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), this.icon);
        Bitmap newIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), icon.getConfig());
        Canvas canvas = new Canvas(newIcon);
        canvas.drawColor(OResource.color(mContext, R.color.theme_primary));
        canvas.drawBitmap(icon, 0, 0, null);
        mNotificationBuilder.setLargeIcon(newIcon);
    } else {//from w  w  w  .  j  a v  a2s. c  o  m
        mNotificationBuilder.setSmallIcon(icon);
    }
    mNotificationBuilder.setAutoCancel(mAutoCancel);
    mNotificationBuilder.setOngoing(mOnGoing);
    mNotificationBuilder.setColor(OResource.color(mContext, notification_color));
    if (bigText != null) {
        NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
        notiStyle.setBigContentTitle(title);
        notiStyle.setSummaryText(text);
        notiStyle.bigText(bigText);
        mNotificationBuilder.setStyle(notiStyle);
    }
    if (bigPictureStyle != null) {
        mNotificationBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bigPictureStyle));
    }

    if (maxProgress != -1) {
        mNotificationBuilder.setProgress(maxProgress, currentProgress, indeterminate);
    }
}

From source file:de.baumann.thema.FragmentWallpaper.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.color) {
        ColorPickerDialogBuilder.with(getActivity()).initialColor(0xff2196f3).setTitle(R.string.custom)
                .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER).density(9)
                .setPositiveButton(R.string.yes, new ColorPickerClickListener() {
                    @Override//www . j av  a2 s  . co  m
                    public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
                        try {
                            WallpaperManager wm = WallpaperManager.getInstance(getActivity());
                            // Create 1x1 bitmap to store the color
                            Bitmap bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
                            // Make a canvas with which we can draw to the bitmap
                            Canvas canvas = new Canvas(bmp);
                            // Fill with color and save
                            canvas.drawColor(selectedColor);
                            canvas.save();

                            wm.setBitmap(bmp);
                            bmp.recycle();
                            Snackbar.make(imgHeader, R.string.applying, Snackbar.LENGTH_LONG).show();
                        } catch (IOException e) {
                            // oh lord!
                        }
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).build().show();
        return false;
    }

    if (id == R.id.help) {

        SpannableString s;

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            s = new SpannableString(
                    Html.fromHtml(getString(R.string.help_wallpaper), Html.FROM_HTML_MODE_LEGACY));
        } else {
            //noinspection deprecation
            s = new SpannableString(Html.fromHtml(getString(R.string.help_wallpaper)));
        }
        Linkify.addLinks(s, Linkify.WEB_URLS);

        final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.title_wallpaper).setMessage(s)
                .setPositiveButton(getString(R.string.yes), null);
        dialog.show();

        return false;
    }
    return super.onOptionsItemSelected(item);
}