当前位置: 首页>>代码示例>>Java>>正文


Java TextUtils.getTrimmedLength方法代码示例

本文整理汇总了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;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:32,代码来源:EmptyView.java

示例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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:21,代码来源:EditorFieldModel.java

示例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;
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:12,代码来源:FilterEditFragment.java

示例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);
            }
        }
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:12,代码来源:MySearchView.java

示例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);
        }
    }
}
 
开发者ID:nichbar,项目名称:Aequorea,代码行数:10,代码来源:MaterialSearchView.java

示例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();
        }
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:14,代码来源:SearchView.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:TabPageIndicator.java

示例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);
        }
    }
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:10,代码来源:SearchView.java

示例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();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:SearchView.java

示例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;
    }
}
 
开发者ID:googlesamples,项目名称:android-AutofillFramework,代码行数:13,代码来源:CustomVirtualView.java

示例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);
}
 
开发者ID:Applications-Development,项目名称:SimpleRssReader,代码行数:34,代码来源:RoundedCornersBackgroundSpan.java

示例12: safeTrimmedIsEmpty

import android.text.TextUtils; //导入方法依赖的package包/类
public static boolean safeTrimmedIsEmpty(CharSequence text) {
    return text == null || TextUtils.getTrimmedLength(text) == 0;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:4,代码来源:AppTextUtils.java

示例13: safeTrimmedIsEmpty

import android.text.TextUtils; //导入方法依赖的package包/类
public static boolean safeTrimmedIsEmpty(String value) {
    return value == null || TextUtils.getTrimmedLength(value) == 0;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:4,代码来源:Utils.java

示例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;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:7,代码来源:SearchView.java

示例15: isEmpty

import android.text.TextUtils; //导入方法依赖的package包/类
private boolean isEmpty() {
    return TextUtils.getTrimmedLength(getText()) == 0;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:SearchView.java


注:本文中的android.text.TextUtils.getTrimmedLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。