Java Code Examples for android.graphics.Bitmap#eraseColor()

The following examples show how to use android.graphics.Bitmap#eraseColor() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private static Bitmap paint(final Bitmap image) {
    final int left = 15;
    final int top = 10;
    final int width = image.getWidth() + left;
    final int height = image.getHeight() + top;

    final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    if (bmp == null) {
        return null;
    }

    bmp.eraseColor(Color.TRANSPARENT);

    final Canvas c = new Canvas(bmp);

    final Bitmap cornerBmp = BitmapManager.getResource(R.drawable.components_thumbnail_corner);
    final Bitmap leftBmp = BitmapManager.getResource(R.drawable.components_thumbnail_left);
    final Bitmap topBmp = BitmapManager.getResource(R.drawable.components_thumbnail_top);

    c.drawBitmap(cornerBmp, null, new Rect(0, 0, left, top), null);
    c.drawBitmap(topBmp, null, new Rect(left, 0, width, top), null);
    c.drawBitmap(leftBmp, null, new Rect(0, top, left, height), null);
    c.drawBitmap(image, null, new Rect(left, top, width, height), null);

    return bmp;
}
 
Example 2
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
    Bitmap bitmap;
    if (Build.VERSION.SDK_INT < 21) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inDither = true;
        options.inPreferredConfig = config;
        options.inPurgeable = true;
        options.inSampleSize = 1;
        options.inMutable = true;
        byte[] array = jpegData.get();
        array[76] = (byte) (height >> 8);
        array[77] = (byte) (height & 0x00ff);
        array[78] = (byte) (width >> 8);
        array[79] = (byte) (width & 0x00ff);
        bitmap = BitmapFactory.decodeByteArray(array, 0, array.length, options);
        Utilities.pinBitmap(bitmap);
        bitmap.setHasAlpha(true);
        bitmap.eraseColor(0);
    } else {
        bitmap = Bitmap.createBitmap(width, height, config);
    }
    if (config == Bitmap.Config.ARGB_8888 || config == Bitmap.Config.ARGB_4444) {
        bitmap.eraseColor(Color.TRANSPARENT);
    }
    return bitmap;
}
 
Example 3
Source Project: FlyoutMenus   File: FlyoutMenuView.java    License: MIT License 6 votes vote down vote up
Bitmap createButtonShadowBitmap() {
	int shadowRadius = (int) buttonElevation * 2;
	int bitmapRadius = buttonRadius + (shadowRadius / 2);
	int bitmapSize = bitmapRadius * 2;
	Bitmap shadowBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
	shadowBitmap.eraseColor(0x0);

	int colors[] = {
			ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
			ColorUtils.setAlphaComponent(SHADOW_COLOR, 0)
	};

	float stops[] = {
			(float) (buttonRadius - (shadowRadius / 2)) / (float) bitmapRadius,
			1f
	};

	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setShader(new RadialGradient(bitmapRadius, bitmapRadius, bitmapRadius, colors, stops, Shader.TileMode.CLAMP));

	Canvas canvas = new Canvas(shadowBitmap);
	canvas.drawRect(0, 0, bitmapSize, bitmapSize, paint);

	return shadowBitmap;
}
 
Example 4
Source Project: BookReader   File: ThemeManager.java    License: Apache License 2.0 6 votes vote down vote up
public static Bitmap getThemeDrawable(int theme) {
    Bitmap bmp = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight(), Bitmap.Config.ARGB_8888);
    switch (theme) {
        case NORMAL:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_white));
            break;
        case YELLOW:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_yellow));
            break;
        case GREEN:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_green));
            break;
        case LEATHER:
            bmp = BitmapFactory.decodeResource(AppUtils.getAppContext().getResources(), R.drawable.theme_leather_bg);
            break;
        case GRAY:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_gray));
            break;
        case NIGHT:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_night));
            break;
        default:
            break;
    }
    return bmp;
}
 
Example 5
Source Project: fangzhuishushenqi   File: ThemeManager.java    License: Apache License 2.0 6 votes vote down vote up
public static Bitmap getThemeDrawable(int theme) {
    Bitmap bmp = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight(), Bitmap.Config.ARGB_8888);
    switch (theme) {
        case NORMAL:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_white));
            break;
        case YELLOW:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_yellow));
            break;
        case GREEN:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_green));
            break;
        case LEATHER:
            bmp = BitmapFactory.decodeResource(AppUtils.getAppContext().getResources(), R.drawable.theme_leather_bg);
            break;
        case GRAY:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_gray));
            break;
        case NIGHT:
            bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_night));
            break;
        default:
            break;
    }
    return bmp;
}
 
