public Object[] _OnCreate(Hashtable Ev){
StarObjectClass self = (StarObjectClass)Ev.get("_DesObject");
StarObjectClass parent = (StarObjectClass)self._Get("_Parent");
StarObjectClass activity = (StarObjectClass)self._Call("getActivity");
StarCLEButton button = new StarCLEButton((Activity)WrapAndroidClass.GetAndroidObject(activity,"AndroidObject"),self);
WrapAndroidClass.SetAndroidObject(self,"AndroidObject",(Object)button);
if( parent != null ){
if( activity == parent ){
Activity android_activity = (Activity)WrapAndroidClass.GetAndroidObject(parent,"AndroidObject");
android_activity.setContentView(button);
}else{
ViewGroup android_viewgroup = (ViewGroup)WrapAndroidClass.GetAndroidObject(parent,"AndroidObject");
android_viewgroup.addView(button);
}
self._LockGC();
self._Call("decAndroidRef");
}
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
StarObjectClass self = ((BasicAndroidInterface)v).getBasicAndroid().getStarObject();
self._ProcessEvent("onClick");
}
});
return null;
}
3. Set Text function of Button
public void setText(StarObjectClass self,String Text){
TextView textview = (TextView)WrapAndroidClass.GetAndroidObject(self,"AndroidObject");
if( textview != null )
textview.setText(Text);
}
4. Export to jar files: “wrapandroid.jar”
Finish the above steps, we can obtain
jar files
wrapandroid.jar and service description files
WrapAndroidService.xml. And then we can write programs with other languages using Eclipse.
Programming with lua
a. Create Android project named “myluaexample”
b. Add Java build library
Copy “wrapandroid.jar” and “starcore_android_r5.jar” to your project directory. Add jar library to your project.
c. Copy “WrapAndroidService.xml” to assets directory of your project
d. Add Permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
e. Create the code.lua file
Create the code.lua file in the asserts directory, input text
SrvGroup = libstarcore._GetSrvGroup()
Service = SrvGroup:_GetService("","")
--get activity
StarActivity = Service.ActivityClass.getCurrent();
--create AbsoluteLayout
MyLayout = Service.AbsoluteLayoutClass:_New(StarActivity);
--create Button
MyButton = Service.ButtonClass:_New(MyLayout);
MyButton:setText("Hello");
function MyButton:onClick(Event)
self:setText("Is Clicked");
end