CrownActivity.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. package crown.android;
  24. import android.app.Activity;
  25. import android.os.Bundle;
  26. import android.util.Log;
  27. import android.view.WindowManager;
  28. import android.view.MotionEvent;
  29. import android.hardware.Sensor;
  30. import android.hardware.SensorEvent;
  31. import android.hardware.SensorEventListener;
  32. import android.hardware.SensorManager;
  33. import android.content.Context;
  34. import android.widget.Toast;
  35. import android.content.res.AssetManager;
  36. import android.view.View;
  37. import android.view.Surface;
  38. import android.view.SurfaceView;
  39. import android.view.SurfaceHolder;
  40. import crown.android.CrownEnum;
  41. /**
  42. * BootStrap of Android Application
  43. */
  44. public class CrownActivity extends Activity
  45. {
  46. // Debug
  47. public static String TAG = "crown";
  48. // Resource attributes
  49. static AssetManager mAssetManager;
  50. // Input attributes
  51. private CrownTouch mTouch;
  52. private CrownSensor mSensor;
  53. private CrownSurfaceView mView;
  54. //-----------------------------------------------------------------------------
  55. public void onCreate(Bundle savedInstanceState)
  56. {
  57. super.onCreate(savedInstanceState);
  58. // init AssetManager
  59. mAssetManager = getAssets();
  60. CrownLib.initAssetManager(mAssetManager);
  61. // init Native Window
  62. mView = new CrownSurfaceView(this);
  63. setContentView(mView);
  64. // Init Input
  65. mTouch = new CrownTouch(this);
  66. mSensor = new CrownSensor(this);
  67. Log.i(TAG, "Crown Activity created");
  68. }
  69. //-----------------------------------------------------------------------------
  70. public void onResume()
  71. {
  72. super.onResume();
  73. // init accelerometer
  74. mSensor.startListening(this);
  75. Log.i(TAG, "Crown Activity resumed");
  76. }
  77. //-----------------------------------------------------------------------------
  78. public void onPause()
  79. {
  80. super.onPause();
  81. // stop accelerometer
  82. mSensor.stopListening();
  83. Log.i(TAG, "Crown Activity paused");
  84. }
  85. //-----------------------------------------------------------------------------
  86. public boolean onTouchEvent(MotionEvent event)
  87. {
  88. mTouch.onTouch(event);
  89. return super.onTouchEvent(event);
  90. }
  91. }