Example 6
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private Bitmap renderPdfDocument(ParcelFileDescriptor fileDescriptor, int targetSize, boolean fit) throws IOException {
    final PdfRenderer pdfRenderer = new PdfRenderer(fileDescriptor);
    final PdfRenderer.Page page = pdfRenderer.openPage(0);
    final Dimensions dimensions = scalePdfDimensions(new Dimensions(page.getHeight(), page.getWidth()), targetSize, fit);
    final Bitmap rendered = Bitmap.createBitmap(dimensions.width, dimensions.height, Bitmap.Config.ARGB_8888);
    rendered.eraseColor(0xffffffff);
    page.render(rendered, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();
    pdfRenderer.close();
    fileDescriptor.close();
    return rendered;
}
 
Example 7
Source Project: Android-Example   File: CurlPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Setter for textures.
 */
public void setTexture(Bitmap texture, int side) {
	if (texture == null) {
		texture = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
		if (side == SIDE_BACK) {
			texture.eraseColor(mColorBack);
		} else {
			texture.eraseColor(mColorFront);
		}
	}
	switch (side) {
	case SIDE_FRONT:
		if (mTextureFront != null)
			mTextureFront.recycle();
		mTextureFront = texture;
		break;
	case SIDE_BACK:
		if (mTextureBack != null)
			mTextureBack.recycle();
		mTextureBack = texture;
		break;
	case SIDE_BOTH:
		if (mTextureFront != null)
			mTextureFront.recycle();
		if (mTextureBack != null)
			mTextureBack.recycle();
		mTextureFront = mTextureBack = texture;
		break;
	}
	mTexturesChanged = true;
}
 
Example 8
Source Project: AndroidDocumentViewer   File: PageView.java    License: MIT License 5 votes vote down vote up
protected CancellableTaskDefinition<Void, Void> getUpdatePageTask(final Bitmap bm, final int sizeX, final int sizeY,
                                                                  final int patchX, final int patchY, final int patchWidth, final int patchHeight) {
    return new MuPDFCancellableTaskDefinition<Void, Void>() {
        @Override
        public Void doInBackground(Cookie cookie, Void... params) {
            // Workaround bug in Android Honeycomb 3.x, where the bitmap generation count
            // is not incremented when drawing.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB &&
                    Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                bm.eraseColor(0);
            mCore.updatePage(bm, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight, cookie);
            return null;
        }
    };
}
 
Example 9
private Bitmap loadBitmap(int width, int height, int index) {
    Bitmap b = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    b.eraseColor(0xFFFFFFFF);
    Canvas c = new Canvas(b);
    Drawable d = getResources().getDrawable(mBitmapIds[index]);

    int margin = 7;
    int border = 3;
    Rect r = new Rect(margin, margin, width - margin, height - margin);

    int imageWidth = r.width() - (border * 2);
    int imageHeight = imageWidth * d.getIntrinsicHeight()
            / d.getIntrinsicWidth();
    if (imageHeight > r.height() - (border * 2)) {
        imageHeight = r.height() - (border * 2);
        imageWidth = imageHeight * d.getIntrinsicWidth()
                / d.getIntrinsicHeight();
    }

    r.left += ((r.width() - imageWidth) / 2) - border;
    r.right = r.left + imageWidth + border + border;
    r.top += ((r.height() - imageHeight) / 2) - border;
    r.bottom = r.top + imageHeight + border + border;

    Paint p = new Paint();
    p.setColor(0xFFC0C0C0);
    c.drawRect(r, p);
    r.left += border;
    r.right -= border;
    r.top += border;
    r.bottom -= border;

    d.setBounds(r);
    d.draw(c);

    return b;
}
 
Example 10
/**
 * Creates an icon with the current content and style.
 * <p/>
 * This method is useful if a custom view has previously been set, or if text content is not
 * applicable.
 */
public Bitmap makeIcon() {
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mContainer.measure(measureSpec, measureSpec);

    int measuredWidth = mContainer.getMeasuredWidth();
    int measuredHeight = mContainer.getMeasuredHeight();

    mContainer.layout(0, 0, measuredWidth, measuredHeight);

    if (mRotation == 1 || mRotation == 3) {
        measuredHeight = mContainer.getMeasuredWidth();
        measuredWidth = mContainer.getMeasuredHeight();
    }

    Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    r.eraseColor(Color.TRANSPARENT);

    Canvas canvas = new Canvas(r);

    switch (mRotation) {
        case 0:
            // do nothing
            break;
        case 1:
            canvas.translate(measuredWidth, 0);
            canvas.rotate(90);
            break;
        case 2:
            canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
            break;
        case 3:
            canvas.translate(0, measuredHeight);
            canvas.rotate(270);
            break;
    }
    mContainer.draw(canvas);
    return r;
}
 
Example 11
private Bitmap cropCenterSquareVideo(Uri uri, int size) {
    MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
    Bitmap frame;
    try {
        metadataRetriever.setDataSource(mXmppConnectionService, uri);
        frame = metadataRetriever.getFrameAtTime(0);
        metadataRetriever.release();
        return cropCenterSquare(frame, size);
    } catch (Exception e) {
        frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        frame.eraseColor(0xff000000);
        return frame;
    }
}
 
Example 12
Source Project: fresco   File: HoneycombBitmapCreator.java    License: MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public Bitmap createNakedBitmap(int width, int height, Bitmap.Config bitmapConfig) {
  CloseableReference<PooledByteBuffer> jpgRef =
      mJpegGenerator.generate((short) width, (short) height);
  EncodedImage encodedImage = null;
  CloseableReference<byte[]> encodedBytesArrayRef = null;
  try {
    encodedImage = new EncodedImage(jpgRef);
    encodedImage.setImageFormat(DefaultImageFormats.JPEG);
    BitmapFactory.Options options =
        getBitmapFactoryOptions(encodedImage.getSampleSize(), bitmapConfig);
    int length = jpgRef.get().size();
    final PooledByteBuffer pooledByteBuffer = jpgRef.get();
    encodedBytesArrayRef = mFlexByteArrayPool.get(length + 2);
    byte[] encodedBytesArray = encodedBytesArrayRef.get();
    pooledByteBuffer.read(0, encodedBytesArray, 0, length);
    Bitmap bitmap = BitmapFactory.decodeByteArray(encodedBytesArray, 0, length, options);
    bitmap.setHasAlpha(true);
    bitmap.eraseColor(Color.TRANSPARENT);
    return bitmap;
  } finally {
    CloseableReference.closeSafely(encodedBytesArrayRef);
    EncodedImage.closeSafely(encodedImage);
    CloseableReference.closeSafely(jpgRef);
  }
}
 
Example 13
Source Project: homeassist   File: IconGenerator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates an icon with the current content and style.
 * <p/>
 * This method is useful if a custom view has previously been set, or if text content is not
 * applicable.
 */
public Bitmap makeIcon() {
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mContainer.measure(measureSpec, measureSpec);

    int measuredWidth = mContainer.getMeasuredWidth();
    int measuredHeight = mContainer.getMeasuredHeight();

    mContainer.layout(0, 0, measuredWidth, measuredHeight);

    if (mRotation == 1 || mRotation == 3) {
        measuredHeight = mContainer.getMeasuredWidth();
        measuredWidth = mContainer.getMeasuredHeight();
    }

    Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    r.eraseColor(Color.TRANSPARENT);

    Canvas canvas = new Canvas(r);

    switch (mRotation) {
        case 0:
            // do nothing
            break;
        case 1:
            canvas.translate(measuredWidth, 0);
            canvas.rotate(90);
            break;
        case 2:
            canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
            break;
        case 3:
            canvas.translate(0, measuredHeight);
            canvas.rotate(270);
            break;
    }
    mContainer.draw(canvas);
    return r;
}
 
Example 14
private Bitmap createThumbnailBitmap(ActivityClientRecord r) {
    Bitmap thumbnail = mAvailThumbnailBitmap;
    try {
        if (thumbnail == null) {
            int w = mThumbnailWidth;
            int h;
            if (w < 0) {
                Resources res = r.activity.getResources();
                mThumbnailHeight = h =
                    res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height);

                mThumbnailWidth = w =
                    res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width);
            } else {
                h = mThumbnailHeight;
            }

            // On platforms where we don't want thumbnails, set dims to (0,0)
            if ((w > 0) && (h > 0)) {
                thumbnail = Bitmap.createBitmap(w, h, THUMBNAIL_FORMAT);
                thumbnail.eraseColor(0);
            }
        }

        if (thumbnail != null) {
            Canvas cv = mThumbnailCanvas;
            if (cv == null) {
                mThumbnailCanvas = cv = new Canvas();
            }

            cv.setBitmap(thumbnail);
            if (!r.activity.onCreateThumbnail(thumbnail, cv)) {
                mAvailThumbnailBitmap = thumbnail;
                thumbnail = null;
            }
            cv.setBitmap(null);
        }

    } catch (Exception e) {
        if (!mInstrumentation.onException(r.activity, e)) {
            throw new RuntimeException(
                    "Unable to create thumbnail of "
                    + r.intent.getComponent().toShortString()
                    + ": " + e.toString(), e);
        }
        thumbnail = null;
    }

    return thumbnail;
}
 
