Java Code Examples for android.text.TextUtils.getTrimmedLength()

The following are Jave code examples for showing how to use getTrimmedLength() of the android.text.TextUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: android_ui   File: EmptyView.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 2
Project: chromium-for-android-56-debug-video   File: EditorFieldModel.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: Phoenix-for-VK   File: FilterEditFragment.java   View Source Code Vote up 5 votes
private Integer getIntFromEditable(String line) {
    if (line == null || TextUtils.getTrimmedLength(line) == 0) {
        return null;
    }

    try {
        return Integer.valueOf(line);
    } catch (NumberFormatException ignored) {
        return null;
    }
}
 
Example 4
Project: Phoenix-for-VK   File: MySearchView.java   View Source Code Vote up 5 votes
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);
            }
        }
    }
}
 
Example 5
Project: Aequorea   File: MaterialSearchView.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 6
Project: CSipSimple   File: SearchView.java   View Source Code Vote up 5 votes
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();
        }
    }
}
 
Example 7
Project: letv   File: TabPageIndicator.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: Sega   File: SearchView.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 9
Project: FinalProject   File: MaterialSearchView.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 10
Project: boohee_v5.6   File: SearchView.java   View Source Code Vote up 5 votes
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();
        }
    }
}
 
Example 11
Project: android-AutofillFramework   File: CustomVirtualView.java   View Source Code Vote up 5 votes
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;
    }
}
 
Example 12
Project: SimpleRssReader   File: RoundedCornersBackgroundSpan.java   View Source Code Vote up 5 votes
@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);
}
 
Example 13
Project: Phoenix-for-VK   File: AppTextUtils.java   View Source Code Vote up 4 votes
public static boolean safeTrimmedIsEmpty(CharSequence text) {
    return text == null || TextUtils.getTrimmedLength(text) == 0;
}
 
Example 14
Project: Phoenix-for-VK   File: Utils.java   View Source Code Vote up 4 votes
public static boolean safeTrimmedIsEmpty(String value) {
    return value == null || TextUtils.getTrimmedLength(value) == 0;
}
 
Example 15
Project: CSipSimple   File: SearchView.java   View Source Code Vote up 4 votes
/**
 * Returns true if the text field is empty, or contains only whitespace.
 */
private boolean isEmpty() {
    return TextUtils.getTrimmedLength(getText()) == 0;
}
 
Example 16
Project: boohee_v5.6   File: SearchView.java   View Source Code Vote up 4 votes
private boolean isEmpty() {
    return TextUtils.getTrimmedLength(getText()) == 0;
}
 
Example 17
Project: kheera-testrunner-android   File: StringUtils.java   View Source Code Vote up 4 votes
public static boolean isEmpty(String text) {
    if (text == null) return true;

    return TextUtils.getTrimmedLength(text) == 0;
}
 
Example 18
Project: financisto1-holo   File: OpenExchangeRatesDownloader.java   View Source Code Vote up 4 votes
private boolean appIdIsNotSet() {
    return TextUtils.getTrimmedLength(appId) == 0;
}