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

The following are Jave code examples for showing how to use setStyle() 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: BilibiliClient   File: OutlineTextView.java   Source Code and License Vote up 6 votes
private void initPaint() {

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(getTextSize());
    mTextPaint.setColor(mColor);
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setTypeface(getTypeface());

    mTextPaintOutline = new TextPaint();
    mTextPaintOutline.setAntiAlias(true);
    mTextPaintOutline.setTextSize(getTextSize());
    mTextPaintOutline.setColor(mBorderColor);
    mTextPaintOutline.setStyle(Paint.Style.STROKE);
    mTextPaintOutline.setTypeface(getTypeface());
    mTextPaintOutline.setStrokeWidth(mBorderSize);
  }
 
Example 2
Project: FancyTrendView   File: TypedTextView.java   Source Code and License Vote up 6 votes
private void init(AttributeSet attrs, int defStyle) {
    this.attrs = attrs;//TODO: check
    this.defStyle = defStyle;

    textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(Color.WHITE);//this.getCurrentTextColor()
    textPaint.setStyle(Paint.Style.FILL);

    cursorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    cursorPaint.setColor(Color.WHITE);

    cursorPaint.setStyle(Paint.Style.FILL);

    cursorTransparentPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    cursorTransparentPaint.setColor(Color.TRANSPARENT);
    cursorPaint.setStyle(Paint.Style.FILL);
    text = this.getText();

    this.postDelayed(new Runnable() {
        @Override
        public void run() {
            prepareAnimate();
        }
    }, 50);

}
 
Example 3
Project: Raffler-Android   File: CustomTextView.java   Source Code and License Vote up 6 votes
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int restoreColor = this.getCurrentTextColor();
    if (strokeColor != null) {
        TextPaint paint = this.getPaint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(strokeJoin);
        paint.setStrokeMiter(strokeMiter);
        this.setTextColor(strokeColor);
        paint.setStrokeWidth(strokeWidth);
        super.onDraw(canvas);
        paint.setStyle(Paint.Style.FILL);
        this.setTextColor(restoreColor);
    }
}
 
Example 4
Project: TPlayer   File: OutlineTextView.java   Source Code and License Vote up 6 votes
private void initPaint() {
  mTextPaint = new TextPaint();
  mTextPaint.setAntiAlias(true);
  mTextPaint.setTextSize(getTextSize());
  mTextPaint.setColor(mColor);
  mTextPaint.setStyle(Paint.Style.FILL);
  mTextPaint.setTypeface(getTypeface());

  mTextPaintOutline = new TextPaint();
  mTextPaintOutline.setAntiAlias(true);
  mTextPaintOutline.setTextSize(getTextSize());
  mTextPaintOutline.setColor(mBorderColor);
  mTextPaintOutline.setStyle(Paint.Style.STROKE);
  mTextPaintOutline.setTypeface(getTypeface());
  mTextPaintOutline.setStrokeWidth(mBorderSize);
}
 
Example 5
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 6
Project: QuanMinTV   File: OutlineTextView.java   Source Code and License Vote up 6 votes
private void initPaint() {
  mTextPaint = new TextPaint();
  mTextPaint.setAntiAlias(true);
  mTextPaint.setTextSize(getTextSize());
  mTextPaint.setColor(mColor);
  mTextPaint.setStyle(Paint.Style.FILL);
  mTextPaint.setTypeface(getTypeface());

  mTextPaintOutline = new TextPaint();
  mTextPaintOutline.setAntiAlias(true);
  mTextPaintOutline.setTextSize(getTextSize());
  mTextPaintOutline.setColor(mBorderColor);
  mTextPaintOutline.setStyle(Paint.Style.STROKE);
  mTextPaintOutline.setTypeface(getTypeface());
  mTextPaintOutline.setStrokeWidth(mBorderSize);
}
 
