Example usage for android.text TextPaint TextPaint

List of usage examples for android.text TextPaint TextPaint

Introduction

In this page you can find the example usage for android.text TextPaint TextPaint.

Prototype

public TextPaint(Paint p) 

Source Link

Usage

From source file:com.muzakki.ahmad.widget.CollapsingTextHelper.java

public CollapsingTextHelper(View view) {
    mView = view;//from  w w w . j  a va2  s  . co m

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mSubPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); // modification

    mCollapsedBounds = new Rect();
    mExpandedBounds = new Rect();
    mCurrentBounds = new RectF();
}

From source file:android.support.design.widget.CustomCollapsingTextHelper.java

public CustomCollapsingTextHelper(View view) {
    mView = view;//w  w  w.ja  va  2 s.c  om
    mTitlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mSubPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mCollapsedBounds = new Rect();
    mExpandedBounds = new Rect();
    mCurrentBounds = new RectF();
}

From source file:org.telegram.ui.Components.AvatarDrawable.java

public AvatarDrawable() {
    super();//from   ww  w. j av a  2 s. c  om

    if (namePaint == null) {
        namePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        namePaint.setColor(0xffffffff);

        namePaintSmall = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        namePaintSmall.setColor(0xffffffff);

        broadcastDrawable = ApplicationLoader.applicationContext.getResources()
                .getDrawable(R.drawable.broadcast_w);
    }

    namePaint.setTextSize(AndroidUtilities.dp(20));
    namePaintSmall.setTextSize(AndroidUtilities.dp(14));
}

From source file:org.telegram.ui.Cells.DialogCell.java

public DialogCell(Context context) {
    super(context);

    if (namePaint == null) {
        namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);

        namePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

        nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        nameEncryptedPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

        messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);

        linePaint = new Paint();

        backPaint = new Paint();
        backPaint.setColor(0x0f000000);/*from  w  w  w  .jav a  2  s .  co  m*/

        messagePrintingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);

        timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        timePaint.setColor(0xff999999);

        countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
        countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

        lockDrawable = getResources().getDrawable(R.drawable.list_secret);
        checkDrawable = getResources().getDrawable(R.drawable.dialogs_check);
        halfCheckDrawable = getResources().getDrawable(R.drawable.dialogs_halfcheck);
        clockDrawable = getResources().getDrawable(R.drawable.msg_clock);
        errorDrawable = getResources().getDrawable(R.drawable.dialogs_warning);
        countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
        countDrawableGrey = getResources().getDrawable(R.drawable.dialogs_badge2);
        groupDrawable = getResources().getDrawable(R.drawable.list_group);
        broadcastDrawable = getResources().getDrawable(R.drawable.list_broadcast);
        muteDrawable = getResources().getDrawable(R.drawable.mute_grey);
        verifiedDrawable = getResources().getDrawable(R.drawable.check_list);
        botDrawable = getResources().getDrawable(R.drawable.bot_list);

        resetPaintColor(context);
    }

    namePaint.setTextSize(AndroidUtilities.dp(17));
    nameEncryptedPaint.setTextSize(AndroidUtilities.dp(17));
    messagePaint.setTextSize(AndroidUtilities.dp(16));
    messagePrintingPaint.setTextSize(AndroidUtilities.dp(16));
    timePaint.setTextSize(AndroidUtilities.dp(13));
    countPaint.setTextSize(AndroidUtilities.dp(13));

    setBackgroundResource(R.drawable.list_selector);

    avatarImage = new ImageReceiver(this);
    avatarImage.setRoundRadius(AndroidUtilities.dp(26));
    avatarDrawable = new AvatarDrawable();
}

From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java

private void prepare() {
    mIconPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mIconPaint.setStyle(Paint.Style.FILL);
    mIconPaint.setTextAlign(Paint.Align.CENTER);
    mIconPaint.setUnderlineText(false);//from   w w  w.j  ava2  s.  c o m
    mIconPaint.setAntiAlias(true);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mContourPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mContourPaint.setStyle(Paint.Style.STROKE);

    mPath = new Path();

    mPathBounds = new RectF();
    mPaddingBounds = new Rect();
}

From source file:enterprayz.megatools.Tools.java

