Example usage for android.graphics Typeface DEFAULT

List of usage examples for android.graphics Typeface DEFAULT

Introduction

In this page you can find the example usage for android.graphics Typeface DEFAULT.

Prototype

Typeface DEFAULT

To view the source code for android.graphics Typeface DEFAULT.

Click Source Link

Document

The default NORMAL typeface object

Usage

From source file:android.support.design.widget.CollapsingTextHelper.java

Typeface getExpandedTypeface() {
    return mExpandedTypeface != null ? mExpandedTypeface : Typeface.DEFAULT;
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java

/**
 * id?/*from   w w  w. j  a v  a2s  .c  o m*/
 *
 * @param viewId
 * @param isBold ?
 * @return
 */
public BGAViewHolderHelper setIsBold(@IdRes int viewId, boolean isBold) {
    getTextView(viewId).getPaint().setTypeface(isBold ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
    return this;
}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

/**
 * id?// ww w.j a  v  a  2  s  . co m
 *
 * @param viewId
 * @param isBold ?
 * @return
 */
public BaseViewHolderHelper setIsBold(@IdRes int viewId, boolean isBold) {
    getTextView(viewId).getPaint().setTypeface(isBold ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
    return this;
}

From source file:com.yek.keyboard.keyboards.views.CandidateView.java

/**
 * If the canvas is null, then only touch calculations are performed to pick
 * the target candidate./* w  ww.j  a  v  a2s . c o m*/
 */
@Override
protected void onDraw(Canvas canvas) {
    if (canvas != null) {
        super.onDraw(canvas);
    }
    mTotalWidth = 0;

    final int height = getHeight();
    if (mBgPadding == null) {
        mBgPadding = new Rect(0, 0, 0, 0);
        if (getBackground() != null) {
            getBackground().getPadding(mBgPadding);
        }
        mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight());
    }

    final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2;
    final int count = mSuggestions.size();
    final Rect bgPadding = mBgPadding;
    final Paint paint = mPaint;
    final int touchX = mTouchX;
    final int scrollX = getScrollX();
    final boolean scrolled = mScrolled;
    final boolean typedWordValid = mTypedWordValid;

    int x = 0;
    for (int i = 0; i < count; i++) {
        CharSequence suggestion = mSuggestions.get(i);
        if (suggestion == null)
            continue;
        final int wordLength = suggestion.length();

        paint.setColor(mColorNormal);
        if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
            paint.setTypeface(Typeface.DEFAULT_BOLD);
            paint.setColor(mColorRecommended);
            // existsAutoCompletion = true;
        } else if (i != 0 || (wordLength == 1 && count > 1)) {
            // HACK: even if i == 0, we use mColorOther when this
            // suggestion's length is 1 and
            // there are multiple suggestions, such as the default
            // punctuation list.
            paint.setColor(mColorOther);
        }

        // now that we set the typeFace, we can measure
        int wordWidth;
        if ((wordWidth = mWordWidth[i]) == 0) {
            float textWidth = paint.measureText(suggestion, 0, wordLength);
            // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2);
            wordWidth = (int) (textWidth + mXGap * 2);
            mWordWidth[i] = wordWidth;
        }

        mWordX[i] = x;

        if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x
                && touchX + scrollX < x + wordWidth) {
            if (canvas != null && !mShowingAddToDictionary) {
                canvas.translate(x, 0);
                mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
                mSelectionHighlight.draw(canvas);
                canvas.translate(-x, 0);
            }
            mSelectedString = suggestion;
            mSelectedIndex = i;
        }

        if (canvas != null) {
            // (+)This is the trick to get RTL/LTR text correct
            if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
                final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2;
                canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint);
            } else {
                final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2;
                // no matter what: StaticLayout
                float textX = x + (wordWidth / 2) - mXGap;
                float textY = y - bgPadding.bottom - bgPadding.top;

                canvas.translate(textX, textY);
                mTextPaint.setTypeface(paint.getTypeface());
                mTextPaint.setColor(paint.getColor());

                StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth,
                        Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
                suggestionText.draw(canvas);

                canvas.translate(-textX, -textY);
            }
            // (-)
            paint.setColor(mColorOther);
            canvas.translate(x + wordWidth, 0);
            // Draw a divider unless it's after the hint
            //or the last suggested word
            if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) {
                canvas.translate(0, dividerYOffset);
                mDivider.draw(canvas);
                canvas.translate(0, -dividerYOffset);
            }
            canvas.translate(-x - wordWidth, 0);
        }
        paint.setTypeface(Typeface.DEFAULT);
        x += wordWidth;
    }
    mTotalWidth = x;
    if (mTargetScrollX != scrollX) {
        scrollToTarget();
    }
}

