Git Product home page Git Product logo

simulationbutterknife's Introduction

SimulationButterKnife

本项目对应的两篇博客分析:

ButterKnife的使用与原理(1)

ButterKnife的使用与原理(2)

分别通过运行时处理自定义注解和编译时处理自定义注解的方式,来模拟实现ButterKnife的效果。 简单的实现了:

  • @ContentView:注入布局文件
  • @BindView:注入控件
  • @OnClick:注入简单的事件监听

这三个注解类型,通过自己实现的注解处理器,可以实现如下的使用效果:

@ContentView(R.layout.activity_apt_impl)
public class AptImplActivity extends AppCompatActivity {

    @BindView(R.id.button1)
    Button mButton1;

    @BindView(R.id.button2)
    Button mButton2;

    @OnClick({R.id.button1})
    public void click() {
        Toast.makeText(this, "点击了第一个按钮", Toast.LENGTH_SHORT).show();
    }

    @OnClick({R.id.button2})
    public void click2() {
        Toast.makeText(this, "点击了第二个按钮", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_apt_impl);
        MyButterKnife.bind(this);
    }
}

主要涉及技术包括:

  • 注解处理器的使用
  • JavaPoet技术
  • 运行时处理注解技术
  • 编译时处理注解技术

比较有价值的参考链接:

1.Android中使用注解

2.生成Java源文件 (javawriter, javapoet, codemodel)

3.javapoet的Github地址

4.annotationprocessing101

5.javapoet——让你从重复无聊的代码中解放出来

6.Compilation Overview

7.深入理解 ButterKnife,让你的程序学会写代码

simulationbutterknife's People

Contributors

caofengbin avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.