Example usage for android.text TextPaint TextPaint

List of usage examples for android.text TextPaint TextPaint

Introduction

In this page you can find the example usage for android.text TextPaint TextPaint.

Prototype

public TextPaint() 

Source Link

Usage

From source file:com.ifoer.util.NetPOSPrinter.java

public NetPOSPrinter(Context context) {
    this.result = 0;
    this.dos = null;
    this.in = null;
    this.huanhangSum = 0;
    this.textPaint = new TextPaint();
    this.formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    this.curDate = new Date(System.currentTimeMillis());
    this.str = this.formatter.format(this.curDate);
    this.company_address = MySharedPreferences.getStringValue(this.mContext, Constants.COMPANYADDRESS);
    this.company_phone = MySharedPreferences.getStringValue(this.mContext, Constants.COMPANYPHONENUMBER);
    this.license_plate_number = MySharedPreferences.getStringValue(this.mContext,
            Constants.LICENSEPLATENUMBERDIAG);
    this.serialNum = MySharedPreferences.getStringValue(this.mContext, MySharedPreferences.serialNoKey);
    this.mContext = context;
}

From source file:com.bitflake.counter.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);/* w w  w  .j  av a2  s. c o m*/
    textPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = this.sideItems;

    try {
        textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (textColor == null) {
            textColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                marqueeRepeatLimit);
        dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt();
    boringMetrics = new BoringLayout.Metrics();
    boringMetrics.ascent = fontMetricsInt.ascent;
    boringMetrics.bottom = fontMetricsInt.bottom;
    boringMetrics.descent = fontMetricsInt.descent;
    boringMetrics.leading = fontMetricsInt.leading;
    boringMetrics.top = fontMetricsInt.top;
    boringMetrics.width = itemWidth;

    setWillNotDraw(false);

    flingScrollerX = new OverScroller(context);
    adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    touchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    overscrollDistance = configuration.getScaledOverscrollDistance();

    previousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    touchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, touchHelper);

}

From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);/*from  w w  w. j a v a  2 s  .  com*/
    mTextPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = mSideItems;

    try {
        mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (mTextColor == null) {
            mTextColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        mMarqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                mMarqueeRepeatLimit);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt();
    mBoringMetrics = new BoringLayout.Metrics();
    mBoringMetrics.ascent = fontMetricsInt.ascent;
    mBoringMetrics.bottom = fontMetricsInt.bottom;
    mBoringMetrics.descent = fontMetricsInt.descent;
    mBoringMetrics.leading = fontMetricsInt.leading;
    mBoringMetrics.top = fontMetricsInt.top;
    mBoringMetrics.width = mItemWidth;

    setWillNotDraw(false);

    mFlingScrollerX = new OverScroller(context);
    mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mOverscrollDistance = configuration.getScaledOverscrollDistance();

    mPreviousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    mTouchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

}

