Java Code Examples for android.graphics.Paint#setFakeBoldText()

The following examples show how to use android.graphics.Paint#setFakeBoldText() . 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: QuranPageReadActivity.java    From QuranAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Function to draw number in the bitmap
     *
     * @param number Number to draw
     * @return the new bitmap after draw
     */
    public Bitmap drawNumbers(String number) {
        //Toast.makeText(QuranPageReadActivity.this,number,Toast.LENGTH_LONG).show();
        //GlobalAttributeUtil.setRepeatCounter(getApplicationContext(), number);
        final String numbers;
        numbers = number;

//        final MyApplication globalVariable = (MyApplication) getApplicationContext();
        float fontAndPadding = getResources().getDimension(R.dimen.draw_number);
        Paint paint = new Paint();
        paint.setTextSize(fontAndPadding);
        paint.setColor(Color.WHITE);
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        paint.setDither(true);
        paint.setFakeBoldText(true);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_repeat);
        Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
        Canvas canvas = new Canvas(mutableBitmap);
        canvas.drawText(numbers, bitmap.getWidth() - fontAndPadding, fontAndPadding, paint);
        return mutableBitmap;
    }
 
Example 2
Source File: QuranPageReadActivity.java    From QuranAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Function to draw number in the bitmap
 *
 * @param number Number to draw
 * @return the new bitmap after draw
 */
public Bitmap drawNumbers(String number) {
    float fontAndPadding = getResources().getDimension(R.dimen.draw_number);
    Paint paint = new Paint();
    paint.setTextSize(fontAndPadding);
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setFakeBoldText(true);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_repeat);
    Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    canvas.drawText(number, bitmap.getWidth() - fontAndPadding, fontAndPadding, paint);
    return mutableBitmap;
}
 
Example 3
Source File: SpanUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
private void apply(final Paint paint, final Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.getShader();

    paint.setTypeface(tf);
}
 
Example 4
Source File: CustomTypefaceSpan.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.setTypeface(tf);
}
 
Example 5
Source File: CustomTypefaceSpan.java    From Newslly with MIT License 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.setTypeface(tf);
}
 
Example 6
Source File: IndexBar.java    From ContactsList with Apache License 2.0 5 votes vote down vote up
/******************
 * common
 ******************/

private void initSetting(Context context, AttributeSet attrs) {
    mOnTouchingLetterChangeListener = getDummyListener();
    mNavigators = new ArrayList<>(0);
    mFocusIndex = -1;

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IndexBar);
    float textSize = typedArray.getDimension(R.styleable.IndexBar_letterSize, 8);
    int letterColor = typedArray.getColor(R.styleable.IndexBar_letterColor,
            ContextCompat.getColor(getContext(), android.R.color.white));
    mLetterSpacingExtra = typedArray.getFloat(R.styleable.IndexBar_letterSpacingExtra, 1.4f);
    int focusLetterColor = typedArray.getColor(R.styleable.IndexBar_focusLetterColor,
            ContextCompat.getColor(getContext(), android.R.color.white));
    typedArray.recycle();

    mPaint = new Paint();
    mPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mPaint.setAntiAlias(true);
    mPaint.setColor(letterColor);
    mPaint.setTextSize(textSize);

    mFocusPaint = new Paint();
    mFocusPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mFocusPaint.setAntiAlias(true);
    mFocusPaint.setFakeBoldText(true);
    mFocusPaint.setTextSize(textSize);
    mFocusPaint.setColor(focusLetterColor);

}
 
Example 7
Source File: StyleSpan.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
private static void apply(Paint paint, int style) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

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

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

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

    paint.setTypeface(tf);
}
 
Example 8
Source File: XulBasicTextRenderer.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Paint _getTextPaint(float fontSizeScale) {
	XulRenderContext ctx = _render.getRenderContext();
	Paint defPaint = ctx.getTextPaintByName(_fontFace);

	if (!(_fontShadowSize == 0 || (_fontShadowColor & 0xFF000000) == 0)) {
		defPaint = ctx.getShadowTextPaintByName(_fontFace);
		defPaint.setShadowLayer(_fontShadowSize, _fontShadowX, _fontShadowY, _fontShadowColor);
	}

	defPaint.setColor(_fontColor);
	if (Math.abs(fontSizeScale - 1.0f) > 0.01f) {
		defPaint.setTextSize(_fontSize * fontSizeScale);
	} else {
		defPaint.setTextSize(_fontSize);
	}

	if (_fontWeight > 1.0) {
		if (_fontWeight > 2.5) {
			defPaint.setStrokeWidth(_fontWeight*fontSizeScale/2);
		} else {
			defPaint.setFakeBoldText(true);
		}
	} else {
		defPaint.setFakeBoldText(false);
	}
	defPaint.setTextScaleX(_fontScaleX);
	defPaint.setUnderlineText(_fontUnderline);
	defPaint.setStrikeThruText(_fontStrikeThrough);
	defPaint.setTextSkewX(_fontItalic ? -0.25f : 0);
	defPaint.setTextAlign(Paint.Align.LEFT);
	return defPaint;
}
 
