Java Code Examples for android.text.TextPaint.setTextSize()

The following are Jave code examples for showing how to use setTextSize() of the android.text.TextPaint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: DMS   File: SwitchMultiButton.java   Source Code and License Vote up 6 votes
/**
 * define paints
 */
private void initPaint() {
    // round rectangle paint
    mStrokePaint = new Paint();
    mStrokePaint.setColor(mSelectedColor);
    mStrokePaint.setStyle(Paint.Style.STROKE);
    mStrokePaint.setAntiAlias(true);
    mStrokePaint.setStrokeWidth(mStrokeWidth);
    // selected paint
    mFillPaint = new Paint();
    mFillPaint.setColor(mSelectedColor);
    mFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mStrokePaint.setAntiAlias(true);
    // selected text paint
    mSelectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mSelectedTextPaint.setTextSize(mTextSize);
    mSelectedTextPaint.setColor(mSelectedColor);
    mStrokePaint.setAntiAlias(true);
    // unselected text paint
    mUnselectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mUnselectedTextPaint.setTextSize(mTextSize);
    mUnselectedTextPaint.setColor(0xffffffff);
    mStrokePaint.setAntiAlias(true);
    mTextHeightOffset = -(mSelectedTextPaint.ascent() + mSelectedTextPaint.descent()) * 0.5f;
}
 
Example 2
Project: snippety   File: TextIndentSpan.java   Source Code and License Vote up 6 votes
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline,
                              int bottom, CharSequence text, int start, int end, boolean first, Layout l) {
    if (first) {
        TextPaint paint = new TextPaint(p);

        paint.setStyle(Paint.Style.FILL);

        if (options.textSize != -1) {
            paint.setTextSize(options.textSize);
        }

        if (options.textColor != -1) {
            paint.setColor(options.textColor);
        }

        if (options.typeface != null) {
            paint.setTypeface(options.typeface);
        }

        c.save();
        c.drawText(data,  x + options.leadWidth, baseline, paint);
        c.restore();
    }
}
 
Example 3
Project: JBase   File: FlowViewVertical.java   Source Code and License Vote up 6 votes
private void init() {
    bgPaint = new Paint();
    bgPaint.setAntiAlias(true);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setColor(bgColor);
    bgPaint.setStrokeWidth(lineBgWidth);

    proPaint = new Paint();
    proPaint.setAntiAlias(true);
    proPaint.setStyle(Paint.Style.FILL);
    proPaint.setColor(proColor);
    proPaint.setStrokeWidth(lineProWidth);

    textPaint = new TextPaint();
    textPaint.setTextSize(textsize);
    textPaint.setAntiAlias(true);
}
 
Example 4
Project: AmenEye   File: ViewUtil.java   Source Code and License Vote up 6 votes
/**
 * Recursive binary search to find the best size for the text.
 * <p>
 * Adapted from https://github.com/grantland/android-autofittextview
 */
public static float getSingleLineTextSize(String text,
                                          TextPaint paint,
                                          float targetWidth,
                                          float low,
                                          float high,
                                          float precision,
                                          DisplayMetrics metrics) {
    final float mid = (low + high) / 2.0f;

    paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid, metrics));
    final float maxLineWidth = paint.measureText(text);

    if ((high - low) < precision) {
        return low;
    } else if (maxLineWidth > targetWidth) {
        return getSingleLineTextSize(text, paint, targetWidth, low, mid, precision, metrics);
    } else if (maxLineWidth < targetWidth) {
        return getSingleLineTextSize(text, paint, targetWidth, mid, high, precision, metrics);
    } else {
        return mid;
    }
}
 
Example 5
Project: airgram   File: TimerDrawable.java   Source Code and License Vote up 5 votes
public TimerDrawable(Context context) {
    if (emptyTimerDrawable == null) {
        emptyTimerDrawable = context.getResources().getDrawable(R.drawable.header_timer);
        timerDrawable = context.getResources().getDrawable(R.drawable.header_timer2);
        timePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        timePaint.setTextSize(AndroidUtilities.dp(11));
        timePaint.setColor(0xffffffff);
        timePaint.setTypeface(FontManager.instance().getTypeface());
    }
}
 
