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.
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);
it works in percentage too?
I think it work with pixels.
ohh, i wanted to set width to 98%
@Mohamed_Tamer I don’t actually see where .Height() method or .Width() are defined Can you kindly tell me?
Well, you can simply see any other component, you won’t find the width and the height property ever? As they is defined in AndroidViewComponent class which is applied for every component.And as HVArrangement extends AndroidViewComponent , so every method in AndroidViewComponent class will be applied to HVArrangement class.
@Soham_Shah you can set the width with percentage! just use this method:
hv.WidthPercent(pCent)
and same for the height
hv.WidthPercent(98);
hv.SetAlign(LAYOUT_ORIENTATION_HORIZONTAL,3);
hv.SetAlign(LAYOUT_ORIENTATION_VERTICAL,2);
and can you tell me what is wrong in this?
It should be
//horizontally
hv.AlignHorizontal(2); //1 = top/left, 2 = vertically/horizontally centered, 3 = bottom/right. Alignment has no effect if the arrangement's height is automatic. "
//Vertically
hv..AlignVertical(1);//1 = top/left, 2 = vertically/horizontally centered, 3 = bottom/right. Alignment has no effect if the arrangement's height is automatic. "
Ok thanks and what about cardview property?
and i want to set bg color to red, to try to find whether the arrangement is getting created or not,
hv.SetBackgroundColor();
so what color i have to type to make it red?
Remove the word set
first.
You can know what is the int value using this block (color utilities):
It is better to look at the docs instead of asking one by one, so you will learn about all properties, methods of all App Inventor classes.
i wanted to create arrangement inside other
final HVArrangement hv = new HVArrangement((ComponentContainer)arrangement, LAYOUT_ORIENTATION_VERTICAL, false);
hv.WidthPercent(98);
hv.AlignHorizontal(3);
hv.AlignVertical(1);
return hv;
final HVArrangement hv = new HVArrangement((ComponentContainer)arrangement, LAYOUT_ORIENTATION_VERTICAL, false);
hv.Width(-2);
hv.BackgroundColor(1062319615);
}
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:48: error: variable hv is already defined in method CreateArrangement(AndroidViewComponent)
[javac] final HVArrangement hv = new HVArrangement((ComponentContainer)arrangement, LAYOUT_ORIENTATION_VERTICAL, false);
[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
ents/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:48: error: variable hv is already defined in method CreateArrangement(AndroidViewComponent)
[javac] final HVArrangement hv = new HVArrangement((ComponentContainer)arrangement, LAYOUT_ORIENTATION_VERTICAL, false);
[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
I think the error message is very clear about what’s going on
i converted a color but it is not accurate the color should be medium blue but it is coming light blue