public static void sendTextBitmap(
      LiveViewAdapter liveView,
      int pluginId,
      String text,
      int bitmapSizeX,
      int fontSize,
      int bitmapSize) {

    // Empty bitmap and link the canvas to it
    Bitmap bitmap = null;
    try {
      bitmap = Bitmap.createBitmap(bitmapSizeX, bitmapSize, Bitmap.Config.RGB_565);
    } catch (IllegalArgumentException e) {
      return;
    }

    Canvas canvas = new Canvas(bitmap);

    // Set the text properties in the canvas
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(fontSize);
    textPaint.setColor(Color.WHITE);

    // Create the text layout and draw it to the canvas
    StaticLayout textLayout =
        new StaticLayout(text, textPaint, bitmapSizeX, Layout.Alignment.ALIGN_CENTER, 1, 1, false);

    textLayout.draw(canvas);

    try {
      liveView.sendImageAsBitmap(pluginId, centerX(bitmap), centerY(bitmap), bitmap);
    } catch (Exception e) {
      Log.d(PluginConstants.LOG_TAG, "Failed to send bitmap", e);
    }
  }
Esempio n. 2
0
  /** Initializes resources */
  private void initResourcesIfNecessary() {
    if (itemsPaint == null) {
      itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
      // itemsPaint.density = getResources().getDisplayMetrics().density;
      itemsPaint.setTextSize(TEXT_SIZE);
    }

    if (valuePaint == null) {
      valuePaint =
          new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
      // valuePaint.density = getResources().getDisplayMetrics().density;
      valuePaint.setTextSize(TEXT_SIZE);
      valuePaint.setShadowLayer(0.1f, 0, 0.1f, 0xFFC0C0C0);
    }

    if (centerDrawable == null) {
      centerDrawable = getContext().getResources().getDrawable(R.drawable.wheel_val);
    }

    if (topShadow == null) {
      topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }

    if (bottomShadow == null) {
      bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    setBackgroundResource(R.drawable.wheel_bg);
  }
Esempio n. 3
0
  /**
   * Computes (using "simulated" drawing/measuring) whether or not the (possibly multi-line) text,
   * will fit within a bounding box defined by the supplied parameters, when rendered at the
   * supplied text (font) size.
   *
   * @param textSize - the text/font size to use
   * @param targetWidth - the width of the containing box
   * @param targetHeight - the height of the containing box
   * @return whether or not the text will fit into the containing box with the provided text size
   */
  private boolean textFits(float textSize, float targetWidth, float targetHeight) {
    // Log.d("TFV", "text: "+text+" text height: "+layout.getHeight()+" target: "+targetHeight+"
    // fits: "+(layout.getWidth() <= targetWidth && layout.getHeight() <= targetHeight));

    // Set the paint's text size to the value used for simulation:
    paint.setTextSize(textSize);

    // Compute maximum width across the lines:
    float width = 0;
    for (String line : textLines)
      // measure bounds for each line of text:
      width =
          Math.max(
              width,
              paint.measureText(line)); // max width is max(previous max width, this line width)
    // determine height by doing no. lines * interline spacing (= font height + spacing between
    // bottom of one line and top of another)
    // NOTE: do not use Paint#getTextBounds because this ignores any spacing above or below the
    // character, which will be included by the
    // StaticLayout regardless (e.g. the bounds height of "." would be very low as it excludes the
    // space above the character)

    // Check whether the text fits:
    boolean fits =
        width <= targetWidth && textLines.length * paint.getFontMetrics(null) <= targetHeight;

    // Reset the paint's text size to match the value held by the view:
    paint.setTextSize(this.textSizePx);

    // Return result:
    return fits;
  }
  // Set the text size of the text paint object and use a static layout to render text off screen
  // before measuring
  private int getTextWidth(CharSequence source, TextPaint paint, int width, float textSize) {
    // modified: make a copy of the original TextPaint object for measuring
    // (apparently the object gets modified while measuring, see also the
    // docs for TextView.getPaint() (which states to access it read-only)

    if (source.toString().contains("\n")) {
      Log.d("DimmableButtonPanel", "source.toString() " + source.toString());
      String[] separated = source.toString().split("\n");
      int longest = 0;

      for (String testString : separated) {
        Log.d("DimmableButtonPanel", "testString " + testString);
        longest = testString.length() > longest ? testString.length() : longest;
      }

      return ((int)
          ((longest) * textSize * 0.85)); // + dpToPx(this.PaddingLeft) + dpToPx(this.PaddingRight);
    }

    TextPaint paintCopy = new TextPaint(paint);
    // Update the text paint object
    paintCopy.setTextSize(textSize);
    return 0; // ((int) ((source.length()  ) * textSize * 0.95));// + dpToPx(this.PaddingLeft) +
              // dpToPx(this.PaddingRight);
  }
Esempio n. 5
0
  private void initRuler(OsmandMapTileView view, FrameLayout parent) {
    rulerTextPaint = new TextPaint();
    rulerTextPaint.setTextSize(20 * scaleCoefficient);
    rulerTextPaint.setAntiAlias(true);

    rulerDrawable = view.getResources().getDrawable(R.drawable.ruler);
  }
 @Override
 public void updateDrawState(TextPaint ds) {
   ds.setColor(_context.getResources().getColor(R.color.red)); // set
   // text
   // color
   ds.setUnderlineText(false); // set to false to remove underline
 }
  private int getTextViewWidth(TextView tv) {
    TextPaint paint = tv.getPaint();
    int width = (int) paint.measureText(tv.getText().toString());
    width += 2 * mPaddingHor;

    return width;
  }
  void InitToolBarView() throws Exception {
    mSettingToolbar = (Toolbar) findViewById(R.id.setting_toolbar);
    mSettingToolbar.setTitle("");
    mSettingToolbar.setNavigationIcon(R.drawable.settingtoolbar_return);
    mSettingToolbarTextViewInfo = (TextView) findViewById(R.id.settingtoolbar_info);
    // 设置字体加粗
    TextPaint tp = mSettingToolbarTextViewInfo.getPaint();
    tp.setFakeBoldText(true);
    setSupportActionBar(mSettingToolbar);

    mViewNetset = (Switch) findViewById(R.id.setting_netsetting);
    mViewTempClear = (TextView) findViewById(R.id.setting_tempclear);
    String strTempSize = DataCleanManager.getTotalCacheSize(getApplicationContext());
    mViewTempClear.setText("清除缓存\n缓存大小为:" + strTempSize);
    mViewSetDefaultUrl = (TextView) findViewById(R.id.setting_setdefaulturl);
    mViewSetDefaultUrl.setText("设置默认网址\n默认网址为:" + GetDafaultUrl());
    mViewCheckUpdate = (TextView) findViewById(R.id.setting_checkupdate);
    mViewAbout = (TextView) findViewById(R.id.setting_about);
    mViewClose = (TextView) findViewById(R.id.setting_close);
    // 设置网络选项初始值
    mIsOnlyWifi = GetNetConfig();
    if (mIsOnlyWifi == 0) {
      SettingInfo.SetmIsOnlyWifi(false);
      mViewNetset.setChecked(false);
    } else {
      SettingInfo.SetmIsOnlyWifi(true);
      mViewNetset.setChecked(true);
    }
  }
Esempio n. 9
0
  /** Initialize the view */
  private final void init() {

    // Foreground text paint
    mTextPaint = new Paint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(16);
    mTextPaint.setColor(0xFF000000);

    // The shadow
    mTextPaintShadow = new TextPaint();
    mTextPaintShadow.setAntiAlias(true);
    mTextPaintShadow.setTextSize(16);
    mTextPaintShadow.setColor(0x00000000);

    // Base padding
    // setPadding(3, 3, 3, 3);

    mMovement = new Vector2D(0, 0);

    mOldMovement = new Vector2D(0, 0);

    // Create our edge paint
    mCurlEdgePaint = new Paint();
    mCurlEdgePaint.setAntiAlias(true);
    mCurlEdgePaint.setStyle(Paint.Style.STROKE);
    //	mCurlEdgePaint.setColor(this.edgeColor);

    //	mCurlEdgePaint.setShadowLayer(10, -5, 5, 0x99000000);

    // Set the default props, those come from an XML :D
    mCurlSpeed = 30;
    mInitialEdgeOffset = 20;
  }
  private Bitmap drawTextToBitmap(String gText) {
    Bitmap bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.TRANSPARENT);
    bitmap.setHasAlpha(true);

    //        bitmap.setHasAlpha(true);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.TRANSPARENT);

    TextPaint textPaint = new TextPaint();
    textPaint.setColor(Color.GREEN);
    textPaint.setTextSize(35);
    RectF rect = new RectF(0, 0, 300, 300);
    StaticLayout sl =
        new StaticLayout(
            gText, textPaint, (int) rect.width(), Layout.Alignment.ALIGN_NORMAL, 1, 1, false);
    canvas.save();
    sl.draw(canvas);
    canvas.restore();

    // Flip the image.
    Matrix m = new Matrix();
    m.preScale(-1, 1);
    Bitmap output =
        Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false);
    output.setDensity(DisplayMetrics.DENSITY_DEFAULT);

    return output;
  }