Example 9
Source File: TextDrawable.java    From ImageLetterIcon with Apache License 2.0 5 votes vote down vote up
private TextDrawable(Builder builder) {
    super(builder.shape);

    // shape properties
    shape = builder.shape;
    height = builder.height;
    width = builder.width;
    radius = builder.radius;

    // text and color
    text = builder.toUpperCase ? builder.text.toUpperCase() : builder.text;
    color = builder.color;
    borderColor = builder.borderColor;

    // text paint settings
    fontSize = builder.fontSize;
    textPaint = new Paint();
    textPaint.setColor(builder.textColor);
    textPaint.setAntiAlias(true);
    textPaint.setFakeBoldText(builder.isBold);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(builder.font);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setStrokeWidth(builder.borderThickness);

    // border paint settings
    borderThickness = builder.borderThickness;
    borderPaint = new Paint();
    borderPaint.setColor(borderColor);
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(borderThickness);

    // drawable paint color
    Paint paint = getPaint();
    paint.setColor(color);
}
 
Example 10
Source File: Trestle.java    From Trestle with Apache License 2.0 5 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    Typeface old = paint.getTypeface();
    int oldStyle = old == null ? 0 : old.getStyle();

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.setTypeface(tf);
}
 
Example 11
Source File: FontPreferenceCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
private void apply(final Paint paint) {
    final Typeface oldTypeface = paint.getTypeface();
    final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    final int fakeStyle = oldStyle & ~_typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.setTypeface(_typeface);
}
 
Example 12
Source File: CalligraphyTypefaceSpan.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void apply(final Paint paint) {
    final Typeface oldTypeface = paint.getTypeface();
    final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    final int fakeStyle = oldStyle & ~typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.setTypeface(typeface);
}
 
Example 13
Source File: TypefaceSpan.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
private void applyCustomTypeFace(Paint paint, Typeface tf) {
    Typeface old = paint.getTypeface();
    int oldStyle = old == null ? 0 : old.getStyle();

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

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

    paint.setTypeface(tf);
}
 
Example 14
Source File: MonthView.java    From MonthAndYearPicker with MIT License 5 votes vote down vote up
/**
 * Sets up the text and style properties for painting.
 */
private void initView() {

    _monthNumberSelectedPaint = new Paint();
    _monthNumberSelectedPaint.setAntiAlias(true);
    if (_monthBgSelectedColor != 0)
        _monthNumberSelectedPaint.setColor(_monthBgSelectedColor);
    // _monthNumberSelectedPaint.setAlpha(200);
    _monthNumberSelectedPaint.setTextAlign(Paint.Align.CENTER);
    _monthNumberSelectedPaint.setStyle(Paint.Style.FILL);
    _monthNumberSelectedPaint.setFakeBoldText(true);

    _monthNumberPaint = new Paint();
    _monthNumberPaint.setAntiAlias(true);
    if (_monthFontColorNormal != 0)
        _monthNumberPaint.setColor(_monthFontColorNormal);
    _monthNumberPaint.setTextSize(_monthTextSize);
    _monthNumberPaint.setTextAlign(Paint.Align.CENTER);
    _monthNumberPaint.setStyle(Paint.Style.FILL);
    _monthNumberPaint.setFakeBoldText(false);

    _monthNumberDisabledPaint = new Paint();
    _monthNumberDisabledPaint.setAntiAlias(true);
    if (_monthFontColorDisabled != 0)
        _monthNumberDisabledPaint.setColor(_monthFontColorDisabled);
    _monthNumberDisabledPaint.setTextSize(_monthTextSize);
    _monthNumberDisabledPaint.setTextAlign(Paint.Align.CENTER);
    _monthNumberDisabledPaint.setStyle(Paint.Style.FILL);
    _monthNumberDisabledPaint.setFakeBoldText(false);
}
 
