refactor backend Adapter classes
This commit is contained in:
parent
4e4d4270db
commit
4fb3d13404
@ -35,6 +35,10 @@ import android.graphics.drawable.Drawable;
|
||||
public final class AndroidGraphics extends CanvasAdapter {
|
||||
public static final AndroidGraphics INSTANCE = new AndroidGraphics();
|
||||
|
||||
public static void init() {
|
||||
g = INSTANCE;
|
||||
}
|
||||
|
||||
// public static android.graphics.Bitmap getAndroidBitmap(Bitmap bitmap) {
|
||||
// return ((AndroidBitmap) bitmap).bitmap;
|
||||
// }
|
||||
|
@ -17,7 +17,6 @@
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.android.canvas.AndroidGraphics;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
@ -40,8 +39,8 @@ public class MainActivity extends AndroidApplication {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
||||
GLAdapter.g = new AndroidGLAdapter();
|
||||
AndroidGraphics.init();
|
||||
GLAdapter.init(new AndroidGLAdapter());
|
||||
|
||||
// TODO make this dpi dependent
|
||||
Tile.SIZE = 400;
|
||||
|
@ -23,10 +23,14 @@ import org.oscim.backend.AssetAdapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class AndroidAssetAdapter extends AssetAdapter {
|
||||
public class AndroidAssets extends AssetAdapter {
|
||||
Context mContext;
|
||||
|
||||
public AndroidAssetAdapter(Context ctx) {
|
||||
public static void init(Context ctx) {
|
||||
g = new AndroidAssets(ctx);
|
||||
}
|
||||
|
||||
private AndroidAssets(Context ctx) {
|
||||
mContext = ctx;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package org.oscim.android;
|
||||
import org.oscim.android.canvas.AndroidGraphics;
|
||||
import org.oscim.android.gl.AndroidGL;
|
||||
import org.oscim.android.input.AndroidMotionEvent;
|
||||
import org.oscim.backend.AssetAdapter;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.event.Gesture;
|
||||
@ -58,9 +57,9 @@ public class MapView extends RelativeLayout {
|
||||
public MapView(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
|
||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
||||
AssetAdapter.g = new AndroidAssetAdapter(context);
|
||||
GLAdapter.g = new AndroidGL();
|
||||
AndroidGraphics.init();
|
||||
AndroidAssets.init(context);
|
||||
GLAdapter.init(new AndroidGL());
|
||||
|
||||
this.setWillNotDraw(true);
|
||||
this.setClickable(true);
|
||||
|
@ -32,7 +32,10 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public final class AndroidGraphics extends CanvasAdapter {
|
||||
public static final AndroidGraphics INSTANCE = new AndroidGraphics();
|
||||
|
||||
public static void init() {
|
||||
g = new AndroidGraphics();
|
||||
}
|
||||
|
||||
public static android.graphics.Paint getAndroidPaint(Paint paint) {
|
||||
return ((AndroidPaint) paint).mPaint;
|
||||
@ -97,7 +100,6 @@ public final class AndroidGraphics extends CanvasAdapter {
|
||||
return new MarkerSymbol(drawableToBitmap(drawable), place);
|
||||
}
|
||||
|
||||
|
||||
public static MarkerSymbol makeMarker(Resources res, int resId, HotspotPlace place) {
|
||||
if (place == null)
|
||||
place = HotspotPlace.CENTER;
|
||||
|
@ -32,8 +32,8 @@ import org.oscim.backend.canvas.Paint;
|
||||
public class AwtGraphics extends CanvasAdapter {
|
||||
private static final AwtGraphics INSTANCE = new AwtGraphics();
|
||||
|
||||
public static final AwtGraphics get() {
|
||||
return INSTANCE;
|
||||
public static void init() {
|
||||
g = INSTANCE;
|
||||
}
|
||||
|
||||
private AwtGraphics() {
|
||||
|
@ -17,7 +17,6 @@
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.awt.AwtGraphics;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.TileSource;
|
||||
@ -33,21 +32,13 @@ public class GdxMapApp extends GdxMap {
|
||||
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
||||
}
|
||||
|
||||
// wrap LwjglGL20 to add GL20 interface
|
||||
// static class GdxGL extends GdxGL20 {
|
||||
// @Override
|
||||
// public void glGetShaderSource(int shader, int bufsize, Buffer length, String source) {
|
||||
// throw new IllegalArgumentException("not implemented");
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void init() {
|
||||
// load native library
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
// init globals
|
||||
CanvasAdapter.g = AwtGraphics.get();
|
||||
GLAdapter.g = new GdxGL20();
|
||||
|
||||
AwtGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new GdxGL20());
|
||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||
}
|
||||
|
||||
@ -70,7 +61,6 @@ public class GdxMapApp extends GdxMap {
|
||||
static protected LwjglApplicationConfiguration getConfig() {
|
||||
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
|
||||
cfg.title = "vtm-gdx";
|
||||
//cfg.useGL20 = true;
|
||||
cfg.width = 1280;
|
||||
cfg.height = 800;
|
||||
cfg.stencil = 8;
|
||||
|
@ -24,11 +24,16 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
|
||||
public class GdxAssetAdapter extends AssetAdapter {
|
||||
public class GdxAssets extends AssetAdapter {
|
||||
static String pathPrefix = "";
|
||||
|
||||
private GdxAssets(String path) {
|
||||
pathPrefix = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openFileAsStream(String fileName) {
|
||||
FileHandle file = Gdx.files.internal("assets/" + fileName);
|
||||
FileHandle file = Gdx.files.internal(pathPrefix + fileName);
|
||||
if (file == null)
|
||||
throw new IllegalArgumentException("missing file " + fileName);
|
||||
|
||||
@ -39,4 +44,8 @@ public class GdxAssetAdapter extends AssetAdapter {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(String path) {
|
||||
g = new GdxAssets(path);
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.backend.AssetAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
@ -51,7 +50,6 @@ public abstract class GdxMap implements ApplicationListener {
|
||||
boolean mRenderRequest;
|
||||
|
||||
public GdxMap() {
|
||||
AssetAdapter.g = new GdxAssetAdapter();
|
||||
|
||||
mMap = new Map() {
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.oscim.ios;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.ios.backend.IosGLAdapter;
|
||||
@ -50,8 +49,8 @@ public class RobovmLauncher extends IOSApplication.Delegate {
|
||||
|
||||
NSAutoreleasePool pool = new NSAutoreleasePool();
|
||||
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
||||
CanvasAdapter.g = IosGraphics.get();
|
||||
GLAdapter.g = new IosGLAdapter();
|
||||
IosGraphics.init();
|
||||
GLAdapter.init(new IosGLAdapter());
|
||||
|
||||
UIApplication.main(argv, null, RobovmLauncher.class);
|
||||
pool.drain();
|
||||
|
@ -16,6 +16,10 @@ public class IosGraphics extends CanvasAdapter {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
g = INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Canvas getCanvas() {
|
||||
return new IosCanvas();
|
||||
|
@ -22,7 +22,7 @@ public class GLAdapter {
|
||||
public final static boolean debugView = false;
|
||||
|
||||
/** The instance provided by backend */
|
||||
public static GL20 g;
|
||||
private static GL20 g;
|
||||
|
||||
public static boolean GDX_DESKTOP_QUIRKS;
|
||||
public static boolean GDX_WEBGL_QUIRKS;
|
||||
@ -35,4 +35,8 @@ public class GLAdapter {
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
public static void init(GL20 gl20) {
|
||||
g = gl20;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user