Example 7
Project: android-slidr   File: Sushi.java   Source Code and License Vote up 6 votes
public Settings(Sushi slidr) {
    this.slidr = slidr;

    paintBar = new Paint();
    paintBar.setAntiAlias(true);
    paintBar.setStrokeWidth(2);
    paintBar.setColor(colorBackground);

    paintTextTop = new TextPaint();
    paintTextTop.setAntiAlias(true);
    paintTextTop.setStyle(Paint.Style.FILL);
    paintTextTop.setColor(textColor);
    paintTextTop.setTextSize(dpToPx(textSize));

    paintTextBubble = new TextPaint();
    paintTextBubble.setAntiAlias(true);
    paintTextBubble.setStyle(Paint.Style.FILL);
    paintTextBubble.setColor(Color.WHITE);
    paintTextBubble.setStrokeWidth(2);
    paintTextBubble.setTextSize(dpToPx(textSizeBubble));

    paintBubble = new Paint();
    paintBubble.setAntiAlias(true);
    paintBubble.setStrokeWidth(3);
}
 
Example 8
Project: LuaViewPlayground   File: WeightStyleSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateDrawState(TextPaint paint) {
    final float newStrokeWidth = (mWeight / (UDFontWeight.WEIGHT_NORMAL_INT + 0.0f));
    if (paint.getStyle() == Paint.Style.FILL) {
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
    }
    paint.setStrokeWidth(newStrokeWidth);
}
 
Example 9
Project: Building-Android-UIs-with-Custom-Views   File: PrimitiveDrawer.java   Source Code and License Vote up 5 votes
public PrimitiveDrawer(Context context, AttributeSet attributeSet) {
    super(context, attributeSet);

    paint = new TextPaint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setColor(0xffffffff);
    paint.setStrokeWidth(1.f);
    paint.setTextSize(35.f);
    paint.setTextAlign(Paint.Align.LEFT);
}
 
Example 10
Project: NovelReader   File: PageLoader.java   Source Code and License Vote up 5 votes
private void initPaint(){
    //绘制提示的画笔
    mTipPaint = new Paint();
    mTipPaint.setColor(mTextColor);
    mTipPaint.setTextAlign(Paint.Align.LEFT);//绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE));//Tip默认的字体大小
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    //绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);

    //绘制标题的画笔
    mTitlePaint = new TextPaint();
    mTitlePaint.setColor(mTextColor);
    mTitlePaint.setTextSize(mTitleSize);
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTitlePaint.setAntiAlias(true);

    //绘制背景的画笔
    mBgPaint = new Paint();
    mBgPaint.setColor(mPageBg);

    mBatteryPaint = new Paint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);
    if (isNightMode){
        mBatteryPaint.setColor(Color.WHITE);
    }
    else {
        mBatteryPaint.setColor(Color.BLACK);
    }
}
 
Example 11
Project: PinView   File: PinView.java   Source Code and License Vote up 5 votes
public PinView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final Resources res = getResources();

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

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.density = res.getDisplayMetrics().density;
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setTextSize(getTextSize());

    mAnimatorTextPaint = new TextPaint(mTextPaint);

    final Resources.Theme theme = context.getTheme();

    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.PinView, defStyleAttr, 0);

    mViewType = a.getInt(R.styleable.PinView_viewType, VIEW_TYPE_RECTANGLE);
    mPinItemCount = a.getInt(R.styleable.PinView_itemCount, DEFAULT_COUNT);
    mPinItemSize = a.getDimensionPixelSize(R.styleable.PinView_itemSize,
            res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_size));
    mPinItemHeight = mPinItemWidth = mPinItemSize;
    if (a.hasValue(R.styleable.PinView_itemHeight)) {
        mPinItemHeight = a.getDimensionPixelOffset(R.styleable.PinView_itemHeight,
                res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_size));
    }
    if (a.hasValue(R.styleable.PinView_itemWidth)) {
        mPinItemWidth = a.getDimensionPixelOffset(R.styleable.PinView_itemWidth,
                res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_size));
    }
    mPinItemSpacing = a.getDimensionPixelOffset(R.styleable.PinView_itemSpacing,
            res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_spacing));
    mPinItemRadius = a.getDimensionPixelOffset(R.styleable.PinView_itemRadius,
            res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_radius));
    mLineWidth = a.getDimensionPixelOffset(R.styleable.PinView_borderWidth,
            res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_line_width));
    mLineColor = a.getColorStateList(R.styleable.PinView_borderColor);
    if (a.hasValue(R.styleable.PinView_lineWidth)) {
        mLineWidth = a.getDimensionPixelOffset(R.styleable.PinView_lineWidth,
                res.getDimensionPixelOffset(R.dimen.pv_pin_view_item_line_width));
    }
    if (a.hasValue(R.styleable.PinView_lineColor)) {
        mLineColor = a.getColorStateList(R.styleable.PinView_lineColor);
    }

    a.recycle();

    setMaxLength(mPinItemCount);
    mPaint.setStrokeWidth(mLineWidth);
    setupAnimator();

    setCursorVisible(false);
    setTextIsSelectable(false);
}
 
