private Typeface getTypeface(TypedArray ta) { if (ta.hasValue(R.styleable.FancyButtonsAttrs_android_fontFamily)) { int fontId = ta.getResourceId(R.styleable.FancyButtonsAttrs_android_fontFamily, 0); if (fontId != 0) return ResourcesCompat.getFont(getContext(), fontId); } if(ta.hasValue(R.styleable.FancyButtonsAttrs_fb_textFontRes)){ int fontId = ta.getResourceId(R.styleable.FancyButtonsAttrs_fb_textFontRes, 0); if (fontId != 0) return ResourcesCompat.getFont(getContext(), fontId); } return null; }
/** * Set custom font for button Text * * @param fontId : Font id * Place your text fonts in font resources. * Eg. res/font/roboto.ttf or res/font/roboto.xml */ public void setCustomTextFont(@FontRes int fontId) { mTextTypeFace = ResourcesCompat.getFont(getContext(), fontId); if (mTextView == null) initializeFancyButton(); else mTextView.setTypeface(mTextTypeFace, textStyle); }
@Test public void getFont() { Typeface typeface = ResourcesCompat.getFont(getApplicationContext(), R.font.vt323_regular); assertThat(typeface).isNotNull(); } }
public static void showSnackbar(Snackbar snackbar) { snackbar.getView().setTag(SNACKBAR); TextView textView = snackbar.getView() .findViewById(android.support.design.R.id.snackbar_text); textView.setTypeface(ResourcesCompat .getFont(textView.getContext(), R.font.roboto_mono_medium)); snackbar.show(); }
Typeface typeface = ResourcesCompat.getFont(context, fontId); if (typeface != null) { textPaint.setTypeface(typeface);
private void drawStopWatch(Canvas canvas) { Log.i(TAG, "draw stop watch"); TextPaint textPaint = new TextPaint(); textPaint.setTextSize(mWidth * 0.35f); textPaint.setColor(Color.WHITE); Typeface typeface = ResourcesCompat.getFont(getContext(), R.font.proxima_nova_thin); textPaint.setTypeface(typeface); mMillisecondsTime = SystemClock.uptimeMillis() - mStartTime; mUpdateTime = mTimeBuffer + mMillisecondsTime; mSeconds = (int) (mUpdateTime / 1000); mMinutes = mSeconds / 60; mSeconds = mSeconds % 60; mMilliseconds = (int) (mUpdateTime % 1000); String value = String.format(Locale.getDefault(), "%02d", mMinutes) + ":" + String.format(Locale.getDefault(), "%02d", mSeconds); SpannableStringBuilder spannableString = new SpannableStringBuilder(value); StaticLayout layout = new StaticLayout(spannableString, textPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER, 1, 1, true); canvas.translate(mCenterX - layout.getWidth() / 2, mCenterY - layout.getHeight() / 2); layout.draw(canvas); if (mStopwatchState == StopwatchState.paused) mTimeBuffer += mMillisecondsTime; }
Typeface typeface = ResourcesCompat.getFont(getContext(), R.font.proxima_nova_thin); TextPaint textPaint = new TextPaint(); textPaint.setColor(minutesProgressColor);
@SuppressWarnings("inlineValue") public static TextView setToolbarTypeface(Toolbar toolbar) { for (int i = 0; i < toolbar.getChildCount(); i++) { View view = toolbar.getChildAt(i); if (view instanceof TextView) { TextView textView = (TextView) view; if (textView.getText().equals(toolbar.getTitle())) { Typeface typeface = ResourcesCompat .getFont(toolbar.getContext(), R.font.roboto_mono_medium); textView.setTypeface(typeface); return textView; } } } return null; }
this.hoursValuesColor = typedArray.getColor(R.styleable.Clock_hours_values_color, DEFAULT_PRIMARY_COLOR); int hoursTypeFace = typedArray.getResourceId(R.styleable.Clock_hours_values_font, R.font.proxima_nova_thin); this.hoursValuesTypeFace = ResourcesCompat.getFont(getContext(), hoursTypeFace); this.clockValueType = typedArray.getInt(R.styleable.Clock_clock_value_type, ClockValueType.none.getId()); this.clockValueDisposition = typedArray.getInt(R.styleable.Clock_clock_value_disposition, ClockValueDisposition.regular.getId());
/** * @param canvas */ private void drawNumbers(Canvas canvas) { TextPaint textPaint = new TextPaint(); textPaint.setTextSize(mWidth * 0.3f); textPaint.setColor(mNumbersColor); textPaint.setColor(mNumbersColor); Typeface typeface = ResourcesCompat.getFont(getContext(), R.font.proxima_nova_thin); textPaint.setTypeface(typeface); Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int amPm = calendar.get(Calendar.AM_PM); String time = String.format("%s:%s%s", String.format(Locale.getDefault(), "%02d", hour), String.format(Locale.getDefault(), "%02d", minute), amPm == AM ? "AM" : "PM"); SpannableStringBuilder spannableString = new SpannableStringBuilder(time); spannableString.setSpan(new RelativeSizeSpan(0.3f), spannableString.toString().length() - 2, spannableString.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // se superscript percent StaticLayout layout = new StaticLayout(spannableString, textPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER, 1, 1, true); canvas.translate(mCenterX - layout.getWidth() / 2, mCenterY - layout.getHeight() / 2); layout.draw(canvas); }
textPaint.setColor(Color.WHITE); Typeface typeface = ResourcesCompat.getFont(getContext(), R.font.proxima_nova_thin); textPaint.setTypeface(typeface);
public TextTool(Context context, ToolType toolType) { super(context, toolType); setRotationEnabled(ROTATION_ENABLED); setRespectImageBounds(RESPECT_IMAGE_BORDERS); setResizePointsVisible(RESIZE_POINTS_VISIBLE); stc = ResourcesCompat.getFont(context, R.font.stc_regular); dubai = ResourcesCompat.getFont(context, R.font.dubai); textPaint = new Paint(); initializePaint(); createOverlayBitmap(); createAndSetBitmap(); resetBoxPosition(); }
/** * @param x * @param y * @param canvas * @param progress */ private void drawProgressValue(int x, int y, Canvas canvas, float progress) { TextPaint textPaint = new TextPaint(); textPaint.setColor(mTextValueColor); textPaint.setStyle(Paint.Style.FILL); textPaint.setTextSize(mWidth * TEXT_FACTOR); Typeface typeface = ResourcesCompat.getFont(getContext(), mTextValueFont); textPaint.setTypeface(typeface); SpannableStringBuilder spannableString = getSpannableValue(progress); StaticLayout layout = new StaticLayout(spannableString, textPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER, 1, 1, true); canvas.translate(x - layout.getWidth() / 2, y - layout.getHeight() / 2); layout.draw(canvas); }
this.mTextColor = typeArray.getColor(R.styleable.CollectionPicker_cp_itemTextColor, mTextColor); this.simplifiedTags = typeArray.getBoolean(R.styleable.CollectionPicker_cp_simplified, false); this.tf = ResourcesCompat.getFont(getContext(), R.font.gt_medium); typeArray.recycle();
hoursValuesTypeFace = ResourcesCompat.getFont(getContext(), clockTheme.getHoursValuesFont()); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage());
Typeface typeface = ResourcesCompat.getFont(context, watermarkText.getTextFont()); watermarkPaint.setTypeface(typeface);
private void initialiseView() { binding = DataBindingUtil.setContentView(this, R.layout.activity_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); binding.search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); binding.search.setImeOptions(EditorInfo.IME_ACTION_SEARCH); binding.search.setIconifiedByDefault(false); binding.search.setOnQueryTextListener(this); EditText searchEditText = binding.search.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchEditText.setTextColor(getResources().getColor(android.R.color.white)); searchEditText.setHintTextColor(getResources().getColor(android.R.color.white)); Typeface myCustomFont = ResourcesCompat.getFont(getApplicationContext(), R.font.gt_medium); searchEditText.setTypeface(myCustomFont); searchListAdapter = new MovieSearchListAdapter(this); binding.includedLayout.moviesList.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); binding.includedLayout.moviesList.setAdapter(searchListAdapter); SnapHelper startSnapHelper = new PagerSnapHelper(position -> { MovieEntity trailer = searchListAdapter.getItem(position); updateBackground(trailer.getPosterPath()); }); startSnapHelper.attachToRecyclerView(binding.includedLayout.moviesList); binding.includedLayout.moviesList.addOnItemTouchListener(new RecyclerItemClickListener(getApplicationContext(), this)); }
private void initialiseView() { binding = DataBindingUtil.setContentView(this, R.layout.activity_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); binding.search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); binding.search.setImeOptions(EditorInfo.IME_ACTION_SEARCH); binding.search.setIconifiedByDefault(false); binding.search.setOnQueryTextListener(this); EditText searchEditText = binding.search.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchEditText.setTextColor(getResources().getColor(android.R.color.white)); searchEditText.setHintTextColor(getResources().getColor(android.R.color.white)); Typeface myCustomFont = ResourcesCompat.getFont(getApplicationContext(), R.font.gt_medium); searchEditText.setTypeface(myCustomFont); searchListAdapter = new TvSearchListAdapter(this); binding.includedLayout.moviesList.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); binding.includedLayout.moviesList.setAdapter(searchListAdapter); SnapHelper startSnapHelper = new PagerSnapHelper(position -> { TvEntity trailer = searchListAdapter.getItem(position); updateBackground(trailer.getPosterPath()); }); startSnapHelper.attachToRecyclerView(binding.includedLayout.moviesList); binding.includedLayout.moviesList.addOnItemTouchListener(new RecyclerItemClickListener(getApplicationContext(), this)); }