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,28 +1,31 @@
package net.osmand.map;
import java.io.IOException;
public interface ITileSource {
public int getMaximumZoomSupported();
public String getName();
public int getTileSize();
public String getUrlToLoad(int x, int y, int zoom);
public byte[] getBytes(int x, int y, int zoom) throws IOException;
public int getMinimumZoomSupported();
public String getTileFormat();
public int getBitDensity();
public boolean isEllipticYTile();
public boolean couldBeDownloadedFromInternet();
public int getExpirationTimeMillis();
public int getExpirationTimeMinutes();
}

View file

@ -105,7 +105,7 @@ public class CoreResourcesFromAndroidAssetsCustom extends interface_ICoreResourc
if (containgDir != null && !containgDir.exists())
containgDir.mkdirs();
extractedPath.createNewFile();
final InputStream resourceStream = assetManager.open(path, AssetManager.ACCESS_STREAMING);
final FileOutputStream fileStream = new FileOutputStream(extractedPath);
Algorithms.streamCopy(resourceStream, fileStream);
@ -114,7 +114,7 @@ public class CoreResourcesFromAndroidAssetsCustom extends interface_ICoreResourc
} catch (IOException e2) {
if (extractedPath.exists())
extractedPath.delete();
Log.e(NATIVE_TAG, "Failed to extract '" + resourceInBundle + "'", e2);
continue;
}
@ -239,8 +239,8 @@ public class CoreResourcesFromAndroidAssetsCustom extends interface_ICoreResourc
}
System.out.println(resourceEntry.defaultVariant.path.getAbsolutePath());
final SWIGTYPE_p_QByteArray bt;
if (resourceEntry.defaultVariant.offset == 0 &&
resourceEntry.defaultVariant.size == resourceEntry.defaultVariant.path.length()) {
if (resourceEntry.defaultVariant.offset == 0
&& resourceEntry.defaultVariant.size == resourceEntry.defaultVariant.path.length()) {
bt = SwigUtilities.readEntireFile(resourceEntry.defaultVariant.path.getAbsolutePath());
} else {
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();
}
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();
if(db == null){
return null;
@ -283,15 +283,7 @@ public class SQLiteTileSource implements ITileSource {
}
}
cursor.close();
if (blob != null) {
Bitmap bmp = null;
bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
if(bmp == null) {
// broken image delete it
db.execSQL("DELETE FROM tiles WHERE x = ? AND y = ? AND z = ?", params);
}
return bmp;
}
return blob;
}
return null;
} finally {
@ -301,6 +293,34 @@ public class SQLiteTileSource implements ITileSource {
}
}
}
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) {
Bitmap bmp = null;
bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
if(bmp == null) {
// broken image delete it
db.execSQL("DELETE FROM tiles WHERE x = ? AND y = ? AND z = ?", params);
}
return bmp;
}
return null;
}
public ITileSource getBase() {
return base;

View file

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