- add compass

- add 'fix orientation' option
- bugfix segv in limitLoadQueue
- remove redundant MapController
- refactor out Location stuff from TileMap
This commit is contained in:
Hannes Janetzek 2012-09-11 04:06:59 +02:00
parent baa40ed9ea
commit 53636cff30
16 changed files with 756 additions and 597 deletions

View File

@ -3,25 +3,24 @@
android:id="@+id/mainView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:windowActionBarOverlay="true"
>
android:windowActionBarOverlay="true" >
<org.mapsforge.android.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- <ToggleButton
<ToggleButton
android:id="@+id/snapToLocationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dip"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/snap_to_position"
android:textOff=""
android:textOn=""
android:visibility="gone" />-->
android:visibility="gone" />
</RelativeLayout>

View File

@ -22,10 +22,18 @@
<item
android:id="@+id/menu_position_map_center"
android:title="@string/menu_position_map_file_center"/>
<item
android:id="@+id/menu_rotation_enable"
android:title="@string/menu_rotation_enable"/>
<item
android:id="@+id/menu_rotation_disable"
android:title="@string/menu_rotation_disable"/>
<item
android:id="@+id/menu_compass_enable"
android:title="@string/menu_compass_enable"/>
<item
android:id="@+id/menu_compass_disable"
android:title="@string/menu_compass_disable"/>
</menu>
</item>
<item

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string-array name="preferences_map_generator_values">
<!-- <item>Mapfile</item> -->
<!-- <item>PostGIS</item>-->
<!-- <item>PostGIS</item> -->
<item>OpenScienceMap</item>
</string-array>
<string-array name="preferences_scale_bar_unit_values">
<item>Imperial</item>
<item>Metric</item>
</string-array>
<string-array name="preferences_text_scale_values">
<item>tiny</item>
<item>small</item>
@ -52,6 +52,9 @@
<string name="menu_mapfile">Map file</string>
<string name="menu_position">Position</string>
<string name="menu_rotation_enable">Enable rotation</string>
<string name="menu_compass_enable">Enable compass</string>
<string name="menu_rotation_disable">Disable rotation</string>
<string name="menu_compass_disable">Disable compass</string>
<string name="menu_position_enter_coordinates">Enter coordinates</string>
<string name="menu_position_last_known">Last known location</string>
<string name="menu_position_map_file_center">Map file center</string>
@ -76,6 +79,8 @@
<string name="preferences_cache_size_value">%.1f MB</string>
<string name="preferences_fullscreen">Full screen mode</string>
<string name="preferences_fullscreen_desc">Hide the status bar</string>
<string name="preferences_fix_orientation">Fix screen orientation</string>
<string name="preferences_fix_orientation_desc">Fix screen orientation</string>
<string name="preferences_map">Map settings</string>
<string name="preferences_map_view_mode">Map mode</string>
<string name="preferences_map_view_mode_desc">Select the operating mode</string>
@ -105,4 +110,5 @@
<string name="unit_symbol_meter">&#160;m</string>
<string name="zoomLevel">Zoom level</string>
<string name="menu_options">Options</string>
</resources>

View File

