Java Code Examples for android.widget.TextView#getTypeface()

The following examples show how to use android.widget.TextView#getTypeface() . 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: StepTab.java    From android-material-stepper with Apache License 2.0 6 votes vote down vote up
public StepTab(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(getContext()).inflate(R.layout.ms_step_tab, this, true);

    mSelectedColor = ContextCompat.getColor(context, R.color.ms_selectedColor);
    mUnselectedColor = ContextCompat.getColor(context, R.color.ms_unselectedColor);
    mErrorColor = ContextCompat.getColor(context, R.color.ms_errorColor);

    mStepNumberTextView = (TextView) findViewById(R.id.ms_stepNumber);
    mStepDoneIndicator = (ImageView) findViewById(R.id.ms_stepDoneIndicator);
    mStepIconBackground = (ImageView) findViewById(R.id.ms_stepIconBackground);
    mStepDivider = findViewById(R.id.ms_stepDivider);
    mStepTitleTextView = (TextView) findViewById(R.id.ms_stepTitle);
    mStepSubtitleTextView = (TextView) findViewById(R.id.ms_stepSubtitle);

    mTitleColor = mStepTitleTextView.getCurrentTextColor();
    mSubtitleColor = mStepSubtitleTextView.getCurrentTextColor();

    Typeface typeface = mStepTitleTextView.getTypeface();
    mNormalTypeface = Typeface.create(typeface, Typeface.NORMAL);
    mBoldTypeface = Typeface.create(typeface, Typeface.BOLD);
    Drawable avd = createCircleToWarningDrawable();
    mStepIconBackground.setImageDrawable(avd);
}
 
Example 2
Source File: FontUtils.java    From FontTextView with MIT License 6 votes vote down vote up
/**
 * <p>Replace the font of specified view and it's children with specified typeface</p>
 */
private void replaceFont(@NonNull View root, @NonNull Typeface typeface) {
    if (root == null || typeface == null) {
        return;
    }

    if (root instanceof TextView) { // If view is TextView or it's subclass, replace it's font
        TextView textView = (TextView)root;
        // Extract previous style of TextView
        int style = Typeface.NORMAL;
        if (textView.getTypeface() != null) {
            style = textView.getTypeface().getStyle();
        }
        textView.setTypeface(typeface, style);
    } else if (root instanceof ViewGroup) { // If view is ViewGroup, apply this method on it's child views
        ViewGroup viewGroup = (ViewGroup) root;
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            replaceFont(viewGroup.getChildAt(i), typeface);
        }
    } // else return
}
 
Example 3
Source File: AACustomFont.java    From AACustomFont with MIT License 5 votes vote down vote up
/**
 * Static method for setting the typeface for the given View
 * The font file should be placed in assets folder in the directory of fonts.
 * Any view that has parent class of TextView can easily use this method.
 *
 * @param view     typeface view
 * @param fontName font name
 */
public static void setCustomFont(View view, String fontName) {
    if (view instanceof TextView) {
        Context context = view.getContext();
        Typeface font = getInstance(context).get(fontName);
        TextView textView = (TextView) view;
        if (textView.getTypeface() != font)
            textView.setTypeface(font);
    }
}
 
Example 4
Source File: TypefaceHelper.java    From android-u2f-bridge with Apache License 2.0 5 votes vote down vote up
public static void applyFont(TextView textView) {
    if (textView.getTypeface() != null && textView.getTypeface().isBold()) {
        textView.setTypeface(getTypeface(textView.getContext(), FontStyle.BOLD));
    } else {
        textView.setTypeface(getTypeface(textView.getContext(), FontStyle.REGULAR));
    }
}
 
Example 5
Source File: MdLayoutInflaterFactory.java    From android-md-core with Apache License 2.0 5 votes vote down vote up
protected void supportTypeface(Context context, TextView view, AttributeSet attrs) {
  if (view == null) {
    return;
  }
  Typeface typeface = Typography.getTypeface(context, attrs, view instanceof Button ? R.attr.buttonStyle : 0, 0);
  typeface = typeface != null ? typeface : Typography.getDefaultTypeface(context);
  if (typeface != null && view.getTypeface() != typeface) {
    view.setTypeface(typeface);
  }
}
 
Example 6
Source File: RowHeaderPresenter.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
protected static float getFontDescent(TextView textView, Paint fontMeasurePaint) {
    if (fontMeasurePaint.getTextSize() != textView.getTextSize()) {
        fontMeasurePaint.setTextSize(textView.getTextSize());
    }
    if (fontMeasurePaint.getTypeface() != textView.getTypeface()) {
        fontMeasurePaint.setTypeface(textView.getTypeface());
    }
    return fontMeasurePaint.descent();
}
 
Example 7
Source File: TypefaceHelper.java    From android-typeface-helper with Apache License 2.0 5 votes vote down vote up
/**
 * Apply typeface to single view
 *
 * @param view      to typeface typeface
 * @param typefaceCollection typeface collection
 */
private static void applyForView(View view, TypefaceCollection typefaceCollection) {

	if (view instanceof TextView) {
		TextView textView = (TextView) view;
		Typeface oldTypeface = textView.getTypeface();
		final int style = oldTypeface == null ? Typeface.NORMAL : oldTypeface.getStyle();
		textView.setTypeface(typefaceCollection.getTypeface(style));
		textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
	}
}
 
