Java Code Examples for android.graphics.Typeface#SANS_SERIF

The following examples show how to use android.graphics.Typeface#SANS_SERIF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Switch.java    From PreferenceFragment with Apache License 2.0 6 votes vote down vote up
private void setSwitchTypefaceByIndex(int typefaceIndex, int styleIndex) {
    Typeface tf = null;
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setSwitchTypeface(tf, styleIndex);
}
 
Example 2
Source File: TextFloatingActionButton.java    From TextFloatingActionButton with MIT License 6 votes vote down vote up
private void setTypefaceFromAttrs(String familyName, int typefaceIndex, int styleIndex) {
    Typeface tf = null;
    if (familyName != null) {
        tf = Typeface.create(familyName, styleIndex);
        if (tf != null) {
            setTypeface(tf);
            return;
        }
    }
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setTypeface(tf, styleIndex);
}
 
Example 3
Source File: ReadBottomStatusBar.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
public void updateTextTypeface(String fontPath, boolean bold) {
    Typeface typeface;
    try {
        if (fontPath != null) {
            typeface = Typeface.createFromFile(fontPath);
        } else {
            typeface = Typeface.SANS_SERIF;
        }
    } catch (Exception e) {
        typeface = Typeface.SANS_SERIF;
    }

    tvTime.setTypeface(typeface);
    tvTitle.setTypeface(typeface);
    tvTitleLeft.setTypeface(typeface);
    tvChapterIndex.setTypeface(typeface);
    tvTime.getPaint().setFakeBoldText(bold);
    tvTitle.getPaint().setFakeBoldText(bold);
    tvTitleLeft.getPaint().setFakeBoldText(bold);
    tvChapterIndex.getPaint().setFakeBoldText(bold);
}
 
Example 4
Source File: TextAppearance.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void createFallbackFont() {
  // Try resolving fontFamily as a string name if specified.
  if (font == null && fontFamily != null) {
    font = Typeface.create(fontFamily, textStyle);
  }

  // Try resolving typeface if specified otherwise fallback to Typeface.DEFAULT.
  if (font == null) {
    switch (typeface) {
      case TYPEFACE_SANS:
        font = Typeface.SANS_SERIF;
        break;
      case TYPEFACE_SERIF:
        font = Typeface.SERIF;
        break;
      case TYPEFACE_MONOSPACE:
        font = Typeface.MONOSPACE;
        break;
      default:
        font = Typeface.DEFAULT;
        break;
    }
    font = Typeface.create(font, textStyle);
  }
}
 
Example 5
Source File: IndicatorSeekBar.java    From IndicatorSeekBar with Apache License 2.0 6 votes vote down vote up
/**
 * initial both the tick texts' and thumb text's typeface,just has 4 type to choose,
 * but you can set the CUSTOM typeface you want by java code.
 * <p>
 * usage like:
 * indicatorSeekbar.customTickTextsTypeface(Typeface.xxx);
 */
private void initTextsTypeface(int typeface, Typeface defaultTypeface) {
    switch (typeface) {
        case 0:
            mTextsTypeface = Typeface.DEFAULT;
            break;
        case 1:
            mTextsTypeface = Typeface.MONOSPACE;
            break;
        case 2:
            mTextsTypeface = Typeface.SANS_SERIF;
            break;
        case 3:
            mTextsTypeface = Typeface.SERIF;
            break;
        default:
            if (defaultTypeface == null) {
                mTextsTypeface = Typeface.DEFAULT;
                break;
            }
            mTextsTypeface = defaultTypeface;
            break;
    }
}
 
Example 6
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void setSwitchTypefaceByIndex(int typefaceIndex, int styleIndex) {
    Typeface tf = null;
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setSwitchTypeface(tf, styleIndex);
}
 
