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

The following examples show how to use android.graphics.Paint#setTextAlign() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartView.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * initialize the internal objects.
 * This method has to be called directly
 * in the constructors.
 */
protected void init() {
    mPreviewPaint = new Paint();
    mPreviewPaint.setTextAlign(Paint.Align.CENTER);
    mPreviewPaint.setColor(Color.BLACK);
    mPreviewPaint.setTextSize(50);

    mStyles = new Styles();
    mViewport = new Viewport(this);
    mGridLabelRenderer = new GridLabelRenderer(this);
    mLegendRenderer = new LegendRenderer(this);

    mSeries = new ArrayList<>();
    mPaintTitle = new Paint();

    mTapDetector = new TapDetector();

    loadStyles();
}
 
Example 2
Source File: FlowViewHorizontal.java    From StepView with Apache License 2.0 6 votes vote down vote up
private void init() {
    bgPaint = new Paint();
    bgPaint.setAntiAlias(true);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setColor(bgColor);
    bgPaint.setStrokeWidth(lineBgWidth);
    bgPaint.setTextSize(textSize);
    bgPaint.setTextAlign(Paint.Align.CENTER);

    proPaint = new Paint();
    proPaint.setAntiAlias(true);
    proPaint.setStyle(Paint.Style.FILL);
    proPaint.setColor(proColor);
    proPaint.setStrokeWidth(lineProWidth);
    proPaint.setTextSize(textSize);
    proPaint.setTextAlign(Paint.Align.CENTER);

}
 
Example 3
Source File: MjpegView.java    From Garage48-PiTank with GNU General Public License v2.0 6 votes vote down vote up
private void init(Context context) {

		this.context = context;
		SurfaceHolder holder = getHolder();
		holder.addCallback(this);
		thread = new MjpegViewThread(holder, context);
		setFocusable(true);
		if (!resume) {
			resume = true;
			overlayPaint = new Paint();
			overlayPaint.setTextAlign(Paint.Align.LEFT);
			overlayPaint.setTextSize(12);
			overlayPaint.setTypeface(Typeface.DEFAULT);
			overlayTextColor = Color.WHITE;
			overlayBackgroundColor = Color.BLACK;
			ovlPos = MjpegView.POSITION_LOWER_RIGHT;
			displayMode = MjpegView.SIZE_STANDARD;
			dispWidth = getWidth();
			dispHeight = getHeight();
		}
	}
 
Example 4
Source File: TileCoordinateDemoActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
private Bitmap drawTileCoords(int x, int y, int zoom) {
    // Synchronize copying the bitmap to avoid a race condition in some devices.
    Bitmap copy = null;
    synchronized (borderTile) {
        copy = borderTile.copy(android.graphics.Bitmap.Config.ARGB_8888, true);
    }
    Canvas canvas = new Canvas(copy);
    String tileCoords = "(" + x + ", " + y + ")";
    String zoomLevel = "zoom = " + zoom;
    /* Paint is not thread safe. */
    Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTextSize(18 * scaleFactor);
    canvas.drawText(tileCoords, TILE_SIZE_DP * scaleFactor / 2,
            TILE_SIZE_DP * scaleFactor / 2, mTextPaint);
    canvas.drawText(zoomLevel, TILE_SIZE_DP * scaleFactor / 2,
            TILE_SIZE_DP * scaleFactor * 2 / 3, mTextPaint);
    return copy;
}
 
Example 5
Source File: DountChart01View.java    From XCL-Charts with Apache License 2.0 6 votes vote down vote up
private void addAttrInfo()
{
	/////////////////////////////////////////////////////////////
	//设置附加信息
	Paint paintTB = new Paint();
	paintTB.setColor(Color.GRAY);
	paintTB.setTextAlign(Align.CENTER);
	paintTB.setTextSize(25);			
	chart.getPlotAttrInfo().addAttributeInfo(XEnum.Location.TOP, "九月的手机,", 0.5f, paintTB);			
	chart.getPlotAttrInfo().addAttributeInfo(XEnum.Location.BOTTOM, "绝对不够......", 0.5f, paintTB);
	
	Paint paintLR = new Paint();		
	paintLR.setTextAlign(Align.CENTER);
	paintLR.setTextSize(25);
	paintLR.setColor(Color.rgb(191, 79, 75));			
	chart.getPlotAttrInfo().addAttributeInfo(XEnum.Location.LEFT, "性能高!", 0.5f, paintLR);			
	chart.getPlotAttrInfo().addAttributeInfo(XEnum.Location.RIGHT, "诱惑大!", 0.5f, paintLR);
	
	Paint paintBase = new Paint();		
	paintBase.setTextAlign(Align.CENTER);
	paintBase.setTextSize(25);
	paintBase.setColor(Color.rgb(242, 167, 69));
	chart.getPlotAttrInfo().addAttributeInfo(XEnum.Location.BOTTOM, 
							"一个肾,", 0.3f, paintBase);		
	/////////////////////////////////////////////////////////////
}
 
