Mercurial > sdl-ios-xcode
annotate android-project/src/org/libsdl/app/SDLActivity.java @ 4996:8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Jan 2011 12:32:55 -0800 |
parents | 9f9bea41e88f |
children | a514bfe6952a |
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 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
32 private static Thread mAudioThread; |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 private static AudioTrack mAudioTrack; |
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 // Load the .so |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 static { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 System.loadLibrary("SDL"); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
38 //System.loadLibrary("SDL_image"); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
39 //System.loadLibrary("SDL_mixer"); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
40 //System.loadLibrary("SDL_ttf"); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 System.loadLibrary("main"); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
44 // Setup |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 protected void onCreate(Bundle savedInstanceState) { |
4989 | 46 //Log.v("SDL", "onCreate()"); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 super.onCreate(savedInstanceState); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
49 // 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
|
50 mSingleton = this; |
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 // 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
|
53 mSurface = new SDLSurface(getApplication()); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 setContentView(mSurface); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 SurfaceHolder holder = mSurface.getHolder(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 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
|
57 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
59 // Events |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 protected void onPause() { |
4989 | 61 //Log.v("SDL", "onPause()"); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 super.onPause(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 protected void onResume() { |
4989 | 66 //Log.v("SDL", "onResume()"); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 super.onResume(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
71 // 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
|
72 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
|
73 public static native void nativeQuit(); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
74 public static native void onNativeResize(int x, int y, int format); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 float y, float p); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 public static native void onNativeAccel(float x, float y, float z); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
80 public static native void nativeRunAudioThread(); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
83 // 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
|
84 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
|
85 mSurface.initEGL(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
88 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
|
89 mSurface.flipEGL(); |
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 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
92 // Audio |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
93 private static Object buf; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
94 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
95 public static Object audioInit(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
96 int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
97 int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
98 int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
99 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
100 Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer"); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
101 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
102 // Let the user pick a larger buffer if they really want -- but ye |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
103 // gods they probably shouldn't, the minimums are horrifyingly high |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
104 // latency already |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
105 desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
106 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
107 mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
108 channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
109 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
110 audioStartThread(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
111 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
112 Log.v("SDL", "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + ((float)mAudioTrack.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer"); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
113 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
114 if (is16Bit) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
115 buf = new short[desiredFrames * (isStereo ? 2 : 1)]; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
116 } else { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
117 buf = new byte[desiredFrames * (isStereo ? 2 : 1)]; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
118 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
119 return buf; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
120 } |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
122 public static void audioStartThread() { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
123 mAudioThread = new Thread(new Runnable() { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
124 public void run() { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
125 mAudioTrack.play(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
126 nativeRunAudioThread(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
127 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
128 }); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
129 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
130 // I'd take REALTIME if I could get it! |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
131 mAudioThread.setPriority(Thread.MAX_PRIORITY); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
132 mAudioThread.start(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
133 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
134 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
135 public static void audioWriteShortBuffer(short[] buffer) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
136 for (int i = 0; i < buffer.length; ) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
137 int result = mAudioTrack.write(buffer, i, buffer.length - i); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
138 if (result > 0) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
139 i += result; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
140 } else if (result == 0) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
141 try { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
142 Thread.sleep(1); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
143 } catch(InterruptedException e) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
144 // Nom nom |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
145 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
146 } else { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
147 Log.w("SDL", "SDL audio: error return from write(short)"); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
148 return; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
149 } |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 } |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
151 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
152 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
153 public static void audioWriteByteBuffer(byte[] buffer) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
154 for (int i = 0; i < buffer.length; ) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
155 int result = mAudioTrack.write(buffer, i, buffer.length - i); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
156 if (result > 0) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
157 i += result; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
158 } else if (result == 0) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
159 try { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
160 Thread.sleep(1); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
161 } catch(InterruptedException e) { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
162 // Nom nom |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
163 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
164 } else { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
165 Log.w("SDL", "SDL audio: error return from write(short)"); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
166 return; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
167 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
168 } |
4965
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 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
171 public static void audioQuit() { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
172 if (mAudioThread != null) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
173 try { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
174 mAudioThread.join(); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
175 } catch(Exception e) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
176 Log.v("SDL", "Problem stopping audio thread: " + e); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
177 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
178 mAudioThread = null; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
179 |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
180 Log.v("SDL", "Finished waiting for audio thread"); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
181 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
182 |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
183 if (mAudioTrack != null) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
184 mAudioTrack.stop(); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
185 mAudioTrack = null; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
186 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
187 } |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 |
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 Simple nativeInit() runnable |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 */ |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
193 class SDLMain implements Runnable { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
194 public void run() { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
195 // Runs SDL_main() |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 SDLActivity.nativeInit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
4989 | 198 //Log.v("SDL", "SDL thread terminated"); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
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 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
|
205 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
|
206 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 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
|
208 */ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 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
|
210 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
|
211 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
212 // 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
|
213 private Thread mSDLThread; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
215 // EGL private objects |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 private EGLContext mEGLContext; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 private EGLSurface mEGLSurface; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 private EGLDisplay mEGLDisplay; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
220 // Sensors |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 private static SensorManager mSensorManager; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
223 // Startup |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 public SDLSurface(Context context) { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 super(context); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 getHolder().addCallback(this); |
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 setFocusable(true); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 setFocusableInTouchMode(true); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 requestFocus(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 setOnKeyListener(this); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 setOnTouchListener(this); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
233 |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 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
|
235 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
237 // 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
|
238 public void surfaceCreated(SurfaceHolder holder) { |
4989 | 239 //Log.v("SDL", "surfaceCreated()"); |
240 | |
241 enableSensor(Sensor.TYPE_ACCELEROMETER, true); | |
4965
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 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
244 // 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
|
245 public void surfaceDestroyed(SurfaceHolder holder) { |
4989 | 246 //Log.v("SDL", "surfaceDestroyed()"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
247 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
248 // 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
|
249 SDLActivity.nativeQuit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
251 // 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
|
252 if (mSDLThread != null) { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
253 try { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
254 mSDLThread.join(); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
255 } catch(Exception e) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
256 Log.v("SDL", "Problem stopping thread: " + e); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
257 } |
4989 | 258 mSDLThread = null; |
259 | |
260 //Log.v("SDL", "Finished waiting for SDL thread"); | |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 } |
4989 | 262 |
263 enableSensor(Sensor.TYPE_ACCELEROMETER, false); | |
4965
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 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
266 // 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
|
267 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
|
268 int format, int width, int height) { |
4989 | 269 //Log.v("SDL", "surfaceChanged()"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
270 |
4991
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
271 int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
272 switch (format) { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
273 case PixelFormat.A_8: |
4989 | 274 Log.v("SDL", "pixel format A_8"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
275 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
276 case PixelFormat.LA_88: |
4989 | 277 Log.v("SDL", "pixel format LA_88"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
278 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
279 case PixelFormat.L_8: |
4989 | 280 Log.v("SDL", "pixel format L_8"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
281 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
282 case PixelFormat.RGBA_4444: |
4989 | 283 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
|
284 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
|
285 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
286 case PixelFormat.RGBA_5551: |
4989 | 287 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
|
288 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
|
289 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
290 case PixelFormat.RGBA_8888: |
4989 | 291 Log.v("SDL", "pixel format RGBA_8888"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
292 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
|
293 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
294 case PixelFormat.RGBX_8888: |
4989 | 295 Log.v("SDL", "pixel format RGBX_8888"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
296 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
|
297 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
298 case PixelFormat.RGB_332: |
4989 | 299 Log.v("SDL", "pixel format RGB_332"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
300 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
|
301 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
302 case PixelFormat.RGB_565: |
4989 | 303 Log.v("SDL", "pixel format RGB_565"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
304 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
|
305 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
306 case PixelFormat.RGB_888: |
4989 | 307 Log.v("SDL", "pixel format RGB_888"); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
308 // 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
|
309 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
|
310 break; |
4991
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
311 default: |
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
312 Log.v("SDL", "pixel format unknown " + format); |
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
313 break; |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
314 } |
4988
f9af88a9c823
Whoops, need to pass that SDL format into native code
Sam Lantinga <slouken@libsdl.org>
parents:
4982
diff
changeset
|
315 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
|
316 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
317 // 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
|
318 if (mSDLThread == null) { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
319 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
|
320 mSDLThread.start(); |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
321 } |
4965
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 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
324 // unused |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 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
|
326 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
328 // EGL functions |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
329 public boolean initEGL() { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
330 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
|
331 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
332 try { |
4965
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 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
|
335 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 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
|
337 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 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
|
339 egl.eglInitialize(dpy, version); |
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 int[] configSpec = { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 //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
|
343 EGL10.EGL_NONE |
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 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
|
346 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
|
347 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
|
348 EGLConfig config = configs[0]; |
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 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
|
351 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 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
|
353 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 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
|
355 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 mEGLContext = ctx; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 mEGLDisplay = dpy; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 mEGLSurface = surface; |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
359 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
360 } catch(Exception e) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 Log.v("SDL", e + ""); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
362 for (StackTraceElement s : e.getStackTrace()) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 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
|
364 } |
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 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
370 // EGL buffer flip |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
371 public void flipEGL() { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
372 try { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 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
|
374 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 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
|
376 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
377 // drawing here |
4965
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 egl.eglWaitGL(); |
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 egl.eglSwapBuffers(mEGLDisplay, mEGLSurface); |
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 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
384 } catch(Exception e) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 Log.v("SDL", "flipEGL(): " + e); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
386 for (StackTraceElement s : e.getStackTrace()) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 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
|
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 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
392 // Key events |
4989 | 393 public boolean onKey(View v, int keyCode, KeyEvent event) { |
4965
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 if (event.getAction() == KeyEvent.ACTION_DOWN) { |
4993
3c9058f3ffe7
Implemented translation from Android keycodes to SDL scancodes
Sam Lantinga <slouken@libsdl.org>
parents:
4991
diff
changeset
|
396 //Log.v("SDL", "key down: " + keyCode); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 SDLActivity.onNativeKeyDown(keyCode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 } |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
400 else if (event.getAction() == KeyEvent.ACTION_UP) { |
4993
3c9058f3ffe7
Implemented translation from Android keycodes to SDL scancodes
Sam Lantinga <slouken@libsdl.org>
parents:
4991
diff
changeset
|
401 //Log.v("SDL", "key up: " + keyCode); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 SDLActivity.onNativeKeyUp(keyCode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 return false; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
409 // Touch events |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
410 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
|
411 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 int action = event.getAction(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 float x = event.getX(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 float y = event.getY(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 float p = event.getPressure(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
417 // 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
|
418 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
|
419 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
422 // Sensor events |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
423 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
|
424 // 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
|
425 if (enabled) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 mSensorManager.registerListener(this, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 mSensorManager.getDefaultSensor(sensortype), |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 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
|
429 } else { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 mSensorManager.unregisterListener(this, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 mSensorManager.getDefaultSensor(sensortype)); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
435 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
|
436 // TODO |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 event.values[1], |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
443 event.values[2]); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 |