From source file:xyz.yhsj.helper.ViewHolderHelper.java

/**
 * id?/*from   ww w  . j  ava 2  s.co  m*/
 *
 * @param viewId
 * @param isBold ?
 * @return
 */
public ViewHolderHelper setIsBold(@IdRes int viewId, boolean isBold) {
    getTextView(viewId).getPaint().setTypeface(isBold ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
    return this;
}

From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java

/**
 * If the canvas is null, then only touch calculations are performed to pick
 * the target candidate./*from   w ww  .  j a  va2  s.  c  o m*/
 */
@Override
protected void onDraw(Canvas canvas) {
    if (canvas != null) {
        super.onDraw(canvas);
    }
    mTotalWidth = 0;

    final int height = getHeight();
    if (mBgPadding == null) {
        mBgPadding = new Rect(0, 0, 0, 0);
        if (getBackground() != null) {
            getBackground().getPadding(mBgPadding);
        }
        mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight());
    }

    final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2;
    final int count = mSuggestions.size();
    final Rect bgPadding = mBgPadding;
    final Paint paint = mPaint;
    final int touchX = mTouchX;
    final int scrollX = getScrollX();
    final boolean scrolled = mScrolled;
    final boolean typedWordValid = mTypedWordValid;

    int x = 0;
    for (int i = 0; i < count; i++) {
        CharSequence suggestion = mSuggestions.get(i);
        if (suggestion == null)
            continue;
        final int wordLength = suggestion.length();

        paint.setColor(mColorNormal);
        if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
            paint.setTypeface(Typeface.DEFAULT_BOLD);
            paint.setColor(mColorRecommended);
            // existsAutoCompletion = true;
        } else if (i != 0 || (wordLength == 1 && count > 1)) {
            // HACK: even if i == 0, we use mColorOther when this
            // suggestion's length is 1 and
            // there are multiple suggestions, such as the default
            // punctuation list.
            paint.setColor(mColorOther);
        }

        // now that we set the typeFace, we can measure
        int wordWidth;
        if ((wordWidth = mWordWidth[i]) == 0) {
            float textWidth = paint.measureText(suggestion, 0, wordLength);
            // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2);
            wordWidth = (int) (textWidth + mHorizontalGap * 2);
            mWordWidth[i] = wordWidth;
        }

        mWordX[i] = x;

        if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x
                && touchX + scrollX < x + wordWidth) {
            if (canvas != null && !mShowingAddToDictionary) {
                canvas.translate(x, 0);
                mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
                mSelectionHighlight.draw(canvas);
                canvas.translate(-x, 0);
            }
            mSelectedString = suggestion;
            mSelectedIndex = i;
        }

        if (canvas != null) {
            // (+)This is the trick to get RTL/LTR text correct
            if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
                final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2;
                canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint);
            } else {
                final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2;
                // no matter what: StaticLayout
                float textX = x + (wordWidth / 2) - mHorizontalGap;
                float textY = y - bgPadding.bottom - bgPadding.top;

                canvas.translate(textX, textY);
                mTextPaint.setTypeface(paint.getTypeface());
                mTextPaint.setColor(paint.getColor());

                StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth,
                        Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
                suggestionText.draw(canvas);

                canvas.translate(-textX, -textY);
            }
            // (-)
            paint.setColor(mColorOther);
            canvas.translate(x + wordWidth, 0);
            // Draw a divider unless it's after the hint
            //or the last suggested word
            if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) {
                canvas.translate(0, dividerYOffset);
                mDivider.draw(canvas);
                canvas.translate(0, -dividerYOffset);
            }
            canvas.translate(-x - wordWidth, 0);
        }
        paint.setTypeface(Typeface.DEFAULT);
        x += wordWidth;
    }
    mTotalWidth = x;
    if (mTargetScrollX != scrollX) {
        scrollToTarget();
    }
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