Esempio n. 11
0
  @Override
  protected void bindCommon(MessageWireframe message) {
    TLLocalContact contact = (TLLocalContact) message.message.getExtras();
    if (contact.getLastName().trim().length() == 0) {
      title = contact.getFirstName().trim();
    } else {
      title = contact.getFirstName().trim() + " " + contact.getLastName().trim();
    }
    phone = contact.getPhoneNumber();
    if (message.message.isOut()) {
      senderPaint.setColor(0xff739f53);
    } else {
      senderPaint.setColor(0xff4884cf);
    }
    this.date =
        org.telegram.android.ui.TextUtil.formatTime(message.message.getDate(), getContext());
    this.showState = message.message.isOut();

    this.basePlaceholder = getResources().getDrawable(R.drawable.st_user_placeholder_dialog);
    if (contact.getUserId() > 0) {
      placeHolderBgPaint.setColor(Placeholders.getBgColor(contact.getUserId()));
    } else {
      placeHolderBgPaint.setColor(Placeholders.GREY);
    }
    boolean isNotContact =
        (message.relatedUser != null) && (message.relatedUser.getLinkType() != LinkType.CONTACT);
    this.showAddButton = isNotContact && (contact.getUserId() != application.getCurrentUid());
    requestLayout();
  }
  @Override
  public void updateDrawState(TextPaint tp) {
    tp.setTypeface(mTypeface);

    // Note: This flag is required for proper typeface rendering
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
  }
  /**
   * Draws value and label layout.
   *
   * @param canvas the canvas for drawing
   */
  private void drawValue(Canvas canvas) {
    valuePaint.setColor(valueTextColor);
    valuePaint.drawableState = getDrawableState();

    labelPaint.setColor(labelTextColor);
    labelPaint.drawableState = getDrawableState();

    Rect bounds = new Rect();
    itemsLayout.getLineBounds(visibleItems / 2, bounds);

    // draw label
    if (labelLayout != null) {
      canvas.save();
      canvas.translate(itemsLayout.getWidth() + LABEL_OFFSET, bounds.top);
      labelLayout.draw(canvas);
      canvas.restore();
    }

    // draw current value
    if (valueLayout != null) {
      canvas.save();
      canvas.translate(0, bounds.top + scrollingOffset);
      valueLayout.draw(canvas);
      canvas.restore();
    }
  }
 @Override
 public void updateDrawState(TextPaint ds) {
   super.updateDrawState(ds);
   ds.setColor(mIsPressed ? mPressedTextColor : mNormalTextColor);
   ds.bgColor = mIsPressed ? mPressedBackgroundColor : mNormalBackgroundColor;
   ds.setUnderlineText(false);
 }
 public void draw(@NonNull Canvas canvas) {
   if (!hasValue()) {
     return;
   }
   if (offset.x == 0 && offset.y == 0) {
     calculatePosition();
   }
   if (highContrast) {
     paint.setColor(contrastColor);
     paint.setAlpha(255);
   }
   final int width = view.getWidth();
   final int height = view.getHeight();
   switch (direction) {
     case up:
       canvas.drawText(value, width + offset.x, offset.y, paint);
       break;
     case down:
       canvas.drawText(value, width + offset.x, height + offset.y, paint);
       break;
     case left:
       canvas.drawText(value, offset.x, height / 2 + offset.y, paint);
       break;
     case right:
       canvas.drawText(value, width + offset.x, height / 2 + offset.y, paint);
       break;
   }
   if (highContrast) {
     paint.setColor(color);
     paint.setAlpha(intAlpha());
   }
 }
  public void init(AttributeSet attrs) {
    TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.SlantedTextView);

    mTextSize = array.getDimension(R.styleable.SlantedTextView_slantedTextSize, mTextSize);
    mTextColor = array.getColor(R.styleable.SlantedTextView_slantedTextColor, mTextColor);
    mSlantedLength = array.getDimension(R.styleable.SlantedTextView_slantedLength, mSlantedLength);
    mSlantedBackgroundColor =
        array.getColor(R.styleable.SlantedTextView_slantedBackgroundColor, mSlantedBackgroundColor);

    if (array.hasValue(R.styleable.SlantedTextView_slantedText)) {
      mSlantedText = array.getString(R.styleable.SlantedTextView_slantedText);
    }

    if (array.hasValue(R.styleable.SlantedTextView_slantedMode)) {
      mMode = array.getInt(R.styleable.SlantedTextView_slantedMode, 0);
    }
    array.recycle();

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    mPaint.setAntiAlias(true);
    mPaint.setColor(mSlantedBackgroundColor);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
  }