Example 15
Source File: SimpleMonthView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
protected void initView() {
       mMonthTitlePaint = new Paint();
       mMonthTitlePaint.setFakeBoldText(true);
       mMonthTitlePaint.setAntiAlias(true);
       mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
       mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
       mMonthTitlePaint.setColor(mMonthTextColor);
       mMonthTitlePaint.setTextAlign(Align.CENTER);
       mMonthTitlePaint.setStyle(Style.FILL);

       mMonthTitleBGPaint = new Paint();
       mMonthTitleBGPaint.setFakeBoldText(true);
       mMonthTitleBGPaint.setAntiAlias(true);
       mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
       mMonthTitleBGPaint.setTextAlign(Align.CENTER);
       mMonthTitleBGPaint.setStyle(Style.FILL);

       mSelectedCirclePaint = new Paint();
       mSelectedCirclePaint.setFakeBoldText(true);
       mSelectedCirclePaint.setAntiAlias(true);
       mSelectedCirclePaint.setColor(mSelectedDaysColor);
       mSelectedCirclePaint.setTextAlign(Align.CENTER);
       mSelectedCirclePaint.setStyle(Style.FILL);
       mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

       mMonthDayLabelPaint = new Paint();
       mMonthDayLabelPaint.setAntiAlias(true);
       mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
       mMonthDayLabelPaint.setColor(mDayTextColor);
       mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
       mMonthDayLabelPaint.setStyle(Style.FILL);
       mMonthDayLabelPaint.setTextAlign(Align.CENTER);
       mMonthDayLabelPaint.setFakeBoldText(true);

       mMonthNumPaint = new Paint();
       mMonthNumPaint.setAntiAlias(true);
       mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
       mMonthNumPaint.setStyle(Style.FILL);
       mMonthNumPaint.setTextAlign(Align.CENTER);
       mMonthNumPaint.setFakeBoldText(false);
}
 
Example 16
Source File: MonthView.java    From cathode with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the text and style properties for painting. Override this if you
 * want to use a different paint.
 */
protected void initView() {
  mMonthTitlePaint = new Paint();
  mMonthTitlePaint.setFakeBoldText(true);
  mMonthTitlePaint.setAntiAlias(true);
  mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
  //mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
  mMonthTitlePaint.setColor(mDayTextColor);
  mMonthTitlePaint.setTextAlign(Align.CENTER);
  mMonthTitlePaint.setStyle(Style.FILL);

  mMonthTitleBGPaint = new Paint();
  mMonthTitleBGPaint.setFakeBoldText(true);
  mMonthTitleBGPaint.setAntiAlias(true);
  mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
  mMonthTitleBGPaint.setTextAlign(Align.CENTER);
  mMonthTitleBGPaint.setStyle(Style.FILL);

  mSelectedCirclePaint = new Paint();
  mSelectedCirclePaint.setFakeBoldText(true);
  mSelectedCirclePaint.setAntiAlias(true);
  mSelectedCirclePaint.setColor(mTodayNumberColor);
  mSelectedCirclePaint.setTextAlign(Align.CENTER);
  mSelectedCirclePaint.setStyle(Style.FILL);
  mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

  mMonthDayLabelPaint = new Paint();
  mMonthDayLabelPaint.setAntiAlias(true);
  mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
  mMonthDayLabelPaint.setColor(mMonthDayLabelColor);
  //mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
  mMonthDayLabelPaint.setStyle(Style.FILL);
  mMonthDayLabelPaint.setTextAlign(Align.CENTER);
  mMonthDayLabelPaint.setFakeBoldText(true);

  mMonthNumPaint = new Paint();
  mMonthNumPaint.setAntiAlias(true);
  mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
  mMonthNumPaint.setStyle(Style.FILL);
  mMonthNumPaint.setTextAlign(Align.CENTER);
  mMonthNumPaint.setFakeBoldText(false);
}
 