Example 15
Source Project: HAPP   File: Notifications.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void newTemp(TempBasal basal, Context c, Realm realm){
    Log.d(TAG, "newTemp: START");
    
    String title, msg;
    Pump pump = new Pump(new Profile(new Date()), realm);
    pump.setNewTempBasal(null, basal);

    if (basal.checkIsCancelRequest()){
        title = "Set: " + basal.getBasal_adjustemnt();
        msg = pump.displayCurrentBasal(true);
    } else {
        title = "Set: " + pump.displayBasalDesc(false);
        msg = pump.displayCurrentBasal(true) + " for " + pump.temp_basal_duration + " mins";
    }

    Intent intent_accept_temp = new Intent();
    try {
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Class.forName("io.realm.TempBasalRealmProxy"), new TempBasalSerializer())
                .create();
        intent_accept_temp.putExtra("SUGGESTED_BASAL", gson.toJson(basal, TempBasal.class));
    } catch (ClassNotFoundException e){
        Log.e(TAG, "Error creating gson object: " + e.getLocalizedMessage());
    }
    intent_accept_temp.setAction(Intents.NOTIFICATION_UPDATE);
    intent_accept_temp.putExtra("NOTIFICATION_TYPE", "newTemp");
    PendingIntent pending_intent_accept_temp = PendingIntent.getBroadcast(c,1,intent_accept_temp,PendingIntent.FLAG_CANCEL_CURRENT);

    Intent intent_open_activity = new Intent(c,MainActivity.class);
    PendingIntent pending_intent_open_activity = PendingIntent.getActivity(c, 2, intent_open_activity, PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap bitmap = Bitmap.createBitmap(320, 320, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(c.getResources().getColor(R.color.secondary_text_light));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(c);
    notificationBuilder.setSmallIcon(R.drawable.exit_to_app);
    notificationBuilder.setColor(c.getResources().getColor(R.color.primary));
    notificationBuilder.extend(new NotificationCompat.WearableExtender().setBackground(bitmap));
    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(msg);
    notificationBuilder.setContentIntent(pending_intent_open_activity);
    notificationBuilder.setPriority(Notification.PRIORITY_MAX);
    notificationBuilder.setCategory(Notification.CATEGORY_ALARM);
    notificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    notificationBuilder.setVibrate(new long[]{500, 1000, 500, 500, 500, 1000, 500});
    notificationBuilder.addAction(R.drawable.exit_to_app, "Accept Temp", pending_intent_accept_temp);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (prefs.getBoolean("temp_basal_notification_make_sound", false)) {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        notificationBuilder.setSound(notification);
    }

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainApp.instance());
    notificationManager.notify(NEW_TEMP, notificationBuilder.build());

    Log.d(TAG, "newTemp: FINISH");
}
 
