Java Code Examples for android.graphics.Paint.setTextAlign()

The following are Jave code examples for showing how to use setTextAlign() 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: DailyReader   File: NewBookFactory.java   View Source Code Vote up 6 votes
public NewBookFactory(ChaptersResponse.MixToc chaptersInfo){
    cacheManager = CacheManager.getInstance();

    EventBus.getDefault().register(this);

    this.mChaptersInfo = chaptersInfo;
    getWidthAndHeight();
    normalPaint = new Paint();
    normalPaint.setTextSize(fontSize);
    normalPaint.setColor(Color.BLACK);
    normalPaint.setTextAlign(Paint.Align.LEFT);

    titlePaint = new Paint();
    titlePaint.setTextSize(titleSize);
    titlePaint.setColor(Color.DKGRAY);
    titlePaint.setTextAlign(Paint.Align.CENTER);
    titlePaint.setTypeface(Typeface.DEFAULT_BOLD);

    contentWidth = width - 2 * normalMargin;
    contentHeight = height - 2 * normalMargin;
    lineCount = contentHeight / (fontSize + normalMargin);

    backgroundBitmap = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.bg_read);
}
 
Example 2
Project: efficientclock   File: EfficientClock.java   View Source Code Vote up 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 3
Project: MusicX-music-player   File: EqView.java   View Source Code Vote up 6 votes
private void init() {
    ateKey = Helper.getATEKey(getContext());
    accentColor = Config.accentColor(getContext(), ateKey);
    textPaint = new Paint();
    textPaint.setColor(labelColor);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTextSize(labelSize);
    textPaint.setFakeBoldText(true);
    textPaint.setTextAlign(Paint.Align.CENTER);
    circlePaint = new Paint();
    circlePaint.setColor(progressSecondaryColor);
    circlePaint.setStrokeWidth(progressSecondaryStrokeWidth);
    circlePaint.setStyle(Paint.Style.FILL);
    circlePaint2 = new Paint();
    circlePaint2.setColor(accentColor);
    circlePaint2.setTextAlign(Paint.Align.CENTER);
    circlePaint2.setStrokeWidth(progressPrimaryStrokeWidth);
    circlePaint2.setStyle(Paint.Style.FILL);
    linePaint = new Paint();
    linePaint.setColor(indicatorColor);
    linePaint.setStrokeWidth(indicatorWidth);

    oval = new RectF();

}
 
Example 4
Project: DailyReader   File: BookFactory.java   View Source Code Vote up 6 votes
public BookFactory(ChaptersResponse.MixToc chaptersInfo){
    this.mChaptersInfo = chaptersInfo;
    getWidthAndHeight();
    mNormalPaint = new Paint();
    mNormalPaint.setTextSize(mNormalSize);
    mNormalPaint.setColor(Color.BLACK);
    mNormalPaint.setTextAlign(Paint.Align.LEFT);

    mTitlePaint = new Paint();
    mTitlePaint.setTextSize(mTitleSize);
    mTitlePaint.setColor(Color.DKGRAY);
    mTitlePaint.setTextAlign(Paint.Align.CENTER);
    mTitlePaint.setTypeface(Typeface.DEFAULT_BOLD);

    mCurrentPage = 0;
    mBackgroundBitmap = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.bg_read);
}
 
Example 5
Project: ChromeLikeTabSwitcher   File: TabSwitcherDrawable.java   View Source Code Vote up 6 votes
/**
 * Creates a new drawable, which allows to display the number of tabs, which are currently
 * contained by a {@link TabSwitcher}.
 *
 * @param context
 *         The context, which should be used by the drawable, as an instance of the class {@link
 *         Context}. The context may not be null
 */
public TabSwitcherDrawable(@NonNull final Context context) {
    ensureNotNull(context, "The context may not be null");
    Resources resources = context.getResources();
    size = resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_size);
    textSizeNormal =
            resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_normal);
    textSizeSmall =
            resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_small);
    background = ContextCompat.getDrawable(context, R.drawable.tab_switcher_drawable_background)
            .mutate();
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(textSizeNormal);
    paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    label = Integer.toString(0);
    int tint = ThemeUtil.getColor(context, android.R.attr.textColorPrimary);
    setColorFilter(tint, PorterDuff.Mode.MULTIPLY);
}
 
