NAV Navbar
xml java objective_c swift

개요

문서의 범위

이 문서는 Android와 iOS에서 MOMLView를 사용하기 위해 OS별로 각각 구현한 Native API를 중심으로 다룹니다.

OS 종류와 상관없는 XML UI element나 Script Object등과 같은 공통 MOML API의 사용법은 MOML API Reference 문서를 참고하십시오.

MOML Native 연동 예

일반적으로 MOML Native 연동이 필요한 상황들은 아래와 같이 분류할 수 있습니다.

• UI element 추가
BUTTON, LABEL, IMAGE 등과 같은 UI element를 사용자가 직접 추가하기 위해서는 DefaultUIComponent를 상속 받아 구현하여 MOMLView.registerUIComponent로 등록해야 합니다.

MOML Native Classes

▹ MOMLViewController

[declaration]
package org.mospi.moml.framework.pub.core;

class MOMLActivity extends Activity implements IMOMLBaseActiviyProxy
class MOMLFragmentActivity extends FragmentActivity implements IMOMLBaseActiviyProxy
class MOMLMapActivity extends MapActivity implements IMOMLBaseActiviyProxy
[declaration]
MOMLUIViewController.h

@interface MOMLUIViewController : UIViewController
[declaration]
class MOMLUIViewController : UIViewController

MOMLView 하나를 관리하고 있으며 MOMLView에서 자주 사용되는 API를 바로 사용할 수 있도록 제공합니다.

[attr] MOMLView momlView

[declaration]
MOMLView getMOMLView()

void setMOMLView(MOMLView momlView)
[declaration]
@property (nonatomic, strong) IBOutlet MOMLView* momlView
[declaration]
@IBOutlet var momlView: MOMLView!

관리하고 있는 MOMLView를 설정하거나 현재 설정된 MOMLView를 리턴합니다.

[func] void loadApplication(url)

[declaration]
void loadApplication(String url)

[example]
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    loadApplication("embed:/moml/applicationInfo.xml");

}
[declaration]
- (void)loadApplication:(NSString *)url

[example]
- (void)viewDidLoad
{
     [super viewDidLoad];

     [self loadApplication:@"embed:/moml/applicationInfo.xml"];
}
[declaration]
func loadApplication(url: String!)

[example]
override func viewDidLoad() {
     super.viewDidLoad()

     loadApplication("embed:/moml/applicationInfo.xml");
}

MOML Application Info XML file을 읽어서 화면에 MOML 앱을 실행합니다.

Parameter Type 설명
url "[url path]"

[func] void loadUrl(url)

[declaration]
void loadUrl(String url)

[example]
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);

     loadUrl("embed:/moml/ui/start.xml");
}
[declaration]
- (void)loadUrl:(NSString *)url

[example]
- (void)viewDidLoad
{
     [super viewDidLoad];

     [self loadUrl:@"embed:/moml/ui/start.xml"];
}
[declaration]
func loadUrl(url: String!)

[example]
override func viewDidLoad() {
     super.viewDidLoad()

     loadUrl("embed:/moml/ui/start.xml");
}

MOML UI XML file을 읽어서 화면에 MOML 앱을 실행합니다.

Parameter Type 설명
url "[url path]"

▹ MOMLView

[declaration]
package org.mospi.moml.framework.pub.core;

class MOMLView extends FrameLayout
[declaration]
MOMLView.h

@interface MOMLView : UIView
[declaration]
class MOMLView : UIView

MOML 페이지를 화면에 보여주며 내부 개체를 관리하고 제어할 수 있는 인터페이스를 제공합니다.

[func] void addUIObjectHandler(uiId, handler)

[declaration]
public void addUIObjectHandler(String uiId, MOMLUIObjectHandler handler)

[example]
getMomlView.addUIObjectHandler("root.coverflow1", new DefaultUIObjectHandler() {
    public boolean onClick(MOMLUIObject uiObject) {
        textView1.setText("MOMLView CoverFlow Index :" + uiObject.getAttribute("index"));
        return true;
    }
});
[declaration]
- (void)addUIObjectHandler:(NSString *)uiId handler:(id<MOMLUIObjectDelegate>)handler

[example]
[self.momlView addUIObjectHandler: @"root.coverflow1" handler:[DefaultUIObjectHandler handlerWithOnClickBlock:^BOOL(MOMLUIObject *uiObject) {
     [textView1 setText:[NSString stringWithFormat:@"MOMLView CoverFlow Index : %@", [uiObject getAttribute:@"index"]];
     return true;
    }]];
[declaration]
func addUIObjectHandler(uiId: String!, handler: MOMLUIObjectDelegate!)

[example]
momlView.addUIObjectHandler("root.nativeTestBtn", handler: DefaultUIObjectHandler(onClick:{ (uiObject) -> Bool in
     textView1.text = "MOMLView CoverFlow Index : \(uiObject.getAttribute("index"))"
     return false;
}))

UI Object를 제어할 수 있는 UIObjectHandler를 추가합니다.

Parameter Type 설명
uiId "[ui object full id]"
handler "[IMOMLUIObjectHandler]" 핸들러 객체

[attr] MOMLUIObject root

[declaration]
MOMLUIObject getRoot()

[example]
MOMLUIObject root = getMomlView().getRoot();
[declaration]
@property (nonatomic, readonly) MOMLUIObject *root

[example]
MOMLUIObject *root = self.momlView.root;
[declaration]
var root: MOMLUIObject! { get }

[example]
var root = momlView.root

MOMLView에서 root CONTAINER element를 제어할 수 있는 MOMLUIObject를 리턴합니다.

[func] void loadApplication(url)

[declaration]
void loadApplication(String url)

[example]
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getMomlView().loadApplication("embed:/moml/applicationInfo.xml");

}
[declaration]
- (void)loadApplication:(NSString *)url

[example]
- (void)viewDidLoad
{
     [super viewDidLoad];

     [self.momlView loadApplication:@"embed:/moml/applicationInfo.xml"];
}
[declaration]
func loadApplication(url: String!)

[example]
override func viewDidLoad() {
     super.viewDidLoad()

     momlView.loadApplication("embed:/moml/applicationInfo.xml");
}

MOML Application Info XML file을 읽어서 화면에 MOML 앱을 실행합니다.

Parameter Type 설명
url "[url path]"

[func] void loadUrl(url)

[declaration]
void loadUrl(String url)

[example]
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getMOMLView().loadUrl("embed:/moml/ui/start.xml");

}
[declaration]
- (void)loadUrl:(NSString *)url

[example]
- (void)viewDidLoad
{
     [super viewDidLoad];

     [self.momlView loadUrl:@"embed:/moml/ui/start.xml"];
}
[declaration]
func loadURL(url: String!)

[example]
override func viewDidLoad() {
     super.viewDidLoad()

     momlView.loadUrl("embed:/moml/ui/start.xml");
}

MOML Application Info XML file을 읽어서 화면에 MOML 앱을 실행합니다.

Parameter Type 설명
url "[url path]"

[func] bool registerObjectComponent(className, objectName, baseObjectName, userObject)