Esempio n. 17
0
 private void drawTitle(Canvas paramCanvas)
 {
   boolean bool = isPlaying();
   if (bool)
     drawLivingLabel(paramCanvas);
   TextPaint localTextPaint = SkinManager.getInstance().getNormalTextPaint();
   String str = getTitle();
   int j = this.mArrowRect.left;
   int i;
   float f1;
   label123: float f2;
   if (bool)
   {
     i = this.mLivingRect.right + this.channelLayout.leftMargin;
     str = TextUtils.ellipsize(str, localTextPaint, j - i, TextUtils.TruncateAt.END).toString();
     localTextPaint.getTextBounds(str, 0, str.length(), this.textBound);
     if (!bool)
       break label202;
     f1 = this.mLivingRect.right + this.livingLayout.leftMargin;
     f2 = this.channelLayout.topMargin + (this.channelLayout.height - this.textBound.top - this.textBound.bottom) / 2;
     if ((!bool) && (!isItemPressed()))
       break label214;
     paramCanvas.drawText(str, f1, f2, SkinManager.getInstance().getHighlightTextPaint());
   }
   while (true)
   {
     drawSubInfo(paramCanvas);
     return;
     i = this.channelLayout.leftMargin;
     break;
     label202: f1 = this.channelLayout.leftMargin;
     break label123;
     label214: paramCanvas.drawText(str, f1, f2, localTextPaint);
   }
 }
