Code Monkey home page Code Monkey logo

preioc's Introduction

#PreIOC 预编译注解框架,解决在Android端使用注解性能低下,妈妈再也不用担心我在项目中使用注解降低性能了(交流群:123965382)

目前框架有BindArray(绑定数组),BindById(绑定控件),BindData(绑定数据,适用于适配器),BindDimen(绑定dimen值),BindString(绑定字符串),OnCheckedChanged(OnCheckedChanged监听),OnClick(OnClick监听),OnItemClick(AdapterView的OnItemClick监听),OnTouch(OnTouch监听)这些常用的注解,如果有需要,以后会继续完善
使用说明,目前说明还在完善中,项目中包含一个Android Studio的demo项目,里面包含了绝大多数注解的使用例子(我记得应该是全部)

Maven及Gradle相关配置

Maven

<dependency>
	<groupId>wang.raye.preioc</groupId>
  	<artifactId>preioccore</artifactId>
	<version>1.0.6</version>
</dependency>

Gradle

compile 'wang.raye.preioc:preioccore:1.0.6'

性能指数

通过和原生、Xutil、以及PreIOC进行绑定200个TextView和设置OnClick监听耗时进行对比

虚拟机
虚拟机耗时
真机(红米Note增强版)
真机(红米Note增强版)

简易教程

下载PreIOC.jar

Android Studio

方法一

在build.gradle 中配置

compile 'wang.raye.preioc:preioccore:1.0.6'
方法二

将下载好的PreIOC.jar放在libs文件夹下或通过maven引用,并添加应用,可以手动修改build.gradle,也可以通过右键直接添加应用(AS1.3)

Eclipse

将下载好的PreIOC.jar放在libs文件夹下,右击项目,选择Properties->Java Compiler->
然后如下设置
Eclipse设置
再点击如下界面
Eclipse设置
设置好后点击add jar,添加PreIOC.jar
添加PreIOC.jar
点击ok,然后apply就OK了
示例代码,此为Annotation项目中的MainActivity

package wang.raye.annotation;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import wang.raye.preioc.PreIOC;
import wang.raye.preioc.annotation.BindArray;
import wang.raye.preioc.annotation.BindById;
import wang.raye.preioc.annotation.BindDimen;
import wang.raye.preioc.annotation.BindString;
import wang.raye.preioc.annotation.OnCheckedChanged;
import wang.raye.preioc.annotation.OnClick;
import wang.raye.preioc.annotation.OnItemClick;
import wang.raye.preioc.annotation.OnTouch;

public class MainActivity extends ActionBarActivity {

    @BindById(R.id.listView)
    ListView listView;

    @BindById(R.id.bindString)
    TextView bindString;
    @BindString(R.string.test)
    String name;
    @BindDimen(R.dimen.activity_horizontal_margin)
    int size;

    @BindArray(R.array.stringArray)
    String[] strArray;

    @BindArray(R.array.intArray)
    int[] intArray;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PreIOC.binder(this);
        listView.setAdapter(new Adapter(this));
        bindString.setText(name);
    }

    @OnClick({R.id.click})
    public void click(View view){
        Toast.makeText(this,"this is click",Toast.LENGTH_SHORT).show();

    }


    @OnTouch({R.id.touch})
     public boolean touch(View view,MotionEvent event){
        if(event.getAction() == MotionEvent.ACTION_UP){
            Toast.makeText(this,"this is touch",Toast.LENGTH_SHORT).show();
        }
        return true;
    }

    @OnCheckedChanged({R.id.checkbox})
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            Toast.makeText(this,"is checked",Toast.LENGTH_SHORT).show();
        }
    }

    @OnItemClick({R.id.listView})
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this,"this position is:"+position+"  id:"+id,Toast.LENGTH_SHORT).show();
    }

    @OnClick({R.id.bindDimen,R.id.stringArray,R.id.intArray})
    public void get(View view){
        switch (view.getId()){
            case R.id.bindDimen:
                Toast.makeText(this,"size is " + size,Toast.LENGTH_SHORT).show();
                break;
            case R.id.stringArray:
                Toast.makeText(this,strArray[1],Toast.LENGTH_SHORT).show();
                break;
            case R.id.intArray:
                Toast.makeText(this,"int array index 1 is :" + intArray[1],Toast.LENGTH_SHORT).show();
                break;
        }
    }
}

preioc's People

Contributors

raywang8888 avatar raywang2014 avatar rayewang avatar

Watchers

James Cloos 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.