Example usage for android.graphics Paint setTypeface

List of usage examples for android.graphics Paint setTypeface

Introduction

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

Prototype

public Typeface setTypeface(Typeface typeface) 

Source Link

Document

Set or clear the typeface object.

Usage

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

private void init() {
    mSolidColor = 0;//from   www  .  j  a v a  2 s . co  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:com.cssweb.android.view.PriceView.java

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*  www .ja v  a 2 s  . c o m*/
    tPaint.setColor(GlobalColor.clrLine);
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setStrokeWidth(1);
    this.x = 0;
    this.y = 0;
    startX = x + tips / 2;
    endX = width - tips / 2;
    canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint);
    canvas.drawLine(startX, DY * 5 + DY / 2, endX, DY * 5 + DY / 2, tPaint);
    canvas.drawLine(startX, DY * 11 + DY / 8, endX, DY * 11 + DY / 8, tPaint);
    //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint);
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

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

            canvas.translate(0, DY * 1.5f);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            //            canvas.drawText("?", x + tips, y, paint);
            //            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(width, -DY * 13f);
            paint.setTextAlign(Paint.Align.RIGHT);

            double zjcj = jo.getDouble("zjcj");
            setColor(paint, zjcj, zrsp);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint);

            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);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangdie, x - tips, 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(0, DY);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangfu + "%", 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);

            canvas.translate(0, DY * 1.5f);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            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.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            //canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1), x - tips, y, paint);

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

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

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);// www.ja  v  a  2  s .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.PriceView.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*from   w  w w.ja  v  a2  s .c o m*/
    tPaint.setColor(GlobalColor.clrLine);
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setStrokeWidth(1);
    this.x = 0;
    this.y = 0;
    startX = x + tips / 2;
    endX = width - tips / 2;
    canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint);
    canvas.drawLine(startX, DY * 7 + DY / 2, endX, DY * 7 + DY / 2, tPaint);
    canvas.drawLine(startX, DY * 18 + DY / 4, endX, DY * 18 + DY / 4, tPaint);
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

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

            canvas.translate(0, DY * 1.5f);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(width, -DY * 15.5f);
            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x - tips, y, paint);

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

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

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            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);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangdie, x - tips, 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(0, DY);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangfu + "%", 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);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), 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);

            canvas.translate(-width, DY * 1.7f);

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

            canvas.drawText("", x + tips, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(width / 2, 0);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText("", x + tips, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(width / 2, 0);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

/**
 * Applies the specified text appearance resource to a paint, returning the
 * text color if one is set in the text appearance.
 *
 * @param p     the paint to modify/*from   w ww.  j a v a  2 s. c o m*/
 * @param resId the resource ID of the text appearance
 * @return the text color, if available
 */
private ColorStateList applyTextAppearance(Paint p, int resId) {
    // Workaround for inaccessible R.styleable.TextAppearance_*
    TextView tv = new TextView(mContext);
    if (SUtils.isApi_23_OrHigher()) {
        tv.setTextAppearance(resId);
    } else {
        //noinspection deprecation
        tv.setTextAppearance(mContext, resId);
    }

    p.setTypeface(tv.getTypeface());
    p.setTextSize(tv.getTextSize());

    final ColorStateList textColor = tv.getTextColors();

    if (textColor != null) {
        final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0);
        p.setColor(enabledColor);
    }

    return textColor;
}

From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java

/**
 * Draws an item label./*from w  w  w  . j  a  v a  2 s .  c o  m*/
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Canvas g2, PlotOrientation orientation, XYDataset dataset, int series, int item,
        double x, double y, boolean negative) {

    XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
    if (generator != null) {
        Font labelFont = getItemLabelFont(series, item);
        Paint paint = getItemLabelPaint(series, item);
        paint.setTypeface(labelFont.getTypeFace());
        paint.setTextSize(labelFont.getSize());
        String label = generator.generateLabel(dataset, series, item);

        // get the label position..
        ItemLabelPosition position = null;
        if (!negative) {
            position = getPositiveItemLabelPosition(series, item);
        } else {
            position = getNegativeItemLabelPosition(series, item);
        }

        // work out the label anchor point...
        Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), position.getRotationAnchor(), paint);
    }

}

From source file:com.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java

@SuppressWarnings("deprecation")
private void setTextViewFontSize() {
    TextView tv = (TextView) findViewById(R.id.textview_cur);
    // At this point tv.getWidth(), tv.getLineCount() will return 0

    Paint mTestPaint = new Paint();
    mTestPaint.setTextSize(tv.getTextSize());
    mTestPaint.setTypeface(Typeface.MONOSPACE);

    final String text = "Peak:XXXXX.XHz(AX#+XX) -XXX.XdB";
    Display display = getWindowManager().getDefaultDisplay();

    // pixels left
    float px = display.getWidth() - getResources().getDimension(R.dimen.textview_RMS_layout_width) - 5;

    float fs = tv.getTextSize(); // size in pixel
    while (mTestPaint.measureText(text) > px && fs > 5) {
        fs -= 0.5;//from  w  w w.  java  2s.  co  m
        mTestPaint.setTextSize(fs);
    }
    ((TextView) findViewById(R.id.textview_cur)).setTextSize(fs / DPRatio);
    ((TextView) findViewById(R.id.textview_peak)).setTextSize(fs / DPRatio);
}

From source file:com.lt.adamlee.aagame.GameView.java