public static int getTextHeight(String text, int maxWidth, float textSize, Typeface typeface) {
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    paint.setTextSize(textSize);/*from w w  w.  j av  a  2s  . co m*/
    paint.setTypeface(typeface);

    int lineCount = 0;

    int index = 0;
    int length = text.length();

    while (index < length - 1) {
        index += paint.breakText(text, index, length, true, maxWidth, null);
        lineCount++;
    }

    Rect bounds = new Rect();
    paint.getTextBounds("Py", 0, 2, bounds);
    return (int) Math.floor(lineCount * bounds.height());
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

public IndicatorTabStrip(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setItemClickable(true);/*  w w w.  j  a  v a  2s. co m*/
    setClickSmoothScroll(true);
    final float density = getResources().getDisplayMetrics().density;
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Align.CENTER);
    if (Build.VERSION.SDK_INT > 4) {
        updateTextPaintDensity();
    }
    mTagLocation = new TagLocation(TagLocation.LOCATION_EDGE);
    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    int n = a.getIndexCount();
    int textSize = (int) (DEFAULT_TEXT_SIZE * density);
    ColorStateList textColors = null;
    Drawable divider = null;
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case 0:
            textSize = a.getDimensionPixelSize(attr, textSize);
            break;
        case 1:
            textColors = a.getColorStateList(attr);
            break;
        case 2:
            divider = a.getDrawable(attr);
            break;
        }
    }
    a.recycle();
    float scale = 1;
    Drawable itemBackground = null;
    ColorStateList gradient = null;
    Drawable indicator = null;
    int indicatorWidthMode = INDICATOR_WIDTH_MODE_SET;
    int indicatorPadding = 0;
    int indicatorWidth = INDICATOR_WIDTH_BY_DRAWABLE;
    int indicatorHeight = INDICATOR_HEIGHT_BY_DRAWABLE;
    Drawable interval = null;
    int minItemWidth = (int) (DEFAULT_ITEM_WIDTH * density);
    int minItemHeight = (int) (DEFAULT_ITEM_HEIGHT * density);
    int tagTextSize = (int) (DEFAULT_TAG_TEXT_SIZE * density);
    int tagTextColor = DEFAULT_TAG_TEXT_COLOR;
    Drawable tagBackground = getDefaultTagBackground();
    int tagMinSizeMode = TAG_MIN_SIZE_MODE_HAS_TEXT;
    int tagMinWidth = (int) (DEFAULT_TAG_MIN_SIZE * density);
    int tagMinHeight = (int) (DEFAULT_TAG_MIN_SIZE * density);
    int tagPaddingLeft = 0;
    int tagPaddingTop = 0;
    int tagPaddingRight = 0;
    int tagPaddingBottom = 0;
    int tagMarginLeft = 0;
    int tagMarginTop = 0;
    int tagMarginRight = 0;
    int tagMarginBottom = 0;
    TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.IndicatorTabStrip);
    textSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTextSize, textSize);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTextColor))
        textColors = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsTextColor);
    scale = custom.getFloat(R.styleable.IndicatorTabStrip_ttsTextScale, scale);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsBackground))
        itemBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsBackground);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsGradient))
        gradient = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsGradient);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsDivider))
        divider = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsDivider);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsIndicator))
        indicator = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsIndicator);
    indicatorWidthMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsIndicatorWidthMode, indicatorWidthMode);
    indicatorPadding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorPadding,
            indicatorPadding);
    indicatorWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorWidth,
            indicatorWidth);
    indicatorHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorHeight,
            indicatorHeight);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsInterval))
        interval = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsInterval);
    minItemWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemWidth, minItemWidth);
    minItemHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemHeight,
            minItemHeight);
    tagTextSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTagTextSize, tagTextSize);
    tagTextColor = custom.getColor(R.styleable.IndicatorTabStrip_ttsTagTextColor, tagTextColor);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagBackground))
        tagBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsTagBackground);
    tagMinSizeMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsTagMinSizeMode, tagMinSizeMode);
    tagMinWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinWidth, tagMinWidth);
    tagMinHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinHeight, tagMinHeight);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagPadding)) {
        final int padding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPadding, 0);
        tagPaddingLeft = padding;
        tagPaddingTop = padding;
        tagPaddingRight = padding;
        tagPaddingBottom = padding;
    }
    tagPaddingLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingLeft,
            tagPaddingLeft);
    tagPaddingTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingTop,
            tagPaddingTop);
    tagPaddingRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingRight,
            tagPaddingRight);
    tagPaddingBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingBottom,
            tagPaddingBottom);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagMargin)) {
        final int margin = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMargin, 0);
        tagMarginLeft = margin;
        tagMarginTop = margin;
        tagMarginRight = margin;
        tagMarginBottom = margin;
    }
    tagMarginLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginLeft,
            tagMarginLeft);
    tagMarginTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginTop, tagMarginTop);
    tagMarginRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginRight,
            tagMarginRight);
    tagMarginBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginBottom,
            tagMarginBottom);
    custom.recycle();
    setTextSize(textSize);
    if (textColors != null) {
        setTextColor(textColors);
    } else {
        setTextColor(DEFAULT_TEXT_COLOR);
    }
    setTextScale(scale);
    setItemBackground(itemBackground);
    setGradient(gradient);
    setDivider(divider);
    setIndicator(indicator);
    setIndicatorWidthMode(indicatorWidthMode);
    setIndicatorPadding(indicatorPadding);
    setIndicatorWidth(indicatorWidth);
    setIndicatorHeight(indicatorHeight);
    setInterval(interval);
    setMinItemWidth(minItemWidth);
    setMinItemHeight(minItemHeight);
    setTagTextSize(tagTextSize);
    setTagTextColor(tagTextColor);
    setTagBackground(tagBackground);
    setTagMinSizeMode(tagMinSizeMode);
    setTagMinWidth(tagMinWidth);
    setTagMinHeight(tagMinHeight);
    setTagPadding(tagPaddingLeft, tagPaddingTop, tagPaddingRight, tagPaddingBottom);
    setTagMargin(tagMarginLeft, tagMarginTop, tagMarginRight, tagMarginBottom);
}