Esempio n. 18
0
  private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    final TypedArray a =
        getContext().obtainStyledAttributes(attrs, R.styleable.MyView, defStyle, 0);

    mExampleString = a.getString(R.styleable.MyView_exampleString);
    mExampleColor = a.getColor(R.styleable.MyView_exampleColor, mExampleColor);
    // Use getDimensionPixelSize or getDimensionPixelOffset when dealing with
    // values that should fall on pixel boundaries.
    mExampleDimension = a.getDimension(R.styleable.MyView_exampleDimension, mExampleDimension);

    if (a.hasValue(R.styleable.MyView_exampleDrawable)) {
      mExampleDrawable = a.getDrawable(R.styleable.MyView_exampleDrawable);
      mExampleDrawable.setCallback(this);
    }

    a.recycle();

    // Set up a default TextPaint object
    mTextPaint = new TextPaint();
    mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.LEFT);

    // Update TextPaint and text measurements from attributes
    invalidateTextPaintAndMeasurements();
  }
  // 下面代码是利用上面计算的显示行数,将文字画在画布上,实时更新。
  @Override
  public void onDraw(Canvas canvas) {
    if (textList.size() == 0) return;
    for (int i = 0; i < textList.size(); i++) {

      if (step < this.getHeight() + textList.size() * tp.getTextSize()) {
        canvas.drawText(
            textList.get(i), 0, this.getHeight() + (i + 1) * tp.getTextSize() - step, tp);
        canvas.drawText(" ", 0, 40, tp);
      } else {
        step = 0;
      }
    }

    invalidate();
    // System.out.println("this.getHeight(): " + this.getHeight());
    if (this.getHeight() < textList.size() * textSize) {
      step = step + speed;
    } else {
      step = this.getHeight();
    }

    // if (step >= this.getHeight() + textList.size() * tp.getTextSize()) {
    // step = 0;
    // }
  }
