Skip to content

Commit

Permalink
Make Android backend hide unnecessary things
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharshachilakapati committed Jan 11, 2017
1 parent 3ff2e9a commit d2ffc6c
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidDirectBuffer extends DirectBuffer
class AndroidDirectBuffer extends DirectBuffer
{
private ByteBuffer nativeBuffer;

public AndroidDirectBuffer(ByteBuffer buffer)
AndroidDirectBuffer(ByteBuffer buffer)
{
super(buffer.capacity());
nativeBuffer = buffer;
}

public AndroidDirectBuffer(int sizeInBytes)
AndroidDirectBuffer(int sizeInBytes)
{
super(sizeInBytes);
nativeBuffer = ByteBuffer.allocateDirect(sizeInBytes).order(ByteOrder.nativeOrder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import android.content.pm.ActivityInfo;
import android.graphics.Point;
import android.opengl.GLSurfaceView;
import android.os.SystemClock;
import com.shc.silenceengine.core.IDisplayDevice;
import com.shc.silenceengine.core.SilenceEngine;
Expand All @@ -38,18 +37,16 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidDisplayDevice implements IDisplayDevice
class AndroidDisplayDevice implements IDisplayDevice
{
public GLSurfaceView surfaceView;
public AndroidLauncher activity;
private AndroidLauncher activity;

private double startTime;

public AndroidDisplayDevice()
AndroidDisplayDevice()
{
this.startTime = SystemClock.elapsedRealtimeNanos();
this.activity = AndroidLauncher.instance;
this.surfaceView = activity.surfaceView;

setSize(800, 600);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidExternalFilePath extends AndroidFilePath
class AndroidExternalFilePath extends AndroidFilePath
{
private File file;

public AndroidExternalFilePath(String path)
AndroidExternalFilePath(String path)
{
super(path, Type.EXTERNAL);
file = new File(Environment.getExternalStorageDirectory(), getPath());
Expand Down Expand Up @@ -126,23 +126,21 @@ public Promise<Void> mkdirs()
public Promise<Void> createFile()
{
return new Promise<>((resolve, reject) ->
{
isDirectory().then(isDirectory ->
{
if (isDirectory)
throw new SilenceException("Cannot convert a directory to a file");

try
{
file.createNewFile();
resolve.invoke(null);
}
catch (IOException e)
isDirectory().then(isDirectory ->
{
reject.invoke(e);
}
});
});
if (isDirectory)
throw new SilenceException("Cannot convert a directory to a file");

try
{
file.createNewFile();
resolve.invoke(null);
}
catch (IOException e)
{
reject.invoke(e);
}
}));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
/**
* @author Sri Harsha Chilakapati
*/
public abstract class AndroidFilePath extends FilePath
abstract class AndroidFilePath extends FilePath
{
/**
* Constructs an instance of FilePath by taking a path string, and a type.
*
* @param path The path string of the path
* @param type The type of the file, one of {@link Type#EXTERNAL} or {@link Type#RESOURCE}.
*/
protected AndroidFilePath(String path, Type type)
AndroidFilePath(String path, Type type)
{
super(path, type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidFileReader extends FileReader
class AndroidFileReader extends FileReader
{
@Override
public void readBinaryFile(FilePath file, UniCallback<DirectBuffer> onComplete, UniCallback<Throwable> onError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidFileWriter extends FileWriter
class AndroidFileWriter extends FileWriter
{
@Override
public void write(String text, FilePath file, boolean append, SimpleCallback onSuccess, UniCallback<Throwable> onError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* @author Sri Harsha Chilakapti
*/
public class AndroidGraphicsDevice implements IGraphicsDevice
class AndroidGraphicsDevice implements IGraphicsDevice
{
@Override
public int glGenBuffers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidIODevice implements IODevice
class AndroidIODevice implements IODevice
{
private FileReader fileReader = new AndroidFileReader();
private FileWriter fileWriter = new AndroidFileWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidImageReader extends ImageReader
class AndroidImageReader extends ImageReader
{
private static int calculateInSampleSize(BitmapFactory.Options options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import com.shc.silenceengine.core.SilenceEngine;
import com.shc.silenceengine.input.InputDevice;

import java.util.HashMap;
Expand All @@ -41,15 +40,15 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidInputDevice extends InputDevice
class AndroidInputDevice extends InputDevice
{
private static Map<Integer, Integer> keyMap;

private GLSurfaceView surfaceView;

public AndroidInputDevice()
AndroidInputDevice()
{
surfaceView = ((AndroidDisplayDevice) SilenceEngine.display).surfaceView;
surfaceView = AndroidLauncher.instance.surfaceView;
surfaceView.setOnKeyListener(this::onKey);
surfaceView.setOnTouchListener(this::onTouch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
*/
public abstract class AndroidLauncher extends Activity
{
public static AndroidLauncher instance;
static AndroidLauncher instance;

public GLSurfaceView surfaceView;
public AndroidWindow renderer;
GLSurfaceView surfaceView;
AndroidWindow renderer;

@Override
protected void onCreate(Bundle savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidLogDevice implements ILogDevice
class AndroidLogDevice implements ILogDevice
{
private Logger rootLogger = new AndroidLogger("SilenceEngine");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidLogger extends Logger
class AndroidLogger extends Logger
{
public AndroidLogger(String name)
AndroidLogger(String name)
{
super(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import com.shc.silenceengine.core.SilenceEngine;
import com.shc.silenceengine.core.SilenceException;
import com.shc.silenceengine.io.FilePath;
import com.shc.silenceengine.utils.functional.Promise;
Expand All @@ -41,14 +40,14 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidResourceFilePath extends AndroidFilePath
class AndroidResourceFilePath extends AndroidFilePath
{
private AssetManager assetManager;

public AndroidResourceFilePath(String path)
AndroidResourceFilePath(String path)
{
super(path, Type.RESOURCE);
assetManager = ((AndroidDisplayDevice) SilenceEngine.display).activity.getAssets();
assetManager = AndroidLauncher.instance.getAssets();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
*/
public final class AndroidRuntime
{
public static Game game;

private AndroidRuntime()
{
}
Expand All @@ -54,8 +52,6 @@ public static void start(Game game)
SilenceEngine.display = new AndroidDisplayDevice();
SilenceEngine.input = new AndroidInputDevice();

AndroidRuntime.game = game;

// Notify the game loop that we got focus
SilenceEngine.gameLoop.onFocusGain();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AndroidWindow implements GLSurfaceView.Renderer
class AndroidWindow implements GLSurfaceView.Renderer
{
public SimpleCallback loopFrame;
public SimpleCallback resized;
SimpleCallback loopFrame;
SimpleCallback resized;

private SimpleCallback startCallback;

public AndroidWindow(SimpleCallback startCallback)
AndroidWindow(SimpleCallback startCallback)
{
this.startCallback = startCallback;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
/**
* @author Sri Harsha Chilakapati
*/
public class AsyncRunner extends AsyncTask<Provider<SimpleCallback>, Void, SimpleCallback>
class AsyncRunner extends AsyncTask<Provider<SimpleCallback>, Void, SimpleCallback>
{
private static List<AsyncRunner> runners = Collections.synchronizedList(new ArrayList<>());

@SuppressWarnings({"unchecked"})
public static void runAsync(Provider<SimpleCallback> callback)
static void runAsync(Provider<SimpleCallback> callback)
{
runners.add((AsyncRunner) new AsyncRunner().execute(callback));
}

public static void cancelAll()
static void cancelAll()
{
for (AsyncRunner runner : runners)
runner.cancel(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static short readUnsignedShortLittleEndian(DataInputStream is) throws IO

private void loadFromStreamImpl(InputStream aIn) throws IOException
{
/**
/*
* references:
* http://www.sonicspot.com/guide/wavefiles.html
* https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
Expand Down Expand Up @@ -111,7 +111,7 @@ private void loadFromStreamImpl(InputStream aIn) throws IOException

short sChannels = 0, sSampleSizeInBits = 0;
long sampleRate = 0;
long chunkLength = 0;
long chunkLength;

while (!foundData)
{
Expand Down

0 comments on commit d2ffc6c

Please sign in to comment.