Java Code Examples for android.graphics.Typeface#create()

The following examples show how to use android.graphics.Typeface#create() . 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: ReactFontManager.java    From react-native-GPay with MIT License 7 votes vote down vote up
private static
@Nullable Typeface createTypeface(
    String fontFamilyName,
    int style,
    AssetManager assetManager) {
  String extension = EXTENSIONS[style];
  for (String fileExtension : FILE_EXTENSIONS) {
    String fileName = new StringBuilder()
        .append(FONTS_ASSET_PATH)
        .append(fontFamilyName)
        .append(extension)
        .append(fileExtension)
        .toString();
    try {
      return Typeface.createFromAsset(assetManager, fileName);
    } catch (RuntimeException e) {
      // unfortunately Typeface.createFromAsset throws an exception instead of returning null
      // if the typeface doesn't exist
    }
  }

  return Typeface.create(fontFamilyName, style);
}
 
Example 2
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 3
Source File: FreeScrollingTextField.java    From CodeEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the text to use the new typeface, scrolls the view to display the
 * caret if needed, and invalidates the entire view
 */
public void setTypeface(Typeface typeface) {
    _defTypeface = typeface;
    _boldTypeface = Typeface.create(typeface, Typeface.BOLD);
    _italicTypeface = Typeface.create(typeface, Typeface.ITALIC);
    _brush.setTypeface(typeface);
    _brushLine.setTypeface(typeface);
    if (_hDoc.isWordWrap())
        _hDoc.analyzeWordWrap();
    _fieldController.updateCaretRow();
    if (!makeCharVisible(_caretPosition)) {
        invalidate();
    }
}
 
Example 4
Source File: GUITextPaint.java    From Beats with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Typeface getTypeface() {
	if (t == null) t = Typeface.create(
			family,
			bold ? (italic ? Typeface.BOLD_ITALIC : Typeface.BOLD) :
				   (italic ? Typeface.ITALIC : Typeface.NORMAL));
	return t;
}
 
Example 5
Source File: NavigationTabBar.java    From NavigationTabBar with Apache License 2.0 5 votes vote down vote up
public void setTypeface(final String typeface) {
    if (TextUtils.isEmpty(typeface)) return;

    Typeface tempTypeface;
    try {
        tempTypeface = Typeface.createFromAsset(getContext().getAssets(), typeface);
    } catch (Exception e) {
        tempTypeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
        e.printStackTrace();
    }

    setTypeface(tempTypeface);
}
 
Example 6
Source File: AmPmCirclesView.java    From Conquer with Apache License 2.0 5 votes vote down vote up
public void initialize(Context context, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;
    }

    Resources res = context.getResources();
    mWhite = res.getColor(R.color.white);
    mAmPmTextColor = res.getColor(R.color.ampm_text_color);
    mBlue = res.getColor(R.color.blue);
    String typefaceFamily = res.getString(R.string.sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    mCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;

    mIsInitialized = true;
}
 
Example 7
Source File: TimeAmPmCirclesView.java    From Android-SwitchDateTimePicker with Apache License 2.0 5 votes vote down vote up
public void initialize(Context context, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;
    }

    Resources res = context.getResources();

    String typefaceFamily = res.getString(R.string.sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    mCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;

    mIsInitialized = true;
}
 
Example 8
Source File: TextAppearanceSpan.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;

        if (tf != null) {
            style = tf.getStyle();
        }

        style |= mStyle;

        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        int fake = style & ~tf.getStyle();

        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(tf);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
Example 9
Source File: BaseExtStorageFontProvider.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Typeface loadTypeface(final FontFamilyType type, final FontInfo fi) {
    final File f = getFontFile(fi);
    try {
        return f.exists() ? Typeface.create(type.getResValue(), fi.style.getStyle()) : null;
    } catch (final Throwable th) {
        th.printStackTrace();
    }
    return null;
}
 
Example 10
Source File: StepArcView.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
/**
 * 3.圆环中心的步数
 */
