android.text.method.SingleLineTransformationMethod#android.text.method.TransformationMethod源码实例Demo

下面列出了android.text.method.SingleLineTransformationMethod#android.text.method.TransformationMethod 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: stynico   文件: AutofitHelper.java
private static int getMaxLines(AppCompatTextView view)
{
       int maxLines = -1; // No limit (Integer.MAX_VALUE also means no limit)

       TransformationMethod method = view.getTransformationMethod();
       if (method != null && method instanceof SingleLineTransformationMethod)
	{
           maxLines = 1;
       }
       else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
           // setMaxLines() and getMaxLines() are only available on android-16+
           maxLines = view.getMaxLines();
       }

       return maxLines;
   }
 
/** Sets the transformation method. */
public static ViewAction setTransformationMethod(
    final TransformationMethod transformationMethod) {
  return new ViewAction() {

    @Override
    public Matcher<View> getConstraints() {
      return ViewMatchers.isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the transformation method";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout item = (TextInputLayout) view;
      item.getEditText().setTransformationMethod(transformationMethod);
    }
  };
}
 
源代码3 项目: kAndroid   文件: AutofitHelper.java
private static int getMaxLines(TextView view) {
    int maxLines = -1; // No limit (Integer.MAX_VALUE also means no limit)

    TransformationMethod method = view.getTransformationMethod();
    if (method != null && method instanceof SingleLineTransformationMethod) {
        maxLines = 1;
    }
    else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // setMaxLines() and getMaxLines() are only available on android-16+
        maxLines = view.getMaxLines();
    }

    return maxLines;
}
 
源代码4 项目: DevUtils   文件: EditTextUtils.java
/**
 * 获取文本视图显示转换
 * @param editText {@link EditText}
 * @param <T>      泛型
 * @return {@link TransformationMethod}
 */
public static <T extends EditText> TransformationMethod getTransformationMethod(final T editText) {
    if (editText != null) {
        return editText.getTransformationMethod();
    }
    return null;
}
 
源代码5 项目: DevUtils   文件: ViewHelper.java
/**
 * 设置文本视图显示转换
 * @param view   {@link View}
 * @param method {@link TransformationMethod}
 * @return {@link ViewHelper}
 */
public ViewHelper setTransformationMethod(final View view, final TransformationMethod method) {
    if (view instanceof EditText) {
        EditTextUtils.setTransformationMethod(EditTextUtils.getEditText(view), method);
    } else {
        TextViewUtils.setTransformationMethod(view, method);
    }
    return this;
}
 
源代码6 项目: DevUtils   文件: TextViewUtils.java
/**
 * 获取文本视图显示转换
 * @param textView {@link TextView}
 * @param <T>      泛型
 * @return {@link TransformationMethod}
 */
public static <T extends TextView> TransformationMethod getTransformationMethod(final T textView) {
    if (textView != null) {
        return textView.getTransformationMethod();
    }
    return null;
}
 
源代码7 项目: VideoOS-Android-SDK   文件: TextUtil.java
static int getMaxLines(TextView view) {
    int maxLines = -1; // No limit (Integer.MAX_VALUE also means no limit)

    TransformationMethod method = view.getTransformationMethod();
    if (method != null && method instanceof SingleLineTransformationMethod) {
        maxLines = 1;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // setMaxLines() and getMaxLines() are only available on android-16+
        maxLines = view.getMaxLines();
    }

    return maxLines;
}
 
源代码8 项目: DarkCalculator   文件: AutofitHelper.java
private static int getMaxLines(TextView view) {
    int maxLines = -1; // No limit (Integer.MAX_VALUE also means no limit)

    TransformationMethod method = view.getTransformationMethod();
    if (method != null && method instanceof SingleLineTransformationMethod) {
        maxLines = 1;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // setMaxLines() and getMaxLines() are only available on android-16+
        maxLines = view.getMaxLines();
    }

    return maxLines;
}
 
private static ViewAssertion isPasswordToggledVisible(final boolean isToggledVisible) {
  return (view, noViewFoundException) -> {
    assertTrue(view instanceof TextInputLayout);
    EditText editText = ((TextInputLayout) view).getEditText();
    TransformationMethod transformationMethod = editText.getTransformationMethod();
    if (isToggledVisible) {
      assertNull(transformationMethod);
    } else {
      assertEquals(PasswordTransformationMethod.getInstance(), transformationMethod);
    }
  };
}
 
源代码10 项目: Trebuchet   文件: AutoExpandTextView.java
/**
 * Re size the font so the specified text fits in the text box assuming the text box is the
 * specified width.
 */