Example 16
Source Project: letv   File: DrawingCacheHolder.java    License: Apache License 2.0 4 votes vote down vote up
private void eraseBitmap(Bitmap bmp) {
    if (bmp != null) {
        bmp.eraseColor(0);
    }
}
 
Example 17
@Override
public void erase(Bitmap bitmapBuffer) {
    bitmapBuffer.eraseColor(backgroundColour);
}
 
Example 18
private void eraseBitmap(Bitmap bmp) {
    if (bmp != null) {
        bmp.eraseColor(Color.TRANSPARENT);
    }
}
 
Example 19
private void adjustLineColor() {

        int linewith = ivLineColor.getWidth();
        int linehight = ivLineColor.getHeight();
        Bitmap bitmapline = Bitmap.createBitmap(linewith, linehight, Bitmap.Config.ARGB_8888);
        bitmapline.eraseColor(Color.BLACK);
        ivLineColor.setImageBitmap(bitmapline);
        Canvas canvasline = new Canvas(bitmapline);
        Paint mPaint = new Paint();
        mPaint.setStrokeWidth(1);

        int index = 0;
        mHueBarColors = new int[linehight];
        for (int i = 0; i < linehight; i++)
            mHueBarColors[i] = Color.BLACK;

        float counter = 256 / ((linehight) / 7);

        try {
            for (float i = 0; i < 256; i += counter) // Red (#f00) to pink  (#f0f)
            {
                mHueBarColors[index] = Color.rgb(255, 0, (int) i);
                index++;
            }
            for (float i = 0; i < 256; i += counter) // Pink (#f0f) to blue  (#00f)

            {
                mHueBarColors[index] = Color.rgb(255 - (int) i, 0, 255);
                index++;
            }
            for (float i = 0; i < 256; i += counter) // Blue (#00f) to light  blue (#0ff)

            {
                mHueBarColors[index] = Color.rgb(0, (int) i, 255);
                index++;
            }
            for (float i = 0; i < 256; i += counter) // Light blue (#0ff) to  green (#0f0)

            {
                mHueBarColors[index] = Color.rgb(0, 255, 255 - (int) i);
                index++;
            }
            for (float i = 0; i < 256; i += counter) // Green (#0f0) to yellow   (#ff0)

            {
                mHueBarColors[index] = Color.rgb((int) i, 255, 0);
                index++;
            }
            for (float i = 0; i < 256; i += counter) // Yellow (#ff0) to red  (#f00)

            {
                mHueBarColors[index] = Color.rgb(255, 255 - (int) i, 0);
                index++;
            }

            if (index < linehight) {
                for (float i = 0; index < linehight; i += counter) // Yellow (#ff0) to red  (#f00)

                {
                    mHueBarColors[index] = Color.rgb(255 - (int) i, (int) i, (int) i);
                    index++;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (int i = 0; i < linehight; i++) {

            mPaint.setColor(mHueBarColors[i]);

            canvasline.drawLine(0, i, linewith, i, mPaint);
        }
    }
 
Example 20
Source Project: homeassist   File: EntityWidgetProvider.java    License: Apache License 2.0 4 votes vote down vote up
public static void updateEntityWidget(Context context, Widget widget) {
    Log.d("YouQi", "Widget updateEntityWidget: " + CommonUtil.deflate(widget));
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    String iconText = widget.getMdiIcon(); //MDIFont.getIcon("mdi:weather-hail");
    int iconColor = ResourcesCompat.getColor(context.getResources(), (widget.isToggleable() && !widget.isCurrentStateActive()) ? R.color.md_grey_500 : R.color.xiaomiPrimaryTextSelected, null);

    Bitmap myBitmap = Bitmap.createBitmap(160, 160, Bitmap.Config.ARGB_8888);
    myBitmap.eraseColor(Color.TRANSPARENT);

    Typeface typeface = ResourcesCompat.getFont(context, R.font.mdi);
    Paint paint = new Paint();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setAntiAlias(true);
    paint.setTypeface(typeface);
    paint.setColor(iconColor);
    paint.setTextSize(160);
    //paint.setStrokeWidth(24); // Text Size
    //setTextSizeForWidth(paint, 48, iconText);
    //paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern

    Canvas canvas = new Canvas(myBitmap);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
    int xPos = (canvas.getWidth() - yPos) / 2;//(canvas.getWidth() / 2);
    canvas.drawText(iconText, 0, yPos, paint);

    RemoteViews remoteViews = new RemoteViews("com.axzae.homeassistant", R.layout.widget_entity);
    remoteViews.setImageViewBitmap(R.id.image_icon, myBitmap);
    remoteViews.setTextViewText(R.id.text_state, widget.getFriendlyStateRow());
    remoteViews.setTextColor(R.id.text_state, iconColor);
    remoteViews.setTextViewText(R.id.text_group, widget.getFriendlyName());

    //https://stackoverflow.com/questions/21311917/onreceive-will-always-receive-the-last-appwidgetid-even-different-instance-widg
    Intent newIntent = new Intent(context, EntityWidgetProvider.class);
    newIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    newIntent.putExtra("appWidgetId", widget.appWidgetId);
    newIntent.putExtra("widget", CommonUtil.deflate(widget));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, widget.appWidgetId, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.item, pendingIntent);
    appWidgetManager.updateAppWidget(widget.appWidgetId, remoteViews);
    Log.d("YouQi", "appWidgetManager updating (" + widget.appWidgetId + "): " + widget.getFriendlyState());
}