private void drawTextNumber(Canvas canvas, float centerX) {
    Paint vTextPaint = new Paint();
    vTextPaint.setTextAlign(Paint.Align.CENTER);
    vTextPaint.setAntiAlias(true);//抗锯齿功能
    vTextPaint.setTextSize(numberTextSize);
    Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
    vTextPaint.setTypeface(font);//字体风格
    vTextPaint.setColor(getResources().getColor(R.color.red_500));
    Rect bounds_Number = new Rect();
    vTextPaint.getTextBounds(stepNumber, 0, stepNumber.length(), bounds_Number);
    canvas.drawText(stepNumber, centerX, getHeight() / 2 + bounds_Number.height() / 2, vTextPaint);

}
 
Example 11
Source File: TypefaceLoader.java    From react-native-navigation with MIT License 5 votes vote down vote up
private Typeface load(String fontFamilyName) {
	Typeface typeface = getTypefaceFromAssets(fontFamilyName);
	if (typeface != null) return typeface;

	int style = getStyle(fontFamilyName);
	return Typeface.create(fontFamilyName, style);
}
 
Example 12
Source File: AmPmCirclesView.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
public void initialize(Context context, TimePickerController controller, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;
    }

    Resources res = context.getResources();

    if (controller.isThemeDark()) {
        mUnselectedColor = getResources().getColor(R.color.mdtp_circle_background_dark_theme);
        mAmPmTextColor = getResources().getColor(R.color.mdtp_white);
        mAmPmDisabledTextColor = getResources().getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
        mSelectedAlpha = SELECTED_ALPHA_THEME_DARK;
    } else {
        mUnselectedColor = getResources().getColor(R.color.mdtp_white);
        mAmPmTextColor = getResources().getColor(R.color.mdtp_ampm_text_color);
        mAmPmDisabledTextColor = getResources().getColor( R.color.mdtp_date_picker_text_disabled);
        mSelectedAlpha = SELECTED_ALPHA;
    }

    mSelectedColor = controller.getAccentColor();
    mTouchedColor = Utils.darkenColor(mSelectedColor);
    mAmPmSelectedTextColor = getResources().getColor( R.color.mdtp_white);

    String typefaceFamily = res.getString(R.string.mdtp_sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    mCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.mdtp_circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mAmDisabled = controller.isAmDisabled();
    mPmDisabled = controller.isPmDisabled();

    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;

    mIsInitialized = true;
}
 
Example 13
Source File: RadialTextsView.java    From MaterialDateRangePicker with Apache License 2.0 4 votes vote down vote up
public void initialize(Resources res, String[] texts, String[] innerTexts,
        boolean is24HourMode, boolean disappearsOut) {
    if (mIsInitialized) {
        Log.e(TAG, "This RadialTextsView may only be initialized once.");
        return;
    }

    // Set up the paint.
    int numbersTextColor = res.getColor(R.color.range_numbers_text_color);
    mPaint.setColor(numbersTextColor);
    String typefaceFamily = res.getString(R.string.range_radial_numbers_typeface);
    mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL);
    String typefaceFamilyRegular = res.getString(R.string.range_sans_serif);
    mTypefaceRegular = Typeface.create(typefaceFamilyRegular, Typeface.NORMAL);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    // Set up the selected paint
    int selectedTextColor = res.getColor(R.color.range_white);
    mSelectedPaint.setColor(selectedTextColor);
    mSelectedPaint.setAntiAlias(true);
    mSelectedPaint.setTextAlign(Align.CENTER);

    mTexts = texts;
    mInnerTexts = innerTexts;
    mIs24HourMode = is24HourMode;
    mHasInnerCircle = (innerTexts != null);

    // Calculate the radius for the main circle.
    if (is24HourMode) {
        mCircleRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.range_circle_radius_multiplier_24HourMode));
    } else {
        mCircleRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.range_circle_radius_multiplier));
        mAmPmCircleRadiusMultiplier =
                Float.parseFloat(res.getString(R.string.range_ampm_circle_radius_multiplier));
    }

    // Initialize the widths and heights of the grid, and calculate the values for the numbers.
    mTextGridHeights = new float[7];
    mTextGridWidths = new float[7];
    if (mHasInnerCircle) {
        mNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.range_numbers_radius_multiplier_outer));
        mTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.range_text_size_multiplier_outer));
        mInnerNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.range_numbers_radius_multiplier_inner));
        mInnerTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.range_text_size_multiplier_inner));

        mInnerTextGridHeights = new float[7];
        mInnerTextGridWidths = new float[7];
    } else {
        mNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.range_numbers_radius_multiplier_normal));
        mTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.range_text_size_multiplier_normal));
    }

    mAnimationRadiusMultiplier = 1;
    mTransitionMidRadiusMultiplier = 1f + (0.05f * (disappearsOut? -1 : 1));
    mTransitionEndRadiusMultiplier = 1f + (0.3f * (disappearsOut? 1 : -1));
    mInvalidateUpdateListener = new InvalidateUpdateListener();

    mTextGridValuesDirty = true;
    mIsInitialized = true;
}
 