private void refitText() {
    CharSequence text = getText();

    if (TextUtils.isEmpty(text)) {
        return;
    }

    TransformationMethod method = getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, this);
    }
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    if (targetWidth > 0) {
        float high = 100;
        float low = 0;

        mPaint.set(getPaint());
        mPaint.setTextSize(getTextSize());
        float letterSpacing = getLetterSpacing(text, mPaint, targetWidth, low, high,
                mPrecision);
        mPaint.setLetterSpacing(letterSpacing);
        calculateSections(text);

        super.setLetterSpacing(letterSpacing);
    }
}
 
源代码11 项目: android-card-form   文件: CardEditTextTest.java
@Test
public void doesNotMaskIfMaskingIsNotEnabled() {
    TransformationMethod originalMethod = mView.getTransformationMethod();

    type("4111111111111111");
    mView.onFocusChanged(false, 1, null);

    assertEquals(originalMethod, mView.getTransformationMethod());
}
 
源代码12 项目: android-card-form   文件: CardEditTextTest.java
@Test
public void doesNotMaskIfFieldIsInvalid() {
    TransformationMethod originalMethod = mView.getTransformationMethod();

    mView.setMask(true);
    type("4111111111111112");

    assertEquals(originalMethod, mView.getTransformationMethod());
}
 
源代码13 项目: kAndroid   文件: AutofitHelper.java
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
                            int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
                displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
源代码14 项目: VideoOS-Android-SDK   文件: TextUtil.java
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
static void adjustTextSize(TextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
源代码15 项目: stynico   文件: AutofitHelper.java
/**
    * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
    */
   private static void autofit(AppCompatTextView view, TextPaint paint, float minTextSize, float maxTextSize,
							int maxLines, float precision)
{
       if (maxLines <= 0 || maxLines == Integer.MAX_VALUE)
	{
           // Don't auto-size since there's no limit on lines.
           return;
       }

       int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
       if (targetWidth <= 0)
	{
           return;
       }

       CharSequence text = view.getText();
       TransformationMethod method = view.getTransformationMethod();
       if (method != null)
	{
           text = method.getTransformation(text, view);
       }

       Context context = view.getContext();
       Resources r = Resources.getSystem();
       DisplayMetrics displayMetrics;

       float size = maxTextSize;
       float high = size;
       float low = 0;

       if (context != null)
	{
           r = context.getResources();
       }
       displayMetrics = r.getDisplayMetrics();

       paint.set(view.getPaint());
       paint.setTextSize(size);

       if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
		|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines)
	{
           size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
								  displayMetrics);
       }

       if (size < minTextSize)
	{
           size = minTextSize;
       }

       view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
   }
 
源代码16 项目: DarkCalculator   文件: AutofitHelper.java
/**
 * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
 */
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
                            int maxLines, float precision) {
    if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
    if (targetWidth <= 0) {
        return;
    }

    CharSequence text = view.getText();
    TransformationMethod method = view.getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, view);
    }

    Context context = view.getContext();
    Resources r = Resources.getSystem();
    DisplayMetrics displayMetrics;

    float size = maxTextSize;
    float high = size;
    float low = 0;

    if (context != null) {
        r = context.getResources();
    }
    displayMetrics = r.getDisplayMetrics();

    paint.set(view.getPaint());
    paint.setTextSize(size);

    if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
            || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
        size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
                displayMetrics);
    }

    if (size < minTextSize) {
        size = minTextSize;
    }

    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
 
源代码17 项目: smart-farmer-android   文件: FireflyDialog.java
/**
 * 设置 EditText 的 transformationMethod
 */
public InputDialogBuilder setTransformationMethod(TransformationMethod transformationMethod) {
    mTransformationMethod = transformationMethod;
    return this;
}
 
源代码18 项目: anvil   文件: DSL.java
public static Void transformationMethod(TransformationMethod arg) {
  return BaseDSL.attr("transformationMethod", arg);
}
 
源代码19 项目: anvil   文件: DSL.java
public static Void transformationMethod(TransformationMethod arg) {
  return BaseDSL.attr("transformationMethod", arg);
}
 
源代码20 项目: android-card-form   文件: CardEditTextTest.java
@Test
public void remasksWhenFocusMovesAwayFromCardEditText() {
    TransformationMethod originalMethod = mView.getTransformationMethod();

    mView.setMask(true);

    type("4111111111111111");
    mView.onFocusChanged(false, 1, null);

    assertTrue(mView.getTransformationMethod() instanceof CardNumberTransformation);

    mView.onFocusChanged(true, 1, null);

    assertEquals(originalMethod, mView.getTransformationMethod());

    mView.onFocusChanged(false, 1, null);

    assertTrue(mView.getTransformationMethod() instanceof CardNumberTransformation);
}
 