Example 6
Source File: MenuCounterDrawable.java    From RetailStore with Apache License 2.0 6 votes vote down vote up
public MenuCounterDrawable(Context context) {
    // mTextSize = context.getResources().getDimension(R.dimen.badge_text_size);
    mTextSize = 18F;

    mBadgePaint = new Paint();
    mBadgePaint.setColor(Color.RED);
    mBadgePaint.setAntiAlias(true);
    mBadgePaint.setStyle(Paint.Style.FILL);

    mTextPaint = new Paint();
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
}
 
Example 7
Source File: DrawableUtils.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a rounded square of a certain color with
 * a character imprinted in white on it.
 *
 * @param character the character to write on the image.
 * @param width     the width of the final image.
 * @param height    the height of the final image.
 * @param color     the background color of the rounded square.
 * @return a valid bitmap of a rounded square with a character on it.
 */
@NonNull
public static Bitmap getRoundedLetterImage(@NonNull Character character, int width, int height, int color) {
    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);

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

    paint.setColor(Color.WHITE);
    canvas.drawText(character.toString(), xPos, yPos, paint);

    return image;
}
 
Example 8
Source File: ColorPickerView.java    From HomeGenie-Android with GNU General Public License v3.0 5 votes vote down vote up
private void initPaintTools(){
	
	mSatValPaint = new Paint();
	mSatValTrackerPaint = new Paint();
	mHuePaint = new Paint();
	mHueAlphaTrackerPaint = new Paint();
	mAlphaPaint = new Paint();
	mAlphaTextPaint = new Paint();
	mBorderPaint = new Paint();
	
	
	mSatValTrackerPaint.setStyle(Style.STROKE);
	mSatValTrackerPaint.setStrokeWidth(2f * mDensity);
	mSatValTrackerPaint.setAntiAlias(true);
	
	mHueAlphaTrackerPaint.setColor(mSliderTrackerColor);
	mHueAlphaTrackerPaint.setStyle(Style.STROKE);
	mHueAlphaTrackerPaint.setStrokeWidth(2f * mDensity);
	mHueAlphaTrackerPaint.setAntiAlias(true);
	
	mAlphaTextPaint.setColor(0xff1c1c1c);
	mAlphaTextPaint.setTextSize(14f * mDensity);
	mAlphaTextPaint.setAntiAlias(true);
	mAlphaTextPaint.setTextAlign(Align.CENTER);
	mAlphaTextPaint.setFakeBoldText(true);

}
 
Example 9
Source File: GridLabelRenderer.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * will load the styles to the internal
 * paint objects (color, text size, text align)
 */
public void reloadStyles() {
    mPaintLine = new Paint();
    mPaintLine.setColor(mStyles.gridColor);
    mPaintLine.setStrokeWidth(0);

    mPaintLabel = new Paint();
    mPaintLabel.setTextSize(getTextSize());
    mPaintLabel.setAntiAlias(true);

    mPaintAxisTitle = new Paint();
    mPaintAxisTitle.setTextSize(getTextSize());
    mPaintAxisTitle.setTextAlign(Paint.Align.CENTER);
}
 
Example 10
Source File: CaptionMapObject.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
public CaptionMapObject(Object id, Drawable drawable, Point position,
		Point pivotPoint, boolean isTouchable, boolean isScalable) {
	super(id, drawable, position, pivotPoint, isTouchable, isScalable);
	
	paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	paint.setColor(Color.WHITE);
	paint.setTextAlign(Align.CENTER);
	paint.setTextSize(14);
	paint.setTypeface(Typeface.SANS_SERIF);
	paint.setFakeBoldText(true);
	paint.setShadowLayer(1, 0, 0, Color.BLACK);
}
 
