PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/android/simple/src/org/swig/simple/SwigSimple.java

#
Java | 75 lines | 49 code | 16 blank | 10 comment | 0 complexity | 9dee307b0fcdae3950a44e904e12add3 MD5 | raw file
 1package org.swig.simple;
 2
 3import android.app.Activity;
 4import android.os.Bundle;
 5import android.view.View;
 6import android.widget.Button;
 7import android.widget.TextView;
 8import android.widget.ScrollView;
 9import android.text.method.ScrollingMovementMethod;
10
11public class SwigSimple extends Activity
12{
13    TextView outputText = null;
14    ScrollView scroller = null;
15
16    /** Called when the activity is first created. */
17    @Override
18    public void onCreate(Bundle savedInstanceState)
19    {
20        super.onCreate(savedInstanceState);
21        setContentView(R.layout.main);
22
23        outputText = (TextView)findViewById(R.id.OutputText);
24        outputText.setText("Press 'Run' to start...\n");
25        outputText.setMovementMethod(new ScrollingMovementMethod());
26
27        scroller = (ScrollView)findViewById(R.id.Scroller);
28    }
29
30    public void onRunButtonClick(View view)
31    {
32      outputText.append("Started...\n");
33      nativeCall();
34      outputText.append("Finished!\n");
35      
36      // Ensure scroll to end of text
37      scroller.post(new Runnable() {
38        public void run() {
39          scroller.fullScroll(ScrollView.FOCUS_DOWN);
40        }
41      });
42    }
43
44    /** Calls into C/C++ code */
45    public void nativeCall()
46    {
47      // Call our gcd() function
48      
49      int x = 42;
50      int y = 105;
51      int g = example.gcd(x,y);
52      outputText.append("The greatest common divisor of " + x + " and " + y + " is " + g + "\n");
53
54      // Manipulate the Foo global variable
55
56      // Output its current value
57      double foo = example.getFoo();
58      outputText.append("Foo = " + foo + "\n");
59
60      // Change its value
61      example.setFoo(3.1415926);
62
63      // See if the change took effect
64      outputText.append("Foo = " + example.getFoo() + "\n");
65
66      // Restore value
67      example.setFoo(foo);
68    }
69
70    /** static constructor */
71    static {
72        System.loadLibrary("example");
73    }
74}
75