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:tm.alashow.datmusic.ui.activity.MainActivity.java

private void showCaptcha(final String captchaImage, final long captchaSid) {
    View rootView = layoutInflater.inflate(R.layout.layout_captcha, null);
    final ImageView captchaImageView = (ImageView) rootView.findViewById(R.id.captcha);
    final EditText captchaKeyView = (EditText) rootView.findViewById(R.id.key);

    Picasso.with(this).load(captchaImage + "&v=" + System.currentTimeMillis())
            .placeholder(getResources().getColor(R.color.image_placeholder)).into(captchaImageView);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(rootView);// www .  j av  a  2s .c o  m
    builder.setPositiveButton(R.string.captcha_submit, null);
    builder.setNegativeButton(R.string.captcha_reload, null);

    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button submitButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            Button reloadButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);

            submitButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String captchaKey = captchaKeyView.getText().toString();
                    if (TextUtils.getTrimmedLength(captchaKey) >= 1) {
                        search(oldQuery, captchaSid, captchaKey);
                        alertDialog.dismiss();
                    } else {
                        U.showCenteredToast(MainActivity.this, R.string.captcha_empty);
                    }
                }
            });

            reloadButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Picasso.with(MainActivity.this).load(captchaImage + "&v=" + System.currentTimeMillis())
                            .placeholder(getResources().getColor(R.color.image_placeholder))
                            .into(captchaImageView);
                }
            });
        }
    });
    alertDialog.show();
}

From source file:com.delexus.imitationzhihu.MySearchView.java

void onSubmitQuery() {
    CharSequence query = mSearchSrcTextView.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());
            }/*from  www .  j av  a 2  s .  co m*/
            setImeVisibility(false);
            dismissSuggestions();
        }
    }
}

From source file:im.vector.adapters.VectorRoomSummaryAdapter.java

/**
 * Defines the new searched pattern/*from  w w w .j a v a  2 s  . c om*/
 *
 * @param pattern the new searched pattern
 */
public void setSearchPattern(String pattern) {
    String trimmedPattern = pattern;

    if (null != pattern) {
        trimmedPattern = pattern.trim().toLowerCase(VectorApp.getApplicationLocale());
        trimmedPattern = TextUtils.getTrimmedLength(trimmedPattern) == 0 ? null : trimmedPattern;
    }

    if (!TextUtils.equals(trimmedPattern, mSearchedPattern)) {

        mSearchedPattern = trimmedPattern;
        mMatchedPublicRoomsCount = null;

        // refresh the layout
        this.notifyDataSetChanged();
    }
}

From source file:android.support.v7.widget.SearchView.java

private void onSubmitQuery() {
    CharSequence query = mSearchSrcTextView.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());
            }/* ww w .  j a  v a 2  s  .  c  o  m*/
            setImeVisibility(false);
            dismissSuggestions();
        }
    }
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

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);
            }//from  w w  w.  jav a 2s . com
            dismissSuggestions();
        }
    }
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * @param save True to save, false to send
 * @param showToast True to show a toast once the message is sent/saved
 *///from  ww  w.j  a v a  2 s.  co  m