源代码21 项目: Mover   文件: MaterialAutoCompleteTextView.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public MaterialAutoCompleteTextView(Context context, AttributeSet attrs, int style) {
    super(context, attrs, style);

    setFocusable(true);
    setFocusableInTouchMode(true);
    setClickable(true);

    floatingLabelTextSize = getResources().getDimensionPixelSize(R.dimen.mtrl_ed_floating_label_text_size);
    bottomSpacing = getResources().getDimensionPixelSize(R.dimen.mtrl_ed_inner_components_spacing);
    bottomEllipsisSize = getResources().getDimensionPixelSize(R.dimen.mtrl_ed_bottom_ellipsis_height);


    // retrieve the default baseColor
    int defaultBaseColor;
    TypedValue baseColorTypedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.windowBackground, baseColorTypedValue, true);
    defaultBaseColor = ColorUtils.getBaseColor(baseColorTypedValue.data);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialEditText);
    baseColor = typedArray.getColor(R.styleable.MaterialEditText_baseColor, defaultBaseColor);
    ColorStateList colorStateList = new ColorStateList(new int[][]{new int[]{android.R.attr.state_enabled}, EMPTY_STATE_SET}, new int[]{baseColor & 0x00ffffff | 0xdf000000, baseColor & 0x00ffffff | 0x44000000});
    setTextColor(colorStateList);

    // retrieve the default primaryColor
    int defaultPrimaryColor;
    TypedValue primaryColorTypedValue = new TypedValue();
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            throw new RuntimeException("SDK_INT less than LOLLIPOP");
        }
        context.getTheme().resolveAttribute(android.R.attr.colorPrimary, primaryColorTypedValue, true);
        defaultPrimaryColor = primaryColorTypedValue.data;
    } catch (Exception e) {
        try {
            int colorAccentId = getResources().getIdentifier("colorPrimary", "attr", getContext().getPackageName());
            if (colorAccentId != 0) {
                context.getTheme().resolveAttribute(colorAccentId, primaryColorTypedValue, true);
                defaultPrimaryColor = primaryColorTypedValue.data;
            } else {
                throw new RuntimeException("colorAccent not found");
            }
        } catch (Exception e1) {
            defaultPrimaryColor = baseColor;
        }
    }

    primaryColor = typedArray.getColor(R.styleable.MaterialEditText_primaryColor, defaultPrimaryColor);
    setFloatingLabelInternal(typedArray.getInt(R.styleable.MaterialEditText_floatingLabel, 0));
    errorColor = typedArray.getColor(R.styleable.MaterialEditText_errorColor, Color.parseColor("#e7492E"));
    minCharacters = typedArray.getInt(R.styleable.MaterialEditText_minCharacters, 0);
    maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_maxCharacters, 0);
    singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_singleLineEllipsis, false);
    helperText = typedArray.getString(R.styleable.MaterialEditText_helperText);
    helperTextColor = typedArray.getColor(R.styleable.MaterialEditText_helperTextColor, -1);
    minBottomTextLines = typedArray.getInt(R.styleable.MaterialEditText_minBottomTextLines, 0);
    String fontPath = typedArray.getString(R.styleable.MaterialEditText_accentTypeface);
    if (fontPath != null) {
        accentTypeface = getCustomTypeface(fontPath);
        textPaint.setTypeface(accentTypeface);
    }
    floatingLabelText = typedArray.getString(R.styleable.MaterialEditText_floatingLabelText);
    if (floatingLabelText == null) {
        floatingLabelText = getHint();
    }
    floatingLabelSpacing = typedArray.getDimensionPixelSize(R.styleable.MaterialEditText_floatingLabelSpacing, bottomSpacing);
    hideUnderline = typedArray.getBoolean(R.styleable.MaterialEditText_hideUnderline, false);
    typedArray.recycle();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(null);
    } else {
        setBackgroundDrawable(null);
    }
    if (singleLineEllipsis) {
        TransformationMethod transformationMethod = getTransformationMethod();
        setSingleLine();
        setTransformationMethod(transformationMethod);
    }
    textPaint.setTextSize(floatingLabelTextSize);
    fontMetrics = textPaint.getFontMetrics();
    initMinBottomLines();
    initPadding();
    initText();
    initFloatingLabel();
    initErrorTextListener();
}
 