public void setTypeface(final String typeface) {
    Typeface tempTypeface;/*from   w  ww.  j av  a2 s .c o  m*/
    try {
        tempTypeface = Typeface.createFromAsset(getContext().getAssets(), typeface);
    } catch (Exception e) {
        tempTypeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
        e.printStackTrace();
    }

    setTypeface(tempTypeface);
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

/**
 * Refreshes funds table with fetched data
 *
 * @param response JSONObject with funds data
 *//* w ww.j  a v a 2s .  c om*/
private void refreshFunds(JSONObject response) {
    try {
        if (response == null) {
            Toast.makeText(getActivity(), getResources().getString(R.string.GeneralErrorText),
                    Toast.LENGTH_LONG).show();
            return;
        }
        String notificationText;
        if (response.getInt("success") == 1) {

            View.OnClickListener fillAmount = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ScrollView scrollView = (ScrollView) getView();
                    if (scrollView != null) {
                        EditText tradeAmount = (EditText) scrollView.findViewById(R.id.TradeAmount);
                        tradeAmount.setText(((TextView) v).getText());
                        scrollView.smoothScrollTo(0, scrollView.findViewById(R.id.tradingSection).getBottom());
                    }
                }
            };

            notificationText = getResources().getString(R.string.FundsInfoUpdatedtext);
            TableLayout fundsContainer = (TableLayout) getView().findViewById(R.id.FundsContainer);
            fundsContainer.removeAllViews();
            JSONObject funds = response.getJSONObject("return").getJSONObject("funds");
            JSONArray fundsNames = response.getJSONObject("return").getJSONObject("funds").names();
            List<String> arrayList = new ArrayList<>();

            for (int i = 0; i < fundsNames.length(); i++) {
                arrayList.add(fundsNames.getString(i));
            }
            Collections.sort(arrayList);
            TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1);

            for (String anArrayList : arrayList) {

                TableRow row = new TableRow(getActivity());
                TextView currency = new TextView(getActivity());
                TextView amount = new TextView(getActivity());
                currency.setText(anArrayList.toUpperCase(Locale.US));
                amount.setText(funds.getString(anArrayList));
                currency.setLayoutParams(layoutParams);
                currency.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                currency.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
                currency.setGravity(Gravity.CENTER);
                amount.setLayoutParams(layoutParams);
                amount.setGravity(Gravity.CENTER);
                amount.setOnClickListener(fillAmount);
                row.addView(currency);
                row.addView(amount);
                fundsContainer.addView(row);
            }

        } else {
            notificationText = response.getString("error");
        }

        mCallback.makeNotification(ConstantHolder.ACCOUNT_INFO_NOTIF_ID, notificationText);

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:im.neon.util.VectorUtils.java

/**
 * Create an avatar bitmap from a text.//w w w.j a  v a 2  s. c  o  m
 *
 * @param backgroundColor the background color.
 * @param text            the text to display.
 * @param pixelsSide      the avatar side in pixels
 * @return the generated bitmap
 */
private static Bitmap createAvatar(int backgroundColor, String text, int pixelsSide) {
    android.graphics.Bitmap.Config bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;

    Bitmap bitmap = Bitmap.createBitmap(pixelsSide, pixelsSide, bitmapConfig);
    Canvas canvas = new Canvas(bitmap);

    canvas.drawColor(backgroundColor);

    // prepare the text drawing
    Paint textPaint = new Paint();
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    textPaint.setColor(Color.WHITE);
    // the text size is proportional to the avatar size.
    // by default, the avatar size is 42dp, the text size is 28 dp (not sp because it has to be fixed).
    textPaint.setTextSize(pixelsSide * 2 / 3);

    // get its size
    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    // draw the text in center
    canvas.drawText(text, (canvas.getWidth() - textBounds.width() - textBounds.left) / 2,
            (canvas.getHeight() + textBounds.height() - textBounds.bottom) / 2, textPaint);

    // Return the avatar
    return bitmap;
}

From source file:com.prey.activities.CheckPasswordActivity.java

protected void bindPasswordControls() {
    Button checkPasswordOkButton = (Button) findViewById(R.id.password_btn_login);
    final EditText pass1 = ((EditText) findViewById(R.id.password_pass_txt));
    checkPasswordOkButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final String passwordtyped = pass1.getText().toString();
            final Context ctx = getApplicationContext();
            if (passwordtyped.equals(""))
                Toast.makeText(ctx, R.string.preferences_password_length_error, Toast.LENGTH_LONG).show();
            else {
                if (passwordtyped.length() < 6 || passwordtyped.length() > 32) {
                    Toast.makeText(ctx, ctx.getString(R.string.error_password_out_of_range, 6, 32),
                            Toast.LENGTH_LONG).show();
                } else {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        new CheckPassword().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, passwordtyped);
                    else
                        new CheckPassword().execute(passwordtyped);
                }/*from   ww w. jav a  2s.c  o  m*/
            }

        }
    });

    //Hack to fix hint's typeface: http://stackoverflow.com/questions/3406534/password-hint-font-in-android
    EditText password = (EditText) findViewById(R.id.password_pass_txt);
    password.setTypeface(Typeface.DEFAULT);
    password.setTransformationMethod(new PasswordTransformationMethod());
}