AppInventor2|Robot Forum 机器人开发交流平台  
  
View: 86|Reply: 0

How to Write Extensions

[Copy link]
  • TA的每日心情
    开心
    2017-7-17 23:27
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    26

    Threads

    38

    Posts

    240

    Credits

    管理员

    Rank: 9Rank: 9Rank: 9

    Credits
    240
    Post time 2017-5-11 09:23:25 | Show all posts |Read mode
    HOW TO CREATE AN EXTENSION FOR APPINVENTOR2

    Hi! I am Qiang, Wei,a high school student from China.I\'ve made many extensions for appinventor2 which are shared in my homepage,but I would rather to share the process I made them.Sometimes, I am very busy in my school work, so I may not respond email immediately.I will respond you as soon as I can. I set up this website not for a long time,and I do very appreciate your support.


    Forum 论坛


    Tools you will need:
    1.Git Bash(a software for download git code sources)
    2.JDK(java 7)
    3.a java code editor(Jedit,EditPlus,etc)
    4.basic java programming experience
    5.Apache ant(a software for complie extensions)


    ​​​2.Install apache ant(click to Download)


    set environmental viables:
    ANT_HOME to your install path

    and add :
    your install path of ant+\"\\bin\" to \"Path\"
    your install path of ant+\"\\lib\" to \"ClassPath\"



    4.Start to create an extension
    -Download the appinventor sources at github and decompress it.
    -create a txt file and type in:
    ant extensions
    read
    -Then,save it with name XXX.sh in /appinventor file

    use the java code editor to establish a new file
    -the first code you must add is the \"package\" line.
    for example      
        package com.WeiWei.mail; //this is a pakage line,you can add a name for your file.

    -after you write package code,you need to import external class.

    code:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    package com.XX;

    ////////////////////////////////////////////LET\'S START TO IMPORT FILE//////////////////////////////////////
    import android.content.Context;      
    import android.util.Log;  
    import com.google.appinventor.components.annotations.*;
    import com.google.appinventor.components.common.ComponentCategory;
    import com.google.appinventor.components.runtime.*;
    import com.google.appinventor.components.runtime.collect.Sets;
    import com.google.appinventor.components.runtime.util.BoundingBox;
    import com.google.appinventor.components.runtime.util.ErrorMessages;
    import com.google.appinventor.components.runtime.util.FileUtil;
    import com.google.appinventor.components.runtime.util.MediaUtil;
    import com.google.appinventor.components.runtime.util.PaintUtil;
    import com.google.appinventor.components.common.ComponentConstants;
    import com.google.appinventor.components.common.PropertyTypeConstants;
    import com.google.appinventor.components.common.YaVersion;

    //the following file is the basic functional files for AppInventor.

    3.Create a class and add annotations.

    code:
    //////////////////////////annotations for basic initialization////////////////////////////////////
    @DesignerComponent(version = mail.VERSION,                           
        description = \"\",                                                        //this is your extension\'s description
        category = ComponentCategory.EXTENSION,     //the category is extension                          
        nonVisible = true,                                                        //only can be nonvisible        
        iconName = \"XXX.jpg\")                                              //picture path
    @SimpleObject(external = true)     
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public class XXX extends AndroidNonvisibleComponent    //set your class name in XXX for replacement.
    implements Component {                                          
        public static final int VERSION = 0;                                          //version number
        private ComponentContainer container;                               //define the component
        private Context context;                                                            //define the context
        private static final String LOG_TAG = \"mail\";                      //modify \"mail\" to your extension name
        public mail(ComponentContainer container) {         
            super(container.$form());                                
            this.container = container;                              
            context = (Context) container.$context();                      //define the context         
            Log.d(LOG_TAG, \"mail Created\" );                                 //record
        }
    ////////////////////////////////////////////add your code here//////////////////////////////////////////////////////////
    ///////////////////choose one or both of the following way//////////////////////////////////////////////////////////////
    @SimpleFunction(description = \"\")//annotation you must add in order to appear in appinventor as a function
    public int plus(int a,int b)
    {
    return a+b;
    }

    @SimpleProperty(description = \"\")//annotations you must add in order to appear in appinventor as an setable characteristics
    public boolean abc(int a,int b)
    {
    if (a ==b){
    return ture;
                    }else
    {return false;}
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }




    Source: How to Write Extensions
    觉得不错?打赏下吧,1元不嫌少,10元不嫌多!
    Reply

    Use magic Report

    You have to log in before you can reply Login | 立即注册

    Points Rules

    Quick Reply To Top Return to the list