Blah Blah

This commit is contained in:
Alexey Pelykh 2014-12-09 18:39:44 +02:00
parent 30037c5590
commit 9910e07a68
5 changed files with 108 additions and 26 deletions

View file

@ -1,5 +1,6 @@
package net.osmand.map; package net.osmand.map;
import java.io.IOException;
public interface ITileSource { public interface ITileSource {
@ -11,6 +12,8 @@ public interface ITileSource {
public String getUrlToLoad(int x, int y, int zoom); public String getUrlToLoad(int x, int y, int zoom);
public byte[] getBytes(int x, int y, int zoom) throws IOException;
public int getMinimumZoomSupported(); public int getMinimumZoomSupported();
public String getTileFormat(); public String getTileFormat();

View file

@ -239,8 +239,8 @@ public class CoreResourcesFromAndroidAssetsCustom extends interface_ICoreResourc
} }
System.out.println(resourceEntry.defaultVariant.path.getAbsolutePath()); System.out.println(resourceEntry.defaultVariant.path.getAbsolutePath());
final SWIGTYPE_p_QByteArray bt; final SWIGTYPE_p_QByteArray bt;
if (resourceEntry.defaultVariant.offset == 0 && if (resourceEntry.defaultVariant.offset == 0
resourceEntry.defaultVariant.size == resourceEntry.defaultVariant.path.length()) { && resourceEntry.defaultVariant.size == resourceEntry.defaultVariant.path.length()) {
bt = SwigUtilities.readEntireFile(resourceEntry.defaultVariant.path.getAbsolutePath()); bt = SwigUtilities.readEntireFile(resourceEntry.defaultVariant.path.getAbsolutePath());
} else { } else {
bt = SwigUtilities.readPartOfFile(resourceEntry.defaultVariant.path.getAbsolutePath(), bt = SwigUtilities.readPartOfFile(resourceEntry.defaultVariant.path.getAbsolutePath(),

View file

@ -0,0 +1,57 @@
package net.osmand.core.android;
import java.io.IOException;
import net.osmand.core.jni.AlphaChannelPresence;
import net.osmand.core.jni.SWIGTYPE_p_QByteArray;
import net.osmand.core.jni.SwigUtilities;
import net.osmand.core.jni.TileId;
import net.osmand.core.jni.ZoomLevel;
import net.osmand.core.jni.interface_ImageMapLayerProvider;
import net.osmand.map.ITileSource;
public class TileSourceProxyProvider extends interface_ImageMapLayerProvider {
private final ITileSource tileSource;
public TileSourceProxyProvider(ITileSource tileSource) {
this.tileSource = tileSource;
}
@Override
public ZoomLevel getMinZoom() {
return ZoomLevel.swigToEnum(tileSource.getMinimumZoomSupported());
}
@Override
public ZoomLevel getMaxZoom() {
return ZoomLevel.swigToEnum(tileSource.getMaximumZoomSupported());
}
@Override
public SWIGTYPE_p_QByteArray obtainImage(TileId tileId, ZoomLevel zoom) {
byte[] image;
try {
image = tileSource.getBytes(tileId.getX(), tileId.getY(), zoom.swigValue());
} catch(IOException e) {
return SwigUtilities.emptyQByteArray();
}
return SwigUtilities.createQByteArrayAsCopyOf(image);
}
@Override
public long getTileSize() {
return tileSource.getTileSize();
}
@Override
public float getTileDensityFactor() {
return 1.0f;
}
@Override
public AlphaChannelPresence getAlphaChannelPresence() {
return AlphaChannelPresence.Unknown;
}
}

View file

@ -262,7 +262,7 @@ public class SQLiteTileSource implements ITileSource {
return db.isDbLockedByOtherThreads(); return db.isDbLockedByOtherThreads();
} }
public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) { public byte[] getBytes(int x, int y, int zoom, long[] timeHolder) throws IOException {
SQLiteConnection db = getDatabase(); SQLiteConnection db = getDatabase();
if(db == null){ if(db == null){
return null; return null;
@ -283,6 +283,33 @@ public class SQLiteTileSource implements ITileSource {
} }
} }
cursor.close(); cursor.close();
return blob;
}
return null;
} finally {
if(log.isDebugEnabled()) {
log.debug("Load tile " + x + "/" + y + "/" + zoom + " for " + (System.currentTimeMillis() - ts)
+ " ms ");
}
}
}
public byte[] getBytes(int x, int y, int zoom) throws IOException {
return getBytes(x, y, zoom, null);
}
public Bitmap getImage(int x, int y, int zoom, long[] timeHolder) {
SQLiteConnection db = getDatabase();
if(db == null){
return null;
}
String[] params = new String[] { x + "", y + "", getFileZoom(zoom) + "" };
byte[] blob;
try {
blob = getBytes(x, y, zoom, timeHolder);
} catch (IOException e) {
return null;
}
if (blob != null) { if (blob != null) {
Bitmap bmp = null; Bitmap bmp = null;
bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length); bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
@ -292,14 +319,7 @@ public class SQLiteTileSource implements ITileSource {
} }
return bmp; return bmp;
} }
}
return null; return null;
} finally {
if(log.isDebugEnabled()) {
log.debug("Load tile " + x + "/" + y + "/" + zoom + " for " + (System.currentTimeMillis() - ts)
+ " ms ");
}
}
} }
public ITileSource getBase() { public ITileSource getBase() {

View file

@ -12,6 +12,7 @@ import net.osmand.plus.R;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import android.annotation.SuppressLint;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
@ -110,6 +111,7 @@ public class MapTileLayer extends BaseMapLayer {
return mapTileAdapter; return mapTileAdapter;
} }
@SuppressLint("WrongCall")
@Override @Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox,
DrawSettings drawSettings) { DrawSettings drawSettings) {