Example 14
Source File: DrawableUtils.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public static Bitmap getRoundedNumberImage(int number, int width, int height, int color, int thickness) {
    String text;

    if (number > 99) {
        text = "\u221E";
    } else {
        text = String.valueOf(number);
    }

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(color);
    Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
    paint.setTypeface(boldText);
    paint.setTextSize(Utils.dpToPx(14));
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int radius = Utils.dpToPx(2);

    RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(outer, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    radius--;
    RectF inner = new RectF(thickness, thickness, canvas.getWidth() - thickness, canvas.getHeight() - thickness);
    canvas.drawRoundRect(inner, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int xPos = (canvas.getWidth() / 2);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));

    canvas.drawText(String.valueOf(text), xPos, yPos, paint);

    return image;
}
 
Example 15
Source File: RunReviewOverlay.java    From science-journal with Apache License 2.0 4 votes vote down vote up
private void init() {
  Resources res = getResources();

  paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  paint.setStyle(Paint.Style.FILL);

  dotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  dotPaint.setStyle(Paint.Style.FILL);

  dotBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  dotBackgroundPaint.setColor(res.getColor(R.color.chart_margins_color));
  dotBackgroundPaint.setStyle(Paint.Style.FILL);

  Typeface valueTypeface = Typeface.create("sans-serif-medium", Typeface.NORMAL);
  Typeface timeTimeface = Typeface.create("sans-serif", Typeface.NORMAL);

  textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  textPaint.setTypeface(valueTypeface);
  textPaint.setTextSize(res.getDimension(R.dimen.run_review_overlay_label_text_size));
  textPaint.setColor(res.getColor(R.color.text_color_white));

  timePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  timePaint.setTypeface(timeTimeface);
  timePaint.setTextSize(res.getDimension(R.dimen.run_review_overlay_label_text_size));
  timePaint.setColor(res.getColor(R.color.text_color_white));

  centerLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  centerLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.chart_grid_line_width));
  centerLinePaint.setStyle(Paint.Style.STROKE);
  centerLinePaint.setColor(res.getColor(R.color.text_color_white));

  linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  linePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.recording_overlay_bar_width));
  int dashSize = res.getDimensionPixelSize(R.dimen.run_review_overlay_dash_size);
  linePaint.setPathEffect(new DashPathEffect(new float[] {dashSize, dashSize}, dashSize));
  linePaint.setColor(res.getColor(R.color.note_overlay_line_color));
  linePaint.setStyle(Paint.Style.STROKE);

  path = new Path();

  // TODO: Need to make sure this is at least as detailed as the SensorAppearance number
  // format!
  textFormat = res.getString(R.string.run_review_chart_label_format);
  timeFormat = ElapsedTimeAxisFormatter.getInstance(getContext());

  cropBackgroundPaint = new Paint();
  cropBackgroundPaint.setStyle(Paint.Style.FILL);
  cropBackgroundPaint.setColor(res.getColor(R.color.text_color_black));
  cropBackgroundPaint.setAlpha(40);

  cropVerticalLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  cropVerticalLinePaint.setStyle(Paint.Style.STROKE);
  cropVerticalLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.chart_grid_line_width));
}
 