Example 6
Project: SubwayTooter   File: ColorPickerView.java   View Source Code Vote up 6 votes
private void initPaintTools() {

    satValPaint = new Paint();
    satValTrackerPaint = new Paint();
    hueAlphaTrackerPaint = new Paint();
    alphaPaint = new Paint();
    alphaTextPaint = new Paint();
    borderPaint = new Paint();

    satValTrackerPaint.setStyle(Style.STROKE);
    satValTrackerPaint.setStrokeWidth(DrawingUtils.dpToPx(getContext(), 2));
    satValTrackerPaint.setAntiAlias(true);

    hueAlphaTrackerPaint.setColor(sliderTrackerColor);
    hueAlphaTrackerPaint.setStyle(Style.STROKE);
    hueAlphaTrackerPaint.setStrokeWidth(DrawingUtils.dpToPx(getContext(), 2));
    hueAlphaTrackerPaint.setAntiAlias(true);

    alphaTextPaint.setColor(0xff1c1c1c);
    alphaTextPaint.setTextSize(DrawingUtils.dpToPx(getContext(), 14));
    alphaTextPaint.setAntiAlias(true);
    alphaTextPaint.setTextAlign(Align.CENTER);
    alphaTextPaint.setFakeBoldText(true);

  }
 
Example 7
Project: IndicatorSeekBar   File: CircleBubbleView.java   View Source Code Vote up 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 8
Project: filepicker   File: TuyaView.java   View Source Code Vote up 6 votes
private void setPaintStyle() {
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    if (currentStyle == 1) {
        mPaint.setStrokeWidth(currentSize);
        mPaint.setColor(currentColor);
    } else {
        mPaint.setAlpha(0);
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        mPaint.setColor(Color.TRANSPARENT);
        mPaint.setStrokeWidth(50);
    }

    mMaskPaint = new Paint();
    mMaskPaint.setStrokeWidth(3);
    mMaskPaint.setTextAlign(Paint.Align.RIGHT);
    mMaskPaint.setColor(Color.GREEN);
    mMaskPaint.setTextSize(40);
}
 
Example 9
Project: AOSP-Kayboard-7.1.2   File: KeyboardView.java   View Source Code Vote up 6 votes
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 10
Project: YiZhi   File: PickerView.java   View Source Code Vote up 5 votes
private void init() {
    timer = new Timer();
    mDataList = new ArrayList<String>();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Style.FILL);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setColor(mColorText);
}
 
Example 11
Project: Widgets   File: PickerView.java   View Source Code Vote up 5 votes
private void init() {
    timer = new Timer();
    mDataList = new ArrayList<T>();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Style.FILL);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setColor(mColorText);
}
 
Example 12
Project: starcor.xul   File: XulBasicTextRenderer.java   View Source Code Vote up 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 13
Project: Android-LineChart   File: LineChartView.java   View Source Code Vote up 5 votes
private void setupView() {
    linePaint = new Paint();
    linePaint.setAntiAlias(true);//抗锯齿
    linePaint.setStyle(Paint.Style.STROKE);//STROKE描边FILL填充
    linePaint.setColor(lineColor);
    linePaint.setStrokeWidth(dip2px(lineWidthDP));//边框宽度

    pointPaint = new Paint();
    pointPaint.setAntiAlias(true);
    pointPaint.setStyle(Paint.Style.FILL);
    pointPaint.setColor(pointColor);
    pointPaint.setStrokeWidth(dip2px(pointWidthDP));

    tablePaint = new Paint();
    tablePaint.setAntiAlias(true);
    tablePaint.setStyle(Paint.Style.STROKE);
    tablePaint.setColor(tableColor);
    tablePaint.setStrokeWidth(dip2px(tableWidthDP));

    textRulerPaint = new Paint();
    textRulerPaint.setAntiAlias(true);
    textRulerPaint.setStyle(Paint.Style.FILL);
    textRulerPaint.setTextAlign(Paint.Align.CENTER);
    textRulerPaint.setColor(rulerTextColor);//文本颜色
    textRulerPaint.setTextSize(sp2px(rulerTextSizeSP));//字体大小

    textPointPaint = new Paint();
    textPointPaint.setAntiAlias(true);
    textPointPaint.setStyle(Paint.Style.FILL);
    textPointPaint.setTextAlign(Paint.Align.CENTER);
    textPointPaint.setColor(pointTextColor);//文本颜色
    textPointPaint.setTextSize(sp2px(pointTextSizeSP));//字体大小

    linePath = new Path();
    tablePath = new Path();

    resetParam();
}
 
