Looking for How to create extensions blocks

Dear all Extension developers, can you please tell me how to add block in java code (sorry for my bad English ) look i am new to this any extension developer can provide there whats app number so that the form will not be flood with my questions

Thank you so much for the support friends. Keep up the good work @yusufcihan, @Abhijith_Dominic, @hammerhai, @Ken

4 Likes

If you write a function, then it will be a purple block (method).

Usage:

@SimpleFunction(description = "Block description")
     public void BlockName(parameters) {
     /* Your code here. */
     }

Example:

@SimpleFunction(description = "Join two text.")
     public String Join(String t1, String t2) {
     return t1 + t2;
     }

And this is for the property, green block.

Get:

@SimpleProperty(category = PropertyCategory.BEHAVIOR,
      description = "Block description.")
  public String Source() {
    return fileName;
  }

Set:

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING,
      defaultValue = "")
@SimpleProperty
  public void Source(String fileName) {
    this.fileName = fileName;
  }

This is only example, you need to do research to learn more about AI2 Extensions.

30 Likes

Great Work! If someone explained like this to me when i started i could’ve made a lot more extensions and gain experience. Great Work!!

8 Likes

For Yellow ie. Events

@SimpleEvent
public void GotFile(String path){
EventDispatcher.dispatchEvent(this, “GotFile”, path);
}

9 Likes

To create the Purple (function) block use:

@SimpleFunction(description = "") // Notice @SimpleFunction
public boolean Statement() { 
/*
** boolean can switch to int, String, void, or boolean. Statement can be named
** to the name of your function, do NOT create duplicates. Public can also
** switch to private or public
*/
}

Example function for boolean:

@SimpleFunction(description = "")
public boolean HasThoughtsAboutMe() {
 return false;
}

Example function for int:

@SimpleFunction(description = "")
public int HasThoughtsAboutMe() {
 return -1;
}

Example function for String:

@SimpleFunction(description = "")
public String HasThoughtsAboutMe() {
 return "Nope, we don't care about you.";
}

Example function for void:

@SimpleFunction(description = "")
public void HasThoughtsAboutMe() {
 GetStatus();
}

To create the Amber (event) block use:

@SimpleEvent(description = "") // Notice @SimpleEvent
public void Statement() { 
/*
** This stays a void! Statement can be named
** to the name of your function, do NOT create duplicates. Public can
** also switch to private or public.
**
** The variables "statement, count", and "crashed" must be thrown when
** this block, so in your block which would throw to this one, you'd use
** Statement("Who knows why your phone died?", 8000, true); Below is
** required to register the block.
*/
}

Example event with one variable:

@SimpleEvent(description = "")
public void GotAppleCount(int count) {
EventDispatcher.dispatchEvent(this, "GotAppleCount", count);
}

Example event with multiple variables:

@SimpleEvent(description = "")
public void GotAppleCount(int count, String statement, boolean areApples) {
EventDispatcher.dispatchEvent(this, "GotAppleCount", count, statement, areApples);
}

Example event with no variable:

@SimpleEvent(description = "")
public void GotAppleCount() {
EventDispatcher.dispatchEvent(this, "GotAppleCount");
}

Follow @yusufcihan’s example for properties, I no longer use them.

26 Likes

These are excellent examples @yusufcihan, @Abhijith_Dominic & @hammerhai!

@clashwithasif, the above examples are excellent. If you are looking to do something that isn’t listed above, what I do is, look at the .java file for a Component that implements something similar to what I need.
You can find the AI Component Sources here:

10 Likes

Thanks Everyone for these examples
Currently i am newbie that will help me at lot

2 Likes

How to add a visible block to the screen would be nice to know. I’ve gotten pretty far in getting an understanding but im stuck on this 1 line of code which keeps blocking me every time. If y’all have any advice please let me know.

:point_down::point_down::point_down::point_down::point_down::point_down::point_down::point_down:

2 Likes

If I am not wrong then extensions are non visible components.

2 Likes

Thats what im thinking after I did some research

1 Like

Thanks for the help ill definitely try it out. And 1 other question. making a purple block to receive color?? I know all the variables and used a few different ways but for some reason I cant figure it out. Basically when the user changing background theme. need guidance and advice dont give me the code.

That’s correct, you can’t add any visual items to the Viewer:

1 Like

Knew it lol

1 Like

Yes, but they are able to animate components (see Phase extension)or add effects (ButtonRipple extension). These are visuble stuff.

2 Likes

To simplify it;

Extensions are non-visible components. However, these non-visible extensions can create visible layouts, modify current components or maybe calculate something. So it doesn’t need to add visible stuff always.

6 Likes

As addition: Extensions are like components, but they do not have any visible parts (UI) by default.

…on the phone mock/preview in the Creator.

Which extension runs instantly (after opening app)?

IDK… :man_shrugging: