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:org.miaowo.miaowo.util.Html.java

private static void endA(Editable text) {
    int len = text.length();
    Href h = getLast(text, Href.class);
    if (h != null) {
        if (h.mHref != null) {
            setSpanFromMark(text, h, new URLSpan((h.mHref)));
        }/* w  ww. ja va2s .c  om*/
    }
}

From source file:com.polito.dion.CommentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_comments, container, false);
    RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list);
    mEditText = (EditText) rootView.findViewById(R.id.editText);
    mETAddType = (EditText) rootView.findViewById(R.id.etAddType);
    mETAddCost = (EditText) rootView.findViewById(R.id.etAddCost);

    final Button sendButton = (Button) rootView.findViewById(R.id.send_comment);

    final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);
    mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item,
            CommentViewHolder.class, commentsRef) {
        @Override//from w  w w. j  av a  2s  . co  m
        protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) {
            Author author = comment.getAuthor();
            viewHolder.commentAuthor.setText(author.getFull_name());
            GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto);

            viewHolder.authorRef = author.getUid();
            viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp()));
            viewHolder.commentText.setText(comment.getText());
            viewHolder.commentAddType.setText(comment.getAddType());
            viewHolder.commentAddCost.setText(comment.getAddCost());

        }
    };
    sendButton.setEnabled(false);
    mEditText.setHint(R.string.new_comment_hint);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                sendButton.setEnabled(true);
            } else {
                sendButton.setEnabled(false);
            }
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Clear input box and hide keyboard.
            final Editable commentText = mEditText.getText();
            final Editable commentAddType = mETAddType.getText();
            final Editable commentAddCost = mETAddCost.getText();
            mEditText.setText("");
            mETAddType.setText("");
            mETAddCost.setText("");

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user == null) {
                Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show();
            }

            Author author = new Author(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid());

            Comment comment = new Comment(author, commentAddCost.toString(), commentAddType.toString(),
                    commentText.toString(), ServerValue.TIMESTAMP);
            commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError error, DatabaseReference firebase) {
                    if (error != null) {
                        Log.w(TAG, "Error posting comment: " + error.getMessage());
                        Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show();
                        mEditText.setText(commentText);
                    }
                }
            });
        }
    });
    mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mCommentsView.setAdapter(mAdapter);
    return rootView;
}

From source file:org.miaowo.miaowo.util.Html.java

private static void start(Editable text, Object mark) {
    int len = text.length();
    text.setSpan(mark, len, len, Spannable.SPAN_MARK_MARK);
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.common.DialogEditList.java

void setup() {
    // New item hides delete button and disables OK initially
    if (getArguments().getLong(LIST_ID, -1) < 1) {
        binding.deleteButton.setVisibility(View.GONE);
        binding.buttons.dialogYes.setEnabled(false);
    }/*from   w  w w.  ja  v  a2s .  com*/

    if (getArguments().getLong(LIST_ID, -1) > 0) {
        getDialog().setTitle(R.string.menu_managelists);
        getLoaderManager().restartLoader(0, null, new LoaderCallbacks<Cursor>() {

            @Override
            public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
                return new CursorLoader(getActivity(), TaskList.getUri(getArguments().getLong(LIST_ID, -1)),
                        TaskList.Columns.FIELDS, null, null, null);
            }

            @Override
            public void onLoadFinished(Loader<Cursor> arg0, Cursor c) {
                if (c.moveToFirst()) {
                    mTaskList = new TaskList(c);
                    fillViews();
                }
                // Don't need it anymore
                getLoaderManager().destroyLoader(0);
            }

            @Override
            public void onLoaderReset(Loader<Cursor> arg0) {

            }
        });
    } else {
        getDialog().setTitle(R.string.menu_createlist);
        mTaskList = new TaskList();
    }

    binding.titleField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            binding.buttons.dialogYes.setEnabled(editable.length() > 0);
        }
    });

    binding.deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            deleteClicked();
        }
    });

    binding.buttons.dialogNo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();
        }
    });

    binding.buttons.dialogYes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            okClicked();
        }
    });
}

From source file:org.miaowo.miaowo.util.Html.java