Example 14
Project: PasscodeView   File: BoxTitle.java   View Source Code Vote up 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: Fitto   File: CanvasBoardView.java   View Source Code Vote up 4 votes
private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.CanvasBoardView, 0, 0);
    playerUser = typedArray.getString(R.styleable.CanvasBoardView_playerUser);
    playerComputer = typedArray.getString(R.styleable.CanvasBoardView_playerComputer);
    computerStoneColor = typedArray.getString(R.styleable.CanvasBoardView_computerStoneColor);
    userStoneColor = typedArray.getString(R.styleable.CanvasBoardView_userStoneColor);
    maximumInitialStones =
            typedArray.getInt(R.styleable.CanvasBoardView_maximumInitialStones, 8);
    stoneRadius = typedArray.getInt(R.styleable.CanvasBoardView_stoneRadius, 20);
    canvasMargin = typedArray.getInt(R.styleable.CanvasBoardView_margin, 20);
    userStonePaint = new Paint();
    userStonePaint.setAntiAlias(true);
    userStonePaint.setDither(true);
    userStonePaint.setColor(Color.parseColor(userStoneColor));
    userStonePaint.setStrokeWidth(stoneRadius);

    computerStonePaint = new Paint();
    computerStonePaint.setAntiAlias(true);
    computerStonePaint.setDither(true);
    computerStonePaint.setColor(Color.parseColor(computerStoneColor));
    computerStonePaint.setStrokeWidth(stoneRadius);

    pickedStonePaint = new Paint();
    pickedStonePaint.setAntiAlias(true);
    pickedStonePaint.setDither(true);
    pickedStonePaint.setColor(Color.parseColor("#8C8C8C"));
    pickedStonePaint.setStrokeWidth(stoneRadius);

    boardPaint = new Paint();
    boardPaint.setAntiAlias(true);
    boardPaint.setDither(true);
    boardPaint.setColor(ContextCompat.getColor(context, R.color.colorAccent));
    boardPaint.setStyle(Paint.Style.STROKE);
    boardPaint.setStrokeJoin(Paint.Join.ROUND);
    boardPaint.setStrokeWidth(4);

    tripletPath = new Path();

    displayMessagePaint = new Paint();
    displayMessagePaint.setAntiAlias(true);
    displayMessagePaint.setTextAlign(Paint.Align.CENTER);
    displayMessagePaint.setTextSize(2 * canvasMargin);
    displayMessagePaint.setColor(Color.parseColor(computerStoneColor));

    scoreMessagePaint = new Paint();
    scoreMessagePaint.setAntiAlias(true);
    scoreMessagePaint.setTextAlign(Paint.Align.CENTER);
    scoreMessagePaint.setTextSize((float) 1.5 * canvasMargin);
    scoreMessagePaint.setColor(Color.parseColor(userStoneColor));

    tripletPaint = new Paint();
    tripletPaint.setAntiAlias(true);
    tripletPaint.setStyle(Paint.Style.STROKE);
    tripletPaint.setColor(Color.parseColor(computerStoneColor));
    tripletPaint.setStrokeWidth(5);

    typedArray.recycle();

    settingsPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    // 24 junctions starting from 1 to 24
    junctionsArray = new Junction[25];

    gameUtility = new GameUtility();
    this.context = context;
    vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    mediaPlayer = MediaPlayer.create(context, R.raw.served);
}
 
Example 16
Project: BookPage   File: BookPageView.java   View Source Code Vote up 4 votes
private void init(Context context, @Nullable AttributeSet attrs){
        defaultWidth = 600;
        defaultHeight = 1000;

        a = new MyPoint();
        f = new MyPoint();
        g = new MyPoint();
        e = new MyPoint();
        h = new MyPoint();
        c = new MyPoint();
        j = new MyPoint();
        b = new MyPoint();
        k = new MyPoint();
        d = new MyPoint();
        i = new MyPoint();

        pointPaint = new Paint();
        pointPaint.setColor(Color.RED);
        pointPaint.setTextSize(25);
        pointPaint.setStyle(Paint.Style.STROKE);

        bgPaint = new Paint();
        bgPaint.setColor(Color.GREEN);

        pathAPaint = new Paint();
        pathAPaint.setColor(Color.GREEN);
        pathAPaint.setAntiAlias(true);//设置抗锯齿

        pathBPaint = new Paint();
        pathBPaint.setColor(getResources().getColor(R.color.blue_light));
        pathBPaint.setAntiAlias(true);//设置抗锯齿
//        pathBPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));我们不需要单独绘制path了,记得注释掉

        pathCPaint = new Paint();
        pathCPaint.setColor(Color.YELLOW);
        pathCPaint.setAntiAlias(true);//设置抗锯齿
//        pathCPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));
//        pathCPaint.setStyle(Paint.Style.STROKE);

        pathCContentPaint = new Paint();
        pathCContentPaint.setColor(Color.YELLOW);
        pathCContentPaint.setAntiAlias(true);//设置抗锯齿

        textPaint = new Paint();
        textPaint.setColor(Color.BLACK);
        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setSubpixelText(true);//设置自像素。如果该项为true,将有助于文本在LCD屏幕上的显示效果。
        textPaint.setTextSize(30);

        pathA = new Path();
        pathB = new Path();
        pathC = new Path();

        style = STYLE_LOWER_RIGHT;
        mScroller = new Scroller(context,new LinearInterpolator());
        mMatrix = new Matrix();

        createGradientDrawable();
    }
 
