@OnClick(R.id.bt_change_bg_color) public void onClickChangeBgColor(View v){ //改变背景(color) binder.getDataProxy().setBackgroundColor(mUserColor1 ? mColor2 : mColor1); mUserColor1 = !mUserColor1; }
@OnClick(R.id.bt_change_bg_res) public void onClickChangeBgRes(View v){ //改变背景(resource id) binder.getDataProxy().setBackgroundRes(mUserRes1 ? mResId2 : mResId1); mUserRes1 = !mUserRes1; }
@OnClick(R.id.bt_change_bg) public void onClickChangeBg(View v){ //改变背景(drawable) binder.getDataProxy().setBackground(mUserDrawable1 ? mDrawable2 : mDrawable1); mUserDrawable1 = !mUserDrawable1; }
@OnClick(R.id.bt_remove) public void onClickRemoveItem(View v){ mBinder.getDataProxy().beginStudentsEditor() .remove(0); }
@OnClick(R.id.bt_replace) public void onClickReplaceItem(View v){ mBinder.getDataProxy().setStudents(createItems()); }
@Override protected void onInit(Context context, Bundle savedInstanceState) { Binder<TestSelfMethod> binder = DataMediatorFactory.createBinder(TestSelfMethod.class); //bind property to textView binder.bindText(TestSelfMethod.PROP_text, mTv); //get proxy mProxy = binder.getDataProxy(); }
@OnClick(R.id.bt_add) public void onClickAddItem(View v){ mBinder.getDataProxy().beginStudentsEditor() .add(0, createItem()); }
@OnClick(R.id.bt_add_all) public void onClickAddItems(View v){ List<Student> list = createItems(); mBinder.getDataProxy().beginStudentsEditor() .addAll(list); }
@OnClick(R.id.bt_change_enable) public void onClickChangeEnable(View v){ //改变enable 状态 binder.getDataProxy().setEnable(!binder.getData().isEnable()); }
@Override protected void onInit(Context context, Bundle savedInstanceState) { initResource(context); mBinder = DataMediatorFactory.createBinder(TextViewBind.class); //绑定一组属性到TextView mBinder.beginBatchTextViewBinder(mTv) .bindText(TextViewBind.PROP_text) .bindTextRes(TextViewBind.PROP_textRes) .bindTextColor(TextViewBind.PROP_textColor) .bindTextColorRes("textColorRes") .bindTextSize("textSize") .bindTextSizeRes("textSizeRes") .end(); mProxy = mBinder.getDataProxy(); }
@Override protected void onInit(Context context, Bundle savedInstanceState) { initResource(context); mUserDrawable1 = true; mUserRes1 = true; mUserColor1 = true; binder = DataMediatorFactory.createBinder(ViewBind.class); //初始化属性。 binder.getDataProxy() .setBackground(mDrawable1) .setBackgroundColor(mColor1) .setBackgroundRes(mResId1) .setEnable(true); // 设置属性拦截器,用于应用绑定的时候过滤一些不需要的属性值。 binder.setPropertyInterceptor(PropertyInterceptor.NULL_AND_ZERO); //绑定并 首次应用属性(绑定只需要1次) binder .bindBackground(ViewBind.PROP_background, mV_bg) //使用生成的property对象。有助于模型变化后用的地方知晓改变。 .bindBackgroundRes(ViewBind.PROP_backgroundRes, mV_bg_res) .bindBackgroundColor(ViewBind.PROP_backgroundColor, mV_bg_color) .bindEnable("enable", mV_enable) .applyProperties( // 创建一个只接收固定属性的 拦截器。(1.1.2支持的). 只是用于本次apply. PropertyInterceptor.createFilter(ViewBind.PROP_background, ViewBind.PROP_backgroundRes, ViewBind.PROP_backgroundColor) ); }