[declaration]
boolean registerObjectComponent(String className, String objectName, String baseObjectName, Object userObj)

[example]
getMomlView().registerObjectComponent(NativeComponent.class.getName(), "native", "object", this);
getMomlView().registerObjectComponent("com.mycompany.moml.NativeComponent", "native", "object", this);
[declaration]
- (BOOL)registerObjectComponent:(NSString *)className name:(NSString *)objectName base:(NSString *)baseObjectName userObject:(NSObject *)userObj

[example]
[self.momlView registerObjectComponent:NSStringFromClass(NativeObjectComponent.class) name:@"native" base:@"object" userObject:self];
[self.momlView registerObjectComponent:@"NativeObjectComponent" name:@"native" base:@"object" userObject:self];
[declaration]
func registerObjectComponent(className: String!, name: String!, base: String!, userObject userObj: NSObject!) -> Bool

[example]
momlView.registerObjectComponent(NSStringFromClass(NativeObjectComponent.self), name: "native", base: "object", userObject: self)
momlView.registerObjectComponent("MyProjectName.NativeObjectComponent", name: "native", base: "object", userObject: self)

사용자 Script Object를 등록합니다.

Parameter Type 설명
className "[full class name]" class 전체 이름 (android의 경우 package 이름을 포함해야 합니다.)
objectName "[identifier]" Script Object의 이름
baseObjectName "[identifier]" 기본이 되는 Script Object의 이름
userObj "[object]" 개체 생성시 파라미터로 전달될 객체

[func] bool registerUIComponent(className, elementName, baseElementName, userObject)

[declaration]
boolean registerUIComponent(String className, String elementName, String baseElementName, Object userObj)

[example]
getMomlView().registerUIComponent(MyButtonUIComponent.class.getName(), "MYBUTTON", "WINDOW", this);
getMomlView().registerUIComponent("com.mycompany.moml.MyButtonUIComponent", "MYBUTTON", "WINDOW", this);
[declaration]
- (BOOL)registerUIComponent:(NSString *)className name:(NSString *)elementName base:(NSString *)baseElementName userObject:(NSObject *)userObj

[example]
[self.momlView registerUIComponent:NSStringFromClass(MyButtonUIComponent.class) name:@"MYBUTTON" base:@"WINDOW" userObject:self];
[self.momlView registerUIComponent@"MyButtonUIComponent" name:@"MYBUTTON" base:@"WINDOW" userObject:self];
[declaration]
func registerUIComponent(className: String!, name: String!, base: String!, userObject userObj: NSObject!) -> Bool

[example]
momlView.registerUIComponent(NSStringFromClass(MyButtonUIComponent.self), name: "MYBUTTON", base: "WINDOW", userObject: self)
momlView.registerUIComponent("MyProjectName.MyButtonUIComponent", name: "MYBUTTON", base: "WINDOW", userObject: self)

사용자 UI element를 등록합니다.

Parameter Type 설명
className "[full class name]" class 전체 이름 (android의 경우 package 이름을 포함해야 합니다.)
objectName "[identifier]" Script Object의 이름
baseObjectName "[identifier]" 기본이 되는 Script Object의 이름
userObj "[object]" 개체 생성시 파라미터로 전달될 객체

bool unregisterObjectComponent(className)

[declaration]
boolean unregisterObjectComponent(String className)

[example]
getMomlView().unregisterObjectComponent(NativeComponent.class.getName());
getMomlView().unregisterObjectComponent("com.mycompany.moml.NativeComponent");
[declaration]
- (BOOL)unregisterObjectComponent:(NSString *)className

[example]
[self.momlView unregisterObjectComponent:NSStringFromClass(NativeObjectComponent.class)];
[self.momlView unregisterObjectComponent:@"NativeObjectComponent"];
[declaration]
func unregisterObjectComponent(className: String!) -> Bool

[example]
momlView.unregisterObjectComponen(NSStringFromClass(NativeObjectComponent.self))
momlView.unregisterObjectComponen("MyProjectName.NativeObjectComponent")

등록한 사용자 Script Object를 등록 해제합니다.

Parameter Type 설명
className "[full class name]" class 전체 이름 (android의 경우 package 이름을 포함해야 합니다.)

bool unregisterUIComponent(className)

[declaration]
boolean unregisterUIComponent(String className)

[example]
getMomlView().unregisterUIComponent(MyButtonUIComponent.class.getName());
getMomlView().unregisterUIComponent("com.mycompany.moml.MyButtonUIComponent");
[declaration]
- (BOOL)unregisterUIComponent:(NSString *)className

[example]
[self.momlView unregisterObjectComponent:NSStringFromClass(MyButtonUIComponent.class)];
[self.momlView unregisterObjectComponent:@"MyButtonUIComponent.class"];
[declaration]
func unregisterUIComponent(className: String!) -> Bool

[example]
momlView.unregisterObjectComponent(NSStringFromClass(MyButtonUIComponent.self))
momlView.unregisterObjectComponent("MyProjectName.MyButtonUIComponent")

등록한 사용자 UI element를 등록 해제합니다.

Parameter Type 설명
className "[full class name]" class 전체 이름 (android의 경우 package 이름을 포함해야 합니다.)

▹ MOMLUIObject

[declaration]
package org.mospi.moml.framework.pub.core;

class MOMLUIObject extends MOMLObject
[declaration]
MOMLUIObject.h

@interface MOMLUIObject : MOMLObject
[declaration]
class MOMLUIObject : MOMLObject

UI element를 외부에서 제어할 수 있도록 해줍니다.

Inherited from MOMLObject

[attr] string elementName

[declaration]
String getElementName();
[declaration]
@property (nonatomic, readonly) NSString *elementName;
[declaration]
var elementName: String! { get }

UI element의 XML Tag 이름을 리턴합니다.

[attr] string idName

[declaration]
String getIdName()
[declaration]
@property (nonatomic, readonly) NSString *idName
[declaration]
var idName: String! { get }

UI element의 id 속성 값을 리턴합니다.

[func] string getAttribute(name)

[declaration]
String getAttribute(String name)
[declaration]
- (NSString *)getAttribute:(NSString*)name
[declaration]
func getAttribute(name: String!) -> String!

Script Object의 속성을 리턴합니다.

Parameter Type 설명
name "[identifier]" 속성의 이름

[func] MOMLUIObject findWindow(name)

[declaration]
MOMLUIObject findWindow(String name)
[declaration]
- (MOMLUIObject*)findWindow:(NSString*)name
[declaration]
func findWindow(name: String!) -> MOMLUIObject!

UI element를 찾습니다.

Parameter Type 설명
name "[identifier]" 찾을 UI element의 id path

[func] IMOMLUIObjectHandler getHandler()

[declaration]
MOMLUIObjectHandler getHandler()
[declaration]
- (id<MOMLUIObjectDelegate>) delegate
[declaration]
func findWindow(name: String!) -> MOMLUIObject!

UI element에 설정된 이벤트를 핸들러를 리턴합니다.

Parameter Type 설명
name "[identifier]" 찾을 UI element의 id path

