예제 #1
0
파일: Switch.java 프로젝트: 30962088/c11_as
 private Layout makeLayout(CharSequence text) {
   final CharSequence transformed =
       (mSwitchTransformationMethod != null)
           ? mSwitchTransformationMethod.getTransformation(text, this)
           : text;
   return new StaticLayout(
       transformed,
       mTextPaint,
       (int) FloatMath.ceil(Layout.getDesiredWidth(transformed, mTextPaint)),
       Layout.Alignment.ALIGN_NORMAL,
       1.f,
       0,
       true);
 }
예제 #2
0
파일: Switch.java 프로젝트: 30962088/c11_as
  /**
   * Sets the switch text color, size, style, hint color, and highlight color from the specified
   * TextAppearance resource.
   *
   * @attr ref android.R.styleable#Switch_switchTextAppearance
   */
  public void setSwitchTextAppearance(Context context, int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.TextAppearanceSwitch);

    ColorStateList colors;
    int ts;

    colors = appearance.getColorStateList(R.styleable.TextAppearanceSwitch_textColor);
    if (colors != null) {
      mTextColors = colors;
    } else {
      // If no color set in TextAppearance, default to the view's textColor
      mTextColors = getTextColors();
    }

    ts = appearance.getDimensionPixelSize(R.styleable.TextAppearanceSwitch_textSize, 0);
    if (ts != 0) {
      if (ts != mTextPaint.getTextSize()) {
        mTextPaint.setTextSize(ts);
        requestLayout();
      }
    }

    int typefaceIndex, styleIndex;

    typefaceIndex = appearance.getInt(R.styleable.TextAppearanceSwitch_typeface, -1);
    styleIndex = appearance.getInt(R.styleable.TextAppearanceSwitch_textStyle, -1);

    setSwitchTypefaceByIndex(typefaceIndex, styleIndex);

    boolean allCaps = appearance.getBoolean(R.styleable.TextAppearanceSwitch_textAllCaps, false);
    if (allCaps) {
      mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
      mSwitchTransformationMethod.setLengthChangesAllowed(true);
    } else {
      mSwitchTransformationMethod = null;
    }

    appearance.recycle();
  }