Example 16
Source File: WeekWeatherView.java    From easyweather with MIT License 4 votes vote down vote up
private void init(Context context) {
    baseLinePaint = new Paint();
    baseLinePaint.setColor(ContextCompat.getColor(context, R.color.maincolor));
    baseLinePaint.setAntiAlias(true);
    baseLinePaint.setStyle(Paint.Style.FILL);
    baseLinePaint.setStrokeWidth(10);

    verticalLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    verticalLinePaint.setStyle(Paint.Style.STROKE);
    verticalLinePaint.setColor(ContextCompat.getColor(context, R.color.lightgray));
    verticalLinePaint.setAntiAlias(true);
    verticalLinePaint.setStrokeWidth(5);
    verticalLinePaint.setStrokeCap(Paint.Cap.ROUND);
    PathEffect effect = new DashPathEffect(new float[]{1, 2, 4, 8}, 1);
    verticalLinePaint.setPathEffect(effect);
    verticalLinePaint.setStrokeJoin(Paint.Join.ROUND);

    highPointPaint = new Paint();
    highPointPaint.setColor(ContextCompat.getColor(context, R.color.red));
    highPointPaint.setAntiAlias(true);
    highPointPaint.setStyle(Paint.Style.STROKE);
    highPointPaint.setStrokeWidth(5);

    lowPointPaint = new Paint();
    lowPointPaint.setColor(ContextCompat.getColor(context, R.color.maincolor));
    lowPointPaint.setAntiAlias(true);
    lowPointPaint.setStyle(Paint.Style.STROKE);
    lowPointPaint.setStrokeWidth(5);

    highLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    highLinePaint.setColor(ContextCompat.getColor(context, R.color.red));
    highLinePaint.setAntiAlias(true);
    highLinePaint.setStrokeWidth(5);
    highLinePaint.setStrokeCap(Paint.Cap.ROUND);
    highLinePaint.setStrokeJoin(Paint.Join.ROUND);
    highLinePaint.setStyle(Paint.Style.STROKE);

    lowLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    lowLinePaint.setColor(ContextCompat.getColor(context, R.color.cadetblue));
    lowLinePaint.setAntiAlias(true);
    lowLinePaint.setStrokeWidth(5);
    lowLinePaint.setStrokeCap(Paint.Cap.ROUND);
    lowLinePaint.setStrokeJoin(Paint.Join.ROUND);
    lowLinePaint.setStyle(Paint.Style.STROKE);

    mPath = new Path();
    dPath = new Path();

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(ContextCompat.getColor(context, R.color.black));
    String familyName = "宋体";
    Typeface font = Typeface.create(familyName, Typeface.BOLD);
    textPaint.setTypeface(font);
    textPaint.setTextAlign(Paint.Align.CENTER);

    lowTempPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    lowTempPaint.setColor(ContextCompat.getColor(context, R.color.cadetblue));
    lowTempPaint.setTypeface(font);
    lowTempPaint.setTextAlign(Paint.Align.CENTER);

    highTempPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    highTempPaint.setColor(ContextCompat.getColor(context, R.color.red));
    highTempPaint.setTypeface(font);
    highTempPaint.setTextAlign(Paint.Align.CENTER);
}
 
