Java Code Examples for android.graphics.Paint#setTextSize()

The following examples show how to use android.graphics.Paint#setTextSize() . 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 simple-keyboard with Apache License 2.0 6 votes vote down vote up
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 2
Source File: DialChart02View.java    From XCL-Charts with Apache License 2.0 6 votes vote down vote up
private void addAttrInfo()
{
	/////////////////////////////////////////////////////////////
	PlotAttrInfo plotAttrInfo = chart.getPlotAttrInfo();

	//设置附加信息
	Paint paintTB = new Paint();
	paintTB.setColor(Color.WHITE);
	paintTB.setTextAlign(Align.CENTER);
	paintTB.setTextSize(30);			
	plotAttrInfo.addAttributeInfo( XEnum.Location.TOP, "100 K/s", 0.9f, paintTB);
	
	Paint paintBT = new Paint();
	paintBT.setColor(Color.WHITE);
	paintBT.setTextAlign(Align.CENTER);
	paintBT.setTextSize(30);
	
	
	plotAttrInfo.addAttributeInfo(XEnum.Location.BOTTOM, 
			"平均速率: "+Float.toString( mPercentage * 100)+"K/s", 0.8f, paintBT);
}
 
Example 3
Source File: WaveView2.java    From PracticeDemo with Apache License 2.0 6 votes vote down vote up
private void init()
{
	mPointsList = new ArrayList<Point>();
	timer = new Timer();

	mPaint = new Paint();
	mPaint.setAntiAlias(true);
	mPaint.setStyle(Style.FILL);
	mPaint.setColor(Color.BLUE);

	mTextPaint = new Paint();
	mTextPaint.setColor(Color.WHITE);
	mTextPaint.setTextAlign(Align.CENTER);
	mTextPaint.setTextSize(30);

	mWavePath = new Path();
}
 
Example 4
Source File: DataRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
    super(viewPortHandler);
    this.mAnimator = animator;

    mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRenderPaint.setStyle(Style.FILL);

    mDrawPaint = new Paint(Paint.DITHER_FLAG);

    mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValuePaint.setColor(Color.rgb(63, 63, 63));
    mValuePaint.setTextAlign(Align.CENTER);
    mValuePaint.setTextSize(Utils.convertDpToPixel(9f));

    mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHighlightPaint.setStyle(Paint.Style.STROKE);
    mHighlightPaint.setStrokeWidth(2f);
    mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
 
Example 5
Source File: KeyboardView.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
protected void drawKeyPopupHint(@Nonnull final Key key, @Nonnull final Canvas canvas,
        @Nonnull final Paint paint, @Nonnull final KeyDrawParams params) {
    if (TextUtils.isEmpty(mKeyPopupHintLetter)) {
        return;
    }
    final int keyWidth = key.getDrawWidth();
    final int keyHeight = key.getHeight();

    paint.setTypeface(params.mTypeface);
    paint.setTextSize(params.mHintLetterSize);
    paint.setColor(params.mHintLabelColor);
    paint.setTextAlign(Align.CENTER);
    final float hintX = keyWidth - mKeyHintLetterPadding
            - TypefaceUtils.getReferenceCharWidth(paint) / 2.0f;
    final float hintY = keyHeight - mKeyPopupHintLetterPadding;
    canvas.drawText(mKeyPopupHintLetter, hintX, hintY, paint);
}
 
Example 6
Source File: BarcodeGraphic.java    From particle-android with Apache License 2.0 6 votes vote down vote up
BarcodeGraphic(GraphicOverlay overlay, FirebaseVisionBarcode barcode) {
  super(overlay);

  this.barcode = barcode;

  rectPaint = new Paint();
  rectPaint.setColor(TEXT_COLOR);
  rectPaint.setStyle(Paint.Style.STROKE);
  rectPaint.setStrokeWidth(STROKE_WIDTH);

  barcodePaint = new Paint();
  barcodePaint.setColor(TEXT_COLOR);
  barcodePaint.setTextSize(TEXT_SIZE);
  // Redraw the overlay, as this graphic has been added.
  postInvalidate();
}
 
