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.ifoer.util.NetPOSPrinter.java

public Bitmap drawBitFirst() {
    this.nBitmapFirst = Bitmap.createBitmap(PRINT_WIDTH, 85, Config.RGB_565);
    Canvas canvas = new Canvas(this.nBitmapFirst);
    canvas.drawColor(-1);
    Paint p = new Paint();
    p.setColor(DefaultRenderer.BACKGROUND_COLOR);
    p.setTextSize(20.0f);/*from   www.  jav a 2 s  .co  m*/
    canvas.drawText(this.mContext.getResources().getString(C0136R.string.print_launch), 0.0f, 20.0f, p);
    canvas.drawLine(0.0f, 40.0f, 384.0f, 40.0f, p);
    canvas.drawText(
            this.mContext.getResources().getString(C0136R.string.print_automobile_fault_diagnosis_test_report),
            20.0f, 70.0f, p);
    canvas.drawLine(0.0f, 80.0f, 384.0f, 80.0f, p);
    return this.nBitmapFirst;
}

From source file:com.ifoer.util.NetPOSPrinter.java

public Bitmap drawBitSecond(String s) {
    if (this.company_address == null) {
        this.company_address = XmlPullParser.NO_NAMESPACE;
    }/*  w w w . ja va  2 s .  c  o m*/
    if (this.company_phone == null) {
        this.company_phone = XmlPullParser.NO_NAMESPACE;
    }
    if (this.license_plate_number == null) {
        this.license_plate_number = XmlPullParser.NO_NAMESPACE;
    }
    StringBuffer ss = new StringBuffer();
    ss.append(new StringBuilder(
            String.valueOf(this.mContext.getResources().getString(C0136R.string.print_test_time)))
                    .append(this.str).append(SpecilApiUtil.LINE_SEP).toString());
    ss.append(new StringBuilder(
            String.valueOf(this.mContext.getResources().getString(C0136R.string.print_serial_number)))
                    .append(this.serialNum).append(SpecilApiUtil.LINE_SEP).toString());
    ss.append(new StringBuilder(
            String.valueOf(this.mContext.getResources().getString(C0136R.string.print_test_company_address)))
                    .append(this.company_address).append(SpecilApiUtil.LINE_SEP).toString());
    ss.append(new StringBuilder(
            String.valueOf(this.mContext.getResources().getString(C0136R.string.print_test_company_phone)))
                    .append(this.company_phone).append(SpecilApiUtil.LINE_SEP).toString());
    ss.append(new StringBuilder(String
            .valueOf(this.mContext.getResources().getString(C0136R.string.print_test_license_plate_number)))
                    .append(this.license_plate_number).append(SpecilApiUtil.LINE_SEP).toString());
    ss.append(s);
    this.textPaint.setColor(DefaultRenderer.BACKGROUND_COLOR);
    this.textPaint.setTextSize(20.0f);
    StaticLayout layout = new StaticLayout(ss, this.textPaint, PRINT_WIDTH, Alignment.ALIGN_NORMAL, 1.0f, 0.0f,
            true);
    this.nBitmapSecond = Bitmap.createBitmap(PRINT_WIDTH, layout.getHeight(), Config.RGB_565);
    Canvas canvas = new Canvas(this.nBitmapSecond);
    canvas.drawColor(-1);
    layout.draw(canvas);
    return this.nBitmapSecond;
}

From source file:com.mianamiana.library.LiquidBallProgressBar.java