From source file:com.lab47billion.appchooser.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    _context = context;//w ww .jav a2s . co  m

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);
    mTextPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = mSideItems;

    try {
        mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (mTextColor == null) {
            mTextColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        mNormalTextSize = a.getDimension(R.styleable.HorizontalPicker_normalTextSize, 20);
        mSelectedTextSize = a.getDimension(R.styleable.HorizontalPicker_selectedTextSize, -1);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        if (mNormalTextSize > -1) {
            setTextSize(mNormalTextSize);
        }
        if (mSelectedTextSize == -1) {
            mSelectedTextSize = mNormalTextSize;
        }

    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt();
    mBoringMetrics = new BoringLayout.Metrics();
    mBoringMetrics.ascent = fontMetricsInt.ascent;
    mBoringMetrics.bottom = fontMetricsInt.bottom;
    mBoringMetrics.descent = fontMetricsInt.descent;
    mBoringMetrics.leading = fontMetricsInt.leading;
    mBoringMetrics.top = fontMetricsInt.top;
    mBoringMetrics.width = mItemWidth;

    setWillNotDraw(false);

    mFlingScrollerX = new OverScroller(context);
    mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mOverscrollDistance = configuration.getScaledOverscrollDistance();

    mPreviousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    /*mTouchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);*/

}

From source file:com.ecuamobi.deckwallet.util.Renderer.java

public static void printQR(final Activity context, final String addressUri) {
    new AsyncTask<Void, Void, Bitmap>() {

        @Override//w  w  w.j a va2s. c o  m
        protected Bitmap doInBackground(Void... params) {
            TextPaint textPaint = new TextPaint();
            textPaint.setAntiAlias(true);
            textPaint.setColor(0xFF000000);
            final int bitmapMargin = 100;//big margin is to prevent possible clipping
            final int textHeight = 28;
            textPaint.setTextSize(textHeight);
            textPaint.setTextAlign(Paint.Align.CENTER);
            final int qrCodePadding = (int) (textPaint.descent() * 2);
            int textWidth = getTextWidth(addressUri, textPaint);
            QRCode addressQrCode = QRCode.getMinimumQRCode(addressUri, ErrorCorrectLevel.M);
            Bitmap addressQrCodeBitmap = addressQrCode.createImage(textWidth);
            Bitmap bmp = Bitmap.createBitmap(textWidth + bitmapMargin * 2,
                    addressQrCodeBitmap.getHeight() + qrCodePadding * 2 + bitmapMargin * 2,
                    Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(bmp);
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setARGB(0xFF, 0xFF, 0xFF, 0xFF);
            paint.setAntiAlias(false);
            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);

            int centerXForAddress = bitmapMargin + textWidth / 2;
            int y = bitmapMargin + qrCodePadding;
            Paint qrCodePaint = new Paint();
            qrCodePaint.setAntiAlias(false);
            qrCodePaint.setDither(false);
            canvas.drawBitmap(addressQrCodeBitmap, centerXForAddress - addressQrCodeBitmap.getWidth() / 2, y,
                    qrCodePaint);
            y += qrCodePadding - textPaint.ascent();
            canvas.drawText(addressUri, centerXForAddress, y + addressQrCodeBitmap.getHeight(), textPaint);
            return bmp;
        }

        @Override
        protected void onPostExecute(final Bitmap bitmap) {
            if (bitmap != null) {
                //DEBUG
                //                    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
                //                    android.widget.ImageView view = new android.widget.ImageView(context);
                //                    view.setImageBitmap(bitmap);
                //                    builder.setView(view);
                //                    builder.setPositiveButton(android.R.string.ok, null);
                //                    builder.show();

                PrintHelper printHelper = new PrintHelper(context);
                printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
                printHelper.printBitmap(addressUri, bitmap);
            }

        }
    }.execute();

}

From source file:org.wikipedia.page.shareafact.SnippetImage.java

private static void drawTitle(@NonNull Canvas canvas, @NonNull String title, int top, boolean isArticleRTL) {
    final int marginBottom = 0;
    final int maxHeight = 70;
    final int maxLines = 2;
    final float maxFontSize = 30.0f;
    final float spacingMultiplier = 0.7f;

    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);//w ww.ja  va2 s.com
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(maxFontSize);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(SERIF);
    textPaint.setShadowLayer(1.0f, 0.0f, 1.0f, Color.GRAY);

    StaticLayout textLayout = optimizeTextSize(
            new TextLayoutParams(title, textPaint, DESCRIPTION_WIDTH, spacingMultiplier), maxHeight, maxLines,
            maxFontSize, maxFontSize);
    int left = HORIZONTAL_PADDING;
    if (isArticleRTL) {
        left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth();
    }
    int marginBottomTotal = marginBottom;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // versions < 5.0 don't compensate for bottom margin correctly when line
        // spacing is less than 1.0, so we'll compensate ourselves
        final int marginBoost = 10;
        marginBottomTotal += marginBoost;
    }

    top = top - marginBottomTotal - textLayout.getHeight();
    canvas.save();
    canvas.translate(left, top);
    textLayout.draw(canvas);
    canvas.restore();
}

