android.text.method.TransformationMethod Java Examples

The following examples show how to use android.text.method.TransformationMethod. 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 Project: stynico   Author: stytooldex   File: AutofitHelper.java    License: MIT License 6 votes vote down vote up
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;
   }
 
Example #2
Source Project: material-components-android   Author: material-components   File: TextInputLayoutActions.java    License: Apache License 2.0 6 votes vote down vote up
/** 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);
    }
  };
}
 
Example #3
Source Project: kAndroid   Author: 1067899750   File: AutofitHelper.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source Project: DevUtils   Author: afkT   File: EditTextUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取文本视图显示转换
 * @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;
}
 
Example #5
Source Project: DevUtils   Author: afkT   File: ViewHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置文本视图显示转换
 * @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;
}
 
Example #6
Source Project: DevUtils   Author: afkT   File: TextViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取文本视图显示转换
 * @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;
}
 
Example #7
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: TextUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #8
Source Project: DarkCalculator   Author: HK-SHAO   File: AutofitHelper.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example #9
Source Project: material-components-android   Author: material-components   File: TextInputLayoutIconsTest.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
  };
}
 
Example #10
Source Project: Trebuchet   Author: talentlo   File: AutoExpandTextView.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #11
Source Project: android-card-form   Author: braintree   File: CardEditTextTest.java    License: MIT License 5 votes vote down vote up
@Test
public void doesNotMaskIfMaskingIsNotEnabled() {
    TransformationMethod originalMethod = mView.getTransformationMethod();

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

    assertEquals(originalMethod, mView.getTransformationMethod());
}
 
Example #12
Source Project: android-card-form   Author: braintree   File: CardEditTextTest.java    License: MIT License 5 votes vote down vote up
@Test
public void doesNotMaskIfFieldIsInvalid() {
    TransformationMethod originalMethod = mView.getTransformationMethod();

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

    assertEquals(originalMethod, mView.getTransformationMethod());
}
 
Example #13
Source Project: kAndroid   Author: 1067899750   File: AutofitHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #14
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: TextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #15
Source Project: stynico   Author: stytooldex   File: AutofitHelper.java    License: MIT License 4 votes vote down vote up
/**
    * 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);
   }
 
Example #16
Source Project: DarkCalculator   Author: HK-SHAO   File: AutofitHelper.java    License: MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source Project: smart-farmer-android   Author: beanu   File: FireflyDialog.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 设置 EditText 的 transformationMethod
 */
public InputDialogBuilder setTransformationMethod(TransformationMethod transformationMethod) {
    mTransformationMethod = transformationMethod;
    return this;
}
 
Example #18
Source Project: anvil   Author: anvil-ui   File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void transformationMethod(TransformationMethod arg) {
  return BaseDSL.attr("transformationMethod", arg);
}
 
Example #19
Source Project: anvil   Author: anvil-ui   File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void transformationMethod(TransformationMethod arg) {
  return BaseDSL.attr("transformationMethod", arg);
}
 
Example #20
Source Project: android-card-form   Author: braintree   File: CardEditTextTest.java    License: MIT License 4 votes vote down vote up
@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);
}
 
Example #21
Source Project: Mover   Author: Codetail   File: MaterialAutoCompleteTextView.java    License: Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #22
Source Project: Mover   Author: Codetail   File: MaterialEditText.java    License: Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #23
Source Project: AndroidMaterialValidation   Author: michael-rapp   File: EditText.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Sets the transformation that is applied to the text that this TextView is displaying.
 */
public final void setTransformationMethod(final TransformationMethod method) {
    getView().setTransformationMethod(method);
}
 
Example #24
Source Project: UltimateAndroid   Author: cymcsg   File: AutofitTextView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example #25
Source Project: UltimateAndroid   Author: cymcsg   File: AutofitTextView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example #26
Source Project: UltimateAndroid   Author: cymcsg   File: AutofitTextView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example #27
Source Project: DevUtils   Author: afkT   File: EditTextUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 设置文本视图显示转换
 * @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;
}
 
Example #28
Source Project: DevUtils   Author: afkT   File: TextViewUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 设置文本视图显示转换
 * @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;
}
 
Example #29
Source Project: android-card-form   Author: braintree   File: CardEditTextTest.java    License: MIT License 3 votes vote down vote up
@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());
}
 
Example #30
Source Project: DevUtils   Author: afkT   File: TextViewUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 设置文本视图显示转换
 * @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;
}