Skip to content

Commit

Permalink
[updated] Everything to use the latest source formatter. Yay! Use it,…
Browse files Browse the repository at this point in the history
… love it!
  • Loading branch information
nathan.sweet committed Aug 14, 2011
1 parent 471911b commit 2f412de
Show file tree
Hide file tree
Showing 1,005 changed files with 48,756 additions and 57,890 deletions.

Large diffs are not rendered by default.

@@ -1,44 +1,41 @@

package com.badlogic.gdx.backends.android;

import android.os.PowerManager.WakeLock;

import com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy;
import com.badlogic.gdx.backends.android.surfaceview.ResolutionStrategy;

/**
* Class defining the configuration of an {@link AndroidApplication}. Allows you
* to disable the use of the accelerometer to save battery among other things.
* @author mzechner
*
*/
/** Class defining the configuration of an {@link AndroidApplication}. Allows you to disable the use of the accelerometer to save
* battery among other things.
* @author mzechner */
public class AndroidApplicationConfiguration {
/** whether to use OpenGL ES 2.0 or not. default: false **/
public boolean useGL20 = false;

/** number of bits per color channel **/
public int r = 5, g = 6, b = 5, a = 0;

/** number of bits for depth and stencil buffer **/
public int depth = 16, stencil = 0;
public int depth = 16, stencil = 0;

/** number of samples for CSAA/MSAA, 2 is a good value **/
public int numSamples = 0;

/** whether to use the accelerometer. default: true **/
public boolean useAccelerometer = true;

/** whether to use the compass. default: true **/
public boolean useCompass = true;
/** the time in milliseconds to sleep after each event in the touch handler, set this
* to 16ms to get rid of touch flooding on pre Android 2.0 devices. default: 0 **/
public boolean useCompass = true;

/** the time in milliseconds to sleep after each event in the touch handler, set this to 16ms to get rid of touch flooding on
* pre Android 2.0 devices. default: 0 **/
public int touchSleepTime = 0;

/** whether to use a {@link WakeLock} or not. In case this is true you have to
* add the permission "android.permission.WAKE_LOCK" to your manifest file. default: false
*/

/** whether to use a {@link WakeLock} or not. In case this is true you have to add the permission "android.permission.WAKE_LOCK"
* to your manifest file. default: false */
public boolean useWakelock = false;

/** the {@link ResolutionStrategy}. default: {@link FillResolutionStrategy} **/
public ResolutionStrategy resolutionStrategy = new FillResolutionStrategy();
}
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.backends.android;

import java.io.IOException;
Expand All @@ -35,12 +36,9 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;

