Hello friends, I am going to tell you how to create an Extension for App Inventor and what you need to develop an Aix Extension.

I have given this information by doing research all over the internet by myself. App inventor extension components are created by programming in Java. Java code can be the basic code that you write, and can also include Java libraries (jar files) from other sources.

You can create extension components for personal use, and if you wish, you can share them by sending AIX files to people or making files available online.

Class Hierarchy



Sample demo Extension Aix code
package com.Pitagoras;
// try this code and learn how it works.

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.*;

@DesignerComponent(version = Pitagoras.VERSION,
    description = "Tenandroid Pitagoras ",
category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "Extension icon url") @SimpleObject(external = true) public class Pitagoras extends AndroidNonvisibleComponent implements Component { public static final int VERSION = 1; public static final float DEFAULT_CATETO_A = 3f; public static final float DEFAULT_CATETO_B = 4f; private ComponentContainer container; private double cateto_a = 0; private double cateto_b = 0; public Pitagoras(ComponentContainer container) { super(container.$form()); this.container = container; Cateto_A(DEFAULT_CATETO_A); Cateto_B(DEFAULT_CATETO_B); } // Obtener el valor. @SimpleProperty(category = PropertyCategory.BEHAVIOR) public double Cateto_A() { return cateto_a; } @SimpleProperty(category = PropertyCategory.BEHAVIOR) public double Cateto_B() { return cateto_b; } // Establecer el valor. @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT, defaultValue = Pitagoras.DEFAULT_CATETO_A + "") @SimpleProperty(description = "Asigna el valor del cateto A. " + "El separador decimal es el punto.") public void Cateto_A(double nuevoCateto_A) { this.cateto_a = nuevoCateto_A; } @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT, defaultValue = Pitagoras.DEFAULT_CATETO_B + "") @SimpleProperty(description = "Asigna el valor del cateto B. " + "El separador decimal es el punto.") public void Cateto_B(double nuevoCateto_B) { this.cateto_b = nuevoCateto_B; } // Funcion para calcular la hipotenusa. @SimpleFunction(description = "Introduce los dos catetos y obtendras la hipotenusa.") public double Pitagoras(double catetoA, double catetoB) { double hipotenusa, cuadrado; hipotenusa = Math.sqrt((catetoA*catetoA)+(catetoB*catetoB)); cuadrado = hipotenusa * hipotenusa; // Calcula el cuadrado de la hipotenusa. YaCalculada(cuadrado); return hipotenusa; } // Bloque disponible despues de calcular la hipotenusa. @SimpleEvent(description = "Muestra la hipotenusa al cuadrado.") public void YaCalculada(double sucuadrado){ EventDispatcher.dispatchEvent(this, "YaCalculada", sucuadrado); } }
credit - kio4.com


Post a Comment

Previous Post Next Post

INNER POST ADS