6
6
import android .content .pm .ConfigurationInfo ;
7
7
import android .opengl .GLSurfaceView ;
8
8
import android .os .Bundle ;
9
+ import android .view .View ;
10
+ import android .widget .SeekBar ;
11
+ import android .widget .Toast ;
9
12
10
13
/**
11
14
* Created by hzqiujiadi on 16/1/22.
12
15
* hzqiujiadi ashqalcn@gmail.com
13
16
*/
14
17
public class MD360DemoActivity extends Activity {
15
18
16
- /** Hold a reference to our GLSurfaceView */
19
+ private static final String TAG = "MD360DemoActivity" ;
20
+ /** Hold a reference to our GLSurfaceView */
17
21
private GLSurfaceView mGLSurfaceView ;
22
+ private MD360Director mDirector ;
18
23
19
24
@ Override
20
25
public void onCreate (Bundle savedInstanceState ){
21
26
super .onCreate (savedInstanceState );
22
-
23
- mGLSurfaceView = new GLSurfaceView (this );
24
-
25
- // Check if the system supports OpenGL ES 2.0.
26
- final ActivityManager activityManager = (ActivityManager ) getSystemService (Context .ACTIVITY_SERVICE );
27
- final ConfigurationInfo configurationInfo = activityManager .getDeviceConfigurationInfo ();
28
- final boolean supportsEs2 = configurationInfo .reqGlEsVersion >= 0x20000 ;
29
-
30
- if (supportsEs2 ){
31
- // Request an OpenGL ES 2.0 compatible context.
32
- mGLSurfaceView .setEGLContextClientVersion (2 );
33
-
34
- // Set the renderer to our demo renderer, defined below.
35
- mGLSurfaceView .setRenderer (new MD360Renderer (this ));
36
- } else {
37
- // This is where you could create an OpenGL ES 1.x compatible
38
- // renderer if you wanted to support both ES 1 and ES 2.
39
- return ;
40
- }
41
-
42
- setContentView (mGLSurfaceView );
27
+ setContentView (R .layout .activity_main );
28
+
29
+ mDirector = new MD360Director ();
30
+ initOpenGL ();
31
+ initSeekBar ();
43
32
}
44
33
34
+ private void initOpenGL (){
35
+ mGLSurfaceView = (GLSurfaceView ) findViewById (R .id .surface_view );
36
+
37
+ // Check if the system supports OpenGL ES 2.0.
38
+ final ActivityManager activityManager = (ActivityManager ) getSystemService (Context .ACTIVITY_SERVICE );
39
+ final ConfigurationInfo configurationInfo = activityManager .getDeviceConfigurationInfo ();
40
+ final boolean supportsEs2 = configurationInfo .reqGlEsVersion >= 0x20000 ;
41
+
42
+ if (supportsEs2 ){
43
+ // Request an OpenGL ES 2.0 compatible context.
44
+ mGLSurfaceView .setEGLContextClientVersion (2 );
45
+
46
+ // Set the renderer to our demo renderer, defined below.
47
+ mGLSurfaceView .setRenderer (new MD360Renderer (this ,mDirector ));
48
+ } else {
49
+ mGLSurfaceView .setVisibility (View .GONE );
50
+ Toast .makeText (MD360DemoActivity .this , "OpenGLES2 not supported." , Toast .LENGTH_SHORT ).show ();
51
+ }
52
+ }
53
+
54
+ private static float progressToValue (int progress , int min , int max ){
55
+ int range = max - min ;
56
+ float result = progress * 1.0f * range / 100.0f + min ;
57
+ return result ;
58
+ }
59
+
60
+ private void initSeekBar () {
61
+ SeekBar viewSeekBar = (SeekBar ) findViewById (R .id .seek_bar_view );
62
+ SeekBar modelSeekBar = (SeekBar ) findViewById (R .id .seek_bar_model );
63
+ SeekBar projectionSeekBar = (SeekBar ) findViewById (R .id .seek_bar_projection );
64
+
65
+ viewSeekBar .setOnSeekBarChangeListener (new SeekBarOnChangeListenerAdapter () {
66
+ @ Override
67
+ public void onProgressChanged (SeekBar seekBar , int progress , boolean fromUser ) {
68
+ int min = 2 ;
69
+ int max = 50 ;
70
+ mDirector .updateCameraDistance (progressToValue (progress ,min ,max ));
71
+ }
72
+ });
73
+
74
+ modelSeekBar .setOnSeekBarChangeListener (new SeekBarOnChangeListenerAdapter () {
75
+ @ Override
76
+ public void onProgressChanged (SeekBar seekBar , int progress , boolean fromUser ) {
77
+ int min = 0 ;
78
+ int max = 360 ;
79
+ mDirector .updateModelRotate (progressToValue (progress ,min ,max ));
80
+ }
81
+ });
82
+
83
+ projectionSeekBar .setOnSeekBarChangeListener (new SeekBarOnChangeListenerAdapter () {
84
+ @ Override
85
+ public void onProgressChanged (SeekBar seekBar , int progress , boolean fromUser ) {
86
+ int min = 1 ;
87
+ int max = 12 ;
88
+ mDirector .updateProjectionNear (progressToValue (progress ,min ,max ));
89
+ }
90
+ });
91
+
92
+ }
93
+
45
94
@ Override
46
95
protected void onResume (){
47
96
// The activity must call the GL surface view's onResume() on activity onResume().
@@ -54,5 +103,18 @@ protected void onPause(){
54
103
// The activity must call the GL surface view's onPause() on activity onPause().
55
104
super .onPause ();
56
105
mGLSurfaceView .onPause ();
57
- }
106
+ }
107
+
108
+ public static abstract class SeekBarOnChangeListenerAdapter implements SeekBar .OnSeekBarChangeListener {
109
+ @ Override
110
+ public void onStartTrackingTouch (SeekBar seekBar ) {
111
+ // nope
112
+ }
113
+
114
+ @ Override
115
+ public void onStopTrackingTouch (SeekBar seekBar ) {
116
+ // nope
117
+ }
118
+ }
119
+
58
120
}
0 commit comments