Example 11
Source File: ArrayView.java    From DS4Android with MIT License 5 votes vote down vote up
private void init() {
    //初始化主画笔
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.BLUE);
    mPaint.setStrokeWidth(5);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(50);
    //初始化主路径
    mPath = new Path();
    //初始化文字画笔
    mTxtPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTxtPaint.setColor(Color.WHITE);
    mTxtPaint.setTextAlign(Paint.Align.CENTER);
    mTxtPaint.setTextSize(40);
    //初始化路径画笔
    mPathPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPathPaint.setColor(Color.GRAY);
    mPathPaint.setStyle(Paint.Style.STROKE);
    mCooPicture = HelpDraw.getCoo(getContext(), mCoo, false);
    mGridPicture = HelpDraw.getGrid(getContext());
    //初始化圆球按钮画笔
    mCtrlPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCtrlPaint.setColor(Color.RED);
    mCtrlPaint.setTextAlign(Paint.Align.CENTER);
    mCtrlPaint.setTextSize(30);
    //初始化时间流ValueAnimator
    mAnimator = ValueAnimator.ofFloat(0, 1);
    mAnimator.setRepeatCount(-1);
    mAnimator.setDuration(2000);
    mAnimator.setRepeatMode(ValueAnimator.REVERSE);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.addUpdateListener(animation -> {
        updateBall();//更新小球位置
        invalidate();
    });
}
 
Example 12
Source File: TextBuilder.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void initParams(Context context)
{
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(Color.BLACK);
    mTextPaint.setDither(true);
    mTextPaint.setFilterBitmap(true);
    mTextPaint.setTextSize(getAllSize());
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setTextAlign(Paint.Align.LEFT);

    //默认值
    mTextChars = DEFAULT_TEXT;
}
 
Example 13
Source File: HomeArc.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public void init(int score) {
	this.score = score;
	Resources res = getResources();
	tb = res.getDimension(R.dimen.historyscore_tb);

	paint_black = new Paint();
	paint_black.setAntiAlias(true);
	paint_black.setColor(blackColor);
	paint_black.setStrokeWidth(tb * 0.2f);
	paint_black.setStyle(Style.STROKE);

	paint_white = new Paint();
	paint_white.setAntiAlias(true);
	paint_white.setColor(whiteColor);
	paint_white.setTextSize(tb*6.0f);
	paint_white.setStrokeWidth(tb * 0.2f);
	paint_white.setTextAlign(Align.CENTER);
	paint_white.setStyle(Style.STROKE);

	rectf = new RectF();
	rectf.set(tb * 0.5f, tb * 0.5f, tb * 18.5f, tb * 18.5f);

	setLayoutParams(new LayoutParams((int) (tb * 19.5f), (int) (tb * 19.5f)));

	this.getViewTreeObserver().addOnPreDrawListener(
			new OnPreDrawListener() {
				public boolean onPreDraw() {
					new thread();
					getViewTreeObserver().removeOnPreDrawListener(this);
					return false;
				}
			});
}
 
Example 14
Source File: Satellite2DView.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
private void setBasics() {
    this.drawLock = false;
    space = Utils.getDpPixels(6.0f);

    // background image
    bitCompassBg = Images.getImageD(R.drawable.var_skyplot);

    // load other images
    int imgSize = (int) Utils.getDpPixels(20);
    satImages = new Bitmap[3];
    satImages[0] = Images.getImageB(R.drawable.ic_sat_01, imgSize);
    satImages[1] = Images.getImageB(R.drawable.ic_sat_02, imgSize);
    satImages[2] = Images.getImageB(R.drawable.ic_sat_03, imgSize);

    mPaintBitmap = new Paint();
    mPaintBitmap.setAntiAlias(true);
    mPaintBitmap.setFilterBitmap(true);

    mPaintText = new Paint();
    mPaintText.setAntiAlias(true);
    mPaintText.setTextAlign(Align.CENTER);
    mPaintText.setTextSize(SAT_TEXT_SIZE);
    mPaintText.setShadowLayer(SAT_TEXT_SIZE / 4.0f, 0, 0, Color.WHITE);

    mPaintSignalLine = new Paint();
    mPaintSignalLine.setAntiAlias(true);
    mPaintSignalLine.setStyle(Style.STROKE);
    mPaintSignalLine.setStrokeWidth(2.0f);
    mPaintSignalLine.setColor(Color.GRAY);
}
 