private static void endFont(Editable text) {
    int len = text.length();
    Font f = getLast(text, Font.class);
    int where = text.getSpanStart(f);
    text.removeSpan(f);// w w  w  .java 2  s . c  o  m

    if (where != len) {
        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = ResourcesCompat.getColorStateList(res, colorRes, null);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = Color.parseColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:org.miaowo.miaowo.util.Html.java

private static void end(Editable text, Class kind, Object repl) {
    int len = text.length();
    Object obj = getLast(text, kind);
    if (obj != null) {
        setSpanFromMark(text, obj, repl);
    }/*w ww.j av  a  2s  .  c o m*/
}

From source file:me.xingrz.finder.ZipFinderActivity.java

private void confirmFilePassword() {
    Editable password = ((EditText) passwordPrompt.findViewById(R.id.password)).getText();

    char[] chars = new char[password.length()];
    password.getChars(0, password.length(), chars, 0);

    extracting.setPassword(chars);/* w w w. j  ava2s .  c  o m*/
    openFileInZip();
}

From source file:org.miaowo.miaowo.util.Html.java

private static void appendNewlines(Editable text, int minNewline) {
    final int len = text.length();

    if (len == 0) {
        return;//from w ww .j  av a 2 s  . co  m
    }

    int existingNewlines = 0;
    for (int i = len - 1; i >= 0 && text.charAt(i) == '\n'; i--) {
        existingNewlines++;
    }

    for (int j = existingNewlines; j < minNewline; j++) {
        text.append("\n");
    }
}

From source file:org.alfresco.mobile.android.application.fragments.create.DocumentPropertiesDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(getActivity(), AnalyticsManager.SCREEN_NODE_CREATE_FORM);

    final String fragmentTag = (String) getArguments().get(ARGUMENT_FRAGMENT_TAG);
    final AlfrescoAccount currentAccount = (AlfrescoAccount) getArguments().get(ARGUMENT_ACCOUNT);
    final DocumentTypeRecord documentType = (DocumentTypeRecord) getArguments().get(ARGUMENT_DOCUMENT_TYPE);
    final ResolveInfo editor = (ResolveInfo) getArguments().get(ARGUMENT_EDITOR);

    File f = null;/* ww  w .j  ava 2  s .  com*/
    if (FileExplorerFragment.TAG.equals(fragmentTag)) {
        // If creation inside the download area, we store it inside
        // download.
        f = AlfrescoStorageManager.getInstance(getActivity()).getDownloadFolder(currentAccount);
    } else {
        // If creation inside a repository folder, we store temporarly
        // inside the capture.
        f = AlfrescoStorageManager.getInstance(getActivity()).getCaptureFolder(currentAccount);
    }

    final File folderStorage = f;

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.app_create_document, (ViewGroup) this.getView());

    ((TextView) v.findViewById(R.id.document_extension)).setText(documentType.extension);

    final MaterialEditText textName = ((MaterialEditText) v.findViewById(R.id.document_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) {
                textName.setFloatingLabelText(getString(R.string.content_name));
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(true);
                if (UIUtils.hasInvalidName(s.toString().trim())) {
                    textName.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    textName.setError(null);
                }
            } else {
                textName.setHint(R.string.create_document_name_hint);
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                textName.setError(null);
            }
        }

        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.create_document_title).customView(v, true).positiveText(R.string.create)
            .negativeText(R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onNegative(MaterialDialog dialog) {
                    dialog.dismiss();
                }

                @Override
                public void onPositive(MaterialDialog dialog) {
                    String fileName = textName.getText().toString().trim().concat(documentType.extension);

                    File newFile = new File(folderStorage, fileName);

                    if (newFile.exists() && FileExplorerFragment.TAG.equals(fragmentTag)) {
                        // If the file already exist, we prompt a warning
                        // message.
                        textName.setError(getString(R.string.create_document_filename_error));
                        return;
                    } else {
                        try {
                            // If there's a template we create the file
                            // based on
                            // this template.
                            if (documentType.templatePath != null) {
                                AssetManager assetManager = getActivity().getAssets();
                                IOUtils.copyFile(assetManager.open(documentType.templatePath), newFile);
                            } else {
                                newFile.createNewFile();
                            }
                        } catch (IOException e1) {
                            Log.e(TAG, Log.getStackTraceString(e1));
                        }
                    }

                    // We create the Intent based on informations we grab
                    // previously.
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.fromFile(newFile);
                    intent.setDataAndType(data, documentType.mimetype);
                    intent.setComponent(new ComponentName(editor.activityInfo.applicationInfo.packageName,
                            editor.activityInfo.name));

                    try {
                        Fragment fr = getFragmentManager().findFragmentByTag(fragmentTag);
                        if (fr != null && fr.isVisible()) {
                            if (fr instanceof DocumentFolderBrowserFragment) {
                                // During Creation on a specific folder.
                                ((DocumentFolderBrowserFragment) fr).setCreateFile(newFile);
                            } else if (fr instanceof FileExplorerFragment) {
                                // During Creation inside the download
                                // folder.
                                ((FileExplorerFragment) fr).setCreateFile(newFile);
                            }
                            fr.startActivity(intent);
                        }
                    } catch (ActivityNotFoundException e) {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showToast(R.string.error_unable_open_file);
                    }
                    dismiss();
                }
            }).build();

    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);

    return dialog;
}

From source file:net.mceoin.cominghome.oauth.OAuthFlowApp.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*  w  w w  .ja v a  2  s .com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauth);
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);

    EditText editPincode = (EditText) findViewById(R.id.editPincode);
    editPincode.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            Button usePincode = (Button) findViewById(R.id.btn_use_pincode);
            if (s.length() == 8) {
                usePincode.setEnabled(true);
            } else {
                usePincode.setEnabled(false);
            }
        }

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    editPincode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                if (v.length() == 8) {
                    usePincode();
                    return true;
                }
            }
            return false;
        }
    });

    Button usePincode = (Button) findViewById(R.id.btn_use_pincode);
    usePincode.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            usePincode();
        }
    });

    WebView webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(false);

    try {
        webView.loadUrl(Constants.AUTHORIZE_URL);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show();
    }

}