annotate android/project/src/org/libsdl/app/SDLActivity.java @ 4918:f5f70fed2c4c

Added a Visual Studio project for testgesture
author Sam Lantinga <slouken@libsdl.org>
date Tue, 30 Nov 2010 12:38:46 -0800
parents 9076cdb027af
children
rev   line source
4726
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
1 package org.libsdl.app;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
2
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
3 import javax.microedition.khronos.egl.EGLConfig;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
4 import javax.microedition.khronos.opengles.GL10;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
5 import javax.microedition.khronos.egl.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
6
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
7 import android.app.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
8 import android.content.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
9 import android.view.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
10 import android.os.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
11 import android.util.Log;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
12 import android.graphics.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
13 import android.text.method.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
14 import android.text.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
15 import android.media.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
16 import android.hardware.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
17 import android.content.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
18
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
19 import java.lang.*;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
20
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
21
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
22 /**
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
23 SDL Activity
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
24 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
25 public class SDLActivity extends Activity {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
26
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
27 //Main components
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
28 private static SDLActivity mSingleton;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
29 private static SDLSurface mSurface;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
30
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
31 //Audio
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
32 private static AudioTrack mAudioTrack;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
33 private static boolean bAudioIsEnabled;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
34
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
35 //Sensors
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
36 private static boolean bAccelIsEnabled;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
37
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
38 //feature IDs. Must match up on the C side as well.
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
39 private static int FEATURE_AUDIO = 1;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
40 private static int FEATURE_ACCEL = 2;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
41
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
42 //Load the .so
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
43 static {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
44 System.loadLibrary("sdlapp");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
45 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
46
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
47 //Setup
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
48 protected void onCreate(Bundle savedInstanceState) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
49 super.onCreate(savedInstanceState);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
50
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
51 //So we can call stuff from static callbacks
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
52 mSingleton = this;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
53
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
54 //Set up the surface
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
55 mSurface = new SDLSurface(getApplication());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
56 setContentView(mSurface);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
57 SurfaceHolder holder = mSurface.getHolder();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
58 holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
59
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
60 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
61
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
62 //Audio
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
63 public static boolean initAudio(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
64
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
65 //blah. Hardcoded things are bad. FIXME when we have more sound stuff
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
66 //working properly.
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
67 mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
68 11025,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
69 AudioFormat.CHANNEL_CONFIGURATION_MONO,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
70 AudioFormat.ENCODING_PCM_8BIT,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
71 2048,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
72 AudioTrack.MODE_STREAM);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
73 bAudioIsEnabled = true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
74 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
75 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
76
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
77 //Accel
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
78 public static boolean initAccel(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
79 mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
80 bAccelIsEnabled = true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
81 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
82 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
83
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
84 public static boolean closeAccel(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
85 mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, false);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
86 bAccelIsEnabled = false;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
87 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
88 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
89
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
90
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
91 //Events
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
92 protected void onPause() {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
93 super.onPause();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
94 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
95
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
96 protected void onResume() {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
97 super.onResume();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
98 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
99
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
100
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
101
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
102
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
103
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
104 //C functions we call
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
105 public static native void nativeInit();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
106 public static native void nativeQuit();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
107 public static native void nativeSetScreenSize(int width, int height);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
108 public static native void onNativeKeyDown(int keycode);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
109 public static native void onNativeKeyUp(int keycode);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
110 public static native void onNativeTouch(int action, float x,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
111 float y, float p);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
112 public static native void onNativeResize(int x, int y, int format);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
113 public static native void onNativeAccel(float x, float y, float z);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
114
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
115
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
116
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
117 //Java functions called from C
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
118 private static void createGLContext(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
119 mSurface.initEGL();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
120 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
121
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
122 public static void flipBuffers(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
123 mSurface.flipEGL();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
124 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
125
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
126 public static void updateAudio(byte [] buf){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
127
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
128 if(mAudioTrack == null){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
129 return;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
130 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
131
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
132 mAudioTrack.write(buf, 0, buf.length);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
133 mAudioTrack.play();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
134
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
135 Log.v("SDL","Played some audio");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
136 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
137
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
138 public static void enableFeature(int featureid, int enabled){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
139 Log.v("SDL","Feature " + featureid + " = " + enabled);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
140
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
141 //Yuck. This is all horribly inelegent. If it gets to more than a few
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
142 //'features' I'll rip this out and make something nicer, I promise :)
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
143 if(featureid == FEATURE_AUDIO){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
144 if(enabled == 1){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
145 initAudio();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
146 }else{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
147 //We don't have one of these yet...
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
148 //closeAudio();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
149 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
150 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
151
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
152 else if(featureid == FEATURE_ACCEL){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
153 if(enabled == 1){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
154 initAccel();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
155 }else{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
156 closeAccel();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
157 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
158 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
159 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
160
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
161
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
162
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
163
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
164
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
165
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
166
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
167 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
168
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
169 /**
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
170 Simple nativeInit() runnable
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
171 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
172 class SDLRunner implements Runnable{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
173 public void run(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
174 //SDLActivity.initAudio();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
175
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
176 //Runs SDL_main()
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
177 SDLActivity.nativeInit();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
178
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
179 Log.v("SDL","SDL thread terminated");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
180 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
181 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
182
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
183
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
184 /**
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
185 SDLSurface. This is what we draw on, so we need to know when it's created
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
186 in order to do anything useful.
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
187
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
188 Because of this, that's where we set up the SDL thread
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
189 */
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
190 class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
191 View.OnKeyListener, View.OnTouchListener, SensorEventListener {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
192
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
193 //This is what SDL runs in. It invokes SDL_main(), eventually
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
194 private Thread mSDLThread;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
195
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
196 //EGL private objects
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
197 private EGLContext mEGLContext;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
198 private EGLSurface mEGLSurface;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
199 private EGLDisplay mEGLDisplay;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
200
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
201 //Sensors
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
202 private static SensorManager mSensorManager;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
203
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
204 //Startup
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
205 public SDLSurface(Context context) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
206 super(context);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
207 getHolder().addCallback(this);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
208
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
209 setFocusable(true);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
210 setFocusableInTouchMode(true);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
211 requestFocus();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
212 setOnKeyListener(this);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
213 setOnTouchListener(this);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
214
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
215 mSensorManager = (SensorManager)context.getSystemService("sensor");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
216 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
217
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
218 //Called when we have a valid drawing surface
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
219 public void surfaceCreated(SurfaceHolder holder) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
220 Log.v("SDL","Surface created");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
221
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
222 int width = getWidth();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
223 int height = getHeight();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
224
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
225 //Set the width and height variables in C before we start SDL so we have
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
226 //it available on init
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
227 SDLActivity.nativeSetScreenSize(width, height);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
228
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
229 //Now start up the C app thread
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
230 mSDLThread = new Thread(new SDLRunner(), "SDLThread");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
231 mSDLThread.start();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
232 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
233
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
234 //Called when we lose the surface
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
235 public void surfaceDestroyed(SurfaceHolder holder) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
236 Log.v("SDL","Surface destroyed");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
237
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
238 SDLActivity.nativeQuit();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
239
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
240 //Now wait for the SDL thread to quit
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
241 try{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
242 mSDLThread.wait();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
243 }catch(Exception e){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
244 Log.v("SDL","Problem stopping thread: " + e);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
245 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
246 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
247
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
248 //Called when the surface is resized
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
249 public void surfaceChanged(SurfaceHolder holder, int format,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
250 int width, int height) {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
251 Log.v("SDL","Surface resized");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
252
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
253 SDLActivity.onNativeResize(width, height, format);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
254 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
255
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
256 //unused
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
257 public void onDraw(Canvas canvas) {}
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
258
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
259
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
260 //EGL functions
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
261 public boolean initEGL(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
262 Log.v("SDL","Starting up");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
263
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
264 try{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
265
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
266 EGL10 egl = (EGL10)EGLContext.getEGL();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
267
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
268 EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
269
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
270 int[] version = new int[2];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
271 egl.eglInitialize(dpy, version);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
272
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
273 int[] configSpec = {
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
274 //EGL10.EGL_DEPTH_SIZE, 16,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
275 EGL10.EGL_NONE
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
276 };
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
277 EGLConfig[] configs = new EGLConfig[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
278 int[] num_config = new int[1];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
279 egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
280 EGLConfig config = configs[0];
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
281
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
282 EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
283
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
284 EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
285
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
286 egl.eglMakeCurrent(dpy, surface, surface, ctx);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
287
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
288 mEGLContext = ctx;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
289 mEGLDisplay = dpy;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
290 mEGLSurface = surface;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
291
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
292
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
293 }catch(Exception e){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
294 Log.v("SDL", e + "");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
295 for(StackTraceElement s : e.getStackTrace()){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
296 Log.v("SDL", s.toString());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
297 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
298 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
299 Log.v("SDL","Done making!");
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
300
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
301 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
302 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
303
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
304 //EGL buffer flip
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
305 public void flipEGL(){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
306 try{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
307
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
308 EGL10 egl = (EGL10)EGLContext.getEGL();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
309 GL10 gl = (GL10)mEGLContext.getGL();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
310
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
311 egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
312
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
313 //drawing here
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
314
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
315 egl.eglWaitGL();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
316
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
317 egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
318
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
319
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
320 }catch(Exception e){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
321 Log.v("SDL", "flipEGL(): " + e);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
322
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
323 for(StackTraceElement s : e.getStackTrace()){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
324 Log.v("SDL", s.toString());
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
325 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
326 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
327 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
328
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
329
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
330
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
331 //Key events
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
332 public boolean onKey(View v, int keyCode, KeyEvent event){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
333
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
334 if(event.getAction() == KeyEvent.ACTION_DOWN){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
335 SDLActivity.onNativeKeyDown(keyCode);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
336 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
337 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
338
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
339 else if(event.getAction() == KeyEvent.ACTION_UP){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
340 SDLActivity.onNativeKeyUp(keyCode);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
341 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
342 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
343
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
344 return false;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
345 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
346
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
347 //Touch events
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
348 public boolean onTouch(View v, MotionEvent event){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
349
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
350 int action = event.getAction();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
351 float x = event.getX();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
352 float y = event.getY();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
353 float p = event.getPressure();
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
354
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
355 //TODO: Anything else we need to pass?
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
356 SDLActivity.onNativeTouch(action, x, y, p);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
357 return true;
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
358 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
359
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
360 //Sensor events
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
361 public void enableSensor(int sensortype, boolean enabled){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
362 //TODO: This uses getDefaultSensor - what if we have >1 accels?
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
363 if(enabled){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
364 mSensorManager.registerListener(this,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
365 mSensorManager.getDefaultSensor(sensortype),
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
366 SensorManager.SENSOR_DELAY_GAME, null);
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
367 }else{
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
368 mSensorManager.unregisterListener(this,
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
369 mSensorManager.getDefaultSensor(sensortype));
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
370 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
371 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
372
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
373 public void onAccuracyChanged(Sensor sensor, int accuracy){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
374 //TODO
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
375 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
376
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
377 public void onSensorChanged(SensorEvent event){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
378 if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
379 SDLActivity.onNativeAccel( event.values[0],
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
380 event.values[1],
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
381 event.values[2] );
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
382 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
383 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
384
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
385
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
386 }
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
387
9076cdb027af Cleanups.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
388