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