Example 7
Source File: TextShowView.java    From easyweather with MIT License 5 votes vote down vote up
private void init() {

        //画笔初始化:
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setFilterBitmap(true);
        mPaint.setDither(true);
        mPaint.setColor(ContextCompat.getColor(MyApplication.getAppContext(),R.color.maincolor));
        String familyName ="宋体";
        Typeface font = Typeface.create(familyName,Typeface.BOLD);
        mPaint.setTypeface(font);
        mPaint.setTextSize(DisplayUtil.sp2px(MyApplication.getAppContext(),50));
        mPaint.setTextAlign(Paint.Align.CENTER);

        //背部图片的初始化
        backBitmap = getDescBitmap();
        int mBitH = backBitmap.getHeight();
        int mBitW = backBitmap.getWidth();
        bPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        bPaint.setFilterBitmap(true);
        bPaint.setDither(true);
        bPaint.setColor(ContextCompat.getColor(MyApplication.getAppContext(),R.color.white));

        //设置当前的高度
        mCurTop = mBitH / 2 ;
        mCurBelow = mCurTop;

        int topRectH = mCurTop;
        int belowRectH = mCurBelow;
        topRect = new Rect(0,
                           topRectH,
                           mBitW,
                           topRectH);  //初始化原图

        belowRect = new Rect(0,
                             belowRectH ,
                             mBitW,
                             belowRectH);
    }
 
Example 8
Source File: ChartView.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
public ChartView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setTextSize(SizeUtils.sp2px(context, 10));
    textMargin = SizeUtils.dp2px(context, 8);
    minPath = new Path();
    maxPath = new Path();
}
 
Example 9
Source File: BadgeDrawable.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
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 10
Source File: TextViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 通过需要的高度, 计算字体大小
 * @param height    需要的高度
 * @param startSize 字体开始预估大小
 * @return 字体大小
 */
public static float reckonTextSizeByHeight(final int height, final float startSize) {
    if (height <= 0 || startSize <= 0) return 0f;
    Paint paint = new Paint();
    // 默认字体大小
    float textSize = startSize;
    // 计算内容高度
    int calcTextHeight;
    // 特殊处理 ( 防止死循环记录控制 )
    int state = 0; // 1 -=, 2 +=
    // 循环计算
    while (true) {
        // 设置画笔大小
        paint.setTextSize(textSize);
        // 获取字体高度
        Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
        // 计算内容高度
        calcTextHeight = (int) Math.ceil((fontMetrics.descent - fontMetrics.ascent));
        // 符合条件则直接返回
        if (calcTextHeight == height) {
            return textSize;
        } else if (calcTextHeight > height) { // 如果计算的字体高度大于
            textSize -= 0.5f;
            if (state == 2) {
                if (calcTextHeight < height) {
                    return textSize;
                }
            }
            state = 1;
        } else {
            textSize += 0.5f;
            if (state == 1) {
                if (calcTextHeight < height) {
                    return textSize;
                }
            }
            state = 2;
        }
    }
}
 
Example 11
Source File: CustomTypefaceSpan.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
private void applyCustomTypeFace(@NonNull Paint paint, @NonNull Typeface tf) {
    paint.setFakeBoldText(false);
    paint.setTextSkewX(0f);
    paint.setTypeface(tf);
    if (animation != Animation.NONE) paint.clearShadowLayer();
    if (iconSizeRatio > 0) paint.setTextSize(paint.getTextSize() * iconSizeRatio);
    else if (iconSizePx > 0) paint.setTextSize(iconSizePx);
    if (iconColor < Integer.MAX_VALUE) paint.setColor(iconColor);
}
 