Example 12
Project: aos-Video   File: SubtitleTextView.java   Source Code and License Vote up 5 votes
@Override
protected void onDraw(Canvas canvas) {
    Canvas c = canvas;
    if (mExternalSurface != null) {
        try {
            canvas.getClipBounds(r);
            getLocationOnScreen(location);
            r.offsetTo(location[0],location[1]);
            c = mExternalSurface.lockCanvas(null);
            c.save();
            c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
            c.clipRect(r);
            c.translate(location[0],location[1]);
        } catch (Exception ignored) {
        }
    }
    TextPaint paint = getPaint();
    int color = getCurrentTextColor();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.MITER);
    paint.setStrokeMiter(1.0f);
    paint.setStrokeWidth(4.0f);
    setTextColor(Color.BLACK);
    super.onDraw(c);
    paint.setStyle(Paint.Style.FILL);
    setTextColor(color);
    super.onDraw(c);
    if (c != canvas) {
        c.restore();
        mExternalSurface.unlockCanvasAndPost(c);
    }
}
 
Example 13
Project: FastTextView   File: StrokeSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateDrawState(TextPaint tp) {
  if (mDrawStroke) {
    tp.setColor(mStrokeColor);
    tp.setStrokeCap(Paint.Cap.ROUND);
    tp.setStrokeWidth(mStrokeWidth);
    tp.setStyle(Paint.Style.STROKE);
  } else {
    tp.setColor(mTextColor);
    tp.setStyle(Paint.Style.FILL);
  }
}
 
Example 14
Project: snippety   File: MultiColorSpan.java   Source Code and License Vote up 5 votes
@Override
public void updateDrawState(TextPaint paint) {
    paint.setStyle(Paint.Style.FILL);
    Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
            Shader.TileMode.MIRROR);
    Matrix matrix = new Matrix();
    matrix.setRotate(angle);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
}
 
Example 15
Project: android-slidr   File: Slidr.java   Source Code and License Vote up 5 votes
public Settings(Slidr slidr) {
    this.slidr = slidr;

    paintIndicator = new Paint();
    paintIndicator.setAntiAlias(true);
    paintIndicator.setStrokeWidth(2);

    paintBar = new Paint();
    paintBar.setAntiAlias(true);
    paintBar.setStrokeWidth(2);
    paintBar.setColor(colorBackground);

    paintStep = new Paint();
    paintStep.setAntiAlias(true);
    paintStep.setStrokeWidth(5);
    paintStep.setColor(colorStoppover);

    paintTextTop = new TextPaint();
    paintTextTop.setAntiAlias(true);
    paintTextTop.setStyle(Paint.Style.FILL);
    paintTextTop.setColor(textColor);
    paintTextTop.setTextSize(textTopSize);

    paintTextBottom = new TextPaint();
    paintTextBottom.setAntiAlias(true);
    paintTextBottom.setStyle(Paint.Style.FILL);
    paintTextBottom.setColor(textColor);
    paintTextBottom.setTextSize(textBottomSize);

    paintBubbleTextCurrent = new TextPaint();
    paintBubbleTextCurrent.setAntiAlias(true);
    paintBubbleTextCurrent.setStyle(Paint.Style.FILL);
    paintBubbleTextCurrent.setColor(Color.WHITE);
    paintBubbleTextCurrent.setStrokeWidth(2);
    paintBubbleTextCurrent.setTextSize(dpToPx(textSizeBubbleCurrent));

    paintBubble = new Paint();
    paintBubble.setAntiAlias(true);
    paintBubble.setStrokeWidth(3);
}
 