Example 15
Source File: StretchPainter.java    From NCalendar with Apache License 2.0 5 votes vote down vote up
private Paint getPaint() {
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setTextAlign(Paint.Align.CENTER);
    return paint;
}
 
Example 16
Source File: MonthView.java    From MonthAndYearPicker with MIT License 5 votes vote down vote up
/**
 * Sets up the text and style properties for painting.
 */
private void initView() {

    _monthNumberSelectedPaint = new Paint();
    _monthNumberSelectedPaint.setAntiAlias(true);
    if (_monthBgSelectedColor != 0)
        _monthNumberSelectedPaint.setColor(_monthBgSelectedColor);
    // _monthNumberSelectedPaint.setAlpha(200);
    _monthNumberSelectedPaint.setTextAlign(Paint.Align.CENTER);
    _monthNumberSelectedPaint.setStyle(Paint.Style.FILL);
    _monthNumberSelectedPaint.setFakeBoldText(true);

    _monthNumberPaint = new Paint();
    _monthNumberPaint.setAntiAlias(true);
    if (_monthFontColorNormal != 0)
        _monthNumberPaint.setColor(_monthFontColorNormal);
    _monthNumberPaint.setTextSize(_monthTextSize);
    _monthNumberPaint.setTextAlign(Paint.Align.CENTER);
    _monthNumberPaint.setStyle(Paint.Style.FILL);
    _monthNumberPaint.setFakeBoldText(false);

    _monthNumberDisabledPaint = new Paint();
    _monthNumberDisabledPaint.setAntiAlias(true);
    if (_monthFontColorDisabled != 0)
        _monthNumberDisabledPaint.setColor(_monthFontColorDisabled);
    _monthNumberDisabledPaint.setTextSize(_monthTextSize);
    _monthNumberDisabledPaint.setTextAlign(Paint.Align.CENTER);
    _monthNumberDisabledPaint.setStyle(Paint.Style.FILL);
    _monthNumberDisabledPaint.setFakeBoldText(false);
}
 
Example 17
Source File: BatteryMeterView.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
public NormalBatteryMeterDrawable(Resources res) {
    super();
    mDisposed = false;

    mFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mFramePaint.setColor(res.getColor(R.color.batterymeter_frame_color));
    mFramePaint.setDither(true);
    mFramePaint.setStrokeWidth(0);
    mFramePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mFramePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));

    mBatteryPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBatteryPaint.setDither(true);
    mBatteryPaint.setStrokeWidth(0);
    mBatteryPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    mWarningTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mWarningTextPaint.setColor(mColors[1]);
    Typeface font = Typeface.create("sans-serif", Typeface.BOLD);
    mWarningTextPaint.setTypeface(font);
    mWarningTextPaint.setTextAlign(Paint.Align.CENTER);

    mBoltPaint = new Paint();
    mBoltPaint.setAntiAlias(true);
    mBoltPaint.setColor(res.getColor(R.color.batterymeter_bolt_color));
    mBoltPoints = loadBoltPoints(res);
}
 