Example 12
Source File: FpsMeter.java    From OpenCV-AndroidSamples with MIT License 5 votes vote down vote up
public void init() {
    mFramesCouner = 0;
    mFrequency = Core.getTickFrequency();
    mprevFrameTime = Core.getTickCount();
    mStrfps = "";

    mPaint = new Paint();
    mPaint.setColor(Color.BLUE);
    mPaint.setTextSize(20);
}
 
Example 13
Source File: ScrollTextView.java    From AndroidTvDemo with Apache License 2.0 5 votes vote down vote up
/**
 * constructs 2
 *
 * @param context
 * @param attrs
 */
public ScrollTextView(Context context, AttributeSet attrs)
{
    super(context, attrs);
    surfaceHolder = this.getHolder(); // get The surface holder
    surfaceHolder.addCallback(this);
    paint = new Paint();
    TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.ScrollText);
    clickEnable = arr.getBoolean(R.styleable.ScrollText_clickEnable, clickEnable);
    isHorizontal = arr.getBoolean(R.styleable.ScrollText_isHorizontal, isHorizontal);
    speed = arr.getInteger(R.styleable.ScrollText_speed, speed);
    text = arr.getString(R.styleable.ScrollText_text);
    textColor = arr.getColor(R.styleable.ScrollText_textColor, textColor);
    textSize = arr.getDimension(R.styleable.ScrollText_textSize, textSize);
    defScrolltimes = arr.getInteger(R.styleable.ScrollText_times, defScrolltimes);
    
    needScrollTimes = defScrolltimes;
    paint.setColor(textColor);
    paint.setTextSize(textSize);
    
    setZOrderOnTop(true); // Control whether the surface view's surface is placed on top of its window.
    getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
    DisplayMetrics metric = new DisplayMetrics();
    ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(metric);
    density = metric.density;
    
    setFocusable(true);
}
 
Example 14
Source File: PercentileView.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    Log.d("DrawStats", "PercentileView - onDraw");
    super.onDraw(canvas);

    CalculatedData rd = getMaybeCalculatedData();

    if (rd == null) {
        Log.d("DrawStats", "PercentileView - onDraw if");

        Paint myPaint = new Paint();
        myPaint.setColor(Color.WHITE);
        myPaint.setAntiAlias(true);
        myPaint.setStyle(Paint.Style.STROKE);
        myPaint.setTextSize(dp2px(15));
        canvas.drawText("Calculating...", dp2px(30), canvas.getHeight() / 2, myPaint);
    } else {
        Log.d("DrawStats", "PercentileView - onDraw else");
        drawPolygon(canvas, rd.q10, rd.q90, outerPaint);
        drawPolygon(canvas, rd.q25, rd.q75, innerPaint);
        drawPolygon(canvas, rd.q50, rd.q50, medianPaint);

        drawHighLow(canvas);
        drawGrid(canvas);
        drawLegend(canvas);
    }


}
 
Example 15
Source File: FpsMeter.java    From SmartPaperScan with Apache License 2.0 5 votes vote down vote up
public void init() {
    mFramesCouner = 0;
    mFrequency = Core.getTickFrequency();
    mprevFrameTime = Core.getTickCount();
    mStrfps = "";

    mPaint = new Paint();
    mPaint.setColor(Color.BLUE);
    mPaint.setTextSize(20);
}
 
Example 16
Source File: FpsMeter.java    From OpenCV-android with Apache License 2.0 5 votes vote down vote up
public void init() {
    mFramesCouner = 0;
    mFrequency = Core.getTickFrequency();
    mprevFrameTime = Core.getTickCount();
    mStrfps = "";

    mPaint = new Paint();
    mPaint.setColor(Color.BLUE);
    mPaint.setTextSize(20);
}
 
Example 17
Source File: BitmapUtils.java    From Cangol-appcore with Apache License 2.0 5 votes vote down vote up
/**
 * 根据数字,创建一张带有数字的图片
 *
 * @param number   数字
 * @param textSize 字体大小
 * @param bitmap   图片
 * @return
 */
