Java Code Examples for android.graphics.Paint.setTextSize()
The following are Jave code examples for showing how to use
setTextSize() of the
android.graphics.Paint
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: efficientclock File: EfficientClock.java View Source Code | 6 votes |
private void initPaint(){ mRingPaint = new Paint(); mRingPaint.setStyle(Paint.Style.FILL); mRingPaint.setAntiAlias(true); mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setAntiAlias(true); mLinePaint.setColor(Color.WHITE); mLinePaint.setStrokeWidth(4); mTextPaint = new Paint(); mTextPaint.setTextSize(40); mTextPaint.setColor(Color.BLACK); mTextPaint.setAntiAlias(true); mTextPaint.setTextAlign(Paint.Align.CENTER); fontMetrics = mTextPaint.getFontMetrics(); mDownTextPaint = new Paint(); mDownTextPaint.setTextSize(80); mDownTextPaint.setColor(Color.parseColor("#ff9933")); mDownTextPaint.setAntiAlias(true); mDownTextPaint.setTextAlign(Paint.Align.CENTER); mDownTextPaint.setStrokeWidth(10); mDownTextPaint.setStrokeCap(Paint.Cap.ROUND); }
Example 2
Project: IndicatorSeekBar File: CircleBubbleView.java View Source Code | 6 votes |
private void init(String maxLengthText) { mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(1); mPaint.setTextAlign(Paint.Align.CENTER); mPaint.setTextSize(mIndicatorTextSize); Rect mRect = new Rect(); mPaint.getTextBounds(maxLengthText, 0, maxLengthText.length(), mRect); mIndicatorWidth = mRect.width() + IndicatorUtils.dp2px(mContext, 4); int minWidth = IndicatorUtils.dp2px(mContext, 36); if (mIndicatorWidth < minWidth) { mIndicatorWidth = minWidth; } mTextHeight = mRect.height(); mIndicatorHeight = mIndicatorWidth * 1.2f; initPath(); }
Example 3
Project: JBase File: CodeImgUtils.java View Source Code | 6 votes |
private Bitmap createBitmap() { padding_left = 0; Bitmap bp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bp); code = createCode(); c.drawColor(Color.rgb(DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_COLOR)); Paint paint = new Paint(); paint.setTextSize(font_size); for (int i = 0; i < code.length(); i++) { randomTextStyle(paint); randomPadding(); c.drawText(code.charAt(i) + "", padding_left, padding_top, paint); } for (int i = 0; i < line_number; i++) { drawLine(c, paint); } c.save(Canvas.ALL_SAVE_FLAG);// 保存 c.restore();// return bp; }
Example 4
Project: Rxjava2.0Demo File: DrawTextView.java View Source Code | 6 votes |
private void initPaint() { DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, dm); mPaint = new Paint(); mPaint.setColor(Color.RED); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(1); mPaint.setTextSize(35); mPaint.setColorFilter(new ColorFilter()); // mPaint.setStyle(Paint.Style.STROKE); mPath = new Path(); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bg1); bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.bg2); bitmapShader1 = new BitmapShader(bitmap1, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); shader = new ComposeShader(bitmapShader, bitmapShader1, PorterDuff.Mode.SRC_OVER); }
Example 5
Project: tuxguitar File: TGPopwindowView.java View Source Code | 5 votes |
private void init() { paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); paint.setTextSize(48.0f); paint.setTextAlign(Paint.Align.CENTER); }
Example 6
Project: opencv-documentscanner-android File: FpsMeter.java View Source Code | 5 votes |
public void init() { mFramesCouner = 0; mFrequency = Core.getTickFrequency(); mprevFrameTime = Core.getTickCount(); mStrfps = ""; mPaint = new Paint(); mPaint.setColor(Color.BLUE); mPaint.setTextSize(20); }
Example 7
Project: Weather-Android File: AbstractWidgetProvider.java View Source Code | 5 votes |
protected Bitmap getWeatherIcon(String text, Context context) { Bitmap myBitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = new Paint(); Typeface clock = Typeface.createFromAsset(context.getAssets(), "fonts/weather.ttf"); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(clock); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setTextSize(150); paint.setTextAlign(Paint.Align.CENTER); myCanvas.drawText(text, 128, 180, paint); return myBitmap; }
Example 8
Project: GitHub File: BaseUtils.java View Source Code | 5 votes |
public static Paint getPaint(Paint.Style style, int color) { Paint mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStyle(style); mPaint.setColor(color); mPaint.setTextSize(30); return mPaint; }
Example 9
Project: RLibrary File: ImageUtils.java View Source Code | 5 votes |
/** * 添加文字水印 * * @param src 源图片 * @param content 水印文本 * @param textSize 水印字体大小 * @param color 水印字体颜色 * @param x 起始坐标x * @param y 起始坐标y * @param recycle 是否回收 * @return 带有文字水印的图片 */ public static Bitmap addTextWatermark(Bitmap src, String content, float textSize, int color, float x, float y, boolean recycle) { if (isEmptyBitmap(src) || content == null) return null; Bitmap ret = src.copy(src.getConfig(), true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Canvas canvas = new Canvas(ret); paint.setColor(color); paint.setTextSize(textSize); Rect bounds = new Rect(); paint.getTextBounds(content, 0, content.length(), bounds); canvas.drawText(content, x, y + textSize, paint); if (recycle && !src.isRecycled()) src.recycle(); return ret; }
Example 10
Project: XERUNG File: BadgeDrawable.java View Source Code | 5 votes |
public BadgeDrawable(Context context) { mTextSize = 15F; myColor = context.getResources().getColor(R.color.theme_primary_dark_badge); mBadgePaint = new Paint(); mBadgePaint.setColor(myColor); mBadgePaint.setAntiAlias(true); mBadgePaint.setStyle(Paint.Style.FILL); mTextPaint = new Paint(); mTextPaint.setColor(Color.YELLOW); mTextPaint.setTypeface(Typeface.DEFAULT_BOLD); mTextPaint.setTextSize(mTextSize); mTextPaint.setAntiAlias(true); mTextPaint.setTextAlign(Paint.Align.CENTER); }
Example 11
Project: android-project-gallery File: ViewUtils.java View Source Code | 5 votes |
/** * 返回字体高度 * * @param textSize * @return */ public static int getFontHeight(float textSize) { Paint paint = new Paint(); paint.setTextSize(textSize); FontMetrics fm = paint.getFontMetrics(); return (int) Math.ceil(fm.descent - fm.top) + 2; }
Example 12
Project: Android-Code-Demos File: ThirdBezierView.java View Source Code | 5 votes |
public ThirdBezierView(Context context, AttributeSet attrs) { super(context, attrs); mPaintBezier = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintBezier.setStrokeWidth(8); mPaintBezier.setStyle(Paint.Style.STROKE); mPaintFlag = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintBezier.setStrokeWidth(3); mPaintBezier.setStyle(Paint.Style.STROKE); mPaintFlagText = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintFlagText.setStyle(Paint.Style.STROKE); mPaintFlagText.setTextSize(20); }
Example 13
Project: microMathematics File: ColorMapView.java View Source Code | 5 votes |
private void drawVerticalBar(Canvas c, Paint p) { p.setTextSize(getTextSize()); p.getTextBounds(COLOR_BAR_WIDTH_PATTERN, 0, COLOR_BAR_WIDTH_PATTERN.length(), tmpRect); final int yMin = Math.min(rect.top, rect.bottom); final int yMax = Math.max(rect.top, rect.bottom); minMaxValues[FunctionIf.MIN] = yMin; minMaxValues[FunctionIf.MAX] = yMax; for (int y = yMin; y < yMax; y++) { p.setColor(getPaletteColor(y, minMaxValues, 255)); final int yl = yMax - (y - yMin); c.drawLine(rect.left, yl, rect.left + tmpRect.width() - 1, yl, p); } }
Example 14
Project: PasscodeView File: BoxTitle.java View Source Code | 5 votes |
@Override void preparePaint() { //Set title paint mTitlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTitlePaint.setColor(mTitleColor); mTitlePaint.setTextAlign(Paint.Align.CENTER); mTitlePaint.setTextSize(getContext().getResources().getDimension(R.dimen.lib_title_text_size)); }
Example 15
Project: DailyStudy File: IndexView.java View Source Code | 5 votes |
private void init(Context context) { float unit = context.getResources().getDisplayMetrics().density; paint = new Paint(); paint.setColor(Color.WHITE);//设置颜色 paint.setAntiAlias(true);//设置抗锯齿 paint.setTypeface(Typeface.DEFAULT_BOLD);//设置粗体字 paint.setTextSize(14 * unit); Log.e(TAG, 14 * unit + "................"); wordsList = Arrays.asList(words); }
Example 16
Project: FakeWeather File: SimplePagerIndicator.java View Source Code | 5 votes |
public SimplePagerIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); titles = new ArrayList<>(); textSize = SizeUtils.sp2px(context, 18); roundRadius = 5; roundPaint = new Paint(); roundPaint.setStyle(Paint.Style.FILL_AND_STROKE); roundPaint.setStrokeWidth(2); roundPaint.setColor(Color.WHITE); roundPaint.setAntiAlias(true); roundPaint.setAlpha(100); selectedRoundPaint = new Paint(); selectedRoundPaint.setStyle(Paint.Style.FILL_AND_STROKE); selectedRoundPaint.setStrokeWidth(2); selectedRoundPaint.setColor(Color.WHITE); selectedRoundPaint.setAntiAlias(true); textPaint = new Paint(); textPaint.setStrokeWidth(0); textPaint.setAntiAlias(true); textPaint.setColor(Color.WHITE); textPaint.setTextSize(textSize); textPaint.setTextAlign(Paint.Align.CENTER); }
Example 17
Project: Markwon File: SpannableTheme.java View Source Code | 4 votes |
public void applyHeadingTextStyle(@NonNull Paint paint, @IntRange(from = 1, to = 6) int level) { paint.setFakeBoldText(true); paint.setTextSize(paint.getTextSize() * HEADING_SIZES[level - 1]); }
Example 18
Project: buildAPKsApps File: AbstractChart.java View Source Code | 4 votes |
/** * Draws the chart legend. * * @param canvas the canvas to paint to * @param renderer the series renderer * @param titles the titles to go to the legend * @param left the left X value of the area to draw to * @param right the right X value of the area to draw to * @param y the y value of the area to draw to * @param width the width of the area to draw to * @param height the height of the area to draw to * @param legendSize the legend size * @param paint the paint to be used for drawing * @param calculate if only calculating the legend size * * @return the legend height */ protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate) { float size = 32; if (renderer.isShowLegend()) { float currentX = left; float currentY = y + height - legendSize + size; paint.setTextAlign(Align.LEFT); paint.setTextSize(renderer.getLegendTextSize()); int sLength = Math.min(titles.length, renderer.getSeriesRendererCount()); for (int i = 0; i < sLength; i++) { SimpleSeriesRenderer r = renderer.getSeriesRendererAt(i); final float lineSize = getLegendShapeWidth(i); if (r.isShowLegendItem()) { String text = titles[i]; if (titles.length == renderer.getSeriesRendererCount()) { paint.setColor(r.getColor()); } else { paint.setColor(Color.LTGRAY); } float[] widths = new float[text.length()]; paint.getTextWidths(text, widths); float sum = 0; for (float value : widths) { sum += value; } float extraSize = lineSize + 10 + sum; float currentWidth = currentX + extraSize; if (i > 0 && getExceed(currentWidth, renderer, right, width)) { currentX = left; currentY += renderer.getLegendTextSize(); size += renderer.getLegendTextSize(); currentWidth = currentX + extraSize; } if (getExceed(currentWidth, renderer, right, width)) { float maxWidth = right - currentX - lineSize - 10; if (isVertical(renderer)) { maxWidth = width - currentX - lineSize - 10; } int nr = paint.breakText(text, true, maxWidth, widths); text = text.substring(0, nr) + "..."; } if (!calculate) { drawLegendShape(canvas, r, currentX, currentY, i, paint); drawString(canvas, text, currentX + lineSize + 5, currentY + 5, paint); } currentX += extraSize; } } } return Math.round(size + renderer.getLegendTextSize()); }
Example 19
Project: Ec2m File: WheelPicker_New.java View Source Code | 4 votes |
public WheelPicker_New(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelPicker); int idData = a.getResourceId(R.styleable.WheelPicker_wheel_data, 0); mData = Arrays.asList(getResources() .getStringArray(idData == 0 ? R.array.WheelArrayDefault : idData)); mItemTextSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_item_text_size, getResources().getDimensionPixelSize(R.dimen.WheelItemTextSize)); mVisibleItemCount = a.getInt(R.styleable.WheelPicker_wheel_visible_item_count, 7); mSelectedItemPosition = a.getInt(R.styleable.WheelPicker_wheel_selected_item_position, 0); hasSameWidth = a.getBoolean(R.styleable.WheelPicker_wheel_same_width, false); mTextMaxWidthPosition = a.getInt(R.styleable.WheelPicker_wheel_maximum_width_text_position, -1); mMaxWidthText = a.getString(R.styleable.WheelPicker_wheel_maximum_width_text); mSelectedItemTextColor = a.getColor (R.styleable.WheelPicker_wheel_selected_item_text_color, -1); mItemTextColor = a.getColor(R.styleable.WheelPicker_wheel_item_text_color, 0xFF888888); mItemSpace = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_item_space, getResources().getDimensionPixelSize(R.dimen.WheelItemSpace)); isCyclic = a.getBoolean(R.styleable.WheelPicker_wheel_cyclic, false); hasIndicator = a.getBoolean(R.styleable.WheelPicker_wheel_indicator, false); mIndicatorColor = a.getColor(R.styleable.WheelPicker_wheel_indicator_color, 0xFFEE3333); mIndicatorSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_indicator_size, getResources().getDimensionPixelSize(R.dimen.WheelIndicatorSize)); hasCurtain = a.getBoolean(R.styleable.WheelPicker_wheel_curtain, false); mCurtainColor = a.getColor(R.styleable.WheelPicker_wheel_curtain_color, 0x88FFFFFF); hasAtmospheric = a.getBoolean(R.styleable.WheelPicker_wheel_atmospheric, false); isCurved = a.getBoolean(R.styleable.WheelPicker_wheel_curved, false); mItemAlign = a.getInt(R.styleable.WheelPicker_wheel_item_align, ALIGN_CENTER); a.recycle(); // 可见数据项改变后更新与之相关的参数 // Update relevant parameters when the count of visible item changed updateVisibleItemCount(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG); mPaint.setTextSize(mItemTextSize); // 更新文本对齐方式 // Update alignment of text updateItemTextAlign(); // 计算文本尺寸 // Correct sizes of text computeTextSize(); mScroller = new Scroller(getContext()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) { ViewConfiguration conf = ViewConfiguration.get(getContext()); mMinimumVelocity = conf.getScaledMinimumFlingVelocity(); mMaximumVelocity = conf.getScaledMaximumFlingVelocity(); mTouchSlop = conf.getScaledTouchSlop(); } mRectDrawn = new Rect(); mRectIndicatorHead = new Rect(); mRectIndicatorFoot = new Rect(); mRectCurrentItem = new Rect(); mCamera = new Camera(); mMatrixRotate = new Matrix(); mMatrixDepth = new Matrix(); }
Example 20
Project: GitHub File: CircleProgressBar.java View Source Code | 4 votes |
private void init(Context context, AttributeSet attrs, int defStyleAttr) { final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.CircleProgressBar, defStyleAttr, 0); // <attr name="mlpb_inner_radius" format="dimension"/> // <attr name="mlpb_background_color" format="color"/> // <attr name="mlpb_progress_color" format="color"/> // <attr name="mlpb_progress_stoke_width" format="dimension"/> // <attr name="mlpb_arrow_width" format="dimension"/> // <attr name="mlpb_arrow_height" format="dimension"/> // // <attr name="mlpb_progress" format="integer"/> // <attr name="mlpb_max" format="integer"/> // // // <attr name="mlpb_progress_text_size" format="dimension"/> // <attr name="mlpb_progress_text_color" format="color"/> // // <attr name="mlpb_progress_text_offset" format="dimension"/> // // <attr name="mlpb_progress_text_visibility" format="enum"> // <enum name="visible" value="0"/> // <enum name="invisible" value="1"/> // </attr> final float density = getContext().getResources().getDisplayMetrics().density; mBackGroundColor = a.getColor( R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT); mProgressColor = a.getColor( R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT); mColors = new int[]{mProgressColor}; mInnerRadius = a.getDimensionPixelOffset( R.styleable.CircleProgressBar_mlpb_inner_radius, -1); mProgressStokeWidth = a.getDimensionPixelOffset( R.styleable.CircleProgressBar_mlpb_progress_stoke_width, (int) (STROKE_WIDTH_LARGE * density)); mArrowWidth = a.getDimensionPixelOffset( R.styleable.CircleProgressBar_mlpb_arrow_width, -1); mArrowHeight = a.getDimensionPixelOffset( R.styleable.CircleProgressBar_mlpb_arrow_height, -1); mTextSize = a.getDimensionPixelOffset( R.styleable.CircleProgressBar_mlpb_progress_text_size, (int) (DEFAULT_TEXT_SIZE * density)); mTextColor = a.getColor( R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK); mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false); mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true); mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0); mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100); int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1); if (textVisible != 1) { mIfDrawText = true; } mTextPaint = new Paint(); mTextPaint.setStyle(Paint.Style.FILL); mTextPaint.setColor(mTextColor); mTextPaint.setTextSize(mTextSize); mTextPaint.setAntiAlias(true); a.recycle(); mProgressDrawable = new MaterialProgressDrawable(getContext(), this); super.setImageDrawable(mProgressDrawable); }