forked from Anuken/Arc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.java
More file actions
154 lines (123 loc) · 5 KB
/
Application.java
File metadata and controls
154 lines (123 loc) · 5 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package arc;
import arc.struct.*;
import arc.util.*;
import java.net.*;
public interface Application extends Disposable{
/** Returns a list of all the application listeners used. */
Seq<ApplicationListener> getListeners();
/** Adds a new application listener. */
default void addListener(ApplicationListener listener){
synchronized(getListeners()){
getListeners().add(listener);
}
}
/** Removes an application listener. */
default void removeListener(ApplicationListener listener){
post(() -> {
synchronized(getListeners()){
getListeners().remove(listener);
}
});
}
/** Call this before update() in each backend. */
default void defaultUpdate(){
Core.settings.save();
Time.updateGlobal();
}
/** @return what {@link ApplicationType} this application has, e.g. Android or Desktop */
ApplicationType getType();
default boolean isDesktop(){
return getType() == ApplicationType.desktop;
}
default boolean isHeadless(){
return getType() == ApplicationType.headless;
}
default boolean isAndroid(){
return getType() == ApplicationType.android;
}
default boolean isIOS(){
return getType() == ApplicationType.iOS;
}
default boolean isMobile(){
return isAndroid() || isIOS();
}
default boolean isWeb(){
return getType() == ApplicationType.web;
}
/** @return the Android API level on Android, the major OS version on iOS (5, 6, 7, ..), or 0 on the desktop. */
default int getVersion(){
return 0;
}
/**
* Returns the id of the current frame. The general contract of this method is that the id is incremented only when the
* application is in the running state right before calling the {@link ApplicationListener#update()} method. Also, the id of
* the first frame is 0; the id of subsequent frames is guaranteed to take increasing values for 2<sup>63</sup>-1 rendering
* cycles.
* @return the id of the current frame
*/
long getFrameId();
/** @return the time span between the current frame and the last frame in seconds. Might be smoothed over n frames. */
float getDeltaTime();
/** @return the average number of frames per second */
int getFramesPerSecond();
/** @return the Java heap memory use in bytes. */
default long getJavaHeap(){
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}
/** @return the Native heap memory use in bytes. Only valid on Android. */
default long getNativeHeap(){
return 0;
}
/** @return the main graphics thread, upon which all ApplicationListener methods are called. May return null if not initialized. */
default @Nullable Thread getMainThread(){
return null;
}
/**
* @return whether the currently executing thread is the main thread.
* If the main thread is not initialized, returns true by default. This is used for error checking purposes.
* */
default boolean isOnMainThread(){
Thread thread = getMainThread();
return thread == null || Thread.currentThread() == thread;
}
@Nullable String getClipboardText();
void setClipboardText(String text);
/** Open a folder in the system's file browser.
* @return whether this operation was successful. */
default boolean openFolder(String file){
return false;
}
/**
* Launches the default browser to display a URI. If the default browser is not able to handle the specified URI, the
* application registered for handling URIs of the specified type is invoked. The application is determined from the protocol
* and path of the URI. A best effort is made to open the given URI; however, since external applications are involved, no guarantee
* can be made as to whether the URI was actually opened. If it is known that the URI was not opened, false will be returned;
* otherwise, true will be returned.
* @param URI the URI to be opened.
* @return false if it is known the uri was not opened, true otherwise.
*/
default boolean openURI(String URI){
return false;
}
default void getDnsServers(Seq<InetSocketAddress> out){}
/** Posts a runnable on the main loop thread.*/
void post(Runnable runnable);
/**
* Schedule an exit from the application. On android, this will cause a call to pause() and dispose() some time in the future,
* it will not immediately finish your application.
* On iOS this should be avoided in production as it breaks Apples guidelines.
*/
void exit();
/** Disposes of core resources. */
@Override
default void dispose(){
//flush any changes to settings upon dispose
if(Core.settings != null){
Core.settings.save();
}
}
/** Enumeration of possible {@link Application} types */
enum ApplicationType{
android, desktop, headless, web, iOS
}
}