package net.garstangs.layout.relative;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
@Permissions(values = {}) // Permissions must always be declared otherwise your app or library won’t work.
@Author("Roger Garstang")
@ActivityObject
@ShortName("RelativeLayout")
@Version(1.00f)
public class MyRelativeLayoutWrapper extends ViewWrapper<MyRelativeLayout> {
public int ViewLeftPadding = 0;
public int ViewTopPadding = 0;
public int ViewRightPadding = 0;
public int ViewBottomPadding = 0;
public int yAlignParentTop = RelativeLayout.ALIGN_PARENT_TOP; // 10
public int yAlignParentCentVert = RelativeLayout.CENTER_VERTICAL; // 15
public int yAlignViewTop = RelativeLayout.ALIGN_TOP; // 6
public int yAlignViewBottom = RelativeLayout.ALIGN_BOTTOM; // 8
public int yAlignViewBaseline = RelativeLayout.ALIGN_BASELINE; // 4
public int yAlignAboveView = RelativeLayout.ABOVE; // 2
public int yAlignBelowView = RelativeLayout.BELOW; // 3
public int xAlignParentLeft = RelativeLayout.ALIGN_PARENT_LEFT; // 9
public int xAlignParentRight = RelativeLayout.ALIGN_PARENT_RIGHT; // 11
public int xAlignParentCentHorz = RelativeLayout.CENTER_HORIZONTAL; // 14
public int xAlignViewLeft = RelativeLayout.ALIGN_LEFT; // 5
public int xAlignViewRight = RelativeLayout.ALIGN_RIGHT; // 7
public int xAlignLeftOfView = RelativeLayout.LEFT_OF; // 0
public int xAlignRightOfView = RelativeLayout.RIGHT_OF; // 1
public int sizeWrapContent = LayoutParams.WRAP_CONTENT;
public int sizeMatchParent = LayoutParams.MATCH_PARENT;
@Override
@Hide
public void innerInitialize(BA pBA, String pEventName, boolean pKeepOldObject) {
if (!pKeepOldObject) {
setObject(new MyRelativeLayout(pBA));
}
super.innerInitialize(pBA, pEventName, true);
}
@Override
public void Initialize(BA ba, String EventPrefix) {
super.Initialize(ba, EventPrefix);
}
public void Hide(){
getObject().setVisibility(View.GONE);
}
public void Show(){
getObject().setVisibility(View.VISIBLE);
}
public void AddView(View NewView, int Width, int Height, int xAlign, View xView, int yAlign, View yView){
RelativeLayout.LayoutParams myLayoutParams = new RelativeLayout.LayoutParams(Width, Height);
myLayoutParams.setMargins(ViewLeftPadding, ViewTopPadding, ViewRightPadding, ViewBottomPadding);
if (xView == null) { // Assume Parent Align
if (xAlign == xAlignParentLeft) myLayoutParams.addRule(xAlignParentLeft);
if (xAlign == xAlignParentRight) myLayoutParams.addRule(xAlignParentRight);
if (xAlign == xAlignParentCentHorz) myLayoutParams.addRule(xAlignParentCentHorz);
}
else {
if (xAlign == xAlignViewLeft) myLayoutParams.addRule(xAlignViewLeft, xView.getId());
if (xAlign == xAlignViewRight) myLayoutParams.addRule(xAlignViewRight, xView.getId());
if (xAlign == xAlignLeftOfView) myLayoutParams.addRule(xAlignLeftOfView, xView.getId());
if (xAlign == xAlignRightOfView) myLayoutParams.addRule(xAlignRightOfView, xView.getId());
}
if (yView == null) { // Assume Parent Align
if (yAlign == yAlignParentTop) myLayoutParams.addRule(yAlignParentTop);
if (yAlign == yAlignParentCentVert) myLayoutParams.addRule(yAlignParentCentVert);
}
else {
if (yAlign == yAlignAboveView) myLayoutParams.addRule(yAlignAboveView, yView.getId());
if (yAlign == yAlignBelowView) myLayoutParams.addRule(yAlignBelowView, yView.getId());
if (yAlign == yAlignViewTop) myLayoutParams.addRule(yAlignViewTop, yView.getId());
if (yAlign == yAlignViewBottom) myLayoutParams.addRule(yAlignViewBottom, yView.getId());
if (yAlign == yAlignViewBaseline) myLayoutParams.addRule(yAlignViewBaseline, yView.getId());
}
NewView.setLayoutParams(myLayoutParams);
getObject().addView(NewView);
}
}