List of usage examples for android.text TextPaint setColor
public void setColor(@ColorInt int color)
From source file:com.lloydtorres.stately.helpers.links.NameListSpan.java
@Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false);//from w w w .j av a 2s. co m ds.setColor(RaraHelper.getThemeLinkColour(context)); }
From source file:se.attentec.attenhome.TypefaceSpan.java
@Override public void updateMeasureState(TextPaint p) { p.setTypeface(mTypeface);/*from www .jav a 2 s.c o m*/ p.setTextSize(mTextSize); p.setColor(mColor); // Note: This flag is required for proper typeface rendering p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); }
From source file:se.attentec.attenhome.TypefaceSpan.java
@Override public void updateDrawState(TextPaint tp) { tp.setTypeface(mTypeface);/*from ww w. j a va 2 s . co m*/ tp.setTextSize(mTextSize); tp.setColor(mColor); // Note: This flag is required for proper typeface rendering tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); }
From source file:com.grarak.kerneladiutor.elements.SplashView.java
private void draw(Canvas canvas, int x, int y, int radius) { if (radius > 0) canvas.drawCircle(x / 2, y / 2, radius, mPaintCircle); matrix.postRotate(rotate);/* w w w . j a v a 2 s . co m*/ Bitmap iconRotate = Bitmap.createBitmap(icon, 0, 0, icon.getWidth(), icon.getHeight(), matrix, false); canvas.drawBitmap(iconRotate, x / 2 - iconRotate.getWidth() / 2, y / 2 - iconRotate.getHeight() / 2, mPaintCircle); TextPaint textPaint = new TextPaint(); textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); textPaint.setColor(textColor); textPaint.setAntiAlias(true); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextSize(textSize); float textHeight = textPaint.descent() - textPaint.ascent(); float textOffset = (textHeight / 2) - textPaint.descent(); canvas.drawText(getResources().getString(R.string.root_waiting), x / 2, y - textOffset - y / 4, textPaint); }
From source file:com.mobisci_lab.virtualkeyboard.softkeyboard.LatinKeyboardView.java
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); TextPaint paint = new TextPaint(); paint.setAntiAlias(true);/* www . j a va 2s . c o m*/ paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); paint.setTextSize(11 * getResources().getDisplayMetrics().density); paint.setColor(ContextCompat.getColor(this.getContext(), R.color.candidate_other)); List<Key> keys = getKeyboard().getKeys(); for (Key key : keys) { float x = key.x + key.width / 2 + key.width / 5; float y = key.y + key.width / 2; String text = ""; switch (key.codes[0]) { case 113: text = "1"; break; case 119: text = "2"; break; case 101: text = "3"; break; case 114: text = "4"; break; case 116: text = "5"; break; case 121: text = "6"; break; case 117: text = "7"; break; case 105: text = "8"; break; case 111: text = "9"; break; case 112: text = "0"; break; } canvas.drawText(text, x, y, paint); } }
From source file:com.raspi.chatapp.util.Notification.java
private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) { Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); RectF mInnerRectF = new RectF(); mInnerRectF.set(0, 0, width, width); mInnerRectF.offset(0, 0);/* w w w . j a v a 2 s . c o m*/ Paint mBgPaint = new Paint(); mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mBgPaint.setStyle(Paint.Style.FILL); mBgPaint.setColor(bgColor); TextPaint mTitleTextPaint = new TextPaint(); mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); mTitleTextPaint.setTextAlign(Paint.Align.CENTER); mTitleTextPaint.setLinearText(true); mTitleTextPaint.setColor(Color.WHITE); mTitleTextPaint.setTextSize(width * 0.8f); float centerX = mInnerRectF.centerX(); float centerY = mInnerRectF.centerY(); int xPos = (int) centerX; int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2); if (round) c.drawOval(mInnerRectF, mBgPaint); else c.drawRect(mInnerRectF, mBgPaint); c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint); return b; }
From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java
/** * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone * number, and if there is a photo also adds the call action icon. *//*from w w w . j av a 2s.c om*/ private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) { final Resources r = mContext.getResources(); final float density = r.getDisplayMetrics().density; Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap(); Bitmap icon = generateQuickContactIcon(photo); Canvas canvas = new Canvas(icon); // Copy in the photo Paint photoPaint = new Paint(); photoPaint.setDither(true); photoPaint.setFilterBitmap(true); Rect dst = new Rect(0, 0, mIconSize, mIconSize); // Create an overlay for the phone number type CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel); if (overlay != null) { TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size)); textPaint.setColor(ContextCompat.getColor(mContext, R.color.textColorIconOverlay)); textPaint.setShadowLayer(4f, 0, 2f, ContextCompat.getColor(mContext, R.color.textColorIconOverlayShadow)); final FontMetricsInt fmi = textPaint.getFontMetricsInt(); // First fill in a darker background around the text to be drawn final Paint workPaint = new Paint(); workPaint.setColor(mOverlayTextBackgroundColor); workPaint.setStyle(Paint.Style.FILL); final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding); final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2; dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize); canvas.drawRect(dst, workPaint); overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END); final float textWidth = textPaint.measureText(overlay, 0, overlay.length()); canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2, mIconSize - fmi.descent - textPadding, textPaint); } // Draw the phone action icon as an overlay Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight()); int iconWidth = icon.getWidth(); dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density))); canvas.drawBitmap(phoneIcon, src, dst, photoPaint); canvas.setBitmap(null); return icon; }
From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java
/** * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone * number, and if there is a photo also adds the call action icon. *//*from www . ja v a2 s . com*/ private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) { final Resources r = mContext.getResources(); final float density = r.getDisplayMetrics().density; Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap(); Bitmap icon = generateQuickContactIcon(photo); Canvas canvas = new Canvas(icon); // Copy in the photo Paint photoPaint = new Paint(); photoPaint.setDither(true); photoPaint.setFilterBitmap(true); Rect dst = new Rect(0, 0, mIconSize, mIconSize); // Create an overlay for the phone number type CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel); if (overlay != null) { TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size)); textPaint.setColor(r.getColor(R.color.textColorIconOverlay)); textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow)); final FontMetricsInt fmi = textPaint.getFontMetricsInt(); // First fill in a darker background around the text to be drawn final Paint workPaint = new Paint(); workPaint.setColor(mOverlayTextBackgroundColor); workPaint.setStyle(Paint.Style.FILL); final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding); final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2; dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize); canvas.drawRect(dst, workPaint); overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END); final float textWidth = textPaint.measureText(overlay, 0, overlay.length()); canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2, mIconSize - fmi.descent - textPadding, textPaint); } // Draw the phone action icon as an overlay Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight()); int iconWidth = icon.getWidth(); dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density))); canvas.drawBitmap(phoneIcon, src, dst, photoPaint); canvas.setBitmap(null); return icon; }
From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
private Bitmap createMarkerIcon(Drawable backgroundImage, String text, int width, int height) { Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // Create a canvas, that will draw on to canvasBitmap. Canvas imageCanvas = new Canvas(canvasBitmap); // Draw the image to our canvas backgroundImage.draw(imageCanvas);//from w w w. jav a2 s.c o m // Set up the paint for use with our Canvas TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | TextPaint.LINEAR_TEXT_FLAG); textPaint.setTextAlign(TextPaint.Align.CENTER); textPaint.setTypeface(Typeface.DEFAULT); textPaint.setTextSize(100f); textPaint.setColor(context.getResources().getColor(android.R.color.white)); int xPos = (imageCanvas.getWidth() / 2); int yPos = (int) ((imageCanvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)); Rect r = new Rect(); textPaint.getTextBounds(text, 0, text.length(), r); // yPos += (Math.abs(r.height()))/2; // Draw the text on top of our image imageCanvas.drawText(text, xPos, yPos, textPaint); // Combine background and text to a LayerDrawable LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { backgroundImage, new BitmapDrawable(canvasBitmap) }); Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); layerDrawable.setBounds(0, 0, width, height); layerDrawable.draw(new Canvas(newBitmap)); return newBitmap; }
From source file:com.todoroo.astrid.actfm.ActFmLoginActivity.java
protected SpannableString getLinkStringWithCustomInterval(String base, String linkComponent, int start, int endOffset, final OnClickListener listener) { SpannableString link = new SpannableString(String.format("%s %s", //$NON-NLS-1$ base, linkComponent));/*from w w w . ja va 2 s.co m*/ ClickableSpan linkSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onClick(widget); } @Override public void updateDrawState(TextPaint ds) { ds.setUnderlineText(true); ds.setColor(Color.rgb(68, 68, 68)); } }; link.setSpan(linkSpan, start, link.length() + endOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return link; }