Example 17
Source File: ExportController.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
public static void exportPDF(Context ctx, Times times, @NonNull LocalDate from, @NonNull LocalDate to) throws IOException {
    PdfDocument document = new PdfDocument();

    PdfDocument.PageInfo pageInfo;
    int pw = 595;
    int ph = 842;
    pageInfo = new PdfDocument.PageInfo.Builder(pw, ph, 1).create();
    PdfDocument.Page page = document.startPage(pageInfo);
    Drawable launcher = Drawable.createFromStream(ctx.getAssets().open("pdf/launcher.png"), null);
    Drawable qr = Drawable.createFromStream(ctx.getAssets().open("pdf/qrcode.png"), null);
    Drawable badge =
            Drawable.createFromStream(ctx.getAssets().open("pdf/badge_" + LocaleUtils.getLanguage("en", "de", "tr", "fr", "ar") + ".png"),
                    null);

    launcher.setBounds(30, 30, 30 + 65, 30 + 65);
    qr.setBounds(pw - 30 - 65, 30 + 65 + 5, pw - 30, 30 + 65 + 5 + 65);
    int w = 100;
    int h = w * badge.getIntrinsicHeight() / badge.getIntrinsicWidth();
    badge.setBounds(pw - 30 - w, 30 + (60 / 2 - h / 2), pw - 30, 30 + (60 / 2 - h / 2) + h);


    Canvas canvas = page.getCanvas();

    Paint paint = new Paint();
    paint.setARGB(255, 0, 0, 0);
    paint.setTextSize(10);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText("com.metinkale.prayer", pw - 30 - w / 2f, 30 + (60 / 2f - h / 2f) + h + 10, paint);

    launcher.draw(canvas);
    qr.draw(canvas);
    badge.draw(canvas);

    paint.setARGB(255, 61, 184, 230);
    canvas.drawRect(30, 30 + 60, pw - 30, 30 + 60 + 5, paint);


    if (times.getSource().drawableId != 0) {
        Drawable source = ctx.getResources().getDrawable(times.getSource().drawableId);

        h = 65;
        w = h * source.getIntrinsicWidth() / source.getIntrinsicHeight();
        source.setBounds(30, 30 + 65 + 5, 30 + w, 30 + 65 + 5 + h);
        source.draw(canvas);
    }

    paint.setARGB(255, 0, 0, 0);
    paint.setTextSize(40);
    paint.setTextAlign(Paint.Align.LEFT);
    canvas.drawText(ctx.getText(R.string.appName).toString(), 30 + 65 + 5, 30 + 50, paint);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setFakeBoldText(true);
    canvas.drawText(times.getName(), pw / 2.0f, 30 + 65 + 50, paint);

    paint.setTextSize(12);
    int y = 30 + 65 + 5 + 65 + 30;
    int p = 30;
    int cw = (pw - p - p) / 7;
    canvas.drawText(ctx.getString(R.string.date), 30 + (0.5f * cw), y, paint);
    canvas.drawText(FAJR.getString(), 30 + (1.5f * cw), y, paint);
    canvas.drawText(Vakit.SUN.getString(), 30 + (2.5f * cw), y, paint);
    canvas.drawText(Vakit.DHUHR.getString(), 30 + (3.5f * cw), y, paint);
    canvas.drawText(Vakit.ASR.getString(), 30 + (4.5f * cw), y, paint);
    canvas.drawText(Vakit.MAGHRIB.getString(), 30 + (5.5f * cw), y, paint);
    canvas.drawText(Vakit.ISHAA.getString(), 30 + (6.5f * cw), y, paint);
    paint.setFakeBoldText(false);
    do {
        y += 20;
        canvas.drawText((from.toString("dd.MM.yyyy")), 30 + (0.5f * cw), y, paint);
        canvas.drawText(times.getTime(from, FAJR.ordinal()).toLocalTime().toString(), 30 + (1.5f * cw), y, paint);
        canvas.drawText(times.getTime(from, SUN.ordinal()).toLocalTime().toString(), 30 + (2.5f * cw), y, paint);
        canvas.drawText(times.getTime(from, DHUHR.ordinal()).toLocalTime().toString(), 30 + (3.5f * cw), y, paint);
        canvas.drawText(times.getTime(from, ASR.ordinal()).toLocalTime().toString(), 30 + (4.5f * cw), y, paint);
        canvas.drawText(times.getTime(from, MAGHRIB.ordinal()).toLocalTime().toString(), 30 + (5.5f * cw), y, paint);
        canvas.drawText(times.getTime(from, ISHAA.ordinal()).toLocalTime().toString(), 30 + (6.5f * cw), y, paint);
    } while (!(from = from.plusDays(1)).isAfter(to));
    document.finishPage(page);


    File outputDir = ctx.getCacheDir();
    if (!outputDir.exists())
        outputDir.mkdirs();
    File outputFile = new File(outputDir, times.getName().replace(" ", "_") + ".pdf");
    if (outputFile.exists())
        outputFile.delete();
    FileOutputStream outputStream = new FileOutputStream(outputFile);
    document.writeTo(outputStream);
    document.close();

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("application/pdf");

    Uri uri = FileProvider.getUriForFile(ctx, ctx.getString(R.string.FILE_PROVIDER_AUTHORITIES), outputFile);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    ctx.startActivity(Intent.createChooser(shareIntent, ctx.getResources().getText(R.string.export)));
}
 
