Mercurial > sdl-ios-xcode
annotate android-project/src/org/libsdl/app/SDLActivity.java @ 4995:9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Jan 2011 11:14:20 -0800 |
parents | 3c9058f3ffe7 |
children | 8d7315668e35 |
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 { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
142 Thread.sleep(10); |
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 { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
160 Thread.sleep(10); |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 /** |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 Simple nativeInit() runnable |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 */ |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
176 class SDLMain implements Runnable { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
177 public void run() { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
178 // Runs SDL_main() |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 SDLActivity.nativeInit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 |
4989 | 181 //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
|
182 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 } |
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 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 /** |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 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
|
188 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
|
189 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 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
|
191 */ |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 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
|
193 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
|
194 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
195 // 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
|
196 private Thread mSDLThread; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
198 // EGL private objects |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 private EGLContext mEGLContext; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 private EGLSurface mEGLSurface; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 private EGLDisplay mEGLDisplay; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
203 // Sensors |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 private static SensorManager mSensorManager; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
206 // Startup |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 public SDLSurface(Context context) { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 super(context); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 getHolder().addCallback(this); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 setFocusable(true); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 setFocusableInTouchMode(true); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 requestFocus(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 setOnKeyListener(this); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 setOnTouchListener(this); |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
216 |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 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
|
218 } |
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 // 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
|
221 public void surfaceCreated(SurfaceHolder holder) { |
4989 | 222 //Log.v("SDL", "surfaceCreated()"); |
223 | |
224 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
|
225 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
227 // 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
|
228 public void surfaceDestroyed(SurfaceHolder holder) { |
4989 | 229 //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
|
230 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
231 // 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
|
232 SDLActivity.nativeQuit(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
234 // 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
|
235 if (mSDLThread != null) { |
4989 | 236 //synchronized (mSDLThread) { |
237 try { | |
238 mSDLThread.join(); | |
239 } catch(Exception e) { | |
240 Log.v("SDL", "Problem stopping thread: " + e); | |
241 } | |
242 //} | |
243 mSDLThread = null; | |
244 | |
245 //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
|
246 } |
4989 | 247 |
248 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
|
249 } |
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 // 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
|
252 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
|
253 int format, int width, int height) { |
4989 | 254 //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
|
255 |
4991
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
256 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
|
257 switch (format) { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
258 case PixelFormat.A_8: |
4989 | 259 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
|
260 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
261 case PixelFormat.LA_88: |
4989 | 262 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
|
263 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
264 case PixelFormat.L_8: |
4989 | 265 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
|
266 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
267 case PixelFormat.RGBA_4444: |
4989 | 268 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
|
269 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
|
270 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
271 case PixelFormat.RGBA_5551: |
4989 | 272 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
|
273 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
|
274 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
275 case PixelFormat.RGBA_8888: |
4989 | 276 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
|
277 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
|
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.RGBX_8888: |
4989 | 280 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
|
281 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
|
282 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
283 case PixelFormat.RGB_332: |
4989 | 284 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
|
285 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
|
286 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
287 case PixelFormat.RGB_565: |
4989 | 288 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
|
289 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
|
290 break; |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
291 case PixelFormat.RGB_888: |
4989 | 292 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
|
293 // 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
|
294 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
|
295 break; |
4991
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
296 default: |
dc9924fc5070
Fixed video mode format for unknown surface format
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
297 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
|
298 break; |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
299 } |
4988
f9af88a9c823
Whoops, need to pass that SDL format into native code
Sam Lantinga <slouken@libsdl.org>
parents:
4982
diff
changeset
|
300 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
|
301 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
302 // 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
|
303 if (mSDLThread == null) { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
304 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
|
305 mSDLThread.start(); |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
306 } |
4965
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 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
309 // unused |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 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
|
311 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
313 // EGL functions |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
314 public boolean initEGL() { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
315 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
|
316 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
317 try { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 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
|
320 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 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
|
322 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 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
|
324 egl.eglInitialize(dpy, version); |
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 int[] configSpec = { |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 //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
|
328 EGL10.EGL_NONE |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 }; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 EGLConfig config = configs[0]; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 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
|
336 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 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
|
338 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 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
|
340 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 mEGLContext = ctx; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 mEGLDisplay = dpy; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 mEGLSurface = surface; |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
344 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
345 } catch(Exception e) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 Log.v("SDL", e + ""); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
347 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
|
348 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
|
349 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 } |
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 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 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
355 // EGL buffer flip |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
356 public void flipEGL() { |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
357 try { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 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
|
359 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 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
|
361 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
362 // drawing here |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 egl.eglWaitGL(); |
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 egl.eglSwapBuffers(mEGLDisplay, mEGLSurface); |
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 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
369 } catch(Exception e) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 Log.v("SDL", "flipEGL(): " + e); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4993
diff
changeset
|
371 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
|
372 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
|
373 } |
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 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
377 // Key events |
4989 | 378 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
|
379 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
380 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
|
381 //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
|
382 SDLActivity.onNativeKeyDown(keyCode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 return true; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 } |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
385 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
|
386 //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
|
387 SDLActivity.onNativeKeyUp(keyCode); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 return true; |
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 return false; |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
394 // Touch events |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
395 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
|
396 |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 int action = event.getAction(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 float x = event.getX(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 float y = event.getY(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 float p = event.getPressure(); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 |
4982
660d3a432102
Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents:
4981
diff
changeset
|
402 // 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
|
403 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
|
404 return true; |
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 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
407 // Sensor events |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
408 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
|
409 // 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
|
410 if (enabled) { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 mSensorManager.registerListener(this, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 mSensorManager.getDefaultSensor(sensortype), |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 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
|
414 } else { |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 mSensorManager.unregisterListener(this, |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 mSensorManager.getDefaultSensor(sensortype)); |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
420 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
|
421 // TODO |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 event.values[1], |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
428 event.values[2]); |
4965
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 } |
91d0085b7560
Added the Android project and lots of info to README.android
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 |
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 |