-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ShadowGLSurfaceView.java
50 lines (42 loc) · 1.3 KB
/
ShadowGLSurfaceView.java
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
package org.robolectric.shadows;
import android.opengl.GLSurfaceView;
import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
/** Fake implementation of GLSurfaceView */
@Implements(GLSurfaceView.class)
public class ShadowGLSurfaceView extends ShadowSurfaceView {
private static final String TAG = "ShadowGLSurfaceView";
@Implementation
protected void onPause() {}
@Implementation
protected void onResume() {}
@Implementation
protected void onDetachedFromWindow() {
stopGLThread();
}
@Implementation
protected void finalize() throws Throwable {
try {
stopGLThread();
} finally {
super.finalize();
}
}
private void stopGLThread() {
try {
Field glThreadField = GLSurfaceView.class.getDeclaredField("mGLThread");
glThreadField.setAccessible(true);
Thread glThread = (Thread) glThreadField.get(realView);
if (glThread != null) {
Method requestExitAndWait = glThread.getClass().getMethod("requestExitAndWait");
requestExitAndWait.invoke(glThread);
}
} catch (Exception e) {
Log.e(TAG, "Exception occurred while stopping GLThread: " + e.getMessage());
e.printStackTrace();
}
}
}