Example 16
Project: WavePullLayout   File: HeaderLayout.java   Source Code and License Vote up 5 votes
private void init() {
    float dSize = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_SP,
            15,
            getContext().getResources().getDisplayMetrics());
    tBuilder = new StringBuilder("");
    setText("");
    mTpaint = new TextPaint();
    mTpaint.setColor(Color.BLUE);
    mTpaint.setAntiAlias(true);
    mTpaint.setTextSize(dSize);
    mTpaint.setStyle(Paint.Style.FILL);
    tRect = new Rect();
    setWillNotDraw(false);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setFilterBitmap(true);
    camera = new Camera();
    matrix = new Matrix();
    mPath = new Path();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mViewOutlineProvider = new ViewOutlineProvider() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                if (mPath.isConvex()) outline.setConvexPath(mPath);
            }
        };

    }
}
 
Example 17
Project: MuslimMateAndroid   File: AzkarActivity.java   Source Code and License Vote up 4 votes
/**
 * Share Button Click.
 * get hadith text and create bitmap with hadith text and share it.
 */
private void onShareButtonClicked(String subject, String body) {
    // check if app grant write external storage permission.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // check permission for marshmellow.
        if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            // Camera permission has not been granted.
            // Camera permission has not been granted yet. Request it directly.
            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
            return;
        }
    }
    // create image from hadith and try share it
    Resources resources = getResources();
    // Create background bitmap
    Bitmap backgroundBitmap = BitmapFactory.decodeResource(resources, R.drawable.backgroundtile);
    Bitmap.Config config = backgroundBitmap.getConfig();
    if (config == null) {
        config = Bitmap.Config.ARGB_8888;
    }

    int width = 600 + (body.length() / 512) * 50;//backgroundBitmap.getWidth();

    // Create logo bitmap
    Bitmap logoBitmap = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher);
    logoBitmap = Bitmap.createScaledBitmap(logoBitmap, 128, 128, false);
    logoBitmap = logoBitmap.copy(config, false);
    int padding = 15;

    // Initiate text paint objects
    TextPaint titleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    titleTextPaint.setStyle(Paint.Style.FILL);
    titleTextPaint.setTextSize(28);
    titleTextPaint.setColor(Color.rgb(64, 0, 0));
    titleTextPaint.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "fonts/simple.otf"));
    StaticLayout titleStaticLayout = new StaticLayout("منظم المسلم" + "\n" + subject, titleTextPaint, width - 3 * padding - logoBitmap.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1.4f, 0.1f, false);
    TextPaint matnTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    matnTextPaint.setStyle(Paint.Style.FILL);
    matnTextPaint.setTextSize(30);
    matnTextPaint.setColor(Color.BLACK);
    matnTextPaint.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "fonts/simple.otf"));
    StaticLayout matnStaticLayout = new StaticLayout(body + "\n", matnTextPaint, width - 2 * padding, Layout.Alignment.ALIGN_CENTER, 1.4f, 0.1f, false);
    int height = padding + Math.max(titleStaticLayout.getHeight(), logoBitmap.getHeight()) + padding + matnStaticLayout.getHeight() + padding;

    Bitmap bitmap = backgroundBitmap.copy(config, true);
    bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);

    // create canvas and draw text on image.
    Canvas canvas = new Canvas(bitmap);
    canvas.save();
    tileBitmap(canvas, backgroundBitmap);
    canvas.drawBitmap(logoBitmap, width - padding - logoBitmap.getWidth(), padding, null);
    canvas.translate(padding, 2 * padding);
    titleStaticLayout.draw(canvas);
    canvas.translate(0, padding + logoBitmap.getHeight());
    matnStaticLayout.draw(canvas);
    canvas.restore();

    // share bitmap.
    shareImage(bitmap);
}
 
Example 18
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();
    }