@ -1,40 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/menu_preferences">
<PreferenceCategory android:title="@string/preferences_map">
<!-- <CheckBoxPreference android:title="@string/preferences_show_scale_bar" android:summary="@string/preferences_show_scale_bar_desc"
android:key="showScaleBar" /> -->
<!-- <ListPreference android:title="@string/preferences_scale_bar_unit" android:summary="@string/preferences_scale_bar_unit_desc"
android:entryValues="@array/preferences_scale_bar_unit_keys" android:entries="@array/preferences_scale_bar_unit_values"
android:key="scaleBarUnit" android:defaultValue="@string/preferences_scale_bar_unit_default" android:dependency="showScaleBar" /> -->
<ListPreference android:title="@string/preferences_map_view_mode" android:summary="@string/preferences_map_view_mode_desc"
android:entryValues="@array/preferences_map_database_keys" android:entries="@array/preferences_map_generator_values"
android:key="mapDatabase" android:defaultValue="@string/preferences_map_database_default" />
<!-- <ListPreference android:title="@string/preferences_text_scale" android:summary="@string/preferences_text_scale_desc"
android:entryValues="@array/preferences_text_scale_keys" android:entries="@array/preferences_text_scale_values"
android:key="textScale" android:defaultValue="@string/preferences_text_scale_default" /> -->
</PreferenceCategory>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/menu_preferences" >
<PreferenceCategory android:title="@string/preferences_general">
<CheckBoxPreference android:title="@string/preferences_fullscreen" android:summary="@string/preferences_fullscreen_desc"
android:key="fullscreen" />
<CheckBoxPreference android:title="@string/preferences_wake_lock" android:summary="@string/preferences_wake_lock_desc"
android:key="wakeLock" />
<!-- <CheckBoxPreference android:title="@string/preferences_cache_persistence" android:summary="@string/preferences_cache_persistence_desc"
<PreferenceCategory android:title="@string/preferences_map" >
<!--
<CheckBoxPreference android:title="@string/preferences_show_scale_bar" android:summary="@string/preferences_show_scale_bar_desc"
android:key="showScaleBar" />
-->
<!--
<ListPreference android:title="@string/preferences_scale_bar_unit" android:summary="@string/preferences_scale_bar_unit_desc"
android:entryValues="@array/preferences_scale_bar_unit_keys" android:entries="@array/preferences_scale_bar_unit_values"
android:key="scaleBarUnit" android:defaultValue="@string/preferences_scale_bar_unit_default" android:dependency="showScaleBar" />
-->
<ListPreference
android:defaultValue="@string/preferences_map_database_default"
android:entries="@array/preferences_map_generator_values"
android:entryValues="@array/preferences_map_database_keys"
android:key="mapDatabase"
android:summary="@string/preferences_map_view_mode_desc"
android:title="@string/preferences_map_view_mode" />
<!--
<ListPreference android:title="@string/preferences_text_scale" android:summary="@string/preferences_text_scale_desc"
android:entryValues="@array/preferences_text_scale_keys" android:entries="@array/preferences_text_scale_values"
android:key="textScale" android:defaultValue="@string/preferences_text_scale_default" />
-->
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_general" >
<CheckBoxPreference
android:key="fullscreen"
android:summary="@string/preferences_fullscreen_desc"
android:title="@string/preferences_fullscreen" />
<CheckBoxPreference
android:key="fixOrientation"
android:summary="@string/preferences_fix_orientation"
android:title="@string/preferences_fix_orientation_desc" />
<CheckBoxPreference
android:key="wakeLock"
android:summary="@string/preferences_wake_lock_desc"
android:title="@string/preferences_wake_lock" />
<!--
<CheckBoxPreference android:title="@string/preferences_cache_persistence" android:summary="@string/preferences_cache_persistence_desc"
android:key="cachePersistence" />
<de.sfb.pampa.preferences.CacheSizePreference
android:title="@string/preferences_cache_size" android:summary="@string/preferences_cache_size_desc" android:key="cacheSize" />
<de.sfb.pampa.preferences.MoveSpeedPreference
android:title="@string/preferences_move_speed" android:summary="@string/preferences_move_speed_desc" android:key="moveSpeed" /> -->
android:title="@string/preferences_move_speed" android:summary="@string/preferences_move_speed_desc" android:key="moveSpeed" />
-->
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_debug" >
<!--
<CheckBoxPreference android:title="@string/preferences_show_fps_counter" android:summary="@string/preferences_show_fps_counter_desc"
android:key="showFpsCounter" />
-->
<CheckBoxPreference
android:key="drawTileFrames"
android:summary="@string/preferences_show_tile_frames_desc"
android:title="@string/preferences_show_tile_frames" />
<CheckBoxPreference
android:key="drawUnmatchedWays"
android:summary="@string/preferences_show_unmatched_ways"
android:title="@string/preferences_show_unmatched_ways" />
<CheckBoxPreference
android:key="disablePolygons"
android:summary="@string/preferences_disable_polygons"
android:title="@string/preferences_disable_polygons" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_debug">
<!-- <CheckBoxPreference android:title="@string/preferences_show_fps_counter" android:summary="@string/preferences_show_fps_counter_desc"
android:key="showFpsCounter" /> -->
<CheckBoxPreference android:title="@string/preferences_show_tile_frames" android:summary="@string/preferences_show_tile_frames_desc"
android:key="drawTileFrames" />
<CheckBoxPreference android:title="@string/preferences_show_unmatched_ways" android:summary="@string/preferences_show_unmatched_ways"
android:key="drawUnmatchedWays" />
<CheckBoxPreference android:title="@string/preferences_disable_polygons" android:summary="@string/preferences_disable_polygons"
android:key="disablePolygons" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,69 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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.mapsforge.android;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class Compass {
private final SensorEventListener mListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
// if (true) Log.d(TAG,
// "sensorChanged (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ")");
// mValues = event.values;
if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0];
if (mMapView != null) {
mMapView.getMapPosition().setRotation(mAngle);
mMapView.redrawTiles();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
/* package */float mAngle = 0;
/* package */MapView mMapView;
private SensorManager mSensorManager;
private Sensor mSensor;
// private float[] mValues;
public Compass(MapActivity mapActivity, MapView mapView) {
mMapView = mapView;
mSensorManager = (SensorManager) mapActivity
.getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
void enable() {
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_GAME);
}
void disable() {
mSensorManager.unregisterListener(mListener);
mMapView.getMapPosition().setRotation(0);
}
}

View File

@ -1,89 +0,0 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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.mapsforge.android;
import org.mapsforge.core.GeoPoint;
import android.view.KeyEvent;
import android.view.View;
/**
* A MapController is used to programmatically modify the position and zoom level of a MapView. Each MapController is
* assigned to a single MapView instance. To retrieve a MapController for a given MapView, use the
* {@link MapView#getController()} method.
*/
public final class MapController implements View.OnKeyListener {
private final MapView mMapView;
/**
* @param mapView
* the MapView which should be controlled by this MapController.
*/
MapController(MapView mapView) {
mMapView = mapView;
}
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
// forward the event to the MapView
return mMapView.onKeyDown(keyCode, keyEvent);
} else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
// forward the event to the MapView
return mMapView.onKeyUp(keyCode, keyEvent);
}
return false;
}
/**
* Sets the center of the MapView without an animation to the given point.
*
* @param geoPoint
* the new center point of the map.
*/
public void setCenter(GeoPoint geoPoint) {
mMapView.setCenter(geoPoint);
}
/**
* Sets the zoom level of the MapView.
*
* @param zoomLevel
* the new zoom level, will be limited by the maximum and minimum possible zoom level.
* @return the new zoom level.
*/
public int setZoom(int zoomLevel) {
mMapView.zoom((byte) (zoomLevel - mMapView.getMapPosition().getZoomLevel()));
return mMapView.getMapPosition().getZoomLevel();
}
/**
* Increases the zoom level of the MapView, unless the maximum zoom level has been reached.
*
* @return true if the zoom level has been changed, false otherwise.
*/
public boolean zoomIn() {
return mMapView.zoom((byte) 1);
}
/**
* Decreases the zoom level of the MapView, unless the minimum zoom level has been reached.
*
* @return true if the zoom level has been changed, false otherwise.
*/
public boolean zoomOut() {
return mMapView.zoom((byte) -1);
}
}

