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;
}
java类android.text.method.TransformationMethod的实例源码
AutofitHelper.java 文件源码
项目:stynico
阅读 31
收藏 0
点赞 0
评论 0
ShowPasswordCheckListener.java 文件源码
项目:okwallet
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
final TransformationMethod transformationMethod = isChecked ? null : PasswordTransformationMethod.getInstance();
for (final EditText passwordView : passwordViews)
passwordView.setTransformationMethod(transformationMethod);
}
TextView.java 文件源码
项目:JotaTextEditor
阅读 20
收藏 0
点赞 0
评论 0
/**
* Sets the transformation that is applied to the text that this
* TextView is displaying.
*
* @attr ref android.R.styleable#TextView_password
* @attr ref android.R.styleable#TextView_singleLine
*/
public final void setTransformationMethod(TransformationMethod method) {
if (method == mTransformation) {
// Avoid the setText() below if the transformation is
// the same.
return;
}
if (mTransformation != null) {
if (mText instanceof Spannable) {
((Spannable) mText).removeSpan(mTransformation);
}
}
mTransformation = method;
setText(mText);
}
AutofitHelper.java 文件源码
项目:AutoResizeEditText
阅读 25
收藏 0
点赞 0
评论 0
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;
}
AutofitHelper.java 文件源码
项目:LuaViewPlayground
阅读 29
收藏 0
点赞 0
评论 0
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;
}
TextUtil.java 文件源码
项目:LuaViewPlayground
阅读 28
收藏 0
点赞 0
评论 0
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;
}
AutofitHelper.java 文件源码
项目:DarkCalculator
阅读 27
收藏 0
点赞 0
评论 0
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;
}
AutofitHelper.java 文件源码
项目:android-autofittextview
阅读 24
收藏 0
点赞 0
评论 0
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;
}
TextInputLayoutTest.java 文件源码
项目:material-components-android
阅读 30
收藏 0
点赞 0
评论 0
static ViewAssertion isPasswordToggledVisible(final boolean isToggledVisible) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
assertTrue(view instanceof TextInputLayout);
EditText editText = ((TextInputLayout) view).getEditText();
TransformationMethod transformationMethod = editText.getTransformationMethod();
if (isToggledVisible) {
assertNull(transformationMethod);
} else {
assertEquals(PasswordTransformationMethod.getInstance(), transformationMethod);
}
}
};
}
AutofitHelper.java 文件源码
项目:android-autofittextview-master
阅读 29
收藏 0
点赞 0
评论 0
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;
}
AVTextView.java 文件源码
项目:AVTextView
阅读 127
收藏 0
点赞 0
评论 0
/**
* Method that catch the text transformation (e.g. uppercase tranformation)
* and return the transformed text
* @param text the text to be transformed
* @return transformed text
*/
private String getTranformedText(String text) {
// Check if text has undergone transformation
TransformationMethod transformationMethod = getTransformationMethod();
if (transformationMethod != null) {
// Get the tranformation
text = transformationMethod.getTransformation(text, this).toString();
}
return text;
}
AutoExpandTextView.java 文件源码
项目:Trebuchet
阅读 24
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
AutofitHelper.java 文件源码
项目:aMatch
阅读 24
收藏 0
点赞 0
评论 0
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;
}
ShowPasswordCheckListener.java 文件源码
项目:ombuds-android
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked)
{
final TransformationMethod transformationMethod = isChecked ? null : PasswordTransformationMethod.getInstance();
for (final EditText passwordView : passwordViews)
passwordView.setTransformationMethod(transformationMethod);
}
MaterialAutoCompleteTextView.java 文件源码
项目:Bookd_Android_App
阅读 32
收藏 0
点赞 0
评论 0
public MaterialAutoCompleteTextView(Context context, AttributeSet attrs, int style) {
super(context, attrs, style);
setFocusable(true);
setFocusableInTouchMode(true);
setClickable(true);
floatingLabelTextSize = getResources().getDimensionPixelSize(R.dimen.floating_label_text_size);
innerComponentsSpacing = getResources().getDimensionPixelSize(R.dimen.inner_components_spacing);
bottomEllipsisSize = getResources().getDimensionPixelSize(R.dimen.bottom_ellipsis_height);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialEditText);
baseColor = typedArray.getColor(R.styleable.MaterialEditText_baseColor, Color.BLACK);
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);
primaryColor = typedArray.getColor(R.styleable.MaterialEditText_primaryColor, baseColor);
setFloatingLabelInternal(typedArray.getInt(R.styleable.MaterialEditText_floatingLabel, 0));
errorColor = typedArray.getColor(R.styleable.MaterialEditText_errorColor, Color.parseColor("#e7492E"));
maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_maxCharacters, 0);
singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_singleLineEllipsis, 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);
}
initPadding();
initText();
initFloatingLabel();
}
MaterialEditText.java 文件源码
项目:Bookd_Android_App
阅读 28
收藏 0
点赞 0
评论 0
public MaterialEditText(Context context, AttributeSet attrs, int style) {
super(context, attrs, style);
setFocusable(true);
setFocusableInTouchMode(true);
setClickable(true);
floatingLabelTextSize = getResources().getDimensionPixelSize(R.dimen.floating_label_text_size);
innerComponentsSpacing = getResources().getDimensionPixelSize(R.dimen.inner_components_spacing);
bottomEllipsisSize = getResources().getDimensionPixelSize(R.dimen.bottom_ellipsis_height);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialEditText);
baseColor = typedArray.getColor(R.styleable.MaterialEditText_baseColor, Color.BLACK);
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);
primaryColor = typedArray.getColor(R.styleable.MaterialEditText_primaryColor, baseColor);
setFloatingLabelInternal(typedArray.getInt(R.styleable.MaterialEditText_floatingLabel, 0));
errorColor = typedArray.getColor(R.styleable.MaterialEditText_errorColor, R.styleable.MaterialEditText_BaseErrorColor);
maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_maxCharacters, 0);
singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_singleLineEllipsis, false);
regularExpression = typedArray.getString(R.styleable.MaterialEditText_regexExpression);
regexErrorText = typedArray.getString(R.styleable.MaterialEditText_regexErrorText);
regexText = typedArray.getString(R.styleable.MaterialEditText_regexText);
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);
}
initPadding();
initText();
initFloatingLabel();
}
TextView.java 文件源码
项目:Tada
阅读 26
收藏 0
点赞 0
评论 0
/**
* Sets the transformation that is applied to the text that this
* TextView is displaying.
*
* @attr ref android.R.styleable#TextView_password
* @attr ref android.R.styleable#TextView_singleLine
*/
public final void setTransformationMethod(TransformationMethod method) {
if (method == mTransformation) {
// Avoid the setText() below if the transformation is
// the same.
return;
}
if (mTransformation != null) {
if (mText instanceof Spannable) {
((Spannable) mText).removeSpan(mTransformation);
}
}
mTransformation = method;
if (method instanceof TransformationMethod2) {
TransformationMethod2 method2 = (TransformationMethod2) method;
mAllowTransformationLengthChange = !isTextSelectable() && !(mText instanceof Editable);
method2.setLengthChangesAllowed(mAllowTransformationLengthChange);
} else {
mAllowTransformationLengthChange = false;
}
setText(mText);
if (hasPasswordTransformationMethod()) {
notifyViewAccessibilityStateChangedIfNeeded(
AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
}
}
MaterialEditText.java 文件源码
项目:Studddinv2_android
阅读 33
收藏 0
点赞 0
评论 0
public MaterialEditText(Context context, AttributeSet attrs, int style) {
super(context, attrs, style);
setFocusable(true);
setFocusableInTouchMode(true);
setClickable(true);
floatingLabelTextSize = getResources().getDimensionPixelSize(R.dimen.floating_label_text_size);
innerComponentsSpacing = getResources().getDimensionPixelSize(R.dimen.inner_components_spacing);
bottomEllipsisSize = getResources().getDimensionPixelSize(R.dimen.bottom_ellipsis_height);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialEditText);
baseColor = typedArray.getColor(R.styleable.MaterialEditText_baseColor, Color.BLACK);
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);
primaryColor = typedArray.getColor(R.styleable.MaterialEditText_primaryColor, baseColor);
setFloatingLabelInternal(typedArray.getInt(R.styleable.MaterialEditText_floatingLabel, 0));
errorColor = typedArray.getColor(R.styleable.MaterialEditText_errorColor, R.styleable.MaterialEditText_BaseErrorColor);
maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_maxCharacters, 0);
singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_singleLineEllipsis, false);
regularExpression = typedArray.getString(R.styleable.MaterialEditText_regexExpression);
regexErrorText = typedArray.getString(R.styleable.MaterialEditText_regexErrorText);
regexText = typedArray.getString(R.styleable.MaterialEditText_regexText);
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);
}
initPadding();
initText();
initFloatingLabel();
}
AutofitHelper.java 文件源码
项目:RealTextView
阅读 22
收藏 0
点赞 0
评论 0
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;
}
AutofitHelper.java 文件源码
项目:skandroid-core
阅读 29
收藏 0
点赞 0
评论 0
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;
}
AutofitHelper.java 文件源码
项目:stynico
阅读 25
收藏 0
点赞 0
评论 0
/**
* 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);
}
AutofitHelper.java 文件源码
项目:AutoResizeEditText
阅读 28
收藏 0
点赞 0
评论 0
/**
* 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);
}
AutofitHelper.java 文件源码
项目:LuaViewPlayground
阅读 31
收藏 0
点赞 0
评论 0
/**
* 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);
}
TextUtil.java 文件源码
项目:LuaViewPlayground
阅读 29
收藏 0
点赞 0
评论 0
/**
* Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
*/
private 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);
}
QMUIDialog.java 文件源码
项目:qmui
阅读 26
收藏 0
点赞 0
评论 0
/**
* 设置 EditText 的 transformationMethod
*/
public EditTextDialogBuilder setTransformationMethod(TransformationMethod transformationMethod) {
mTransformationMethod = transformationMethod;
return this;
}
AutofitHelper.java 文件源码
项目:DarkCalculator
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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);
}
TextViewWrapper.java 文件源码
项目:AndroidViewHelper
阅读 22
收藏 0
点赞 0
评论 0
/**
* @see TextView#setTransformationMethod(TransformationMethod)
*/
public W setTransformationMethod(TransformationMethod method) {
mView.setTransformationMethod(method);
return (W) this;
}
MyTextView.java 文件源码
项目:DailyStudy
阅读 22
收藏 0
点赞 0
评论 0
public MyTextView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
// using the minimal recommended font size
_minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());
_maxTextSize = getTextSize();
_paint = new TextPaint(getPaint());
if (_maxLines == 0)
// no value was assigned during construction
_maxLines = NO_LINE_LIMIT;
// prepare size tester:
_sizeTester = new SizeTester() {
final RectF textRect = new RectF();
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public int onTestSize(final int suggestedSize, final RectF availableSpace) {
_paint.setTextSize(suggestedSize);
final TransformationMethod transformationMethod = getTransformationMethod();
final String text;
if (transformationMethod != null)
text = transformationMethod.getTransformation(getText(), MyTextView.this).toString();
else
text = getText().toString();
final boolean singleLine = getMaxLines() == 1;
if (singleLine) {
textRect.bottom = _paint.getFontSpacing();
textRect.right = _paint.measureText(text);
} else {
final StaticLayout layout = new StaticLayout(text, _paint, _widthLimit, Layout.Alignment.ALIGN_NORMAL, _spacingMult, _spacingAdd, true);
// return early if we have more lines
if (getMaxLines() != NO_LINE_LIMIT && layout.getLineCount() > getMaxLines())
return 1;
textRect.bottom = layout.getHeight();
int maxWidth = -1;
int lineCount = layout.getLineCount();
for (int i = 0; i < lineCount; i++) {
int end = layout.getLineEnd(i);
if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text.charAt(end - 1), text.charAt(end)))
return 1;
if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
}
//for (int i = 0; i < layout.getLineCount(); i++)
// if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
// maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
textRect.right = maxWidth;
}
textRect.offsetTo(0, 0);
if (availableSpace.contains(textRect))
// may be too small, don't worry we will find the best match
return -1;
// else, too big
return 1;
}
};
_initialized = true;
}
QMUIDialog.java 文件源码
项目:QMUI_Android
阅读 20
收藏 0
点赞 0
评论 0
/**
* 设置 EditText 的 transformationMethod
*/
public EditTextDialogBuilder setTransformationMethod(TransformationMethod transformationMethod) {
mTransformationMethod = transformationMethod;
return this;
}
AutofitHelper.java 文件源码
项目:android-autofittextview
阅读 34
收藏 0
点赞 0
评论 0
/**
* 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);
}