Search in sources :

Example 76 with Editable

use of android.text.Editable in project LuaViewSDK by alibaba.

the class UDEditText method setCallback.

/**
     * 设置EditText代理
     * BeginEditing --开始编辑
     * EndEditing -- 结束编辑
     * Clear -- 删除
     * Return --返回
     *
     * @return
     */
public UDEditText setCallback(final LuaValue callback) {
    this.mCallback = callback;
    final EditText view = getView();
    if (view != null) {
        if (this.mCallback != null && this.mCallback.istable()) {
            view.addTextChangedListener(new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    if (mCallback != null && mCallback.istable()) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "BeginEditing", "beginEditing"));
                    }
                }

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

                @Override
                public void afterTextChanged(Editable s) {
                    if (mCallback != null && mCallback.istable()) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "EndEditing", "endEditing"));
                    }
                }
            });
        }
    }
    return this;
}
Also used : EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 77 with Editable

use of android.text.Editable in project Notes by MiCode.

the class NotesListActivity method showCreateOrModifyFolderDialog.

private void showCreateOrModifyFolderDialog(final boolean create) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
    final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
    showSoftInput();
    if (!create) {
        if (mFocusNoteDataItem != null) {
            etName.setText(mFocusNoteDataItem.getSnippet());
            builder.setTitle(getString(R.string.menu_folder_change_name));
        } else {
            Log.e(TAG, "The long click data item is null");
            return;
        }
    } else {
        etName.setText("");
        builder.setTitle(this.getString(R.string.menu_create_folder));
    }
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            hideSoftInput(etName);
        }
    });
    final Dialog dialog = builder.setView(view).show();
    final Button positive = (Button) dialog.findViewById(android.R.id.button1);
    positive.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            hideSoftInput(etName);
            String name = etName.getText().toString();
            if (DataUtils.checkVisibleFolderName(mContentResolver, name)) {
                Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name), Toast.LENGTH_LONG).show();
                etName.setSelection(0, etName.length());
                return;
            }
            if (!create) {
                if (!TextUtils.isEmpty(name)) {
                    ContentValues values = new ContentValues();
                    values.put(NoteColumns.SNIPPET, name);
                    values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
                    values.put(NoteColumns.LOCAL_MODIFIED, 1);
                    mContentResolver.update(Notes.CONTENT_NOTE_URI, values, NoteColumns.ID + "=?", new String[] { String.valueOf(mFocusNoteDataItem.getId()) });
                }
            } else if (!TextUtils.isEmpty(name)) {
                ContentValues values = new ContentValues();
                values.put(NoteColumns.SNIPPET, name);
                values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
                mContentResolver.insert(Notes.CONTENT_NOTE_URI, values);
            }
            dialog.dismiss();
        }
    });
    if (TextUtils.isEmpty(etName.getText())) {
        positive.setEnabled(false);
    }
    /**
         * When the name edit text is null, disable the positive button
         */
    etName.addTextChangedListener(new TextWatcher() {

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (TextUtils.isEmpty(etName.getText())) {
                positive.setEnabled(false);
            } else {
                positive.setEnabled(true);
            }
        }

        public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) ContentValues(android.content.ContentValues) DialogInterface(android.content.DialogInterface) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Button(android.widget.Button) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) OnClickListener(android.view.View.OnClickListener) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 78 with Editable

use of android.text.Editable in project MaterialSearchView by MiguelCatalan.

the class MaterialSearchView method initSearchView.

private void initSearchView() {
    mSearchSrcTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            onSubmitQuery();
            return true;
        }
    });
    mSearchSrcTextView.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mUserQuery = s;
            startFilter(s);
            MaterialSearchView.this.onTextChanged(s);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showKeyboard(mSearchSrcTextView);
                showSuggestions();
            }
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 79 with Editable

use of android.text.Editable in project Carbon by ZieIony.

the class AutoCompleteEditText method initAutoCompleteEditText.

private void initAutoCompleteEditText() {
    autoCompleteTextWatcher = new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable text) {
            if (!prevText.equals(text.toString()))
                autoComplete();
            prevText = text.toString();
        }
    };
    addTextChangedListener(autoCompleteTextWatcher);
    setOnEditorActionListener((textView, actionId, keyEvent) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            autoCompleting = true;
            Editable text = getText();
            HintSpan[] spans = text.getSpans(0, length(), HintSpan.class);
            if (spans.length > 1) {
                throw new IllegalStateException("more than one HintSpan");
            }
            int cursorPosition = getSelectionStart();
            for (HintSpan span : spans) {
                if (cursorPosition == text.getSpanStart(span)) {
                    text.removeSpan(span);
                    break;
                }
            }
            setSelection(cursorPosition);
            AutoCompleteEditText.super.setImeOptions(prevOptions);
            autoCompleting = false;
        }
        return false;
    });
}
Also used : SimpleTextWatcher(carbon.internal.SimpleTextWatcher) Editable(android.text.Editable) SuppressLint(android.annotation.SuppressLint)

Example 80 with Editable

use of android.text.Editable in project Carbon by ZieIony.

the class AutoCompleteEditText method onSelectionChanged.

@Override
protected void onSelectionChanged(int selStart, int selEnd) {
    if (autoCompleting)
        return;
    if (selStart == selEnd) {
        Editable text = getText();
        HintSpan[] spans = text.getSpans(0, length(), HintSpan.class);
        if (spans.length > 1)
            throw new IllegalStateException("more than one HintSpan");
        autoCompleting = true;
        if (spans.length == 1) {
            HintSpan span = spans[0];
            if (selStart >= text.getSpanStart(span) && selStart < text.getSpanEnd(span)) {
                setSelection(text.getSpanStart(span));
            } else if (selStart == text.getSpanEnd(span)) {
                text.removeSpan(span);
                super.setImeOptions(prevOptions);
            }
        }
        autoCompleting = false;
    }
    autoComplete();
    super.onSelectionChanged(selStart, selEnd);
}
Also used : Editable(android.text.Editable)

Aggregations

Editable (android.text.Editable)511 TextWatcher (android.text.TextWatcher)158 View (android.view.View)117 TextView (android.widget.TextView)77 Paint (android.graphics.Paint)73 Spannable (android.text.Spannable)45 TextPaint (android.text.TextPaint)44 EditText (android.widget.EditText)39 KeyEvent (android.view.KeyEvent)34 InputMethodManager (android.view.inputmethod.InputMethodManager)33 Intent (android.content.Intent)30 ImageView (android.widget.ImageView)30 SpellCheckSpan (android.text.style.SpellCheckSpan)26 SuppressLint (android.annotation.SuppressLint)24 AdapterView (android.widget.AdapterView)23 Spanned (android.text.Spanned)22 SuggestionSpan (android.text.style.SuggestionSpan)21 ListView (android.widget.ListView)19 SpannableStringBuilder (android.text.SpannableStringBuilder)18 DialogInterface (android.content.DialogInterface)16