/**
* An implementation of the {@link Audio} interface for Android.
*
* @author mzechner
/** An implementation of the {@link Audio} interface for Android.
*
*/
* @author mzechner */
public final class AndroidAudio implements Audio {
private SoundPool soundPool;
private final AudioManager manager;
Expand All @@ -54,7 +52,7 @@ public AndroidAudio (Activity context) {
}

protected void pause () {
synchronized(musics) {
synchronized (musics) {
wasPlaying.clear();
for (AndroidMusic music : musics) {
if (music.isPlaying()) {
Expand All @@ -67,24 +65,22 @@ protected void pause () {
}

protected void resume () {
synchronized(musics) {
synchronized (musics) {
for (int i = 0; i < musics.size(); i++) {
if (wasPlaying.get(i)) musics.get(i).play();
}
}
}

/**
* {@inheritDoc}
*/
@Override public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
/** {@inheritDoc} */
@Override
public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
return new AndroidAudioDevice(samplingRate, isMono);
}

/**
* {@inheritDoc}
*/
@Override public Music newMusic (FileHandle file) {
/** {@inheritDoc} */
@Override
public Music newMusic (FileHandle file) {
AndroidFileHandle aHandle = (AndroidFileHandle)file;

MediaPlayer mediaPlayer = new MediaPlayer();
Expand All @@ -96,7 +92,7 @@ protected void resume () {
descriptor.close();
mediaPlayer.prepare();
AndroidMusic music = new AndroidMusic(this, mediaPlayer);
synchronized(musics) {
synchronized (musics) {
musics.add(music);
}
return music;
Expand All @@ -109,7 +105,7 @@ protected void resume () {
mediaPlayer.setDataSource(aHandle.path());
mediaPlayer.prepare();
AndroidMusic music = new AndroidMusic(this, mediaPlayer);
synchronized(musics) {
synchronized (musics) {
musics.add(music);
}
return music;
Expand All @@ -120,10 +116,9 @@ protected void resume () {

}

/**
* {@inheritDoc}
*/
@Override public Sound newSound (FileHandle file) {
/** {@inheritDoc} */
@Override
public Sound newSound (FileHandle file) {
AndroidFileHandle aHandle = (AndroidFileHandle)file;
if (aHandle.type() == FileType.Internal) {
try {
Expand All @@ -144,23 +139,20 @@ protected void resume () {
}
}

/**
* {@inheritDoc}
*/
@Override public AudioRecorder newAudioRecoder (int samplingRate, boolean isMono) {
/** {@inheritDoc} */
@Override
public AudioRecorder newAudioRecoder (int samplingRate, boolean isMono) {
return new AndroidAudioRecorder(samplingRate, isMono);
}

/**
* Kills the soundpool and all other resources
*/
/** Kills the soundpool and all other resources */
public void dispose () {
synchronized(musics) {
synchronized (musics) {
// gah i hate myself.... music.dispose() removes the music from the list...
ArrayList<AndroidMusic> musicsCopy = new ArrayList<AndroidMusic>(musics);
for (AndroidMusic music : musicsCopy) {
music.dispose();
}
}
}
soundPool.release();
}
Expand Down
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.backends.android;

import android.media.AudioFormat;
Expand All @@ -21,12 +22,9 @@

import com.badlogic.gdx.audio.AudioDevice;

/**
* Implementation of the {@link AudioDevice} interface for Android using the AudioTrack class. You will need to set the permission
/** Implementation of the {@link AudioDevice} interface for Android using the AudioTrack class. You will need to set the permission
* android.permission.RECORD_AUDIO in your manifest file.
* @author mzechner
*
*/
* @author mzechner */
class AndroidAudioDevice implements AudioDevice {
/** the audio track **/
private final AudioTrack track;
Expand All @@ -36,7 +34,7 @@ class AndroidAudioDevice implements AudioDevice {

/** whether this device is in mono or stereo mode **/
private final boolean isMono;

/** the latency in samples **/
private final int latency;

Expand All @@ -47,25 +45,29 @@ class AndroidAudioDevice implements AudioDevice {
track = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, isMono ? AudioFormat.CHANNEL_CONFIGURATION_MONO
: AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, minSize, AudioTrack.MODE_STREAM);
track.play();
latency = minSize / (isMono?1:2);
latency = minSize / (isMono ? 1 : 2);
}

@Override public void dispose () {
@Override
public void dispose () {
track.stop();
track.release();
}

@Override public boolean isMono () {
@Override
public boolean isMono () {
return isMono;
}

@Override public void writeSamples (short[] samples, int offset, int numSamples) {
@Override
public void writeSamples (short[] samples, int offset, int numSamples) {
int writtenSamples = track.write(samples, offset, numSamples);
while (writtenSamples != numSamples)
writtenSamples += track.write(samples, offset + writtenSamples, numSamples - writtenSamples);
}

@Override public void writeSamples (float[] samples, int offset, int numSamples) {
@Override
public void writeSamples (float[] samples, int offset, int numSamples) {
if (buffer.length < samples.length) buffer = new short[samples.length];

int bound = offset + numSamples;
Expand All @@ -82,7 +84,8 @@ class AndroidAudioDevice implements AudioDevice {
writtenSamples += track.write(buffer, writtenSamples, numSamples - writtenSamples);
}

@Override public int getLatency () {
@Override
public int getLatency () {
return latency;
}
}
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.backends.android;

import android.media.AudioFormat;
Expand All @@ -21,11 +22,8 @@

import com.badlogic.gdx.audio.AudioRecorder;

/**
* {@link AudioRecorder} implementation for the android system based on AudioRecord
* @author badlogicgames@gmail.com
*
*/
/** {@link AudioRecorder} implementation for the android system based on AudioRecord
* @author badlogicgames@gmail.com */
public class AndroidAudioRecorder implements AudioRecorder {
/** the audio track we read samples from **/
private AudioRecord recorder;
Expand All @@ -38,12 +36,14 @@ public AndroidAudioRecorder (int samplingRate, boolean isMono) {
recorder.startRecording();
}

@Override public void dispose () {
@Override
public void dispose () {
recorder.stop();
recorder.release();
}

@Override public void read (short[] samples, int offset, int numSamples) {
@Override
public void read (short[] samples, int offset, int numSamples) {
int read = 0;
while (read != numSamples) {
read += recorder.read(samples, offset + read, numSamples - read);
Expand Down
Expand Up @@ -26,10 +26,8 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;

/**
* @author mzechner
* @author Nathan Sweet
*/
/** @author mzechner
* @author Nathan Sweet */
public class AndroidFileHandle extends FileHandle {
// The asset manager, or null if this is not an internal file.
final AssetManager assets;
Expand Down
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.backends.android;

import android.content.res.AssetManager;
Expand All @@ -21,10 +22,8 @@
import com.badlogic.gdx.Files;
import com.badlogic.gdx.files.FileHandle;

/**
* @author mzechner
* @author Nathan Sweet
*/
/** @author mzechner
* @author Nathan Sweet */
public class AndroidFiles implements Files {
protected final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
protected final AssetManager assets;
Expand All @@ -33,31 +32,38 @@ public AndroidFiles (AssetManager assets) {
this.assets = assets;
}

@Override public FileHandle getFileHandle (String path, FileType type) {
@Override
public FileHandle getFileHandle (String path, FileType type) {
return new AndroidFileHandle(type == FileType.Internal ? assets : null, path, type);
}

@Override public FileHandle classpath (String path) {
@Override
public FileHandle classpath (String path) {
return new AndroidFileHandle(null, path, FileType.Classpath);
}

@Override public FileHandle internal (String path) {
@Override
public FileHandle internal (String path) {
return new AndroidFileHandle(assets, path, FileType.Internal);
}

@Override public FileHandle external (String path) {
@Override
public FileHandle external (String path) {
return new AndroidFileHandle(null, path, FileType.External);
}

@Override public FileHandle absolute (String path) {
@Override
public FileHandle absolute (String path) {
return new AndroidFileHandle(null, path, FileType.Absolute);
}

@Override public String getExternalStoragePath () {
@Override
public String getExternalStoragePath () {
return sdcard;
}

@Override public boolean isExternalStorageAvailable () {
@Override
public boolean isExternalStorageAvailable () {
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}
}

0 comments on commit 2f412de

Please sign in to comment.