diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml
index 75d2bdd6..c237b828 100644
--- a/vtm-android-example/AndroidManifest.xml
+++ b/vtm-android-example/AndroidManifest.xml
@@ -27,6 +27,7 @@
+
-
+
+
+
\ No newline at end of file
diff --git a/vtm-android-example/res/drawable-mdpi/file_picker_back.png b/vtm-android-example/res/drawable-mdpi/file_picker_back.png
new file mode 100644
index 00000000..67190153
Binary files /dev/null and b/vtm-android-example/res/drawable-mdpi/file_picker_back.png differ
diff --git a/vtm-android-example/res/drawable-mdpi/file_picker_file.png b/vtm-android-example/res/drawable-mdpi/file_picker_file.png
new file mode 100644
index 00000000..d0411244
Binary files /dev/null and b/vtm-android-example/res/drawable-mdpi/file_picker_file.png differ
diff --git a/vtm-android-example/res/drawable-mdpi/file_picker_folder.png b/vtm-android-example/res/drawable-mdpi/file_picker_folder.png
new file mode 100644
index 00000000..c2c3f5fb
Binary files /dev/null and b/vtm-android-example/res/drawable-mdpi/file_picker_folder.png differ
diff --git a/vtm-android-example/res/layout/activity_file_picker.xml b/vtm-android-example/res/layout/activity_file_picker.xml
new file mode 100644
index 00000000..3ed7ea46
--- /dev/null
+++ b/vtm-android-example/res/layout/activity_file_picker.xml
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file
diff --git a/vtm-android-example/res/values/strings.xml b/vtm-android-example/res/values/strings.xml
index 8e666a04..5e2d46c5 100644
--- a/vtm-android-example/res/values/strings.xml
+++ b/vtm-android-example/res/values/strings.xml
@@ -7,5 +7,9 @@
Default
Tubes
Osmarender
+ OK
+ Cancel
+ Error
+ The selected file is invalid.
\ No newline at end of file
diff --git a/vtm-android-example/src/org/oscim/android/filepicker/FilePicker.java b/vtm-android-example/src/org/oscim/android/filepicker/FilePicker.java
new file mode 100755
index 00000000..40553e4f
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/filepicker/FilePicker.java
@@ -0,0 +1,250 @@
+/*
+ * 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 .
+ */
+package org.oscim.android.filepicker;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.oscim.android.test.R;
+
+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.view.View;
+import android.widget.AdapterView;
+import android.widget.GridView;
+
+/**
+ * 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.
+ *
+ * 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.
+ *
+ * Another FileFilter
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 PREFERENCES_FILE = "FilePicker";
+ 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;
+ protected Comparator mFileComparator = getDefaultFileComparator();
+ protected FileFilter mFileDisplayFilter;
+ protected ValidFileFilter mFileSelectFilter;
+
+ /**
+ * 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 void setFileComparator(Comparator fileComparator) {
+ mFileComparator = 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 void setFileDisplayFilter(FileFilter fileDisplayFilter) {
+ mFileDisplayFilter = 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 void setFileSelectFilter(ValidFileFilter fileSelectFilter) {
+ mFileSelectFilter = fileSelectFilter;
+ }
+
+ /**
+ * Creates the default file comparator.
+ *
+ * @return the default file comparator.
+ */
+ private static Comparator getDefaultFileComparator() {
+ // order all files by type and alphabetically by name
+ return new Comparator() {
+ @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 mDirectory;
+ private FilePickerIconAdapter mFilePickerIconAdapter;
+ private File[] mFiles;
+ private File[] mFilesWithParentFolder;
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ File selectedFile = mFiles[(int) id];
+ if (selectedFile.isDirectory()) {
+ mDirectory = selectedFile;
+ browseToCurrentDirectory();
+ } else if (mFileSelectFilter == null || mFileSelectFilter.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(mDirectory.getAbsolutePath());
+
+ // read the subfolders and files from the current directory
+ if (mFileDisplayFilter == null) {
+ mFiles = mDirectory.listFiles();
+ } else {
+ mFiles = mDirectory.listFiles(mFileDisplayFilter);
+ }
+
+ if (mFiles == null) {
+ mFiles = new File[0];
+ } else {
+ // order the subfolders and files
+ Arrays.sort(mFiles, mFileComparator);
+ }
+
+ // if a parent directory exists, add it at the first position
+ if (mDirectory.getParentFile() != null) {
+ mFilesWithParentFolder = new File[mFiles.length + 1];
+ mFilesWithParentFolder[0] = mDirectory.getParentFile();
+ System.arraycopy(mFiles, 0, mFilesWithParentFolder, 1,
+ mFiles.length);
+ mFiles = mFilesWithParentFolder;
+ mFilePickerIconAdapter.setFiles(mFiles, true);
+ } else {
+ mFilePickerIconAdapter.setFiles(mFiles, false);
+ }
+ mFilePickerIconAdapter.notifyDataSetChanged();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_file_picker);
+
+ mFilePickerIconAdapter = new FilePickerIconAdapter(this);
+ GridView gridView = (GridView) findViewById(R.id.filePickerView);
+ gridView.setOnItemClickListener(this);
+ gridView.setAdapter(mFilePickerIconAdapter);
+
+ // 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(mFileSelectFilter.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 (mDirectory != null) {
+ editor.putString(CURRENT_DIRECTORY, mDirectory.getAbsolutePath());
+ }
+ editor.commit();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ // restore the current directory
+ SharedPreferences preferences = getSharedPreferences(PREFERENCES_FILE,
+ MODE_PRIVATE);
+ mDirectory = new File(preferences.getString(CURRENT_DIRECTORY,
+ DEFAULT_DIRECTORY));
+ if (!mDirectory.exists() || !mDirectory.canRead()) {
+ mDirectory = new File(DEFAULT_DIRECTORY);
+ }
+ browseToCurrentDirectory();
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/filepicker/FilePickerIconAdapter.java b/vtm-android-example/src/org/oscim/android/filepicker/FilePickerIconAdapter.java
new file mode 100755
index 00000000..8943cfe9
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/filepicker/FilePickerIconAdapter.java
@@ -0,0 +1,116 @@
+/*
+ * 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 .
+ */
+package org.oscim.android.filepicker;
+
+import java.io.File;
+
+import org.oscim.android.test.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 mContext;
+ private File mCurrentFile;
+ private File[] mFiles;
+ private boolean mHasParentFolder;
+ private TextView mTextView;
+
+ /**
+ * 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();
+ mContext = context;
+ }
+
+ @Override
+ public int getCount() {
+ if (mFiles == null) {
+ return 0;
+ }
+ return mFiles.length;
+ }
+
+ @Override
+ public Object getItem(int index) {
+ return mFiles[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
+ mTextView = (TextView) convertView;
+ } else {
+ // create a new view object
+ mTextView = new TextView(mContext);
+ mTextView.setLines(2);
+ mTextView.setGravity(Gravity.CENTER_HORIZONTAL);
+ mTextView.setPadding(5, 10, 5, 10);
+ }
+
+ if (index == 0 && mHasParentFolder) {
+ // the parent directory of the current folder
+ mTextView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_back, 0, 0);
+ mTextView.setText("..");
+ } else {
+ mCurrentFile = mFiles[index];
+ if (mCurrentFile.isDirectory()) {
+ mTextView.setCompoundDrawablesWithIntrinsicBounds(0,
+ R.drawable.file_picker_folder,
+ 0,
+ 0);
+ } else {
+ mTextView.setCompoundDrawablesWithIntrinsicBounds(0,
+ R.drawable.file_picker_file,
+ 0,
+ 0);
+ }
+ mTextView.setText(mCurrentFile.getName());
+ }
+ return mTextView;
+ }
+
+ /**
+ * 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) {
+ mFiles = files.clone();
+ mHasParentFolder = newHasParentFolder;
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/filepicker/FilterByFileExtension.java b/vtm-android-example/src/org/oscim/android/filepicker/FilterByFileExtension.java
new file mode 100644
index 00000000..32e1c9df
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/filepicker/FilterByFileExtension.java
@@ -0,0 +1,48 @@
+/*
+ * 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 .
+ */
+package org.oscim.android.filepicker;
+
+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 mExtension;
+
+ /**
+ * @param extension
+ * the allowed file name extension.
+ */
+ public FilterByFileExtension(String extension) {
+ mExtension = 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(mExtension)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/filepicker/ValidFileFilter.java b/vtm-android-example/src/org/oscim/android/filepicker/ValidFileFilter.java
new file mode 100644
index 00000000..45f80ded
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/filepicker/ValidFileFilter.java
@@ -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 .
+ */
+package org.oscim.android.filepicker;
+
+import java.io.FileFilter;
+
+import org.oscim.tiling.source.TileSource.OpenResult;
+
+/**
+ * An extension of the {@link FileFilter} interface.
+ */
+public interface ValidFileFilter extends FileFilter {
+ /**
+ * @return the result of the last {@link #accept} call (might be null).
+ */
+ OpenResult getFileOpenResult();
+}
diff --git a/vtm-android-example/src/org/oscim/android/filepicker/ValidMapFile.java b/vtm-android-example/src/org/oscim/android/filepicker/ValidMapFile.java
new file mode 100644
index 00000000..2f668077
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/filepicker/ValidMapFile.java
@@ -0,0 +1,42 @@
+/*
+ * 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 .
+ */
+package org.oscim.android.filepicker;
+
+import java.io.File;
+
+import org.oscim.tiling.source.TileSource.OpenResult;
+import org.oscim.tiling.source.mapfile.MapFileTileSource;
+
+/**
+ * Accepts all valid map files.
+ */
+public final class ValidMapFile implements ValidFileFilter {
+ private OpenResult mOpenResult;
+
+ @Override
+ public boolean accept(File file) {
+ MapFileTileSource mapFileSource = new MapFileTileSource();
+ mapFileSource.setMapFile(file.getAbsolutePath());
+
+ this.mOpenResult = mapFileSource.open();
+ mapFileSource.close();
+ return mOpenResult.isSuccess();
+ }
+
+ @Override
+ public OpenResult getFileOpenResult() {
+ return mOpenResult;
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/filepicker/ValidRenderTheme.java b/vtm-android-example/src/org/oscim/android/filepicker/ValidRenderTheme.java
new file mode 100644
index 00000000..ff8f799e
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/filepicker/ValidRenderTheme.java
@@ -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 .
+ */
+package org.oscim.android.filepicker;
+
+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.oscim.theme.RenderThemeHandler;
+import org.oscim.tiling.source.TileSource.OpenResult;
+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 OpenResult mOpenResult;
+
+ @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));
+ mOpenResult = OpenResult.SUCCESS;
+ } catch (ParserConfigurationException e) {
+ mOpenResult = new OpenResult(e.getMessage());
+ } catch (SAXException e) {
+ mOpenResult = new OpenResult(e.getMessage());
+ } catch (IOException e) {
+ mOpenResult = new OpenResult(e.getMessage());
+ } finally {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (IOException e) {
+ mOpenResult = new OpenResult(e.getMessage());
+ }
+ }
+
+ return mOpenResult.isSuccess();
+ }
+
+ @Override
+ public OpenResult getFileOpenResult() {
+ return mOpenResult;
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java b/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java
new file mode 100644
index 00000000..dec90852
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/test/MapsforgeMapActivity.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.android.test;
+
+import org.oscim.android.MapActivity;
+import org.oscim.android.MapView;
+import org.oscim.android.filepicker.FilePicker;
+import org.oscim.android.filepicker.FilterByFileExtension;
+import org.oscim.android.filepicker.ValidMapFile;
+import org.oscim.core.MapPosition;
+import org.oscim.core.Tile;
+import org.oscim.layers.tile.vector.VectorTileLayer;
+import org.oscim.layers.tile.vector.labeling.LabelLayer;
+import org.oscim.theme.InternalRenderTheme;
+import org.oscim.tiling.source.mapfile.MapFileTileSource;
+import org.oscim.tiling.source.mapfile.MapInfo;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+public class MapsforgeMapActivity extends MapActivity {
+ private static final int SELECT_MAP_FILE = 0;
+
+ MapView mMapView;
+ MapFileTileSource mTileSource;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_map);
+
+ mMapView = (MapView) findViewById(R.id.mapView);
+ registerMapView(mMapView);
+
+ startActivityForResult(new Intent(this, MapFilePicker.class),
+ SELECT_MAP_FILE);
+ }
+
+ public static class MapFilePicker extends FilePicker {
+ public MapFilePicker() {
+ setFileDisplayFilter(new FilterByFileExtension(".map"));
+ setFileSelectFilter(new ValidMapFile());
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.theme_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onMenuItemSelected(int featureId, MenuItem item) {
+
+ switch (item.getItemId()) {
+ case R.id.theme_default:
+ mMap.setTheme(InternalRenderTheme.DEFAULT);
+ item.setChecked(true);
+ return true;
+
+ case R.id.theme_tubes:
+ mMap.setTheme(InternalRenderTheme.TRONRENDER);
+ item.setChecked(true);
+ return true;
+
+ case R.id.theme_osmarender:
+ mMap.setTheme(InternalRenderTheme.OSMARENDER);
+ item.setChecked(true);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
+
+ if (requestCode == SELECT_MAP_FILE) {
+ if (resultCode != RESULT_OK || intent == null)
+ return;
+ if (intent.getStringExtra(FilePicker.SELECTED_FILE) == null)
+ return;
+
+ mTileSource = new MapFileTileSource();
+ String file = intent.getStringExtra(FilePicker.SELECTED_FILE);
+ if (mTileSource.setMapFile(file)) {
+
+ VectorTileLayer l = mMap.setBaseMap(mTileSource);
+ mMap.setTheme(InternalRenderTheme.DEFAULT);
+ mMap.getLayers().add(new LabelLayer(mMap, l.getTileRenderer()));
+
+ MapInfo info = mTileSource.getMapInfo();
+ if (info.boundingBox != null) {
+ MapPosition pos = new MapPosition();
+ pos.setByBoundingBox(info.boundingBox,
+ Tile.SIZE * 4,
+ Tile.SIZE * 4);
+ mMap.setMapPosition(pos);
+ Samples.log.debug("set position {}",pos);
+ } else if (info.mapCenter != null) {
+
+ double scale = 1 << 8;
+ if (info.startZoomLevel != null)
+ scale = 1 << info.startZoomLevel.intValue();
+
+ mMap.setMapPosition(info.mapCenter.getLatitude(),
+ info.mapCenter.getLongitude(),
+ scale);
+ }
+ }
+ }
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java
index c217df8d..6a4b511f 100644
--- a/vtm-android-example/src/org/oscim/android/test/Samples.java
+++ b/vtm-android-example/src/org/oscim/android/test/Samples.java
@@ -17,6 +17,9 @@
*/
package org.oscim.android.test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@@ -29,6 +32,8 @@ import android.widget.LinearLayout;
* A simple start screen for the sample activities.
*/
public class Samples extends Activity {
+ public static Logger log = LoggerFactory.getLogger(Samples.class);
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -37,6 +42,7 @@ public class Samples extends Activity {
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples);
linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(BitmapTileMapActivity.class));
+ linearLayout.addView(createButton(MapsforgeMapActivity.class));
linearLayout.addView(createButton(PathOverlayActivity.class));
linearLayout.addView(createButton(MarkerOverlayActivity.class));
}