Example 17
Source File: RadialTextsView.java    From AlarmOn with Apache License 2.0 4 votes vote down vote up
public void initialize(Context context, String[] texts, String[] innerTexts,
        TimePickerController controller, SelectionValidator validator, boolean disappearsOut) {
    if (mIsInitialized) {
        Log.e(TAG, "This RadialTextsView may only be initialized once.");
        return;
    }
    Resources res = context.getResources();

    // Set up the paint.
    int textColorRes = controller.isThemeDark() ? R.color.mdtp_white : R.color.mdtp_numbers_text_color;
    mPaint.setColor(ContextCompat.getColor(context, textColorRes));
    String typefaceFamily = res.getString(R.string.mdtp_radial_numbers_typeface);
    mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL);
    String typefaceFamilyRegular = res.getString(R.string.mdtp_sans_serif);
    mTypefaceRegular = Typeface.create(typefaceFamilyRegular, Typeface.NORMAL);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    // Set up the selected paint
    int selectedTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mSelectedPaint.setColor(selectedTextColor);
    mSelectedPaint.setAntiAlias(true);
    mSelectedPaint.setTextAlign(Align.CENTER);

    // Set up the inactive paint
    int inactiveColorRes = controller.isThemeDark() ? R.color.mdtp_date_picker_text_disabled_dark_theme
            : R.color.mdtp_date_picker_text_disabled;
    mInactivePaint.setColor(ContextCompat.getColor(context, inactiveColorRes));
    mInactivePaint.setAntiAlias(true);
    mInactivePaint.setTextAlign(Align.CENTER);

    mTexts = texts;
    mInnerTexts = innerTexts;
    mIs24HourMode = controller.is24HourMode();
    mHasInnerCircle = (innerTexts != null);

    // Calculate the radius for the main circle.
    if (mIs24HourMode) {
        mCircleRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_circle_radius_multiplier_24HourMode));
    } else {
        mCircleRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_circle_radius_multiplier));
        mAmPmCircleRadiusMultiplier =
                Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier));
    }

    // Initialize the widths and heights of the grid, and calculate the values for the numbers.
    mTextGridHeights = new float[7];
    mTextGridWidths = new float[7];
    if (mHasInnerCircle) {
        mNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_numbers_radius_multiplier_outer));
        mTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_text_size_multiplier_outer));
        mInnerNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_numbers_radius_multiplier_inner));
        mInnerTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_text_size_multiplier_inner));

        mInnerTextGridHeights = new float[7];
        mInnerTextGridWidths = new float[7];
    } else {
        mNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_numbers_radius_multiplier_normal));
        mTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_text_size_multiplier_normal));
    }

    mAnimationRadiusMultiplier = 1;
    mTransitionMidRadiusMultiplier = 1f + (0.05f * (disappearsOut? -1 : 1));
    mTransitionEndRadiusMultiplier = 1f + (0.3f * (disappearsOut? 1 : -1));
    mInvalidateUpdateListener = new InvalidateUpdateListener();

    mValidator = validator;

    mTextGridValuesDirty = true;
    mIsInitialized = true;
}
 
