android monkey tests

This commit is contained in:
Hannes Janetzek 2014-10-03 03:02:22 +02:00
parent 82525ec769
commit 8f6f1bf238
3 changed files with 83 additions and 21 deletions

View File

@ -25,14 +25,17 @@ import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.tiling.TileSource; import org.oscim.tiling.TileSource;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
public class BaseMapActivity extends MapActivity { public class BaseMapActivity extends MapActivity {
static final Logger log = LoggerFactory.getLogger(BaseMapActivity.class);
final static boolean USE_CACHE = true; final static boolean USE_CACHE = false;
MapView mMapView; MapView mMapView;
VectorTileLayer mBaseLayer; VectorTileLayer mBaseLayer;

View File

@ -14,27 +14,29 @@
*/ */
package org.oscim.android.test; package org.oscim.android.test;
import static org.oscim.tiling.source.bitmap.DefaultSources.OPENSTREETMAP;
import org.oscim.android.MapActivity; import org.oscim.android.MapActivity;
import org.oscim.android.MapView; import org.oscim.android.MapView;
import org.oscim.android.cache.TileCache; import org.oscim.android.cache.TileCache;
import org.oscim.backend.canvas.Color; import org.oscim.backend.canvas.Color;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import org.oscim.layers.TileGridLayer; import org.oscim.layers.TileGridLayer;
import org.oscim.layers.tile.bitmap.BitmapTileLayer; import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.renderer.MapRenderer; import org.oscim.renderer.MapRenderer;
import org.oscim.tiling.TileSource; import org.oscim.tiling.TileSource;
import org.oscim.tiling.source.bitmap.DefaultSources;
import android.os.Bundle; import android.os.Bundle;
public class BitmapTileMapActivity extends MapActivity { public class BitmapTileMapActivity extends MapActivity {
private final static boolean USE_CACHE = true; private final static boolean USE_CACHE = false;
private final TileSource mTileSource; private final TileSource mTileSource;
protected BitmapTileLayer mBitmapLayer; protected BitmapTileLayer mBitmapLayer;
public BitmapTileMapActivity() { public BitmapTileMapActivity() {
mTileSource = OPENSTREETMAP.build(); //mTileSource = DefaultSources.STAMEN_TONER.build();
mTileSource = DefaultSources.OPENSTREETMAP.build();
} }
public BitmapTileMapActivity(TileSource tileSource) { public BitmapTileMapActivity(TileSource tileSource) {
@ -64,6 +66,8 @@ public class BitmapTileMapActivity extends MapActivity {
mBitmapLayer = new BitmapTileLayer(mMap, mTileSource); mBitmapLayer = new BitmapTileLayer(mMap, mTileSource);
mMap.layers().add(mBitmapLayer); mMap.layers().add(mBitmapLayer);
//loooop(1);
} }
@Override @Override
@ -72,4 +76,36 @@ public class BitmapTileMapActivity extends MapActivity {
if (USE_CACHE) if (USE_CACHE)
mCache.dispose(); mCache.dispose();
} }
// Stress testing
void loooop(final int i) {
final long time = (long) (500 + Math.random() * 1000);
mMapView.postDelayed(new Runnable() {
@Override
public void run() {
MapPosition p = new MapPosition();
if (i == 1) {
mMapView.map().getMapPosition(p);
p.setScale(4);
mMapView.map().animator().animateTo(time, p);
} else {
//mMapView.map().setMapPosition(p);
p.setScale(2 + (1 << (int) (Math.random() * 13)));
// p.setX((p.getX() + (Math.random() * 4 - 2) / p.getScale()));
// p.setY((p.getY() + (Math.random() * 4 - 2) / p.getScale()));
p.setX(MercatorProjection.longitudeToX(Math.random() * 180));
p.setY(MercatorProjection.latitudeToY(Math.random() * 60));
p.setTilt((float) (Math.random() * 60));
p.setBearing((float) (Math.random() * 360));
//mMapView.map().setMapPosition(p);
mMapView.map().animator().animateTo(time, p);
}
loooop((i + 1) % 2);
}
}, time);
}
} }

View File

@ -15,10 +15,13 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/package org.oscim.android.test; */package org.oscim.android.test;
import org.oscim.layers.tile.buildings.BuildingLayer; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import org.oscim.layers.tile.vector.labeling.LabelLayer; import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Layers; import org.oscim.map.Layers;
import org.oscim.map.Map; import org.oscim.map.Map;
import org.oscim.theme.IRenderTheme;
import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import android.os.Bundle; import android.os.Bundle;
@ -31,33 +34,53 @@ public class SimpleMapActivity extends BaseMapActivity {
Map m = this.map(); Map m = this.map();
Layers layers = mMap.layers(); Layers layers = mMap.layers();
layers.add(new BuildingLayer(mMap, mBaseLayer)); //layers.add(new BuildingLayer(mMap, mBaseLayer));
layers.add(new LabelLayer(mMap, mBaseLayer)); layers.add(new LabelLayer(mMap, mBaseLayer));
//layers.add(new TileGridLayer(mMap));
m.setTheme(VtmThemes.DEFAULT); m.setTheme(VtmThemes.DEFAULT);
//mMap.setTheme(VtmThemes.TRONRENDER);
//mMap.setTheme(VtmThemes.TRON2);
//mMap.setTheme(VtmThemes.OSMARENDER);
} }
void runTheMonkey() {
themes[0] = ThemeLoader.load(VtmThemes.DEFAULT);
themes[1] = ThemeLoader.load(VtmThemes.OSMARENDER);
themes[2] = ThemeLoader.load(VtmThemes.TRONRENDER);
loooop(1);
}
IRenderTheme[] themes = new IRenderTheme[3];
// Stress testing // Stress testing
void loooop(final int i) { void loooop(final int i) {
final long time = (long) (500 + Math.random() * 1000);
mMapView.postDelayed(new Runnable() { mMapView.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
VtmThemes t;
if (i == 0)
t = VtmThemes.DEFAULT;
else if (i == 1)
t = VtmThemes.TRONRENDER;
else
t = VtmThemes.OSMARENDER;
mMapView.map().setTheme(t); mMapView.map().setTheme(themes[i]);
MapPosition p = new MapPosition();
if (i == 1) {
mMapView.map().getMapPosition(p);
p.setScale(4);
mMapView.map().animator().animateTo(time, p);
} else {
//mMapView.map().setMapPosition(p);
p.setScale(2 + (1 << (int) (Math.random() * 13)));
// p.setX((p.getX() + (Math.random() * 4 - 2) / p.getScale()));
// p.setY((p.getY() + (Math.random() * 4 - 2) / p.getScale()));
p.setX(MercatorProjection.longitudeToX(Math.random() * 180));
p.setY(MercatorProjection.latitudeToY(Math.random() * 60));
p.setTilt((float) (Math.random() * 60));
p.setBearing((float) (Math.random() * 360));
//mMapView.map().setMapPosition(p);
mMapView.map().animator().animateTo(time, p);
}
loooop((i + 1) % 2);
loooop((i + 1) % 3);
} }
}, 300 + (int) (Math.random() * 200)); }, time);
} }
} }