Example 6
Project: revolution-irc   File: StaticLabelTextInputLayout.java   Source Code and License Vote up 5 votes
public StaticLabelTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mTextPaint.setTypeface(getTypeface());
    mTextPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material));
    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context,
            new int[] { android.R.attr.textColorHint });
    mTextColorUnfocused = ta.getColor(android.R.attr.textColorHint, 0);
    ta.recycle();
    mTextColorFocused = ThemeHelper.getAccentColor(context);
    mTextPaint.setColor(mTextColorUnfocused);
}
 
Example 7
Project: airgram   File: BotHelpCell.java   Source Code and License Vote up 5 votes
public BotHelpCell(Context context) {
    super(context);

    textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(AndroidUtilities.dp(16));
    textPaint.setColor(0xff000000);
    textPaint.linkColor = Theme.MSG_LINK_TEXT_COLOR;

    urlPaint = new Paint();
    urlPaint.setColor(Theme.MSG_LINK_SELECT_BACKGROUND_COLOR);
}
 
Example 8
Project: airgram   File: PopupAudioView.java   Source Code and License Vote up 5 votes
public PopupAudioView(Context context) {
    super(context);
    if (backgroundMediaDrawableIn == null) {
        backgroundMediaDrawableIn = getResources().getDrawable(R.drawable.msg_in_photo);
        statesDrawable[0][0] = getResources().getDrawable(R.drawable.play_g);
        statesDrawable[0][1] = getResources().getDrawable(R.drawable.play_g_s);
        statesDrawable[1][0] = getResources().getDrawable(R.drawable.pause_g);
        statesDrawable[1][1] = getResources().getDrawable(R.drawable.pause_g_s);
        statesDrawable[2][0] = getResources().getDrawable(R.drawable.file_g_load);
        statesDrawable[2][1] = getResources().getDrawable(R.drawable.file_g_load_s);
        statesDrawable[3][0] = getResources().getDrawable(R.drawable.file_g_cancel);
        statesDrawable[3][1] = getResources().getDrawable(R.drawable.file_g_cancel_s);

        statesDrawable[4][0] = getResources().getDrawable(R.drawable.play_b);
        statesDrawable[4][1] = getResources().getDrawable(R.drawable.play_b_s);
        statesDrawable[5][0] = getResources().getDrawable(R.drawable.pause_b);
        statesDrawable[5][1] = getResources().getDrawable(R.drawable.pause_b_s);
        statesDrawable[6][0] = getResources().getDrawable(R.drawable.file_b_load);
        statesDrawable[6][1] = getResources().getDrawable(R.drawable.file_b_load_s);
        statesDrawable[7][0] = getResources().getDrawable(R.drawable.file_b_cancel);
        statesDrawable[7][1] = getResources().getDrawable(R.drawable.file_b_cancel_s);

        timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        timePaint.setTextSize(AndroidUtilities.dp(16));
    }

    TAG = MediaController.getInstance().generateObserverTag();

    seekBar = new SeekBar(getContext());
    seekBar.setDelegate(this);
    progressView = new ProgressView();
}
 
Example 9
Project: RNLearn_Project1   File: FontStylingSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateMeasureState(TextPaint ds) {
  if (mFontSize != -1) {
    ds.setTextSize(mFontSize);
  }

  updateTypeface(ds);
}
 
Example 10
Project: ceji_android   File: PageCurlAnimator.java   Source Code and License Vote up 5 votes
/**
 * Initialize the view
 */
