Last active
December 6, 2021 00:55
-
-
Save ysfchn/b47aad010de577081133bde89ab3bfe7 to your computer and use it in GitHub Desktop.
DynamicArrangements extension for App Inventor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** ~~~~~ | |
* Created with the AppyBuilder Code Editor. | |
* This is a template for basic Extension. | |
* Modify this template to customize your extension. | |
* | |
* **** NOTE: DO NOT use a package name. | |
* **** The package name will be created for you automatically. | |
* **** Adding a package name will cause a compile error | |
*/ | |
import android.content.Context; | |
import android.util.Log; | |
import com.google.appinventor.components.annotations.*; | |
import com.google.appinventor.components.runtime.*; | |
import com.google.appinventor.components.common.ComponentCategory; | |
import com.google.appinventor.components.common.ComponentConstants; | |
import android.view.View; | |
@DesignerComponent(version = 1, description = "Extension to create dynamic arrangements, made by Yusuf Cihan, in AppyBuilder's Code Editor.", | |
category = ComponentCategory.EXTENSION, | |
nonVisible = true, iconName = "http://yusufcihan.com/img/favicon.png") | |
@SimpleObject(external = true) | |
public class DynamicArrangements extends AndroidNonvisibleComponent { | |
private ComponentContainer container; | |
/** | |
* @param container container, component will be placed in | |
*/ | |
public DynamicArrangements(ComponentContainer container) { | |
super(container.$form()); | |
this.container = container; | |
} | |
@SimpleEvent(description = "This event called when any arrangement clicked that created by CreateArrangement block.") | |
public void OnClick(AndroidViewComponent arrangement) { | |
EventDispatcher.dispatchEvent(this, "OnClick", arrangement); | |
} | |
@SimpleFunction(description = "Creates a dynamic arrangement in selected arrangement.") | |
public Object CreateArrangement(AndroidViewComponent arrangement, int orientation, boolean scrollable, final boolean clickable) { | |
final HVArrangement hv = new HVArrangement((ComponentContainer)arrangement, orientation, scrollable); | |
hv.getView().setOnClickListener(new View.OnClickListener() { | |
public void onClick(View v) { | |
if (clickable) { | |
OnClick(hv); | |
} | |
} | |
}); | |
return hv; | |
} | |
@SimpleFunction(description = "Specifies the component's vertical height, measured in pixels.") | |
public void SetHeight(AndroidViewComponent component, int height) { | |
((HVArrangement)component).Height(height); | |
} | |
@SimpleFunction(description = "Returns the component's vertical height, measured in pixels.") | |
public int GetHeight(AndroidViewComponent component) { | |
return ((HVArrangement)component).Height(); | |
} | |
@SimpleFunction(description = "Sets the background color for an arrangement.") | |
public void SetBackgroundColor(AndroidViewComponent component, int color) { | |
((HVArrangement)component).getView().setBackgroundColor(color); | |
} | |
@SimpleFunction(description = "Sets the degrees that the arrangement is rotated around the pivot point. Increasing values result in clockwise rotation.") | |
public void SetRotation(AndroidViewComponent component, float rotation) { | |
((HVArrangement)component).getView().setRotation(rotation); | |
} | |
@SimpleFunction(description = "The degrees that the arrangement is rotated around the pivot point.") | |
public float GetRotation(AndroidViewComponent component) { | |
return ((HVArrangement)component).getView().getRotation(); | |
} | |
@SimpleFunction(description = "Specifies the component's horizontal width, measured in pixels.") | |
public void SetWidth(AndroidViewComponent component, int width) { | |
((HVArrangement)component).Width(width); | |
} | |
@SimpleFunction(description = "Returns the component's horizontal width, measured in pixels.") | |
public int GetWidth(AndroidViewComponent component) { | |
return ((HVArrangement)component).Width(); | |
} | |
@SimpleFunction(description = "Specifies whether the component should be visible on the screen. Value is true if the component is showing and false if hidden.") | |
public void SetVisibility(AndroidViewComponent component, boolean visibility) { | |
((HVArrangement)component).Visible(visibility); | |
} | |
@SimpleFunction(description = "Returns true if the component is visible.") | |
public boolean GetVisibility(AndroidViewComponent component) { | |
return ((HVArrangement)component).Visible(); | |
} | |
@SimpleFunction(description = "Sets the vertical or horizontal alignment for contents of the arrangement. The choices are: 1 = top/left, 2 = vertically/horizontally centered, 3 = bottom/right. Alignment has no effect if the arrangement's height is automatic. ") | |
public void SetAlign(AndroidViewComponent component, int orientation, int align) { | |
if (orientation == ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL) | |
{ | |
((HVArrangement)component).AlignHorizontal(align); | |
} | |
else if(orientation == ComponentConstants.LAYOUT_ORIENTATION_VERTICAL) | |
{ | |
((HVArrangement)component).AlignVertical(align); | |
} | |
} | |
@SimpleFunction(description = "Returns a number that encodes how contents of the arrangement are aligned vertically or horizontally.") | |
public int GetAlign(AndroidViewComponent component, int orientation) { | |
int result = 0; | |
if (orientation == ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL) | |
{ | |
result = ((HVArrangement)component).AlignHorizontal(); | |
} | |
else if(orientation == ComponentConstants.LAYOUT_ORIENTATION_VERTICAL) | |
{ | |
result = ((HVArrangement)component).AlignVertical(); | |
} | |
return result; | |
} | |
@SimpleProperty(description = "Horizontal layout orientation.") | |
public int HorizontalOrientation() { | |
return ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL; | |
} | |
@SimpleProperty(description = "Vertical layout orientation.") | |
public int VerticalOrientation() { | |
return ComponentConstants.LAYOUT_ORIENTATION_VERTICAL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment