Mercurial > sdl-ios-xcode
annotate android-project/src/org/libsdl/app/SDLActivity.java @ 4980:d9fdff945ec9
A bit of cleanup in the Android driver
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 12 Jan 2011 13:52:41 -0800 |
parents | 91d0085b7560 |
children | 55b82067815b |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 //Main components |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 //Audio |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 //Sensors |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 //feature IDs. Must match up on the C side as well. |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 //Load the .so |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 //Setup |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 //So we can call stuff from static callbacks |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 //Set up the surface |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 //Audio |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 //blah. Hardcoded things are bad. FIXME when we have more sound stuff |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 //working properly. |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 //Accel |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 //Events |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 //C functions we call |
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 nativeInit(); |
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 nativeQuit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 public static native void nativeSetScreenSize(int width, int height); |
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 onNativeKeyDown(int keycode); |
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 onNativeKeyUp(int keycode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 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
|
112 float y, float p); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 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
|
114 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
|
115 |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 //Java functions called from C |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 private static void createGLContext(){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 mSurface.initEGL(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 public static void flipBuffers(){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 mSurface.flipEGL(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 } |
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 public static void updateAudio(byte [] buf){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 if(mAudioTrack == null){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 return; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 } |
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 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
|
134 mAudioTrack.play(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 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
|
137 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 public static void enableFeature(int featureid, int enabled){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 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
|
141 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 //Yuck. This is all horribly inelegent. If it gets to more than a few |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 //'features' I'll rip this out and make something nicer, I promise :) |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 if(featureid == FEATURE_AUDIO){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 if(enabled == 1){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 initAudio(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 }else{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 //We don't have one of these yet... |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 //closeAudio(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 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
|
154 if(enabled == 1){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 initAccel(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 }else{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 closeAccel(); |
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 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 /** |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 Simple nativeInit() runnable |
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 class SDLRunner implements Runnable{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 public void run(){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 //SDLActivity.initAudio(); |
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 //Runs SDL_main() |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 SDLActivity.nativeInit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 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
|
175 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 } |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 /** |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 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
|
181 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
|
182 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 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
|
184 */ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 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
|
186 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
|
187 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 //This is what SDL runs in. It invokes SDL_main(), eventually |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 private Thread mSDLThread; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 //EGL private objects |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 private EGLContext mEGLContext; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 private EGLSurface mEGLSurface; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 private EGLDisplay mEGLDisplay; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 //Sensors |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 private static SensorManager mSensorManager; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 //Startup |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 public SDLSurface(Context context) { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 super(context); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 getHolder().addCallback(this); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 setFocusable(true); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 setFocusableInTouchMode(true); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 requestFocus(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 setOnKeyListener(this); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 setOnTouchListener(this); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 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
|
211 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 //Called when we have a valid drawing surface |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 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
|
215 Log.v("SDL","Surface created"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 int width = getWidth(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 int height = getHeight(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 //Set the width and height variables in C before we start SDL so we have |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 //it available on init |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 SDLActivity.nativeSetScreenSize(width, height); |
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 //Now start up the C app thread |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 mSDLThread = new Thread(new SDLRunner(), "SDLThread"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 mSDLThread.start(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 //Called when we lose the surface |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 public void surfaceDestroyed(SurfaceHolder holder) { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 Log.v("SDL","Surface destroyed"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 SDLActivity.nativeQuit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 //Now wait for the SDL thread to quit |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 try{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 mSDLThread.wait(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 }catch(Exception e){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 Log.v("SDL","Problem stopping thread: " + e); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 //Called when the surface is resized |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 public void surfaceChanged(SurfaceHolder holder, int format, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 int width, int height) { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 Log.v("SDL","Surface resized"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 SDLActivity.onNativeResize(width, height, format); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 //unused |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 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
|
253 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 //EGL functions |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 public boolean initEGL(){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 Log.v("SDL","Starting up"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 try{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 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
|
262 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 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
|
264 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 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
|
266 egl.eglInitialize(dpy, version); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 int[] configSpec = { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 //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
|
270 EGL10.EGL_NONE |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 }; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 EGLConfig config = configs[0]; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 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
|
278 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 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
|
280 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 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
|
282 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 mEGLContext = ctx; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 mEGLDisplay = dpy; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 mEGLSurface = surface; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 }catch(Exception e){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 Log.v("SDL", e + ""); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 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
|
291 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
|
292 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 Log.v("SDL","Done making!"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 return true; |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 //EGL buffer flip |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 public void flipEGL(){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 try{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 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
|
304 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
|
305 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 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
|
307 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 //drawing here |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 egl.eglWaitGL(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 egl.eglSwapBuffers(mEGLDisplay, mEGLSurface); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 }catch(Exception e){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 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
|
317 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 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
|
319 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
|
320 } |
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 |
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 //Key events |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 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
|
328 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 if(event.getAction() == KeyEvent.ACTION_DOWN){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 SDLActivity.onNativeKeyDown(keyCode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 return true; |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 else if(event.getAction() == KeyEvent.ACTION_UP){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 SDLActivity.onNativeKeyUp(keyCode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 } |
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 return false; |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 //Touch events |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 public boolean onTouch(View v, MotionEvent event){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 int action = event.getAction(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 float x = event.getX(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 float y = event.getY(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 float p = event.getPressure(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 //TODO: Anything else we need to pass? |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 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
|
352 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 //Sensor events |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 public void enableSensor(int sensortype, boolean enabled){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 //TODO: This uses getDefaultSensor - what if we have >1 accels? |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 if(enabled){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 mSensorManager.registerListener(this, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 mSensorManager.getDefaultSensor(sensortype), |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 SensorManager.SENSOR_DELAY_GAME, null); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 }else{ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 mSensorManager.unregisterListener(this, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 mSensorManager.getDefaultSensor(sensortype)); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 } |
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 public void onAccuracyChanged(Sensor sensor, int accuracy){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 //TODO |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 public void onSensorChanged(SensorEvent event){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 SDLActivity.onNativeAccel( event.values[0], |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 event.values[1], |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 event.values[2] ); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 |