Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Recycle some bitmaps in ScreenCache, clean screencache on finalize(),…
Browse files Browse the repository at this point in the history
… add lang for google static api
  • Loading branch information
Aubort Jean-Baptiste committed Apr 4, 2011
1 parent 74e5fc8 commit de66c05
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions android/src/com/nutiteq/android/MapView.java
Expand Up @@ -63,6 +63,7 @@ protected void onDraw(final Canvas canvas) {
}
catch (OutOfMemoryError e) {
e.printStackTrace();
mapComponent.cleanNetworkCache();
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle("OutOfMemory");
dialog.setMessage(e.getLocalizedMessage());
Expand Down
22 changes: 7 additions & 15 deletions src/com/mgmaps/cache/ScreenCache.java
Expand Up @@ -10,7 +10,6 @@

import com.nutiteq.components.MapPos;
import com.nutiteq.components.MapTile;
import com.nutiteq.log.Log;
import com.nutiteq.maps.GeoMap;
import com.nutiteq.ui.ImageProcessor;

Expand Down Expand Up @@ -162,6 +161,10 @@ public int add(final MapTile t, final MapPos mp, final GeoMap displayedMap, fina
// find a place to add
for (int i = 0; i < size; i++) {
if (!valid[i] || t.equals(tiles[i])) {
if (images[i] != null && images[i].getBitmap() != null
&& !images[i].getBitmap().isRecycled()) {
images[i].getBitmap().recycle();
}
valid[i] = true;
tiles[i] = t;
//BattleTac code starts
Expand Down Expand Up @@ -197,9 +200,9 @@ private int sweepFind(final MapTile t, final MapPos mp, final GeoMap displayedMa
found = i;
} else if (!tiles[i].isVisible(mp, displayedMap, screenCenterX, screenCenterY)) {
valid[i] = false;
// if (images[i] != null) {
// images[i].getBitmap().recycle();
// }
if (images[i] != null) {
images[i].getBitmap().recycle();
}
tiles[i] = null;
images[i] = null;
}
Expand All @@ -219,14 +222,6 @@ private int sweepFind(final MapTile t, final MapPos mp, final GeoMap displayedMa
*/
public void setImageProcessor(final ImageProcessor processor) {
imageProcessor = processor;
// for (int i = 0; i < size; i++) {
// valid[i] = false;
// if (images[i] != null) {
// images[i].getBitmap().recycle();
// }
// tiles[i] = null;
// images[i] = null;
// }
}
//BattleTac code ends

Expand All @@ -243,9 +238,6 @@ public Vector<MapTile> getTiles() {
public void renewTileImages() {
for(int i=0; i < size; i++) {
if( valid[i] && tiles[i] != null ) {
if (images[i] != null) {
images[i].getBitmap().recycle();
}
images[i] = tiles[i].getImage();
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/com/nutiteq/components/ImageBuffer.java
Expand Up @@ -5,7 +5,7 @@

import com.nutiteq.utils.Utils;

public class ImageBuffer {
public class ImageBuffer extends Object {
private Image[] bufferImages;
private Graphics[] bufferGraphics;
private int front;
Expand All @@ -18,6 +18,11 @@ public ImageBuffer(final int numberOfImages, final int imageWidth, final int ima
bufferGraphics[i] = bufferImages[i].getGraphics();
}
}

@Override
protected void finalize() {
clean();
}

public Image getFrontImage() {
return bufferImages[front];
Expand Down Expand Up @@ -55,5 +60,6 @@ public void clean() {
}
bufferImages = null;
bufferGraphics = null;
System.gc();
}
}
5 changes: 4 additions & 1 deletion src/com/nutiteq/maps/GoogleStaticMap.java
Expand Up @@ -21,6 +21,7 @@ public class GoogleStaticMap extends EPSG3785 implements GeoMap, UnstreamedMap {
private final String developerKey;
private final String imageFormat;
private final String mapType;
private final String lang;
private final boolean sensor;

/**
Expand Down Expand Up @@ -49,12 +50,13 @@ public class GoogleStaticMap extends EPSG3785 implements GeoMap, UnstreamedMap {
* now required for all static map requests.
*/
public GoogleStaticMap(final String developerKey, final int tileSize, final int minZoom,
final int maxZoom, final String imageFormat, final String mapType, final boolean sensor) {
final int maxZoom, final String imageFormat, final String mapType, final String lang, final boolean sensor) {
super(new StringCopyright(""), tileSize, minZoom, maxZoom);
this.developerKey = developerKey;
this.imageFormat = imageFormat;
this.mapType = mapType;
this.sensor = sensor;
this.lang = lang;
}

public String buildPath(final int mapX, final int mapY, final int zoom) {
Expand All @@ -68,6 +70,7 @@ public String buildPath(final int mapX, final int mapY, final int zoom) {
url.append("&maptype=").append(mapType);
url.append("&key=").append(developerKey);
url.append("&sensor=").append(sensor);
url.append("&lang=").append(lang);
return url.toString();
}
}
2 changes: 2 additions & 0 deletions src/com/nutiteq/net/DefaultDownloadStreamOpener.java
Expand Up @@ -10,6 +10,8 @@
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import android.text.StaticLayout;

import com.nutiteq.log.Log;
import com.nutiteq.utils.IOUtils;

Expand Down

0 comments on commit de66c05

Please sign in to comment.