Copyright (C) 2013 Madis Pink
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...
If you think the Android project bad listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.madisp.bad.decor;
/*fromwww.java2s.com*/import android.util.TypedValue;
import android.widget.Checkable;
import com.madisp.bad.eval.BadConverter;
import com.madisp.bad.eval.Scope;
import com.madisp.bad.eval.Watcher;
import com.madisp.bad.expr.Expression;
import com.madisp.bad.expr.ExpressionFactory;
import com.madisp.bad.lib.R;
/**
* Created with IntelliJ IDEA.
* User: madis
* Date: 5/9/13
* Time: 2:03 PM
*/publicclass CheckableDecorator extends BaseDecorator<Checkable> {
public CheckableDecorator(ExpressionFactory expressionFactory) {
super(expressionFactory);
}
@Override
publicint[] attrs() {
returnnewint[] { R.attr.checked };
}
@Override
publicvoid decorate(Scope scope, finalint attr, final TypedValue tv, final Checkable view) {
if (attr == R.attr.checked) {
final Expression expr = expressionFactory.buildExpression(tv.string.toString());
expr.addWatcher(scope, new Watcher() {
@Override
publicvoid fire(Scope scope) {
Object obj = expr.value(scope);
boolean bol = BadConverter.bool(obj);
view.setChecked(bol);
}
});
view.setChecked(BadConverter.bool(expr.value(scope)));
}
}
@Override
public Class<Checkable> clazz() {
return Checkable.class;
}
}