Esempio n. 20
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (currentMessageObject == null) {
      return;
    }

    if (currentMessageObject.isOutOwner()) {
      timePaint.setColor(theme.ChatMusicCell_timePaint_color);
    } else {
      timePaint.setColor(theme.ChatMusicCell_timePaint_color_2);
    }
    radialProgress.draw(canvas);

    canvas.save();
    canvas.translate(timeX + titleX, AndroidUtilities.dp(12) + namesOffset);
    titleLayout.draw(canvas);
    canvas.restore();

    canvas.save();
    if (MediaController.getInstance().isPlayingAudio(currentMessageObject)) {
      canvas.translate(seekBarX, seekBarY);
      seekBar.draw(canvas);
    } else {
      canvas.translate(timeX + authorX, AndroidUtilities.dp(32) + namesOffset);
      authorLayout.draw(canvas);
    }
    canvas.restore();

    canvas.save();
    canvas.translate(timeX, AndroidUtilities.dp(52) + namesOffset);
    timeLayout.draw(canvas);
    canvas.restore();
  }
  @SuppressWarnings("NullableProblems")
  @Override
  protected void onDraw(Canvas canvas) {

    // Draw Title Text
    if (mAttributes.isShowTitle()
        && mTitlePaint != null
        && mCurTitleProperty != null
        && mCurTitleProperty.mAlpha != 0) {
      CharSequence buf = getHint();
      if (buf != null) {
        mTitlePaint.setTextSize(mCurTitleProperty.mTextSize);

        int color = getCurrentTitleTextColor();
        int alpha = GeniusUi.modulateAlpha(Color.alpha(color), mCurTitleProperty.mAlpha);

        mTitlePaint.setColor(color);
        mTitlePaint.setAlpha(alpha);

        canvas.drawText(
            buf,
            0,
            buf.length(),
            mCurTitleProperty.mPaddingLeft,
            mCurTitleProperty.mPaddingTop + mCurTitleProperty.mTextSize,
            mTitlePaint);
      }
    }

    super.onDraw(canvas);
  }
  private void sendTextBitmap(LiveViewAdapter mLiveViewAdapter, int mPluginId, String txt) {
    // Empty bitmap and link the canvas to it
    Bitmap bitmap = null;
    try {
      bitmap = Bitmap.createBitmap(128, 128, Bitmap.Config.RGB_565);
    } catch (IllegalArgumentException e) {
      return;
    }

    Canvas canvas = new Canvas(bitmap);

    // Set the text properties in the canvas
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(18);
    textPaint.setColor(Color.WHITE);

    // Create the text layout and draw it to the canvas
    Layout textLayout =
        new StaticLayout(txt, textPaint, 128, Layout.Alignment.ALIGN_CENTER, 1, 1, false);
    textLayout.draw(canvas);

    try {
      mLiveViewAdapter.sendImageAsBitmap(
          mPluginId, PluginUtils.centerX(bitmap), PluginUtils.centerY(bitmap), bitmap);
    } catch (Exception e) {
      Log.d(PluginConstants.LOG_TAG, "Failed to send bitmap", e);
    }
  }
 float addStyleRun(TextPaint paint, int len, FontMetricsInt fm) {
   if (fm != null) {
     paint.getFontMetricsInt(fm);
   }
   int p = this.mPos;
   this.mPos = p + len;
   if (this.mEasy) {
     return paint.getTextRunAdvances(this.mChars, p, len, p, len, this.mDir != 1, this.mWidths, p);
   }
   float totalAdvance = 0.0f;
   int level = this.mLevels[p];
   int q = p;
   int i = p + 1;
   int e = p + len;
   while (true) {
     if (i == e || this.mLevels[i] != level) {
       totalAdvance +=
           paint.getTextRunAdvances(
               this.mChars, q, i - q, q, i - q, (level & 1) != 0, this.mWidths, q);
       if (i == e) {
         return totalAdvance;
       }
       q = i;
       level = this.mLevels[i];
     }
     i++;
   }
 }
