public boolean isValid(EditText et) { return TextUtils.getTrimmedLength(et.getText()) > 0; } }
public boolean hasData() { return !TextUtils.isEmpty(fileName) && TextUtils.getTrimmedLength(fileName) > 0 && !TextUtils.isEmpty(filePath) && TextUtils.getTrimmedLength(filePath) > 0 && fileSize > 0 && width > 0 && height > 0 && !TextUtils.isEmpty(folderName) && TextUtils.getTrimmedLength(folderName) > 0 && !TextUtils.isEmpty(folderPath) && TextUtils.getTrimmedLength(folderPath) > 0; }
/** * Returns true if the text field is empty, or contains only whitespace. */ private boolean isEmpty() { return TextUtils.getTrimmedLength(getText()) == 0; }
/** * Write contents to a file. * * @param file The file instance. * @param contents The content to be written to the file. Must not be empty or whitespace only. * @throws IOException If an I/O error occurs */ public static void write(@NonNull File file, @NonNull String contents) throws IOException { if (TextUtils.isEmpty(contents) || TextUtils.getTrimmedLength(contents) <= 0) { return; } BufferedWriter writer = new BufferedWriter(new FileWriter(file)); //noinspection TryFinallyCanBeTryWithResources try { writer.write(contents); } finally { //noinspection ThrowFromFinallyBlock writer.close(); } }
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); } } }
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); } } }
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); } } }
private static void writeValueToFile(Context context, String value, String filename) throws IOException { if (TextUtils.isEmpty(value)) { return; } BufferedWriter writer = null; try { File file = new File(context.getFilesDir(), filename); if (!TextUtils.isEmpty(value) && TextUtils.getTrimmedLength(value) > 0) { writer = new BufferedWriter(new FileWriter(file)); writer.write(value); writer.flush(); } } catch (IOException e) { HockeyLog.error("Failed to write value to " + filename, e); } finally { if (writer != null) { writer.close(); } } }
private void onSubmitQuery() { CharSequence submittedQuery = searchEditText.getText(); if (submittedQuery != null && TextUtils.getTrimmedLength(submittedQuery) > 0) { if (onQueryChangeListener == null || !onQueryChangeListener.onQueryTextSubmit(submittedQuery.toString())) { closeSearch(); searchEditText.setText(null); } } }
/** * Gets the text of a <code>node</code> by returning the content description * (if available) or by returning the text. * * @param node The node. * @return The node text. */ public static CharSequence getNodeText(AccessibilityNodeInfoCompat node) { if (node == null) { return null; } // Prefer content description over text. // TODO: Why are we checking the trimmed length? final CharSequence contentDescription = node.getContentDescription(); if (!TextUtils.isEmpty(contentDescription) && (TextUtils.getTrimmedLength(contentDescription) > 0)) { return contentDescription; } final CharSequence text = node.getText(); if (!TextUtils.isEmpty(text) && (TextUtils.getTrimmedLength(text) > 0)) { return text; } return null; }
private void appendRemainder(){ if(mOutput != null && TextUtils.getTrimmedLength(mOutput.contentString()) > 0){ SpannedBuilderUtils.fixFlags(mOutput); mResult.add(mOutput); } }
protected 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; } }
/** * 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; }
/** * Called when a query is submitted. This will close the search view. */ private void onSubmitQuery() { // Get the query. CharSequence query = mSearchEditText.getText(); // If the query is not null and it has some text, submit it. if(query != null && TextUtils.getTrimmedLength(query) > 0) { // If we don't have a listener, or if the search view handled the query, close it. // TODO - Improve. if(mOnQueryTextListener == null || !mOnQueryTextListener.onQueryTextSubmit(query.toString())) { if (mShouldKeepHistory) { saveQueryToDb(query.toString(),System.currentTimeMillis()); } // Refresh the cursor on the adapter, // so the new entry will be shown on the next time the user opens the search view. refreshAdapterCursor(); closeSearch(); mSearchEditText.setText(""); } } }
/** * 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; }
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(); } } }
/** * Removes whitespaces from the start and end of the specified <var>text</var>. * * @param text The text to be trimmed. * @return Trimmed text. */ private CharSequence trimText(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; }
@Test(expected = IOException.class) public void writeError() throws Exception { mockStatic(TextUtils.class); when(TextUtils.isEmpty(anyString())).thenReturn(false); when(TextUtils.getTrimmedLength(anyString())).thenReturn(4); BufferedWriter writer = mock(BufferedWriter.class); whenNew(BufferedWriter.class).withAnyArguments().thenReturn(writer); whenNew(FileWriter.class).withAnyArguments().thenReturn(mock(FileWriter.class)); doThrow(new IOException("mock")).when(writer).write(anyString()); FileManager.write(mock(File.class), "test"); verify(writer).close(); }
@Override public void onTagOpen(MarkupContext context, MarkupTag tag, RichTextDocumentElement out) { String current = out.contentString(); Markers.P marker = new Markers.P(); SpannedBuilderUtils.startSpan(out, marker); if(TextUtils.getTrimmedLength(current) > 0 ) { marker.newLinesAtStart = SpannedBuilderUtils.ensureAtLeastThoseNewLines(out, 2); }else { marker.newLinesAtStart = 1; ///just start with a new line should be fine out.append('\n'); } }
protected AccessibilityNodeInfo provideAccessibilityNodeInfo(View parent, Context context) { final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(); node.setSource(parent, id); node.setPackageName(context.getPackageName()); node.setClassName(getClassName()); node.setEditable(editable); node.setViewIdResourceName(idEntry); node.setVisibleToUser(true); final Rect absBounds = line.getAbsCoordinates(); if (absBounds != null) { node.setBoundsInScreen(absBounds); } if (TextUtils.getTrimmedLength(text) > 0) { // TODO: Must checked trimmed length because input fields use 8 empty spaces to // set width node.setText(text); } return node; }