Java Code Examples for android.graphics.Typeface#SERIF

The following examples show how to use android.graphics.Typeface#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 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 2
Source File: ImageTextView.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
public ImageTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ImageTextView, defStyleAttr, 0);
    mText = "";
    mText = array.getString(R.styleable.ImageTextView_text);
    mTextSize = array.getDimension(R.styleable.ImageTextView_textSize, 10.0f);
    int id = array.getResourceId(R.styleable.ImageTextView_bitmap, R.drawable.default_album);
    mBitmap = BitmapFactory.decodeResource(context.getResources(), id);
    array.recycle();

    paint.setAntiAlias(true);
    if (mBitmap != null) {
        shader = new BitmapShader(mBitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    }
    typeface = Typeface.SERIF;

}
 
Example 3
Source File: Switch.java    From MCPELauncher 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 4
Source File: ChatSettingsHelper.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
public static Typeface getFont() {
    if (sCachedFont != null)
        return sCachedFont;
    String font = ChatSettings.getFontString();
    if (ListWithCustomSetting.isPrefCustomValue(font)) {
        File file = ListWithCustomSetting.getCustomFile(SettingsHelper.getContext(),
                ChatSettings.PREF_FONT, font);
        try {
            sCachedFont = Typeface.createFromFile(file);
            return sCachedFont;
        } catch (Exception ignored) {
        }
    }
    if (font.equals("monospace"))
        return Typeface.MONOSPACE;
    else if (font.equals("serif"))
        return Typeface.SERIF;
    else
        return Typeface.DEFAULT;
}
 
Example 5
Source File: AccentSwitch.java    From holoaccent 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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: SegmentedButton.java    From SegmentedButton with Apache License 2.0 4 votes vote down vote up
private void getAttributes(AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.SegmentedButton);

    drawableTintOnSelection = ta.getColor(R.styleable.SegmentedButton_sb_drawableTint_onSelection, Color.WHITE);
    hasDrawableTintOnSelection = ta.hasValue(R.styleable.SegmentedButton_sb_drawableTint_onSelection);

    textColorOnSelection = ta.getColor(R.styleable.SegmentedButton_sb_textColor_onSelection, Color.WHITE);
    hasTextColorOnSelection = ta.hasValue(R.styleable.SegmentedButton_sb_textColor_onSelection);

    rippleColor = ta.getColor(R.styleable.SegmentedButton_sb_rippleColor, 0);
    hasRipple = ta.hasValue(R.styleable.SegmentedButton_sb_rippleColor);

    text = ta.getString(R.styleable.SegmentedButton_sb_text);
    hasText = ta.hasValue(R.styleable.SegmentedButton_sb_text);
    textSize = ta.getDimension(R.styleable.SegmentedButton_sb_textSize, ConversionHelper.spToPx(getContext(), 14));
    textColor = ta.getColor(R.styleable.SegmentedButton_sb_textColor, Color.GRAY);
    textTypefacePath = ta.getString(R.styleable.SegmentedButton_sb_textTypefacePath);
    hasTextTypefacePath = ta.hasValue(R.styleable.SegmentedButton_sb_textTypefacePath);
    int typeface = ta.getInt(R.styleable.SegmentedButton_sb_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;
    }

    try {
        hasWeight = ta.hasValue(R.styleable.SegmentedButton_android_layout_weight);
        buttonWeight = ta.getFloat(R.styleable.SegmentedButton_android_layout_weight, 0);

        buttonWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButton_android_layout_width, 0);

    } catch (Exception ex) {
        hasWeight = true;
        buttonWeight = 1;
    }
    hasWidth = !hasWeight && buttonWidth > 0;


    drawable = ta.getResourceId(R.styleable.SegmentedButton_sb_drawable, 0);
    drawableTint = ta.getColor(R.styleable.SegmentedButton_sb_drawableTint, -1);
    drawableWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButton_sb_drawableWidth, -1);
    drawableHeight = ta.getDimensionPixelSize(R.styleable.SegmentedButton_sb_drawableHeight, -1);
    drawablePadding = ta.getDimensionPixelSize(R.styleable.SegmentedButton_sb_drawablePadding, 0);

    hasDrawable = ta.hasValue(R.styleable.SegmentedButton_sb_drawable);
    hasDrawableTint = ta.hasValue(R.styleable.SegmentedButton_sb_drawableTint);
    hasDrawableWidth = ta.hasValue(R.styleable.SegmentedButton_sb_drawableWidth);
    hasDrawableHeight = ta.hasValue(R.styleable.SegmentedButton_sb_drawableHeight);

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


    ta.recycle();
}
 
Example 14
Source File: ViewUtil.java    From material 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: 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 16
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 17
Source File: TextDrawable.java    From QiQuYing with Apache License 2.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 18
Source File: TextDrawable.java    From iview-android-tv with MIT License 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 19
Source File: SystemFontResolver.java    From SDHtmlTextView with Apache License 2.0 4 votes vote down vote up
public SystemFontResolver() {
    this.defaultFont = new FontFamily("default", Typeface.DEFAULT);
    this.serifFont = new FontFamily("serif", Typeface.SERIF);
    this.sansSerifFont = new FontFamily("sans-serif", Typeface.SANS_SERIF);
    this.monoSpaceFont = new FontFamily("monospace", Typeface.MONOSPACE );
}