Esempio n. 24
0
File: ax.java Progetto: ZoneMo/test
 public final void updateDrawState(TextPaint paramTextPaint) {
   paramTextPaint.setColor(this.linkColor);
   if (asg()) {
     paramTextPaint.bgColor = this.bgColor;
     return;
   }
   paramTextPaint.bgColor = 0;
 }
 public void setTypeface(@NonNull Typeface newTypeface) {
   final Typeface oldTypeface = baseTextPaint.getTypeface();
   if (oldTypeface == newTypeface) {
     return;
   }
   baseTextPaint.setTypeface(newTypeface);
   textView.setBaseTextPaint(baseTextPaint);
 }
Esempio n. 26
0
  private void invalidateTextPaintAndMeasurements() {
    mTextPaint.setTextSize(mExampleDimension);
    mTextPaint.setColor(mExampleColor);
    mTextWidth = mTextPaint.measureText(mExampleString);

    Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = fontMetrics.bottom;
  }
 public static TextView applyNoteViewAttrs(Context context, EditText noteView, CharSequence text) {
   TextPaint paint = noteView.getPaint();
   paint.setFlags(TextPaint.ANTI_ALIAS_FLAG);
   noteView.setTypeface(Typeface.createFromAsset(context.getAssets(), "comic.ttf"));
   noteView.setText(text);
   Selection.removeSelection(noteView.getText());
   return noteView;
 }
 private void init(Context context) {
   DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
   float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 17.0F, displayMetrics);
   mTextPaint.setTextSize(textSize);
   Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
   cent1 = (int) (fontMetrics.descent - fontMetrics.ascent);
   cent2 = (int) fontMetrics.descent + 1 >> 1;
 }
Esempio n. 29
0
  @Override
  public void updateDrawState(TextPaint textPaint) {
    super.updateDrawState(textPaint);

    textPaint.setUnderlineText(false);
    textPaint.setColor(activity.getResources().getColor(R.color.secondary_text));
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC));
  }
Esempio n. 30
0
  /**
   * Sets the typeface in which the text should be displayed on the switch. Note that not all
   * Typeface families actually have bold and italic variants, so you may need to use {@link
   * #setSwitchTypeface(Typeface, int)} to get the appearance that you actually want.
   *
   * @attr ref android.R.styleable#TextView_typeface
   * @attr ref android.R.styleable#TextView_textStyle
   */
  public void setSwitchTypeface(Typeface tf) {
    if (mTextPaint.getTypeface() != tf) {
      mTextPaint.setTypeface(tf);

      requestLayout();
      invalidate();
    }
  }