Search in sources :

Example 61 with Editable

use of android.text.Editable in project FloatingSearchView by renaudcerrato.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    DaggerAppComponent.builder().build().inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSearch.setListener(this);
    mSearchView = (FloatingSearchView) findViewById(R.id.search);
    mSearchView.setAdapter(mAdapter = new SearchAdapter());
    mSearchView.showLogo(true);
    mSearchView.setItemAnimator(new CustomSuggestionItemAnimator(mSearchView));
    updateNavigationIcon(R.id.menu_icon_search);
    mSearchView.showIcon(shouldShowNavigationIcon());
    mSearchView.setOnIconClickListener(new FloatingSearchView.OnIconClickListener() {

        @Override
        public void onNavigationClick() {
            // toggle
            mSearchView.setActivated(!mSearchView.isActivated());
        }
    });
    mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {

        @Override
        public void onSearchAction(CharSequence text) {
            mSearchView.setActivated(false);
        }
    });
    mSearchView.setOnMenuItemClickListener(this);
    mSearchView.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence query, int start, int before, int count) {
            showClearButton(query.length() > 0 && mSearchView.isActivated());
            search(query.toString().trim());
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mSearchView.setOnSearchFocusChangedListener(new FloatingSearchView.OnSearchFocusChangedListener() {

        @Override
        public void onFocusChanged(final boolean focused) {
            boolean textEmpty = mSearchView.getText().length() == 0;
            showClearButton(focused && !textEmpty);
            if (!focused)
                showProgressBar(false);
            mSearchView.showLogo(!focused && textEmpty);
            if (focused)
                mSearchView.showIcon(true);
            else
                mSearchView.showIcon(shouldShowNavigationIcon());
        }
    });
    mSearchView.setText(null);
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) FloatingSearchView(com.mypopsy.widget.FloatingSearchView)

Example 62 with Editable

use of android.text.Editable in project MaterialEditText by rengwuxian.

the class MaterialAutoCompleteTextView method initFloatingLabel.

private void initFloatingLabel() {
    // observe the text changing
    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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (floatingLabelEnabled) {
                if (s.length() == 0) {
                    if (floatingLabelShown) {
                        floatingLabelShown = false;
                        getLabelAnimator().reverse();
                    }
                } else if (!floatingLabelShown) {
                    floatingLabelShown = true;
                    getLabelAnimator().start();
                }
            }
        }
    });
    // observe the focus state to animate the floating label's text color appropriately
    innerFocusChangeListener = new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (floatingLabelEnabled && highlightFloatingLabel) {
                if (hasFocus) {
                    getLabelFocusAnimator().start();
                } else {
                    getLabelFocusAnimator().reverse();
                }
            }
            if (validateOnFocusLost && !hasFocus) {
                validate();
            }
            if (outerFocusChangeListener != null) {
                outerFocusChangeListener.onFocusChange(v, hasFocus);
            }
        }
    };
    super.setOnFocusChangeListener(innerFocusChangeListener);
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AppCompatAutoCompleteTextView(android.support.v7.widget.AppCompatAutoCompleteTextView) View(android.view.View) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 63 with Editable

use of android.text.Editable in project material by rey5137.

the class ContactEditText method replaceSpan.

private void replaceSpan(RecipientSpan span, Recipient newRecipient) {
    Editable text = getText();
    int start = text.getSpanStart(span);
    int end = text.getSpanEnd(span);
    String replace = newRecipient.number;
    text.replace(start, end - 2, newRecipient.number, 0, replace.length());
    span.setRecipient(newRecipient);
    text.setSpan(span, start, start + replace.length() + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : Editable(android.text.Editable) Paint(android.graphics.Paint)

Example 64 with Editable

use of android.text.Editable in project mobile-android by photo.

the class TwitterFragment method init.

void init(View view, Bundle savedInstanceState) {
    try {
        new ShowCurrentlyLoggedInUserTask(view).execute();
        messageEt = (EditText) view.findViewById(R.id.message);
        if (savedInstanceState != null) {
            messageEt.setText(savedInstanceState.getString(TWEET));
            textModified = savedInstanceState.getBoolean(TEXT_MODIFIED);
            photo = savedInstanceState.getParcelable(PHOTO);
        } else {
            String message = getDefaultTweetMessage(photo);
            messageEt.setText(message);
        }
        messageEt.addTextChangedListener(new TextWatcher() {

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

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

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        Button logOutButton = (Button) view.findViewById(R.id.logoutBtn);
        logOutButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                TrackerUtils.trackButtonClickEvent("logoutBtn", TwitterFragment.this);
                performTwitterLogout();
            }
        });
        sendButton = (Button) view.findViewById(R.id.sendBtn);
        sendButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                TrackerUtils.trackButtonClickEvent("sendBtn", TwitterFragment.this);
                if (GuiUtils.checkLoggedInAndOnline()) {
                    postTweet();
                }
            }
        });
        if (!textModified) {
            sendButton.setEnabled(false);
            PhotoUtils.validateShareTokenExistsAsyncAndRunAsync(photo, new RunnableWithParameter<Photo>() {

                @Override
                public void run(Photo parameter) {
                    sendButton.setEnabled(true);
                    String message = getDefaultTweetMessage(photo, true);
                    messageEt.setText(message);
                }
            }, new Runnable() {

                @Override
                public void run() {
                    sendButton.setEnabled(false);
                }
            }, new TweetLoadingControl(view));
        }
    } catch (Exception ex) {
        GuiUtils.error(TAG, R.string.errorCouldNotInitTwitterFragment, ex, getActivity());
        dismissAllowingStateLoss();
    }
}
Also used : Photo(com.trovebox.android.common.model.Photo) View(android.view.View) TextView(android.widget.TextView) TwitterException(twitter4j.TwitterException) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnClickListener(android.view.View.OnClickListener)

Example 65 with Editable

use of android.text.Editable in project Calligraphy by chrisjenx.

the class CalligraphyUtils method applyFontToTextView.

/**
     * Applies a Typeface to a TextView, if deferred,its recommend you don't call this multiple
     * times, as this adds a TextWatcher.
     *
     * Deferring should really only be used on tricky views which get Typeface set by the system at
     * weird times.
     *
     * @param textView Not null, TextView or child of.
     * @param typeface Not null, Typeface to apply to the TextView.
     * @param deferred If true we use Typefaces and TextChange listener to make sure font is always
     *                 applied, but this sometimes conflicts with other
     *                 {@link android.text.Spannable}'s.
     * @return true if applied otherwise false.
     * @see #applyFontToTextView(android.widget.TextView, android.graphics.Typeface)
     */
public static boolean applyFontToTextView(final TextView textView, final Typeface typeface, boolean deferred) {
    if (textView == null || typeface == null)
        return false;
    textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    textView.setTypeface(typeface);
    if (deferred) {
        textView.setText(applyTypefaceSpan(textView.getText(), typeface), TextView.BufferType.SPANNABLE);
        textView.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) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                applyTypefaceSpan(s, typeface);
            }
        });
    }
    return true;
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Paint(android.graphics.Paint)

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