protected void sendOrSaveWithSanityChecks(final boolean save, final boolean showToast,
        final boolean orientationChanged, final boolean autoSend) {
    if (mAccounts == null || mAccount == null) {
        Toast.makeText(this, R.string.send_failed, Toast.LENGTH_SHORT).show();
        if (autoSend) {
            finish();
        }
        return;
    }

    final String[] to, cc, bcc;
    if (orientationChanged) {
        to = cc = bcc = new String[0];
    } else {
        to = getToAddresses();
        cc = getCcAddresses();
        bcc = getBccAddresses();
    }

    final ArrayList<String> recipients = buildEmailAddressList(to);
    recipients.addAll(buildEmailAddressList(cc));
    recipients.addAll(buildEmailAddressList(bcc));

    // Don't let the user send to nobody (but it's okay to save a message
    // with no recipients)
    if (!save && (to.length == 0 && cc.length == 0 && bcc.length == 0)) {
        showRecipientErrorDialog(getString(R.string.recipient_needed));
        return;
    }

    List<String> wrongEmails = new ArrayList<String>();
    if (!save) {
        checkInvalidEmails(to, wrongEmails);
        checkInvalidEmails(cc, wrongEmails);
        checkInvalidEmails(bcc, wrongEmails);
    }

    // Don't let the user send an email with invalid recipients
    if (wrongEmails.size() > 0) {
        String errorText = String.format(getString(R.string.invalid_recipient), wrongEmails.get(0));
        showRecipientErrorDialog(errorText);
        return;
    }

    if (!save) {
        if (autoSend) {
            // Skip all further checks during autosend. This flow is used by Android Wear
            // and Google Now.
            sendOrSave(save, showToast);
            return;
        }

        // Show a warning before sending only if there are no attachments, body, or subject.
        if (mAttachmentsView.getAttachments().isEmpty() && showEmptyTextWarnings()) {
            boolean warnAboutEmptySubject = isSubjectEmpty();
            boolean emptyBody = TextUtils.getTrimmedLength(mBodyView.getEditableText()) == 0;

            // A warning about an empty body may not be warranted when
            // forwarding mails, since a common use case is to forward
            // quoted text and not append any more text.
            boolean warnAboutEmptyBody = emptyBody && (!mForward || isBodyEmpty());

            // When we bring up a dialog warning the user about a send,
            // assume that they accept sending the message. If they do not,
            // the dialog listener is required to enable sending again.
            if (warnAboutEmptySubject) {
                showSendConfirmDialog(R.string.confirm_send_message_with_no_subject, showToast, recipients);
                return;
            }

            if (warnAboutEmptyBody) {
                showSendConfirmDialog(R.string.confirm_send_message_with_no_body, showToast, recipients);
                return;
            }
        }
        // Ask for confirmation to send.
        if (showSendConfirmation()) {
            showSendConfirmDialog(R.string.confirm_send_message, showToast, recipients);
            return;
        }
    }

    performAdditionalSendOrSaveSanityChecks(save, showToast, recipients);
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Test to see if the subject is empty.//w  ww  . j  a  v  a2  s .c om
 *
 * @return boolean.
 */
// TODO: this will likely go away when composeArea.focus() is implemented
// after all the widget control is moved over.
public boolean isSubjectEmpty() {
    return TextUtils.getTrimmedLength(mSubject.getText()) == 0;
}

From source file:com.tct.mail.compose.ComposeActivity.java

/**
 * @param save True to save, false to send
 * @param showToast True to show a toast once the message is sent/saved
 *///w  w w  .  java2  s  .c o  m
protected void sendOrSaveWithSanityChecks(final boolean save, final boolean showToast,
        final boolean orientationChanged, final boolean autoSend) {
    if (mAccounts == null || mAccount == null) {
        //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083
        Utility.showShortToast(this, R.string.send_failed);
        //Toast.makeText(this, R.string.send_failed, Toast.LENGTH_SHORT).show();
        if (autoSend) {
            finish();
        }
        return;
    }

    final String[] to, cc, bcc;
    if (orientationChanged) {
        to = cc = bcc = new String[0];
    } else {
        to = getToAddresses();
        cc = getCcAddresses();
        bcc = getBccAddresses();
    }
    // TS: tao.gan 2016-03-16 EMAIL BUGFIX-1761777 MOD_S
    //NOTE: NO USED,but will increase timeconsume with lots of address data.
    /*final ArrayList<String> recipients = buildEmailAddressList(to);
    recipients.addAll(buildEmailAddressList(cc));
    recipients.addAll(buildEmailAddressList(bcc));*/

    final ArrayList<String> recipients = new ArrayList<String>();
    // TS: tao.gan 2015-03-16 EMAIL BUGFIX-1761777 MOD_E
    // Don't let the user send to nobody (but it's okay to save a message
    // with no recipients)
    if (!save && (to.length == 0 && cc.length == 0 && bcc.length == 0)) {
        showRecipientErrorDialog(getString(R.string.recipient_needed));
        return;
    }

    List<String> wrongEmails = new ArrayList<String>();
    if (!save) {
        checkInvalidEmails(to, wrongEmails);
        checkInvalidEmails(cc, wrongEmails);
        checkInvalidEmails(bcc, wrongEmails);
    }

    // Don't let the user send an email with invalid recipients
    if (wrongEmails.size() > 0) {
        String errorText = String.format(getString(R.string.invalid_recipient), wrongEmails.get(0));
        showRecipientErrorDialog(errorText);
        return;
    }

    if (!save) {
        if (autoSend) {
            // Skip all further checks during autosend. This flow is used by Android Wear
            // and Google Now.
            sendOrSave(save, showToast);
            return;
        }

        //TS: lin-zhou 2015-8-28 EMAIL BUGFIX_1065369 ADD_S
        boolean warnAboutEmptySubject = isSubjectEmpty();
        // When we bring up a dialog warning the user about a send,
        // assume that they accept sending the message. If they do not,
        // the dialog listener is required to enable sending again.
        if (warnAboutEmptySubject) {
            showSendConfirmDialog(R.string.confirm_send_message_with_no_subject, showToast, recipients);
            return;
        }
        //TS: lin-zhou 2015-8-28 EMAIL BUGFIX_1065369 ADD_E
        // Show a warning before sending only if there are no attachments, body, or subject.
        if (mAttachmentsView.getAttachments().isEmpty() && showEmptyTextWarnings()) {
            //TS: lin-zhou 2015-8-28 EMAIL BUGFIX_1065369 DEL_S
            //boolean warnAboutEmptySubject = isSubjectEmpty();
            //TS: lin-zhou 2015-8-28 EMAIL BUGFIX_1065369 DEL_E
            boolean emptyBody = TextUtils.getTrimmedLength(mBodyView.getEditableText()) == 0;

            // A warning about an empty body may not be warranted when
            // forwarding mails, since a common use case is to forward
            // quoted text and not append any more text.
            boolean warnAboutEmptyBody = emptyBody && (!mForward || isBodyEmpty());

            //TS: lin-zhou 2015-8-28 EMAIL BUGFIX_1065369 DEL_S
            /*// When we bring up a dialog warning the user about a send,
            // assume that they accept sending the message. If they do not,
            // the dialog listener is required to enable sending again.
            if (warnAboutEmptySubject) {
            showSendConfirmDialog(R.string.confirm_send_message_with_no_subject,
                    showToast, recipients);
            return;
            }*/
            //TS: lin-zhou 2015-8-28 EMAIL BUGFIX_1065369 DEL_E

            if (warnAboutEmptyBody) {
                showSendConfirmDialog(R.string.confirm_send_message_with_no_body, showToast, recipients);
                return;
            }
        }
        // Ask for confirmation to send.
        if (showSendConfirmation()) {
            showSendConfirmDialog(R.string.confirm_send_message, showToast, recipients);
            return;
        }
    }

    performAdditionalSendOrSaveSanityChecks(save, showToast, recipients);
}