refactor VectorTileMap
This commit is contained in:
@@ -17,9 +17,7 @@ package org.mapsforge.android;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.mapsforge.android.inputhandling.MapMover;
|
||||
import org.mapsforge.android.inputhandling.TouchHandler;
|
||||
import org.mapsforge.android.inputhandling.ZoomAnimator;
|
||||
import org.mapsforge.android.mapgenerator.JobParameters;
|
||||
import org.mapsforge.android.mapgenerator.JobQueue;
|
||||
import org.mapsforge.android.mapgenerator.JobTheme;
|
||||
@@ -33,15 +31,14 @@ import org.mapsforge.android.rendertheme.InternalRenderTheme;
|
||||
import org.mapsforge.android.utils.GlConfigChooser;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.MapPosition;
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.mapdatabase.mapfile.MapDatabase;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
|
||||
import android.content.Context;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
@@ -70,14 +67,15 @@ public class MapView extends GLSurfaceView {
|
||||
private static final float DEFAULT_TEXT_SCALE = 1;
|
||||
|
||||
private final MapController mMapController;
|
||||
private final MapMover mMapMover;
|
||||
// private final MapMover mMapMover;
|
||||
// private final ZoomAnimator mZoomAnimator;
|
||||
|
||||
private final MapScaleBar mMapScaleBar;
|
||||
private final MapViewPosition mMapViewPosition;
|
||||
|
||||
private final MapZoomControls mMapZoomControls;
|
||||
private final Projection mProjection;
|
||||
private final TouchHandler mTouchEventHandler;
|
||||
private final ZoomAnimator mZoomAnimator;
|
||||
|
||||
private IMapDatabase mMapDatabase;
|
||||
private MapGenerator mMapGenerator;
|
||||
@@ -151,10 +149,10 @@ public class MapView extends GLSurfaceView {
|
||||
mJobQueue = new JobQueue(this);
|
||||
mMapWorker = new MapWorker(this);
|
||||
mMapWorker.start();
|
||||
mMapMover = new MapMover(this);
|
||||
mMapMover.start();
|
||||
mZoomAnimator = new ZoomAnimator(this);
|
||||
mZoomAnimator.start();
|
||||
// mMapMover = new MapMover(this);
|
||||
// mMapMover.start();
|
||||
// mZoomAnimator = new ZoomAnimator(this);
|
||||
// mZoomAnimator.start();
|
||||
|
||||
setMapGeneratorInternal(mapGenerator);
|
||||
|
||||
@@ -232,12 +230,12 @@ public class MapView extends GLSurfaceView {
|
||||
return mMapGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the MapMover which is used by this MapView.
|
||||
*/
|
||||
public MapMover getMapMover() {
|
||||
return mMapMover;
|
||||
}
|
||||
// /**
|
||||
// * @return the MapMover which is used by this MapView.
|
||||
// */
|
||||
// public MapMover getMapMover() {
|
||||
// return mMapMover;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the current position and zoom level of this MapView.
|
||||
@@ -267,32 +265,32 @@ public class MapView extends GLSurfaceView {
|
||||
return mProjection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the ZoomAnimator is currently running, false otherwise.
|
||||
*/
|
||||
public boolean isZoomAnimatorRunning() {
|
||||
return mZoomAnimator.isExecuting();
|
||||
}
|
||||
// /**
|
||||
// * @return true if the ZoomAnimator is currently running, false otherwise.
|
||||
// */
|
||||
// public boolean isZoomAnimatorRunning() {
|
||||
// return mZoomAnimator.isExecuting();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
|
||||
return mMapMover.onKeyDown(keyCode, keyEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
|
||||
return mMapMover.onKeyUp(keyCode, keyEvent);
|
||||
}
|
||||
// @Override
|
||||
// public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
|
||||
// return mMapMover.onKeyDown(keyCode, keyEvent);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
|
||||
// return mMapMover.onKeyUp(keyCode, keyEvent);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent motionEvent) {
|
||||
return mTouchEventHandler.handleMotionEvent(motionEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTrackballEvent(MotionEvent motionEvent) {
|
||||
return mMapMover.onTrackballEvent(motionEvent);
|
||||
}
|
||||
// @Override
|
||||
// public boolean onTrackballEvent(MotionEvent motionEvent) {
|
||||
// return mMapMover.onTrackballEvent(motionEvent);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Calculates all necessary tiles and adds jobs accordingly.
|
||||
@@ -365,17 +363,16 @@ public class MapView extends GLSurfaceView {
|
||||
return false;
|
||||
}
|
||||
|
||||
mZoomAnimator.pause();
|
||||
// mZoomAnimator.pause();
|
||||
// mMapMover.pause();
|
||||
mMapWorker.pause();
|
||||
mMapMover.pause();
|
||||
mZoomAnimator.awaitPausing();
|
||||
mMapMover.awaitPausing();
|
||||
// mZoomAnimator.awaitPausing();
|
||||
// mMapMover.awaitPausing();
|
||||
mMapWorker.awaitPausing();
|
||||
mMapMover.stopMove();
|
||||
|
||||
mZoomAnimator.proceed();
|
||||
// mZoomAnimator.proceed();
|
||||
// mMapMover.stopMove();
|
||||
// mMapMover.proceed();
|
||||
mMapWorker.proceed();
|
||||
mMapMover.proceed();
|
||||
|
||||
mMapDatabase.closeFile();
|
||||
FileOpenResult fileOpenResult = mMapDatabase.openFile(new File(mapFile));
|
||||
@@ -588,9 +585,9 @@ public class MapView extends GLSurfaceView {
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
mMapMover.interrupt();
|
||||
// mMapMover.interrupt();
|
||||
mMapWorker.interrupt();
|
||||
mZoomAnimator.interrupt();
|
||||
// mZoomAnimator.interrupt();
|
||||
|
||||
try {
|
||||
mMapWorker.join();
|
||||
@@ -617,10 +614,9 @@ public class MapView extends GLSurfaceView {
|
||||
boolean hasValidCenter() {
|
||||
if (!mMapViewPosition.isValid()) {
|
||||
return false;
|
||||
} else if (!mMapGenerator.requiresInternetConnection() &&
|
||||
(!mMapDatabase.hasOpenFile() ||
|
||||
!mMapDatabase.getMapFileInfo().boundingBox
|
||||
.contains(getMapPosition().getMapCenter()))) {
|
||||
} else if (!mMapGenerator.requiresInternetConnection()
|
||||
&& (!mMapDatabase.hasOpenFile() || !mMapDatabase.getMapFileInfo().boundingBox.contains(getMapPosition()
|
||||
.getMapCenter()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -635,16 +631,16 @@ public class MapView extends GLSurfaceView {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapWorker.pause();
|
||||
mMapMover.pause();
|
||||
mZoomAnimator.pause();
|
||||
// mMapMover.pause();
|
||||
// mZoomAnimator.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapWorker.proceed();
|
||||
mMapMover.proceed();
|
||||
mZoomAnimator.proceed();
|
||||
// mMapMover.proceed();
|
||||
// mZoomAnimator.proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,9 +33,9 @@ import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.SphericalMercator;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.mapdatabase.IMapDatabaseCallback;
|
||||
import org.mapsforge.mapdatabase.MapFileInfo;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
package org.mapsforge.android.mapgenerator;
|
||||
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
|
||||
import android.util.AttributeSet;
|
||||
|
||||
@@ -33,7 +33,7 @@ public final class MapDatabaseFactory {
|
||||
public static IMapDatabase createMapDatabase(AttributeSet attributeSet) {
|
||||
String mapDatabaseName = attributeSet.getAttributeValue(null, MAP_DATABASE_ATTRIBUTE_NAME);
|
||||
if (mapDatabaseName == null) {
|
||||
return new org.mapsforge.mapdatabase.mapfile.MapDatabase();
|
||||
return new org.mapsforge.database.mapfile.MapDatabase();
|
||||
}
|
||||
|
||||
MapDatabaseInternal mapDatabaseInternal = MapDatabaseInternal.valueOf(mapDatabaseName);
|
||||
@@ -48,11 +48,11 @@ public final class MapDatabaseFactory {
|
||||
public static IMapDatabase createMapDatabase(MapDatabaseInternal mapDatabaseInternal) {
|
||||
switch (mapDatabaseInternal) {
|
||||
case MAP_READER:
|
||||
return new org.mapsforge.mapdatabase.mapfile.MapDatabase();
|
||||
return new org.mapsforge.database.mapfile.MapDatabase();
|
||||
case JSON_READER:
|
||||
return new org.mapsforge.mapdatabase.json.MapDatabase();
|
||||
return new org.mapsforge.database.json.MapDatabase();
|
||||
case POSTGIS_READER:
|
||||
return new org.mapsforge.mapdatabase.postgis.MapDatabase();
|
||||
return new org.mapsforge.database.postgis.MapDatabase();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.mapsforge.android.mapgenerator;
|
||||
import org.mapsforge.android.MapRenderer;
|
||||
import org.mapsforge.android.MapView;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
|
||||
/**
|
||||
* A MapGenerator provides map tiles either by downloading or rendering them.
|
||||
|
||||
@@ -385,7 +385,7 @@
|
||||
stroke-linecap="butt" />
|
||||
</rule>
|
||||
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-min="16">
|
||||
<line stroke="#c1bcb6" stroke-width="0.25" stroke-linecap="butt" />
|
||||
<line stroke="#c1bcb6" stroke-width="0.2" stroke-linecap="butt" />
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ import org.mapsforge.android.rendertheme.renderinstruction.Line;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.mapdatabase.IMapDatabaseCallback;
|
||||
import org.mapsforge.mapdatabase.MapFileInfo;
|
||||
import org.mapsforge.mapdatabase.mapfile.MapDatabase;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase;
|
||||
package org.mapsforge.database;
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase;
|
||||
package org.mapsforge.database;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
* 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.mapdatabase;
|
||||
package org.mapsforge.database;
|
||||
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.mapdatabase.mapfile.MapDatabase;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
|
||||
/**
|
||||
* Callback methods which can be triggered from the {@link MapDatabase}.
|
||||
@@ -12,11 +12,11 @@
|
||||
* 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.mapdatabase;
|
||||
package org.mapsforge.database;
|
||||
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.mapdatabase.mapfile.MapDatabase;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
|
||||
/**
|
||||
* Contains the immutable metadata of a map file.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.json;
|
||||
package org.mapsforge.database.json;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -20,10 +20,10 @@ import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.MercatorProjection;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.mapdatabase.IMapDatabaseCallback;
|
||||
import org.mapsforge.mapdatabase.MapFileInfo;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
/**
|
||||
* This utility class contains methods to convert byte arrays to numbers.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
@@ -21,7 +21,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.mapsforge.core.LRUCache;
|
||||
import org.mapsforge.mapdatabase.mapfile.header.SubFileParameter;
|
||||
import org.mapsforge.database.mapfile.header.SubFileParameter;
|
||||
|
||||
/**
|
||||
* A cache for database index blocks with a fixed size and LRU policy.
|
||||
@@ -12,9 +12,9 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
import org.mapsforge.mapdatabase.mapfile.header.SubFileParameter;
|
||||
import org.mapsforge.database.mapfile.header.SubFileParameter;
|
||||
|
||||
/**
|
||||
* An immutable container class which is the key for the index cache.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -23,12 +23,12 @@ import java.util.logging.Logger;
|
||||
import org.mapsforge.core.MercatorProjection;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.mapdatabase.IMapDatabaseCallback;
|
||||
import org.mapsforge.mapdatabase.mapfile.header.MapFileHeader;
|
||||
import org.mapsforge.mapdatabase.mapfile.header.MapFileInfo;
|
||||
import org.mapsforge.mapdatabase.mapfile.header.SubFileParameter;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.mapfile.header.MapFileHeader;
|
||||
import org.mapsforge.database.mapfile.header.MapFileInfo;
|
||||
import org.mapsforge.database.mapfile.header.SubFileParameter;
|
||||
|
||||
/**
|
||||
* A class for reading binary map files.
|
||||
@@ -227,6 +227,9 @@ public class MapDatabase implements IMapDatabase {
|
||||
*/
|
||||
@Override
|
||||
public void executeQuery(Tile tile, IMapDatabaseCallback mapDatabaseCallback) {
|
||||
if (mMapFileHeader == null)
|
||||
return;
|
||||
|
||||
if (mIntBuffer == null)
|
||||
mIntBuffer = new int[MAXIMUM_WAY_NODES_SEQUENCE_LENGTH * 2];
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.mapdatabase.mapfile.header.SubFileParameter;
|
||||
import org.mapsforge.database.mapfile.header.SubFileParameter;
|
||||
|
||||
final class QueryCalculations {
|
||||
private static int getFirstLevelTileBitmask(Tile tile) {
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
class QueryParameters {
|
||||
long fromBaseTileX;
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile;
|
||||
package org.mapsforge.database.mapfile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
@@ -12,12 +12,12 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.mapfile.ReadBuffer;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.mapfile.ReadBuffer;
|
||||
|
||||
/**
|
||||
* Reads and validates the header data from a binary map file.
|
||||
@@ -12,17 +12,17 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.mapdatabase.mapfile.MapDatabase;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
|
||||
/**
|
||||
* Contains the immutable metadata of a map file.
|
||||
*
|
||||
* @see MapDatabase#getMapFileInfo()
|
||||
*/
|
||||
public class MapFileInfo extends org.mapsforge.mapdatabase.MapFileInfo {
|
||||
public class MapFileInfo extends org.mapsforge.database.MapFileInfo {
|
||||
|
||||
/**
|
||||
* True if the map file includes debug information, false otherwise.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.Tag;
|
||||
@@ -12,11 +12,11 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.mapfile.ReadBuffer;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.mapfile.ReadBuffer;
|
||||
|
||||
final class OptionalFields {
|
||||
/**
|
||||
@@ -12,14 +12,14 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.mapfile.ReadBuffer;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.mapfile.ReadBuffer;
|
||||
|
||||
final class RequiredFields {
|
||||
/**
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import org.mapsforge.core.MercatorProjection;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.mapfile.header;
|
||||
package org.mapsforge.database.mapfile.header;
|
||||
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* $Id: Geometry.java 9324 2012-02-27 22:08:12Z pramsey $
|
||||
*/
|
||||
|
||||
package org.mapsforge.mapdatabase.postgis;
|
||||
package org.mapsforge.database.postgis;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* 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.mapdatabase.postgis;
|
||||
package org.mapsforge.database.postgis;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
@@ -29,10 +29,10 @@ import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.SphericalMercator;
|
||||
import org.mapsforge.core.Tag;
|
||||
import org.mapsforge.core.Tile;
|
||||
import org.mapsforge.mapdatabase.FileOpenResult;
|
||||
import org.mapsforge.mapdatabase.IMapDatabase;
|
||||
import org.mapsforge.mapdatabase.IMapDatabaseCallback;
|
||||
import org.mapsforge.mapdatabase.MapFileInfo;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.IMapDatabaseCallback;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.postgresql.PGConnection;
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
package org.mapsforge.mapdatabase.postgis;
|
||||
package org.mapsforge.database.postgis;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -22,7 +22,7 @@
|
||||
* $Id: ValueGetter.java 9324 2012-02-27 22:08:12Z pramsey $
|
||||
*/
|
||||
|
||||
package org.mapsforge.mapdatabase.postgis;
|
||||
package org.mapsforge.database.postgis;
|
||||
|
||||
abstract class ValueGetter {
|
||||
byte[] data;
|
||||
63
src/org/mapsforge/tilemap/FileUtils.java
Normal file
63
src/org/mapsforge/tilemap/FileUtils.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.tilemap;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import org.mapsforge.tilemap.R;
|
||||
|
||||
final class FileUtils {
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.00 ");
|
||||
private static final double ONE_GIGABYTE = 1000000000;
|
||||
private static final double ONE_KILOBYTE = 1000;
|
||||
private static final double ONE_MEGABYTE = 1000000;
|
||||
|
||||
/**
|
||||
* Formats the given file size as a human readable string, using SI prefixes.
|
||||
*
|
||||
* @param fileSize
|
||||
* the file size to be formatted.
|
||||
* @param resources
|
||||
* a reference to the application resources.
|
||||
* @return a human readable file size.
|
||||
* @throws IllegalArgumentException
|
||||
* if the given file size is negative.
|
||||
*/
|
||||
static String formatFileSize(long fileSize, Resources resources) {
|
||||
if (fileSize < 0) {
|
||||
throw new IllegalArgumentException("invalid file size: " + fileSize);
|
||||
} else if (fileSize < 1000) {
|
||||
if (fileSize == 1) {
|
||||
// singular
|
||||
return "1 " + resources.getString(R.string.file_size_byte);
|
||||
}
|
||||
|
||||
// plural, including zero
|
||||
return fileSize + " " + resources.getString(R.string.file_size_bytes);
|
||||
} else {
|
||||
if (fileSize < ONE_MEGABYTE) {
|
||||
return DECIMAL_FORMAT.format(fileSize / ONE_KILOBYTE) + resources.getString(R.string.file_size_kb);
|
||||
} else if (fileSize < ONE_GIGABYTE) {
|
||||
return DECIMAL_FORMAT.format(fileSize / ONE_MEGABYTE) + resources.getString(R.string.file_size_mb);
|
||||
}
|
||||
return DECIMAL_FORMAT.format(fileSize / ONE_GIGABYTE) + resources.getString(R.string.file_size_gb);
|
||||
}
|
||||
}
|
||||
|
||||
private FileUtils() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
47
src/org/mapsforge/tilemap/InfoView.java
Normal file
47
src/org/mapsforge/tilemap/InfoView.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.tilemap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/**
|
||||
* Simple activity to display the info web page from the assets folder.
|
||||
*/
|
||||
public class InfoView extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
WebView webView = new WebView(this);
|
||||
webView.loadUrl("file:///android_asset/info.xml");
|
||||
setContentView(webView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// check if the full screen mode should be activated
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
src/org/mapsforge/tilemap/MyLocationListener.java
Normal file
70
src/org/mapsforge/tilemap/MyLocationListener.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.tilemap;
|
||||
|
||||
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.mapController.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;
|
||||
}
|
||||
}
|
||||
41
src/org/mapsforge/tilemap/SeekBarChangeListener.java
Normal file
41
src/org/mapsforge/tilemap/SeekBarChangeListener.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.tilemap;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
635
src/org/mapsforge/tilemap/TileMap.java
Executable file
635
src/org/mapsforge/tilemap/TileMap.java
Executable file
@@ -0,0 +1,635 @@
|
||||
package org.mapsforge.tilemap;
|
||||
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mapsforge.android.DebugSettings;
|
||||
import org.mapsforge.android.MapActivity;
|
||||
import org.mapsforge.android.MapController;
|
||||
import org.mapsforge.android.MapScaleBar;
|
||||
import org.mapsforge.android.MapView;
|
||||
import org.mapsforge.android.mapgenerator.MapDatabaseFactory;
|
||||
import org.mapsforge.android.mapgenerator.MapDatabaseInternal;
|
||||
import org.mapsforge.android.mapgenerator.MapGenerator;
|
||||
import org.mapsforge.android.rendertheme.InternalRenderTheme;
|
||||
import org.mapsforge.android.utils.AndroidUtils;
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.MapFileInfo;
|
||||
import org.mapsforge.tilemap.filefilter.FilterByFileExtension;
|
||||
import org.mapsforge.tilemap.filefilter.ValidMapFile;
|
||||
import org.mapsforge.tilemap.filefilter.ValidRenderTheme;
|
||||
import org.mapsforge.tilemap.filepicker.FilePicker;
|
||||
import org.mapsforge.tilemap.preferences.EditPreferences;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
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.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
/**
|
||||
* A map application which uses the features from the mapsforge map library. The map can be centered to the current
|
||||
* location. A simple file browser for selecting the map file is also included. Some preferences can be adjusted via the
|
||||
* {@link EditPreferences} activity.
|
||||
*/
|
||||
public class TileMap extends MapActivity {
|
||||
private static final String BUNDLE_CENTER_AT_FIRST_FIX = "centerAtFirstFix";
|
||||
private static final String BUNDLE_SHOW_MY_LOCATION = "showMyLocation";
|
||||
private static final String BUNDLE_SNAP_TO_LOCATION = "snapToLocation";
|
||||
private static final int DIALOG_ENTER_COORDINATES = 0;
|
||||
private static final int DIALOG_INFO_MAP_FILE = 1;
|
||||
private static final int DIALOG_LOCATION_PROVIDER_DISABLED = 2;
|
||||
private static final FileFilter FILE_FILTER_EXTENSION_MAP = new FilterByFileExtension(".map");
|
||||
private static final FileFilter FILE_FILTER_EXTENSION_XML = new FilterByFileExtension(".xml");
|
||||
private static final int SELECT_MAP_FILE = 0;
|
||||
private static final int SELECT_RENDER_THEME_FILE = 1;
|
||||
private LocationManager locationManager;
|
||||
private MapDatabaseInternal mapDatabaseInternal;
|
||||
private MyLocationListener myLocationListener;
|
||||
private boolean showMyLocation;
|
||||
private boolean snapToLocation;
|
||||
private ToggleButton snapToLocationView;
|
||||
private WakeLock wakeLock;
|
||||
MapController mapController;
|
||||
MapView mapView;
|
||||
private Menu mMenu = null;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.options_menu, menu);
|
||||
mMenu = menu;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_info:
|
||||
return true;
|
||||
|
||||
case R.id.menu_info_map_file:
|
||||
showDialog(DIALOG_INFO_MAP_FILE);
|
||||
return true;
|
||||
|
||||
case R.id.menu_position:
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_last_known:
|
||||
gotoLastKnownPosition();
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_enter_coordinates:
|
||||
showDialog(DIALOG_ENTER_COORDINATES);
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_map_center:
|
||||
// disable GPS follow mode if it is enabled
|
||||
disableSnapToLocation(true);
|
||||
this.mapController.setCenter(this.mapView.getMapDatabase().getMapFileInfo().mapCenter);
|
||||
return true;
|
||||
|
||||
case R.id.menu_preferences:
|
||||
startActivity(new Intent(this, EditPreferences.class));
|
||||
return true;
|
||||
|
||||
case R.id.menu_render_theme:
|
||||
return true;
|
||||
|
||||
case R.id.menu_render_theme_osmarender:
|
||||
this.mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
||||
return true;
|
||||
|
||||
case R.id.menu_render_theme_select_file:
|
||||
startRenderThemePicker();
|
||||
return true;
|
||||
|
||||
case R.id.menu_mapfile:
|
||||
startMapFilePicker();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MapGenerator mapGenerator = this.mapView.getMapGenerator();
|
||||
|
||||
if (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_info_map_file).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_info_map_file).setEnabled(true);
|
||||
}
|
||||
|
||||
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);
|
||||
} 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 (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_position_map_center).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_position_map_center).setEnabled(true);
|
||||
}
|
||||
|
||||
if (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_render_theme).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_render_theme).setEnabled(true);
|
||||
}
|
||||
|
||||
if (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_mapfile).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_mapfile).setEnabled(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTrackballEvent(MotionEvent event) {
|
||||
// forward the event to the MapView
|
||||
return this.mapView.onTrackballEvent(event);
|
||||
}
|
||||
|
||||
private void configureMapView() {
|
||||
// configure the MapView and activate the zoomLevel buttons
|
||||
this.mapView.setClickable(true);
|
||||
this.mapView.setBuiltInZoomControls(true);
|
||||
this.mapView.setFocusable(true);
|
||||
|
||||
this.mapController = this.mapView.getController();
|
||||
}
|
||||
|
||||
private boolean enableShowMyLocation(boolean centerAtFirstFix) {
|
||||
if (!this.showMyLocation) {
|
||||
Criteria criteria = new Criteria();
|
||||
criteria.setAccuracy(Criteria.ACCURACY_FINE);
|
||||
String bestProvider = this.locationManager.getBestProvider(criteria, true);
|
||||
if (bestProvider == null) {
|
||||
showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.showMyLocation = true;
|
||||
this.myLocationListener.setCenterAtFirstFix(centerAtFirstFix);
|
||||
this.locationManager.requestLocationUpdates(bestProvider, 1000, 0, this.myLocationListener);
|
||||
this.snapToLocationView.setVisibility(View.VISIBLE);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void gotoLastKnownPosition() {
|
||||
Location currentLocation;
|
||||
Location bestLocation = null;
|
||||
for (String provider : this.locationManager.getProviders(true)) {
|
||||
currentLocation = this.locationManager.getLastKnownLocation(provider);
|
||||
if (bestLocation == null || currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
|
||||
bestLocation = currentLocation;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestLocation != null) {
|
||||
GeoPoint point = new GeoPoint(bestLocation.getLatitude(), bestLocation.getLongitude());
|
||||
this.mapController.setCenter(point);
|
||||
} else {
|
||||
showToastOnUiThread(getString(R.string.error_last_location_unknown));
|
||||
}
|
||||
}
|
||||
|
||||
private void startMapFilePicker() {
|
||||
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_MAP);
|
||||
FilePicker.setFileSelectFilter(new ValidMapFile());
|
||||
startActivityForResult(new Intent(this, FilePicker.class), SELECT_MAP_FILE);
|
||||
}
|
||||
|
||||
private void startRenderThemePicker() {
|
||||
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_XML);
|
||||
FilePicker.setFileSelectFilter(new ValidRenderTheme());
|
||||
startActivityForResult(new Intent(this, FilePicker.class), SELECT_RENDER_THEME_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (requestCode == SELECT_MAP_FILE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
disableSnapToLocation(true);
|
||||
if (intent != null && intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
||||
this.mapView.setMapFile(intent.getStringExtra(FilePicker.SELECTED_FILE));
|
||||
}
|
||||
} else if (resultCode == RESULT_CANCELED && !this.mapView.getMapGenerator().requiresInternetConnection()
|
||||
&& this.mapView.getMapFile() == null) {
|
||||
finish();
|
||||
}
|
||||
} else if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK && intent != null
|
||||
&& intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
||||
try {
|
||||
this.mapView.setRenderTheme(intent.getStringExtra(FilePicker.SELECTED_FILE));
|
||||
} catch (FileNotFoundException e) {
|
||||
showToastOnUiThread(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
// set up the layout views
|
||||
setContentView(R.layout.activity_advanced_map_viewer);
|
||||
this.mapView = (MapView) findViewById(R.id.mapView);
|
||||
configureMapView();
|
||||
|
||||
this.snapToLocationView = (ToggleButton) findViewById(R.id.snapToLocationView);
|
||||
this.snapToLocationView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (isSnapToLocationEnabled()) {
|
||||
disableSnapToLocation(true);
|
||||
} else {
|
||||
enableSnapToLocation(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// get the pointers to different system services
|
||||
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
this.myLocationListener = new MyLocationListener(this);
|
||||
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
this.wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "AMV");
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.getBoolean(BUNDLE_SHOW_MY_LOCATION)) {
|
||||
enableShowMyLocation(savedInstanceState.getBoolean(BUNDLE_CENTER_AT_FIRST_FIX));
|
||||
if (savedInstanceState.getBoolean(BUNDLE_SNAP_TO_LOCATION)) {
|
||||
enableSnapToLocation(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
if (id == DIALOG_ENTER_COORDINATES) {
|
||||
builder.setIcon(android.R.drawable.ic_menu_mylocation);
|
||||
builder.setTitle(R.string.menu_position_enter_coordinates);
|
||||
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);
|
||||
|
||||
// set the map center and zoom level
|
||||
EditText latitudeView = (EditText) view.findViewById(R.id.latitude);
|
||||
EditText longitudeView = (EditText) view.findViewById(R.id.longitude);
|
||||
double latitude = Double.parseDouble(latitudeView.getText().toString());
|
||||
double longitude = Double.parseDouble(longitudeView.getText().toString());
|
||||
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
|
||||
TileMap.this.mapController.setCenter(geoPoint);
|
||||
SeekBar zoomLevelView = (SeekBar) view.findViewById(R.id.zoomLevel);
|
||||
TileMap.this.mapController.setZoom(zoomLevelView.getProgress());
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
return builder.create();
|
||||
} else if (id == DIALOG_LOCATION_PROVIDER_DISABLED) {
|
||||
builder.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
builder.setTitle(R.string.error);
|
||||
builder.setMessage(R.string.no_location_provider_available);
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
return builder.create();
|
||||
} else if (id == DIALOG_INFO_MAP_FILE) {
|
||||
builder.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
builder.setTitle(R.string.menu_info_map_file);
|
||||
LayoutInflater factory = LayoutInflater.from(this);
|
||||
builder.setView(factory.inflate(R.layout.dialog_info_map_file, null));
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
return builder.create();
|
||||
} else {
|
||||
// do dialog will be created
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
disableShowMyLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
// release the wake lock if necessary
|
||||
if (this.wakeLock.isHeld()) {
|
||||
this.wakeLock.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, final Dialog dialog) {
|
||||
if (id == DIALOG_ENTER_COORDINATES) {
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.latitude);
|
||||
GeoPoint mapCenter = this.mapView.getMapPosition().getMapCenter();
|
||||
editText.setText(Double.toString(mapCenter.getLatitude()));
|
||||
|
||||
editText = (EditText) dialog.findViewById(R.id.longitude);
|
||||
editText.setText(Double.toString(mapCenter.getLongitude()));
|
||||
|
||||
SeekBar zoomlevel = (SeekBar) dialog.findViewById(R.id.zoomLevel);
|
||||
zoomlevel.setMax(this.mapView.getMapGenerator().getZoomLevelMax());
|
||||
zoomlevel.setProgress(this.mapView.getMapPosition().getZoomLevel());
|
||||
|
||||
final TextView textView = (TextView) dialog.findViewById(R.id.zoomlevelValue);
|
||||
textView.setText(String.valueOf(zoomlevel.getProgress()));
|
||||
zoomlevel.setOnSeekBarChangeListener(new SeekBarChangeListener(textView));
|
||||
} else if (id == DIALOG_INFO_MAP_FILE) {
|
||||
MapFileInfo mapFileInfo = this.mapView.getMapDatabase().getMapFileInfo();
|
||||
|
||||
TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
|
||||
textView.setText(this.mapView.getMapFile());
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
|
||||
textView.setText(FileUtils.formatFileSize(mapFileInfo.fileSize, getResources()));
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
|
||||
textView.setText(String.valueOf(mapFileInfo.fileVersion));
|
||||
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug);
|
||||
// if (mapFileInfo.debugFile) {
|
||||
// textView.setText(R.string.info_map_file_debug_yes);
|
||||
// } else {
|
||||
// textView.setText(R.string.info_map_file_debug_no);
|
||||
// }
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDate);
|
||||
Date date = new Date(mapFileInfo.mapDate);
|
||||
textView.setText(DateFormat.getDateTimeInstance().format(date));
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea);
|
||||
BoundingBox boundingBox = mapFileInfo.boundingBox;
|
||||
textView.setText(boundingBox.getMinLatitude() + ", " + boundingBox.getMinLongitude() + " - \n"
|
||||
+ boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude());
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition);
|
||||
GeoPoint startPosition = mapFileInfo.startPosition;
|
||||
if (startPosition == null) {
|
||||
textView.setText(null);
|
||||
} else {
|
||||
textView.setText(startPosition.getLatitude() + ", " + startPosition.getLongitude());
|
||||
}
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
|
||||
Byte startZoomLevel = mapFileInfo.startZoomLevel;
|
||||
if (startZoomLevel == null) {
|
||||
textView.setText(null);
|
||||
} else {
|
||||
textView.setText(startZoomLevel.toString());
|
||||
}
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewLanguagePreference);
|
||||
textView.setText(mapFileInfo.languagePreference);
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
|
||||
textView.setText(mapFileInfo.comment);
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewCreatedBy);
|
||||
textView.setText(mapFileInfo.createdBy);
|
||||
} else {
|
||||
super.onPrepareDialog(id, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
MapScaleBar mapScaleBar = this.mapView.getMapScaleBar();
|
||||
mapScaleBar.setShowMapScaleBar(preferences.getBoolean("showScaleBar", false));
|
||||
String scaleBarUnitDefault = getString(R.string.preferences_scale_bar_unit_default);
|
||||
String scaleBarUnit = preferences.getString("scaleBarUnit", scaleBarUnitDefault);
|
||||
mapScaleBar.setImperialUnits(scaleBarUnit.equals("imperial"));
|
||||
|
||||
// if (preferences.contains("mapGenerator")) {
|
||||
// String name = preferences.getString("mapGenerator", MapGeneratorInternal.SW_RENDERER.name());
|
||||
// MapGeneratorInternal mapGeneratorInternalNew;
|
||||
// try {
|
||||
// mapGeneratorInternalNew = MapGeneratorInternal.valueOf(name);
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// mapGeneratorInternalNew = MapGeneratorInternal.SW_RENDERER;
|
||||
// }
|
||||
//
|
||||
// if (mapGeneratorInternalNew != this.mapGeneratorInternal) {
|
||||
// MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(mapGeneratorInternalNew);
|
||||
// this.mapView.setMapGenerator(mapGenerator);
|
||||
// this.mapGeneratorInternal = mapGeneratorInternalNew;
|
||||
// }
|
||||
// }
|
||||
if (preferences.contains("mapDatabase")) {
|
||||
String name = preferences.getString("mapDatabase", MapDatabaseInternal.MAP_READER.name());
|
||||
MapDatabaseInternal mapDatabaseInternalNew;
|
||||
try {
|
||||
mapDatabaseInternalNew = MapDatabaseInternal.valueOf(name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
mapDatabaseInternalNew = MapDatabaseInternal.MAP_READER;
|
||||
}
|
||||
Log.d("VectorTileMap", "set map database " + mapDatabaseInternalNew);
|
||||
|
||||
if (mapDatabaseInternalNew != this.mapDatabaseInternal) {
|
||||
IMapDatabase mapDatabase = MapDatabaseFactory.createMapDatabase(mapDatabaseInternalNew);
|
||||
this.mapView.setMapDatabase(mapDatabase);
|
||||
this.mapDatabaseInternal = mapDatabaseInternalNew;
|
||||
}
|
||||
}
|
||||
try {
|
||||
String textScaleDefault = getString(R.string.preferences_text_scale_default);
|
||||
this.mapView.setTextScale(Float.parseFloat(preferences.getString("textScale", textScaleDefault)));
|
||||
} catch (NumberFormatException e) {
|
||||
this.mapView.setTextScale(1);
|
||||
}
|
||||
|
||||
if (preferences.getBoolean("fullscreen", false)) {
|
||||
Log.i("mapviewer", "FULLSCREEN");
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
Log.i("mapviewer", "NO FULLSCREEN");
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
if (preferences.getBoolean("wakeLock", false) && !this.wakeLock.isHeld()) {
|
||||
this.wakeLock.acquire();
|
||||
}
|
||||
|
||||
boolean drawTileFrames = preferences.getBoolean("drawTileFrames", false);
|
||||
boolean drawTileCoordinates = preferences.getBoolean("drawTileCoordinates", false);
|
||||
boolean disablePolygons = preferences.getBoolean("disablePolygons", false);
|
||||
DebugSettings debugSettings = new DebugSettings(drawTileCoordinates, drawTileFrames, disablePolygons);
|
||||
this.mapView.setDebugSettings(debugSettings);
|
||||
|
||||
if (!this.mapView.getMapGenerator().requiresInternetConnection() && this.mapView.getMapFile() == null) {
|
||||
startMapFilePicker();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(BUNDLE_SHOW_MY_LOCATION, isShowMyLocationEnabled());
|
||||
outState.putBoolean(BUNDLE_CENTER_AT_FIRST_FIX, this.myLocationListener.isCenterAtFirstFix());
|
||||
outState.putBoolean(BUNDLE_SNAP_TO_LOCATION, this.snapToLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the "show my location" mode.
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
private boolean disableShowMyLocation() {
|
||||
if (this.showMyLocation) {
|
||||
this.showMyLocation = false;
|
||||
disableSnapToLocation(false);
|
||||
this.locationManager.removeUpdates(this.myLocationListener);
|
||||
// if (this.circleOverlay != null) {
|
||||
// this.mapView.getOverlays().remove(this.circleOverlay);
|
||||
// this.mapView.getOverlays().remove(this.itemizedOverlay);
|
||||
// this.circleOverlay = null;
|
||||
// this.itemizedOverlay = null;
|
||||
// }
|
||||
this.snapToLocationView.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 (this.snapToLocation) {
|
||||
this.snapToLocation = false;
|
||||
this.snapToLocationView.setChecked(false);
|
||||
this.mapView.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 (!this.snapToLocation) {
|
||||
this.snapToLocation = true;
|
||||
this.mapView.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 this.showMyLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the "snap to location" mode.
|
||||
*
|
||||
* @return true if the "snap to location" mode is enabled, false otherwise.
|
||||
*/
|
||||
boolean isSnapToLocationEnabled() {
|
||||
return this.snapToLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the UI thread to display the given text message as toast notification.
|
||||
*
|
||||
* @param text
|
||||
* the text message to display
|
||||
*/
|
||||
void showToastOnUiThread(final String text) {
|
||||
|
||||
if (AndroidUtils.currentThreadIsUiThread()) {
|
||||
Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
} else {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast toast = Toast.makeText(TileMap.this, text, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.tilemap.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
/**
|
||||
* Accepts all readable directories and all readable files with a given extension.
|
||||
*/
|
||||
public class FilterByFileExtension implements FileFilter {
|
||||
private final String extension;
|
||||
|
||||
/**
|
||||
* @param extension
|
||||
* the allowed file name extension.
|
||||
*/
|
||||
public FilterByFileExtension(String extension) {
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
// accept only readable files
|
||||
if (file.canRead()) {
|
||||
if (file.isDirectory()) {
|
||||
// accept all directories
|
||||
return true;
|
||||
} else if (file.isFile() && file.getName().endsWith(this.extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
29
src/org/mapsforge/tilemap/filefilter/ValidFileFilter.java
Normal file
29
src/org/mapsforge/tilemap/filefilter/ValidFileFilter.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.tilemap.filefilter;
|
||||
|
||||
import java.io.FileFilter;
|
||||
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
|
||||
/**
|
||||
* An extension of the {@link FileFilter} interface.
|
||||
*/
|
||||
public interface ValidFileFilter extends FileFilter {
|
||||
/**
|
||||
* @return the result of the last {@link #accept} call (might be null).
|
||||
*/
|
||||
FileOpenResult getFileOpenResult();
|
||||
}
|
||||
41
src/org/mapsforge/tilemap/filefilter/ValidMapFile.java
Normal file
41
src/org/mapsforge/tilemap/filefilter/ValidMapFile.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.tilemap.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.mapsforge.database.IMapDatabase;
|
||||
import org.mapsforge.database.mapfile.MapDatabase;
|
||||
|
||||
/**
|
||||
* Accepts all valid map files.
|
||||
*/
|
||||
public final class ValidMapFile implements ValidFileFilter {
|
||||
private FileOpenResult fileOpenResult;
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
IMapDatabase mapDatabase = new MapDatabase();
|
||||
this.fileOpenResult = mapDatabase.openFile(file);
|
||||
mapDatabase.closeFile();
|
||||
return this.fileOpenResult.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult getFileOpenResult() {
|
||||
return this.fileOpenResult;
|
||||
}
|
||||
}
|
||||
71
src/org/mapsforge/tilemap/filefilter/ValidRenderTheme.java
Normal file
71
src/org/mapsforge/tilemap/filefilter/ValidRenderTheme.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.tilemap.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.mapsforge.android.rendertheme.RenderThemeHandler;
|
||||
import org.mapsforge.database.FileOpenResult;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* Accepts all valid render theme XML files.
|
||||
*/
|
||||
public final class ValidRenderTheme implements ValidFileFilter {
|
||||
private FileOpenResult fileOpenResult;
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
InputStream inputStream = null;
|
||||
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
RenderThemeHandler renderThemeHandler = new RenderThemeHandler();
|
||||
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
|
||||
xmlReader.setContentHandler(renderThemeHandler);
|
||||
xmlReader.parse(new InputSource(inputStream));
|
||||
this.fileOpenResult = FileOpenResult.SUCCESS;
|
||||
} catch (ParserConfigurationException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
} catch (SAXException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return this.fileOpenResult.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult getFileOpenResult() {
|
||||
return this.fileOpenResult;
|
||||
}
|
||||
}
|
||||
245
src/org/mapsforge/tilemap/filepicker/FilePicker.java
Executable file
245
src/org/mapsforge/tilemap/filepicker/FilePicker.java
Executable file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* 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.tilemap.filepicker;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.mapsforge.tilemap.filefilter.ValidFileFilter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
import org.mapsforge.tilemap.R;
|
||||
|
||||
/**
|
||||
* A FilePicker displays the contents of directories. The user can navigate within the file system and select a single
|
||||
* file whose path is then returned to the calling activity. The ordering of directory contents can be specified via
|
||||
* {@link #setFileComparator(Comparator)}. By default subfolders and files are grouped and each group is ordered
|
||||
* alphabetically.
|
||||
* <p>
|
||||
* A {@link FileFilter} can be activated via {@link #setFileDisplayFilter(FileFilter)} to restrict the displayed files
|
||||
* and folders. By default all files and folders are visible.
|
||||
* <p>
|
||||
* Another <code>FileFilter</code> can be applied via {@link #setFileSelectFilter(ValidFileFilter)} to check if a
|
||||
* selected file is valid before its path is returned. By default all files are considered as valid and can be selected.
|
||||
*/
|
||||
public class FilePicker extends Activity implements AdapterView.OnItemClickListener {
|
||||
/**
|
||||
* The name of the extra data in the result {@link Intent}.
|
||||
*/
|
||||
public static final String SELECTED_FILE = "selectedFile";
|
||||
|
||||
private static final String CURRENT_DIRECTORY = "currentDirectory";
|
||||
private static final String DEFAULT_DIRECTORY = "/";
|
||||
private static final int DIALOG_FILE_INVALID = 0;
|
||||
// private static final int DIALOG_FILE_SELECT = 1;
|
||||
private static Comparator<File> fileComparator = getDefaultFileComparator();
|
||||
private static FileFilter fileDisplayFilter;
|
||||
private static ValidFileFilter fileSelectFilter;
|
||||
private static final String PREFERENCES_FILE = "FilePicker";
|
||||
|
||||
/**
|
||||
* Sets the file comparator which is used to order the contents of all directories before displaying them. If set to
|
||||
* null, subfolders and files will not be ordered.
|
||||
*
|
||||
* @param fileComparator
|
||||
* the file comparator (may be null).
|
||||
*/
|
||||
public static void setFileComparator(Comparator<File> fileComparator) {
|
||||
FilePicker.fileComparator = fileComparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file display filter. This filter is used to determine which files and subfolders of directories will be
|
||||
* displayed. If set to null, all files and subfolders are shown.
|
||||
*
|
||||
* @param fileDisplayFilter
|
||||
* the file display filter (may be null).
|
||||
*/
|
||||
public static void setFileDisplayFilter(FileFilter fileDisplayFilter) {
|
||||
FilePicker.fileDisplayFilter = fileDisplayFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file select filter. This filter is used when the user selects a file to determine if it is valid. If set
|
||||
* to null, all files are considered as valid.
|
||||
*
|
||||
* @param fileSelectFilter
|
||||
* the file selection filter (may be null).
|
||||
*/
|
||||
public static void setFileSelectFilter(ValidFileFilter fileSelectFilter) {
|
||||
FilePicker.fileSelectFilter = fileSelectFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default file comparator.
|
||||
*
|
||||
* @return the default file comparator.
|
||||
*/
|
||||
private static Comparator<File> getDefaultFileComparator() {
|
||||
// order all files by type and alphabetically by name
|
||||
return new Comparator<File>() {
|
||||
@Override
|
||||
public int compare(File file1, File file2) {
|
||||
if (file1.isDirectory() && !file2.isDirectory()) {
|
||||
return -1;
|
||||
} else if (!file1.isDirectory() && file2.isDirectory()) {
|
||||
return 1;
|
||||
} else {
|
||||
return file1.getName().compareToIgnoreCase(file2.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private File currentDirectory;
|
||||
private FilePickerIconAdapter filePickerIconAdapter;
|
||||
private File[] files;
|
||||
private File[] filesWithParentFolder;
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
File selectedFile = this.files[(int) id];
|
||||
if (selectedFile.isDirectory()) {
|
||||
this.currentDirectory = selectedFile;
|
||||
browseToCurrentDirectory();
|
||||
} else if (fileSelectFilter == null || fileSelectFilter.accept(selectedFile)) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SELECTED_FILE, selectedFile.getAbsolutePath()));
|
||||
finish();
|
||||
} else {
|
||||
showDialog(DIALOG_FILE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Browses to the current directory.
|
||||
*/
|
||||
private void browseToCurrentDirectory() {
|
||||
setTitle(this.currentDirectory.getAbsolutePath());
|
||||
|
||||
// read the subfolders and files from the current directory
|
||||
if (fileDisplayFilter == null) {
|
||||
this.files = this.currentDirectory.listFiles();
|
||||
} else {
|
||||
this.files = this.currentDirectory.listFiles(fileDisplayFilter);
|
||||
}
|
||||
|
||||
if (this.files == null) {
|
||||
this.files = new File[0];
|
||||
} else {
|
||||
// order the subfolders and files
|
||||
Arrays.sort(this.files, fileComparator);
|
||||
}
|
||||
|
||||
// if a parent directory exists, add it at the first position
|
||||
if (this.currentDirectory.getParentFile() != null) {
|
||||
this.filesWithParentFolder = new File[this.files.length + 1];
|
||||
this.filesWithParentFolder[0] = this.currentDirectory.getParentFile();
|
||||
System.arraycopy(this.files, 0, this.filesWithParentFolder, 1, this.files.length);
|
||||
this.files = this.filesWithParentFolder;
|
||||
this.filePickerIconAdapter.setFiles(this.files, true);
|
||||
} else {
|
||||
this.filePickerIconAdapter.setFiles(this.files, false);
|
||||
}
|
||||
this.filePickerIconAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_file_picker);
|
||||
|
||||
this.filePickerIconAdapter = new FilePickerIconAdapter(this);
|
||||
GridView gridView = (GridView) findViewById(R.id.filePickerView);
|
||||
gridView.setOnItemClickListener(this);
|
||||
gridView.setAdapter(this.filePickerIconAdapter);
|
||||
|
||||
// if (savedInstanceState == null) {
|
||||
// // first start of this instance
|
||||
// showDialog(DIALOG_FILE_SELECT);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
switch (id) {
|
||||
case DIALOG_FILE_INVALID:
|
||||
builder.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
builder.setTitle(R.string.error);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(getString(R.string.file_invalid));
|
||||
stringBuilder.append("\n\n");
|
||||
stringBuilder.append(FilePicker.fileSelectFilter.getFileOpenResult().getErrorMessage());
|
||||
|
||||
builder.setMessage(stringBuilder.toString());
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
return builder.create();
|
||||
// case DIALOG_FILE_SELECT:
|
||||
// builder.setMessage(R.string.file_select);
|
||||
// builder.setPositiveButton(R.string.ok, null);
|
||||
// return builder.create();
|
||||
default:
|
||||
// do dialog will be created
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
// save the current directory
|
||||
Editor editor = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE).edit();
|
||||
editor.clear();
|
||||
if (this.currentDirectory != null) {
|
||||
editor.putString(CURRENT_DIRECTORY, this.currentDirectory.getAbsolutePath());
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// check if the full screen mode should be activated
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
|
||||
// restore the current directory
|
||||
SharedPreferences preferences = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE);
|
||||
this.currentDirectory = new File(preferences.getString(CURRENT_DIRECTORY, DEFAULT_DIRECTORY));
|
||||
if (!this.currentDirectory.exists() || !this.currentDirectory.canRead()) {
|
||||
this.currentDirectory = new File(DEFAULT_DIRECTORY);
|
||||
}
|
||||
browseToCurrentDirectory();
|
||||
}
|
||||
}
|
||||
108
src/org/mapsforge/tilemap/filepicker/FilePickerIconAdapter.java
Executable file
108
src/org/mapsforge/tilemap/filepicker/FilePickerIconAdapter.java
Executable file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.tilemap.filepicker;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mapsforge.tilemap.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* An adapter for the FilePicker GridView.
|
||||
*/
|
||||
class FilePickerIconAdapter extends BaseAdapter {
|
||||
private final Context context;
|
||||
private File currentFile;
|
||||
private File[] files;
|
||||
private boolean hasParentFolder;
|
||||
private TextView textView;
|
||||
|
||||
/**
|
||||
* Creates a new FilePickerIconAdapter with the given context.
|
||||
*
|
||||
* @param context
|
||||
* the context of this adapter, through which new Views are created.
|
||||
*/
|
||||
FilePickerIconAdapter(Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (this.files == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.files.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int index) {
|
||||
return this.files[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int index, View convertView, ViewGroup parent) {
|
||||
if (convertView instanceof TextView) {
|
||||
// recycle the old view
|
||||
this.textView = (TextView) convertView;
|
||||
} else {
|
||||
// create a new view object
|
||||
this.textView = new TextView(this.context);
|
||||
this.textView.setLines(2);
|
||||
this.textView.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
this.textView.setPadding(5, 10, 5, 10);
|
||||
}
|
||||
|
||||
if (index == 0 && this.hasParentFolder) {
|
||||
// the parent directory of the current folder
|
||||
this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_back, 0, 0);
|
||||
this.textView.setText("..");
|
||||
} else {
|
||||
this.currentFile = this.files[index];
|
||||
if (this.currentFile.isDirectory()) {
|
||||
this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_folder, 0, 0);
|
||||
} else {
|
||||
this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_file, 0, 0);
|
||||
}
|
||||
this.textView.setText(this.currentFile.getName());
|
||||
}
|
||||
return this.textView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data of this adapter.
|
||||
*
|
||||
* @param files
|
||||
* the new files for this adapter.
|
||||
* @param newHasParentFolder
|
||||
* true if the file array has a parent folder at index 0, false otherwise.
|
||||
*/
|
||||
void setFiles(File[] files, boolean newHasParentFolder) {
|
||||
this.files = files.clone();
|
||||
this.hasParentFolder = newHasParentFolder;
|
||||
}
|
||||
}
|
||||
45
src/org/mapsforge/tilemap/preferences/EditPreferences.java
Normal file
45
src/org/mapsforge/tilemap/preferences/EditPreferences.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.tilemap.preferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.WindowManager;
|
||||
import org.mapsforge.tilemap.R;
|
||||
|
||||
/**
|
||||
* Activity to edit the application preferences.
|
||||
*/
|
||||
public class EditPreferences extends PreferenceActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// check if the full screen mode should be activated
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
154
src/org/mapsforge/tilemap/preferences/SeekBarPreference.java
Normal file
154
src/org/mapsforge/tilemap/preferences/SeekBarPreference.java
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.tilemap.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.preference.DialogPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* This abstract class provides all code for a seek bar preference. Deriving classes only need to set the current and
|
||||
* maximum value of the seek bar. An optional text message above the seek bar is also supported as well as an optional
|
||||
* current value message below the seek bar.
|
||||
*/
|
||||
abstract class SeekBarPreference extends DialogPreference implements OnSeekBarChangeListener {
|
||||
private TextView currentValueTextView;
|
||||
private Editor editor;
|
||||
private SeekBar preferenceSeekBar;
|
||||
|
||||
/**
|
||||
* How much the value should increase when the seek bar is moved.
|
||||
*/
|
||||
int increment = 1;
|
||||
|
||||
/**
|
||||
* The maximum value of the seek bar.
|
||||
*/
|
||||
int max;
|
||||
|
||||
/**
|
||||
* Optional text message to display on top of the seek bar.
|
||||
*/
|
||||
String messageText;
|
||||
|
||||
/**
|
||||
* The SharedPreferences instance that is used.
|
||||
*/
|
||||
final SharedPreferences preferencesDefault;
|
||||
|
||||
/**
|
||||
* The current value of the seek bar.
|
||||
*/
|
||||
int seekBarCurrentValue;
|
||||
|
||||
/**
|
||||
* Create a new seek bar preference.
|
||||
*
|
||||
* @param context
|
||||
* the context of the seek bar preferences activity.
|
||||
* @param attrs
|
||||
* A set of attributes (currently ignored).
|
||||
*/
|
||||
SeekBarPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.preferencesDefault = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// check if the "OK" button was pressed and the seek bar value has changed
|
||||
if (which == DialogInterface.BUTTON_POSITIVE
|
||||
&& this.seekBarCurrentValue != this.preferenceSeekBar.getProgress()) {
|
||||
// get the value of the seek bar and save it in the preferences
|
||||
this.seekBarCurrentValue = this.preferenceSeekBar.getProgress();
|
||||
this.editor = this.preferencesDefault.edit();
|
||||
this.editor.putInt(this.getKey(), this.seekBarCurrentValue);
|
||||
this.editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (this.currentValueTextView != null) {
|
||||
this.currentValueTextView.setText(getCurrentValueText(progress));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
// create a layout for the optional text messageText and the seek bar
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
linearLayout.setPadding(20, 10, 20, 10);
|
||||
|
||||
// check if a text message should appear above the seek bar
|
||||
if (this.messageText != null) {
|
||||
// create a text view for the text messageText
|
||||
TextView messageTextView = new TextView(getContext());
|
||||
messageTextView.setText(this.messageText);
|
||||
messageTextView.setPadding(0, 0, 0, 20);
|
||||
// add the text message view to the layout
|
||||
linearLayout.addView(messageTextView);
|
||||
}
|
||||
|
||||
// create the seek bar and set the maximum and current value
|
||||
this.preferenceSeekBar = new SeekBar(getContext());
|
||||
this.preferenceSeekBar.setOnSeekBarChangeListener(this);
|
||||
this.preferenceSeekBar.setMax(this.max);
|
||||
this.preferenceSeekBar.setProgress(Math.min(this.seekBarCurrentValue, this.max));
|
||||
this.preferenceSeekBar.setKeyProgressIncrement(this.increment);
|
||||
this.preferenceSeekBar.setPadding(0, 0, 0, 10);
|
||||
// add the seek bar to the layout
|
||||
linearLayout.addView(this.preferenceSeekBar);
|
||||
|
||||
// create the text view for the current value below the seek bar
|
||||
this.currentValueTextView = new TextView(getContext());
|
||||
this.currentValueTextView.setText(getCurrentValueText(this.preferenceSeekBar.getProgress()));
|
||||
this.currentValueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
// add the current value text view to the layout
|
||||
linearLayout.addView(this.currentValueTextView);
|
||||
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value text.
|
||||
*
|
||||
* @param progress
|
||||
* the current progress level of the seek bar.
|
||||
* @return the new current value text
|
||||
*/
|
||||
abstract String getCurrentValueText(int progress);
|
||||
}
|
||||
Reference in New Issue
Block a user