Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Add support for TextWatcher #120

Description

@mathieuboniface

It's possible with a TextView to get notified when some changes are made within it by implementing a TextWatcher and pass it to the instance of the TextView. This is largely used with EditText (extends TextView) to interact with user events on this view.

See TextWatcher interface here : http://developer.android.com/reference/android/text/TextWatcher.html
See EditText class here : http://developer.android.com/reference/android/widget/EditText.html

I think we could introduce three new annotations : @BeforeTextChanged @TextChanged @AfterTextChanged

Activity

  1. JoanZapata commented on Feb 29, 2012

    @JoanZapata
    Contributor

    That would be nice ! What is the difference between @TextChanged and @AfterTextChanged ?

  2. mathieuboniface commented on Feb 29, 2012

    @mathieuboniface
    ContributorAuthor

    @shuya-inc Good question !

    I found some explanation on this thread on StackOverflow : http://stackoverflow.com/questions/476848/android-textwatcher-aftertextchanged-vs-textwatcher-ontextchanged

    I think we should check that annotated methods take the proper arguments while annotation processing.

  3. mathieuboniface commented on May 1, 2012

    @mathieuboniface
    ContributorAuthor

    I will start the implementation by providing two annotations :

    • @BeforeTextChange

    Annotated method must have at least a CharSequence parameter, the start, count and after parameters can be all declared or none of them, (developers cannot annotate a method that declare one or two parameters among the three).

    • @TextChange

    Same as above but the annotated method can take an Editable paremeter instead of the CharSequence parameter.

    Those annotations can take multiple id as value parameters (like @click, @touch, etc...)

    Comments are welcome.

  4. mathieuboniface commented on May 8, 2012

    @mathieuboniface
    ContributorAuthor

    I changed my mind since I write the last comment.

    I think have one annotations for two methods is a bit complex for users. So the first implementation should offer three annotations :

    • @BeforeTextChange
    • @TextChange
    • @AfterTextChange

    All the parameter will be optionals. the integers parameters are identified by their names (before, after, start, count). The CharSequence or Editable parameter (following context) are identified by their types. The targeted widget can be added as parameter of the annotated method.

    Some examples of valid declaration :

        @TextChange(R.id.helloTextView)
        void onTextChange(CharSequence s, int before, int start, int count) {}
    
        @TextChange(R.id.helloTextView)
        void onTextChangeParameterReversed(CharSequence s, int start, int before, int count) {}
    
        @BeforeTextChange(R.id.helloTextView)
        void beforeTextChange(int count, int start, CharSequence s, int after) {}
    
        @AfterTextChange({R.id.helloTextView, R.id.watchedEditText})
        void afterTextChange(TextView tv, Editable s) {}
    
        @TextChange(R.id.watchedEditText)
        void onTextChange(TextView editText, CharSequence s, int before) {}
  5. added a commit that references this issue on May 8, 2012
  6. pyricau commented on May 10, 2012

    @pyricau
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions