本文整理汇总了Java中android.text.method.TransformationMethod类的典型用法代码示例。如果您正苦于以下问题:Java TransformationMethod类的具体用法?Java TransformationMethod怎么用?Java TransformationMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransformationMethod类属于android.text.method包,在下文中一共展示了TransformationMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMaxLines
import android.text.method.TransformationMethod; //导入依赖的package包/类
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;
}
示例2: onCheckedChanged
import android.text.method.TransformationMethod; //导入依赖的package包/类
@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);
}
示例3: setTransformationMethod
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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);
}
示例4: getMaxLines
import android.text.method.TransformationMethod; //导入依赖的package包/类
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;
}
示例5: getMaxLines
import android.text.method.TransformationMethod; //导入依赖的package包/类
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;
}
示例6: isPasswordToggledVisible
import android.text.method.TransformationMethod; //导入依赖的package包/类
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);
}
}
};
}
示例7: getTranformedText
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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;
}
示例8: refitText
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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);
}
}
示例9: onCheckedChanged
import android.text.method.TransformationMethod; //导入依赖的package包/类
@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);
}
示例10: MaterialAutoCompleteTextView
import android.text.method.TransformationMethod; //导入依赖的package包/类
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();
}
示例11: MaterialEditText
import android.text.method.TransformationMethod; //导入依赖的package包/类
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();
}
示例12: setTransformationMethod
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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);
}
}
示例13: autofit
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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);
}
示例14: autofit
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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);
}
示例15: adjustTextSize
import android.text.method.TransformationMethod; //导入依赖的package包/类
/**
* 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);
}