Example usage for android.text TextUtils getTrimmedLength

List of usage examples for android.text TextUtils getTrimmedLength

Introduction

In this page you can find the example usage for android.text TextUtils getTrimmedLength.

Prototype

public static int getTrimmedLength(CharSequence s) 

Source Link

Document

Returns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as by String#trim .

Usage

From source file:Main.java

public static boolean isPasswordValid(String password) {
    Boolean isPasswordValid = true;
    if (!TextUtils.isEmpty(password)) {
        if (TextUtils.getTrimmedLength(password) <= 7) {
            isPasswordValid = false;//www .j  a  va  2  s . co m
        }
    } else {
        isPasswordValid = false;
    }
    return isPasswordValid;
}

From source file:Main.java

/**
 * Gets the text of a <code>node</code> by returning the content description
 * (if available) or by returning the text.
 *
 * @param node The node./* w w w  . ja  v  a 2 s.c o m*/
 * @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;
}

From source file:com.flowzr.budget.holo.rates.OpenExchangeRatesDownloader.java

private boolean appIdIsNotSet() {
    return TextUtils.getTrimmedLength(appId) == 0;
}

From source file:com.segment.analytics.internal.Utils.java

/** Returns true if the string is null, or empty (once trimmed). */
public static boolean isNullOrEmpty(CharSequence text) {
    return TextUtils.isEmpty(text) || TextUtils.getTrimmedLength(text) == 0;
}

From source file:tm.alashow.datmusic.ui.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    layoutInflater = LayoutInflater.from(this);

    setTitle(R.string.app_name);/*w ww  . j  a  v a2s .  c o m*/

    U.setColorScheme(swipeRefreshLayout);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            search(oldQuery, true);
        }
    });
    errorView.setOnRetryListener(new ErrorView.RetryListener() {
        @Override
        public void onRetry() {
            U.hideView(errorView);
            search(oldQuery);
        }
    });

    getConfig();

    //GCM Registration
    try {
        GCMRegistrar.checkDevice(this);
        GCMRegistrar.checkManifest(this);
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
            GCMRegistrar.register(this, Config.GCM_SENDER_ID);
        } else {

            RequestParams params = new RequestParams();
            params.put("reg_id", regId);
            params.put("id", U.getDeviceId(this));

            ApiClient.get(Config.ENDPOINT_API + "reg_id.php", params, new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String queryExtra = getIntent().getExtras().getString(Config.EXTRA_QUERY);
        if (queryExtra != null && TextUtils.getTrimmedLength(queryExtra) > 1) {
            search(queryExtra);
            if (mSearchView != null) {
                mSearchView.setIconified(false);
                mSearchView.setQuery(queryExtra, false);
            }
        } else {
            searchWithRandomArtist();
        }
    } else {
        searchWithRandomArtist();
    }
}

From source file:dev.drsoran.moloko.fragments.ChangeTagsFragment.java

private void onListItemClick(ListView l, View v, int position, long id) {
    final ChangeTag tag = (ChangeTag) l.getAdapter().getItem(position);
    final Editable tagsEdit = editView.getEditableText();

    if (tag.isAvailable) {
        if (TextUtils.isEmpty(tagsEdit)) {
            tagsEdit.append(tag.tag);//from w  w  w .java2s  .  com
        } else {
            final int trimmedLength = TextUtils.getTrimmedLength(tagsEdit);
            if (tagsEdit.charAt(trimmedLength - 1) == ',') {
                tagsEdit.append(tag.tag);
            } else {
                tagsEdit.append(", " + tag.tag);
            }
        }
    } else {
        // Cut the removed tag including any trailing ,
        String content = UIUtils.getTrimmedText(editView);
        content = content.replaceAll(tag.tag + "\\,*\\s*", Strings.EMPTY_STRING);

        editView.setText(content);
    }

    Selection.setSelection(tagsEdit, tagsEdit.length());
    updateTagList();
}

From source file:com.macadamian.blinkup.BlinkUpPlugin.java

/**********************************************************
 * @return true if mApiKey is 32 alpha-numeric characters
 *********************************************************/
