~russo79/mnemosyne-proj/force-matplotlib-pyqt4-backend

« back to all changes in this revision

Viewing changes to mnemosyne/mnemosyne/android/mnemosyne/src/org/mnemosyne/MnemosyneActivity.java

  • Committer: Peter.Bienstman at UGent
  • Date: 2014-04-24 18:48:32 UTC
  • Revision ID: peter.bienstman@ugent.be-20140424184832-ne26w2kf0sh36bam
Android review widget.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.mnemosyne;
 
2
 
 
3
import java.io.IOException;
 
4
import java.io.InputStream;
 
5
 
 
6
import android.app.Activity;
 
7
import android.content.res.AssetManager;
 
8
import android.os.Bundle;
 
9
import android.widget.TextView;
 
10
 
 
11
import com.srplab.www.starcore.*;
 
12
 
 
13
public class MnemosyneActivity extends Activity {
 
14
 
 
15
        static TextView MyEdit1;
 
16
        
 
17
    @Override
 
18
    public void onCreate(Bundle savedInstanceState) {
 
19
        super.onCreate(savedInstanceState);
 
20
        setContentView(R.layout.main);
 
21
        
 
22
        MyEdit1 = (TextView)this.findViewById(R.id.widget61);
 
23
        
 
24
        try {
 
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 );
 
29
        }
 
30
        catch (IOException e) {
 
31
        }                               
 
32
        
 
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();
 
37
        
 
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");
 
44
 
 
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", "");
 
49
        }
 
50
                
 
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"));
 
58
 
 
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__"));
 
63
 
 
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));
 
69
                
 
70
                
 
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");
 
75
        
 
76
                StarObjectClass inst = (StarObjectClass) python._Get("class1");
 
77
        
 
78
        // Create object and functions for proxy----*/
 
79
                
 
80
        StarObjectClass object = Service._New()._Assign(new StarObjectClass() {
 
81
                
 
82
                public void postExec(StarObjectClass self) {
 
83
                        printStr("Callback in Java from Python.");
 
84
            };
 
85
                    
 
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));
 
89
             };
 
90
             
 
91
        });
 
92
       
 
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----*/
 
99
        proxy1._Free();
 
100
        proxy2._Free();
 
101
 
 
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)));    
 
106
    }
 
107
    
 
108
    private void printStr(Object str)
 
109
    {
 
110
        String in_Str;
 
111
        
 
112
        in_Str = MyEdit1.getText().toString();
 
113
        in_Str = in_Str + "\n" + str;
 
114
        MyEdit1.setText(in_Str);        
 
115
    }
 
116
}
 
 
b'\\ No newline at end of file'