3
import java.io.IOException;
4
import java.io.InputStream;
6
import android.app.Activity;
7
import android.content.res.AssetManager;
8
import android.os.Bundle;
9
import android.widget.TextView;
11
import com.srplab.www.starcore.*;
13
public class MnemosyneActivity extends Activity {
15
static TextView MyEdit1;
18
public void onCreate(Bundle savedInstanceState) {
19
super.onCreate(savedInstanceState);
20
setContentView(R.layout.main);
22
MyEdit1 = (TextView)this.findViewById(R.id.widget61);
25
AssetManager assetManager = getAssets();
26
InputStream dataSource = assetManager.open("testpy.zip");
27
StarCoreFactoryPath.CreatePath(Runtime.getRuntime(),"/data/data/"+getPackageName()+"/files");
28
StarCoreFactoryPath.Install(dataSource, "/data/data/"+getPackageName()+"/files",true );
30
catch (IOException e) {
33
StarCoreFactoryPath.StarCoreCoreLibraryPath = "/data/data/"+ getPackageName()+"/lib";
34
StarCoreFactoryPath.StarCoreShareLibraryPath = "/data/data/"+getPackageName()+"/lib";
35
StarCoreFactoryPath.StarCoreOperationPath = "/data/data/"+getPackageName()+"/files";
36
StarCoreFactory starcore = StarCoreFactory.GetFactory();
38
StarSrvGroupClass SrvGroup = starcore._GetSrvGroup(0);
39
StarServiceClass Service = SrvGroup._GetService("test", "123");
40
if ( Service == null ) { // The service has not been initialized.
41
Service = starcore._InitSimple("test", "123", 0, 0);
42
Service._CheckPassword(false);
43
SrvGroup = (StarSrvGroupClass) Service._Get("_ServiceGroup");
45
SrvGroup._InitRaw("python", Service);
46
SrvGroup._LoadRawModule("python", "", "/data/data/" + getPackageName() + "/files/testpy.py", false);
47
//SrvGroup._LoadRawModule("python", "", "/data/data/" + getPackageName() + "/files/callback.py", false);
48
//Service._DoFile("python", "/data/data/"+getPackageName()+"/files/callback.py", "");
51
//--Attach object to global Python space
52
StarObjectClass python = Service._ImportRawContext("python", "", false, "");
53
//--all Python function tt, the return contains two integer, which will be packed into parapkg
54
StarParaPkgClass ParaPkg = (StarParaPkgClass)python._Call("tt","hello ","world");
55
printStr("ret from python : "+ParaPkg._Get(0)+" "+ParaPkg._Get(1));
56
//--get global int value g1
57
printStr("python value g1 : "+python._Get("g1"));
59
//--call Python function yy, the return is dict, which will be mapped to cle object
60
StarObjectClass yy = (StarObjectClass) python._Call("yy","hello ","world",123);
61
//--call dict __len__ function to get dict length
62
printStr("python value dict length : "+yy._Call("__len__"));
64
//--get global class Multiply
65
StarObjectClass Multiply = Service._ImportRawContext("python", "Multiply", true, null);
66
StarObjectClass multiply = Multiply._Callobject("_StarCall",33,44);
67
//--call instance method multiply
68
printStr("instance multiply = " + multiply._Call("multiply",11,22));
71
//--attach object to testpy.Class1 ---*/
72
//StarObjectClass TestCallBack = Service._ImportRawContext("python", "Class1", true, "");
73
//--create an instance of TestCallBack-----*/
74
//StarObjectClass inst = TestCallBack._Callobject("_StarCall");
76
StarObjectClass inst = (StarObjectClass) python._Get("class1");
78
// Create object and functions for proxy----*/
80
StarObjectClass object = Service._New()._Assign(new StarObjectClass() {
82
public void postExec(StarObjectClass self) {
83
printStr("Callback in Java from Python.");
86
public float getNum(StarObjectClass self, StarParaPkgClass input) {
87
printStr("Callback [getNum] in Java from Python : " + input._Get(0) + " " + input._Get(1));
88
return (float)(input._Getdouble(0) + input._Getdouble(1));
93
// Create proxy for interface testcallback/ICallBack ---*/
94
StarObjectClass proxy1 = Service._NewRawProxy("python", object, "postExec", "_name_does_not_seem_to_matter_Class1.postExec", 0);
95
StarObjectClass proxy2 = Service._NewRawProxy("python", object, "getNum", "Class1.getNum", 0);
96
//--set the proxy to TestCallBack instance ---*/
97
inst._Call("setCallBack", proxy1, proxy2);
98
//--now proxy can be freed----*/
102
//--call inst function postExec----*/
103
inst._Call("postExec");
104
//--call inst function getNum----*/
105
printStr(inst._Call("getNum", SrvGroup._NewParaPkg(123.0,456.0)));
108
private void printStr(Object str)
112
in_Str = MyEdit1.getText().toString();
113
in_Str = in_Str + "\n" + str;
114
MyEdit1.setText(in_Str);
b'\\ No newline at end of file'