Example 18
Source File: TimeActivity.java    From Primary with GNU General Public License v3.0 4 votes vote down vote up
private Bitmap getClockBitmap(int hour, int minute, int second) {
    Paint black = new Paint();
    black.setARGB(255,0,0,0);
    black.setStrokeWidth(mClockwidth /60);
    black.setStyle(Paint.Style.STROKE);

    Paint hourColor = new Paint();
    hourColor.setARGB(255,0,0,200);
    hourColor.setStrokeWidth(mClockwidth /40);
    hourColor.setStyle(Paint.Style.STROKE);


    //System.out.println(mClockwidth);
    Paint hourColorThin = new Paint(hourColor);
    hourColorThin.setStrokeWidth(3);
    hourColorThin.setTextSize(Math.min(28, mClockwidth/8));
    hourColorThin.setTextAlign(Paint.Align.CENTER);

    Paint minuteColor = new Paint();
    minuteColor.setARGB(255,0,200,0);
    minuteColor.setStrokeWidth(mClockwidth /52);
    minuteColor.setStyle(Paint.Style.STROKE);

    Paint minuteColorThin = new Paint(minuteColor);
    minuteColorThin.setStrokeWidth(3);


    Paint secondColor = new Paint();
    secondColor.setARGB(255,180,0,64);
    secondColor.setStrokeWidth(2);
    secondColor.setStyle(Paint.Style.STROKE);

    int centerX = mClockwidth /2;
    int centerY = mClockwidth /2;
    int radius = mClockwidth /2 - 10;

    double hourRadian = 2 * Math.PI / 12;
    double minuteRadian = 2 * Math.PI / 60;
    double secondRadian = 2 * Math.PI / 60;

    Bitmap bitmap = Bitmap.createBitmap(mClockwidth, mClockwidth, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    for (int mintick=1; mintick<=60; mintick++) {

        float dX = (float)(Math.cos(minuteRadian * mintick - Math.PI/2));
        float dY = (float)(Math.sin(minuteRadian * mintick- Math.PI/2));

        canvas.drawLine(centerX + dX*radius, centerY + dY*radius, centerX + dX*(radius-10), centerY + dY*(radius-10), minuteColorThin);
        if (mintick % 5 == 0) {
            float iX = centerX + dX * (radius - 15);
            float iY = centerY + dY * (radius - 15);
            float itX = centerX + dX * (radius - 30);
            float itY = centerY + dY * (radius - 30) + 10;
            canvas.drawLine(centerX + dX * radius, centerY + dY * radius, iX, iY, hourColorThin);
            canvas.drawText((mintick/5)+"", itX, itY, hourColorThin);

        }
    }

    double hourAdj = minute/60.0;

    float hX = (float)(Math.cos(hourRadian * (hour+hourAdj) - Math.PI/2) * (radius*.5));
    float hY = (float)(Math.sin(hourRadian * (hour+hourAdj) - Math.PI/2) * (radius*.5));
    canvas.drawLine(centerX, centerY, centerX+hX, centerY+hY, hourColor);

    double minuteAdj = 0;
    if (second!=-1) {
        minuteAdj = second/60.0;
    }

    float mX = (float)(Math.cos(minuteRadian * (minute+minuteAdj) - Math.PI/2) * (radius*.8));
    float mY = (float)(Math.sin(minuteRadian * (minute+minuteAdj) - Math.PI/2) * (radius*.8));
    canvas.drawLine(centerX, centerY, centerX+mX, centerY+mY, minuteColor);

    if (second!=-1) {
        float sX = (float) (Math.cos(secondRadian * second - Math.PI / 2) * (radius * .95));
        float sY = (float) (Math.sin(secondRadian * second - Math.PI / 2) * (radius * .95));
        canvas.drawLine(centerX, centerY, centerX + sX, centerY + sY, secondColor);
    }

    canvas.drawCircle(centerX, centerY, 4, black);
    canvas.drawCircle(centerX, centerY, radius, black);
    return bitmap;
}
 
Example 19
Source File: XyzRuler.java    From XyzInfo with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.XyzRuler);
    borderWidth = ta.getDimension(R.styleable.XyzRuler_rBorderWidth, 8);
    lineWidth = ta.getDimension(R.styleable.XyzRuler_rLineWidth, 2.0f);
    borderColor = ta.getColor(R.styleable.XyzRuler_rBorderColor, Color.BLUE);
    lineColor = ta.getColor(R.styleable.XyzRuler_rLineColor, Color.WHITE);
    trigonSize = (int) ta.getDimension(R.styleable.XyzRuler_rTrigonSize, 20);
    pixel = ta.getInt(R.styleable.XyzRuler_rPixel, 15);
    step = ta.getInt(R.styleable.XyzRuler_rStep, 1);
    int textSize = (int) ta.getDimension(R.styleable.XyzRuler_rTextSize, 30);
    int textColor = ta.getColor(R.styleable.XyzRuler_rTextColor, Color.WHITE);
    lineHeight = (int) ta.getDimension(R.styleable.XyzRuler_rLineHeight, 25);
    lineToText = (int) ta.getDimension(R.styleable.XyzRuler_rLineToText, 35);
    begin = ta.getInt(R.styleable.XyzRuler_rBegin, 0);
    selectItem = begin;
    end = ta.getInt(R.styleable.XyzRuler_rEnd, 1000);
    minVelocity = ta.getInt(R.styleable.XyzRuler_rMinVelocity, 500);
    animTime = ta.getInt(R.styleable.XyzRuler_rAnimTime, 300);
    indicateHeight = (int) ta.getDimension(R.styleable.XyzRuler_rIndicateHeight, 0);
    isRect = ta.getBoolean(R.styleable.XyzRuler_rIsRect, true);
    isTop = ta.getBoolean(R.styleable.XyzRuler_rIsTop, true);
    ta.recycle();
    scroller = new Scroller(context);
    setOverScrollMode(OVER_SCROLL_ALWAYS);

    lPaint = new Paint();
    lPaint.setAntiAlias(true);
    lPaint.setColor(lineColor);
    lPaint.setStrokeWidth(lineWidth);

    bPaint = new Paint();
    bPaint.setAntiAlias(true);
    bPaint.setStyle(Paint.Style.STROKE);
    bPaint.setStrokeWidth(borderWidth);
    bPaint.setColor(borderColor);

    tPaint = new Paint();
    tPaint.setAntiAlias(true);
    tPaint.setTextAlign(Paint.Align.CENTER);
    tPaint.setColor(textColor);
    tPaint.setTextSize(textSize);
    tPaint.setStyle(Paint.Style.FILL);

    sPaint = new Paint();
    sPaint.setAntiAlias(true);
    sPaint.setStyle(Paint.Style.FILL);
    sPaint.setStrokeWidth(borderWidth);
    sPaint.setColor(borderColor);

    sumPixel = ((end - begin) / step) * pixel;

    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (null != onSelectItem) {
                selectItem = onSelectItem.setSelectItem();
            }
            selectItem();
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });

}
 
