PolycodeView.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. Copyright (C) 2016 by Joachim Meyer
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "polycode/core/PolyAndroidCore.h"
  21. #include <android/native_activity.h>
  22. #include <android/sensor.h>
  23. #include <android/log.h>
  24. #include <android/configuration.h>
  25. //Sensor types the NDK supports but are not in the enum of sensor types
  26. #define ASENSOR_TYPE_ORIENTATION 3
  27. #define ASENSOR_TYPE_GRAVITY 9
  28. #define ASENSOR_TYPE_LINEAR_ACCELERATION 10
  29. #define ASENSOR_TYPE_ROTATION_VECTOR 11
  30. #define ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 14
  31. #define ASENSOR_TYPE_GAME_ROTATION_VECTOR 15
  32. #define ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED 16
  33. #define ASENSOR_TYPE_SIGNIFICANT_MOTION 17
  34. #define ASESNOR_TYPE_STEP_DETECTOR 18
  35. #define ASESNOR_TYPE_STEP_COUNTER 19
  36. #define ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 20
  37. #define LOGI(text) ((void)__android_log_write(ANDROID_LOG_INFO, "TemplateApp", text))
  38. #define LOGE(text) ((void)__android_log_write(ANDROID_LOG_ERROR, "TemplateApp", text))
  39. #define ACONFIGURATION_DENSITY_XXXHIGH 640
  40. namespace Polycode {
  41. enum{
  42. // Android lifecycle status flags. Not app-specific
  43. // Set between onResume and onPause
  44. APP_STATUS_ACTIVE = 0x00000001,
  45. // Set between onWindowFocusChanged(true) and (false)
  46. APP_STATUS_FOCUSED = 0x00000002,
  47. // Set when the app's SurfaceHolder points to a
  48. // valid, nonzero-sized surface
  49. APP_STATUS_HAS_REAL_SURFACE = 0x00000004,
  50. // Mask of all app lifecycle status flags
  51. APP_STATUS_INTERACTABLE = 0x00000007
  52. };
  53. class PolycodeView : public PolycodeViewBase {
  54. public:
  55. PolycodeView(ANativeActivity* native, String title);
  56. ~PolycodeView();
  57. String windowTitle;
  58. ANativeActivity* native_activity;
  59. ANativeWindow* native_window;
  60. AInputQueue* native_input;
  61. AConfiguration* native_config;
  62. ASensorManager* sensorManager;
  63. ASensorEventQueue* sensorQueue;
  64. int64_t gyroTimestamp;
  65. jobject WakeLock;
  66. unsigned int lifecycleFlags;
  67. bool isInteractable();
  68. bool firstWindowCreate;
  69. };
  70. }
  71. struct startHelper{
  72. pthread_t thread;
  73. pthread_mutex_t mutex;
  74. pthread_cond_t cond;
  75. ANativeActivity* activity;
  76. int running;
  77. };
  78. void onStart(ANativeActivity* activity);
  79. void onResume(ANativeActivity* activity);
  80. void onPause(ANativeActivity* activity);
  81. void* onSaveInstanceState(ANativeActivity* activity, size_t *outSize);
  82. void onStop(ANativeActivity* activity);
  83. void onDestroy(ANativeActivity* activity);
  84. void onWindowFocusChanged(ANativeActivity* activity, int hasFocus);
  85. void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow *window);
  86. void onNativeWindowResized(ANativeActivity* activity, ANativeWindow *window);
  87. void onNativeWindowRedrawNeeded(ANativeActivity* activity, ANativeWindow *window);
  88. void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow *window);
  89. void onInputQueueCreated(ANativeActivity* activity, AInputQueue *queue);
  90. void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue *queue);
  91. void onContentRectChanged(ANativeActivity* activity, const ARect *rect);
  92. void onConfiguartionChanged(ANativeActivity* activity);
  93. void onLowMemory(ANativeActivity* activity);
  94. static int inputLoop(int fd, int events, void* data);
  95. static int sensorLoop(int fd, int events, void* data);
  96. void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize);
  97. void* startApp(void* data);
  98. int JNIGetUnicodeChar(ANativeActivity* native_activity, int eventType, int keyCode, int metaState);
  99. void JNIAutoHideNavBar(ANativeActivity* native_activity);
  100. void JNIWakeLock(ANativeActivity* native_activity, bool acquire);