Example 17
Project: GitHub   File: SimpleMonthView.java   View Source Code Vote up 4 votes
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);

       mMonthTitleBGPaint = new Paint();
       mMonthTitleBGPaint.setFakeBoldText(true);
       mMonthTitleBGPaint.setAntiAlias(true);
       mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
       mMonthTitleBGPaint.setTextAlign(Align.CENTER);
       mMonthTitleBGPaint.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(mDayTextColor);
       mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
       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 18
Project: RNLearn_Project1   File: ARTTextShadowNode.java   View Source Code Vote up 4 votes
private void applyTextPropertiesToPaint(Paint paint) {
  int alignment = mTextAlignment;
  switch (alignment) {
    case TEXT_ALIGNMENT_LEFT:
      paint.setTextAlign(Paint.Align.LEFT);
      break;
    case TEXT_ALIGNMENT_RIGHT:
      paint.setTextAlign(Paint.Align.RIGHT);
      break;
    case TEXT_ALIGNMENT_CENTER:
      paint.setTextAlign(Paint.Align.CENTER);
      break;
  }
  if (mFrame != null) {
    if (mFrame.hasKey(PROP_FONT)) {
      ReadableMap font = mFrame.getMap(PROP_FONT);
      if (font != null) {
        float fontSize = DEFAULT_FONT_SIZE;
        if (font.hasKey(PROP_FONT_SIZE)) {
          fontSize = (float) font.getDouble(PROP_FONT_SIZE);
        }
        paint.setTextSize(fontSize * mScale);
        boolean isBold =
            font.hasKey(PROP_FONT_WEIGHT) && "bold".equals(font.getString(PROP_FONT_WEIGHT));
        boolean isItalic =
            font.hasKey(PROP_FONT_STYLE) && "italic".equals(font.getString(PROP_FONT_STYLE));
        int fontStyle;
        if (isBold && isItalic) {
          fontStyle = Typeface.BOLD_ITALIC;
        } else if (isBold) {
          fontStyle = Typeface.BOLD;
        } else if (isItalic) {
          fontStyle = Typeface.ITALIC;
        } else {
          fontStyle = Typeface.NORMAL;
        }
        // NB: if the font family is null / unsupported, the default one will be used
        paint.setTypeface(Typeface.create(font.getString(PROP_FONT_FAMILY), fontStyle));
      }
    }
  }
}
 
Example 19
Project: Xndroid   File: DrawableUtils.java   View Source Code Vote up 4 votes
@NonNull
public static Bitmap getRoundedNumberImage(int number, int width, int height, int color, int thickness) {
    String text;

    if (number > 99) {
        text = "\u221E";
    } else {
        text = String.valueOf(number);
    }

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(color);
    Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
    paint.setTypeface(boldText);
    paint.setTextSize(Utils.dpToPx(14));
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int radius = Utils.dpToPx(2);

    RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(outer, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    radius--;
    RectF inner = new RectF(thickness, thickness, canvas.getWidth() - thickness, canvas.getHeight() - thickness);
    canvas.drawRoundRect(inner, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int xPos = (canvas.getWidth() / 2);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));

    canvas.drawText(String.valueOf(text), xPos, yPos, paint);

    return image;
}
 
Example 20
Project: betterHotels   File: IconView.java   View Source Code Vote up 4 votes
private void init(Context context, AttributeSet attrs){
    mode = Mode.MEDIUM;
    reactionType = Reaction.LIKE;
    showText = false;
    showTextWhenLarge = false;
    textSize = 0;
    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setStyle(Paint.Style.FILL);
    textColor = Color.parseColor("#FFFFFF");
    textPaint.setColor(textColor);
    textPaint.setTextAlign(Paint.Align.LEFT);
    textBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textBackgroundPaint.setStyle(Paint.Style.FILL);
    textBackgroundColor = Color.parseColor("#000000");
    textBackgroundPaint.setColor(textBackgroundColor);
    textBackgroundPaint.setAlpha(230);
    if(attrs != null){
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IconView, 0, 0);
        int r = a.getInteger(R.styleable.IconView_reaction, 0);
        switch(r){
            default:
            case 0:
                reactionType = Reaction.LIKE;
                break;
            case 1:
                reactionType = Reaction.LOVE;
                break;
            case 2:
                reactionType = Reaction.LAUGH;
                break;
            case 3:
                reactionType = Reaction.WOW;
                break;
            case 4:
                reactionType = Reaction.SAD;
                break;
            case 5:
                reactionType = Reaction.ANGRY;
                break;
        }
    }
    handleImage(context);
}