Merge branch 'wip_android'

This commit is contained in:
Hannes Janetzek 2014-01-19 22:57:40 +01:00
commit ab2e82a456
15 changed files with 145 additions and 68 deletions

@ -1 +1 @@
Subproject commit 6093f28947a9188f58c6a362d196920dfd5d02c8 Subproject commit 2173ae1f3f4349c44908a8be97d93fdce6734094

View File

@ -10,7 +10,7 @@
<uses-sdk <uses-sdk
android:minSdkVersion="10" android:minSdkVersion="10"
android:targetSdkVersion="18" /> android:targetSdkVersion="10" />
<application <application
android:allowBackup="true" android:allowBackup="true"
@ -30,17 +30,26 @@
<activity <activity
android:name="org.oscim.android.test.SimpleMapActivity" android:name="org.oscim.android.test.SimpleMapActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/title_activity_map" > android:label="@string/title_activity_map" >
</activity> </activity>
<activity <activity
android:name="org.oscim.android.test.PathOverlayActivity" android:name="org.oscim.android.test.PathOverlayActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/title_activity_map" > android:label="@string/title_activity_map" >
</activity> </activity>
<activity <activity
android:name="org.oscim.android.test.MarkerOverlayActivity" android:name="org.oscim.android.test.MarkerOverlayActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/title_activity_map" >
</activity>
<activity
android:name="org.oscim.android.test.BitmapTileMapActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/title_activity_map" > android:label="@string/title_activity_map" >
</activity> </activity>
</application> </application>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<group android:id="@+id/themes" android:checkableBehavior="single" android:menuCategory="container">
<item android:id="@+id/theme_default" android:checkable="true" android:title="@string/theme_default" android:checked="true" android:showAsAction="never"></item>
<item android:id="@+id/theme_tubes" android:checkable="true" android:title="@string/theme_tubes" android:showAsAction="never"></item>
<item android:id="@+id/theme_osmarender" android:checkable="true" android:title="@string/theme_osmarender" android:showAsAction="never"></item>
</group>
</menu>

View File

@ -4,5 +4,8 @@
<string name="hello_world">Hello world!</string> <string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string> <string name="menu_settings">Settings</string>
<string name="title_activity_map">MapActivity</string> <string name="title_activity_map">MapActivity</string>
<string name="theme_default">Default</string>
<string name="theme_tubes">Tubes</string>
<string name="theme_osmarender">Osmarender</string>
</resources> </resources>

View File