private final void init() {		
	
	// Foreground text paint
	mTextPaint = new Paint();
	mTextPaint.setAntiAlias(true);
	mTextPaint.setTextSize(16);
	mTextPaint.setColor(0xFF000000);
	
	// The shadow
	mTextPaintShadow = new TextPaint();
	mTextPaintShadow.setAntiAlias(true);
	mTextPaintShadow.setTextSize(16);
	mTextPaintShadow.setColor(0x00000000);
	
	// Base padding
	//setPadding(3, 3, 3, 3);
	
	mMovement =  new Vector2D(0,0);
	
	mOldMovement = new Vector2D(0,0);				
	
	// Create our edge paint
	mCurlEdgePaint = new Paint();
	mCurlEdgePaint.setAntiAlias(true);
	mCurlEdgePaint.setStyle(Paint.Style.STROKE);
//	mCurlEdgePaint.setColor(this.edgeColor);
	
//	mCurlEdgePaint.setShadowLayer(10, -5, 5, 0x99000000);
	
	
	// Set the default props, those come from an XML :D
	mCurlSpeed = 30;		
	mInitialEdgeOffset = 20;
	
}
 
Example 11
Project: DragBadgeView   File: DragBadgeView.java   Source Code and License Vote up 5 votes
private void init(AttributeSet attrs) {
    TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.DragBadgeView);
    mText = mDrawText = array.getString(R.styleable.DragBadgeView_text);
    float textSize = array.getDimension(R.styleable.DragBadgeView_textSize, sp2px(10));
    int bgColor = array.getColor(R.styleable.DragBadgeView_bgColor, Color.RED);
    int textColor = array.getColor(R.styleable.DragBadgeView_textColor, Color.WHITE);
    mMaxMoveRange = array.getDimension(R.styleable.DragBadgeView_maxMoveRange, dp2px(80));
    mDragEnable = array.getBoolean(R.styleable.DragBadgeView_dragEnable, true);
    mMaxShowValue = array.getInt(R.styleable.DragBadgeView_maxShowValue, 99);
    array.recycle();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(bgColor);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTextSize(textSize);
    mTextPaint.setColor(textColor);

    if (mText == null) {
        mText = mDrawText = "-1";
    }

    measureText();

    //绘制文字及背景需要的RectF
    mTextRectF = new RectF();
}
 
Example 12
Project: AutoResizeEditText   File: AutofitHelper.java   Source Code and License Vote up 5 votes
private static int getLineCount(CharSequence text, TextPaint paint, float size, float width,
                                DisplayMetrics displayMetrics) {
    paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
            displayMetrics));
    StaticLayout layout = new StaticLayout(text, paint, (int) width,
            Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
    return layout.getLineCount();
}
 
Example 13
Project: Markwon   File: SpannableTheme.java   Source Code and License Vote up 5 votes
public void applySuperScriptStyle(@NonNull TextPaint paint) {
    final float ratio;
    if (Float.compare(scriptTextSizeRatio, .0F) == 0) {
        ratio = SCRIPT_DEF_TEXT_SIZE_RATIO;
    } else {
        ratio = scriptTextSizeRatio;
    }
    paint.setTextSize(paint.getTextSize() * ratio);
    paint.baselineShift += (int) (paint.ascent() / 2);
}
 
Example 14
Project: AndroidPDF   File: Page.java   Source Code and License Vote up 5 votes
private TextPaint textPaint() {
    final TextPaint paint = new TextPaint();
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);
    paint.setTextSize(24);
    paint.setTextAlign(Paint.Align.CENTER);
    return paint;
}
 
Example 15
Project: PaoMovie   File: DonutProgress.java   Source Code and License Vote up 5 votes
protected void initPainters() {
    if (showText) {
        textPaint = new TextPaint();
        textPaint.setColor(textColor);
        textPaint.setTextSize(textSize);
        textPaint.setAntiAlias(true);

        innerBottomTextPaint = new TextPaint();
        innerBottomTextPaint.setColor(innerBottomTextColor);
        innerBottomTextPaint.setTextSize(innerBottomTextSize);
        innerBottomTextPaint.setAntiAlias(true);
    }

    finishedPaint = new Paint();
    finishedPaint.setColor(finishedStrokeColor);
    finishedPaint.setStyle(Paint.Style.STROKE);
    finishedPaint.setAntiAlias(true);
    finishedPaint.setStrokeWidth(finishedStrokeWidth);

    unfinishedPaint = new Paint();
    unfinishedPaint.setColor(unfinishedStrokeColor);
    unfinishedPaint.setStyle(Paint.Style.STROKE);
    unfinishedPaint.setAntiAlias(true);
    unfinishedPaint.setStrokeWidth(unfinishedStrokeWidth);

    innerCirclePaint = new Paint();
    innerCirclePaint.setColor(innerBackgroundColor);
    innerCirclePaint.setAntiAlias(true);
}
 