View File

@ -53,8 +53,7 @@ import android.view.MotionEvent;
/**
* A MapView shows a map on the display of the device. It handles all user input and touch gestures to move and zoom the
* map. This MapView also includes a scale bar and zoom controls. The {@link #getController()} method returns a
* {@link MapController} to programmatically modify the position and zoom level of the map.
* map. This MapView also includes a scale bar and zoom controls.
* <p>
* This implementation supports offline map rendering as well as downloading map images (tiles) over an Internet
* connection. The operation mode of a MapView can be set in the constructor and changed at runtime with the
@ -78,14 +77,16 @@ public class MapView extends GLSurfaceView {
private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
public final static boolean debugFrameTime = false;
public boolean enableRotation = false;
private final MapController mMapController;
public boolean enableRotation = false;
public boolean enableCompass = false;
private final MapViewPosition mMapViewPosition;
private final MapZoomControls mMapZoomControls;
private final Projection mProjection;
private final TouchHandler mTouchEventHandler;
private final Compass mCompass;
private IMapDatabase mMapDatabase;
private MapDatabases mMapDatabaseType;
@ -131,6 +132,7 @@ public class MapView extends GLSurfaceView {
throw new IllegalArgumentException(
"context is not an instance of MapActivity");
}
Log.d(TAG, "create MapView: " + mapDatabaseType.name());
// TODO make this dpi dependent
@ -140,8 +142,6 @@ public class MapView extends GLSurfaceView {
debugSettings = new DebugSettings(false, false, false, false);
mMapController = new MapController(this);
mMapDatabaseType = mapDatabaseType;
mMapViewPosition = new MapViewPosition(this);
@ -152,6 +152,8 @@ public class MapView extends GLSurfaceView {
mTouchEventHandler = new TouchHandler(mapActivity, this);
mCompass = new Compass(mapActivity, this);
mJobQueue = new JobQueue();
mMapRenderer = MapRendererFactory.createMapRenderer(this, mapGeneratorType);
@ -194,6 +196,8 @@ public class MapView extends GLSurfaceView {
if (!debugFrameTime)
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
// mCompass.enable();
}
private void initMapStartPosition() {
@ -208,13 +212,6 @@ public class MapView extends GLSurfaceView {
}
}
/**
* @return the MapController for this MapView.
*/
public MapController getController() {
return mMapController;
}
/**
* @return the debug settings which are used in this MapView.
*/
@ -259,7 +256,10 @@ public class MapView extends GLSurfaceView {
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
if (this.isClickable())
return mTouchEventHandler.handleMotionEvent(motionEvent);
return false;
}
/**
@ -279,17 +279,6 @@ public class MapView extends GLSurfaceView {
mMapRenderer.updateMap(true);
}
/**
* Sets the visibility of the zoom controls.
*
* @param showZoomControls
* true if the zoom controls should be visible, false otherwise.
*/
public void setBuiltInZoomControls(boolean showZoomControls) {
mMapZoomControls.setShowMapZoomControls(showZoomControls);
}
/**
* Sets the center of the MapView and triggers a redraw.
*
@ -299,6 +288,7 @@ public class MapView extends GLSurfaceView {
public void setCenter(GeoPoint geoPoint) {
MapPosition mapPosition = new MapPosition(geoPoint,
mMapViewPosition.getZoomLevel(), 1);
setCenterAndZoom(mapPosition);
}
@ -562,12 +552,13 @@ public class MapView extends GLSurfaceView {
int oldHeight) {
mJobQueue.clear();
mCompass.disable();
mapWorkersPause(true);
super.onSizeChanged(width, height, oldWidth, oldHeight);
mapWorkersProceed();
mCompass.enable();
}
void destroy() {
@ -619,12 +610,18 @@ public class MapView extends GLSurfaceView {
public void onPause() {
super.onPause();
mapWorkersPause(false);
if (this.enableCompass)
mCompass.disable();
}
@Override
public void onResume() {
super.onResume();
mapWorkersProceed();
if (this.enableCompass)
mCompass.enable();
}
/**
@ -634,7 +631,9 @@ public class MapView extends GLSurfaceView {
* the new map position of this MapView.
*/
void setCenterAndZoom(MapPosition mapPosition) {
Log.d(TAG, "setCenterAndZoom "
+ " lat: " + mapPosition.lat
+ " lon: " + mapPosition.lon);
mMapViewPosition.setMapCenterAndZoomLevel(mapPosition);
redrawTiles();
}
@ -687,7 +686,39 @@ public class MapView extends GLSurfaceView {
public void enableRotation(boolean enable) {
enableRotation = enable;
if (enable && this.enableCompass) {
this.enableCompass = false;
mCompass.disable();
}
}
public void enableCompass(boolean enable) {
if (enable == this.enableCompass)
return;
this.enableCompass = enable;
if (enable)
this.enableRotation = false;
if (enable)
mCompass.enable();
else
mCompass.disable();
}
// /**
// * Sets the visibility of the zoom controls.
// *
// * @param showZoomControls
// * true if the zoom controls should be visible, false otherwise.
// */
// public void setBuiltInZoomControls(boolean showZoomControls) {
// mMapZoomControls.setShowMapZoomControls(showZoomControls);
//
// }
// public final int
// public Handler messageHandler = new Handler() {

View File

@ -60,6 +60,7 @@ public class MapViewPosition {
if (!isValid()) {
return null;
}
// Log.d("MapViewPosition", "lat: " + mLatitude + " lon: " + mLongitude);
return new MapPosition(mLatitude, mLongitude, mZoomLevel, mScale, mRotation);
}
@ -113,7 +114,7 @@ public class MapViewPosition {
double pixelY = MercatorProjection.latitudeToPixelY(mLatitude, mZoomLevel);
double dx, dy;
if (mMapView.enableRotation) {
if (mMapView.enableRotation || mMapView.enableCompass) {
float rad = (float) Math.toRadians(mRotation);
dx = mx / mScale;
dy = my / mScale;
@ -142,6 +143,10 @@ public class MapViewPosition {
mRotation -= angle;
}
public void setRotation(float f) {
mRotation = f;
}
synchronized void setMapCenter(GeoPoint geoPoint) {
mLatitude = MercatorProjection.limitLatitude(geoPoint.getLatitude());
mLongitude = MercatorProjection.limitLongitude(geoPoint.getLongitude());

View File

@ -160,7 +160,7 @@ public class MapZoomControls {
* true if the zoom controls should be visible, false otherwise.
*/
public void setShowMapZoomControls(boolean showMapZoomControls) {
mShowMapZoomControls = false; // showMapZoomControls;
mShowMapZoomControls = false;
}
/**

View File

@ -461,8 +461,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
if (MapView.debugFrameTime)
start = SystemClock.uptimeMillis();
mRotate = mMapView.enableRotation;
if (mRotate != (mMapView.enableRotation || mMapView.enableCompass)) {
Matrix.setIdentityM(mMVPMatrix, 0);
mRotate = mMapView.enableRotation || mMapView.enableCompass;
}
if (mUpdateColor && mClearColor != null) {
glClearColor(mClearColor[0], mClearColor[1], mClearColor[2], mClearColor[3]);
mUpdateColor = false;

View File

@ -19,13 +19,18 @@ import android.util.Log;
class QuadTree {
private static String TAG = "QuadTree";
// pointer to tile 0/0/0
private static QuadTree root;
// parent pointer is used to link pool items
private static QuadTree pool;
// TreeTile members
QuadTree parent;
// .... x y
// 0 => 0 0
// 1 => 1 0
// 2 => 0 1
// 3 => 1 1
final QuadTree[] child = new QuadTree[4];
int refs = 0;
byte id;

View File

@ -79,10 +79,14 @@ class TileLoader {
newTiles = new TilesData(numTiles);
}
static void updateMap(boolean clear) {
static synchronized void updateMap(boolean clear) {
boolean changedPos = false;
boolean changedZoom = false;
if (mMapView == null || mMapView.getMapPosition() == null)
return;
MapPosition mapPosition = mMapView.getMapPosition().getMapPosition();
if (mapPosition == null) {
@ -100,8 +104,6 @@ class TileLoader {
mTiles.clear();
mTilesLoaded.clear();
QuadTree.init();
// curTiles.cnt = 0;
// mBufferMemoryUsage = 0;
}
}
@ -161,24 +163,10 @@ class TileLoader {
limitCache(mapPosition, remove);
}
int size = mTilesLoaded.size();
if (size > MAX_TILES_IN_QUEUE)
limitLoadQueue(size);
limitLoadQueue();
}
/**
* Manage tiles that have data to be uploaded to gl
*
* @param tile
* tile processed by MapGenerator
*/
static void addTileLoaded(MapTile tile) {
synchronized (mTilesLoaded) {
mTilesLoaded.add(tile);
}
}
private static boolean updateVisibleList(MapPosition mapPosition, int zdir) {
double x = mapPosition.x;
double y = mapPosition.y;
@ -398,7 +386,7 @@ class TileLoader {
int removes = remove;
int size = mTiles.size();
int tmp = size;
// int tmp = size;
// remove orphaned tiles
for (int i = 0; i < size;) {
@ -417,7 +405,7 @@ class TileLoader {
i++;
}
Log.d(TAG, "remove tiles: " + removes + " " + size + " " + tmp);
// Log.d(TAG, "remove tiles: " + removes + " " + size + " " + tmp);
if (removes <= 0)
return;
@ -461,8 +449,11 @@ class TileLoader {
}
}
private static void limitLoadQueue(int remove) {
int size = remove;
private static void limitLoadQueue() {
int size = mTilesLoaded.size();
if (size < MAX_TILES_IN_QUEUE)
return;
synchronized (mTilesLoaded) {
@ -481,8 +472,11 @@ class TileLoader {
// clear loaded but not used tiles
if (size < MAX_TILES_IN_QUEUE)
return;
// Log.d(TAG, "queue: " + mTilesLoaded.size() + " " + size + " "
// + (size - MAX_TILES_IN_QUEUE / 2));
for (int i = 0, n = size - MAX_TILES_IN_QUEUE / 2; i < n; n--) {
for (int i = 0, n = size - MAX_TILES_IN_QUEUE + 20; i < n; i++) {
MapTile t = mTilesLoaded.get(i);
synchronized (t) {
@ -493,15 +487,28 @@ class TileLoader {
if (tileInUse(t)) {
// Log.d(TAG, "keep unused tile data: " + t + " " + t.isActive);
i++;
continue;
}
// Log.d(TAG, "remove unused tile data: " + t);
mTilesLoaded.remove(i);
mTiles.remove(t);
// Log.d(TAG, "remove unused tile data: " + t);
clearTile(t);
}
}
}
}
/**
* Manage tiles that have data to be uploaded to gl
*
* @param tile
* tile processed by MapGenerator
*/
static void addTileLoaded(MapTile tile) {
synchronized (mTilesLoaded) {
mTilesLoaded.add(tile);
}
}
}

View File

@ -0,0 +1,254 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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.mapsforge.app;
import org.mapsforge.core.GeoPoint;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
public class LocationHandler {
private static final int DIALOG_LOCATION_PROVIDER_DISABLED = 2;
private MyLocationListener mLocationListener;
private LocationManager mLocationManager;
private boolean mShowMyLocation;
private ToggleButton mSnapToLocationView;
private boolean mSnapToLocation;
/* package */final TileMap mTileMap;
LocationHandler(TileMap tileMap) {
mTileMap = tileMap;
mLocationManager = (LocationManager) tileMap
.getSystemService(Context.LOCATION_SERVICE);
mLocationListener = new MyLocationListener(tileMap);
mSnapToLocationView = (ToggleButton) tileMap
.findViewById(R.id.snapToLocationView);
mSnapToLocationView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (isSnapToLocationEnabled()) {
disableSnapToLocation(true);
} else {
enableSnapToLocation(true);
}
}
});
}
boolean enableShowMyLocation(boolean centerAtFirstFix) {
Log.d("TileMap", "enableShowMyLocation " + mShowMyLocation);
if (!mShowMyLocation) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String bestProvider = mLocationManager.getBestProvider(criteria, true);
if (bestProvider == null) {
mTileMap.showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
return false;
}
mShowMyLocation = true;
Log.d("TileMap", "enableShowMyLocation " + mShowMyLocation);
mLocationListener.setCenterAtFirstFix(centerAtFirstFix);
mLocationManager.requestLocationUpdates(bestProvider, 1000, 0,
mLocationListener);
mSnapToLocationView.setVisibility(View.VISIBLE);
return true;
}
return false;
}
void gotoLastKnownPosition() {
Location currentLocation;
Location bestLocation = null;
for (String provider : mLocationManager.getProviders(true)) {
currentLocation = mLocationManager.getLastKnownLocation(provider);
if (currentLocation == null)
continue;
if (bestLocation == null
|| currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
bestLocation = currentLocation;
}
}
if (bestLocation != null) {
GeoPoint point = new GeoPoint(bestLocation.getLatitude(),
bestLocation.getLongitude());
mTileMap.mMapView.setCenter(point);
} else {
mTileMap.showToastOnUiThread(mTileMap
.getString(R.string.error_last_location_unknown));
}
}
/**
* Disables the "show my location" mode.
*
* @return ...
*/
boolean disableShowMyLocation() {
if (mShowMyLocation) {
mShowMyLocation = false;
disableSnapToLocation(false);
mLocationManager.removeUpdates(mLocationListener);
// if (circleOverlay != null) {
// mapView.getOverlays().remove(circleOverlay);
// mapView.getOverlays().remove(itemizedOverlay);
// circleOverlay = null;
// itemizedOverlay = null;
// }
mSnapToLocationView.setVisibility(View.GONE);
return true;
}
return false;
}
/**
* Returns the status of the "show my location" mode.
*
* @return true if the "show my location" mode is enabled, false otherwise.
*/
boolean isShowMyLocationEnabled() {
return mShowMyLocation;
}
/**
* Disables the "snap to location" mode.
*
* @param showToast
* defines whether a toast message is displayed or not.
*/
void disableSnapToLocation(boolean showToast) {
if (mSnapToLocation) {
mSnapToLocation = false;
mSnapToLocationView.setChecked(false);
mTileMap.mMapView.setClickable(true);
if (showToast) {
mTileMap.showToastOnUiThread(mTileMap
.getString(R.string.snap_to_location_disabled));
}
}
}
/**
* Enables the "snap to location" mode.
*
* @param showToast
* defines whether a toast message is displayed or not.
*/
void enableSnapToLocation(boolean showToast) {
if (!mSnapToLocation) {
mSnapToLocation = true;
mTileMap.mMapView.setClickable(false);
if (showToast) {
mTileMap.showToastOnUiThread(mTileMap
.getString(R.string.snap_to_location_enabled));
}
}
}
/**
* Returns the status of the "snap to location" mode.
*
* @return true if the "snap to location" mode is enabled, false otherwise.
*/
boolean isSnapToLocationEnabled() {
return mSnapToLocation;
}
class MyLocationListener implements LocationListener {
private final TileMap tileMap;
private boolean centerAtFirstFix;
MyLocationListener(TileMap tileMap) {
this.tileMap = tileMap;
}
@Override
public void onLocationChanged(Location location) {
Log.d("LocationListener", "onLocationChanged, "
+ " lon:" + location.getLongitude()
+ " lat:" + location.getLatitude());
if (!isShowMyLocationEnabled()) {
return;
}
GeoPoint point = new GeoPoint(location.getLatitude(), location.getLongitude());
// this.advancedMapViewer.overlayCircle.setCircleData(point, location.getAccuracy());
// this.advancedMapViewer.overlayItem.setPoint(point);
// this.advancedMapViewer.circleOverlay.requestRedraw();
// this.advancedMapViewer.itemizedOverlay.requestRedraw();
if (this.centerAtFirstFix || isSnapToLocationEnabled()) {
this.centerAtFirstFix = false;
this.tileMap.mMapView.setCenter(point);
}
}
@Override
public void onProviderDisabled(String provider) {
// do nothing
}
@Override
public void onProviderEnabled(String provider) {
// do nothing
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// do nothing
}
boolean isCenterAtFirstFix() {
return this.centerAtFirstFix;
}
void setCenterAtFirstFix(boolean centerAtFirstFix) {
this.centerAtFirstFix = centerAtFirstFix;
}
}
}

View File

@ -1,70 +0,0 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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.mapsforge.app;
import org.mapsforge.core.GeoPoint;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
class MyLocationListener implements LocationListener {
private final TileMap advancedMapViewer;
private boolean centerAtFirstFix;
MyLocationListener(TileMap advancedMapViewer) {
this.advancedMapViewer = advancedMapViewer;
}
@Override
public void onLocationChanged(Location location) {
if (!this.advancedMapViewer.isShowMyLocationEnabled()) {
return;
}
GeoPoint point = new GeoPoint(location.getLatitude(), location.getLongitude());
// this.advancedMapViewer.overlayCircle.setCircleData(point, location.getAccuracy());
// this.advancedMapViewer.overlayItem.setPoint(point);
// this.advancedMapViewer.circleOverlay.requestRedraw();
// this.advancedMapViewer.itemizedOverlay.requestRedraw();
if (this.centerAtFirstFix || this.advancedMapViewer.isSnapToLocationEnabled()) {
this.centerAtFirstFix = false;
this.advancedMapViewer.mMapController.setCenter(point);
}
}
@Override
public void onProviderDisabled(String provider) {
// do nothing
}
@Override
public void onProviderEnabled(String provider) {
// do nothing
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// do nothing
}
boolean isCenterAtFirstFix() {
return this.centerAtFirstFix;
}
void setCenterAtFirstFix(boolean centerAtFirstFix) {
this.centerAtFirstFix = centerAtFirstFix;
}
}

View File

@ -1,41 +0,0 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* 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.mapsforge.app;
import android.widget.SeekBar;
import android.widget.TextView;
class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
private final TextView textView;
SeekBarChangeListener(TextView textView) {
this.textView = textView;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
this.textView.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// do nothing
}
}

View File

@ -7,7 +7,6 @@ import java.util.Date;
import org.mapsforge.android.DebugSettings;
import org.mapsforge.android.MapActivity;
import org.mapsforge.android.MapController;
import org.mapsforge.android.MapView;
import org.mapsforge.android.mapgenerator.MapDatabases;
import org.mapsforge.android.rendertheme.InternalRenderTheme;
@ -30,9 +29,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
@ -71,14 +68,12 @@ public class TileMap extends MapActivity {
new FilterByFileExtension(".xml");
private static final int SELECT_MAP_FILE = 0;
private static final int SELECT_RENDER_THEME_FILE = 1;
private LocationManager mLocationManager;
LocationHandler mLocation;
private MapDatabases mMapDatabase;
private MyLocationListener mMyLocationListener;
private boolean mShowMyLocation;
private boolean mSnapToLocation;
// private ToggleButton mSnapToLocationView;
private WakeLock mWakeLock;
MapController mMapController;
MapView mMapView;
private Menu mMenu = null;
@ -108,36 +103,48 @@ public class TileMap extends MapActivity {
case R.id.menu_rotation_enable:
mMapView.enableRotation(true);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_rotation_disable:
mMapView.enableRotation(false);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_compass_enable:
mMapView.enableCompass(true);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_compass_disable:
mMapView.enableCompass(false);
toggleMenuRotation(mMenu,
mMapView.enableRotation,
mMapView.enableCompass);
return true;
case R.id.menu_position_my_location_enable:
if (enableShowMyLocation(true)) {
mMenu.findItem(R.id.menu_position_my_location_enable)
.setVisible(false);
mMenu.findItem(R.id.menu_position_my_location_enable)
.setEnabled(false);
mMenu.findItem(R.id.menu_position_my_location_disable)
.setVisible(true);
mMenu.findItem(R.id.menu_position_my_location_disable)
.setEnabled(true);
}
toggleMenuItem(mMenu,
R.id.menu_position_my_location_enable,
R.id.menu_position_my_location_disable,
!mLocation.enableShowMyLocation(true));
return true;
case R.id.menu_position_my_location_disable:
if (disableShowMyLocation()) {
mMenu.findItem(R.id.menu_position_my_location_enable)
.setVisible(true);
mMenu.findItem(R.id.menu_position_my_location_enable)
.setEnabled(true);
mMenu.findItem(R.id.menu_position_my_location_disable)
.setVisible(false);
mMenu.findItem(R.id.menu_position_my_location_disable)
.setEnabled(false);
}
toggleMenuItem(mMenu,
R.id.menu_position_my_location_enable,
R.id.menu_position_my_location_disable,
mLocation.disableShowMyLocation());
return true;
case R.id.menu_position_last_known:
gotoLastKnownPosition();
mLocation.gotoLastKnownPosition();
return true;
case R.id.menu_position_enter_coordinates:
@ -146,8 +153,9 @@ public class TileMap extends MapActivity {
case R.id.menu_position_map_center:
// disable GPS follow mode if it is enabled
disableSnapToLocation(true);
mMapController.setCenter(mMapView.getMapDatabase()
mLocation.disableSnapToLocation(true);
mMapView.setCenter(mMapView.getMapDatabase()
.getMapFileInfo().mapCenter);
return true;
@ -182,38 +190,68 @@ public class TileMap extends MapActivity {
}
}
private static void toggleMenuRotation(Menu menu, boolean rotate, boolean compass) {
toggleMenuItem(menu,
R.id.menu_rotation_enable,
R.id.menu_rotation_disable,
!rotate);
toggleMenuItem(menu,
R.id.menu_compass_enable,
R.id.menu_compass_disable,
!compass);
}
private static void toggleMenuItem(Menu menu, int id, int id2, boolean enable) {
menu.findItem(id).setVisible(enable);
menu.findItem(id).setEnabled(enable);
menu.findItem(id2).setVisible(!enable);
menu.findItem(id2).setEnabled(!enable);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
onCreateOptionsMenu(menu);
Log.d("TileMap", "prepare options...");
toggleMenuItem(menu,
R.id.menu_position_my_location_enable,
R.id.menu_position_my_location_disable,
!mLocation.isShowMyLocationEnabled());
// menu.findItem(R.id.menu_info_map_file).setEnabled(true);
// if (mLocation.isShowMyLocationEnabled()) {
// menu.findItem(R.id.menu_position_my_location_enable).setVisible(false);
// menu.findItem(R.id.menu_position_my_location_enable).setEnabled(false);
// menu.findItem(R.id.menu_position_my_location_disable).setVisible(true);
// menu.findItem(R.id.menu_position_my_location_disable).setEnabled(true);
// } else {
// menu.findItem(R.id.menu_position_my_location_enable).setVisible(true);
// menu.findItem(R.id.menu_position_my_location_enable).setEnabled(true);
// menu.findItem(R.id.menu_position_my_location_disable).setVisible(false);
// menu.findItem(R.id.menu_position_my_location_disable).setEnabled(false);
// }
if (isShowMyLocationEnabled()) {
menu.findItem(R.id.menu_position_my_location_enable).setVisible(false);
menu.findItem(R.id.menu_position_my_location_enable).setEnabled(false);
menu.findItem(R.id.menu_position_my_location_disable).setVisible(true);
menu.findItem(R.id.menu_position_my_location_disable).setEnabled(true);
menu.findItem(R.id.menu_render_theme).setEnabled(true);
if (mMapDatabase == MapDatabases.MAP_READER) {
menu.findItem(R.id.menu_mapfile).setVisible(true);
menu.findItem(R.id.menu_position_map_center).setVisible(true);
} else {
menu.findItem(R.id.menu_position_my_location_enable).setVisible(true);
menu.findItem(R.id.menu_position_my_location_enable).setEnabled(true);
menu.findItem(R.id.menu_position_my_location_disable).setVisible(false);
menu.findItem(R.id.menu_position_my_location_disable).setEnabled(false);
menu.findItem(R.id.menu_mapfile).setVisible(false);
menu.findItem(R.id.menu_position_map_center).setVisible(false);
}
menu.findItem(R.id.menu_position_map_center).setEnabled(true);
menu.findItem(R.id.menu_render_theme).setEnabled(true);
// menu.findItem(R.id.menu_mapfile).setEnabled(true);
toggleMenuItem(menu,
R.id.menu_compass_enable,
R.id.menu_compass_disable,
!mMapView.enableCompass);
if (mMapDatabase == MapDatabases.MAP_READER)
menu.findItem(R.id.menu_mapfile).setVisible(true);
else
menu.findItem(R.id.menu_mapfile).setVisible(false);
toggleMenuItem(mMenu,
R.id.menu_rotation_enable,
R.id.menu_rotation_disable,
!mMapView.enableRotation);
return super.onPrepareOptionsMenu(menu);
// return true;
}
@Override
@ -225,52 +263,8 @@ public class TileMap extends MapActivity {
private void configureMapView() {
// configure the MapView and activate the zoomLevel buttons
mMapView.setClickable(true);
mMapView.setBuiltInZoomControls(true);
// mMapView.setBuiltInZoomControls(true);
mMapView.setFocusable(true);
mMapController = mMapView.getController();
}
private boolean enableShowMyLocation(boolean centerAtFirstFix) {
if (!mShowMyLocation) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String bestProvider = mLocationManager.getBestProvider(criteria, true);
if (bestProvider == null) {
showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
return false;
}
mShowMyLocation = true;
mMyLocationListener.setCenterAtFirstFix(centerAtFirstFix);
mLocationManager.requestLocationUpdates(bestProvider, 1000, 0,
mMyLocationListener);
// mSnapToLocationView.setVisibility(View.VISIBLE);
return true;
}
return false;
}
private void gotoLastKnownPosition() {
Location currentLocation;
Location bestLocation = null;
for (String provider : mLocationManager.getProviders(true)) {
currentLocation = mLocationManager.getLastKnownLocation(provider);
if (currentLocation == null)
continue;
if (bestLocation == null
|| currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
bestLocation = currentLocation;
}
}
if (bestLocation != null) {
GeoPoint point = new GeoPoint(bestLocation.getLatitude(),
bestLocation.getLongitude());
mMapController.setCenter(point);
} else {
showToastOnUiThread(getString(R.string.error_last_location_unknown));
}
}
private void startMapFilePicker() {
@ -291,7 +285,7 @@ public class TileMap extends MapActivity {
if (requestCode == SELECT_MAP_FILE) {
if (resultCode == RESULT_OK) {
disableSnapToLocation(true);
mLocation.disableSnapToLocation(true);
if (intent != null) {
if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
@ -301,9 +295,6 @@ public class TileMap extends MapActivity {
}
} else if (resultCode == RESULT_CANCELED) {
startActivity(new Intent(this, EditPreferences.class));
// && !mapView.getMapGenerator().requiresInternetConnection()
// && mapView.getMapFile() == null) {
// finish();
}
} else if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK
&& intent != null
@ -334,41 +325,30 @@ public class TileMap extends MapActivity {
}
// set up the layout views
setContentView(R.layout.activity_advanced_map_viewer);
setContentView(R.layout.activity_tilemap);
// getActionBar().setDisplayOptions(ActionBar.NAVIGATION_MODE_TABS);
mMapView = (MapView) findViewById(R.id.mapView);
configureMapView();
// mSnapToLocationView = (ToggleButton) findViewById(R.id.snapToLocationView);
//
// mSnapToLocationView.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View view) {
// if (isSnapToLocationEnabled()) {
// disableSnapToLocation(true);
// } else {
// enableSnapToLocation(true);
// }
// }
// });
mLocation = new LocationHandler(this);
// get the pointers to different system services
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mMyLocationListener = new MyLocationListener(this);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager
.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "AMV");
if (savedInstanceState != null) {
if (savedInstanceState.getBoolean(BUNDLE_SHOW_MY_LOCATION)) {
enableShowMyLocation(savedInstanceState
.getBoolean(BUNDLE_CENTER_AT_FIRST_FIX));
// enableShowMyLocation(savedInstanceState
// .getBoolean(BUNDLE_CENTER_AT_FIRST_FIX));
if (savedInstanceState.getBoolean(BUNDLE_SNAP_TO_LOCATION)) {
enableSnapToLocation(false);
mLocation.enableSnapToLocation(false);
}
}
}
@ -383,12 +363,13 @@ public class TileMap extends MapActivity {
LayoutInflater factory = LayoutInflater.from(this);
final View view = factory.inflate(R.layout.dialog_enter_coordinates, null);
builder.setView(view);
builder.setPositiveButton(R.string.go_to_position,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// disable GPS follow mode if it is enabled
disableSnapToLocation(true);
mLocation.disableSnapToLocation(true);
// set the map center and zoom level
EditText latitudeView = (EditText) view
@ -400,11 +381,13 @@ public class TileMap extends MapActivity {
double longitude = Double.parseDouble(longitudeView.getText()
.toString());
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
TileMap.this.mMapController.setCenter(geoPoint);
TileMap.this.mMapView.setCenter(geoPoint);
SeekBar zoomLevelView = (SeekBar) view
.findViewById(R.id.zoomLevel);
TileMap.this.mMapController.setZoom(zoomLevelView
.getProgress());
TileMap.this.mMapView.zoom((byte) (zoomLevelView
.getProgress() - mMapView.getMapPosition()
.getZoomLevel()));
}
});
builder.setNegativeButton(R.string.cancel, null);
@ -431,7 +414,7 @@ public class TileMap extends MapActivity {
@Override
protected void onDestroy() {
super.onDestroy();
disableShowMyLocation();
mLocation.disableShowMyLocation();
}
@Override
@ -587,6 +570,13 @@ public class TileMap extends MapActivity {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
if (preferences.getBoolean("fixOrientation", true)) {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// this all returns the orientation which is not currently active?!
// getWindow().getWindowManager().getDefaultDisplay().getRotation());
// getWindow().getWindowManager().getDefaultDisplay().getOrientation());
}
if (preferences.getBoolean("wakeLock", false) && !mWakeLock.isHeld()) {
mWakeLock.acquire();
}
@ -628,83 +618,11 @@ public class TileMap extends MapActivity {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(BUNDLE_SHOW_MY_LOCATION, isShowMyLocationEnabled());
outState.putBoolean(BUNDLE_CENTER_AT_FIRST_FIX,
mMyLocationListener.isCenterAtFirstFix());
outState.putBoolean(BUNDLE_SNAP_TO_LOCATION, mSnapToLocation);
}
outState.putBoolean(BUNDLE_SHOW_MY_LOCATION, mLocation.isShowMyLocationEnabled());
// outState.putBoolean(BUNDLE_CENTER_AT_FIRST_FIX,
// mMyLocationListener.isCenterAtFirstFix());
/**
* Disables the "show my location" mode.
*
* @return ...
*/
private boolean disableShowMyLocation() {
if (mShowMyLocation) {
mShowMyLocation = false;
disableSnapToLocation(false);
mLocationManager.removeUpdates(mMyLocationListener);
// if (circleOverlay != null) {
// mapView.getOverlays().remove(circleOverlay);
// mapView.getOverlays().remove(itemizedOverlay);
// circleOverlay = null;
// itemizedOverlay = null;
// }
// mSnapToLocationView.setVisibility(View.GONE);
return true;
}
return false;
}
/**
* Disables the "snap to location" mode.
*
* @param showToast
* defines whether a toast message is displayed or not.
*/
void disableSnapToLocation(boolean showToast) {
if (mSnapToLocation) {
mSnapToLocation = false;
// mSnapToLocationView.setChecked(false);
mMapView.setClickable(true);
if (showToast) {
showToastOnUiThread(getString(R.string.snap_to_location_disabled));
}
}
}
/**
* Enables the "snap to location" mode.
*
* @param showToast
* defines whether a toast message is displayed or not.
*/
void enableSnapToLocation(boolean showToast) {
if (!mSnapToLocation) {
mSnapToLocation = true;
mMapView.setClickable(false);
if (showToast) {
showToastOnUiThread(getString(R.string.snap_to_location_enabled));
}
}
}
/**
* Returns the status of the "show my location" mode.
*
* @return true if the "show my location" mode is enabled, false otherwise.
*/
boolean isShowMyLocationEnabled() {
return mShowMyLocation;
}
/**
* Returns the status of the "snap to location" mode.
*
* @return true if the "snap to location" mode is enabled, false otherwise.
*/
boolean isSnapToLocationEnabled() {
return mSnapToLocation;
// outState.putBoolean(BUNDLE_SNAP_TO_LOCATION, mSnapToLocation);
}
/**
@ -734,4 +652,28 @@ public class TileMap extends MapActivity {
// // TODO Auto-generated method stub
// return false;
// }
class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
private final TextView textView;
SeekBarChangeListener(TextView textView) {
this.textView = textView;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
this.textView.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// do nothing
}
}
}