@WatermelonIce, can you please edit the code and change whatever is wrong?
Let me check the source code of HVArrangement
first and see how it works
In HVArrangement:
You need to specify container, orientation and scrollable.
Therefore,
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 = " made by Soham Shah",
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;
}
@SimpleFunction(description = "Creates a dynamic arrangement in selected arrangement.")
public void CreateArrangement(AndroidViewComponent component) {
new HVArrangement((ComponentContainer)component, LAYOUT_ORIENTATION_HORIZONTAL /*or LAYOUT_ORIENTATION_VERTICAL*/, true //or false depends on scrollable or not)
}
Note
- Constant of orientation:
static final int LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL; //0
static final int LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL; //1
can you please send the code like you did for below so i can copy and paste
It is from github
You can easily try @yusufcihan source code as i’ve said earlier :
No need to copy all code of the HVArrangement in your extension.Simply import
com.google.appinventor.components.runtime.HVArrangement
Here the output of this constructor ( HVArrangement ) will be better if it was assigned to a variable so you can use later.Something like:
HVArrangement myArrangement = new HVArrangement ( layout,orentationEnum,scrollable );
Well actually I am just showing the code and tell him what should he deals with parameters
I thought you told him that becuase he said send me the code, so you sent him the github link .Any way, he still need to import the HVArrangement class, or at least import its parent packagecom.google.appinventor.components.runtime.*;
Just tested, after removing unnecessary imports in my post 11, it works.
so what do i need to change?
Did you not see my test code…
Also you can see this.It should do it properly
i copied the same code but i get the error:
Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml
extensions:
clean:
init:
common_CommonUtils:
init:
CommonUtils:
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
CopyToRunLibDir:
components_AndroidRuntime:
init:
CommonConstants:
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
HtmlEntities:
[javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
AndroidRuntime:
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:25: error: class DynamicArrangements is public, should be declared in a file named DynamicArrangements.java
[javac] public class DynamicArrangements extends AndroidNonvisibleComponent {
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 1 warning
BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.
Total time: 7 seconds
ojects/goldv2/appinventor-sources/appinventor/components/build/HtmlEntities.jar
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
AndroidRuntime:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:25: error: class DynamicArrangements is public, should be declared in a file named DynamicArrangements.java
[javac] public class DynamicArrangements extends AndroidNonvisibleComponent {
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 1 warning
BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.
Total time: 6 seconds
What is the name of your project?It should be DynamicArrangements
If your project has another name, rename this one:
To the name of your project.
name of project is Mjkl4.java
so i should change it to
public class Mjkl4 extends AndroidNonvisibleComponent {
?
yes it should be
@Mohamed_Tamer i am able to create the same dynamic arrangements extension but it requires user to input what sort of arrangement user wants, whereas i want to directly create verticalarrangement
code:
/** ~~~~~
* 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;
import com.google.appinventor.components.runtime.HVArrangement;
@DesignerComponent(version = 1, description = "Extension By Soham Shah.",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://yusufcihan.com/img/favicon.png")
@SimpleObject(external = true)
public class Mjkl4 extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Mjkl4(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, LAYOUT_ORIENTATION_VERTICAL, false);
/*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;
}*/
}
error:
Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml
extensions:
clean:
[delete] Deleting directory /projects/goldv2/appinventor-sources/appinventor/components/build
BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:34: The following error [delete] Deleting directory /projects/goldv2/appinventor-sources/appinventor/components/reports
init:
common_CommonUtils:
init:
CommonUtils:
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
CopyToRunLibDir:
components_AndroidRuntime:
init:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/build/components
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/reports
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/reports/raw
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/reports/html
CommonConstants:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants/com/google/appinventor/components/common/package-info.class
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants.jar
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants-gwt.jar
HtmlEntities:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/components/build/HtmlEntities.jar
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
AndroidRuntime:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:42: error: illegal start of type
[javac] public Object CreateArrangement(AndroidViewComponent arrangement, /*int orientation, boolean scrollable, final boolean clickable*/) {
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:42: error: ')' expected
[javac] public Object CreateArrangement(AndroidViewComponent arrangement, /*int orientation, boolean scrollable, final boolean clickable*/) {
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:42: error: ';' expected
[javac] public Object CreateArrangement(AndroidViewComponent arrangement, /*int orientation, boolean scrollable, final boolean clickable*/) {
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:51: error: illegal start of type
[javac] return hv;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:51: error: ';' expected
[javac] return hv;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Mjkl4/Mjkl4.java:136: error: class, interface, or enum expected
[javac] }
[javac] ^
[javac] 6 errors
[javac] 1 warning
BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.
Total time: 2 seconds
The error is that you need to remove this comma:
In this line
And btw, you can change the return type here:
To HVArrangement
it works but how can i set width in the same block?
Put this code under the code you create the arrangement with:
hv.Height(myHeight);