源代码22 项目: Mover   文件: MaterialEditText.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public MaterialEditText(Context context, AttributeSet attrs, int style) {
    super(context, attrs, style);

    setFocusable(true);
    setFocusableInTouchMode(true);
    setClickable(true);

    floatingLabelTextSize = getResources().getDimensionPixelSize(R.dimen.mtrl_ed_floating_label_text_size);
    bottomSpacing = getResources().getDimensionPixelSize(R.dimen.mtrl_ed_inner_components_spacing);
    bottomEllipsisSize = getResources().getDimensionPixelSize(R.dimen.mtrl_ed_bottom_ellipsis_height);


    // retrieve the default baseColor
    int defaultBaseColor;
    TypedValue baseColorTypedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.windowBackground, baseColorTypedValue, true);
    defaultBaseColor = ColorUtils.getBaseColor(baseColorTypedValue.data);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialEditText);
    baseColor = typedArray.getColor(R.styleable.MaterialEditText_baseColor, defaultBaseColor);
    ColorStateList colorStateList = new ColorStateList(new int[][]{new int[]{android.R.attr.state_enabled}, EMPTY_STATE_SET}, new int[]{baseColor & 0x00ffffff | 0xdf000000, baseColor & 0x00ffffff | 0x44000000});
    setTextColor(colorStateList);

    // retrieve the default primaryColor
    int defaultPrimaryColor;
    TypedValue primaryColorTypedValue = new TypedValue();
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            throw new RuntimeException("SDK_INT less than LOLLIPOP");
        }
        context.getTheme().resolveAttribute(android.R.attr.colorPrimary, primaryColorTypedValue, true);
        defaultPrimaryColor = primaryColorTypedValue.data;
    } catch (Exception e) {
        try {
            int colorAccentId = getResources().getIdentifier("colorPrimary", "attr", getContext().getPackageName());
            if (colorAccentId != 0) {
                context.getTheme().resolveAttribute(colorAccentId, primaryColorTypedValue, true);
                defaultPrimaryColor = primaryColorTypedValue.data;
            } else {
                throw new RuntimeException("colorAccent not found");
            }
        } catch (Exception e1) {
            defaultPrimaryColor = baseColor;
        }
    }

    primaryColor = typedArray.getColor(R.styleable.MaterialEditText_primaryColor, defaultPrimaryColor);
    setFloatingLabelInternal(typedArray.getInt(R.styleable.MaterialEditText_floatingLabel, 0));
    errorColor = typedArray.getColor(R.styleable.MaterialEditText_errorColor, Color.parseColor("#e7492E"));
    minCharacters = typedArray.getInt(R.styleable.MaterialEditText_minCharacters, 0);
    maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_maxCharacters, 0);
    singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_singleLineEllipsis, false);
    helperText = typedArray.getString(R.styleable.MaterialEditText_helperText);
    helperTextColor = typedArray.getColor(R.styleable.MaterialEditText_helperTextColor, -1);
    minBottomTextLines = typedArray.getInt(R.styleable.MaterialEditText_minBottomTextLines, 0);
    String fontPath = typedArray.getString(R.styleable.MaterialEditText_accentTypeface);
    if (fontPath != null) {
        accentTypeface = getCustomTypeface(fontPath);
        textPaint.setTypeface(accentTypeface);
    }
    floatingLabelText = typedArray.getString(R.styleable.MaterialEditText_floatingLabelText);
    if (floatingLabelText == null) {
        floatingLabelText = getHint();
    }
    floatingLabelSpacing = typedArray.getDimensionPixelSize(R.styleable.MaterialEditText_floatingLabelSpacing, bottomSpacing);
    hideUnderline = typedArray.getBoolean(R.styleable.MaterialEditText_hideUnderline, false);
    typedArray.recycle();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(null);
    } else {
        setBackgroundDrawable(null);
    }
    if (singleLineEllipsis) {
        TransformationMethod transformationMethod = getTransformationMethod();
        setSingleLine();
        setTransformationMethod(transformationMethod);
    }
    textPaint.setTextSize(floatingLabelTextSize);
    fontMetrics = textPaint.getFontMetrics();
    initMinBottomLines();
    initPadding();
    initText();
    initFloatingLabel();
    initErrorTextListener();
}
 
源代码23 项目: AndroidMaterialValidation   文件: EditText.java
/**
 * Sets the transformation that is applied to the text that this TextView is displaying.
 */
public final void setTransformationMethod(final TransformationMethod method) {
    getView().setTransformationMethod(method);
}
 
源代码24 项目: UltimateAndroid   文件: AutofitTextView.java
/**
 * Re size the font so the specified text fits in the text box assuming the text box is the
 * specified width.
 */
