Skip to content
玩具级 View 注入项目
Java
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
sample
viewfinder-annotation
viewfinder-compiler
viewfinder
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

ViewFinder

一个学习 APT 的玩具项目, 实现了简单的 View 注入功能, 完成了类似于 ButterKnife 中的 @BindView@OnClick 两个注解的功能。

A simple project to study with APT in Android, and it can work well like @BindView & @OnClick annotations in ButterKnife to inject for views.

Before

public class MainActivity extends AppCompatActivity {

    TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextView = (TextView) findViewById(R.id.tv);
        mTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "onTextClick", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

After

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.tv) TextView mTextView;
    @OnClick(R.id.btn)
    public void onButtonClick() {
        Toast.makeText(this, "onButtonClick", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewFinder.inject(this);
    }
}

学习记录: Android 利用 APT 技术在编译期生成代码

You can’t perform that action at this time.