Example 18
Source File: RadialTextsView.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
public void initialize(Context context, String[] texts, String[] innerTexts,
        TimePickerController controller, SelectionValidator validator, boolean disappearsOut) {
    if (mIsInitialized) {
        Log.e(TAG, "This RadialTextsView may only be initialized once.");
        return;
    }
    Resources res = context.getResources();

    // Set up the paint.
    int textColorRes = controller.isThemeDark() ? R.color.mdtp_white : R.color.mdtp_numbers_text_color;
    mPaint.setColor(ContextCompat.getColor(context, textColorRes));
    String typefaceFamily = res.getString(R.string.mdtp_radial_numbers_typeface);
    mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL);
    String typefaceFamilyRegular = res.getString(R.string.mdtp_sans_serif);
    mTypefaceRegular = Typeface.create(typefaceFamilyRegular, Typeface.NORMAL);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    // Set up the selected paint
    int selectedTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mSelectedPaint.setColor(selectedTextColor);
    mSelectedPaint.setAntiAlias(true);
    mSelectedPaint.setTextAlign(Align.CENTER);

    // Set up the inactive paint
    int inactiveColorRes = controller.isThemeDark() ? R.color.mdtp_date_picker_text_disabled_dark_theme
            : R.color.mdtp_date_picker_text_disabled;
    mInactivePaint.setColor(ContextCompat.getColor(context, inactiveColorRes));
    mInactivePaint.setAntiAlias(true);
    mInactivePaint.setTextAlign(Align.CENTER);

    mTexts = texts;
    mInnerTexts = innerTexts;
    mIs24HourMode = controller.is24HourMode();
    mHasInnerCircle = (innerTexts != null);

    // Calculate the radius for the main circle.
    if (mIs24HourMode || controller.getVersion() != TimePickerDialog.Version.VERSION_1) {
        mCircleRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_circle_radius_multiplier_24HourMode));
    } else {
        mCircleRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_circle_radius_multiplier));
        mAmPmCircleRadiusMultiplier =
                Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier));
    }

    // Initialize the widths and heights of the grid, and calculate the values for the numbers.
    mTextGridHeights = new float[7];
    mTextGridWidths = new float[7];
    if (mHasInnerCircle) {
        mNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_numbers_radius_multiplier_outer));
        mInnerNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_numbers_radius_multiplier_inner));

        // Version 2 layout draws outer circle bigger than inner
        if (controller.getVersion() == TimePickerDialog.Version.VERSION_1) {
            mTextSizeMultiplier = Float.parseFloat(
                    res.getString(R.string.mdtp_text_size_multiplier_outer));
            mInnerTextSizeMultiplier = Float.parseFloat(
                    res.getString(R.string.mdtp_text_size_multiplier_inner));
        } else {
            mTextSizeMultiplier = Float.parseFloat(
                    res.getString(R.string.mdtp_text_size_multiplier_outer_v2));
            mInnerTextSizeMultiplier = Float.parseFloat(
                    res.getString(R.string.mdtp_text_size_multiplier_inner_v2));
        }

        mInnerTextGridHeights = new float[7];
        mInnerTextGridWidths = new float[7];
    } else {
        mNumbersRadiusMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_numbers_radius_multiplier_normal));
        mTextSizeMultiplier = Float.parseFloat(
                res.getString(R.string.mdtp_text_size_multiplier_normal));
    }

    mAnimationRadiusMultiplier = 1;
    mTransitionMidRadiusMultiplier = 1f + (0.05f * (disappearsOut? -1 : 1));
    mTransitionEndRadiusMultiplier = 1f + (0.3f * (disappearsOut? 1 : -1));
    mInvalidateUpdateListener = new InvalidateUpdateListener();

    mValidator = validator;

    mTextGridValuesDirty = true;
    mIsInitialized = true;
}
 
Example 19
Source File: OControlHelper.java    From framework with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Typeface boldFont() {
    return Typeface.create("sans-serif-condensed", 0);
}
 
Example 20
Source File: AndroidPaint.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private static Typeface getTypeface(org.oscim.backend.canvas.Paint.FontFamily fontFamily,
                                    org.oscim.backend.canvas.Paint.FontStyle fontStyle) {
    final int style;
    switch (fontStyle) {
        case BOLD:
            style = Typeface.BOLD;
            break;
        case BOLD_ITALIC:
            style = Typeface.BOLD_ITALIC;
            break;
        case ITALIC:
            style = Typeface.ITALIC;
            break;
        default:
            style = Typeface.NORMAL;
            break;
    }

    switch (fontFamily) {
        case DEFAULT:
            return Typeface.create(Typeface.DEFAULT, style);
        case DEFAULT_BOLD:
            return Typeface.create(Typeface.DEFAULT_BOLD, style);
        case MONOSPACE:
            return Typeface.create(Typeface.MONOSPACE, style);
        case SANS_SERIF:
            return Typeface.create(Typeface.SANS_SERIF, style);
        case SERIF:
            return Typeface.create(Typeface.SERIF, style);
        case THIN:
            return Typeface.create("sans-serif-thin", style);
        case LIGHT:
            return Typeface.create("sans-serif-light", style);
        case MEDIUM:
            return Typeface.create("sans-serif-medium", style);
        case BLACK:
            return Typeface.create("sans-serif-black", style);
        case CONDENSED:
            return Typeface.create("sans-serif-condensed", style);
    }

    throw new IllegalArgumentException("unknown font family: " + fontFamily);
}