Example 20
Source File: DialView.java    From android-dial-picker with Apache License 2.0 4 votes vote down vote up
/**
 * @param attrs   are the attributes containing the values given by user
 * @param context context of the activity to use this view class
 */

private void init(AttributeSet attrs, Context context) {
    paintInnerCircle = new Paint();
    paintArc = new Paint();
    paintLines = new Paint();
    paintText = new Paint();

    paintArc.setStyle(Paint.Style.STROKE);
    paintArc.setPathEffect(new DashPathEffect(new float[]{5, 10}, 0));
    paintLines.setAntiAlias(true);
    paintText.setTextAlign(Paint.Align.RIGHT);


    if (attrs != null) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DialView);
        lineInterval = typedArray.getInt(R.styleable.DialView_lineInterval, 0);
        maxValue = typedArray.getInt(R.styleable.DialView_maxValue, 0);
        minValue = typedArray.getInt(R.styleable.DialView_minValue, 0);
        leastCount = typedArray.getInt(R.styleable.DialView_leastCount, 0);
        centerPadding = typedArray.getInt(R.styleable.DialView_centerPadding, 0);
        textSize = typedArray.getInt(R.styleable.DialView_textSize, 0);
        dialDirection = typedArray.getInt(R.styleable.DialView_dialDirection, 0);
        tickGapAngle = ((double) typedArray.getInt(R.styleable.DialView_tickGapAngle, 0)
                / (double) 180) * PI;
        startColor = typedArray.getColor(R.styleable.DialView_startColor, 0);
        endColor = typedArray.getColor(R.styleable.DialView_endColor, 0);
        paintLineColor = typedArray.getColor(R.styleable.DialView_paintLineColor, 0);
        paintTextColor = typedArray.getColor(R.styleable.DialView_paintTextColor, 0);
        paintArcColor = typedArray.getColor(R.styleable.DialView_paintArcColor, 0);
        typedArray.recycle();
    }

    if (minValue >= maxValue) {
        maxValue = minValue;
        minValue = 0;
    }

    paintInnerCircle.setStyle(Paint.Style.FILL);
    paintInnerCircle.setFilterBitmap(true);
    paintInnerCircle.setShader(new LinearGradient(0, 0, 0, getHeight(), endColor, startColor, Shader.TileMode.CLAMP));
    paintLines.setColor(paintLineColor);
    paintText.setColor(paintTextColor);
    paintArc.setColor(paintArcColor);

    switch (dialDirection) {
        //for left
        case 1:
            currentTheta = 0;
            initTheta = 0;
            angleToCompare = 0;
            break;
        //for top
        case 2:
            currentTheta = PI / 2;
            initTheta = PI / 2;
            angleToCompare = 90;
            break;
        //for right
        case 3:
            currentTheta = PI;
            initTheta = PI;
            angleToCompare = 180;
            break;
        //for bottom
        case 4:
            currentTheta = PI * 3 / 2;
            initTheta = PI * 3 / 2;
            angleToCompare = 270;
            break;

        default:
            // // TODO: 4/5/17 nothing
            break;
    }
    paintText.setTextSize(textSize);
}