public void about(Canvas c) {
    int textsize = (int) F.hf(20.0f);
    Paint p3 = new Paint();
    p3.setTypeface(tf);
    p3.setColor(ViewCompat.MEASURED_STATE_MASK);
    p3.setFlags(1);//from  w  ww  . j  ava 2 s. co m
    p3.setTextSize((float) textsize);
    Paint pagepaint = new Paint();
    pagepaint.setColor(getResources().getColor(R.color.abc_secondary_text_material_light));
    c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, pagepaint);
    p3.setTextSize(F.hf(30.0f));
    c.drawText(ctx.getString(R.string.about),
            ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.about)) / 2.0f),
            (float) (screenH / 4), p3);
    p3.setTextSize((float) textsize);
    c.drawText(ctx.getString(R.string.app_name),
            ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.app_name)) / 2.0f),
            (float) (((textsize * 2) + 1) + ((screenH - (textsize * 7)) / 2)), p3);
    c.drawText("License Version 1.7", ((float) (screenW / 2)) - (p3.measureText("License Version 1.7") / 2.0f),
            (float) (((textsize * 3) + 1) + ((screenH - (textsize * 7)) / 2)), p3);
    p3.setTextSize(F.hf(17.0f));
    c.drawText("Powered by Map Game Studio",
            ((float) (screenW / 2)) - (p3.measureText("Powered by Map Game Studio") / 2.0f),
            (float) (((textsize * 4) + 1) + ((screenH - (textsize * 7)) / 2)), p3);
    p3.setTextSize(F.hf(17.0f));
    c.drawText("Email:mapgamestudio@gmail.com",
            ((float) (screenW / 2)) - (p3.measureText("Email:mapgamestudio@gmail.com") / 2.0f),
            (float) (((textsize * 5) + 1) + ((screenH - (textsize * 7)) / 2)), p3);
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void makeBMP(CalculationResult res) {

    Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);

    //canvas.drawARGB(155, 253, 255, 253);
    canvas.drawARGB(255, 255, 255, 255);
    Paint p = new Paint();
    p.setTypeface(Utility.getNazaninFont());
    p.setTextSize(25);//from   w  w w. j  a v  a2  s.  c o m
    p.setAntiAlias(true);

    int y = 20;
    Drawable d = getResources().getDrawable(R.drawable.abfa);
    d.setBounds(100, 10, 300, 210);
    d.draw(canvas);
    p.setTextAlign(Paint.Align.CENTER);
    y += 210;
    canvas.drawText("   ?  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText(":" + Utility.NowDate(), 200, y, p);
    y += 40;
    canvas.drawText("___________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.CustomerNumber, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.Title, 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p);

    y += 40;
    Paint p1 = new Paint();
    p1.setTypeface(Utility.getNazaninFont());
    p1.setARGB(255, 0, 0, 0);
    p1.setAntiAlias(true);
    p1.setStrokeWidth(40);
    p1.setStyle(Paint.Style.STROKE);
    canvas.drawLine(10, y, 390, y, p1);
    p.setARGB(255, 255, 255, 255);
    canvas.drawText("  :" + Seprate3(res.TotalAmount) + " ", 200, y, p);
    p.setARGB(255, 0, 0, 0);

    y += 40;
    canvas.drawText("__________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.BillIdentifier, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p);

    /* Path pth = new Path();
     pth.addArc(10, 20, 390, 790, 0, 360);
            
     p.setColor(Color.argb(20, 10, 10, 10));
     p.setTextSize(30);
     String watermark = "";
     for (int i = 0; i < 15; i++) {
     watermark += "  ";
     }
     canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/
    //File file = new File(getCacheDir()+ "/billing.png");
    File file = new File("/sdcard/billing.png");
    FileOutputStream outfile;
    try {
        outfile = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile);

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "image/*");
        startActivity(intent);

    } catch (Exception ex) {
        Log.e("error", ex.toString());
    }

}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void makePDF(CalculationResult res) {

    PdfDocument doc = new PdfDocument();
    PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create();
    PdfDocument.Page page = doc.startPage(inf);

    Canvas canvas = page.getCanvas();

    //canvas.drawARGB(155, 253, 255, 253);
    canvas.drawARGB(255, 255, 255, 255);
    Paint p = new Paint();
    p.setTypeface(Utility.getNazaninFont());
    p.setTextSize(25);/* ww  w . j  a v  a2  s .  c o m*/
    p.setAntiAlias(true);

    int y = 20;
    Drawable d = getResources().getDrawable(R.drawable.abfa);
    d.setBounds(100, 10, 300, 210);
    d.draw(canvas);
    p.setTextAlign(Paint.Align.CENTER);
    y += 210;
    canvas.drawText("   ?  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText(":" + Utility.NowDate(), 200, y, p);
    y += 40;
    canvas.drawText("___________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.CustomerNumber, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.Title, 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p);

    y += 40;
    Paint p1 = new Paint();
    p1.setTypeface(Utility.getNazaninFont());
    p1.setARGB(255, 0, 0, 0);
    p1.setAntiAlias(true);
    p1.setStrokeWidth(40);
    p1.setStyle(Paint.Style.STROKE);
    canvas.drawLine(10, y, 390, y, p1);
    p.setARGB(255, 255, 255, 255);
    canvas.drawText("  :" + Seprate3(res.TotalAmount) + " ", 200, y, p);
    p.setARGB(255, 0, 0, 0);

    y += 40;
    canvas.drawText("__________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.BillIdentifier, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p);

    doc.finishPage(page);
    //File file = new File(getCacheDir()+ "/billing.png");
    File file = new File("/sdcard/billing.pdf");
    FileOutputStream outfile;
    try {
        outfile = new FileOutputStream(file);
        //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile);
        doc.writeTo(outfile);
        doc.close();

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        //intent.setDataAndType(Uri.fromFile(file), "image/*");
        intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        startActivity(intent);
        //new RetrieveFeedTask().execute(bmp);

    } catch (Exception ex) {
        Log.e("error", ex.toString());
        new AlertDialog.Builder(this).setMessage(
                "    ? pdf    ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa   ")
                .show();
    }

}