Java Code Examples for android.graphics.Typeface#DEFAULT

The following examples show how to use android.graphics.Typeface#DEFAULT . 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: TypefaceUtils.java    From VideoMeeting with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param context
 * @param familyName
 *            if start with 'asset:' prefix, then load font from asset
 *            folder.
 * @param style
 * @return
 */
public static Typeface load(Context context, String familyName, int style) {
	if (familyName != null && familyName.startsWith(PREFIX_ASSET)) {
		synchronized (sCachedFonts) {
			try {
				if (!sCachedFonts.containsKey(familyName)) {
					final Typeface typeface = Typeface.createFromAsset(
							context.getAssets(),
							familyName.substring(PREFIX_ASSET.length()));
					sCachedFonts.put(familyName, typeface);
					return typeface;
				}
			} catch (Exception e) {
				return Typeface.DEFAULT;
			}

			return sCachedFonts.get(familyName);
		}
	}
	return Typeface.create(familyName, style);
}
 
Example 2
Source File: FontUtils.java    From android-skeleton-project with MIT License 6 votes vote down vote up
/**
 * Creates Roboto typeface and puts it into cache
 * @param context
 * @param fontType
 * @return
 */
public static Typeface getTypeface(Context context, String fontType) {
    String fontPath = fontMap.get(fontType);
    Typeface newTypeface = null;
    try {
        if (!typefaceCache.containsKey(fontType))
        {
            typefaceCache.put(fontType, Typeface.createFromAsset(context.getAssets(), fontPath));
        }
        newTypeface = typefaceCache.get(fontType);
    } catch (NullPointerException e) {

    } catch (RuntimeException r) {
        newTypeface = Typeface.DEFAULT;
    }

    return newTypeface;
}
 
Example 3
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 4
Source File: PCanvas.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
public void typeface(String type) {
    Typeface selectedType;

    switch (type) {
        case "monospace":
            selectedType = Typeface.MONOSPACE;
            break;
        case "sans":
            selectedType = Typeface.SANS_SERIF;
            break;
        case "serif":
            selectedType = Typeface.SERIF;
            break;
        default:
            selectedType = Typeface.DEFAULT;

    }
    mPaintFill.setTypeface(selectedType);
}
 
Example 5
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
/* This code was taken from the method setFontStyle of the class ReactTextShadowNode
/* TODO: Factor into a common place they can both use
*/
@ReactProp(name = ViewProps.FONT_STYLE)
public void setFontStyle(ReactEditText view, @Nullable String fontStyleString) {
  int fontStyle = UNSET;
  if ("italic".equals(fontStyleString)) {
    fontStyle = Typeface.ITALIC;
  } else if ("normal".equals(fontStyleString)) {
    fontStyle = Typeface.NORMAL;
  }

  Typeface currentTypeface = view.getTypeface();
  if (currentTypeface == null) {
    currentTypeface = Typeface.DEFAULT;
  }
  if (fontStyle != currentTypeface.getStyle()) {
    view.setTypeface(currentTypeface, fontStyle);
  }
}
 
Example 6
Source File: LuaResourceFinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 在 asset 或者 文件系统 找字体文件
 * TODO 优化
 *
 * @param nameOrPath
 * @return
 */
public Typeface findTypeface(String nameOrPath) {
    Typeface typeface = null;
    if (!TextUtils.isEmpty(nameOrPath)) {
        String typefaceNameOrPath = FileUtil.hasPostfix(nameOrPath) ? nameOrPath : ParamUtil.getFileNameWithPostfix(nameOrPath, "ttf");//如果没有后缀,则处理成.ttf
        String filepath = buildPathInSdcardIfExists(typefaceNameOrPath);

        if (filepath != null) {//从文件系统加载
            typeface = TypefaceUtil.create(filepath);
        }

        if (typeface == null) {//从asset下加载
            filepath = buildPathInAssetsIfExists(typefaceNameOrPath);
            if (filepath != null) {
                typeface = TypefaceUtil.create(mContext, filepath);
            }
        }

        if (typeface == null) {//default name
            typeface = TypefaceUtil.create(mContext, nameOrPath);
        }
    }
    return typeface != null ? typeface : Typeface.DEFAULT;
}
 
Example 7
Source File: ContactEditText.java    From material with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
    mRecipientMap = new HashMap<>();
    mAutoCompleteMode = AUTOCOMPLETE_MODE_MULTI;

    mDefaultAvatarId = R.drawable.ic_user;
    mSpanHeight = ThemeUtil.dpToPx(context, 32);
    mSpanMaxWidth = ThemeUtil.dpToPx(context, 150);
    mSpanPaddingLeft = ThemeUtil.dpToPx(context, 8);
    mSpanPaddingRight = ThemeUtil.dpToPx(context, 12);
    mSpanTextSize = ThemeUtil.spToPx(context, 14);
    mSpanTextColor = 0xFF000000;
    mSpanTypeface = Typeface.DEFAULT;
    mSpanBackgroundColor = 0xFFE0E0E0;
    mSpanSpacing = ThemeUtil.dpToPx(context, 4);

    super.init(context, attrs, defStyleAttr, defStyleRes);
}
 
