Example usage for android.graphics Paint setTextAlign

List of usage examples for android.graphics Paint setTextAlign

Introduction

In this page you can find the example usage for android.graphics Paint setTextAlign.

Prototype

public void setTextAlign(Align align) 

Source Link

Document

Set the paint's text alignment.

Usage

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) {
    RectF faceRect = new RectF();
    faceRect.set(10, 10, 190, 190);//w ww  .j a  v  a  2s  .  c o m

    Paint scalePaint = new Paint();
    scalePaint.setStyle(Paint.Style.STROKE);
    scalePaint.setColor(getResources().getColor(R.color.WarningGreen));
    scalePaint.setStrokeWidth(1);
    scalePaint.setAntiAlias(true);

    scalePaint.setTextSize(12);
    scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf"));
    scalePaint.setTextAlign(Paint.Align.CENTER);

    float scalePosition = 10;
    RectF scaleRect = new RectF();
    scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition,
            faceRect.bottom - scalePosition);

    if (!Colors)
        scalePaint.setColor(Color.WHITE);

    scalePaint.setStrokeWidth(2);
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    for (int i = 0; i < Max; ++i) {
        if (Colors) {
            if (i > 20)
                scalePaint.setColor(getResources().getColor(R.color.WarningYellow));

            if (i > 40)
                scalePaint.setColor(getResources().getColor(R.color.WarningOrange));

            if (i > 60)
                scalePaint.setColor(getResources().getColor(R.color.WarningRed));
        }

        canvas.drawLine(100, 20, 100, 18, scalePaint);
        int divisor = 5;

        if (Max > 100)
            divisor = 25;

        if (i % divisor == 0) {
            canvas.drawText(Integer.toString(i), 100, 16, scalePaint);
        }

        canvas.rotate((360.0f / Max), 100, 100);
    }

    canvas.restore();
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawHKPrice(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from  www.j av  a  2  s  .  co m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wb")<0)
            //               paint.setColor(GlobalColor.colorPriceDown);
            //            else if(jo.getDouble("wb")>0)
            //               paint.setColor(GlobalColor.colorpriceUp);
            //            else 
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 3);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            //            canvas.drawText("", x, y, paint);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wc")<0) {
            //               paint.setColor(GlobalColor.colorPriceDown);
            //               canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint);
            //            }
            //            else if(jo.getDouble("wc")>0) {
            //               paint.setColor(GlobalColor.colorpriceUp);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            //            else {
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText("", x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

private void drawQihuo(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*w w  w.jav  a  2 s .  com*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x-tips, y, paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint);

            canvas.translate(0, -DY * 4);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            canvas.translate(width / 2, -DY * 5);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("dt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x-tips, y, paint);   

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawPrice(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*  w ww. j a v a 2  s.c om*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            int syjd = jo.getInt("syjd");
            switch (syjd) {
            case 1:
                canvas.drawText("()", x, y, paint);
                break;
            case 2:
                canvas.drawText("()", x, y, paint);
                break;
            case 3:
                canvas.drawText("()", x, y, paint);
                break;
            case 4:
                canvas.drawText("()", x, y, paint);
                break;
            default:
                canvas.drawText("", x, y, paint);
                break;
            }

            if (jo.getDouble("wb") < 0)
                paint.setColor(GlobalColor.colorPriceDown);
            else if (jo.getDouble("wb") > 0)
                paint.setColor(GlobalColor.colorpriceUp);
            else
                paint.setColor(GlobalColor.colorPriceEqual);
            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            if (jo.getInt("tp") == 1)
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x - tips, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 5);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            if (NameRule.isBond(type))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText("PE()", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            if (jo.getDouble("wc") < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
                canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x - tips, y,
                        paint);
            } else if (jo.getDouble("wc") > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
                canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x - tips, y, paint);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
                canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), false), x - tips, y, paint);
            }
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("gb"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint);
            canvas.translate(0, DY);
            if (NameRule.isBond(type)) {
                canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint);
            } else {
                canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint);
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

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