private boolean apiKeyFormatValid() {
    if (TextUtils.isEmpty(mApiKey) || TextUtils.getTrimmedLength(mApiKey) != 32) {
        return false;
    }//from   www  . j  a  va  2 s. com

    String isAlphaNumericPattern = "^[a-zA-Z0-9]*$";
    return mApiKey.matches(isAlphaNumericPattern);
}

From source file:com.android.ex.chips.RecipientEditTextView.java

/**
 * Convenience method: Append the specified text slice to the TextView's display buffer, upgrading it to
 * BufferType.EDITABLE if it was not already editable. Commas are excluded as they are added automatically by the
 * view.//from   www . j a  va 2 s  .c  o m
 */
@Override
public void append(final CharSequence text, final int start, final int end) {
    // We don't care about watching text changes while appending.
    if (mTextWatcher != null)
        removeTextChangedListener(mTextWatcher);
    super.append(text, start, end);
    if (!TextUtils.isEmpty(text) && TextUtils.getTrimmedLength(text) > 0) {
        String displayString = text.toString();
        if (!displayString.trim().endsWith(String.valueOf(COMMIT_CHAR_COMMA))) {
            // We have no separator, so we should add it
            super.append(SEPARATOR, 0, SEPARATOR.length());
            displayString += SEPARATOR;
        }
        if (!TextUtils.isEmpty(displayString) && TextUtils.getTrimmedLength(displayString) > 0) {
            mPendingChipsCount++;
            mPendingChips.add(displayString);
        }
    }
    // Put a message on the queue to make sure we ALWAYS handle pending
    // chips.
    if (mPendingChipsCount > 0)
        postHandlePendingChips();
    mHandler.post(mAddTextWatcher);
}

From source file:com.nice295.scratchgames.fragment.MygamesFragment.java

private void showAddDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.DialogTheme);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.dialog_add, null);
    dialogBuilder.setView(dialogView);//  w w  w.  j  a va2  s . com

    final EditText editId = (EditText) dialogView.findViewById(R.id.editId);
    final EditText editName = (EditText) dialogView.findViewById(R.id.editName);
    final EditText editUser = (EditText) dialogView.findViewById(R.id.editUser);

    dialogBuilder.setTitle(getString(R.string.add_you_game_title));
    dialogBuilder.setMessage(getString(R.string.add_you_game_message));
    dialogBuilder.setPositiveButton(getString(R.string.add), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            if (editId.getText() != null && editName.getText() != null && editUser.getText() != null) {

                addNewMyItem(editId.getText().toString(), editName.getText().toString(),
                        editUser.getText().toString(),
                        "https://cdn2.scratch.mit.edu/get_image/project/" + editId.getText() + "_282x210.png");

                addNewMyItemExt(editId.getText().toString());

                editId.clearFocus();
                editId.setText("");
                editName.clearFocus();
                editName.setText("");
                editUser.clearFocus();
                editUser.setText("");

                getActivity().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

                Toast.makeText(getActivity(), getString(R.string.added_your_game), Toast.LENGTH_SHORT).show();

            } else {
                Log.e(TAG, "Input Text!");
            }
        }
    });

    dialogBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });

    final AlertDialog b = dialogBuilder.create();
    b.show();

    // Initially disable the button
    ((AlertDialog) b).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);

    // Now set the textchange listener for edittext
    editName.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            // Check if edittext is empty
            if (editId.getText().length() != 9 || TextUtils.getTrimmedLength(s) < 3) {
                // Disable ok button
                ((AlertDialog) b).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            } else {
                // Something into edit text. Enable the button.
                ((AlertDialog) b).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }

        }
    });

    // Now set the textchange listener for edittext
    editId.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            // Check if edittext is empty
            if (editName.getText().length() < 3 || TextUtils.getTrimmedLength(s) != 9) {
                // Disable ok button
                ((AlertDialog) b).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            } else {
                // Something into edit text. Enable the button.
                ((AlertDialog) b).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }

        }
    });
}

From source file:edu.cmu.cylab.starslinger.view.ComposeFragment.java

private boolean isSendableText() {
    return TextUtils.getTrimmedLength(mEditTextMessage.getText()) != 0;
}