From source file:com.yek.keyboard.keyboards.views.CandidateView.java

/**
 * Construct a CandidateView for showing suggested words for completion.
 *///w ww  .j  a va2 s.co  m
public CandidateView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed);

    mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary);
    // themed
    final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext());
    TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0,
            theme.getThemeResId());
    int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal);
    int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended);
    int colorOther = ContextCompat.getColor(context, R.color.candidate_other);
    float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height);
    try {
        colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal);
        colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor,
                colorRecommended);
        colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther);
        mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage);
        final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage);
        if (stripImage == null)
            setBackgroundColor(Color.BLACK);
        else
            setBackgroundDrawable(stripImage);
        fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel);
    } catch (Exception e) {
        Logger.w(TAG, "Got an exception while reading theme data", e);
    }
    mXGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20);
    a.recycle();
    mColorNormal = colorNormal;
    mColorRecommended = colorRecommended;
    mColorOther = colorOther;
    if (mDivider == null)
        mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider);
    // end of themed

    mPaint = new Paint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(fontSizePixel);
    mPaint.setStrokeWidth(0);
    mPaint.setTextAlign(Align.CENTER);
    mTextPaint = new TextPaint(mPaint);
    final int minTouchableWidth = context.getResources()
            .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width);
    mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth));
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
    scrollTo(0, getScrollY());
}

From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java

/**
 * Construct a CandidateView for showing suggested words for completion.
 *///from  w w w  .  ja v  a  2  s  . c  o m
public CandidateView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed);

    mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary);
    // themed
    final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext());
    TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0,
            theme.getThemeResId());
    int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal);
    int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended);
    int colorOther = ContextCompat.getColor(context, R.color.candidate_other);
    float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height);
    try {
        colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal);
        colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor,
                colorRecommended);
        colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther);
        mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage);
        final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage);
        if (stripImage == null)
            setBackgroundColor(Color.BLACK);
        else
            setBackgroundDrawable(stripImage);
        fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel);
    } catch (Exception e) {
        Logger.w(TAG, "Got an exception while reading theme data", e);
    }
    mHorizontalGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20);
    a.recycle();
    mColorNormal = colorNormal;
    mColorRecommended = colorRecommended;
    mColorOther = colorOther;
    if (mDivider == null)
        mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider);
    // end of themed

    mPaint = new Paint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(fontSizePixel);
    mPaint.setStrokeWidth(0);
    mPaint.setTextAlign(Align.CENTER);
    mTextPaint = new TextPaint(mPaint);
    final int minTouchableWidth = context.getResources()
            .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width);
    mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth));
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
    scrollTo(0, getScrollY());
}

From source file:com.seek.ruler.SimpleRulerView.java

/**
 * set default/*from   w w  w .  ja v a2 s .c o m*/
 * 
 * @param attrs
 */
private void init(AttributeSet attrs) {
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mIntervalDis = dm.density * 5;

    mRulerLineWidth = dm.density * 2;
    mTextSize = dm.scaledDensity * 14;

    TypedArray typedArray = attrs == null ? null
            : getContext().obtainStyledAttributes(attrs, R.styleable.simpleRulerView);
    if (typedArray != null) {
        mHighlightColor = typedArray.getColor(R.styleable.simpleRulerView_highlightColor, mHighlightColor);
        mTextColor = typedArray.getColor(R.styleable.simpleRulerView_textColor, mTextColor);
        mRulerColor = typedArray.getColor(R.styleable.simpleRulerView_rulerColor, mRulerColor);
        mIntervalValue = typedArray.getFloat(R.styleable.simpleRulerView_intervalValue, mIntervalValue);
        mMaxValue = typedArray.getFloat(R.styleable.simpleRulerView_maxValue, mMaxValue);
        mMinValue = typedArray.getFloat(R.styleable.simpleRulerView_minValue, mMinValue);
        mTextSize = typedArray.getDimension(R.styleable.simpleRulerView_textSize, mTextSize);
        mRulerLineWidth = typedArray.getDimension(R.styleable.simpleRulerView_rulerLineWidth, mRulerLineWidth);
        mIntervalDis = typedArray.getDimension(R.styleable.simpleRulerView_intervalDistance, mIntervalDis);
        retainLength = typedArray.getInteger(R.styleable.simpleRulerView_retainLength, 0);
    }

    calculateTotal();

    mRulerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRulerPaint.setStrokeWidth(mRulerLineWidth);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTextSize(mTextSize);

    mGestureDetectorCompat = new GestureDetectorCompat(getContext(), this);
    mScroller = new OverScroller(getContext(), new DecelerateInterpolator());

    setSelectedIndex(0);
}