private void init() {
    mSolidColor = 0;//from   w w w  .j  a  v  a  2s . c o m
    mSelectionDivider = new ColorDrawable(ContextCompat.getColor(getContext(), R.color.colorAccent) & 0x00ffffff
            | (0x9f << 24)) /*getResources().getDrawable(R.drawable.numberpicker_selection_divider)*/;

    mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
    mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());

    mMinHeight = SIZE_UNSPECIFIED;

    mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180,
            getResources().getDisplayMetrics());
    if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
        throw new IllegalArgumentException("minHeight > maxHeight");
    }

    mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64,
            getResources().getDisplayMetrics());

    mMaxWidth = SIZE_UNSPECIFIED;
    if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
        throw new IllegalArgumentException("minWidth > maxWidth");
    }

    mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);

    mVirtualButtonPressedDrawable = getResources().getDrawable(R.drawable.item_background_holo_light);

    mPressedStateHelper = new PressedStateHelper();

    setWillNotDraw(false);

    mInputText = new TextView(getContext());
    addView(mInputText);
    mInputText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mInputText.setGravity(Gravity.CENTER);
    mInputText.setSingleLine(true);
    mInputText.setBackgroundResource(0);
    mInputText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mTextSize = (int) mInputText.getTextSize();

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(mTextSize);
    paint.setTypeface(mInputText.getTypeface());
    ColorStateList colors = mInputText.getTextColors();
    int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
    paint.setColor(color);
    mSelectorWheelPaint = paint;

    mFlingScroller = new Scroller(getContext(), null, true);
    mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));

    updateInputTextView();
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initText(Paint paint, int height, int color, Paint.Align align) {
    paint.setColor(color);/*from  w  ww.  ja v a2  s  .  co m*/
    paint.setTextSize(height);
    paint.setTextAlign(align);
}

From source file:com.cssweb.android.view.KlineMini.java

public void drawQuoteWin(Canvas canvas, JSONObject quoteData, int idx) throws JSONException {
    Paint mPaint = new Paint();
    mPaint.setTextAlign(Paint.Align.LEFT);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mPaint.setAntiAlias(true);//from   ww w  .j  a v a 2s.  co  m

    mPaint.setColor(GlobalColor.colorKlinePopub);
    mPaint.setTextSize(sTextSize);
    canvas.drawText(":", 0, axisLabelHeight, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 3, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 5, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 7, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 9, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 11, mPaint);

    mPaint.setTextAlign(Paint.Align.RIGHT);
    String qt = quoteData.getJSONArray("K").getJSONArray(idx).getString(0);
    double jrkp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(1);
    double zg = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(2);
    double zd = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(3);
    double sp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4);
    double preclose;
    if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) {
        switch (idx) {
        case 0:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(7);
            break;
        default:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(7);
            break;
        }
        if (quoteData.getJSONArray("K").length() == 1) {
            preclose = quoteData.getJSONArray("K").getJSONArray(0).getDouble(7);
        }
    } else {
        switch (idx) {
        case 0:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4);
            break;
        default:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(4);
            break;
        }
        if (quoteData.getJSONArray("K").length() == 1) {
            preclose = quoteData.getDouble("zrsp");//quoteData.getJSONArray("K").getJSONArray(0).getDouble(4);
        }
    }
    //      if(quoteData.getJSONArray("K").length()==1 && quoteData.getJSONObject("todayData")!=null){
    //         preclose = quoteData.getJSONObject("todayData").getDouble("zrsp");
    //      }
    mPaint.setColor(getcolor(jrkp, preclose));
    canvas.drawText(Utils.dataFormation(jrkp, stockdigit), klineX, axisLabelHeight * 2, mPaint);
    mPaint.setColor(getcolor(zg, preclose));
    canvas.drawText(Utils.dataFormation(zg, stockdigit), klineX, axisLabelHeight * 4, mPaint);
    mPaint.setColor(getcolor(zd, preclose));
    canvas.drawText(Utils.dataFormation(zd, stockdigit), klineX, axisLabelHeight * 6, mPaint);
    mPaint.setColor(getcolor(sp, preclose));
    canvas.drawText(Utils.dataFormation(sp, stockdigit), klineX, axisLabelHeight * 8, mPaint);
    double zhangdie = sp - preclose;
    if (zhangdie > 0)
        mPaint.setColor(GlobalColor.colorpriceUp);
    else if (zhangdie < 0)
        mPaint.setColor(GlobalColor.colorPriceDown);
    else
        mPaint.setColor(GlobalColor.colorPriceEqual);
    canvas.drawText(Utils.dataFormation(zhangdie, 1), klineX, axisLabelHeight * 10, mPaint);
    if (quoteData.getString("period").equals("min5") || quoteData.getString("period").equals("min15")
            || quoteData.getString("period").equals("min30") || quoteData.getString("period").equals("min60")) {
        qt = qt.substring(4, 6) + '/' + qt.substring(6, 8) + ' ' + qt.substring(8);
    } else {
        qt = qt.substring(2, 4) + qt.substring(4, 6) + qt.substring(6, 8);
    }
    mPaint.setColor(GlobalColor.colorLabelName);
    canvas.drawText(qt, klineX, axisLabelHeight * 12, mPaint);
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*from   w  ww  .jav  a 2  s.c  o m*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);

            canvas.translate(-DX * 4f, DY * 1.2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);

            canvas.translate(width / 2, -DY * 1);
            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 4);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 4);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:in.sc9.discreteslider.DiscreteSlider.java