Example 8
Source File: ViewHierarchyElementAndroid.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 4 votes vote down vote up
Builder(int id, @Nullable ViewHierarchyElementAndroid parent, View fromView) {
  // Bookkeeping
  this.id = id;
  this.parentId = (parent != null) ? parent.getId() : null;

  this.drawingOrder = null;

  // API 16+ properties
  this.scrollable = AT_16 ? fromView.isScrollContainer() : null;

  // API 11+ properties
  this.backgroundDrawableColor =
      (AT_11 && (fromView != null) && (fromView.getBackground() instanceof ColorDrawable))
          ? ((ColorDrawable) fromView.getBackground()).getColor()
          : null;

  // Base properties
  this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView);
  this.className = fromView.getClass().getName();
  this.accessibilityClassName = null;
  this.packageName = fromView.getContext().getPackageName();
  this.resourceName =
      (fromView.getId() != View.NO_ID)
          ? ViewAccessibilityUtils.getResourceNameForView(fromView)
          : null;
  this.contentDescription = SpannableStringAndroid.valueOf(fromView.getContentDescription());
  this.enabled = fromView.isEnabled();
  if (fromView instanceof TextView) {
    TextView textView = (TextView) fromView;
    // Hint text takes precedence if no text is present.
    CharSequence text = textView.getText();
    if (TextUtils.isEmpty(text)) {
      text = textView.getHint();
    }
    this.text = SpannableStringAndroid.valueOf(text);
    this.textSize = textView.getTextSize();

    this.textColor = textView.getCurrentTextColor();
    this.typefaceStyle =
        (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null;
  } else {
    this.text = null;
    this.textSize = null;
    this.textColor = null;
    this.typefaceStyle = null;
  }

  this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView);
  this.clickable = fromView.isClickable();
  this.longClickable = fromView.isLongClickable();
  this.focusable = fromView.isFocusable();
  this.editable = ViewAccessibilityUtils.isViewEditable(fromView);
  this.canScrollForward =
      (ViewCompat.canScrollVertically(fromView, 1)
          || ViewCompat.canScrollHorizontally(fromView, 1));
  this.canScrollBackward =
      (ViewCompat.canScrollVertically(fromView, -1)
          || ViewCompat.canScrollHorizontally(fromView, -1));
  this.checkable = (fromView instanceof Checkable);
  this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null;
  this.hasTouchDelegate = (fromView.getTouchDelegate() != null);
  this.touchDelegateBounds = ImmutableList.of(); // Unavailable from the View API
  this.boundsInScreen = getBoundsInScreen(fromView);
  this.nonclippedHeight = fromView.getHeight();
  this.nonclippedWidth = fromView.getWidth();
  this.actionList = ImmutableList.of(); // Unavailable from the View API
}
 
Example 9
Source File: BySearch.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@Override
public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags)
{
    long now = System.currentTimeMillis();
    int position = cursor.getPosition();

    // set list title
    String groupTitle = getTitle(cursor, view.getContext());
    TextView title = (TextView) view.findViewById(android.R.id.title);
    if (title != null)
    {
        title.setText(groupTitle);

    }
    // set search time
    TextView text1 = (TextView) view.findViewById(android.R.id.text1);
    if (text1 != null)
    {
        text1.setText(DateUtils.getRelativeTimeSpanString(
                cursor.getLong(cursor.getColumnIndex(SearchHistoryDatabaseHelper.SearchHistoryColumns.TIMESTAMP)), now, DateUtils.MINUTE_IN_MILLIS));
    }

    // set list elements
    TextView text2 = (TextView) view.findViewById(android.R.id.text2);
    int childrenCount = adapter.getChildrenCount(position);
    if (text2 != null && ((ExpandableGroupDescriptorAdapter) adapter).childCursorLoaded(position))
    {
        Resources res = view.getContext().getResources();

        text2.setText(res.getQuantityString(R.plurals.number_of_tasks, childrenCount, childrenCount));
    }

    // show/hide divider
    View divider = view.findViewById(R.id.divider);
    if (divider != null)
    {
        divider.setVisibility((flags & FLAG_IS_EXPANDED) != 0 && childrenCount > 0 ? View.VISIBLE : View.GONE);
    }

    View colorbar1 = view.findViewById(R.id.colorbar1);
    View colorbar2 = view.findViewById(R.id.colorbar2);

    if (colorbar1 != null)
    {
        colorbar1.setVisibility(View.GONE);
    }
    if (colorbar2 != null)
    {
        colorbar2.setVisibility(View.GONE);
    }

    View removeSearch = view.findViewById(R.id.quick_add_task);
    if (removeSearch != null)
    {
        ((ImageView) removeSearch).setImageResource(R.drawable.content_remove);
        removeSearch.setOnClickListener(removeListener);
        GroupTag tag = (GroupTag) removeSearch.getTag();
        Long groupId = cursor.getLong(cursor.getColumnIndex(SearchHistoryColumns._ID));
        if (tag == null || tag.groupId != groupId)
        {
            removeSearch.setTag(new GroupTag(groupTitle, groupId));
        }
    }

    if ((flags & FLAG_IS_EXPANDED) != 0)
    {
        if (removeSearch != null)
        {
            removeSearch.setVisibility(View.VISIBLE);
        }
        if (text2 != null)
        {
            text2.setVisibility(View.GONE);
        }
    }
    else
    {
        if (removeSearch != null)
        {
            removeSearch.setVisibility(View.GONE);
        }
        if (text2 != null)
        {
            text2.setVisibility(View.VISIBLE);
        }
    }

    // TODO: swap styles instead of modifying the font style
    boolean isHistoric = cursor.getInt(cursor.getColumnIndex(SearchHistoryColumns.HISTORIC)) > 0;
    Typeface oldtypeface = title.getTypeface();
    title.setTypeface(oldtypeface, swapStyle(isHistoric, oldtypeface));

    // set history icon
    ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
    icon.setImageResource(R.drawable.ic_history);
    icon.setVisibility(isHistoric ? View.VISIBLE : View.INVISIBLE);
}