@ -28,7 +28,7 @@ import android.view.Menu;
public class BaseMapActivity extends MapActivity { public class BaseMapActivity extends MapActivity {
private final static boolean USE_CACHE = false; private final static boolean USE_CACHE = true;
MapView mMapView; MapView mMapView;
VectorTileLayer mBaseLayer; VectorTileLayer mBaseLayer;
@ -42,6 +42,7 @@ public class BaseMapActivity extends MapActivity {
setContentView(R.layout.activity_map); setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapView); mMapView = (MapView) findViewById(R.id.mapView);
registerMapView(mMapView);
mTileSource = new OSciMap4TileSource(); mTileSource = new OSciMap4TileSource();
mTileSource.setOption("url", "http://opensciencemap.org/tiles/vtm"); mTileSource.setOption("url", "http://opensciencemap.org/tiles/vtm");

View File

@ -0,0 +1,37 @@
/*
* Copyright 2014 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.android.test;
import org.oscim.android.MapActivity;
import org.oscim.android.MapView;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.layers.tile.bitmap.StamenTonerTiles;
import android.os.Bundle;
public class BitmapTileMapActivity extends MapActivity {
MapView mMapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapView);
//registerMapView(mMapView);
mMap.getLayers().add(new BitmapTileLayer(mMap, StamenTonerTiles.INSTANCE, 20));
}
}

View File

@ -43,6 +43,7 @@ public class MarkerOverlayActivity extends MapActivity implements OnItemGestureL
setContentView(R.layout.activity_map); setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapView); mMapView = (MapView) findViewById(R.id.mapView);
registerMapView(mMapView);
MarkerSymbol symbol = AndroidGraphics.makeMarker(getResources(), MarkerSymbol symbol = AndroidGraphics.makeMarker(getResources(),
R.drawable.marker_poi, R.drawable.marker_poi,

View File

@ -24,6 +24,8 @@ import org.oscim.android.MapView;
import org.oscim.backend.canvas.Color; import org.oscim.backend.canvas.Color;
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.layers.PathLayer; import org.oscim.layers.PathLayer;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.layers.tile.bitmap.StamenTonerTiles;
import android.os.Bundle; import android.os.Bundle;
@ -37,6 +39,9 @@ public class PathOverlayActivity extends MapActivity {
setContentView(R.layout.activity_map); setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapView); mMapView = (MapView) findViewById(R.id.mapView);
registerMapView(mMapView);
mMap.getLayers().add(new BitmapTileLayer(mMap, StamenTonerTiles.INSTANCE, 20));
for (double lon = -180; lon < 180; lon += 5) { for (double lon = -180; lon < 180; lon += 5) {
List<GeoPoint> pts = new ArrayList<GeoPoint>(); List<GeoPoint> pts = new ArrayList<GeoPoint>();

View File

@ -36,6 +36,7 @@ public class Samples extends Activity {
setContentView(R.layout.activity_samples); setContentView(R.layout.activity_samples);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples);
linearLayout.addView(createButton(SimpleMapActivity.class)); linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(BitmapTileMapActivity.class));
linearLayout.addView(createButton(PathOverlayActivity.class)); linearLayout.addView(createButton(PathOverlayActivity.class));
linearLayout.addView(createButton(MarkerOverlayActivity.class)); linearLayout.addView(createButton(MarkerOverlayActivity.class));
} }

View File

@ -15,11 +15,12 @@
* 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.vector.BuildingLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer; import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.theme.InternalRenderTheme; import org.oscim.theme.InternalRenderTheme;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SimpleMapActivity extends BaseMapActivity { public class SimpleMapActivity extends BaseMapActivity {
@ -27,7 +28,8 @@ public class SimpleMapActivity extends BaseMapActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mMap.getLayers().add(new BuildingLayer(mMap, mBaseLayer.getTileLayer())); //mMap.getLayers().add(new BuildingLayer(mMap, mBaseLayer.getTileLayer()));
mMap.getLayers().add(new LabelLayer(mMap, mBaseLayer.getTileLayer())); mMap.getLayers().add(new LabelLayer(mMap, mBaseLayer.getTileLayer()));
//mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer())); //mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
@ -37,5 +39,55 @@ public class SimpleMapActivity extends BaseMapActivity {
//mMap.setTheme(InternalRenderTheme.OSMARENDER); //mMap.setTheme(InternalRenderTheme.OSMARENDER);
mMap.setMapPosition(53.08, 8.83, Math.pow(2, 14)); mMap.setMapPosition(53.08, 8.83, Math.pow(2, 14));
//loooop(0);
}
void loooop(final int i) {
mMapView.postDelayed(new Runnable() {
@Override
public void run() {
InternalRenderTheme t;
if (i == 0)
t = InternalRenderTheme.DEFAULT;
else if (i == 1)
t = InternalRenderTheme.TRONRENDER;
else
t = InternalRenderTheme.OSMARENDER;
mMapView.getMap().setTheme(t);
loooop((i + 1) % 3);
}
}, 300 + (int)(Math.random() * 200));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.theme_menu, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.theme_default:
mMap.setTheme(InternalRenderTheme.DEFAULT);
item.setChecked(true);
return true;
case R.id.theme_tubes:
mMap.setTheme(InternalRenderTheme.TRONRENDER);
item.setChecked(true);
return true;
case R.id.theme_osmarender:
mMap.setTheme(InternalRenderTheme.OSMARENDER);
item.setChecked(true);
return true;
}
return false;
} }
} }

View File

@ -50,9 +50,9 @@ public class Compass {
private final SensorManager mSensorManager; private final SensorManager mSensorManager;
private final Sensor mSensor; private final Sensor mSensor;
public Compass(MapActivity mapActivity, Map map) { public Compass(Context context, Map map) {
mMap = map; mMap = map;
mSensorManager = (SensorManager) mapActivity mSensorManager = (SensorManager) context
.getSystemService(Context.SENSOR_SERVICE); .getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);

View File

@ -45,8 +45,6 @@ public abstract class MapActivity extends Activity {
private static final String PREFERENCES_FILE = "MapActivity"; private static final String PREFERENCES_FILE = "MapActivity";
//private static final String KEY_THEME = "Theme";
private static boolean containsViewport(SharedPreferences sharedPreferences) { private static boolean containsViewport(SharedPreferences sharedPreferences) {
return sharedPreferences.contains(KEY_LATITUDE) return sharedPreferences.contains(KEY_LATITUDE)
&& sharedPreferences.contains(KEY_LONGITUDE) && sharedPreferences.contains(KEY_LONGITUDE)
@ -100,8 +98,8 @@ public abstract class MapActivity extends Activity {
* @param map * @param map
* the calling MapView. * the calling MapView.
*/ */
public final void registerMapView(Map map) { public final void registerMapView(MapView map) {
mMap = map; mMap = map.getMap();
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE, SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
MODE_PRIVATE); MODE_PRIVATE);

View File

@ -35,7 +35,6 @@ import android.util.DisplayMetrics;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener; import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
/** /**
@ -91,9 +90,6 @@ public class MapView extends RelativeLayout {
public MapView(Context context, AttributeSet attributeSet) { public MapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet); super(context, attributeSet);
if (!(context instanceof MapActivity))
throw new IllegalArgumentException("context is not an instance of MapActivity");
CanvasAdapter.g = AndroidGraphics.INSTANCE; CanvasAdapter.g = AndroidGraphics.INSTANCE;
AssetAdapter.g = new AndroidAssetAdapter(context); AssetAdapter.g = new AndroidAssetAdapter(context);
GLAdapter.g = new AndroidGL(); GLAdapter.g = new AndroidGL();
@ -108,13 +104,8 @@ public class MapView extends RelativeLayout {
// TODO make this dpi dependent // TODO make this dpi dependent
Tile.SIZE = 400; Tile.SIZE = 400;
MapActivity mapActivity = (MapActivity) context;
mMap = new AndroidMap(this); mMap = new AndroidMap(this);
mCompass = new Compass(context, mMap);
mCompass = new Compass(mapActivity, mMap);
mapActivity.registerMapView(mMap);
mMap.clearMap(); mMap.clearMap();
mMap.updateMap(false); mMap.updateMap(false);
@ -122,9 +113,7 @@ public class MapView extends RelativeLayout {
mGestureDetector = new GestureDetector(context, new OnGestureListener() { mGestureDetector = new GestureDetector(context, new OnGestureListener() {
@Override @Override
public boolean onSingleTapUp(MotionEvent e) { public boolean onSingleTapUp(MotionEvent e) {
boolean handled = mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e)); return mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e));
mMotionEvent.wrap(null);
return handled;
} }
@Override @Override
@ -139,7 +128,6 @@ public class MapView extends RelativeLayout {
@Override @Override
public void onLongPress(MotionEvent e) { public void onLongPress(MotionEvent e) {
mMap.handleGesture(Gesture.LONG_PRESS, mMotionEvent.wrap(e)); mMap.handleGesture(Gesture.LONG_PRESS, mMotionEvent.wrap(e));
mMotionEvent.wrap(null);
} }
@Override @Override
@ -149,34 +137,9 @@ public class MapView extends RelativeLayout {
@Override @Override
public boolean onDown(MotionEvent e) { public boolean onDown(MotionEvent e) {
boolean handled = mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e)); return mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e));
mMotionEvent.wrap(null);
return handled;
} }
}); });
//mGestureDetector.setOnDoubleTapListener(new OnDoubleTapListener() {
//
// @Override
// public boolean onSingleTapConfirmed(MotionEvent e) {
// return false;
// }
//
// @Override
// public boolean onDoubleTapEvent(MotionEvent e) {
// return false;
// }
//
// @Override
// public boolean onDoubleTap(MotionEvent e) {
// return false;
// }
//});
}
View getView() {
return this;
} }
public Map getMap() { public Map getMap() {
@ -220,7 +183,6 @@ public class MapView extends RelativeLayout {
return true; return true;
} }
// synchronized ???
@Override @Override
protected void onSizeChanged(int width, int height, protected void onSizeChanged(int width, int height,
int oldWidth, int oldHeight) { int oldWidth, int oldHeight) {

View File

@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDoneException; import android.database.sqlite.SQLiteDoneException;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
@ -108,9 +107,14 @@ public class TileCache implements ITileCache {
mDatabase.close(); mDatabase.close();
} }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public TileCache(Context context, String cacheDirectory, String dbName) { public TileCache(Context context, String cacheDirectory, String dbName) {
dbHelper = new SQLiteHelper(context); dbHelper = new SQLiteHelper(context);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
dbHelper.setWriteAheadLoggingEnabled(true);
mDatabase = dbHelper.getWritableDatabase(); mDatabase = dbHelper.getWritableDatabase();
mStmtGetTile = mDatabase.compileStatement("" + mStmtGetTile = mDatabase.compileStatement("" +
@ -154,7 +158,7 @@ public class TileCache implements ITileCache {
class SQLiteHelper extends SQLiteOpenHelper { class SQLiteHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "tile.db"; private static final String DATABASE_NAME = "tile.db";
private static final int DATABASE_VERSION = 3; private static final int DATABASE_VERSION = 8;
private static final String DATABASE_CREATE = private static final String DATABASE_CREATE =
"CREATE TABLE " "CREATE TABLE "
@ -209,13 +213,12 @@ public class TileCache implements ITileCache {
mStmtPutTile.bindBlob(6, bytes); mStmtPutTile.bindBlob(6, bytes);
mStmtPutTile.execute(); mStmtPutTile.execute();
mStmtPutTile.clearBindings(); mStmtPutTile.clearBindings();
} }
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public synchronized TileReader getTileApi11(Tile tile) { public TileReader getTileApi11(Tile tile) {
InputStream in = null; InputStream in = null;
mStmtGetTile.bindLong(1, tile.tileX); mStmtGetTile.bindLong(1, tile.tileX);
@ -242,8 +245,8 @@ public class TileCache implements ITileCache {
@Override @Override
public synchronized TileReader getTile(Tile tile) { public synchronized TileReader getTile(Tile tile) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) //if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
return getTileApi11(tile); // return getTileApi11(tile);
mQueryVals[0] = String.valueOf(tile.zoomLevel); mQueryVals[0] = String.valueOf(tile.zoomLevel);
mQueryVals[1] = String.valueOf(tile.tileX); mQueryVals[1] = String.valueOf(tile.tileX);
@ -268,12 +271,7 @@ public class TileCache implements ITileCache {
return new CacheTileReader(tile, in, Integer.MAX_VALUE); return new CacheTileReader(tile, in, Integer.MAX_VALUE);
} }
public SQLiteDatabase open() throws SQLException {
return dbHelper.getWritableDatabase();
}
@Override @Override
public void setCacheSize(long size) { public void setCacheSize(long size) {
// TODO Auto-generated method stub
} }
} }

View File

@ -24,23 +24,23 @@ public class AndroidCanvas implements Canvas {
final android.graphics.Canvas canvas; final android.graphics.Canvas canvas;
public AndroidCanvas() { public AndroidCanvas() {
this.canvas = new android.graphics.Canvas(); canvas = new android.graphics.Canvas();
} }
@Override @Override
public void setBitmap(Bitmap bitmap) { public void setBitmap(Bitmap bitmap) {
this.canvas.setBitmap(((AndroidBitmap) bitmap).mBitmap); canvas.setBitmap(((AndroidBitmap) bitmap).mBitmap);
} }
@Override @Override
public void drawText(String string, float x, float y, Paint stroke) { public void drawText(String string, float x, float y, Paint stroke) {
this.canvas.drawText(string, x, y, ((AndroidPaint) stroke).mPaint); if (string != null)
canvas.drawText(string, x, y, ((AndroidPaint) stroke).mPaint);
} }
@Override @Override
public void drawBitmap(Bitmap bitmap, float x, float y) { public void drawBitmap(Bitmap bitmap, float x, float y) {
this.canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null); canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
} }