private void drawTextArray(Canvas canvas, int thumbWidth, int halfThumb, float yPos, int left, float intervel) {
    int lenTextArray = textArray.length;
    if (lenTextArray == 0)
        return;/*ww  w  . j a v  a  2 s.  co  m*/

    float currentLeft = left;

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextAlign(Paint.Align.LEFT);
    paint.setColor(mtextColor);
    paint.setTextSize(mTextSize);
    //paint.setTypeface(); //TODO setTypeface in Discrete Seek Bar
    //elloWorldTextView2.setTextSize(activity.pixelsToSp(activity, textSize));
    //paint.m

    for (int i = 0; i < lenTextArray; i++) {
        /*if((int)getThumbValue(0)==i*(int)scaleStep)
        paint.setColor(Color.parseColor("#ffff0000"));
        else
        paint.setColor(Color.parseColor("#ff22445b"));*/

        float textLen = paint.measureText(textArray[i]);

        if (i == 0) {
            if (textStyle != NONE && (textStyle == ODD || textStyle == EXTREMES || textStyle == ALL))
                canvas.drawText(textArray[i], currentLeft, yPos, paint);
        } else if (i == lenTextArray - 1) {
            if (textStyle != NONE)
                if ((textStyle == ALL) || (i % 2 == 0 && textStyle == ODD) || (i % 2 != 0 && textStyle == EVEN)
                        || (textStyle == EXTREMES))
                    canvas.drawText(textArray[i], currentLeft - textLen, yPos, paint);
        } else {
            if (textStyle != 0 && textStyle != 3) {
                if ((textStyle == ALL) || (i % 2 == 0 && textStyle == ODD) || (i % 2 != 0 && textStyle == EVEN))
                    canvas.drawText(textArray[i], currentLeft - (textLen / 2), yPos, paint);
            }
        }
        currentLeft += intervel;
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//  w  w  w .  j  a v  a  2s.c o m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3.5f, DY * 1.2f);
            //canvas.translate(-DX*0.5f, DY*2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(width / 2 - DX, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, 0);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x, y, paint);

            canvas.translate(width / 2, -DY * 3);
            paint.setTextAlign(Paint.Align.RIGHT);

            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            double amp = jo.getDouble("amp");
            if (amp == 0)
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 2.5f, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2 - DX, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}