[func] View getView()

[declaration]
FrameLayout getFrameLayout()
[declaration]
@property (nonatomic, readonly) UIView *view
[declaration]
var view: UIView! { get }

UI element의 Native View를 리턴합니다.

Parameter Type 설명
name "[identifier]" 찾을 UI element의 id path

[func] void setAttribute(name, value)

[declaration]
void setAttribute(String name, String value)
[declaration]
- (void)setAttribute:(NSString*)name value:(NSString*)value
[declaration]
- (void)setAttribute:(NSString*)name value:(NSString*)value

Script Object의 속성을 설정합니다.

Parameter Type 설명
name "[identifier]" 속성의 이름
value "[string]"

[func] void setHandler(handler)

[declaration]
void setHandler(MOMLUIObjectHandler handler)
[declaration]
- (void)setDelegate:(id<MOMLUIObjectDelegate> )handler
[declaration]
var delegate: MOMLUIObjectDelegate!

UI element의 이벤트를 핸들링할 수 있는 인터페이스를 설정합니다.

Parameter Type 설명
handler "[IMOMLUIObjectHandler]" 핸들러 객체

[func] string runScript(script, targetId)

[declaration]
String runScript(String script)

[example]
MOMLUIObject root = getMomlView().getRoot ();
String userId = root.runScript("userVariable.userId";

if (userId != null && userId.equals("guest")) {
    root.runScript("function.root.login('" + userId + "')");
}
[declaration]
- (NSString *)runScript:(NSString *)script

[example]
MOMLUIObject *root = self.momlView.root
NSString *userId = [root runScript:@"userVariable.userId"];

if (userId != nil && [userId isEqualToString:@"guest"]) {
    [root runScript:[NSString stringWithFormat:@"function.root.login('%@')", userId]];
}
[declaration]
func runScript(script: String!) -> String!

[exmaple]
var root = momlView.root
var userId = root.runScript("userVariable.userId")

if userId != nil && userId == "guest" {
    root.runScript("function.root.login('\(userId)')")
}

현재 UI element를 caller로 스크립트를 실행하고 결과를 리턴합니다.

Parameter Type 설명
script "[script]" 실행할 스크립트 구문

▹ MOMLObjectApiInfo

[declaration]
package org.mospi.moml.framework.pub.objectapi;

class ObjectApiInfo
[declaration]
MOMLObjectApiInfo.h

@interface MOMLObjectApiInfo : NSObject
[declaration]
class MOMLObjectApiInfo : NSObject

사용자 Script Object나 UI element의 API 정보를 정의합니다.

[func] MOMLObjectApiInfo createObjectApiInfo(name, modVer, addVer, delVer, parent)

[declaration]
static ObjectApiInfo createObjectApiInfo(String name, String modVer, String addVer, String delVer, Object parent)

[example]
public ObjectApiInfo getObjectApiInfo() {

     ObjectApiInfo apiInfo = ObjectApiInfo.createObjectApiInfo("QRCODE", "1.0.0", "1.0.0", "", getBase());

     apiInfo.registerProperty("data", null, "1.0.0", "1.0.0", "");
     apiInfo.registerMethod("share", null, 0, "1.0.0", "1.0.0", "");

     return apiInfo;
}
[declaration]
+ (MOMLObjectApiInfo *)createObjectApiInfoWithName:(NSString *)name modifiedVersion:(NSString *)modVer addedVersion:(NSString *)addVer deletedVersion:(NSString *)delVer parent:(MOMLObjectApiInfo *)parent

[example]
- (MOMLObjectApiInfo *)getObjectApiInfo
{
    MOMLObjectApiInfo *objApiInfo = [MOMLObjectApiInfo createObjectApiInfoWithName:@"QRCODE" modifiedVersion:@"1.0.0" addedVersion:@"1.0.0" deletedVersion:@"" parent:[super getObjectApiInfo]];

    REGISTER_PROPERTY(data, 1.0.0, 1.0.0, )
    REGISTER_METHOD(share, 0, 1.0.0, 1.0.0, )

    return objApiInfo;
}
[declaration]
class func createObjectApiInfoWithName(name: String!, modifiedVersion: String!, addedVersion: String!, deletedVersion: String!, parent: MOMLObjectApiInfo!) -> MOMLObjectApiInfo!

[example]
override func getObjectApiInfo() -> MOMLObjectApiInfo! {
     var objApiInfo = MOMLObjectApiInfo.createObjectApiInfoWithName("QRCODE", modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "", parent: getBase().getObjectApiInfo())

     objApiInfo.registerPropertyName("data", internalName: nil, modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "")
     objApiInfo.registerMethodName("share", internalName: nil, parameterCount: 0, modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "")

     return objApiInfo

Script Object가 지원하는 함수 정보 테이블을 생성합니다.

Parameter Type 설명
name "[identifier]" 클래스의 이름
modVer "[number].[ number].[ number]" 클래스의 API가 마지막으로 수정된 라이브러리 버전
addVer "[number].[ number].[ number]" 클래스의 API가 최초로 추가된 라이브러리 버전
delVer "[number].[ number].[ number]" 클래스의 API가 삭제된 라이브러리 버전
parent "[ObjectApiInfo]" 부모 클래스의 ObjectApiInfo

[func] void registerMethod(name, internalName, parameterCount, modVer, addVer, delVer)

[declaration]
void registerMethod(String name, String internalName, int parameterCount, String modVer, String addVer, String delVer)
[declaration]
- (void)registerMethodName:(NSString *)name internalName:(NSString *)internalName parameterCount:(int)parameterCount modifiedVersion:(NSString *)modVer addedVersion:(NSString *)addVer deletedVersion:(NSString *)delVer
[declaration]
func registerMethodName(name: String!, internalName: String!, parameterCount: Int32, modifiedVersion: String!, addedVersion: String!, deletedVersion: String!)

Script Object가 지원하는 함수를 선언합니다.

Parameter Type 설명
name "[identifier]" 외부로 노출할 함수 이름
internalName "[identifier]" 실제로 구현한 함수 이름
parameterCount "[number]" 함수 인자 개수
modVer "[number].[ number].[ number]" 함수의 API가 마지막으로 수정된 라이브러리 버전
addVer "[number].[ number].[ number]" 함수의 API가 최초로 추가된 라이브러리 버전
delVer "[number].[ number].[ number]" 함수의 API가 삭제된 라이브러리 버전

[func] void registerProperty(name, internalName, modVer, addVer, delVer)

[declaration]
void registerProperty(String name, String internalName, String modVer, String addVer, String delVer)
[declaration]
- (void)registerPropertyName:(NSString *)name internalName:(NSString *)internalName modifiedVersion:(NSString *)modVer addedVersion:(NSString *)addVer deletedVersion:(NSString *)delVer
[declaration]
func registerPropertyName(name: String!, internalName: String!, modifiedVersion: String!, addedVersion: String!, deletedVersion: String!)

Script Object가 지원하는 속성을 선언합니다.

Parameter Type 설명
name "[identifier]" 외부로 노출할 속성 이름
internalName "[identifier]" 실제로 구현한 속성 이름
modVer "[number].[ number].[ number]" 속성의 수PI가 마지막으로 수정된 라이브러리 버전
addVer "[number].[ number].[ number]" 속성의 API가 최초로 추가된 라이브러리 버전
delVer "[number].[ number].[ number]" 속성의 API가 삭제된 라이브러리 버전

MOML Helper Classes

MOML Helper class들은 MOML Native Interface들을 편하게 사용하기 위해 라이브러리 외부에서 별도로 구현한 클래스입니다.

▹ MOMLHelper

[declaration]
MOMLHelper.java

class MOMLHelper
[declaration]
MOMLHelper.h

@interface MOMLHelper : NSObject
[declaration]
MOMLHelper.swift

class MOMLHelper

MOML Native 연동을 위한 여러 함수들을 제공합니다.

[func] string runFunction(caller, function, args...)

[declaration]
static String runFunction(MOMLUIObject caller, String function, Object... args)

[example]
int count = 6;

String result = MOMLHelper.runFunction(getMomlView().getRoot(), "function.root.log", "count : ", count);
[declaration]
+ (NSString *)runFunction:(MOMLUIObject *)caller function:(NSString *)function, ...

[example]
int count = 6;

NSString *result = [MOMLHelper runFunction:self.momlView.root function:@"function.root.log", @"count", [NSNumber numberWithInt:count], nil];
[declaration]
func runFunction(caller: MOMLUIObject!, function: NSString!, args: AnyObject...) -> String!

[example]
var count = 6

var result = MOMLHelper.runFunction(momlView.root, function: "function.root.log", args: "count", count)

함수 호출 스크립트를 만들어서 시행하고 결과를 리턴합니다.

Parameter Type 설명
caller "[MOMLUIObject]" 함수 호출 시 caller로 지정할 UI element
name "[identifier][. [identifier]]..." ⎮ "function.[identifier][. [identifier]]..." 함수를 실행할 개체.함수이름
args "[[string] ⎮ [number]], ... " 함수 파라미터

[func] View findViewByClass(view, class)

[declaration]
static View findViewByClass(View view, Class<?> cls)

[example]
Button button = (Button)MOMLHelper.findViewByClass(uiObject.getFrameLayout(), Button.class);

if (button != null)
    button.setTextColor(Color.GREEN);
[declaration]
+ (UIView *)findView:(UIView *)view withClass:(Class)cls

[example]
UIButton *button = (UIButton*)[MOMLHelper findView:uiObject.view withClass:UIButton.class];

if (button != nil)
    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[declaration]
class func findView(view: UIView!, cls: AnyClass!) -> UIView!

[example]
if let button = MOMLHelper.findView(uiObject.view, cls: UIButton.self) as? UIButton {
    button.setTitleColor(UIColor.greenColor(), forState: UIControlState.Normal)
}

view와 view 자식들 중에서 class 타입과 일치하는 view를 찾습니다.

Parameter Type 설명
view "[View]" 찾을 뷰, 자기 자신도 검색에 포함합니다.
cls "[Class]" class 타입

[func] string setAttribute(caller, attribute, value)

[declaration]
static String setAttribute(MOMLUIObject caller, String attribute, Object value)

[example]
MOMLHelper.setAttribute(getMomlView().getRoot(), "userVariable.nativeValue", text);
[declaration]
+ (NSString *)setAttribute:(MOMLUIObject *)caller attribute:(NSString *)attribute value:(NSObject *)value

[example]
[MOMLHelper setAttribute:self.momlView.root attribute:@"userVariable.nativeValue" value:text];
[declaration]
class func setAttribute(caller: MOMLUIObject!, attribute: NSString!, value: AnyObject!) -> String!

[example]
MOMLHelper.setAttribute(momlView.root, attribute: "userVariable.nativeValue" value: text)

함수 호출 스크립트를 만들어서 실행하고 결과를 리턴합니다.

Parameter Type 설명
caller "[MOMLUIObject]" 함수 호출 시 caller로 지정할 UI element
attribute "[identifier][. [identifier]]..." ⎮ "function.[identifier][. [identifier]]..." 속성을 설정할 개체.속성이름
value "[string]" ⎮ "[number]" ⎮ "function.[identifier][. [identifier]]..." 속성 값

▹ DefaultUIObjectHandler

[declaration]
DefaultUIObjectHandler.java

class DefaultUIObjectHandler implements MOMLUIObjectHandler

[example]
getMomlView.addUIObjectHandler("root.coverflow1", new DefaultUIObjectHandler() {
    public boolean onClick(MOMLUIObject uiObject) {
        textView1.setText("MOMLView CoverFlow Index :" + uiObject.getAttribute("index"));
        return true;
    }
});
[declaration]
DefaultUIObjectHandler.h

@interface DefaultUIObjectHandler : NSObject <MOMLUIObjectDelegate>

[example]
[self.momlView addUIObjectHandler: [DefaultUIObjectHandler handlerWithOnClickBlock:^BOOL(MOMLUIObject *uiObject) {
     [textView1 setText:[NSString stringWithFormat:@"MOMLView CoverFlow Index : %@", [uiObject getAttribute:@"index"]]];
}] forUiId:@"root.coverflow1"];
[declaration]
DefaultUIObjectHandler.swift

class DefaultUIObjectHandler : NSObject, MOMLUIObjectDelegate

[example]
momlView.addUIObjectHandler("root.nativeTestBtn", handler: DefaultUIObjectHandler(onClick:{ (uiObject) -> Bool in
     textView1.text = "MOMLView CoverFlow Index : \(uiObject.getAttribute("index"))"
     return false;
}))

UI element에서 발생한 이벤트를 핸들링할 수 있도록 합니다.

▹ DefaultObjectComponent

DefaultObjectComponent.java

class DefaultObjectComponent implements MOMLComponent

[example]
TestObjectComponent.java

package com.mycompany.componentdemo;

import com.mycompany.componentdemo.DefaultObjectComponent;
import org.mospi.moml.framework.pub.objectapi.ObjectApiInfo;

public class TestObjectComponent extends DefaultObjectComponent {
    @Override
    public ObjectApiInfo createObjectApiInfo() {
        ObjectApiInfo apiInfo = ObjectApiInfo.createObjectApiInfo("test", "1.0.0", "1.0.0", "", getBase().getObjectApiInfo());
        apiInfo.registerProperty("name", null, "1.0.0", "1.0.0", "");
        apiInfo.registerMethod("hello", null, 0, "1.0.0", "1.0.0", "");
        apiInfo.registerMethod("average", null, -1, "1.0.0", "1.0.0", "");
        return apiInfo;
    }

    private String mName;

    public TestObjectComponent() {
    }

    public String getName() {
        return mName;
    }

    public void setName(String value) {
        mName = value;
    }

    public String hello() {
        return "hello";
    }

    public double average(Object...args) {
        double sum = 0;
        for (Object arg : args) {
            if (arg instanceof Double) {
                sum += (Double)arg;                     
            } else {
                sum += Double.parseDouble(arg.toString());
            }
        }
        double avg = sum / args.length;
        return avg;
    }
}
[declaration]
DefaultObjectComponent.h

@interface MOMLNAME(ObjectComponent) : NSObject <IMOMLComponent>

[example]
DefaultComponentDefine.h

#define MOML_DEFAULT_COMPONENT_NAMESPACE MyCompanyTest


TestObjectComponent.h

#pragma push_macro("MOML_DEFAULT_COMPONENT_NAMESPACE")
#ifdef MOML_DEFAULT_COMPONENT_NAMESPACE
#undef MOML_DEFAULT_COMPONENT_NAMESPACE
#endif

#import "DefaultObjectComponent.h"

@interface TestObjectComponent : MOMLNAME(ObjectComponent)
@end

#pragma pop_macro("MOML_DEFAULT_COMPONENT_NAMESPACE")


TestObjectComponent.m

#import "TestObjectComponent.h"
#import "MOMLObjectApiInfo.h"

@interface TestObjectComponent()
{
    NSString *_name;
}
@end

@implementation TestObjectComponent

- (MOMLObjectApiInfo *)createObjectApiInfo
{
    MOMLObjectApiInfo *objApiInfo = [MOMLObjectApiInfo createObjectApiInfoWithName:@"test" modifiedVersion:@"1.0.0" addedVersion:@"1.0.0" deletedVersion:@"" parent:[[self getBase] getObjectApiInfo]];

    REGISTER_PROPERTY(name, 1.0.0, 1.0.0, 1.0.0)
    REGISTER_METHOD(hello, 0, 1.0.0, 1.0.0, 1.0.0)
    REGISTER_METHOD(average, -1, 1.0.0, 1.0.0, 1.0.0)

    return objApiInfo;
}

- (id) init
{
    self = [super init];
    return self;
}

- (NSString *)hello
{
    return @"hello";
}

- (NSString *)name
{
    return _name;
}

-(void)setName:(NSString *)name
{
    _name = name;
}

-(double)average:(NSArray *)args
{
    double sum = 0;

    for (NSObject *arg in args) {
        if ([arg isKindOfClass:NSNumber.class]) {
            sum += [(NSNumber *)arg doubleValue];
        } else if ([arg isKindOfClass:NSString.class]) {
            sum += [(NSString *)arg doubleValue];
        }
    }

    return sum / args.count;
}
@end
[declaration]
DefaultObjectComponent.swift

class DefaultObjectComponent : NSObject, IMOMLComponent

[example]
TestObjectComponent.swift

import Agate

class TestObjectComponent: DefaultObjectComponent {
    var name: String?

    override func createObjectApiInfo() -> MOMLObjectApiInfo! {
        var objApiInfo = MOMLObjectApiInfo.createObjectApiInfo(self, "test")

        objApiInfo.registerProperty("name")
        objApiInfo.registerMethod("hello", 0)
        objApiInfo.registerMethod("average", -1)

        return objApiInfo
    }

    func hello() -> String {
        return "hello"
    }

    func average(args:[AnyObject]) -> Double {
        var sum: Double = 0

        for arg in args {
            if arg is NSNumber {
                sum += (arg as NSNumber).doubleValue
            } else if arg is NSString {
                sum += (arg as NSString).doubleValue
            }
        }

        return sum / Double(args.count)
    }
}

이 클래스를 상속받아 사용자 Script Object를 구현할 수 있습니다.

[func] MOMLObjectApiInfo createObjectApiInfo()

[declaration]
ObjectApiInfo createObjectApiInfo()
[declaration]
- (MOMLObjectApiInfo *)createObjectApiInfo
[declaration]
func createObjectApiInfo() -> MOMLObjectApiInfo!

Script Object가 지원하는 함수에 대한 정보들을 생성하여 리턴합니다.

[func] string callFunction(name, args)

[declaration]
String callFunction(String name, ArrayList<Object>args)

[example]
public ObjectApiInfo createObjectApiInfo() {
    ...
    apiInfo.registerMethod("sum", null, -1, "1.0.0", "1.0.0", "");
    return apiInfo;
}

public double sum(Object...args) {
    double sum = 0;
    for (Object arg : args) {
        if (arg instanceof Double) {
            sum += (Double)arg;               
        } else {
            sum += Double.parseDouble(arg.toString());
        }
    }
    return sum;
}
[declaration]
- (NSString*) callFunction:(NSString *)name args:(NSArray *)args

[example]
- (MOMLObjectApiInfo *)createObjectApiInfo
{
    ...
    REGISTER_METHOD(sum, -1, 1.0.0, 1.0.0, 1.0.0)

    return objApiInfo;
}

- (double)sum:(NSArray *)args
{
    double sum = 0;

    for (NSObject *arg in args) {
        if ([arg isKindOfClass:NSNumber.class]) {
            sum += [(NSNumber *)arg doubleValue];
        } else if ([arg isKindOfClass:NSString.class]) {
            sum += [(NSString *)arg doubleValue];
        }
    }

    return sum
}
[declaration]
func callFunction(name: String!, args: [AnyObject]!) -> String!

[example]
override func createObjectApiInfo() -> MOMLObjectApiInfo! {
     ...
    objApiInfo.registerMethodName("sum", internalName: nil, parameterCount: -1, modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "")

    return objApiInfo;
}

func sum(args:[AnyObject]) -> Double {
{
    double sum = 0;

    for arg in args {
        if arg is NSNumber {
            sum += (arg as NSNumber).doubleValue
        } else if arg is NSString {
            sum += (arg as NSString).doubleValue
        }
    }   
    return sum
}

각 OS언어의 reflection 기능을 사용하여 class에 정의된 내부 구현 함수를 매핑하여 호출합니다.

OS 언어 get 동작 set 동작
Android Java String getName() void setName(String name)
iOS Objective-C - (NSString *)name - (void) setName:(NSString *)name
iOS Swift String name() void setName(name: String!)
Android Java iOS Objective-C iOS Swift
data types boolean
int
long
float
double
java.lang.String
bool
BOOL
(unsigned) int
(unsigned) short
(unsigned) long
(unsigned) long long
float
double
const char*
NSString*
Bool
Int
UInt
Double
Float
String
Android Java iOS Objective-C iOS Swift
parameter type Object... NSArray* [AnyObject]
variant argument types java.lang.String
java.lang.Double
NSString*
NSNumber*
String
NSNumber
Parameter Type 설명
name "[identifier]" 내부 구현 함수 이름
args "[array]" 함수 파라미터

▹ DefaultUIComponent

[declaration]
DefaultUIComponent.java

class DefaultUIComponent extends DefaultObjectComponent implements MOMLUIComponent

[example]
TestUIComponentView.java
package com.mycompany.componentdemo;

import com.mycompany.componentdemo.DefaultObjectComponent;
import org.mospi.moml.framework.pub.objectapi.ObjectApiInfo;
import android.content.Context;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TestUIComponentView extends DefaultUIComponent {
    @Override
    public ObjectApiInfo createObjectApiInfo() {
        ObjectApiInfo apiInfo = ObjectApiInfo.createObjectApiInfo("TESTUI", "1.0.0", "1.0.0", "", getBase().getObjectApiInfo());

        apiInfo.registerProperty("webSource", null, "1.0.0", "1.0.0", "");
        apiInfo.registerMethod("back", "back", 0, "1.0.0", "1.0.0", "");
        apiInfo.registerMethod("forward", "forward", 0, "1.0.0", "1.0.0", "");

        return apiInfo;
    }

    private WebView mWebView;
    private String mWebSource;

    public TestUIComponentView() {
    }

    @Override
    public void onInitialUpdate() {
        // TODO Auto-generated method stub
        super.onInitialUpdate();
        setWebSource((String) uiObj.getProperty("webSource"));
    }

    @Override
    public View createView(Context context) {
        mWebView = new WebView(context);
        mWebView.setWebViewClient(new WebViewClient() {});

        return mWebView;
    }

    public void setWebSource(String url) {
        if (url == null || url.length() == 0)
            return;
        mWebSource = url;
        mWebView.loadUrl(url);
    }

    public String getWebSource() {
        return mWebSource;
    }

    public void back() {
        mWebView.goBack();
    }

    public void forward() {
        mWebView.goForward();
    }
}
[declaration]
DefaultUIComponent.h

@interface MOMLNAME(UIComponent) : MOMLNAME(ObjectComponent) <IMOMLUIComponent>

[example]
DefaultComponentDefine.h

#define MOML_DEFAULT_COMPONENT_NAMESPACE MyCompanyTest


TestUIComponentView.h
#pragma push_macro("MOML_DEFAULT_COMPONENT_NAMESPACE")
#ifdef MOML_DEFAULT_COMPONENT_NAMESPACE
#undef MOML_DEFAULT_COMPONENT_NAMESPACE
#endif

#import "DefaultUIComponent.h"

@interface TestUIComponentView : MOMLNAME(UIComponent)
@end

#pragma push_macro("MOML_DEFAULT_COMPONENT_NAMESPACE")
#ifdef MOML_DEFAULT_COMPONENT_NAMESPACE
#undef MOML_DEFAULT_COMPONENT_NAMESPACE
#endif


TestObjectComponentView.m

#import "TestUIComponentView.h"
#import "MOMLObjectApiInfo.h"

@interface TestUIComponentView ()
{
    UIWebView *_webView;
    NSString *_webSource;
}
@end

@implementation TestUIComponentView

- (MOMLObjectApiInfo *)createObjectApiInfo
{
    MOMLObjectApiInfo *objApiInfo = [MOMLObjectApiInfo createObjectApiInfoWithName:@"TESTUI" modifiedVersion:@"1.0.0" addedVersion:@"1.0.0" deletedVersion:@"" parent:[[self getBase] getObjectApiInfo]];

    REGISTER_PROPERTY(webSource, 1.0.0, 1.0.0, )
    REGISTER_METHOD(back, 0, 1.0.0, 1.0.0, 1.0.0)
    REGISTER_METHOD(forward, 0, 1.0.0, 1.0.0, 1.0.0)

    return objApiInfo;
}

- (id) init
{
    self = [super init];

    return self;
}

- (UIView *) createView;
{
    _webView = [[UIWebView alloc] init];
    return _webView;
}

- (void) onInitialUpdate
{
    [super onInitialUpdate];
    [self setWebSource:[self.uiObject getAttribute:@"webSource"]];
}

- (NSString *) webSource
{
    return _webSource;
}

- (void) setWebSource:(NSString *) src
{
    if (src == nil || src.length == 0)
        return;

    _webSource = src;
    NSURL *url = [NSURL URLWithString:src];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
}

- (void) back
{
    [_webView goBack];
}

- (void) forward
{
    [_webView goForward];
}

@end
[declaration]
DefaultUIComponent.swift

class DefaultUIComponent: DefaultObjectComponent, IMOMLUIComponent

[example]
TestUIComponentView.swift

import Agate

class TestUIComponentView: DefaultUIComponent {
    private var _webView: UIWebView?
    private var _webSource: String?

    override func createObjectApiInfo() -> MOMLObjectApiInfo! {
        var objApiInfo = MOMLObjectApiInfo.createObjectApiInfo(self, "TESTUI")

        objApiInfo.registerProperty("webSource")
        objApiInfo.registerMethod("back", 0)
        objApiInfo.registerMethod("forward", 0)

        return objApiInfo
    }

    override init() {
        super.init()
    }

    override func createView() -> UIView! {
       _webView = UIWebView()

        return _webView;
    }

    override func onInitialUpdate() {
        super.onInitialUpdate()
        setWebSource(uiObject?.getAttribute("webSource"))
    }

    func webSource() -> String! {
        return _webSource;
    }

    func setWebSource(src: String!) {
        if src == nil || countElements(src) == 0 {
            return
        }

        _webSource = src

        var url : NSURL = NSURL(string: src)!
        var request = NSURLRequest(URL: url)
        _webView?.loadRequest(request)
    }

    func back() {
        _webView?.goBack()
    }

    func forward() {
        _webView?.goForward()
    }   
}
<?xml version="1.0" encoding="UTF-8"?>

<MOML version="1.1.7">
    <THEMES>
        <THEME element="BUTTON" defaultImg="#0080ff" textColor="#ffffff" margin="2,2,2,2"/>
    </THEMES>
    <UILAYOUT portrait="320,480" landscape="320,480">
        <WINDOW layout="0,0,320,480" defaultImg="#ffffff">
          <WINDOW layout="0,0,320,auto" align="linear:vertical">
                 <LABEL text="UI handler: " />
                 <WINDOW layout="320,auto" align="linear" >
                        <BUTTON id="nativeTestBtn" text="native onClick" onClick="'native'" />
                        <BUTTON text="get native value by fireEvent" onClick="device.toastPopup(root.fireEvent('onGetNativeValue', 'apple', 'orange'))" />
                 </WINDOW>
                 <LABEL text="test object: " />
                 <WINDOW layout="320,auto" align="linear" >
                        <BUTTON text="test.hello" onClick="device.toastPopup(test.hello)" />
                        <BUTTON text="test.average(1, 2.5, '3', 4)" onClick="device.toastPopup(test.average(1, 2.5, '3', 4))" />
                 </WINDOW>
                 <LABEL text="TESTUI element: " />
                 <WINDOW layout="320,auto" align="linear" >
                     <BUTTON text="set webSource" onClick="custom1.webSource = 'http://mospi.org'" />
                     <BUTTON text="get webSource" onClick="device.toastPopup(custom1.webSource)" />
                 </WINDOW>
                 <WINDOW layout="320,auto" align="linear">
                     <BUTTON text="back" onClick="custom1.back" />
                     <BUTTON text="forward" onClick="custom1.forward" />
                 </WINDOW>
            </WINDOW>
            <TESTUI id="custom1" layout="0,prev.bottom,320,parent.height-prev.bottom" webSource="http://google.com" onTest="function.onTestEvent" defaultImg="#ff0000"/>
        </WINDOW>
    </UILAYOUT>   

    <FUNCTION id="onNativeCall(arg1)" >
           <RETURN condition="arg1 == userVariable.nativeValue" cmd="'received arg1:\n' + arg1" elseCmd="'arg1 is not equal to userVariable.nativeValue'"/>
    </FUNCTION>
</MOML>

이 클래스를 상속받아 사용자 UI element를 구현할 수 있습니다.

MOML Native Interfaces

MOML Native Interface들은 라이브러리 외부에서 개발자가 구현해야 하는 인터페이스들입니다.
이 인터페이스를 바로 직접 구현하는 것보다는 Helper class들을 사용하는 것이 편리합니다.

▹ IMOMLUIObjectHandler

[declaration]
package org.mospi.moml.framework.pub.core;

interface MOMLUIObjectHandler
[declaration]
MOMLUIObject.h

@protocol MOMLUIObjectDelegate<NSObject>
[declaration]
protocol MOMLUIObjectDelegate : NSObjectProtocol

UI element에서 발생한 이벤트를 핸들링할 수 있도록 합니다.

[func] string onEvent(uiObject, eventName, args...)

[declaration]
String onEvent(MOMLUIObject uiObject, String eventName, String... args);
[declaration]
- (NSString *)momlUIObject:(MOMLUIObject *)momlUIObject onEvent:(NSString *)eventName args:(NSArray *)args;
[declaration]
optional func momlUIObject(momlUIObject: MOMLUIObject!, onEvent eventName: String!, args: [AnyObject]!) -> String!

UI element의 이벤트가 발생되면 호출됩니다.

Parameter Type 설명
uiObject "[MOMLUIObject]" 이벤트가 발생한 UI element를 제어할 수 있는 MOMLUIObject 인터페이스

▹ IMOMLComponent

[declaration]
package org.mospi.moml.framework.pub.object;

interface MOMLComponent
[declaration]
IMOMLComponent.h

@protocol IMOMLComponent <NSObject>
[declaration]
protocol IMOMLComponent : NSObjectProtocol

사용자 Script Object는 이 인터페이스를 상속받아 구현해야 합니다.

[func] string callFunction(name, args)

[declaration]
String callFunction(String name, ArrayList<Object>args)

[example]
public String callFunction(String name, ArrayList<Object> args) {
    if (name.equals("text") && args.size() == 0)
        return getText();
    if (name.equals("setText") && args.size() == 1) {
        setText(args.get(0));
        return null;
    }

    return baseComponent.callFunction(name, args);                     
}
[declaration]
- (NSString*) callFunction:(NSString *)name args:(NSArray *)args

[example]
- (NSString*) callFunction:(NSString *)name args:(NSArray *)args
{
    if ([name isEqualToString:@"text"] && args.count == 0)
        return self.text;

    if ([name isEqualToString:@"setText"] && args.count == 1) {
        [self setText:[args objectAtIndex:0]];
        return nil;
    }
    return [_baseComponent callFunction:name args:args];              
}
[declaration]
func callFunction(name: String!, args: [AnyObject]!) -> String!

[example]
func callFunction(name: String!, args: [AnyObject]!) -> String!
{
    if name == "text" && args.count == 0 {
        return self.text
    }

    if name == "setText" && args.count == 1 {
        self.text = args[0]
    }

    return baseComponent?.callFunction(name args: args)
}

함수 호출이나 속성의 get/set을 구현합니다.

사용예 name args
str = obj.text "text" [] (길이가 0인 배열)
obj.text = "TEST" "setText" ["TEST"] (value 1개를 포함한 배열)
Parameter Type 설명
name "[identifier]" 내부 구현 함수 이름
args "[array]" 함수 파라미터

[func] IMOMLComponent getBase()

[declaration]
MOMLComponent getBase()
[declaration]
- (id<IMOMLComponent>) getBase
[declaration]
func getBase() -> IMOMLComponent!

base component를 리턴합니다.

[func] MOMLObjectApiInfo getObjectApiInfo()

[declaration]
ObjectApiInfo getObjectApiInfo()

[example]
public ObjectApiInfo getObjectApiInfo() {
    ObjectApiInfo apiInfo = ObjectApiInfo.createObjectApiInfo("QRCODE", "1.0.0", "1.0.0", "", getBase().getObjectApiInfo());

    apiInfo.registerProperty("data", null, "1.0.0", "1.0.0", "");
    apiInfo.registerMethod("share", null, 0, "1.0.0", "1.0.0", "");

    return apiInfo;
}
[declaration]
- (MOMLObjectApiInfo *)getObjectApiInfo

[example]
- (MOMLObjectApiInfo *)getObjectApiInfo
{
    MOMLObjectApiInfo *objApiInfo = [MOMLObjectApiInfo createObjectApiInfoWithName:@"QRCODE" modifiedVersion:@"1.0.0" addedVersion:@"1.0.0" deletedVersion:@"" parent:[[self getBase] getObjectApiInfo]];

    REGISTER_PROPERTY(data, 1.0.0, 1.0.0, )
    REGISTER_METHOD(share, 0, 1.0.0, 1.0.0, )

    return objApiInfo;
}
[declaration]
func getObjectApiInfo() -> MOMLObjectApiInfo!

[example]
override func getObjectApiInfo() -> MOMLObjectApiInfo! {
    var objApiInfo = MOMLObjectApiInfo.createObjectApiInfoWithName("QRCODE", modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "", parent: getBase().getObjectApiInfo())

    objApiInfo.registerPropertyName("data", internalName: nil, modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "")
    objApiInfo.registerMethodName("share", internalName: nil, parameterCount: 0, modifiedVersion: "1.0.0", addedVersion: "1.0.0", deletedVersion: "")

    return objApiInfo
}

Script Object가 지원하는 함수에 대한 정보들을 리턴합니다.

[func] void initBase(baseComponent, userObj, momlObj)

[declaration]
void initBase(Context context, MOMLComponent base, Object userObj, MOMLObject momlObj)

[example]
public void initBase(final Context context, MOMLComponent base, Object userObj, MOMLObject obj) {
     this.context = context;
     this.baseComponent = base;
     this.obj = obj;
     this.userObj = userObj;
}
[declaration]
void initBase(Context context, MOMLComponent base, Object userObj, MOMLObject momlObj)

[example]
- (void) initBase:(id<IMOMLComponent>)base userObject:(NSObject *)userObj object:(MOMLObject *)object
{
    _baseComponent = base;
    _userObject = userObj;
    _object = object;
}
[declaration]
func initBase(base: IMOMLComponent!, userObject userObj: NSObject!, object: MOMLObject!)

[example]
func initBase(base: IMOMLComponent!, userObject userObj: NSObject!, object: MOMLObject!) {
     self.baseComponent = base
     self.userObject = userObj
     self.object = object
}

Script Object가 생성될 때 호출됩니다.

Parameter Type 설명
base "[IMOMLComponent]" base component 인터페이스
userObj "[object]" component 등록 시 전달한 사용자 정의 object
momlObj "[object]" 현재 component의 MOMLObject 인터페이스

▹ IMOMLUIComponent

[declaration]
package org.mospi.moml.framework.pub.ui;

interface MOMLUIComponent
[declaration]
IMOMLComponent.h

@protocol IMOMLUIComponent <NSObject>
[declaration]
protocol IMOMLUIComponent : IMOMLComponent, NSObjectProtocol

사용자 UI element는 이 인터페이스를 상속받아 구현해야 합니다.

[func] View createView()

[declaration]
View createView(Context context)

[example]
public View createView(Context context) {
     mView = new TextView(context);
     mView.setText("CustomUIComponent");
     return mView;
}
[declaration]
- (UIView *) createView

[example]
- (UIView *) createView;
{
    _view = [[UITextView alloc] init];
    return _view;
}
[declaration]
func createView() -> UIView!

[example]
func createView() -> UIView! {
    view = UITextView();
    return view
}

UI element의 native view를 생성하여 리턴합니다.

[func] void layout(rect)

[declaration]
void layout(int l, int t, int r, int b)
[declaration]
- (void) layout:(CGRect) rect
[declaration]
func layout(rect: CGRect)

UI element의 크기를 조절하고 내부 뷰들을 크기에 맞추어 재배치 합니다.

[func] void onInitialUpdate()

[declaration]
void onInitialUpdate()
[declaration]
- (void) onInitialUpdate
[declaration]
func onInitialUpdate()

UI element의 화면 배치가 끝난 후 최초 한 번 호출됩니다.

[func] string onEvent(eventName, args...)

[declaration]
String onEvent(String eventName, String... args)

[example]
public String onEvent(String eventName, String... args) {
     return ((MOMLUIComponent)baseComponent).onEvent(eventName, args);
}
[declaration]
- (NSString *)onEvent:(NSString *)eventName args:(NSArray *)args

[example]
- (NSString *)onEvent:(NSString *)eventName args:(NSArray *)args
{
    return [_uiBaseComponent onEvent:eventName args:args];
}
[declaration]
func onEvent(eventName: String!, args: [AnyObject]!) -> String!

[example]
func onEvent(eventName: String!, args: [AnyObject]!) -> String!
{
    return uiBaseComponent?.onEvent(eventName, args: args)
}

이벤트를 전달합니다.

Parameter Type 설명
eventName "[identifier]" onClick, onChange와 같은 이벤트 이름

MOML Native Layout XML

▹ MOMLView

[declaration]
package org.mospi.moml.framework.pub.core;

org.mospi.moml.framework.pub.core.MOMLView

[example]
/res/values/org_mospi_moml_framework_attrs.xml
<?xml version="1.0" encoding="utf-8"?>

<resources>
    <declare-styleable name="MOMLView">
        <attr name="applicationInfo" format="string" />
        <attr name="startUrl" format="string" />
    </declare-styleable>
</resources>

/res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:moml="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/labelNativeArea"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_gravity="top|left"
        android:gravity="center_vertical"
        android:text="native button : " />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_gravity="top|right"
        android:layout_toRightOf="@id/labelNativeArea"
        android:text="function.root.onNativeCall"
        android:onClick="onButton1Click"/>

    <org.mospi.moml.framework.pub.core.MOMLView
        android:id="@+id/momlView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top|left"
        android:layout_marginTop="40dp"
        moml:applicationInfo="embed:/moml/applicationInfo.xml" />
</RelativeLayout>

MainActivity.java
@Override
public class MainActivity extends MOMLActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // uses momlView from layout resource
        MOMLView momlView1 = (MOMLView) findViewById(R.id.momlView1);
        setMomlView(momlView1);
    }
}
[declaration]
MOMLView.h

@interface MOMLView : UIView

[example]
MOMLViewIB.m

#import "MOMLView.h"

#ifdef TARGET_INTERFACE_BUILDER
@implementation MOMLView(InterfaceBuilder)

- (void)drawRect:(CGRect)rect {
    CGRect frame = self.bounds;

    // background
    [[UIColor colorWithRed:0.8 green:0.9 blue:1 alpha:1] set];
    UIRectFill(frame);

    // background text
    [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5] set];
    CGFloat fontSize = MIN(self.bounds.size.width / 4, self.bounds.size.height / 2);
    [@"MOML" drawInRect:CGRectMake(0, (frame.size.height - fontSize) / 2, frame.size.width, fontSize) withFont:[UIFont systemFontOfSize:fontSize] lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];

    // msg text
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:1] set];
    UIFont *font = [UIFont systemFontOfSize:10];
    CGRect msgRect = CGRectInset(frame, 5, 2);

    NSString *msg = @"applicationInfo or startUrl is not specified.";

    if (self.applicationInfo)
        msg = [NSString stringWithFormat:@"Application Info :\n\t%@", self.applicationInfo];
    else if (self.startUrl)
        msg = [NSString stringWithFormat:@"Start Url :\n\t%@", self.startUrl];

    [msg drawInRect:msgRect withFont:font];
}
@end

