Android Open Source - WheelView Text Drawable






From Project

Back to project page WheelView.

License

The source code is released under:

Apache License

If you think the Android project WheelView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lukedeighton.wheelsample;
//from ww w . j a va 2  s .co m
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

public class TextDrawable extends Drawable {

    private final String text;
    private final Paint paint;

    public TextDrawable(String text) {

        this.text = text;

        this.paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setTextSize(52f);
        paint.setAntiAlias(true);
        paint.setFakeBoldText(true);
        paint.setShadowLayer(12f, 0, 0, Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.LEFT);
    }

    @Override
    public void draw(Canvas canvas) {
        Rect bounds = getBounds();
        canvas.drawText(text, bounds.centerX() - 15f /*just a lazy attempt to centre the text*/ * text.length(), bounds.centerY() + 15f, paint);
    }

    @Override
    public void setAlpha(int alpha) {
        paint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        paint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}




Java Source Code List

com.lukedeighton.wheelsample.MainActivity.java
com.lukedeighton.wheelsample.MaterialColor.java
com.lukedeighton.wheelsample.TextDrawable.java
com.lukedeighton.wheelview.Circle.java
com.lukedeighton.wheelview.WheelView.java
com.lukedeighton.wheelview.adapter.WheelAdapter.java
com.lukedeighton.wheelview.adapter.WheelArrayAdapter.java
com.lukedeighton.wheelview.transformer.FadingSelectionTransformer.java
com.lukedeighton.wheelview.transformer.ScalingItemTransformer.java
com.lukedeighton.wheelview.transformer.SimpleItemTransformer.java
com.lukedeighton.wheelview.transformer.WheelItemTransformer.java
com.lukedeighton.wheelview.transformer.WheelSelectionTransformer.java