File: AndroidApplication.h

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (77 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include "../../Application.h"

struct android_app;
struct AInputEvent;

namespace nCine
{
	/// Main entry point and handler for Android applications
	class AndroidApplication : public Application
	{
	public:
		/// Entry point method to be called in the `android_main()` function
		static void Run(struct android_app* state, CreateAppEventHandlerDelegate createAppEventHandler);

		/// Processes an Android application command
		static void ProcessCommand(struct android_app* state, std::int32_t cmd);

		/// Returns true if the application has already called `Init()`
		inline bool IsInitialized() const {
			return isInitialized_;
		}

		/// Returns true if the main screen is round
		inline bool IsScreenRound() const {
			return isScreenRound_;
		}

		bool OpenUrl(StringView url) override;

		/// Handles invocation of the Back gesture
		void HandleBackInvoked();

		/// Handles the intent sent to the application activity
		void HandleIntent(StringView action, StringView uri);

		/// Handles changes of content bounds
		void HandleContentBoundsChanged(Recti bounds);

		bool CanShowScreenKeyboard() override;
		bool ToggleScreenKeyboard() override;
		bool ShowScreenKeyboard() override;
		bool HideScreenKeyboard() override;

	private:
		bool isInitialized_;
		bool isBackInvoked_;
		bool isScreenRound_;

		struct android_app* state_;
		CreateAppEventHandlerDelegate createAppEventHandler_;
		
		void PreInit();
		/// Must be called at the beginning to initialize the application
		void Init();
		/// Must be called before exiting to shut down the application
		void Shutdown();

		AndroidApplication();
		~AndroidApplication();

		AndroidApplication(const AndroidApplication&) = delete;
		AndroidApplication& operator=(const AndroidApplication&) = delete;

		/// Returns the singleton reference to the Android application
		static AndroidApplication& theAndroidApplication() {
			return static_cast<AndroidApplication&>(theApplication());
		}

		friend Application& theApplication();
	};

	/// Returns application instance
	Application& theApplication();

}