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:Main.java

/**
 * @see android.text.Html// www  .j av a  2 s .com
 */
private static void start(Editable text, Object mark) {
    int len = text.length();
    text.setSpan(mark, len, len, Spanned.SPAN_MARK_MARK);
}

From source file:Main.java

public static void locateCursur(final EditText text) {
    if (text == null) {
        return;/*from   w  ww. java2s  .com*/
    }
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Editable b = text.getText();
            text.setSelection(b.length());
        }
    }, 100);
}

From source file:Main.java

/**
 * Modified from {@link android.text.Html}
 *//*from  ww  w  . j  a v  a 2 s .c  om*/
private static void end(Editable text, Class<?> kind, Object... replaces) {
    int len = text.length();
    Object obj = getLast(text, kind);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    if (where != len) {
        for (Object replace : replaces) {
            text.setSpan(replace, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:Main.java

public static void convertToLowercase(Editable s) {
    String lowerCase = s.toString().toLowerCase();
    if (!lowerCase.equals(s.toString())) {
        s.replace(0, s.length(), lowerCase);
    }// ww w  .  j  a v  a2s.c  o  m
}

From source file:Main.java

/**
 * Formats the text while the user types for Expiration Date
 * @param et The edit text being worked on
 * @param textWatcher Text watcher to both remove and add back on. (Pass 'this' from class)
 * @param <T> T extends EditText//from   w w w. j  av  a2 s  . co m
 */
public static <T extends EditText> void formatExpirationDateWhileTyping(T et, TextWatcher textWatcher) {
    if (et == null) {
        return;
    }
    if (textWatcher == null) {
        return;
    }
    Editable s = et.getText();
    if (s == null) {
        return;
    }

    if (s.length() > 0) {
        String input = s.toString();
        input = input.replace("/", "");
        input = input.replace(" / ", "");
        if (input.length() <= 2) {
        } else if (input.length() >= 3 && input.length() <= 7) {
            String sub1 = input.substring(0, 2);
            String sub2 = input.substring(2);
            String toSet = sub1 + "/" + sub2;

            et.removeTextChangedListener(textWatcher);
            et.setText(toSet);
            et.setSelection(toSet.length());
            et.addTextChangedListener(textWatcher);
        }
    }
}

From source file:org.eyeseetea.malariacare.network.CustomParser.java

/** Modified from {@link android.text.Html} */
private static void end(Editable text, Class<?> kind, Object... replaces) {
    int len = text.length();
    Object obj = getLast(text, kind);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);//  w  w  w  .j  a v a2 s . c om
    if (where != len) {
        for (Object replace : replaces) {
            text.setSpan(replace, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return;
}

From source file:org.mozilla.focus.widget.InlineAutocompleteEditText.java

private static boolean hasCompositionString(Editable content) {
    Object[] spans = content.getSpans(0, content.length(), Object.class);

    if (spans != null) {
        for (Object span : spans) {
            if ((content.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0) {
                // Found composition string.
                return true;
            }/* www. j ava2 s.com*/
        }
    }

    return false;
}

From source file:com.schedjoules.eventdiscovery.framework.widgets.ClearableEditText.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mClearIcon = new TintedDrawable(getContext(), R.drawable.schedjoules_ic_clear_black_24dp,
            new AttributeColor(getContext(), R.attr.schedjoules_appBarIconColor)).get();

    addTextChangedListener(new AbstractTextWatcher() {
        @Override//from  ww  w.  j av a2  s. c  o  m
        public void afterTextChanged(Editable text) {
            Drawable clearIcon = text.length() > 0 ? mClearIcon : null;
            setCompoundDrawablesWithIntrinsicBounds(null, null, clearIcon, null);
        }
    });

    mGestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent event) {
            if (event.getRawX() >= getRight() - getTotalPaddingRight()) {
                setText("");
            }
            return false;
        }
    });
}

From source file:com.googlecode.eyesfree.brailleback.rule.DefaultBrailleRule.java

@Override
public void format(Editable result, Context context, AccessibilityNodeInfoCompat node) {
    int oldLength = result.length();
    CharSequence text = LabelingUtils.getNodeText(node, getLabelManager());
    if (text == null) {
        text = "";
    }//ww w  . j ava 2s. c o m

    result.append(text);

    if (node.isCheckable() || node.isChecked()) {
        CharSequence mark;
        if (node.isChecked()) {
            mark = context.getString(R.string.checkmark_checked);
        } else {
            mark = context.getString(R.string.checkmark_not_checked);
        }
        StringUtils.appendWithSpaces(result, mark);
    }

    if (oldLength == result.length() && AccessibilityNodeInfoUtils.isActionableForAccessibility(node)) {
        result.append(getFallbackText(context, node));
    }
}

From source file:org.alfresco.mobile.android.application.fragments.node.upload.UploadLocalDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlfrescoAccount currentAccount = (AlfrescoAccount) getArguments().get(ARGUMENT_ACCOUNT);
    File f = AlfrescoStorageManager.getInstance(getActivity()).getDownloadFolder(currentAccount);
    final File file = (File) getArguments().get(ARGUMENT_FILE);

    final File folderStorage = f;

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.app_create_document, (ViewGroup) this.getView());
    v.findViewById(R.id.document_extension).setVisibility(View.GONE);
    final MaterialEditText textName = ((MaterialEditText) v.findViewById(R.id.document_name));
    textName.setText(file.getName());/*from   www.  j av a2 s. c o  m*/
    textName.setFloatingLabelText(getString(R.string.content_name));

    // This Listener is responsible to enable or not the validate button and
    // error message.
    textName.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(true);
                textName.setError(null);
                textName.setFloatingLabelText(getString(R.string.content_name));
            } else {
                textName.setHint(R.string.create_document_name_hint);
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
            }
        }

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

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

    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).iconRes(R.drawable.ic_application_logo)
            .title(R.string.import_document_name).customView(v, true).positiveText(R.string.action_import)
            .negativeText(R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    String fileName = textName.getText().toString();

                    File newFile = new File(folderStorage, fileName);

                    if (newFile.exists()) {
                        // If the file already exist, we prompt a warning
                        // message.
                        textName.setError(getString(R.string.create_document_filename_error));
                        return;
                    } else {
                        UIUtils.hideKeyboard(getActivity());

                        DataProtectionManager.getInstance(getActivity()).copyAndEncrypt(file, newFile);

                        if (getActivity() instanceof PublicDispatcherActivity) {
                            getActivity().finish();
                        }
                    }
                    dialog.dismiss();
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                    getActivity().finish();
                }
            }).build();

    return dialog;
}