From source file:com.xbm.android.matisse.internal.ui.widget.CheckView.java

private void initTextPaint() {
    if (mTextPaint == null) {
        mTextPaint = new TextPaint();
        mTextPaint.setAntiAlias(true);//from  w  ww .ja v a2  s  .c o m
        mTextPaint.setColor(Color.WHITE);
        mTextPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
        mTextPaint.setTextSize(12.0f * mDensity);
    }
}

From source file:com.quran.labs.androidquran.widgets.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    final float fontSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP,
            metrics);// w  w  w . j  av  a  2s.c o  m
    final TextPaint paint = new TextPaint();
    paint.setTextSize(fontSize);
    paint.setTypeface(Typeface.DEFAULT_BOLD);

    int targetWidth = 0;
    final int tabs = adapter.getCount();
    for (int i = 0; i < tabs; i++) {
        String str = adapter.getPageTitle(i).toString();
        str = str.toUpperCase(Locale.getDefault());

        int width = (int) paint.measureText(str);
        width = width + 2 * mTabPadding;
        if (width > targetWidth) {
            targetWidth = width;
        }
    }

    if (targetWidth * tabs < metrics.widthPixels) {
        targetWidth = metrics.widthPixels / tabs;
    }

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (tabTitleView != null) {
            tabTitleView.setText(adapter.getPageTitle(i));
        }
        tabView.setOnClickListener(tabClickListener);

        final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(targetWidth,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        mTabStrip.addView(tabView, params);
    }
}

From source file:com.raspi.chatapp.util.Notification.java

private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) {
    Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    RectF mInnerRectF = new RectF();
    mInnerRectF.set(0, 0, width, width);
    mInnerRectF.offset(0, 0);//from w w  w  .j av  a2  s.  co m

    Paint mBgPaint = new Paint();
    mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setStyle(Paint.Style.FILL);
    mBgPaint.setColor(bgColor);

    TextPaint mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(Color.WHITE);
    mTitleTextPaint.setTextSize(width * 0.8f);

    float centerX = mInnerRectF.centerX();
    float centerY = mInnerRectF.centerY();

    int xPos = (int) centerX;
    int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2);

    if (round)
        c.drawOval(mInnerRectF, mBgPaint);
    else
        c.drawRect(mInnerRectF, mBgPaint);
    c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint);

    return b;
}

From source file:org.wikipedia.page.shareafact.SnippetImage.java

private static void drawWordmarkFromText(@NonNull Context context, @NonNull Canvas canvas,
        boolean isArticleRTL) {
    final int maxWidth = WIDTH - DESCRIPTION_WIDTH - 2 * HORIZONTAL_PADDING;
    final float fontSize = 20.0f;
    final float scaleX = 1.06f;

    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);//from   ww  w  .  j  av  a2 s.  c  om
    textPaint.setColor(Color.LTGRAY);
    textPaint.setTextSize(fontSize);
    textPaint.setTypeface(SERIF);
    textPaint.setTextScaleX(scaleX);

    Spanned wikipedia = StringUtil.fromHtml(context.getString(R.string.wp_stylized));
    Layout.Alignment align = L10nUtil.isDeviceRTL() ? ALIGN_OPPOSITE : ALIGN_NORMAL;
    StaticLayout wordmarkLayout = buildLayout(
            new TextLayoutParams(wikipedia, textPaint, maxWidth, 1.0f, align));
    final int width = (int) wordmarkLayout.getLineWidth(0);
    final int height = wordmarkLayout.getHeight();

    final int bottom = HEIGHT - BOTTOM_PADDING;
    final int top = bottom - height;

    int left = WIDTH - HORIZONTAL_PADDING - width;
    if (isArticleRTL) {
        left = HORIZONTAL_PADDING;
    }

    canvas.save(); // --
    canvas.translate(left, top);
    wordmarkLayout.draw(canvas);
    canvas.restore(); // --
}