Example 8
Source File: RingProgressBar.java    From YCProgress with Apache License 2.0 6 votes vote down vote up
public RingProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initialize(context, attrs);


    // 其他准备工作
    mSin_1 = (float) Math.sin(Math.toRadians(1)); // 求sin(1°)。角度需转换成弧度
    mPaint = new Paint();
    mPaint.setAntiAlias(true);      // 消除锯齿

    //百分比字体类型,设置成默认值
    mPercentTypeface = Typeface.DEFAULT;

    mClearCanvasXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
    if (percentThinPadding != 0) {
        mPercentThinXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_OUT);
    }

}
 
Example 9
Source File: SpanFormatter.java    From nfcard with GNU General Public License v3.0 5 votes vote down vote up
FontSpan(int color, float size, Typeface face) {
	this.color = color;
	this.size = size;

	if (face == Typeface.DEFAULT) {
		this.face = null;
		this.bold = false;
	} else if (face == Typeface.DEFAULT_BOLD) {
		this.face = null;
		this.bold = true;
	} else {
		this.face = face;
		this.bold = false;
	}
}
 
Example 10
Source File: TypefaceUtils.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
private static int getCharGeometryCacheKey(final char referenceChar, final Paint paint) {
    final int labelSize = (int)paint.getTextSize();
    final Typeface face = paint.getTypeface();
    final int codePointOffset = referenceChar << 15;
    if (face == Typeface.DEFAULT) {
        return codePointOffset + labelSize;
    } else if (face == Typeface.DEFAULT_BOLD) {
        return codePointOffset + labelSize + 0x1000;
    } else if (face == Typeface.MONOSPACE) {
        return codePointOffset + labelSize + 0x2000;
    } else {
        return codePointOffset + labelSize;
    }
}
 
Example 11
Source File: MarkdownBuilderTest.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
public MarkdownBuilderTest() {
    Context context = InstrumentationRegistry.getTargetContext();
    int bulletPointColor = ContextCompat.getColor(context, R.color.colorAccent);
    int codeBackgroundColor = ContextCompat.getColor(context, R.color.code_background);
    Typeface codeBlockTypeface = Typeface.DEFAULT;
    builder = new MarkdownBuilder(bulletPointColor, codeBackgroundColor, codeBlockTypeface,
            new Parser());
}
 
Example 12
Source File: SuggestionItemResources.java    From persistentsearchview with Apache License 2.0 5 votes vote down vote up
public SuggestionItemResources() {
    mIconColor = Color.BLACK;
    mRecentSearchIconColor = Color.BLACK;
    mSearchSuggestionIconColor = Color.BLACK;
    mTextColor = Color.BLACK;
    mSelectedTextColor = Color.BLACK;
    mCurrentQuery = "";
    mTypeface = Typeface.DEFAULT;
}
 
Example 13
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 14
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
private static Typeface getTextTypeface(@Nullable final CharSequence text) {
    return hasStyleSpan(text, BOLD_SPAN) ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT;
}
 
Example 15
Source File: CollapsingTextHelper.java    From cathode with Apache License 2.0 4 votes vote down vote up
Typeface getExpandedTypeface() {
  return mExpandedTypeface != null ? mExpandedTypeface : Typeface.DEFAULT;
}
 
Example 16
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 );
}
 
Example 17
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 18
Source File: CollapsingTextHelper.java    From UIWidget with Apache License 2.0 4 votes vote down vote up
public Typeface getCollapsedTypeface() {
    return mCollapsedTypeface != null ? mCollapsedTypeface : Typeface.DEFAULT;
}
 
