Java Code Examples for android.graphics.Paint#setTextScaleX()
The following examples show how to use
android.graphics.Paint#setTextScaleX() .
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 check out the related API usage on the sidebar.
Example 1
Source File: MainKeyboardView.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) { final int maxTextWidth = width - mLanguageOnSpacebarHorizontalMargin * 2; paint.setTextScaleX(1.0f); final float textWidth = TypefaceUtils.getStringWidth(text, paint); if (textWidth < width) { return true; } final float scaleX = maxTextWidth / textWidth; if (scaleX < MINIMUM_XSCALE_OF_LANGUAGE_NAME) { return false; } paint.setTextScaleX(scaleX); return TypefaceUtils.getStringWidth(text, paint) < maxTextWidth; }
Example 2
Source File: MainKeyboardView.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) { final int maxTextWidth = width - mLanguageOnSpacebarHorizontalMargin * 2; paint.setTextScaleX(1.0f); final float textWidth = TypefaceUtils.getStringWidth(text, paint); if (textWidth < width) { return true; } final float scaleX = maxTextWidth / textWidth; if (scaleX < MINIMUM_XSCALE_OF_LANGUAGE_NAME) { return false; } paint.setTextScaleX(scaleX); return TypefaceUtils.getStringWidth(text, paint) < maxTextWidth; }
Example 3
Source File: WheelView.java From Android-PickerView with Apache License 2.0 | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setColor(textColorOut); paintOuterText.setAntiAlias(true); paintOuterText.setTypeface(typeface); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setColor(textColorCenter); paintCenterText.setAntiAlias(true); paintCenterText.setTextScaleX(1.1F); paintCenterText.setTypeface(typeface); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setColor(dividerColor); paintIndicator.setAntiAlias(true); setLayerType(LAYER_TYPE_SOFTWARE, null); }
Example 4
Source File: WheelView.java From AndroidPicker with MIT License | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setAntiAlias(true); paintOuterText.setColor(textColorOuter); paintOuterText.setTypeface(typeface); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setAntiAlias(true); paintCenterText.setColor(textColorCenter); paintCenterText.setTextScaleX(1.0F); paintCenterText.setTypeface(typeface); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setAntiAlias(true); paintIndicator.setColor(dividerConfig.color); paintIndicator.setStrokeWidth(dividerConfig.thick); paintIndicator.setAlpha(dividerConfig.alpha); paintShadow = new Paint(); paintShadow.setAntiAlias(true); paintShadow.setColor(dividerConfig.shadowColor); paintShadow.setAlpha(dividerConfig.shadowAlpha); setLayerType(LAYER_TYPE_SOFTWARE, null); }
Example 5
Source File: WheelView.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setColor(textColorOut); paintOuterText.setAntiAlias(true); paintOuterText.setTypeface(Typeface.MONOSPACE); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setColor(textColorCenter); paintCenterText.setAntiAlias(true); paintCenterText.setTextScaleX(1.1F); paintCenterText.setTypeface(Typeface.MONOSPACE); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setColor(dividerColor); paintIndicator.setAntiAlias(true); if (android.os.Build.VERSION.SDK_INT >= 11) { setLayerType(LAYER_TYPE_SOFTWARE, null); } }
Example 6
Source File: WheelView.java From Android-PickerDialog with Apache License 2.0 | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setColor(textColorOut); paintOuterText.setAntiAlias(true); paintOuterText.setTypeface(Typeface.MONOSPACE); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setColor(textColorCenter); paintCenterText.setAntiAlias(true); paintCenterText.setTextScaleX(1.1F); paintCenterText.setTypeface(Typeface.MONOSPACE); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setColor(dividerColor); paintIndicator.setAntiAlias(true); if (android.os.Build.VERSION.SDK_INT >= 11) { setLayerType(LAYER_TYPE_SOFTWARE, null); } }
Example 7
Source File: MainKeyboardView.java From openboard with GNU General Public License v3.0 | 6 votes |
private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) { final int maxTextWidth = width - mLanguageOnSpacebarHorizontalMargin * 2; paint.setTextScaleX(1.0f); final float textWidth = TypefaceUtils.getStringWidth(text, paint); if (textWidth < width) { return true; } final float scaleX = maxTextWidth / textWidth; if (scaleX < MINIMUM_XSCALE_OF_LANGUAGE_NAME) { return false; } paint.setTextScaleX(scaleX); return TypefaceUtils.getStringWidth(text, paint) < maxTextWidth; }
Example 8
Source File: WheelView.java From Android-PickerView with Apache License 2.0 | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setColor(textColorOut); paintOuterText.setAntiAlias(true); paintOuterText.setTypeface(typeface); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setColor(textColorCenter); paintCenterText.setAntiAlias(true); paintCenterText.setTextScaleX(1.1F); paintCenterText.setTypeface(typeface); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setColor(dividerColor); paintIndicator.setAntiAlias(true); setLayerType(LAYER_TYPE_SOFTWARE, null); }
Example 9
Source File: WheelView.java From AndroidFrame with Apache License 2.0 | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setColor(textColorOut); paintOuterText.setAntiAlias(true); paintOuterText.setTypeface(typeface); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setColor(textColorCenter); paintCenterText.setAntiAlias(true); paintCenterText.setTextScaleX(1.1F); paintCenterText.setTypeface(typeface); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setColor(dividerColor); paintIndicator.setAntiAlias(true); if (android.os.Build.VERSION.SDK_INT >= 11) { setLayerType(LAYER_TYPE_SOFTWARE, null); } }
Example 10
Source File: MainDraw.java From kAndroid with Apache License 2.0 | 6 votes |
@Override public void drawMaxAndMin(@NonNull BaseKChartView view, Canvas canvas, float maxX, float minX, ICandle maxPoint, ICandle minPoint) { float high = view.getMainY(maxPoint.getHighPrice()); float low = view.getMainY(minPoint.getLowPrice()); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.GRAY); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(view.getTextSize()); float aa = view.getSclase(); if (aa < 1.5) { paint.setTextScaleX((2.0f - aa)); } else { paint.setTextScaleX(0.5f); } Paint.FontMetrics fm = paint.getFontMetrics(); float textHeight = fm.descent - fm.ascent; float baseLine = (textHeight - fm.bottom - fm.top) / 2; float paddingTop = DensityUtil.dp2px( 8);//距顶 float paddingBottom = DensityUtil.dp2px( 1);//距底 canvas.drawText(maxPoint.getHighPrice() + "", maxX, high - baseLine+paddingTop, paint); canvas.drawText(minPoint.getLowPrice() + "", minX, low + baseLine-paddingBottom, paint); }
Example 11
Source File: LoopView.java From FastWaiMai with MIT License | 6 votes |
private void initPaints() { paintOuterText = new Paint(); paintOuterText.setColor(colorGray); paintOuterText.setAntiAlias(true); paintOuterText.setTypeface(Typeface.MONOSPACE); paintOuterText.setTextSize(textSize); paintCenterText = new Paint(); paintCenterText.setColor(colorBlack); paintCenterText.setAntiAlias(true); paintCenterText.setTextScaleX(scaleX); paintCenterText.setTypeface(Typeface.MONOSPACE); paintCenterText.setTextSize(textSize); paintIndicator = new Paint(); paintIndicator.setColor(colorLightGray); paintIndicator.setAntiAlias(true); if (android.os.Build.VERSION.SDK_INT >= 11) { setLayerType(LAYER_TYPE_SOFTWARE, null); } }
Example 12
Source File: MainKeyboardView.java From LokiBoard-Android-Keylogger with Apache License 2.0 | 6 votes |
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) { final Keyboard keyboard = getKeyboard(); if (keyboard == null) { return; } final int width = key.getWidth(); final int height = key.getHeight(); paint.setTextAlign(Align.CENTER); paint.setTypeface(Typeface.DEFAULT); paint.setTextSize(mLanguageOnSpacebarTextSize); final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); // Draw language text with shadow final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; final float baseline = height / 2 + textHeight / 2; paint.setColor(mLanguageOnSpacebarTextColor); paint.setAlpha(mLanguageOnSpacebarAnimAlpha); canvas.drawText(language, width / 2, baseline - descent, paint); paint.clearShadowLayer(); paint.setTextScaleX(1.0f); }
Example 13
Source File: MainKeyboardView.java From LokiBoard-Android-Keylogger with Apache License 2.0 | 6 votes |
private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) { final int maxTextWidth = width - mLanguageOnSpacebarHorizontalMargin * 2; paint.setTextScaleX(1.0f); final float textWidth = TypefaceUtils.getStringWidth(text, paint); if (textWidth < width) { return true; } final float scaleX = maxTextWidth / textWidth; if (scaleX < MINIMUM_XSCALE_OF_LANGUAGE_NAME) { return false; } paint.setTextScaleX(scaleX); return TypefaceUtils.getStringWidth(text, paint) < maxTextWidth; }
Example 14
Source File: MainKeyboardView.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) { final Keyboard keyboard = getKeyboard(); if (keyboard == null) { return; } final int width = key.getWidth(); final int height = key.getHeight(); paint.setTextAlign(Align.CENTER); paint.setTypeface(Typeface.DEFAULT); paint.setTextSize(mLanguageOnSpacebarTextSize); final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); // Draw language text with shadow final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; final float baseline = height / 2 + textHeight / 2; if (mLanguageOnSpacebarTextShadowRadius > 0.0f) { paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0, mLanguageOnSpacebarTextShadowColor); } else { paint.clearShadowLayer(); } paint.setColor(mLanguageOnSpacebarTextColor); paint.setAlpha(mLanguageOnSpacebarAnimAlpha); canvas.drawText(language, width / 2, baseline - descent, paint); paint.clearShadowLayer(); paint.setTextScaleX(1.0f); }
Example 15
Source File: MainKeyboardView.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) { final Keyboard keyboard = getKeyboard(); if (keyboard == null) { return; } final int width = key.getWidth(); final int height = key.getHeight(); paint.setTextAlign(Align.CENTER); paint.setTypeface(Typeface.DEFAULT); paint.setTextSize(mLanguageOnSpacebarTextSize); final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); // Draw language text with shadow final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; final float baseline = height / 2 + textHeight / 2; if (mLanguageOnSpacebarTextShadowRadius > 0.0f) { paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0, mLanguageOnSpacebarTextShadowColor); } else { paint.clearShadowLayer(); } paint.setColor(mLanguageOnSpacebarTextColor); paint.setAlpha(mLanguageOnSpacebarAnimAlpha); canvas.drawText(language, width / 2, baseline - descent, paint); paint.clearShadowLayer(); paint.setTextScaleX(1.0f); }
Example 16
Source File: XulBasicTextRenderer.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
protected Paint _getTextPaint(float fontSizeScale) { XulRenderContext ctx = _render.getRenderContext(); Paint defPaint = ctx.getTextPaintByName(_fontFace); if (!(_fontShadowSize == 0 || (_fontShadowColor & 0xFF000000) == 0)) { defPaint = ctx.getShadowTextPaintByName(_fontFace); defPaint.setShadowLayer(_fontShadowSize, _fontShadowX, _fontShadowY, _fontShadowColor); } defPaint.setColor(_fontColor); if (Math.abs(fontSizeScale - 1.0f) > 0.01f) { defPaint.setTextSize(_fontSize * fontSizeScale); } else { defPaint.setTextSize(_fontSize); } if (_fontWeight > 1.0) { if (_fontWeight > 2.5) { defPaint.setStrokeWidth(_fontWeight*fontSizeScale/2); } else { defPaint.setFakeBoldText(true); } } else { defPaint.setFakeBoldText(false); } defPaint.setTextScaleX(_fontScaleX); defPaint.setUnderlineText(_fontUnderline); defPaint.setStrikeThruText(_fontStrikeThrough); defPaint.setTextSkewX(_fontItalic ? -0.25f : 0); defPaint.setTextAlign(Paint.Align.LEFT); return defPaint; }
Example 17
Source File: VerificationCodeView.java From VerificationCodeView with MIT License | 5 votes |
/** * 初始化 */ private void initView() { mRandom=new Random(); bgPaint=new Paint(); bgPaint.setAntiAlias(true); bgPaint.setColor(YELLOW_BG_COLOR); linePaint=new Paint(); linePaint.setAntiAlias(true); linePaint.setStyle(Paint.Style.STROKE); linePaint.setColor(Color.BLACK); linePaint.setStrokeWidth(5); linePaint.setStrokeCap(Paint.Cap.ROUND); maxTextSize=DisplayUtils.spToPx(getContext(),50); defaultTextSize=DisplayUtils.spToPx(getContext(),30); textPaint=new Paint(); textPaint.setAntiAlias(true); textPaint.setTextSize(defaultTextSize); textPaint.setShadowLayer(5,3,3,0xFF999999); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setTextScaleX(0.8F); textPaint.setColor(Color.GREEN); textBound=new Rect(); }
Example 18
Source File: EncodingUtils.java From tysq-android with GNU General Public License v3.0 | 5 votes |
/** * 显示条形的内容 * * @param bCBitmap 已生成的条形码的位图 * @param content 条形码包含的内容 * @return 返回生成的新位图, 它是 方法{@link #createQRCode(String, int, int, Bitmap)}返回的位图与新绘制文本content的组合 */ private static Bitmap showContent(Bitmap bCBitmap, String content) { if (TextUtils.isEmpty(content) || null == bCBitmap) { return null; } Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL);//设置填充样式 paint.setTextSize(20); // paint.setTextAlign(Paint.Align.CENTER); //测量字符串的宽度 int textWidth = (int) paint.measureText(content); Paint.FontMetrics fm = paint.getFontMetrics(); //绘制字符串矩形区域的高度 int textHeight = (int) (fm.bottom - fm.top); // x 轴的缩放比率 float scaleRateX = bCBitmap.getWidth() / textWidth; paint.setTextScaleX(scaleRateX); //绘制文本的基线 int baseLine = bCBitmap.getHeight() + textHeight; //创建一个图层,然后在这个图层上绘制bCBitmap、content Bitmap bitmap = Bitmap.createBitmap(bCBitmap.getWidth(), bCBitmap.getHeight() + 2 * textHeight, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(); canvas.drawColor(Color.WHITE); canvas.setBitmap(bitmap); canvas.drawBitmap(bCBitmap, 0, 0, null); canvas.drawText(content, bCBitmap.getWidth() / 10, baseLine, paint); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); return bitmap; }
Example 19
Source File: MainKeyboardView.java From openboard with GNU General Public License v3.0 | 5 votes |
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) { final Keyboard keyboard = getKeyboard(); if (keyboard == null) { return; } final int width = key.getWidth(); final int height = key.getHeight(); paint.setTextAlign(Align.CENTER); paint.setTypeface(Typeface.DEFAULT); paint.setTextSize(mLanguageOnSpacebarTextSize); final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); // Draw language text with shadow final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; final float baseline = height / 2 + textHeight / 2; if (mLanguageOnSpacebarTextShadowRadius > 0.0f) { paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0, mLanguageOnSpacebarTextShadowColor); } else { paint.clearShadowLayer(); } paint.setColor(mLanguageOnSpacebarTextColor); paint.setAlpha(mLanguageOnSpacebarAnimAlpha); canvas.drawText(language, width / 2, baseline - descent, paint); paint.clearShadowLayer(); paint.setTextScaleX(1.0f); }
Example 20
Source File: LoopView.java From phphub-android with Apache License 2.0 | 4 votes |
private void d() { if (arrayList == null) { return; } paintA = new Paint(); paintA.setColor(colorGray); paintA.setAntiAlias(true); paintA.setTypeface(Typeface.MONOSPACE); paintA.setTextSize(textSize); paintB = new Paint(); paintB.setColor(colorBlack); paintB.setAntiAlias(true); paintB.setTextScaleX(1.05F); paintB.setTypeface(Typeface.MONOSPACE); paintB.setTextSize(textSize); paintC = new Paint(); paintC.setColor(colorGrayLight); paintC.setAntiAlias(true); paintC.setTypeface(Typeface.MONOSPACE); paintC.setTextSize(textSize); if (android.os.Build.VERSION.SDK_INT >= 11) { setLayerType(1, null); } gestureDetector = new GestureDetector(context, simpleOnGestureListener); gestureDetector.setIsLongpressEnabled(false); e(); t = (int) ((float) h * l * (float) (r - 1)); s = (int) ((double) (t * 2) / Math.PI); u = (int) ((double) t / Math.PI); v = g + textSize; n = (int) (((float) s - l * (float) h) / 2.0F); o = (int) (((float) s + l * (float) h) / 2.0F); if (positon == -1) { if (isLoop) { positon = (arrayList.size() + 1) / 2; } else { positon = 0; } } p = positon; }