* Formatted many android classes and files

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9202 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent 8d9895036b
commit 1aed2068be
  1. 5
      engine/src/android/com/jme3/asset/plugins/AndroidLocator.java
  2. 13
      engine/src/android/com/jme3/audio/plugins/AndroidAudioLoader.java
  3. 19
      engine/src/android/com/jme3/input/android/AndroidInput.java
  4. 11
      engine/src/android/com/jme3/input/android/AndroidTouchInputListener.java
  5. 359
      engine/src/android/com/jme3/system/android/AndroidConfigChooser.java
  6. 5
      engine/src/android/com/jme3/system/android/OGLESContext.java
  7. 16
      engine/src/android/com/jme3/util/AndroidLogHandler.java
  8. 21
      engine/src/android/com/jme3/util/RingBuffer.java
  9. 32
      engine/src/android/res/layout/about.xml
  10. 18
      engine/src/android/res/layout/tests.xml

@ -4,9 +4,6 @@ import com.jme3.asset.*;
import com.jme3.system.android.JmeAndroidSystem;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AndroidLocator implements AssetLocator {
@ -80,7 +77,7 @@ public class AndroidLocator implements AssetLocator {
assetPath = assetPath.replace("//", "/");
try {
return create(manager, key, assetPath);
}catch (IOException ex){
} catch (IOException ex) {
// This is different handling than URL locator
// since classpath locating would return null at the getResource()
// call, otherwise there's a more critical error...

@ -5,15 +5,16 @@ import com.jme3.asset.AssetLoader;
import com.jme3.audio.android.AndroidAudioData;
import java.io.IOException;
public class AndroidAudioLoader implements AssetLoader
{
/**
* <code>AndroidAudioLoader</code> will create an
* {@link AndroidAudioData} object with the specified asset key.
*/
public class AndroidAudioLoader implements AssetLoader {
@Override
public Object load(AssetInfo assetInfo) throws IOException
{
public Object load(AssetInfo assetInfo) throws IOException {
AndroidAudioData result = new AndroidAudioData();
result.setAssetKey( assetInfo.getKey() );
result.setAssetKey(assetInfo.getKey());
return result;
}
}

@ -24,8 +24,11 @@ import java.util.logging.Logger;
* @author larynx
*
*/
public class AndroidInput extends GLSurfaceView implements TouchInput,
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener, ScaleGestureDetector.OnScaleGestureListener {
public class AndroidInput extends GLSurfaceView implements
TouchInput,
GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener,
ScaleGestureDetector.OnScaleGestureListener {
final private static int MAX_EVENTS = 1024;
// Custom settings
@ -164,7 +167,9 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
/**
* Fetches a touch event from the reuse pool
* @param wait if true waits for a reusable event to get available/released by an other thread, if false returns a new one if needed
* @param wait if true waits for a reusable event to get available/released
* by an other thread, if false returns a new one if needed.
*
* @return a usable TouchEvent
*/
private TouchEvent getNextFreeTouchEvent(boolean wait) {
@ -183,7 +188,6 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
}
}
if (evt == null) {
if (eventPool.isEmpty() && wait) {
logger.warning("eventPool buffer underrun");
@ -228,13 +232,9 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
// final int historySize = event.getHistorySize();
//final int pointerCount = event.getPointerCount();
switch (action) {
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_DOWN:
touch = getNextFreeTouchEvent();
touch.set(Type.DOWN, event.getX(pointerIndex), this.getHeight() - event.getY(pointerIndex), 0, 0);
touch.setPointerId(pointerId);
@ -279,8 +279,6 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
}
bWasHandled = true;
break;
case MotionEvent.ACTION_OUTSIDE:
break;
@ -311,7 +309,6 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
} else {
return true;
}
}
@Override

@ -6,14 +6,17 @@ import com.jme3.input.RawInputListener;
import com.jme3.input.event.TouchEvent;
/**
* AndroidTouchInputListener is an inputlistener interface which defines callbacks/events for android touch screens
* For use with class AndroidInput
* AndroidTouchInputListener is an inputlistener interface which defines
* callbacks/events for android touch screens For use with class AndroidInput
*
* @author larynx
*
*/
public interface AndroidTouchInputListener extends RawInputListener
{
public interface AndroidTouchInputListener extends RawInputListener {
public void onTouchEvent(TouchEvent evt);
public void onMotionEvent(MotionEvent evt);
public void onAndroidKeyEvent(KeyEvent evt);
}

@ -2,6 +2,7 @@ package com.jme3.system.android;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@ -9,26 +10,23 @@ import javax.microedition.khronos.egl.EGLDisplay;
/**
* AndroidConfigChooser is used to determine the best suited EGL Config
* @author larynx
*
* @author larynx
*/
public class AndroidConfigChooser implements EGLConfigChooser
{
public class AndroidConfigChooser implements EGLConfigChooser {
private static final Logger logger = Logger.getLogger(AndroidConfigChooser.class.getName());
protected int clientOpenGLESVersion = 0;
protected EGLConfig bestConfig = null;
protected EGLConfig fastestConfig = null;
protected EGLConfig choosenConfig = null;
protected ConfigType type;
protected int pixelFormat;
protected boolean verbose = false;
private final static int EGL_OPENGL_ES2_BIT = 4;
public enum ConfigType
{
public enum ConfigType {
/**
* RGB565, 0 alpha, 16 depth, 0 stencil
*/
@ -39,94 +37,79 @@ public class AndroidConfigChooser implements EGLConfigChooser
BEST,
/**
* Turn off config chooser and use hardcoded
* setEGLContextClientVersion(2);
* setEGLConfigChooser(5, 6, 5, 0, 16, 0);
* setEGLContextClientVersion(2); setEGLConfigChooser(5, 6, 5, 0, 16,
* 0);
*/
LEGACY
}
public AndroidConfigChooser(ConfigType type, boolean verbose)
{
public AndroidConfigChooser(ConfigType type) {
this.type = type;
this.verbose = verbose;
}
/**
* Gets called by the GLSurfaceView class to return the best config
*/
*/
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
logger.info("GLSurfaceView asks for egl config, returning: ");
logEGLConfig(choosenConfig, display, egl);
return choosenConfig;
}
/**
* findConfig is used to locate the best config and init the chooser with
*
* @param egl
* @param display
* @return true if successfull, false if no config was found
*/
public boolean findConfig(EGL10 egl, EGLDisplay display)
{
if (type == ConfigType.BEST)
{
ComponentSizeChooser compChooser = new ComponentSizeChooser(8, 8, 8, 8, 32, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
public boolean findConfig(EGL10 egl, EGLDisplay display) {
if (type == ConfigType.BEST) {
ComponentSizeChooser compChooser = new ComponentSizeChooser(8, 8, 8, 8, 32, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
if (choosenConfig == null)
{
if (choosenConfig == null) {
compChooser = new ComponentSizeChooser(8, 8, 8, 0, 32, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
if (choosenConfig == null)
{
if (choosenConfig == null) {
compChooser = new ComponentSizeChooser(8, 8, 8, 8, 16, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
if (choosenConfig == null)
{
if (choosenConfig == null) {
compChooser = new ComponentSizeChooser(8, 8, 8, 0, 16, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
}
}
}
}
logger.info("JME3 using best EGL configuration available here: ");
}
else
{
ComponentSizeChooser compChooser = new ComponentSizeChooser(5, 6, 5, 0, 16, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
} else {
ComponentSizeChooser compChooser = new ComponentSizeChooser(5, 6, 5, 0, 16, 0);
choosenConfig = compChooser.chooseConfig(egl, display);
logger.info("JME3 using fastest EGL configuration available here: ");
}
if (choosenConfig != null)
{
logger.info("JME3 using choosen config: ");
logEGLConfig(choosenConfig, display, egl);
if (choosenConfig != null) {
logger.info("JME3 using choosen config: ");
logEGLConfig(choosenConfig, display, egl);
pixelFormat = getPixelFormat(choosenConfig, display, egl);
clientOpenGLESVersion = getOpenGLVersion(choosenConfig, display, egl);
return true;
}
else
{
} else {
logger.severe("###ERROR### Unable to get a valid OpenGL ES 2.0 config, nether Fastest nor Best found! Bug. Please report this.");
clientOpenGLESVersion = 1;
pixelFormat = PixelFormat.UNKNOWN;
return false;
}
}
}
private int getPixelFormat(EGLConfig conf, EGLDisplay display, EGL10 egl)
{
private int getPixelFormat(EGLConfig conf, EGLDisplay display, EGL10 egl) {
int[] value = new int[1];
int result = PixelFormat.RGB_565;
int result = PixelFormat.RGB_565;
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RED_SIZE, value);
if (value[0] == 8)
{
if (value[0] == 8) {
result = PixelFormat.RGBA_8888;
/*
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_ALPHA_SIZE, value);
@ -139,165 +122,163 @@ public class AndroidConfigChooser implements EGLConfigChooser
result = PixelFormat.RGB_888;
}*/
}
if (verbose)
{
logger.info("Using PixelFormat " + result);
if (verbose) {
logger.log(Level.INFO, "Using PixelFormat {0}", result);
}
//return result; TODO Test pixelformat
return PixelFormat.TRANSPARENT;
}
private int getOpenGLVersion(EGLConfig conf, EGLDisplay display, EGL10 egl)
{
private int getOpenGLVersion(EGLConfig conf, EGLDisplay display, EGL10 egl) {
int[] value = new int[1];
int result = 1;
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RENDERABLE_TYPE, value);
// Check if conf is OpenGL ES 2.0
if ((value[0] & EGL_OPENGL_ES2_BIT) != 0)
{
if ((value[0] & EGL_OPENGL_ES2_BIT) != 0) {
result = 2;
}
return result;
return result;
}
/**
* log output with egl config details
*
* @param conf
* @param display
* @param egl
*/
public void logEGLConfig(EGLConfig conf, EGLDisplay display, EGL10 egl)
{
public void logEGLConfig(EGLConfig conf, EGLDisplay display, EGL10 egl) {
int[] value = new int[1];
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RED_SIZE, value);
logger.info(String.format("EGL_RED_SIZE = %d", value[0] ) );
logger.info(String.format("EGL_RED_SIZE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_GREEN_SIZE, value);
logger.info(String.format("EGL_GREEN_SIZE = %d", value[0] ) );
logger.info(String.format("EGL_GREEN_SIZE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_BLUE_SIZE, value);
logger.info(String.format("EGL_BLUE_SIZE = %d", value[0] ) );
logger.info(String.format("EGL_BLUE_SIZE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_ALPHA_SIZE, value);
logger.info(String.format("EGL_ALPHA_SIZE = %d", value[0] ) );
logger.info(String.format("EGL_ALPHA_SIZE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_DEPTH_SIZE, value);
logger.info(String.format("EGL_DEPTH_SIZE = %d", value[0] ) );
logger.info(String.format("EGL_DEPTH_SIZE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_STENCIL_SIZE, value);
logger.info(String.format("EGL_STENCIL_SIZE = %d", value[0] ) );
logger.info(String.format("EGL_STENCIL_SIZE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RENDERABLE_TYPE, value);
logger.info(String.format("EGL_RENDERABLE_TYPE = %d", value[0] ) );
logger.info(String.format("EGL_RENDERABLE_TYPE = %d", value[0]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_SURFACE_TYPE, value);
logger.info(String.format("EGL_SURFACE_TYPE = %d", value[0] ) );
logger.info(String.format("EGL_SURFACE_TYPE = %d", value[0]));
}
public int getClientOpenGLESVersion()
{
public int getClientOpenGLESVersion() {
return clientOpenGLESVersion;
}
public void setClientOpenGLESVersion(int clientOpenGLESVersion)
{
public void setClientOpenGLESVersion(int clientOpenGLESVersion) {
this.clientOpenGLESVersion = clientOpenGLESVersion;
}
public int getPixelFormat()
{
public int getPixelFormat() {
return pixelFormat;
}
private abstract class BaseConfigChooser implements EGLConfigChooser
{
private abstract class BaseConfigChooser implements EGLConfigChooser {
private boolean bClientOpenGLESVersionSet;
public BaseConfigChooser(int[] configSpec)
{
bClientOpenGLESVersionSet = false;
mConfigSpec = filterConfigSpec(configSpec);
}
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
int[] num_config = new int[1];
if (!egl.eglChooseConfig(display, mConfigSpec, null, 0,
num_config)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
int numConfigs = num_config[0];
if (numConfigs <= 0)
{
//throw new IllegalArgumentException("No configs match configSpec");
return null;
}
EGLConfig[] configs = new EGLConfig[numConfigs];
if (!egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs,
num_config)) {
throw new IllegalArgumentException("eglChooseConfig#2 failed");
}
EGLConfig config = chooseConfig(egl, display, configs);
//if (config == null) {
// throw new IllegalArgumentException("No config chosen");
//}
return config;
}
abstract EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs);
protected int[] mConfigSpec;
private int[] filterConfigSpec(int[] configSpec)
{
if (bClientOpenGLESVersionSet == true) {
return configSpec;
}
/* We know none of the subclasses define EGL_RENDERABLE_TYPE.
* And we know the configSpec is well formed.
*/
int len = configSpec.length;
int[] newConfigSpec = new int[len + 2];
System.arraycopy(configSpec, 0, newConfigSpec, 0, len-1);
newConfigSpec[len-1] = EGL10.EGL_RENDERABLE_TYPE;
newConfigSpec[len] = 4; /* EGL_OPENGL_ES2_BIT */
newConfigSpec[len+1] = EGL10.EGL_NONE;
bClientOpenGLESVersionSet = true;
return newConfigSpec;
}
public BaseConfigChooser(int[] configSpec) {
bClientOpenGLESVersionSet = false;
mConfigSpec = filterConfigSpec(configSpec);
}
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] num_config = new int[1];
if (!egl.eglChooseConfig(display, mConfigSpec, null, 0,
num_config)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
int numConfigs = num_config[0];
if (numConfigs <= 0) {
//throw new IllegalArgumentException("No configs match configSpec");
return null;
}
EGLConfig[] configs = new EGLConfig[numConfigs];
if (!egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs,
num_config)) {
throw new IllegalArgumentException("eglChooseConfig#2 failed");
}
EGLConfig config = chooseConfig(egl, display, configs);
//if (config == null) {
// throw new IllegalArgumentException("No config chosen");
//}
return config;
}
abstract EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs);
protected int[] mConfigSpec;
private int[] filterConfigSpec(int[] configSpec) {
if (bClientOpenGLESVersionSet == true) {
return configSpec;
}
/*
* We know none of the subclasses define EGL_RENDERABLE_TYPE. And we
* know the configSpec is well formed.
*/
int len = configSpec.length;
int[] newConfigSpec = new int[len + 2];
System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1);
newConfigSpec[len - 1] = EGL10.EGL_RENDERABLE_TYPE;
newConfigSpec[len] = 4; /*
* EGL_OPENGL_ES2_BIT
*/
newConfigSpec[len + 1] = EGL10.EGL_NONE;
bClientOpenGLESVersionSet = true;
return newConfigSpec;
}
}
/**
* Choose a configuration with exactly the specified r,g,b,a sizes,
* and at least the specified depth and stencil sizes.
* Choose a configuration with exactly the specified r,g,b,a sizes, and at
* least the specified depth and stencil sizes.
*/
private class ComponentSizeChooser extends BaseConfigChooser
{
private class ComponentSizeChooser extends BaseConfigChooser {
private int[] mValue;
// Subclasses can adjust these values:
protected int mRedSize;
protected int mGreenSize;
protected int mBlueSize;
protected int mAlphaSize;
protected int mDepthSize;
protected int mStencilSize;
public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize)
{
super(new int[] {
EGL10.EGL_RED_SIZE, redSize,
EGL10.EGL_GREEN_SIZE, greenSize,
EGL10.EGL_BLUE_SIZE, blueSize,
EGL10.EGL_ALPHA_SIZE, alphaSize,
EGL10.EGL_DEPTH_SIZE, depthSize,
EGL10.EGL_STENCIL_SIZE, stencilSize,
EGL10.EGL_NONE});
int alphaSize, int depthSize, int stencilSize) {
super(new int[]{
EGL10.EGL_RED_SIZE, redSize,
EGL10.EGL_GREEN_SIZE, greenSize,
EGL10.EGL_BLUE_SIZE, blueSize,
EGL10.EGL_ALPHA_SIZE, alphaSize,
EGL10.EGL_DEPTH_SIZE, depthSize,
EGL10.EGL_STENCIL_SIZE, stencilSize,
EGL10.EGL_NONE});
mValue = new int[1];
mRedSize = redSize;
mGreenSize = greenSize;
@ -305,25 +286,22 @@ public class AndroidConfigChooser implements EGLConfigChooser
mAlphaSize = alphaSize;
mDepthSize = depthSize;
mStencilSize = stencilSize;
}
}
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs)
{
for (EGLConfig config : configs)
{
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
for (EGLConfig config : configs) {
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
if ((d >= mDepthSize) && (s >= mStencilSize))
{
if ((d >= mDepthSize) && (s >= mStencilSize)) {
int r = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
if ((r == mRedSize) && (g == mGreenSize)
@ -336,27 +314,12 @@ public class AndroidConfigChooser implements EGLConfigChooser
}
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue)
{
EGLConfig config, int attribute, int defaultValue) {
if (egl.eglGetConfigAttrib(display, config, attribute, mValue))
{
if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
return mValue[0];
}
return defaultValue;
}
private int[] mValue;
// Subclasses can adjust these values:
protected int mRedSize;
protected int mGreenSize;
protected int mBlueSize;
protected int mAlphaSize;
protected int mDepthSize;
protected int mStencilSize;
}
}

@ -52,6 +52,7 @@ import com.jme3.system.SystemListener;
import com.jme3.system.Timer;
import com.jme3.system.android.AndroidConfigChooser.ConfigType;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@ -145,12 +146,12 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer {
int[] version = new int[2];
if (egl.eglInitialize(display, version) == true) {
logger.info("Display EGL Version: " + version[0] + "." + version[1]);
logger.log(Level.INFO, "Display EGL Version: {0}.{1}", new Object[]{version[0], version[1]});
}
try {
// Create a config chooser
AndroidConfigChooser configChooser = new AndroidConfigChooser(configType, eglConfigVerboseLogging);
AndroidConfigChooser configChooser = new AndroidConfigChooser(configType);
// Init chooser
if (!configChooser.findConfig(egl, display)) {
listener.handleError("Unable to find suitable EGL config", null);

@ -4,7 +4,12 @@ import android.util.Log;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* Converts from Java based logging ({@link Logger} to Android based
* logging {@link Log}.
*/
public class AndroidLogHandler extends Handler {
@Override
@ -21,17 +26,16 @@ public class AndroidLogHandler extends Handler {
String clsName = record.getSourceClassName();
String msg = record.getMessage();
Throwable t = record.getThrown();
if (level == Level.INFO){
if (level == Level.INFO) {
Log.i(clsName, msg, t);
}else if (level == Level.SEVERE){
} else if (level == Level.SEVERE) {
Log.e(clsName, msg, t);
}else if (level == Level.WARNING){
} else if (level == Level.WARNING) {
Log.w(clsName, msg, t);
}else if (level == Level.CONFIG){
} else if (level == Level.CONFIG) {
Log.d(clsName, msg, t);
}else if (level == Level.FINE || level == Level.FINER || level == Level.FINEST){
} else if (level == Level.FINE || level == Level.FINER || level == Level.FINEST) {
Log.v(clsName, msg, t);
}
}
}

@ -4,20 +4,21 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Ring buffer (fixed size queue) implementation using a circular array (array with wrap-around).
* Ring buffer (fixed size queue) implementation using a circular array (array
* with wrap-around).
*/
// suppress unchecked warnings in Java 1.5.0_6 and later
@SuppressWarnings("unchecked")
public class RingBuffer<Item> implements Iterable<Item> {
public class RingBuffer<T> implements Iterable<T> {
private Item[] buffer; // queue elements
private T[] buffer; // queue elements
private int count = 0; // number of elements on queue
private int indexOut = 0; // index of first element of queue
private int indexIn = 0; // index of next available slot
// cast needed since no generic array creation in Java
public RingBuffer(int capacity) {
buffer = (Item[]) new Object[capacity];
buffer = (T[]) new Object[capacity];
}
public boolean isEmpty() {
@ -28,7 +29,7 @@ public class RingBuffer<Item> implements Iterable<Item> {
return count;
}
public void push(Item item) {
public void push(T item) {
if (count == buffer.length) {
throw new RuntimeException("Ring buffer overflow");
}
@ -37,23 +38,23 @@ public class RingBuffer<Item> implements Iterable<Item> {
count++;
}
public Item pop() {
public T pop() {
if (isEmpty()) {
throw new RuntimeException("Ring buffer underflow");
}
Item item = buffer[indexOut];
T item = buffer[indexOut];
buffer[indexOut] = null; // to help with garbage collection
count--;
indexOut = (indexOut + 1) % buffer.length; // wrap-around
return item;
}
public Iterator<Item> iterator() {
public Iterator<T> iterator() {
return new RingBufferIterator();
}
// an iterator, doesn't implement remove() since it's optional
private class RingBufferIterator implements Iterator<Item> {
private class RingBufferIterator implements Iterator<T> {
private int i = 0;
@ -65,7 +66,7 @@ public class RingBuffer<Item> implements Iterable<Item> {
throw new UnsupportedOperationException();
}
public Item next() {
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}

@ -1,29 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/buttonsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/buttonsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="copyright (c) 2009-2010 JMonkeyEngine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="copyright (c) 2009-2010 JMonkeyEngine"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="http://www.jmonkeyengine.org"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="http://www.jmonkeyengine.org"
/>
</LinearLayout>

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/buttonsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@+id/buttonsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--
<Button
android:id="@+id/SimpleTextured"

Loading…
Cancel
Save