#endif // TARGET_INTERFACE_BUILDER
[declaration]
MOMLView.h

@interface MOMLView : UIView

화면의 일부 영역만 MOMLView를 사용하는 경우 Android Layout Editor나 Xcode의 Interface Builder를 통하여 MOMLView를 생성하도록 할 수도 있습니다.

Android
- Android Layout Editor에서 MOMLView의 applicationInfo나 startUrl 속성을 사용하기 위해서는 resources/declare-styleable element를 정의해야 합니다.

iOS
- Interface Builder의 Attributes Inspector에서 MOMLView의 applicationInfo나 startUrl 속성을 사용하기 위해서는 MOMLView.h 가 프로젝트에 포함되어 있어야 합니다.
- ViewController 소스에서 MOMLView에 대해 추가적인 다른 작업을 하기 위해서는 다른 View들과 마찬가지로 ViewController에 MOMLView에 대한 Referencing Outlet을 설정해야 합니다.
- MOMLUIViewController를 사용하는 경우 MOMLView의 Referencing Outlet으로 MOMLUIViewController의 momlView Outlet을 연결하십시오.
- MOMLView의 – (void)drawRect:(CGRect)rect 함수를 재정의하여 Interface Builder에서 MOMLView영역이 그려지도록 할 수 있습니다.

[attr] string applicationInfo

[declaration]
<attr name="applicationInfo" format="string" />
[declaration]
@property (nonatomic) IBInspectable NSString *applicationInfo
[declaration]
@property (nonatomic) IBInspectable NSString *applicationInfo

뷰가 로딩될 때 자동으로 MOMLView.loadApplication(1)함수를 사용하여 로딩할 MOML Application Info XML 파일을 지정합니다.

[attr] string startUrl

[declaration]
<attr name="startUrl" format="string" />
[declaration]
@property (nonatomic) IBInspectable NSString *startUrl
[declaration]
@property (nonatomic) IBInspectable NSString *startUrl

뷰가 로딩될 때 자동으로 MOMLView.loadUrl(1)함수를 사용하여 로딩할 MOML UI XML 파일을 지정합니다.