public static Bitmap createAlbumIcon(int number, int textSize, Bitmap bitmap) {
    if (number == 0) {
        return bitmap;
    }
    final int len = getNumberLength(number);
    final int x = len * (textSize);
    final int y = textSize;

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();
    final Bitmap contactIcon = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    final Canvas canvas = new Canvas(contactIcon);

    final Paint iconPaint = new Paint();
    iconPaint.setDither(true);
    iconPaint.setFilterBitmap(true);
    final Rect src1 = new Rect(0, 0, width, height);
    final Rect dst1 = new Rect(0, 0, width, height);
    canvas.drawBitmap(bitmap, src1, dst1, iconPaint);
    final Paint bgPaint = new Paint();
    bgPaint.setColor(Color.RED);
    canvas.drawRect(width - x / 2 - 6, 0, width + x / 2 + 6, y, bgPaint);
    final Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
    countPaint.setColor(Color.WHITE);
    countPaint.setTextSize(textSize);
    countPaint.setTypeface(Typeface.DEFAULT_BOLD);
    canvas.drawText(String.valueOf(number), width - x / 2 - 5, y - 2, countPaint);
    return contactIcon;
}
 
Example 18
Source File: GameView2.java    From Simple-Brick-Games with GNU General Public License v3.0 5 votes vote down vote up
public GameView2(Context context) {
    super(context);
    ourHolder = getHolder();
    paint = new Paint();
    pBlack = new Paint();
    pBackground = new Paint();
    pForeground = new Paint();
    pBackground.setColor(Color.WHITE);
    pBlack.setTextSize((float) (width * 1.2));
}
 
Example 19
Source File: MonthView.java    From MaterialDateRangePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the text and style properties for painting. Override this if you
 * want to use a different paint.
 */
protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
    mMonthTitlePaint.setColor(mDayTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);

    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mTodayNumberColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

    mMonthDayLabelPaint = new Paint();
    mMonthDayLabelPaint.setAntiAlias(true);
    mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
    mMonthDayLabelPaint.setColor(mMonthDayTextColor);
    mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(),"Roboto-Medium"));
    mMonthDayLabelPaint.setStyle(Style.FILL);
    mMonthDayLabelPaint.setTextAlign(Align.CENTER);
    mMonthDayLabelPaint.setFakeBoldText(true);

    mMonthNumPaint = new Paint();
    mMonthNumPaint.setAntiAlias(true);
    mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
    mMonthNumPaint.setStyle(Style.FILL);
    mMonthNumPaint.setTextAlign(Align.CENTER);
    mMonthNumPaint.setFakeBoldText(false);
}
 
Example 20
Source File: NumberPicker.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void init() {
    mSolidColor = 0;
    mSelectionDivider = new Paint();
    mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton));

    mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
    mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());

    mMinHeight = SIZE_UNSPECIFIED;

    mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics());
    if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
        throw new IllegalArgumentException("minHeight > maxHeight");
    }

    mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics());

    mMaxWidth = SIZE_UNSPECIFIED;
    if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
        throw new IllegalArgumentException("minWidth > maxWidth");
    }

    mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);

    mPressedStateHelper = new PressedStateHelper();

    setWillNotDraw(false);

    mInputText = new TextView(getContext());
    mInputText.setGravity(Gravity.CENTER);
    mInputText.setSingleLine(true);
    mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    mInputText.setBackgroundResource(0);
    mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    mInputText.setVisibility(INVISIBLE);
    addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mTextSize = (int) mInputText.getTextSize();

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(mTextSize);
    paint.setTypeface(mInputText.getTypeface());
    ColorStateList colors = mInputText.getTextColors();
    int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
    paint.setColor(color);
    mSelectorWheelPaint = paint;

    mFlingScroller = new Scroller(getContext(), null, true);
    mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));

    updateInputTextView();
}