Example usage for android.text Editable length

List of usage examples for android.text Editable length

Introduction

In this page you can find the example usage for android.text Editable length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:sssemil.com.hostsaway.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info/*from   ww w . j a v  a 2  s  .  c o m*/
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (RegexUtils.isValidHostname(hostname)) {
                        if (RegexUtils.isValidIP(ip)) {
                            ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId,
                                    hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.adaway.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info//  w w  w  .  j a  va 2 s. c  om
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (RegexUtils.isValidHostname(hostname)) {
                        if (RegexUtils.isValidIP(ip)) {
                            ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId,
                                    hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(org.adaway.R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(org.adaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.adawaycn.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info//from www .  j a  va2s  .c o  m
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (org.adawaycn.util.RegexUtils.isValidHostname(hostname)) {
                        if (org.adawaycn.util.RegexUtils.isValidIP(ip)) {
                            org.adawaycn.provider.ProviderHelper.updateRedirectionListItemHostnameAndIp(
                                    mActivity, mCurrentRowId, hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.fatelon.partyphotobooth.setup.fragments.EventInfoSetupFragment.java

@Override
public void onPause() {
    Context appContext = getActivity().getApplicationContext();

    // Store title.
    String lineOneString = null;/*ww  w. j  a  v  a 2s.c om*/
    Editable lineOne = mLineOne.getText();
    if (lineOne != null && lineOne.length() > 0) {
        lineOneString = lineOne.toString();
    }
    mPreferencesHelper.storeEventLineOne(appContext, lineOneString);

    String lineTwoString = null;
    Editable lineTwo = mLineTwo.getText();
    if (lineTwo != null && lineTwo.length() > 0) {
        lineTwoString = lineTwo.toString();
    }
    mPreferencesHelper.storeEventLineTwo(appContext, lineTwoString);

    // Store logo uri.
    String logoUriString = null;
    CharSequence logoUri = mLogoUri.getText();
    if (logoUri != null && logoUri.length() > 0) {
        logoUriString = logoUri.toString();
    }
    mPreferencesHelper.storeEventLogoUri(appContext, logoUriString);

    // Store date.
    if (mDateHidden.isChecked()) {
        mPreferencesHelper.storeEventDate(appContext, PreferencesHelper.EVENT_DATE_HIDDEN);
    } else {
        Calendar calendar = new GregorianCalendar(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth());
        mPreferencesHelper.storeEventDate(appContext, calendar.getTimeInMillis());
    }

    super.onPause();
}

From source file:org.cocos2dx.lib.TextInputWraper.java

@Override
public void afterTextChanged(Editable s) {
    if (isFullScreenEdit()) {
        return;/*w  w  w. j a va 2 s.co m*/
    }

    LogD("afterTextChanged: " + s);
    int nModified = s.length() - mText.length();
    if (nModified > 0) {
        final String insertText = s.subSequence(mText.length(), s.length()).toString();
        mMainView.insertText(insertText);
        LogD("insertText(" + insertText + ")");
    } else {
        for (; nModified < 0; ++nModified) {
            mMainView.deleteBackward();
            LogD("deleteBackward");
        }
    }
    mText = s.toString();
}

From source file:com.jlabs.peepaid.searchviewlay.SearchViewLayout.java

private void callSearchListener() {
    Editable editable = mSearchEditText.getText();
    if (editable != null && editable.length() > 0) {
        if (mSearchListener != null) {
            mSearchListener.onFinished(editable.toString());
        }//from  ww w .  j av a  2s. co  m
    }
}

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

private void changeColor() {
    Editable editable = edit.getText();
    int i = editable.toString().indexOf('#');
    if (i != -1) // should start with a #
    {// w  w  w.j  av  a  2  s.  c o m
        editable.delete(i, i + 1);
    }
    editable.insert(0, "#");

    while (editable.length() < 3) // supply an alpha value (FF)
    {
        editable.insert(1, "F");
    }
    if (editable.length() == 7) {
        editable.insert(1, "FF");
    }

    while (editable.length() < 9) // fill rest with "0"
    {
        editable.append("0");
    }

    //Log.d("DEBUG", "color is " + editable.toString());
    edit.setText(editable);
    setColor(editable.toString());
    onColorChanged(getColor());
}

From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java

@Override
public void afterTextChanged(Editable s) {
    mSendTextButton.setEnabled(s.length() > 0);
    EmojiSpannableFactory.getInstance(mActivity).updateSpannable(s);
}

From source file:com.dirkgassen.wator.ui.fragment.NewWorld.java

/**
 * Checks the given text for validity: the text must not be empty and the value must be between {@code min} and
 * {@code max}. If the text is not valid one of the given string resources is loaded and set as the error text
 * on the given {@link EditText}./*  w w  w  . j a v  a  2s  .  c  o  m*/
 *
 * This method can be called to validate the text from a {@link AfterTextWatcher}.
 *
 * @param inputNo index into the {@link #inputs} array that specifies which {@link EditText} is being validated
 * @param s       the text entered and to be verified
 * @param min     minimum value to check for
 * @param max     maximum value to check for
 * @param emptyErrorResourceId string resource ID for the error when the text is empty
 * @param minErrorResourceId string resource ID for the error when the text is a value that is smaller than {@code min}
 * @param maxErrorResourceId string resource ID for the error when the text is a value that is larger than {@code max}
 * @return        {@code true} if the entered text is valid; {@code false} otherwise
 */
private boolean doMinMaxCheck(int inputNo, Editable s, int min, int max, @StringRes int emptyErrorResourceId,
        @StringRes int minErrorResourceId, @StringRes int maxErrorResourceId) {
    if (s.length() == 0) {
        inputs[inputNo].setError(getString(emptyErrorResourceId));
        return false;
    }
    int value = Integer.valueOf(s.toString());
    if (value < min) {
        inputs[inputNo].setError(getString(minErrorResourceId, min));
        return false;
    } else if (value > max) {
        inputs[inputNo].setError(getString(maxErrorResourceId, max));
        return false;
    } else {
        inputs[inputNo].setError(null);
        return true;
    }
}

From source file:com.todoroo.astrid.core.CustomFilterActivity.java

private void setUpListeners() {
    ((Button) findViewById(R.id.add)).setOnClickListener(new View.OnClickListener() {
        @Override//from ww  w  .  j  av a2s  . c  o  m
        public void onClick(View v) {
            listView.showContextMenu();
        }
    });

    final Button saveAndView = ((Button) findViewById(R.id.saveAndView));
    saveAndView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveAndView();
        }
    });

    filterName.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0) {
                saveAndView.setText(R.string.CFA_button_view);
                saveAndView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.tango_next, 0);
            } else {
                saveAndView.setText(R.string.CFA_button_save);
                saveAndView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.tango_save, 0);
            }
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //
        }
    });

    listView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            if (menu.hasVisibleItems()) {
                /* If it has items already, then the user did not click on the "Add Criteria" button, but instead
                   long held on a row in the list view, which caused CustomFilterAdapter.onCreateContextMenu
                   to be invoked before this onCreateContextMenu method was invoked.
                 */
                return;
            }

            int i = 0;
            for (CustomFilterCriterion item : criteria.values()) {
                try {
                    menu.add(CustomFilterActivity.MENU_GROUP_FILTER, i, 0, item.name);
                } catch (NullPointerException e) {
                    throw new NullPointerException("One of the criteria is null. Criteria: " + criteria); //$NON-NLS-1$
                }
                i++;
            }
        }
    });
}