Example 18
Source File: MonthView.java    From PersianDateRangePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the text and style properties for painting. Override this if you
 * want to use a different paint.
 */
protected void initView() {
  mMonthTitlePaint = new Paint();
  mMonthTitlePaint.setFakeBoldText(true);
  mMonthTitlePaint.setAntiAlias(true);
  mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
  if (mController.getTypeface() != null) {
    Typeface typeface = Typeface.create(TypefaceHelper.get(getContext(), mController.getTypeface()), Typeface.BOLD);
    mMonthTitlePaint.setTypeface(typeface);
  } else {
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
  }
  mMonthTitlePaint.setColor(mDayTextColor);
  mMonthTitlePaint.setTextAlign(Align.CENTER);
  mMonthTitlePaint.setStyle(Style.FILL);

  mSelectedCirclePaint = new Paint();
  mSelectedCirclePaint.setFakeBoldText(true);
  mSelectedCirclePaint.setAntiAlias(true);
  mSelectedCirclePaint.setColor(mTodayNumberColor);
  mSelectedCirclePaint.setTextAlign(Align.CENTER);
  if (mController.getTypeface() != null) {
    mSelectedCirclePaint.setTypeface(TypefaceHelper.get(getContext(), mController.getTypeface()));
  }
  mSelectedCirclePaint.setStyle(Style.FILL);
  mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

  mMonthDayLabelPaint = new Paint();
  mMonthDayLabelPaint.setAntiAlias(true);
  mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
  mMonthDayLabelPaint.setColor(mMonthDayTextColor);
  if (mController.getTypeface() != null) {
    mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(), mController.getTypeface()));
  } else {
    mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(), "Roboto-Medium"));
  }
  mMonthDayLabelPaint.setStyle(Style.FILL);
  mMonthDayLabelPaint.setTextAlign(Align.CENTER);
  mMonthDayLabelPaint.setFakeBoldText(true);

  mMonthNumPaint = new Paint();
  mMonthNumPaint.setAntiAlias(true);
  mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
  mMonthNumPaint.setStyle(Style.FILL);
  mMonthNumPaint.setTextAlign(Align.CENTER);
  if (mController.getTypeface() != null) {
    mMonthNumPaint.setTypeface(TypefaceHelper.get(getContext(), mController.getTypeface()));
  }
  mMonthNumPaint.setFakeBoldText(false);
}
 
Example 19
Source File: AirMonthView.java    From AirCalendar with MIT License 4 votes vote down vote up
protected void initView() {
        // 년월 타이틀을 그림
        mMonthTitlePaint = new Paint();
        mMonthTitlePaint.setFakeBoldText(true);
        mMonthTitlePaint.setAntiAlias(true);
        mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
        mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
        mMonthTitlePaint.setColor(mMonthTextColor);
        mMonthTitlePaint.setTextAlign(Align.LEFT);
        mMonthTitlePaint.setStyle(Style.FILL);

        mMonthTitleBGPaint = new Paint();
        mMonthTitleBGPaint.setFakeBoldText(true);
        mMonthTitleBGPaint.setAntiAlias(true);
        mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
        mMonthTitleBGPaint.setTextAlign(Align.CENTER);
        mMonthTitleBGPaint.setStyle(Style.FILL);

        mSelectedCirclePaint = new Paint();
        mSelectedCirclePaint.setFakeBoldText(true);
        mSelectedCirclePaint.setAntiAlias(true);
        mSelectedCirclePaint.setColor(mSelectedDaysBgColor);
        mSelectedCirclePaint.setTextAlign(Align.CENTER);
        mSelectedCirclePaint.setStyle(Style.FILL);

        mSelectedIntervalPaint = new Paint();
        mSelectedIntervalPaint.setAntiAlias(true);
        mSelectedIntervalPaint.setColor(mSelectedDaysBgColor);
//        mSelectedIntervalPaint.setAlpha(SELECTED_CIRCLE_ALPHA);

        mMonthDayLabelPaint = new Paint();
        mMonthDayLabelPaint.setAntiAlias(true);
        mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
        mMonthDayLabelPaint.setColor(getResources().getColor(R.color.colorMonthDayLabelPaint));
        mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
        mMonthDayLabelPaint.setStyle(Style.FILL);
        mMonthDayLabelPaint.setTextAlign(Align.CENTER);
        mMonthDayLabelPaint.setFakeBoldText(true);

        mWeekDayLinePaint = new Paint();
        mWeekDayLinePaint.setAntiAlias(true);
        mWeekDayLinePaint.setStrokeWidth((float) 2.0);
        mWeekDayLinePaint.setColor(mWeekDayLineColor);

        mMonthNumPaint = new Paint();
        mMonthNumPaint.setAntiAlias(true);
        mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
        mMonthNumPaint.setStyle(Style.FILL);
        mMonthNumPaint.setTextAlign(Align.CENTER);
        mMonthNumPaint.setFakeBoldText(false);
    }
 