Example 19
Source File: IconData.java    From Status with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize all of the settings / variables of the icon to their
 * preference values. If it's the first init, this will also set up
 * the animated attributes; if not, it will simply update them to match
 * their 'default' values.
 *
 * @param isFirstInit Whether this is the first initialization of
 *                    the icon (this method may be called externally
 *                    to update values on a preference change without
 *                    restarting Status's entire service).
 */
protected void init(boolean isFirstInit) {
    iconColor.setDefault((int) PreferenceData.ICON_ICON_COLOR_LIGHT.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_ICON_COLOR.getValue(getContext()), getIdentifierArgs()));
    defaultIconDarkColor = (int) PreferenceData.ICON_ICON_COLOR_DARK.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_DARK_ICON_COLOR.getValue(getContext()), getIdentifierArgs());

    textColor.setDefault((int) PreferenceData.ICON_TEXT_COLOR_LIGHT.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_ICON_TEXT_COLOR.getValue(getContext()), getIdentifierArgs()));
    defaultTextDarkColor = (int) PreferenceData.ICON_TEXT_COLOR_DARK.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_DARK_ICON_TEXT_COLOR.getValue(getContext()), getIdentifierArgs());

    iconSize.setDefault(DimenUtils.dpToPx((int) PreferenceData.ICON_ICON_SCALE.getSpecificValue(getContext(), getIdentifierArgs())));
    iconOffsetX.to((int) PreferenceData.ICON_ICON_OFFSET_X.getSpecificValue(getContext(), getIdentifierArgs()));
    iconOffsetY.to((int) PreferenceData.ICON_ICON_OFFSET_Y.getSpecificValue(getContext(), getIdentifierArgs()));
    textSize.setDefault((float) DimenUtils.spToPx((float) (int) PreferenceData.ICON_TEXT_SIZE.getSpecificValue(getContext(), getIdentifierArgs())));
    textOffsetX.to((int) PreferenceData.ICON_TEXT_OFFSET_X.getSpecificValue(getContext(), getIdentifierArgs()));
    textOffsetY.to((int) PreferenceData.ICON_TEXT_OFFSET_Y.getSpecificValue(getContext(), getIdentifierArgs()));
    padding.to(DimenUtils.dpToPx((int) PreferenceData.ICON_ICON_PADDING.getSpecificValue(getContext(), getIdentifierArgs())));

    backgroundColor = PreferenceData.STATUS_COLOR.getValue(getContext());

    Typeface typefaceFont = Typeface.DEFAULT;
    String typefaceName = PreferenceData.ICON_TEXT_TYPEFACE.getSpecificOverriddenValue(getContext(), null, getIdentifierArgs());
    if (typefaceName != null) {
        try {
            typefaceFont = Typeface.createFromAsset(getContext().getAssets(), typefaceName);
        } catch (Exception ignored) {
        }
    }

    typeface = Typeface.create(typefaceFont, (int) PreferenceData.ICON_TEXT_EFFECT.getSpecificValue(getContext(), getIdentifierArgs()));

    isAnimations = PreferenceData.STATUS_ICON_ANIMATIONS.getValue(getContext());

    if (styles.size() > 0) {
        String name = PreferenceData.ICON_ICON_STYLE.getSpecificOverriddenValue(context, styles.get(0).name, getIdentifierArgs());
        if (name != null) {
            for (IconStyleData style : styles) {
                if (style.name.equals(name)) {
                    this.style = style;
                    break;
                }
            }
        }

        if (style == null) style = styles.get(0);
        onIconUpdate(level);
    }

    if (isFirstInit) {
        textAlpha.to(255);
        iconAlpha.to(255);
        textColor.setCurrent(textColor.getDefault());
        iconColor.setCurrent(iconColor.getDefault());
        textSize.toDefault();
        textOffsetX.setCurrent(textOffsetX.getTarget());
        textOffsetY.setCurrent(textOffsetY.getTarget());
        iconSize.toDefault();
        iconOffsetX.setCurrent(iconOffsetX.getTarget());
        iconOffsetY.setCurrent(iconOffsetY.getTarget());
    } else {
        if (isText)
            textSize.toDefault();
        if (isIcon)
            iconSize.toDefault();
    }
}
 
Example 20
Source File: FragmentPrice.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private void setupChart(LineChart chart, LineData data, int color) {
    ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);
    chart.getDescription().setEnabled(false);
    chart.setDrawGridBackground(false);
    chart.setTouchEnabled(false);
    chart.setDragEnabled(false);
    chart.setScaleEnabled(true);
    chart.setPinchZoom(false);
    chart.setBackgroundColor(color);
    chart.setViewPortOffsets(0, 23, 0, 0);
    chart.setData(data);
    Legend l = chart.getLegend();
    l.setEnabled(false);

    chart.getAxisLeft().setEnabled(true);
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getAxisLeft().setDrawAxisLine(false);
    chart.getAxisLeft().setSpaceTop(10);
    chart.getAxisLeft().setSpaceBottom(30);
    chart.getAxisLeft().setAxisLineColor(0xFFFFFF);
    chart.getAxisLeft().setTextColor(0xFFFFFF);
    chart.getAxisLeft().setDrawTopYLabelEntry(true);
    chart.getAxisLeft().setLabelCount(10);

    chart.getXAxis().setEnabled(true);
    chart.getXAxis().setDrawGridLines(false);
    chart.getXAxis().setDrawAxisLine(false);
    chart.getXAxis().setAxisLineColor(0xFFFFFF);
    chart.getXAxis().setTextColor(0xFFFFFF);

    Typeface tf = Typeface.DEFAULT;

    // X Axis
    XAxis xAxis = chart.getXAxis();
    xAxis.setTypeface(tf);
    xAxis.removeAllLimitLines();

    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);

    xAxis.setTextColor(Color.argb(150, 255, 255, 255));

    if (displayType == 1 || displayType == 2) // Week and Month
        xAxis.setValueFormatter(new WeekXFormatter());
    else if (displayType == 0) //  Day
        xAxis.setValueFormatter(new HourXFormatter());
    else
        xAxis.setValueFormatter(new YearXFormatter()); // Year

    // Y Axis
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.removeAllLimitLines();
    leftAxis.setTypeface(tf);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    leftAxis.setTextColor(Color.argb(150, 255, 255, 255));
    leftAxis.setValueFormatter(new DontShowNegativeFormatter(displayInUsd));
    chart.getAxisRight().setEnabled(false); // Deactivates horizontal lines

    chart.animateX(1300);
    chart.notifyDataSetChanged();
}