private BitmapShader createShader(int foregroundColor, int backgroundColor) {

    DrawableCompat.setTint(mWave, foregroundColor);

    Bitmap b = Bitmap.createBitmap(mWaveW, mWaveH, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.drawColor(backgroundColor);

    mWave.setBounds(0, 0, mWaveW, mWaveH);
    mWave.draw(c);/*w  w  w.j a  va 2  s.  com*/

    BitmapShader shader = new BitmapShader(b, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);

    return shader;
}

From source file:om.sstvencoder.CropView.java

public Bitmap getBitmap() {
    if (!mImageOK)
        return null;

    Bitmap result = Bitmap.createBitmap(mModeSize.getWidth(), mModeSize.getHeight(), Bitmap.Config.ARGB_8888);
    mImageDrawRect.set(getIntRect(mInputRect));
    adjustCanvasAndImageRect(mModeSize.getWidth(), mModeSize.getHeight());

    Canvas canvas = new Canvas(result);
    canvas.drawColor(Color.BLACK);
    drawBitmap(canvas);/*from w w w .  j  ava2s  .  c o m*/
    mLabelHandler.drawLabels(canvas, mOutputRect, new Rect(0, 0, mModeSize.getWidth(), mModeSize.getHeight()));

    return result;
}

From source file:com.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java

private void createSharableBitmap() {
    Bitmap sharableBitmap = Bitmap.createBitmap(getView().getWidth(), getView().getHeight(),
            Bitmap.Config.ARGB_8888);/*w w  w  . j ava 2 s .c o  m*/
    Canvas canvas = new Canvas(sharableBitmap);
    canvas.drawColor(ContextCompat.getColor(getContext(), R.color.white));

    // Load the view for the sharable. This will be drawn to the bitmap
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_sharable_tongue_twister, null);

    TextView textView = (TextView) layout.findViewById(R.id.twister_sharable_tongue_twister);
    textView.setText(mQuestion);

    textView = (TextView) layout.findViewById(R.id.twister_sharable_i_said);
    textView.setText(mUnderstoodText);

    textView = (TextView) layout.findViewById(R.id.mimic_twister_share_success);
    textView.setText(mSuccessMessage);

    // Perform the layout using the dimension of the bitmap
    int widthSpec = View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY);
    layout.measure(widthSpec, heightSpec);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    // Draw the generated view to canvas
    layout.draw(canvas);

    String title = getString(R.string.app_short_name) + ": " + getString(R.string.mimic_twister_name);
    mSharableUri = ShareFragment.saveShareableBitmap(getActivity(), sharableBitmap, title);
}

From source file:com.f2prateek.dfg.core.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);/* w  w w  .  j a va2s.co  m*/
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_stat_app_notification)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:com.sspai.dkjt.service.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);//w w w  . j  a va  2 s .co m
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_actionbar_logo)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:android.example.com.visualizerpreferences.AudioVisuals.VisualizerView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mBytes == null) {
        return;//from w  w  w .  j  av a  2  s  .  com
    }

    // Get the current angle all of the shapes are at
    double currentAngleRadians = calcCurrentAngle();

    // Draw the background
    canvas.drawColor(backgroundColor);

    // Draw each shape
    if (showBass) {
        mBassCircle.draw(canvas, bass, currentAngleRadians);
    }
    if (showMid) {
        mMidSquare.draw(canvas, mid, currentAngleRadians);
    }
    if (showTreble) {
        mTrebleTriangle.draw(canvas, treble, currentAngleRadians);
    }

    // Invalidate the view to immediately redraw
    invalidate();
}

From source file:com.evilduck.piano.views.instrument.PianoView.java

@Override
protected void onDraw(Canvas canvas) {
    if (isInEditMode()) {
        canvas.drawColor(Color.GRAY);
        return;//from w w w  .jav a  2s . co m
    }

    if (measurementChanged) {
        measurementChanged = false;
        keyboard.initializeInstrument(getMeasuredHeight(), getContext());

        float oldInstrumentWidth = instrumentWidth;
        instrumentWidth = keyboard.getWidth();

        float ratio = (float) instrumentWidth / oldInstrumentWidth;
        xOffset = (int) (xOffset * ratio);
    }

    int localXOffset = getOffsetInsideOfBounds();

    canvas.save();
    canvas.scale(scaleX, 1.0f);
    canvas.translate(-localXOffset, 0);

    keyboard.updateBounds(localXOffset, canvasWidth + localXOffset);
    keyboard.draw(canvas);

    if (!notesToDraw.isEmpty()) {
        keyboard.drawOverlays(notesToDraw, canvas);
    }

    canvas.restore();
}