2022年5月6日 星期五

App inventor:aix程式碼與積木顏色對應說明

aix檔中程式透過@後的裝飾符來判斷執行那項功能,會出現那一種顏色的積木


一、當裝飾符為@SimpleFunction,會出現紫色的積木,範例 如下:

@SimpleFunction(description = "Takes a screenshot of the current app, with the given quality, compressFormat and saves the screenshot as the given path.")
public void TakeScreenshot(int quality, String compressFormat, String path) {
}


TakeScreenshot為function的名稱,quality, compressFormat 及path為可傳入的參數。

二、當裝飾符為@SimpleProperty,會出現淺綠色或是緣色的積木,範例 如下:
//設定屬性,回傳JPEG
@SimpleProperty(description = "A compress format block.")
public String Jpeg() {
return "JPEG";
}

沒有參數時出現淺綠色

@SimpleProperty(description = "A compress format block.")
public String Jpeg(int a) {
return "JPEG";
}
有參數時出現深綠色



三、當裝飾符為@SimpleEvent,會出現橘色的積木,範例 如下:
@SimpleEvent(description = "This event is fired when the extension has taken the screenshot in the given path.")
public void SavedScreenshot (String path) {
EventDispatcher.dispatchEvent(this, "SavedScreenshot", path);
}


四、當裝飾符為@DesignerProperty,會出現在ui設定頁面,範例 如下:


@DesignerProperty(editorType = DesignerProperty.PROPERTY_TYPE_COLOR,
defaultValue = Component.DEFAULT_VALUE_COLOR_BLACK)
@SimpleProperty
public void PaintColor(int argb) {
paintColor = argb;
changePaint(paint, argb);
}

@DesignerProperty要放在@SimpleProperty前:

editorType = DesignerProperty.PROPERTY_TYPE_COLOR 的類型為PROPERTY_TYPE_COLOR
defaultValue = Component.DEFAULT_VALUE_COLOR_BLACK 預設值為Component.DEFAULT_VALUE_COLOR_BLACK
editorTye 類型參考 點我
defaultvalue類型參考 點我



其它:

@DesignerComponent(
version = 1,
description = "",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")
設定此程式的基本資訊

version = 1 版本
description = "" 程式描述
category 擴充自什麼包
nonVisible = true 不顯示於ui介面
iconName = "" 程式小圖位址

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "okhttp-3.6.0.jar.jar"+"okio-2.8.0.jar"+"okhttp-urlconnection-3.10.0")
//Permissions
@UsesPermissions(permissionNames = "android.permission.INTERNET")

UsesLibraries 可透過右下角的Libraries按鍵加入你的包,再加在上面
UsesPermissions 為要要求的權限

沒有留言:

張貼留言