Example 16
Project: PlusGram   File: HintDialogCell.java   Source Code and License Vote up 5 votes
public HintDialogCell(Context context) {
    super(context);
    setBackgroundResource(R.drawable.list_selector);

    imageView = new BackupImageView(context);
    imageView.setRoundRadius(AndroidUtilities.dp(27));
    addView(imageView, LayoutHelper.createFrame(54, 54, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));

    nameTextView = new TextView(context);
    nameTextView.setTextColor(0xff212121);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    nameTextView.setMaxLines(2);
    nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    nameTextView.setLines(2);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0));

    if (countDrawable == null) {
        countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
        countDrawableGrey = getResources().getDrawable(R.drawable.dialogs_badge2);

        countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        countPaint.setColor(0xffffffff);
        countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    }
    countPaint.setTextSize(AndroidUtilities.dp(13));
}
 
Example 17
Project: Android-LabelView   File: LabelView.java   Source Code and License Vote up 4 votes
private void init(Context context, AttributeSet attrs) {

        if (attrs != null) {
            TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.LabelView, 0, 0);
            try {
                textValue = a.getString(R.styleable.LabelView_textValue);
                labelValue = a.getString(R.styleable.LabelView_labelValue);
                lineColour = a.getColor(R.styleable.LabelView_lineColour, ContextCompat.getColor(context, DEFAULT_LINE_COLOR));
                textColour = a.getColor(R.styleable.LabelView_textColour, ContextCompat.getColor(context, DEFAULT_TEXT_COLOR));
                labelColour = a.getColor(R.styleable.LabelView_labelColour, ContextCompat.getColor(context, DEFAULT_TEXT_COLOR));
                lineThickness = a.getFloat(R.styleable.LabelView_lineThickness, 4f);
                labelSize = a.getDimensionPixelSize(R.styleable.LabelView_labelSize, (int) DEFAULT_TEXT_SIZE);
                textSize = a.getDimensionPixelSize(R.styleable.LabelView_textSize, (int) DEFAULT_TEXT_SIZE);
            } finally {
                a.recycle();
            }
        } else {
            textSize = labelSize = (int) DEFAULT_TEXT_SIZE;
            lineColour = ContextCompat.getColor(context, DEFAULT_LINE_COLOR);
            textColour = ContextCompat.getColor(context, DEFAULT_TEXT_COLOR);
            labelColour = textColour;
            lineThickness = DEFAULT_LINE_THICKNESS;
        }

        if (textValue == null) textValue = "";
        if (labelValue == null) labelValue = "";

        linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        linePaint.setColor(lineColour);
        linePaint.setStyle(Paint.Style.STROKE);
        linePaint.setStrokeWidth(lineThickness);
        linePaint.setStrokeCap(Paint.Cap.SQUARE);
        textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

        textPaint.setColor(textColour);
        textPaint.setTextSize(textSize);
        textPaint.setStyle(Paint.Style.FILL);

        labelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        labelPaint.setColor(labelColour);
        labelPaint.setTextSize(labelSize);
        textMetrics = textPaint.getFontMetrics();
        labelMetrics = labelPaint.getFontMetrics();

        textBounds = new Rect();
        labelBounds = new Rect();
    }
 
Example 18
Project: android-autofittextview   File: AutofitHelper.java   Source Code and License Vote up 4 votes
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
        int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
                displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
Example 19
Project: Android-LabelView   File: LabelView.java   Source Code and License Vote up 4 votes
private void setRawTextSize(TextPaint paint, float textSize) {
    paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, getResources().getDisplayMetrics()));
    requestLayout();
    invalidate();
}
 
Example 20
Project: IconDotTextView   File: TextConfig.java   Source Code and License Vote up 4 votes
private void initPaint() {
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(DEFAULT_COLOR);
    mTextPaint.setTextSize(mSize);
}