package org.itsnat.droid.impl.xmlinflater.layout.attr.view;
import android.view.View;
import android.widget.RelativeLayout;
import org.itsnat.droid.impl.dom.DOMAttr;
import org.itsnat.droid.impl.xmlinflater.layout.AttrLayoutContext;
import org.itsnat.droid.impl.xmlinflater.layout.PendingViewPostCreateProcess;
import org.itsnat.droid.impl.xmlinflater.layout.classtree.ClassDescViewBased;
import org.itsnat.droid.impl.xmlinflater.shared.attr.AttrDesc;
/**
* Created by jmarranz on 30/04/14.
*/
public class AttrDescView_view_View_layout_rellayout_byBoolean extends AttrDesc<ClassDescViewBased,View,AttrLayoutContext>
{
protected int selector;
public AttrDescView_view_View_layout_rellayout_byBoolean(ClassDescViewBased parent, String name, int selector)
{
super(parent,name);
this.selector = selector;
}
@Override
public void setAttribute(final View view, DOMAttr attr, AttrLayoutContext attrCtx)
{
final boolean convValue = getBoolean(attr.getResourceDesc(), attrCtx.getXMLInflaterContext());
Runnable task = new Runnable(){
@Override
public void run()
{
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)view.getLayoutParams();
params.addRule(selector, convValue ? RelativeLayout.TRUE : 0);
}};
PendingViewPostCreateProcess pendingViewPostCreateProcess = attrCtx.getPendingViewPostCreateProcess();
if (pendingViewPostCreateProcess != null)
{
pendingViewPostCreateProcess.addPendingLayoutParamsTask(task);
}
else
{
task.run();
PendingViewPostCreateProcess.onChangedLayoutParams(view);
}
}
@Override
public void removeAttribute(View view, AttrLayoutContext attrCtx)
{
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)view.getLayoutParams();
params.addRule(selector, 0); // ver el caso LayoutBelow
PendingViewPostCreateProcess.onChangedLayoutParams(view);
}
}