ProIOC 预编译注解框架,解决在Android端使用注解性能低下,妈妈再也不用担心我在项目中使用注解降低性能了(交流群:123965382)
目前框架有BindArray(绑定数组),BindById(绑定控件),BindData(绑定数据,适用于适配器),BindDimen(绑定dimen值),BindString(绑定字符串),OnCheckedChanged(OnCheckedChanged监听),OnClick(OnClick监听),OnItemClick(AdapterView的OnItemClick监听),OnTouch(OnTouch监听)这些常用的注解,如果有需要,以后会继续完善
使用说明,目前说明还在完善中,项目中包含一个Android Studio的demo项目,里面包含了绝大多数注解的使用例子(我记得应该是全部)
虚拟机
真机(红米Note增强版)
下载PreIOC.jar
将下载好的PreIOC.jar放在libs文件夹下,并添加应用,可以手动修改build.gradle,也可以通过右键直接添加应用(AS1.3)
将下载好的PreIOC.jar放在libs文件夹下,右击项目,选择Properties->Java Compiler->
然后如下设置
再点击如下界面
设置好后点击add 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; } } }