本文整理汇总了Java中android.text.TextUtils.getTrimmedLength方法的典型用法代码示例。如果您正苦于以下问题:Java TextUtils.getTrimmedLength方法的具体用法?Java TextUtils.getTrimmedLength怎么用?Java TextUtils.getTrimmedLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.TextUtils
的用法示例。
在下文中一共展示了TextUtils.getTrimmedLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trimText
import android.text.TextUtils; //导入方法依赖的package包/类
/**
* Trims the specified text by removing white spaces at its start and also at its end.
*
* @param text The text to be trimmed.
* @return Trimmed text.
*/
@NonNull
public static CharSequence trimText(@NonNull CharSequence text) {
int length = text.length();
final int trimmedLength = TextUtils.getTrimmedLength(text);
if (length > trimmedLength) {
final SpannableStringBuilder builder = new SpannableStringBuilder(text);
// Remove white spaces from the start.
int start = 0;
while (start < length && builder.charAt(start) <= ' ') {
start++;
}
builder.delete(0, start);
length -= start;
// Remove white spaces from the end.
int end = length;
while (end >= 0 && builder.charAt(end - 1) <= ' ') {
end--;
}
builder.delete(end, length);
return builder;
}
return text;
}
示例2: isValid
import android.text.TextUtils; //导入方法依赖的package包/类
/**
* Returns true if the field value is valid. Also updates the error message.
*
* @return Whether the field value is valid.
*/
public boolean isValid() {
if (isRequired()
&& (TextUtils.isEmpty(mValue) || TextUtils.getTrimmedLength(mValue) == 0)) {
mErrorMessage = mRequiredErrorMessage;
return false;
}
if (mValidator != null && !mValidator.isValid(mValue)) {
mErrorMessage = mInvalidErrorMessage;
return false;
}
mErrorMessage = null;
return true;
}
示例3: getIntFromEditable
import android.text.TextUtils; //导入方法依赖的package包/类
private Integer getIntFromEditable(String line) {
if (line == null || TextUtils.getTrimmedLength(line) == 0) {
return null;
}
try {
return Integer.valueOf(line);
} catch (NumberFormatException ignored) {
return null;
}
}
示例4: onSubmitQuery
import android.text.TextUtils; //导入方法依赖的package包/类
private void onSubmitQuery() {
CharSequence query = mInput.getText();
if (query != null && TextUtils.getTrimmedLength(query) > 0) {
if (mOnQueryChangeListener != null && mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
}
}
}
示例5: onSubmitQuery
import android.text.TextUtils; //导入方法依赖的package包/类
private void onSubmitQuery() {
CharSequence query = mSearchSrcTextView.getText();
if (query != null && TextUtils.getTrimmedLength(query) > 0) {
if (mOnQueryChangeListener == null || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
closeSearch();
mSearchSrcTextView.setText(null);
}
}
}
示例6: onSubmitQuery
import android.text.TextUtils; //导入方法依赖的package包/类
private void onSubmitQuery() {
CharSequence query = mQueryTextView.getText();
if (query != null && TextUtils.getTrimmedLength(query) > 0) {
if (mOnQueryChangeListener == null
|| !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
if (mSearchable != null) {
launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, query.toString());
setImeVisibility(false);
}
dismissSuggestions();
}
}
}
示例7: getTabWidth
import android.text.TextUtils; //导入方法依赖的package包/类
protected int getTabWidth(CharSequence text) {
if (TextUtils.isEmpty(text) || TextUtils.getTrimmedLength(text) == 0) {
return 0;
}
Pattern p = Pattern.compile("[一-龥]");
int len = 0;
for (int i = 0; i < text.length(); i++) {
char cr = text.charAt(i);
int i2 = p.matcher(String.valueOf(cr)).matches() ? WOLD_DEFAULT_WIDTH : !Character.isLowerCase(cr) ? (WOLD_DEFAULT_WIDTH / 3) * 2 : WOLD_DEFAULT_WIDTH / 2;
len += i2;
}
return UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN) + len;
}
示例8: onSubmitQuery
import android.text.TextUtils; //导入方法依赖的package包/类
private void onSubmitQuery() {
CharSequence query = mEditText.getText();
if (query != null && TextUtils.getTrimmedLength(query) > 0) {
dispatchFilters();
if (mOnQueryChangeListener == null || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
mEditText.setText(query);
}
}
}
示例9: onSubmitQuery
import android.text.TextUtils; //导入方法依赖的package包/类
private void onSubmitQuery() {
CharSequence query = this.mSearchSrcTextView.getText();
if (query != null && TextUtils.getTrimmedLength(query) > 0) {
if (this.mOnQueryChangeListener == null || !this.mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
if (this.mSearchable != null) {
launchQuerySearch(0, null, query.toString());
}
setImeVisibility(false);
dismissSuggestions();
}
}
}
示例10: getAutofillValue
import android.text.TextUtils; //导入方法依赖的package包/类
public AutofillValue getAutofillValue() {
switch (type) {
case AUTOFILL_TYPE_TEXT:
return (TextUtils.getTrimmedLength(text) > 0)
? AutofillValue.forText(text)
: null;
case AUTOFILL_TYPE_DATE:
return AutofillValue.forDate(date);
default:
return null;
}
}
示例11: drawBackground
import android.text.TextUtils; //导入方法依赖的package包/类
@Override
public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline,
int bottom, CharSequence text, int start, int end, int lnum) {
mHoldersOnLine.clear();
for (BackgroundHolder backgroundHolder : mBackgroundHolders) {
if (start > backgroundHolder.getEnd() || end < backgroundHolder.getStart()) {
continue;
}
final CharSequence part = text.subSequence(start, end);
final int trimmedLength = TextUtils.getTrimmedLength(part);
final String trimmedText = part.toString().trim();
// skip empty parts
if (TextUtils.isEmpty(trimmedText)) {
continue;
}
// do not add background to lines that ends with spaces
if (trimmedLength != part.length()) {
final int trimmedLengthStart = getTrimmedLengthStart(part);
final int trimmedLengthEnd = getTrimmedLengthEnd(part, trimmedLengthStart);
start = start + trimmedLengthStart;
end = end - trimmedLengthEnd;
}
final int startInText = start < backgroundHolder.getStart() ? backgroundHolder.getStart() : start;
final int endInText = end > backgroundHolder.getEnd() ? backgroundHolder.getEnd() : end;
// skip empty parts
if (startInText == endInText) {
continue;
}
updateHoldersOnLine(p, left, right, top, baseline, text, backgroundHolder,
startInText, endInText);
}
drawBackgrounds(c, left, right);
}
示例12: safeTrimmedIsEmpty
import android.text.TextUtils; //导入方法依赖的package包/类
public static boolean safeTrimmedIsEmpty(CharSequence text) {
return text == null || TextUtils.getTrimmedLength(text) == 0;
}
示例13: safeTrimmedIsEmpty
import android.text.TextUtils; //导入方法依赖的package包/类
public static boolean safeTrimmedIsEmpty(String value) {
return value == null || TextUtils.getTrimmedLength(value) == 0;
}
示例14: isEmpty
import android.text.TextUtils; //导入方法依赖的package包/类
/**
* Returns true if the text field is empty, or contains only whitespace.
*/
private boolean isEmpty() {
return TextUtils.getTrimmedLength(getText()) == 0;
}
示例15: isEmpty
import android.text.TextUtils; //导入方法依赖的package包/类
private boolean isEmpty() {
return TextUtils.getTrimmedLength(getText()) == 0;
}