Coder Social home page Coder Social logo

pengju1218 / android-lite-auto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from litesuits/android-lite-auto

0.0 2.0 0.0 7 KB

lite your android ! the code is on the way~

Home Page: http://lihttp://litesuits.com?from=auto

License: Apache License 2.0

android-lite-auto's Introduction

android-lite-auto

lite your android, the code is on the way~ !

LiteAuto是一个代码生成框架,思路参考 JakeWharton 的开源项目 ButterKnife,在它的思路基础添加了一些自己的想法,从0到1设计并实现的。

LiteAuto设计思路的关键是约定大于配置,通过 更简单的注解 帮你自动生成 Android 中琐碎、冗长的功能代码。

目前可以自动生成 View 和 Event 相关的重复代码,还可以生成常用操作代码,而这些都是在编译时期自动生成的代码,几乎不影响性能,而且使得项目非常清晰简单。

和 ButterKnife 的不同点之一是 LiteAuto 只需要在 Activity 上添加一个 @LiteAuto 注解即可,框架自动分析 Activity 或者 Fragment 内部所有的 View 元素,判断是否在 layout 文件中有与之对应的 View 控件,比如一个 TextView 变量名为 “tvLabel”,框架会自动查找 layout 里面id 为 “tvLabel”的控件,并为之生成findViewById代码,如果查找不到那么探测下一个View,Event代码生成并关联的思路也是如此。

关于 @LiteAuto 注解,如果你有 View 变量不需要和 layout 文件关联,只需为变量添加 @UnBind 注解即可。

关于 @SemiAuto 注解,如果你需要向像 ButterKnife 一样,每个 View 或 Event 单独注解, 那么为Activity等添加 @SemiAuto 注解即可。

比如,之前的代码是这样:

public class MainActivity extends Activity {

    TextView tvLabel;
    TextView tvLabel1;
    TextView tvLabel2;
    TextView tvLabel3;
    Button button;
    ImageView imageView;
    ProgressBar progressBar;

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

        tvLabel = (TextView) findViewById(R.id.tvLabel);
        tvLabel1 = (TextView) findViewById(R.id.tvLabel1);
        tvLabel2 = (TextView) findViewById(R.id.tvLabel2);
        tvLabel3 = (TextView) findViewById(R.id.tvLabel3);
        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);

        tvLabel1.setOnClickListener(new View.OnClickListener() {

            @Override 
            public void onClick(View v) {
                tvLabel1.setText("TvLabel 1 Clicked!");
            }
        });

        tvLabel2.setOnClickListener(new View.OnClickListener() {

            @Override 
            public void onClick(View v) {
                tvLabel2.setText("TvLabel 2 Clicked!");
                tvLabel3.setText("show me, show me pls!");
            }
        });
    }

}

那么,使用 LiteAuto 的代码是这样:

// 无需findViewById,也不需要为单个变量添加注解,Activity级别添加一个注解即可。
// 框架会分析类和成员变量,自动生成代码
@AutoLite
public class LiteMainActivity extends Activity {

    TextView tvLabel;
    TextView tvLabel1;
    TextView tvLabel2;
    TextView tvLabel3;
    Button button;
    ImageView imageView;
    ProgressBar progressBar;

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

    public void clickTvLabel1(View view) {
        tvLabel1.setText("TvLabel Clicked!");
    }

    public void clickTvLabel2(View view) {
        tvLabel2.setText("TvLabel Clicked!");
        tvLabel3.setText("show me, show me pls!");
    }

}

android-lite-auto's People

Contributors

litesuits avatar

Watchers

 avatar  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.