private void refitText() {
    if (!mSizeToFit) {
        return;
    }

    if (mMaxLines <= 0) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    CharSequence text = getText();
    TransformationMethod method = getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, this);
    }
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    if (targetWidth > 0) {
        Context context = getContext();
        Resources r = Resources.getSystem();
        DisplayMetrics displayMetrics;

        float size = mMaxTextSize;
        float high = size;
        float low = 0;

        if (context != null) {
            r = context.getResources();
        }
        displayMetrics = r.getDisplayMetrics();

        mPaint.set(getPaint());
        mPaint.setTextSize(size);

        if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth)
                || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
            size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
                    displayMetrics);
        }

        if (size < mMinTextSize) {
            size = mMinTextSize;
        }

        super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }
}
 
源代码25 项目: UltimateAndroid   文件: AutofitTextView.java
/**
 * Re size the font so the specified text fits in the text box assuming the text box is the
 * specified width.
 */
private void refitText() {
    if (!mSizeToFit) {
        return;
    }

    if (mMaxLines <= 0) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    CharSequence text = getText();
    TransformationMethod method = getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, this);
    }
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    if (targetWidth > 0) {
        Context context = getContext();
        Resources r = Resources.getSystem();
        DisplayMetrics displayMetrics;

        float size = mMaxTextSize;
        float high = size;
        float low = 0;

        if (context != null) {
            r = context.getResources();
        }
        displayMetrics = r.getDisplayMetrics();

        mPaint.set(getPaint());
        mPaint.setTextSize(size);

        if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth)
                || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
            size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
                    displayMetrics);
        }

        if (size < mMinTextSize) {
            size = mMinTextSize;
        }

        super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }
}
 
源代码26 项目: UltimateAndroid   文件: AutofitTextView.java
/**
 * Re size the font so the specified text fits in the text box assuming the text box is the
 * specified width.
 */
private void refitText() {
    if (!mSizeToFit) {
        return;
    }

    if (mMaxLines <= 0) {
        // Don't auto-size since there's no limit on lines.
        return;
    }

    CharSequence text = getText();
    TransformationMethod method = getTransformationMethod();
    if (method != null) {
        text = method.getTransformation(text, this);
    }
    int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    if (targetWidth > 0) {
        Context context = getContext();
        Resources r = Resources.getSystem();
        DisplayMetrics displayMetrics;

        float size = mMaxTextSize;
        float high = size;
        float low = 0;

        if (context != null) {
            r = context.getResources();
        }
        displayMetrics = r.getDisplayMetrics();

        mPaint.set(getPaint());
        mPaint.setTextSize(size);

        if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth)
                || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
            size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
                    displayMetrics);
        }

        if (size < mMinTextSize) {
            size = mMinTextSize;
        }

        super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }
}
 
源代码27 项目: DevUtils   文件: EditTextUtils.java
/**
 * 设置文本视图显示转换
 * @param editText {@link EditText}
 * @param method   {@link TransformationMethod}
 * @param <T>      泛型
 * @return {@link EditText}
 */
public static <T extends EditText> T setTransformationMethod(final T editText, final TransformationMethod method) {
    if (editText != null) {
        editText.setTransformationMethod(method);
    }
    return editText;
}
 
源代码28 项目: DevUtils   文件: TextViewUtils.java
/**
 * 设置文本视图显示转换
 * @param textView {@link TextView}
 * @param method   {@link TransformationMethod}
 * @param <T>      泛型
 * @return {@link TextView}
 */
public static <T extends TextView> T setTransformationMethod(final T textView, final TransformationMethod method) {
    if (textView != null) {
        textView.setTransformationMethod(method);
    }
    return textView;
}
 
源代码29 项目: android-card-form   文件: CardEditTextTest.java
@Test
public void unmasksWhenFocusChangesBackToCardEditText() {
    TransformationMethod originalMethod = mView.getTransformationMethod();

    mView.setMask(true);

    type("4111111111111111");
    mView.onFocusChanged(false, 1, null);

    assertTrue(mView.getTransformationMethod() instanceof CardNumberTransformation);

    mView.onFocusChanged(true, 1, null);

    assertEquals(originalMethod, mView.getTransformationMethod());
}
 
源代码30 项目: DevUtils   文件: TextViewUtils.java
/**
 * 设置文本视图显示转换
 * @param view   {@link TextView}
 * @param method {@link TransformationMethod}
 * @return {@link View}
 */
public static View setTransformationMethod(final View view, final TransformationMethod method) {
    setTransformationMethod(getTextView(view), method);
    return view;
}