Example 7
Source File: TextViewUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the font typeface for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param typeface  one of @link Component#TYPEFACE_DEFAULT},
 *                  {@link Component#TYPEFACE_SERIF},
 *                  {@link Component#TYPEFACE_SANSSERIF} or
 *                  {@link Component#TYPEFACE_MONOSPACE}
 * @param bold true for bold, false for not bold
 * @param italic true for italic, false for not italic
 */
public static void setFontTypeface(TextView textview, int typeface,
    boolean bold, boolean italic) {
  Typeface tf;
  switch (typeface) {
    default:
      throw new IllegalArgumentException();

    case Component.TYPEFACE_DEFAULT:
      tf = Typeface.DEFAULT;
      break;

    case Component.TYPEFACE_SERIF:
      tf = Typeface.SERIF;
      break;

    case Component.TYPEFACE_SANSSERIF:
      tf = Typeface.SANS_SERIF;
      break;

    case Component.TYPEFACE_MONOSPACE:
      tf = Typeface.MONOSPACE;
      break;
  }

  int style = 0;
  if (bold) {
    style |= Typeface.BOLD;
  }
  if (italic) {
    style |= Typeface.ITALIC;
  }
  textview.setTypeface(Typeface.create(tf, style));
  textview.requestLayout();
}
 
Example 8
Source File: Element.java    From htmlview with Apache License 2.0 5 votes vote down vote up
public Paint getFont() {
  if (this.fontCache == null) {
    this.fontCache = new Paint(Paint.ANTI_ALIAS_FLAG);
    this.fontCache.setTextSize(getScaledPx(Style.FONT_SIZE));
    int style = computedStyle.getRaw(Style.FONT_WEIGHT) >= Style.BOLD ? Typeface.BOLD : Typeface.NORMAL;
    switch (computedStyle.getEnum(Style.FONT_STYLE)) {
    case Style.ITALIC: 
      style |= Typeface.ITALIC;
      break;
    case Style.OBLIQUE:
      fontCache.setTextSkewX(-0.25f);
      break;
    }
    Typeface typeface = Typeface.DEFAULT;
    String fontFamily = computedStyle.getString(Style.FONT_FAMILY);
    if (fontFamily != null) {
      String s = CssUtils.identifierToLowerCase(fontFamily);
      if (s.indexOf("monospace") != -1) {
        typeface = Typeface.MONOSPACE;
      } else if (s.indexOf("serif") != -1) {
        typeface = s.indexOf("sans") != -1 ? Typeface.SANS_SERIF : Typeface.SERIF;
      }
    }
    this.fontCache.setTypeface(style == 0 ? typeface : Typeface.create(typeface, style));
    this.fontCache.setColor(computedStyle.getColor(Style.COLOR));
  }
  return this.fontCache;
}
 
Example 9
Source File: EditText.java    From AndroidMaterialValidation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the enum {@link Typeface}, which corresponds to a specific value.
 *
 * @param value
 *         The value
 * @return The value of the enum {@link Typeface}, which corresponds to the given value
 */
private Typeface parseTypeface(final int value) {
    switch (value) {
        case TYPEFACE_SANS_SERIF_VALUE:
            return Typeface.SANS_SERIF;
        case TYPEFACE_SERIF_VALUE:
            return Typeface.SERIF;
        case TYPEFACE_MONOSPACE_VALUE:
            return Typeface.MONOSPACE;
        default:
            return Typeface.DEFAULT;
    }
}
 
Example 10
Source File: VP.java    From BambooPlayer with Apache License 2.0 5 votes vote down vote up
public static Typeface getTypeface(int type) {
	switch (type) {
	case 0:
		return Typeface.DEFAULT;
	case 1:
		return Typeface.SANS_SERIF;
	case 2:
		return Typeface.SERIF;
	case 3:
		return Typeface.MONOSPACE;
	default:
		return DEFAULT_TYPEFACE;
	}
}
 
Example 11
Source File: TransitionEditView.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
private void initTypeFaces() {
    mTypefaces = new Typeface[4];
    mTypefaces[0] = Typeface.SANS_SERIF;
    mTypefaces[1] = Typeface.DEFAULT_BOLD;
    mTypefaces[2] = Typeface.createFromAsset(mContext.getAssets(), "fonts/zcool-gdh.ttf");
    mTypefaces[3] = Typeface.createFromAsset(mContext.getAssets(), "fonts/HappyZcool-2016.ttf");
}
 
Example 12
Source File: PromptUtils.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * Based on setTypefaceFromAttrs in android TextView, Copyright (C) 2006 The Android Open
 * Source Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java
 */
@NonNull
public static Typeface setTypefaceFromAttrs(@Nullable String familyName, int typefaceIndex, int styleIndex)
{
    Typeface tf = null;
    if (familyName != null)
    {
        tf = Typeface.create(familyName, styleIndex);
        if (tf != null)
        {
            return tf;
        }
    }
    switch (typefaceIndex)
    {
        case 1:
            tf = Typeface.SANS_SERIF;
            break;

        case 2:
            tf = Typeface.SERIF;
            break;

        case 3:
            tf = Typeface.MONOSPACE;
            break;
    }
    return Typeface.create(tf, styleIndex);
}
 
Example 13
Source File: TextDrawable.java    From CryptoBuddy with GNU Affero General Public License v3.0 4 votes vote down vote up
public TextDrawable(Context context) {
    super();
    //Used to load and scale resource items
    mResources = context.getResources();
    //Definition of this drawables size
    mTextBounds = new Rect();
    //Paint to use for the text
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.density = mResources.getDisplayMetrics().density;
    mTextPaint.setDither(true);

    int textSize = 15;
    ColorStateList textColor = null;
    int styleIndex = -1;
    int typefaceIndex = -1;

    //Set default parameters from the current theme
    TypedArray a = context.getTheme().obtainStyledAttributes(themeAttributes);
    int appearanceId = a.getResourceId(0, -1);
    a.recycle();

    TypedArray ap = null;
    if (appearanceId != -1) {
        ap = context.obtainStyledAttributes(appearanceId, appearanceAttributes);
    }
    if (ap != null) {
        for (int i=0; i < ap.getIndexCount(); i++) {
            int attr = ap.getIndex(i);
            switch (attr) {
                case 0: //Text Size
                    textSize = a.getDimensionPixelSize(attr, textSize);
                    break;
                case 1: //Typeface
                    typefaceIndex = a.getInt(attr, typefaceIndex);
                    break;
                case 2: //Text Style
                    styleIndex = a.getInt(attr, styleIndex);
                    break;
                case 3: //Text Color
                    textColor = a.getColorStateList(attr);
                    break;
                default:
                    break;
            }
        }

        ap.recycle();
    }

    setTextColor(textColor != null ? textColor : ColorStateList.valueOf(0xFF000000));
    setRawTextSize(textSize);

    Typeface tf = null;
    switch (typefaceIndex) {
        case SANS:
            tf = Typeface.SANS_SERIF;
            break;

        case SERIF:
            tf = Typeface.SERIF;
            break;

        case MONOSPACE:
            tf = Typeface.MONOSPACE;
            break;
    }

    setTypeface(tf, styleIndex);
}
 
Example 14
Source File: ViewUtil.java    From MDPreference with Apache License 2.0 4 votes vote down vote up
public static void applyTextAppearance(TextView v, int resId){
    if(resId == 0)
        return;

    String fontFamily = null;
    int typefaceIndex = -1;
    int styleIndex = -1;
    int shadowColor = 0;
    float dx = 0, dy = 0, r = 0;

    TypedArray appearance = v.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (appearance != null) {
        int n = appearance.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = appearance.getIndex(i);

            if (attr == R.styleable.TextAppearance_android_textColorHighlight) {
                v.setHighlightColor(appearance.getColor(attr, 0));

            } else if (attr == R.styleable.TextAppearance_android_textColor) {
                v.setTextColor(appearance.getColorStateList(attr));

            } else if (attr == R.styleable.TextAppearance_android_textColorHint) {
                v.setHintTextColor(appearance.getColorStateList(attr));

            } else if (attr == R.styleable.TextAppearance_android_textColorLink) {
                v.setLinkTextColor(appearance.getColorStateList(attr));

            } else if (attr == R.styleable.TextAppearance_android_textSize) {
                v.setTextSize(TypedValue.COMPLEX_UNIT_PX, appearance.getDimensionPixelSize(attr, 0));

            } else if (attr == R.styleable.TextAppearance_android_typeface) {
                typefaceIndex = appearance.getInt(attr, -1);

            } else if (attr == R.styleable.TextAppearance_android_fontFamily) {
                fontFamily = appearance.getString(attr);

            } else if (attr == R.styleable.TextAppearance_tv_fontFamily) {
                fontFamily = appearance.getString(attr);

            } else if (attr == R.styleable.TextAppearance_android_textStyle) {
                styleIndex = appearance.getInt(attr, -1);

            } else if (attr == R.styleable.TextAppearance_android_textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                    v.setAllCaps(appearance.getBoolean(attr, false));

            } else if (attr == R.styleable.TextAppearance_android_shadowColor) {
                shadowColor = appearance.getInt(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_shadowDx) {
                dx = appearance.getFloat(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_shadowDy) {
                dy = appearance.getFloat(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_shadowRadius) {
                r = appearance.getFloat(attr, 0);

            } else if (attr == R.styleable.TextAppearance_android_elegantTextHeight) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    v.setElegantTextHeight(appearance.getBoolean(attr, false));

            } else if (attr == R.styleable.TextAppearance_android_letterSpacing) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    v.setLetterSpacing(appearance.getFloat(attr, 0));

            } else if (attr == R.styleable.TextAppearance_android_fontFeatureSettings) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    v.setFontFeatureSettings(appearance.getString(attr));

            }
        }

        appearance.recycle();
    }

    if (shadowColor != 0)
        v.setShadowLayer(r, dx, dy, shadowColor);

    Typeface tf = null;
    if (fontFamily != null) {
        tf = TypefaceUtil.load(v.getContext(), fontFamily, styleIndex);
        if (tf != null)
            v.setTypeface(tf);
    }
    if(tf != null) {
        switch (typefaceIndex) {
            case 1:
                tf = Typeface.SANS_SERIF;
                break;
            case 2:
                tf = Typeface.SERIF;
                break;
            case 3:
                tf = Typeface.MONOSPACE;
                break;
        }
        v.setTypeface(tf, styleIndex);
    }
}
 
Example 15
Source File: MaterialAutoCompleteTextView.java    From Mover with Apache License 2.0 4 votes vote down vote up
private Typeface getCustomTypeface(@NonNull String name) {
    if(isInEditMode()){
        return Typeface.SANS_SERIF;
    }
    return Typeface.createFromAsset(getContext().getAssets(), "fonts/" + name + ".ttf");
}
 
Example 16
Source File: GUITextPaint.java    From Beats with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public GUITextPaint sansSerif() {
	family = Typeface.SANS_SERIF;
	return this;
}
 
Example 17
Source File: PageLoader.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 作用:设置与文字相关的参数
 */
private void setTextParams() {
    // 文字大小
    mTextSize = ScreenUtils.spToPx(mSettingManager.getTextSize());
    // 行间距
    mTextInterval = ScreenUtils.dpToPx(mSettingManager.getLineSpacing());
    // 段落间距
    mTextPara = ScreenUtils.dpToPx(mSettingManager.getParagraphSpacing());

    Typeface typeface;
    try {
        if (mSettingManager.getFontPath() != null) {
            typeface = Typeface.createFromFile(mSettingManager.getFontPath());
        } else {
            typeface = Typeface.SANS_SERIF;
        }
    } catch (Exception e) {
        ToastUtils.toast(mContext, "字体文件未找,到恢复默认字体");
        mSettingManager.setReadBookFont(null);
        typeface = Typeface.SANS_SERIF;
    }

    // 绘制提示的画笔
    mTipPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTipPaint.setColor(mTextColor);
    mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
    mTipPaint.setTypeface(typeface);
    mTipPaint.setFakeBoldText(mSettingManager.getTextBold());
    mTipPaint.setSubpixelText(true);
    mTipPaint.setDither(true);

    // 绘制标题的画笔
    mTitlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTitlePaint.setColor(mTextColor);
    mTitlePaint.setTextSize(mTextSize * 1.25f);
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(typeface);
    mTitlePaint.setFakeBoldText(true);
    mTitlePaint.setSubpixelText(true);
    mTitlePaint.setDither(true);

    // 绘制页面内容的画笔
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTypeface(typeface);
    mTextPaint.setFakeBoldText(mSettingManager.getTextBold());
    mTextPaint.setSubpixelText(true);
    mTextPaint.setDither(true);
}
 
Example 18
Source File: RadioRealButton.java    From RadioRealButton with Apache License 2.0 4 votes vote down vote up
/***
 * GET ATTRIBUTES FROM XML
 */
private void getAttributes(AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.RadioRealButton);

    drawable = ta.getResourceId(R.styleable.RadioRealButton_rrb_drawable, -1);
    drawableTint = ta.getColor(R.styleable.RadioRealButton_rrb_drawableTint, 0);
    drawableTintTo = ta.getColor(R.styleable.RadioRealButton_rrb_drawableTintTo, 0);
    drawableWidth = ta.getDimensionPixelSize(R.styleable.RadioRealButton_rrb_drawableWidth, -1);
    drawableHeight = ta.getDimensionPixelSize(R.styleable.RadioRealButton_rrb_drawableHeight, -1);

    hasDrawable = ta.hasValue(R.styleable.RadioRealButton_rrb_drawable);
    hasDrawableTint = ta.hasValue(R.styleable.RadioRealButton_rrb_drawableTint);
    hasDrawableTintTo = ta.hasValue(R.styleable.RadioRealButton_rrb_drawableTintTo);
    hasDrawableWidth = ta.hasValue(R.styleable.RadioRealButton_rrb_drawableWidth);
    hasDrawableHeight = ta.hasValue(R.styleable.RadioRealButton_rrb_drawableHeight);

    text = ta.getString(R.styleable.RadioRealButton_rrb_text);
    hasText = ta.hasValue(R.styleable.RadioRealButton_rrb_text);
    textColor = ta.getColor(R.styleable.RadioRealButton_rrb_textColor, Color.BLACK);
    textColorTo = ta.getColor(R.styleable.RadioRealButton_rrb_textColorTo, Color.BLACK);

    hasTextColor = ta.hasValue(R.styleable.RadioRealButton_rrb_textColor);
    hasTextColorTo = ta.hasValue(R.styleable.RadioRealButton_rrb_textColorTo);
    textSize = ta.getDimensionPixelSize(R.styleable.RadioRealButton_rrb_textSize, -1);
    hasTextSize = ta.hasValue(R.styleable.RadioRealButton_rrb_textSize);
    textStyle = ta.getInt(R.styleable.RadioRealButton_rrb_textStyle, -1);
    hasTextStyle = ta.hasValue(R.styleable.RadioRealButton_rrb_textStyle);

    int typeface = ta.getInt(R.styleable.RadioRealButton_rrb_textTypeface, -1);
    switch (typeface) {
        case 0:
            textTypeface = Typeface.MONOSPACE;
            break;
        case 1:
            textTypeface = Typeface.DEFAULT;
            break;
        case 2:
            textTypeface = Typeface.SANS_SERIF;
            break;
        case 3:
            textTypeface = Typeface.SERIF;
            break;
    }
    textTypefacePath = ta.getString(R.styleable.RadioRealButton_rrb_textTypefacePath);
    hasTextTypefacePath = ta.hasValue(R.styleable.RadioRealButton_rrb_textTypefacePath);

    hasRipple = ta.getBoolean(R.styleable.RadioRealButton_rrb_ripple, true);
    rippleColor = ta.getColor(R.styleable.RadioRealButton_rrb_rippleColor, Color.GRAY);
    hasRippleColor = ta.hasValue(R.styleable.RadioRealButton_rrb_rippleColor);

    backgroundColor = ta.getColor(R.styleable.RadioRealButton_rrb_backgroundColor, Color.TRANSPARENT);

    int defaultPadding = ConversionHelper.dpToPx(getContext(), 10);
    padding = ta.getDimensionPixelSize(R.styleable.RadioRealButton_android_padding, defaultPadding);
    paddingLeft = ta.getDimensionPixelSize(R.styleable.RadioRealButton_android_paddingLeft, 0);
    paddingRight = ta.getDimensionPixelSize(R.styleable.RadioRealButton_android_paddingRight, 0);
    paddingTop = ta.getDimensionPixelSize(R.styleable.RadioRealButton_android_paddingTop, 0);
    paddingBottom = ta.getDimensionPixelSize(R.styleable.RadioRealButton_android_paddingBottom, 0);

    hasPaddingLeft = ta.hasValue(R.styleable.RadioRealButton_android_paddingLeft);
    hasPaddingRight = ta.hasValue(R.styleable.RadioRealButton_android_paddingRight);
    hasPaddingTop = ta.hasValue(R.styleable.RadioRealButton_android_paddingTop);
    hasPaddingBottom = ta.hasValue(R.styleable.RadioRealButton_android_paddingBottom);

    drawablePadding = ta.getDimensionPixelSize(R.styleable.RadioRealButton_rrb_drawablePadding, 4);

    drawableGravity = DrawableGravity.getById(ta.getInteger(R.styleable.RadioRealButton_rrb_drawableGravity, 0));

    checked = ta.getBoolean(R.styleable.RadioRealButton_rrb_checked, false);

    enabled = ta.getBoolean(R.styleable.RadioRealButton_android_enabled, true);
    hasEnabled = ta.hasValue(R.styleable.RadioRealButton_android_enabled);
    clickable = ta.getBoolean(R.styleable.RadioRealButton_android_clickable, true);
    hasClickable = ta.hasValue(R.styleable.RadioRealButton_android_clickable);

    textGravity = ta.getInt(R.styleable.RadioRealButton_rrb_textGravity, Gravity.NO_GRAVITY);

    textFillSpace = ta.getBoolean(R.styleable.RadioRealButton_rrb_textFillSpace, false);

    selectorColor = ta.getColor(R.styleable.RadioRealButton_rrb_selectorColor, Color.TRANSPARENT);
    hasSelectorColor = ta.hasValue(R.styleable.RadioRealButton_rrb_selectorColor);

    ta.recycle();
}
 
Example 19
Source File: PageLoader.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 初始化画笔
 */
private void initPaint() {
    Typeface typeface;
    try {
        if (!TextUtils.isEmpty(readBookControl.getFontPath())) {
            typeface = Typeface.createFromFile(readBookControl.getFontPath());
        } else {
            typeface = Typeface.SANS_SERIF;
        }
    } catch (Exception e) {
        Toast.makeText(mContext, "字体文件未找,到恢复默认字体", Toast.LENGTH_SHORT).show();
        readBookControl.setReadBookFont(null);
        typeface = Typeface.SANS_SERIF;
    }
    // 绘制提示的画笔
    mTipPaint = new TextPaint();
    mTipPaint.setColor(readBookControl.getTextColor());
    mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
    mTipPaint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    // 绘制标题的画笔
    mTitlePaint = new TextPaint();
    mTitlePaint.setColor(readBookControl.getTextColor());
    mTitlePaint.setTextSize(mTitleSize);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mTitlePaint.setLetterSpacing(readBookControl.getTextLetterSpacing());
    }
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(Typeface.create(typeface, Typeface.BOLD));
    mTitlePaint.setTextAlign(Paint.Align.CENTER);
    mTitlePaint.setAntiAlias(true);

    // 绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(readBookControl.getTextColor());
    mTextPaint.setTextSize(mTextSize);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mTextPaint.setLetterSpacing(readBookControl.getTextLetterSpacing());
    }
    int bold = readBookControl.getTextBold() ? Typeface.BOLD : Typeface.NORMAL;
    mTextPaint.setTypeface(Typeface.create(typeface, bold));
    mTextPaint.setAntiAlias(true);

    // 绘制结束的画笔
    mTextEndPaint = new TextPaint();
    mTextEndPaint.setColor(readBookControl.getTextColor());
    mTextEndPaint.setTextSize(mTextEndSize);
    mTextEndPaint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
    mTextEndPaint.setAntiAlias(true);
    mTextEndPaint.setSubpixelText(true);
    mTextEndPaint.setTextAlign(Paint.Align.CENTER);

    // 绘制电池的画笔
    mBatteryPaint = new TextPaint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);
    mBatteryPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE - 3));
    mBatteryPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "number.ttf"));

    setupTextInterval();
    // 初始化页面样式
    initPageStyle();
}