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.

Adding @Check Annotation #389

Description

@ened

In a recent project I have to deal with lots CheckBoxes.
There is some special logic (e.g. disallow multi select etc) and it should be possible to add this into AA.
I'd follow to the idea of @Click - if no-one else is working on it already.

Any preferred names & methods? I'm thinking of:

@Check({R.id.chk1, R.id.chk2})
void checkBoxChecked(CheckBox box, boolean checked) {
}

The (optional) checked parameter might be superfluous as this is also provided through the box object.

Activity

  1. pyricau commented on Nov 8, 2012

    @pyricau
    Contributor

    Interesting. Could you write a small code sample on what the generated code would look like ?

  2. mathieuboniface commented on Nov 8, 2012

    @mathieuboniface
    Contributor

    It seems a really great idea to me !

    I think we should extend the usage of this annotation to CompoundButton and all its subclasses.

    Also I would prefer a name like @CheckedStateChange or @CheckedChange. Until now we use listeners interfaces names to determine the annotation name :

    • OnClickListener => @Click
    • OnTouchListener => @Touch
    • OnItemClickListener => @ItemClick
    • OnCheckedChangeListener should be @CheckedChange

    Finally I think it would be nice to let users determine which parameters they really need. In this manner, the view and the checked parameters will be optional (like the @TextChange or @SeekBarProgressChange)

    By browsing youtube I found the Compound sound : http://www.youtube.com/watch?v=RoX9ojwca8M :)

  3. ened commented on Nov 9, 2012

    @ened
    ContributorAuthor

    Ah, I understand the naming scheme and of course makes sense like that.

    Code sample:

    XML Layout:

    <CheckBox android:id="@+id/chkType1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/type1"
            />
    <CheckBox android:id="@+id/chkType2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/type2"
            />
    <CheckBox android:id="@+id/chkType3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/type3"
            />
    <CheckBox android:id="@+id/chkType4"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/type4"
            />

    Activity Code:

    package com.myapp;
    
    // ...
    
    @CheckedChange({R.id.chkType1, R.id.chkType2})
    void checkBoxChecked(CompoundButton buttonView, boolean isChecked) {
      // Both parameters for convenience.
    }
    @CheckedChange(R.id.chkType3)
    void type3Checked(CompoundButton buttonView) {
      // Just the button.
    }
    @CheckedChange(R.id.chkType4)
    void type4Checked(boolean isChecked) {
     // Just the state.
    }

    Generated code:

    private void afterSetContentView_() {
        {
            View view = findViewById(com.myapp.R.chkType1);
            if (view!= null) {
                ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        MyActivity_.this.checkBoxChecked(buttonView, isChecked);
                    }
                }
                );
            }
        }
        {
            View view = findViewById(com.myapp.R.chkType2);
            if (view!= null) {
                ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        MyActivity_.this.checkBoxChecked(buttonView, isChecked);
                    }
                }
                );
            }
        }
        {
            View view = findViewById(com.myapp.R.chkType3);
            if (view!= null) {
                ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        MyActivity_.this.type3Checked(buttonView);
                    }
                }
                );
            }
        }
        {
            View view = findViewById(com.myapp.R.chkType4);
            if (view!= null) {
                ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        MyActivity_.this.type4Checked(isChecked);
                    }
                }
                );
            }
        }
    }

    Merci ;-)

  4. mathieuboniface commented on Nov 9, 2012

    @mathieuboniface
    Contributor

    Hi Sebastian :)

    The generated code seems good.

    Are you interested in contributing to AndroidAnnotations ? The implementation of that feature could be a good way to take a tour on AndroidAnnotations plumbing.

  5. ened commented on Nov 9, 2012

    @ened
    ContributorAuthor

    Yes, I'd love to work on that.
    Will do once time allows. Hope within a week or 2.

  6. mathieuboniface commented on Nov 9, 2012

    @mathieuboniface
    Contributor

    Great !

  7. luxtau commented on Jan 10, 2013

    @luxtau

    What state of this feature?

  8. mathieuboniface commented on Jan 12, 2013

    @mathieuboniface
    Contributor

    Hi @luxtau,

    This feature is planned for 3.0. It seems that nobody has started working on that issue.

    Feel free to implement it :)

  9. naixx commented on Jan 12, 2013

    @naixx
    Contributor

    Probably, it will be easier to implement this feature after #434. So, I'm woriking

  10. yDelouis commented on Jun 19, 2013

    @yDelouis
    Contributor

    This should be documented and closed.

  11. DayS commented on Jun 20, 2013

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions