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