Example 20
Source File: CompassView.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
public CompassView(Context context, AttributeSet attrs,
                   int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  setFocusable(true);
  final TypedArray a = context.obtainStyledAttributes(attrs,
    R.styleable.CompassView, defStyleAttr, 0);
  if (a.hasValue(R.styleable.CompassView_bearing)) {
    setBearing(a.getFloat(R.styleable.CompassView_bearing, 0));
  }
  a.recycle();

  Context c = this.getContext();
  Resources r = this.getResources();

  circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  circlePaint.setColor(ContextCompat.getColor(c, R.color.background_color));
  circlePaint.setStrokeWidth(1);
  circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  circlePaint.setStyle(Paint.Style.STROKE);

  northString = r.getString(R.string.cardinal_north);
  eastString = r.getString(R.string.cardinal_east);
  southString = r.getString(R.string.cardinal_south);
  westString = r.getString(R.string.cardinal_west);

  textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  textPaint.setColor(ContextCompat.getColor(c, R.color.text_color));
  textPaint.setTextSize(40);
  textPaint.setFakeBoldText(true);
  textPaint.setSubpixelText(true);
  textPaint.setTextAlign(Paint.Align.LEFT);
  textPaint.setTextSize(30);

  textHeight = (int)textPaint.measureText("yY");

  markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  markerPaint.setColor(ContextCompat.getColor(c, R.color.marker_color));
  markerPaint.setAlpha(200);
  markerPaint.setStrokeWidth(1);
  markerPaint.setStyle(Paint.Style.STROKE);
  markerPaint.setShadowLayer(2, 1, 1, ContextCompat.getColor(c,
    R.color.shadow_color));

  borderGradientColors = new int[4];
  borderGradientPositions = new float[4];
  borderGradientColors[3] = ContextCompat.getColor(c,
    R.color.outer_border);
  borderGradientColors[2] = ContextCompat.getColor(c,
    R.color.inner_border_one);
  borderGradientColors[1] = ContextCompat.getColor(c,
    R.color.inner_border_two);
  borderGradientColors[0] = ContextCompat.getColor(c,
    R.color.inner_border);
  borderGradientPositions[3] = 0.0f;
  borderGradientPositions[2] = 1-0.03f;
  borderGradientPositions[1] = 1-0.06f;
  borderGradientPositions[0] = 1.0f;

  glassGradientColors = new int[5];
  glassGradientPositions = new float[5];

  int glassColor = 245;
  glassGradientColors[4] = Color.argb(65, glassColor,
    glassColor, glassColor);
  glassGradientColors[3] = Color.argb(100, glassColor,
    glassColor, glassColor);
  glassGradientColors[2] = Color.argb(50, glassColor,
    glassColor, glassColor);
  glassGradientColors[1] = Color.argb(0, glassColor,
    glassColor, glassColor);
  glassGradientColors[0] = Color.argb(0, glassColor,
    glassColor, glassColor);
  glassGradientPositions[4] = 1-0.0f;
  glassGradientPositions[3] = 1-0.06f;
  glassGradientPositions[2] = 1-0.10f;
  glassGradientPositions[1] = 1-0.20f;
  glassGradientPositions[0] = 1-1.0f;

  skyHorizonColorFrom = ContextCompat.getColor(c,
    R.color.horizon_sky_from);
  skyHorizonColorTo = ContextCompat.getColor(c,
    R.color.horizon_sky_to);
  groundHorizonColorFrom = ContextCompat.getColor(c,
    R.color.horizon_ground_from);
  groundHorizonColorTo = ContextCompat.getColor(c,
    R.color.horizon_ground_to);
}