├── .gitattributes
├── .gitignore
├── GoogleWrapperSample
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ └── org.eclipse.m2e.core.prefs
├── AndroidManifest.xml
├── pom.xml
├── project.properties
├── res
│ ├── drawable
│ │ ├── berlin.jpg
│ │ ├── icon.png
│ │ ├── marker_default.png
│ │ └── marker_default_focused_base.png
│ └── values
│ │ └── strings.xml
└── src
│ └── org
│ └── osmdroid
│ └── google
│ └── sample
│ └── GoogleWrapperSample.java
├── LICENSE
├── OSMDroid_CleanUp_Settings.xml
├── OSMDroid_Formatter_Settings.xml
├── OSMMapTilePackager
├── .classpath
├── .project
├── build-jar.xml
├── build.gradle
├── build.xml
├── ext
│ ├── svnkit.jar
│ ├── svntask.jar
│ └── usages.txt
├── libs
│ └── sqlitejdbc-v056.jar
├── pom.xml
└── src
│ └── org
│ └── osmdroid
│ └── mtp
│ ├── OSMMapTilePackager.java
│ ├── adt
│ └── OSMTileInfo.java
│ ├── download
│ └── DownloadManager.java
│ ├── ui
│ ├── BatchExecutorGUI.java
│ └── OSMMapTilePackagerUI.java
│ └── util
│ ├── DbCreator.java
│ ├── FolderDeleter.java
│ ├── FolderFileCounter.java
│ ├── FolderZipper.java
│ └── Util.java
├── OpenStreetMapViewer
├── .classpath
├── .project
├── AndroidManifest.xml
├── build.gradle
├── default.properties
├── ext
│ ├── doc
│ │ └── gudermann.xlsx
│ ├── img
│ │ ├── Openstreetmap_logo.svg
│ │ ├── marker_default.svg
│ │ └── marker_default_focused_base.svg
│ └── php
│ │ └── gpxuploader
│ │ ├── README.txt
│ │ └── upload.php
├── pom.xml
├── project.properties
├── res
│ ├── drawable
│ │ ├── center.png
│ │ ├── direction_arrow.png
│ │ ├── ic_menu_compass.png
│ │ ├── ic_menu_mapmode.png
│ │ ├── ic_menu_mylocation.png
│ │ ├── ic_menu_offline.png
│ │ ├── icon.png
│ │ ├── marker_default.png
│ │ ├── marker_default_focused_base.png
│ │ ├── navto_small.png
│ │ ├── next.png
│ │ ├── person.png
│ │ ├── previous.png
│ │ ├── zoom_in.png
│ │ └── zoom_out.png
│ ├── layout
│ │ ├── main.xml
│ │ └── mapview.xml
│ ├── values-de
│ │ ├── strings.xml
│ │ └── tile_sources.xml
│ ├── values-it
│ │ ├── strings.xml
│ │ └── tile_sources.xml
│ └── values
│ │ ├── strings.xml
│ │ └── tile_sources.xml
└── src
│ └── org
│ └── osmdroid
│ ├── MapActivity.java
│ ├── MapFragment.java
│ ├── ResourceProxyImpl.java
│ ├── RotationGestureDetector.java
│ ├── RotationGestureOverlay.java
│ ├── SampleItemizedOverlay.java
│ ├── SampleOverlayItem.java
│ ├── constants
│ └── OpenStreetMapConstants.java
│ ├── samplefragments
│ ├── BaseSampleFragment.java
│ ├── SampleFactory.java
│ ├── SampleFragmentXmlLayout.java
│ ├── SampleLimitedScrollArea.java
│ └── SampleWithMinimapItemizedoverlayWithFocus.java
│ ├── samples
│ ├── SampleExtensive.java
│ ├── SampleLoader.java
│ ├── SampleMapActivity.java
│ ├── SampleOSMContributor.java
│ ├── SampleWithMinimapItemizedoverlay.java
│ ├── SampleWithMinimapZoomcontrols.java
│ ├── SampleWithTilesOverlay.java
│ └── SampleWithTilesOverlayAndCustomTileSource.java
│ └── views
│ └── util
│ └── MapTileProviderFactory.java
├── README.md
├── osmdroid-android-it
├── AndroidManifest.xml
├── default.properties
├── pom.xml
├── res
│ ├── drawable-hdpi
│ │ └── icon.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── osmdroid
│ ├── ContextResourceProxyTest.java
│ ├── TileSystemMathTest.java
│ ├── test
│ └── MapActivityTest.java
│ ├── tileprovider
│ └── modules
│ │ └── MapTileProviderTest.java
│ └── views
│ ├── OpenStreetMapViewTest.java
│ └── util
│ └── OpenStreetMapTileProviderDirectTest.java
├── osmdroid-android
├── .classpath
├── .project
├── Android.mk
├── build.gradle
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ ├── microsoft
│ │ │ └── mappoint
│ │ │ │ └── TileSystem.java
│ │ └── org
│ │ │ ├── metalev
│ │ │ └── multitouch
│ │ │ │ └── controller
│ │ │ │ └── MultiTouchController.java
│ │ │ └── osmdroid
│ │ │ ├── DefaultResourceProxyImpl.java
│ │ │ ├── LocationListenerProxy.java
│ │ │ ├── ResourceProxy.java
│ │ │ ├── SensorEventListenerProxy.java
│ │ │ ├── api
│ │ │ ├── IGeoPoint.java
│ │ │ ├── IMap.java
│ │ │ ├── IMapController.java
│ │ │ ├── IMapView.java
│ │ │ ├── IMyLocationOverlay.java
│ │ │ ├── IPosition.java
│ │ │ ├── IProjection.java
│ │ │ ├── Marker.java
│ │ │ ├── OnCameraChangeListener.java
│ │ │ └── Polyline.java
│ │ │ ├── contributor
│ │ │ ├── GpxToPHPUploader.java
│ │ │ ├── OSMUploader.java
│ │ │ ├── RouteRecorder.java
│ │ │ └── util
│ │ │ │ ├── RecordedGeoPoint.java
│ │ │ │ ├── RecordedRouteGPXFormatter.java
│ │ │ │ ├── Util.java
│ │ │ │ └── constants
│ │ │ │ └── OpenStreetMapContributorConstants.java
│ │ │ ├── events
│ │ │ ├── DelayedMapListener.java
│ │ │ ├── MapAdapter.java
│ │ │ ├── MapEvent.java
│ │ │ ├── MapListener.java
│ │ │ ├── ScrollEvent.java
│ │ │ └── ZoomEvent.java
│ │ │ ├── http
│ │ │ ├── HttpClientFactory.java
│ │ │ └── IHttpClientFactory.java
│ │ │ ├── tileprovider
│ │ │ ├── BitmapPool.java
│ │ │ ├── ExpirableBitmapDrawable.java
│ │ │ ├── IMapTileProviderCallback.java
│ │ │ ├── IRegisterReceiver.java
│ │ │ ├── LRUMapTileCache.java
│ │ │ ├── MapTile.java
│ │ │ ├── MapTileCache.java
│ │ │ ├── MapTileProviderArray.java
│ │ │ ├── MapTileProviderBase.java
│ │ │ ├── MapTileProviderBasic.java
│ │ │ ├── MapTileRequestState.java
│ │ │ ├── ReusableBitmapDrawable.java
│ │ │ ├── constants
│ │ │ │ └── OpenStreetMapTileProviderConstants.java
│ │ │ ├── modules
│ │ │ │ ├── ArchiveFileFactory.java
│ │ │ │ ├── ConfigurablePriorityThreadFactory.java
│ │ │ │ ├── DatabaseFileArchive.java
│ │ │ │ ├── GEMFFileArchive.java
│ │ │ │ ├── IArchiveFile.java
│ │ │ │ ├── IFilesystemCache.java
│ │ │ │ ├── INetworkAvailablityCheck.java
│ │ │ │ ├── MBTilesFileArchive.java
│ │ │ │ ├── MapTileDownloader.java
│ │ │ │ ├── MapTileFileArchiveProvider.java
│ │ │ │ ├── MapTileFileStorageProviderBase.java
│ │ │ │ ├── MapTileFilesystemProvider.java
│ │ │ │ ├── MapTileModuleProviderBase.java
│ │ │ │ ├── NetworkAvailabliltyCheck.java
│ │ │ │ ├── TileWriter.java
│ │ │ │ └── ZipFileArchive.java
│ │ │ ├── tilesource
│ │ │ │ ├── BitmapTileSourceBase.java
│ │ │ │ ├── CloudmadeTileSource.java
│ │ │ │ ├── IStyledTileSource.java
│ │ │ │ ├── ITileSource.java
│ │ │ │ ├── MapBoxTileSource.java
│ │ │ │ ├── OnlineTileSourceBase.java
│ │ │ │ ├── QuadTreeTileSource.java
│ │ │ │ ├── TileSourceFactory.java
│ │ │ │ └── XYTileSource.java
│ │ │ └── util
│ │ │ │ ├── CloudmadeUtil.java
│ │ │ │ ├── ManifestUtil.java
│ │ │ │ ├── SimpleInvalidationHandler.java
│ │ │ │ ├── SimpleRegisterReceiver.java
│ │ │ │ └── StreamUtils.java
│ │ │ ├── util
│ │ │ ├── BoundingBoxE6.java
│ │ │ ├── GEMFFile.java
│ │ │ ├── GeoPoint.java
│ │ │ ├── GeometryMath.java
│ │ │ ├── LocationUtils.java
│ │ │ ├── MyMath.java
│ │ │ ├── NetworkLocationIgnorer.java
│ │ │ ├── Position.java
│ │ │ ├── ResourceProxyImpl.java
│ │ │ ├── TileLooper.java
│ │ │ ├── TileSystem.java
│ │ │ └── constants
│ │ │ │ ├── GeoConstants.java
│ │ │ │ └── UtilConstants.java
│ │ │ └── views
│ │ │ ├── MapController.java
│ │ │ ├── MapControllerOld.java
│ │ │ ├── MapView.java
│ │ │ ├── Projection.java
│ │ │ ├── drawing
│ │ │ ├── OsmBitmapShader.java
│ │ │ └── OsmPath.java
│ │ │ ├── overlay
│ │ │ ├── DirectedLocationOverlay.java
│ │ │ ├── IOverlayMenuProvider.java
│ │ │ ├── ItemizedIconOverlay.java
│ │ │ ├── ItemizedOverlay.java
│ │ │ ├── ItemizedOverlayControlView.java
│ │ │ ├── ItemizedOverlayWithFocus.java
│ │ │ ├── MinimapOverlay.java
│ │ │ ├── MyLocationOverlay.java
│ │ │ ├── NonAcceleratedOverlay.java
│ │ │ ├── Overlay.java
│ │ │ ├── OverlayItem.java
│ │ │ ├── OverlayManager.java
│ │ │ ├── PathOverlay.java
│ │ │ ├── ScaleBarOverlay.java
│ │ │ ├── SimpleLocationOverlay.java
│ │ │ ├── TilesOverlay.java
│ │ │ ├── compass
│ │ │ │ ├── CompassOverlay.java
│ │ │ │ ├── IOrientationConsumer.java
│ │ │ │ ├── IOrientationProvider.java
│ │ │ │ └── InternalCompassOrientationProvider.java
│ │ │ └── mylocation
│ │ │ │ ├── GpsMyLocationProvider.java
│ │ │ │ ├── IMyLocationConsumer.java
│ │ │ │ ├── IMyLocationProvider.java
│ │ │ │ └── MyLocationNewOverlay.java
│ │ │ └── util
│ │ │ ├── Mercator.java
│ │ │ ├── MyMath.java
│ │ │ ├── PathProjection.java
│ │ │ └── constants
│ │ │ ├── MapViewConstants.java
│ │ │ ├── MathConstants.java
│ │ │ └── OverlayConstants.java
│ └── resources
│ │ └── org
│ │ └── osmdroid
│ │ ├── center.png
│ │ ├── direction_arrow.png
│ │ ├── ic_menu_compass.png
│ │ ├── ic_menu_mapmode.png
│ │ ├── ic_menu_mylocation.png
│ │ ├── ic_menu_offline.png
│ │ ├── marker_default.png
│ │ ├── marker_default_focused_base.png
│ │ ├── navto_small.png
│ │ ├── next.png
│ │ ├── person.png
│ │ └── previous.png
│ └── test
│ └── java
│ └── org
│ └── osmdroid
│ ├── DefaultResourceProxyTest.java
│ └── util
│ └── GeoPointTest.java
├── osmdroid-third-party
├── .classpath
├── .project
├── build.gradle
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── osmdroid
│ ├── google
│ ├── overlay
│ │ ├── GoogleItemizedOverlay.java
│ │ ├── GooglePolylineOverlay.java
│ │ └── GoogleTilesOverlay.java
│ └── wrapper
│ │ ├── GeoPoint.java
│ │ ├── MapController.java
│ │ ├── MapView.java
│ │ ├── MyLocationOverlay.java
│ │ ├── Projection.java
│ │ └── v2
│ │ ├── GeoPoint.java
│ │ ├── GoogleV1MapWrapper.java
│ │ ├── MapFactory.java
│ │ ├── MapWrapper.java
│ │ ├── OsmdroidMapWrapper.java
│ │ └── Projection.java
│ └── tileprovider
│ └── tilesource
│ └── bing
│ ├── BingMapTileSource.java
│ └── imagerymetadata
│ ├── ImageryMetaData.java
│ └── ImageryMetaDataResource.java
└── pom.xml
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
3 | *.java text
4 | *.txt text
5 | *.xml text
6 | *.gradle text
7 | *.php text
8 | *.properties text
9 | .classpath text
10 | .project text
11 |
12 | *.png binary
13 | *.jpg binary
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | gen-external-apklibs/
15 | target/
16 |
17 | # Local configuration file (sdk path, etc)
18 | local.properties
19 |
20 | # Eclipse project files
21 | .classpath
22 | .project
23 | .settings
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Intellij project files
29 | *.iml
30 | *.ipr
31 | *.iws
32 | .idea/
33 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | GoogleWrapperSample
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.eclipse.m2e.core.maven2Nature
36 | com.android.ide.eclipse.adt.AndroidNature
37 | org.eclipse.jdt.core.javanature
38 |
39 |
40 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 | encoding/src=UTF-8
4 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Fri Jan 20 22:36:39 CET 2012
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4 | org.eclipse.jdt.core.compiler.compliance=1.6
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.source=1.6
7 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | #Fri Jan 20 22:36:39 CET 2012
2 | activeProfiles=
3 | eclipse.preferences.version=1
4 | resolveWorkspaceProjects=true
5 | version=1
6 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.osmdroid
7 | osmdroid-parent
8 | 4.2
9 |
10 |
11 | GoogleWrapperSample
12 | apk
13 |
14 | Google wrapper sample application
15 |
16 |
17 |
18 |
19 | android
20 | android
21 |
22 |
23 | com.google.android.maps
24 | maps
25 |
26 |
27 | com.google.android.gms
28 | google-play-services
29 | apklib
30 |
31 |
32 | com.google.android.gms
33 | google-play-services
34 | jar
35 |
36 |
37 |
38 | commons-logging
39 | commons-logging
40 |
41 |
42 |
43 | ${project.groupId}
44 | osmdroid-android
45 | ${project.version}
46 |
47 |
48 | ${project.groupId}
49 | osmdroid-third-party
50 | ${project.version}
51 |
52 |
53 | org.slf4j
54 | slf4j-android
55 |
56 |
57 |
58 |
59 | ${basedir}/src
60 |
61 |
62 | com.jayway.maven.plugins.android.generation2
63 | android-maven-plugin
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-16
12 | android.library.reference.1=gen-external-apklibs/com.google.android.gms_google-play-services_15.0.0
13 |
--------------------------------------------------------------------------------
/GoogleWrapperSample/res/drawable/berlin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/GoogleWrapperSample/res/drawable/berlin.jpg
--------------------------------------------------------------------------------
/GoogleWrapperSample/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/GoogleWrapperSample/res/drawable/icon.png
--------------------------------------------------------------------------------
/GoogleWrapperSample/res/drawable/marker_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/GoogleWrapperSample/res/drawable/marker_default.png
--------------------------------------------------------------------------------
/GoogleWrapperSample/res/drawable/marker_default_focused_base.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/GoogleWrapperSample/res/drawable/marker_default_focused_base.png
--------------------------------------------------------------------------------
/GoogleWrapperSample/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | GoogleWrapperSample
4 |
5 | Google Map v1
6 | Google Map v2
7 | OpenStreetMap
8 |
9 | Enable MyLocation
10 | Disable MyLocation
11 | Rotate
12 |
13 | get your own key!
14 |
15 | Unknown
16 |
17 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | OSMMapTilePackager
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.m2e.core.maven2Nature
21 | org.eclipse.jdt.core.javanature
22 |
23 |
24 |
25 | osmdroid-android-src
26 | 2
27 | PARENT-1-PROJECT_LOC/osmdroid-android/src
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/build-jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | sourceSets {
3 | main.java.srcDirs = ['src']
4 | }
5 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/ext/svnkit.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OSMMapTilePackager/ext/svnkit.jar
--------------------------------------------------------------------------------
/OSMMapTilePackager/ext/svntask.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OSMMapTilePackager/ext/svntask.jar
--------------------------------------------------------------------------------
/OSMMapTilePackager/libs/sqlitejdbc-v056.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OSMMapTilePackager/libs/sqlitejdbc-v056.jar
--------------------------------------------------------------------------------
/OSMMapTilePackager/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.osmdroid
6 | osmdroid-parent
7 | 4.2
8 |
9 |
10 | osmdroid-packager
11 | jar
12 |
13 | OSM map tile packager
14 | A tool to package OpenStreetMap tiles
15 |
16 |
17 |
18 |
19 | android
20 | android
21 |
22 |
23 | org.apache.httpcomponents
24 | httpmime
25 |
26 |
27 | org.apache.james
28 | apache-mime4j
29 |
30 |
31 |
32 |
33 | org.slf4j
34 | slf4j-api
35 |
36 |
37 |
38 |
39 | org.slf4j
40 | slf4j-log4j12
41 |
42 |
43 | junit
44 | junit
45 |
46 |
47 |
48 |
49 | org.osmdroid
50 | osmdroid-android
51 | ${project.version}
52 |
53 |
54 |
55 |
56 |
57 | ${basedir}/src
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/src/org/osmdroid/mtp/util/DbCreator.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.mtp.util;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.IOException;
7 | import java.sql.Connection;
8 | import java.sql.DriverManager;
9 | import java.sql.PreparedStatement;
10 | import java.sql.SQLException;
11 | import java.sql.Statement;
12 |
13 | public class DbCreator
14 | {
15 | public static void putFolderToDb(final File pDestinationFile, final File pFolderToPut) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException
16 | {
17 | pDestinationFile.delete();
18 | Class.forName("org.sqlite.JDBC");
19 | final Connection conn = DriverManager.getConnection("jdbc:sqlite:" + pDestinationFile);
20 | final Statement stat = conn.createStatement();
21 | stat.execute("CREATE TABLE tiles (key INTEGER PRIMARY KEY, provider TEXT, tile BLOB)");
22 | stat.close();
23 | final PreparedStatement prep = conn.prepareStatement("insert into tiles values (?, ?, ?);");
24 | for(final File zf : pFolderToPut.listFiles())
25 | {
26 | for(final File xf : zf.listFiles())
27 | {
28 | for(final File yf : xf.listFiles())
29 | {
30 | // escaped path separator
31 | // Windows -> \\
32 | // Unix -> \/
33 | final String[] s = yf.toString().split("\\" + File.separator);
34 | final long z = Long.parseLong(s[s.length - 3]);
35 | final long x = Long.parseLong(s[s.length - 2]);
36 | final long y = Long.parseLong(s[s.length - 1].split(".png")[0]);
37 | final long index = (((z << z) + x) << z) + y;
38 | prep.setLong(1, index);
39 | final String provider = s[s.length - 4];
40 | prep.setString(2, provider);
41 | final byte[] image = new byte[(int) yf.length()];
42 | final FileInputStream str = new FileInputStream(yf);
43 | str.read(image);
44 | str.close();
45 | prep.setBytes(3, image);
46 | prep.executeUpdate();
47 | }
48 | }
49 | }
50 | conn.setAutoCommit(false);
51 | prep.executeBatch();
52 | conn.setAutoCommit(true);
53 | conn.close();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/src/org/osmdroid/mtp/util/FolderDeleter.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 2:27:27 AM - Mar 6, 2009
2 | package org.osmdroid.mtp.util;
3 |
4 | import java.io.File;
5 |
6 | public class FolderDeleter {
7 | // ===========================================================
8 | // Constants
9 | // ===========================================================
10 |
11 | // ===========================================================
12 | // Fields
13 | // ===========================================================
14 |
15 | // ===========================================================
16 | // Constructors
17 | // ===========================================================
18 |
19 | // ===========================================================
20 | // Getter & Setter
21 | // ===========================================================
22 |
23 | // ===========================================================
24 | // Methods from SuperClass/Interfaces
25 | // ===========================================================
26 |
27 | // ===========================================================
28 | // Methods
29 | // ===========================================================
30 |
31 | /**
32 | * @return true
on success, false
otherwise.
33 | */
34 | public static boolean deleteFolder(final File pFolder){
35 | final File[] children = pFolder.listFiles();
36 |
37 | for(final File c : children){
38 | if(c.isDirectory()){
39 | if(!deleteFolder(c)){
40 | System.err.println("Could not delete " + c.getAbsolutePath());
41 | return false;
42 | }
43 | }else{
44 | if(!c.delete()){
45 | System.err.println("Could not delete " + c.getAbsolutePath());
46 | return false;
47 | }
48 | }
49 | }
50 | return pFolder.delete();
51 | }
52 |
53 | // ===========================================================
54 | // Inner and Anonymous Classes
55 | // ===========================================================
56 | }
57 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/src/org/osmdroid/mtp/util/FolderFileCounter.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 3:43:56 PM - Mar 6, 2009
2 | package org.osmdroid.mtp.util;
3 |
4 | import java.io.File;
5 |
6 | public class FolderFileCounter {
7 | // ===========================================================
8 | // Constants
9 | // ===========================================================
10 |
11 | // ===========================================================
12 | // Fields
13 | // ===========================================================
14 |
15 | // ===========================================================
16 | // Constructors
17 | // ===========================================================
18 |
19 | // ===========================================================
20 | // Getter & Setter
21 | // ===========================================================
22 |
23 | // ===========================================================
24 | // Methods from SuperClass/Interfaces
25 | // ===========================================================
26 |
27 | // ===========================================================
28 | // Methods
29 | // ===========================================================
30 |
31 | /**
32 | * @return true
on success, false
otherwise.
33 | */
34 | public static int getTotalRecursiveFileCount(final File pFolder){
35 | final File[] children = pFolder.listFiles();
36 |
37 | int tmpCnt = 0;
38 | for(final File c : children){
39 | if(c.isDirectory()){
40 | tmpCnt += getTotalRecursiveFileCount(c);
41 | }else{
42 | tmpCnt++;
43 | }
44 | }
45 | return tmpCnt;
46 | }
47 |
48 | // ===========================================================
49 | // Inner and Anonymous Classes
50 | // ===========================================================
51 | }
52 |
--------------------------------------------------------------------------------
/OSMMapTilePackager/src/org/osmdroid/mtp/util/Util.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 10:15:51 PM - Mar 5, 2009
2 | package org.osmdroid.mtp.util;
3 |
4 | import org.osmdroid.mtp.adt.OSMTileInfo;
5 |
6 | public class Util {
7 | // ===========================================================
8 | // Constants
9 | // ===========================================================
10 |
11 | // ===========================================================
12 | // Fields
13 | // ===========================================================
14 |
15 | // ===========================================================
16 | // Constructors
17 | // ===========================================================
18 |
19 | // ===========================================================
20 | // Getter & Setter
21 | // ===========================================================
22 |
23 | // ===========================================================
24 | // Methods from SuperClass/Interfaces
25 | // ===========================================================
26 |
27 | // ===========================================================
28 | // Methods
29 | // ===========================================================
30 |
31 | /**
32 | * For a description see:
33 | * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames
34 | * For a code-description see:
35 | * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames#compute_bounding_box_for_tile_number
36 | * @param aLat latitude to get the {@link OSMTileInfo} for.
37 | * @param aLon longitude to get the {@link OSMTileInfo} for.
38 | * @return The {@link OSMTileInfo} providing 'x' 'y' and 'z'(oom) for the coordinates passed.
39 | */
40 | public static OSMTileInfo getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) {
41 | final int y = (int) Math.floor((1 - Math.log(Math.tan(aLat * Math.PI / 180) + 1 / Math.cos(aLat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom));
42 | final int x = (int) Math.floor((aLon + 180) / 360 * (1 << zoom));
43 |
44 | return new OSMTileInfo(x, y, zoom);
45 | }
46 |
47 | // ===========================================================
48 | // Inner and Anonymous Classes
49 | // ===========================================================
50 | }
51 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | OpenStreetMapViewer
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.eclipse.m2e.core.maven2Nature
36 | com.android.ide.eclipse.adt.AndroidNature
37 | org.eclipse.jdt.core.javanature
38 |
39 |
40 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.4'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | dependencies {
12 | }
13 |
14 | android {
15 | compileSdkVersion 16
16 | buildToolsVersion "16"
17 |
18 | defaultConfig {
19 | minSdkVersion 4
20 | targetSdkVersion 16
21 | }
22 | sourceSets {
23 | main {
24 | manifest.srcFile 'AndroidManifest.xml'
25 | java.srcDirs = ['src']
26 | resources.srcDirs = ['src']
27 | aidl.srcDirs = ['src']
28 | renderscript.srcDirs = ['src']
29 | res.srcDirs = ['res']
30 | assets.srcDirs = ['assets']
31 | }
32 |
33 | instrumentTest.setRoot('tests')
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-7
12 | apk-configurations=
13 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/ext/doc/gudermann.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/ext/doc/gudermann.xlsx
--------------------------------------------------------------------------------
/OpenStreetMapViewer/ext/php/gpxuploader/README.txt:
--------------------------------------------------------------------------------
1 | Place upload.php and the data-folder to the server and protect the data folder with a password! (Otherwise malicious code can be executed!)
--------------------------------------------------------------------------------
/OpenStreetMapViewer/ext/php/gpxuploader/upload.php:
--------------------------------------------------------------------------------
1 | \n";
18 | $baseErrorTag = "";
19 | $baseSuccessTag = "";
20 | $errorTag = "";
21 | $successTag = "";
22 |
23 | $uploaded_size = $_FILES['gpxfile']['size'];
24 |
25 | $maxFilesize = 500000; // In Bytes
26 |
27 | //This is our size condition
28 | if ($errorCode == $ERRCODE_NONE && $uploaded_size > $maxFilesize) {
29 | $errorCode = $ERRCODE_FILESIZE_EXCEEDED;
30 | $errorTag = sprintf($baseErrorTag, $errorCode, "Filezise exceeded. File: '" . $uploaded_size . "' Max: '" . $maxFilesize . "'");
31 | }
32 |
33 | if ($errorCode == $ERRCODE_NONE && !endsWith($filename, ".gpx")) {
34 | $errorCode = $ERRCODE_FILEENDING_BAD;
35 | $errorTag = sprintf($baseErrorTag, $errorCode, "Bad file-ending.");
36 | }
37 |
38 | //This is our limit file type condition
39 | if ($errorCode == $ERRCODE_NONE && $uploaded_type == "text/php") {
40 | $errorCode = $ERRCODE_FILETYPE_DISALLOWED;
41 | $errorTag = sprintf($baseErrorTag, $errorCode, "Disallowed Filetype");
42 | }
43 |
44 | if ($errorCode == $ERRCODE_NONE) { //If everything is ok we try to upload it
45 | if(move_uploaded_file($_FILES['gpxfile']['tmp_name'], $target)) {
46 | $successTag = sprintf($baseSuccessTag, "The file '". $filename . "' has been uploaded");
47 | } else {
48 | $errorCode = $ERRCODE_UPLOAD_ERROR;
49 | $errorTag = sprintf($baseErrorTag, $errorCode, "File '" . $filename . "' could not be uploaded.");
50 | }
51 | }
52 |
53 | if($errorCode == $ERRCODE_NONE){
54 | echo $xmlHead . $successTag;
55 | } else {
56 | echo $xmlHead . $errorTag;
57 | }
58 | ?>
--------------------------------------------------------------------------------
/OpenStreetMapViewer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.osmdroid
7 | osmdroid-parent
8 | 4.2
9 |
10 |
11 | OpenStreetMapViewer
12 | apk
13 |
14 | OpenStreetMap viewer
15 |
16 |
17 |
18 |
19 | android
20 | android
21 |
22 |
23 | android.support
24 | compatibility-v4
25 |
26 |
27 | commons-logging
28 | commons-logging
29 |
30 |
31 |
32 | ${project.groupId}
33 | osmdroid-android
34 | ${project.version}
35 |
36 |
37 | ${project.groupId}
38 | osmdroid-third-party
39 | ${project.version}
40 |
41 |
42 | org.slf4j
43 | slf4j-android
44 |
45 |
46 |
47 |
48 | ${basedir}/src
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-jarsigner-plugin
53 |
54 |
55 | com.jayway.maven.plugins.android.generation2
56 | android-maven-plugin
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-16
12 | apk-configurations=
13 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/center.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/center.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/direction_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/direction_arrow.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/ic_menu_compass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/ic_menu_compass.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/ic_menu_mapmode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/ic_menu_mapmode.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/ic_menu_mylocation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/ic_menu_mylocation.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/ic_menu_offline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/ic_menu_offline.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/icon.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/marker_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/marker_default.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/marker_default_focused_base.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/marker_default_focused_base.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/navto_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/navto_small.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/next.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/person.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/previous.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/previous.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/zoom_in.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/zoom_in.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/drawable/zoom_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/OpenStreetMapViewer/res/drawable/zoom_out.png
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/layout/mapview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Kartenmodus
4 | Standort
5 | Über
6 | Diese Software benutzt Kartenmaterial von OpenStreetMap.org
7 |
8 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/values-de/tile_sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | OSM Basislayer
4 | TopographischReliefFahrradkarte
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/values-it/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | OpenStreetMap
4 |
5 | Sconosciuta
6 | Tipo mappa
7 | La mia posizione
8 | Info
9 | Questo software usa dati delle mappe forniti da <b>OpenStreetMap.org</b>
10 |
11 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/values-it/tile_sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Mapnik
4 | Mappa ciclistica
5 | Sentieri
6 | Rilievo
7 |
8 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | OpenStreetMap
4 |
5 | Unknown
6 | Map mode
7 | My location
8 | Offline mode
9 | Samples
10 | About
11 | This software uses map data provided by <b>OpenStreetMap.org</b>
12 |
13 | Got the first fix
14 |
15 | Set to offline mode
16 | Set to online mode
17 |
18 | showing and tracking my current location
19 | hiding my current location
20 |
21 | %s m
22 | %s km
23 | %s mi
24 | %s nm
25 | %s ft
26 |
27 | Compass
28 |
29 |
30 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/res/values/tile_sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Mapnik
4 | Cycle Map
5 | Public transport
6 | OSM base layer
7 | Topographic
8 | Hills
9 | Mapquest
10 | Mapquest Aerial
11 | Bing
12 | MapBox
13 | OpenFietsKaart overlay
14 | Netherlands base overlay
15 | Netherlands roads overlay
16 |
17 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/MapActivity.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 00:23:14 - 03.10.2008
2 | package org.osmdroid;
3 |
4 | import android.app.AlertDialog;
5 | import android.app.Dialog;
6 | import android.content.DialogInterface;
7 | import android.os.Bundle;
8 | import android.support.v4.app.FragmentActivity;
9 | import android.support.v4.app.FragmentManager;
10 |
11 | /**
12 | * Default map view activity.
13 | *
14 | * @author Manuel Stahl
15 | *
16 | */
17 | public class MapActivity extends FragmentActivity
18 | {
19 |
20 | private static final int DIALOG_ABOUT_ID = 1;
21 | private static final String MAP_FRAGMENT_TAG = "org.osmdroid.MAP_FRAGMENT_TAG";
22 |
23 | // ===========================================================
24 | // Constructors
25 | // ===========================================================
26 | /** Called when the activity is first created. */
27 | @Override
28 | public void onCreate(final Bundle savedInstanceState)
29 | {
30 | super.onCreate(savedInstanceState);
31 |
32 | this.setContentView(R.layout.main);
33 |
34 | FragmentManager fm = this.getSupportFragmentManager();
35 |
36 | if (fm.findFragmentByTag(MAP_FRAGMENT_TAG) == null) {
37 | MapFragment mapFragment = MapFragment.newInstance();
38 | fm.beginTransaction().add(R.id.map_container, mapFragment, MAP_FRAGMENT_TAG).commit();
39 | }
40 | }
41 |
42 | @Override
43 | protected Dialog onCreateDialog(final int id)
44 | {
45 | Dialog dialog;
46 |
47 | switch (id) {
48 | case DIALOG_ABOUT_ID:
49 | return new AlertDialog.Builder(MapActivity.this).setIcon(R.drawable.icon)
50 | .setTitle(R.string.app_name).setMessage(R.string.about_message)
51 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
52 | @Override
53 | public void onClick(final DialogInterface dialog, final int whichButton)
54 | {
55 | //
56 | }
57 | }).create();
58 |
59 | default:
60 | dialog = null;
61 | break;
62 | }
63 | return dialog;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/ResourceProxyImpl.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.drawable.Drawable;
7 |
8 | /**
9 | * This is an extension of {@link org.osmdroid.DefaultResourceProxyImpl}
10 | * that first tries to get from the resources that this class is defined in.
11 | * If you don't want to copy this to your own app, you could instead use {@link org.osmdroid.util.ResourceProxyImpl}.
12 | */
13 | public class ResourceProxyImpl extends DefaultResourceProxyImpl {
14 |
15 | private final Context mContext;
16 |
17 | public ResourceProxyImpl(final Context pContext) {
18 | super(pContext);
19 | mContext = pContext;
20 | }
21 |
22 | @Override
23 | public String getString(final string pResId) {
24 | try {
25 | final int res = R.string.class.getDeclaredField(pResId.name()).getInt(null);
26 | return mContext.getString(res);
27 | } catch (final Exception e) {
28 | return super.getString(pResId);
29 | }
30 | }
31 |
32 | @Override
33 | public String getString(final string pResId, final Object... formatArgs) {
34 | try {
35 | final int res = R.string.class.getDeclaredField(pResId.name()).getInt(null);
36 | return mContext.getString(res, formatArgs);
37 | } catch (final Exception e) {
38 | return super.getString(pResId, formatArgs);
39 | }
40 | }
41 |
42 | @Override
43 | public Bitmap getBitmap(final bitmap pResId) {
44 | try {
45 | final int res = R.drawable.class.getDeclaredField(pResId.name()).getInt(null);
46 | return BitmapFactory.decodeResource(mContext.getResources(), res);
47 | } catch (final Exception e) {
48 | return super.getBitmap(pResId);
49 | }
50 | }
51 |
52 | @Override
53 | public Drawable getDrawable(final bitmap pResId) {
54 | try {
55 | final int res = R.drawable.class.getDeclaredField(pResId.name()).getInt(null);
56 | return mContext.getResources().getDrawable(res);
57 | } catch (final Exception e) {
58 | return super.getDrawable(pResId);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/RotationGestureDetector.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import android.view.MotionEvent;
4 |
5 | public class RotationGestureDetector {
6 |
7 | public interface RotationListener {
8 | public void onRotate(float deltaAngle);
9 | }
10 |
11 | protected float mRotation;
12 | private RotationListener mListener;
13 |
14 | public RotationGestureDetector(RotationListener listener) {
15 | mListener = listener;
16 | }
17 |
18 | private float rotation(MotionEvent event) {
19 | double delta_x = (event.getX(0) - event.getX(1));
20 | double delta_y = (event.getY(0) - event.getY(1));
21 | double radians = Math.atan2(delta_y, delta_x);
22 | return (float) Math.toDegrees(radians);
23 | }
24 |
25 | public void onTouch(MotionEvent e) {
26 | if (e.getPointerCount() != 2)
27 | return;
28 |
29 | if (e.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
30 | mRotation = rotation(e);
31 | }
32 |
33 | float rotation = rotation(e);
34 | float delta = rotation - mRotation;
35 | mRotation += delta;
36 | mListener.onRotate(delta);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/SampleOverlayItem.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import org.osmdroid.util.GeoPoint;
4 | import org.osmdroid.views.overlay.OverlayItem;
5 |
6 | import android.graphics.Canvas;
7 | import android.graphics.drawable.Drawable;
8 |
9 | public class SampleOverlayItem extends OverlayItem {
10 |
11 | public SampleOverlayItem(String aUid, String aTitle, String aDescription, GeoPoint aGeoPoint,
12 | Drawable aMarker, HotspotPlace aHotspotPlace) {
13 | super(aUid, aTitle, aDescription, aGeoPoint);
14 | this.setMarker(aMarker);
15 | this.setMarkerHotspot(aHotspotPlace);
16 | }
17 |
18 | public void draw(Canvas canvas) {
19 | //
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/constants/OpenStreetMapConstants.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 23:11:31 - 22.09.2008
2 | package org.osmdroid.constants;
3 |
4 | /**
5 | *
6 | * This class contains constants used by the sample applications.
7 | *
8 | * @author Nicolas Gramlich
9 | *
10 | */
11 | public interface OpenStreetMapConstants {
12 | // ===========================================================
13 | // Final Fields
14 | // ===========================================================
15 |
16 | public static final String DEBUGTAG = "OPENSTREETMAP";
17 |
18 | public static final boolean DEBUGMODE = false;
19 |
20 | public static final int NOT_SET = Integer.MIN_VALUE;
21 |
22 | public static final String PREFS_NAME = "org.andnav.osm.prefs";
23 | public static final String PREFS_TILE_SOURCE = "tilesource";
24 | public static final String PREFS_SCROLL_X = "scrollX";
25 | public static final String PREFS_SCROLL_Y = "scrollY";
26 | public static final String PREFS_ZOOM_LEVEL = "zoomLevel";
27 | public static final String PREFS_SHOW_LOCATION = "showLocation";
28 | public static final String PREFS_SHOW_COMPASS = "showCompass";
29 |
30 | // ===========================================================
31 | // Methods
32 | // ===========================================================
33 | }
34 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/samplefragments/BaseSampleFragment.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.samplefragments;
2 |
3 | import org.osmdroid.ResourceProxy;
4 | import org.osmdroid.ResourceProxyImpl;
5 | import org.osmdroid.views.MapView;
6 |
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | public abstract class BaseSampleFragment extends Fragment {
14 |
15 | public abstract String getSampleTitle();
16 |
17 | // ===========================================================
18 | // Fields
19 | // ===========================================================
20 |
21 | protected MapView mMapView;
22 | protected ResourceProxy mResourceProxy;
23 |
24 | @Override
25 | public void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | }
28 |
29 | @Override
30 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
31 | mResourceProxy = new ResourceProxyImpl(inflater.getContext().getApplicationContext());
32 | mMapView = new MapView(inflater.getContext(), 256, mResourceProxy);
33 | return mMapView;
34 | }
35 |
36 | @Override
37 | public void onActivityCreated(Bundle savedInstanceState) {
38 | super.onActivityCreated(savedInstanceState);
39 |
40 | addOverlays();
41 |
42 | mMapView.setBuiltInZoomControls(true);
43 | mMapView.setMultiTouchControls(true);
44 | }
45 |
46 | /**
47 | * An appropriate place to override and add overlays.
48 | */
49 | protected void addOverlays() {
50 | //
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/samplefragments/SampleFactory.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.samplefragments;
2 |
3 |
4 | public final class SampleFactory {
5 |
6 | private final BaseSampleFragment[] mSamples;
7 |
8 | private static SampleFactory _instance;
9 | public static SampleFactory getInstance() {
10 | if (_instance == null) {
11 | _instance = new SampleFactory();
12 | }
13 | return _instance;
14 | }
15 |
16 | private SampleFactory() {
17 | mSamples = new BaseSampleFragment[] { new SampleWithMinimapItemizedoverlayWithFocus(),
18 | new SampleLimitedScrollArea(), new SampleFragmentXmlLayout() };
19 | }
20 |
21 | public BaseSampleFragment getSample(int index) {
22 | return mSamples[index];
23 | }
24 |
25 | public int count() {
26 | return mSamples.length;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/samplefragments/SampleFragmentXmlLayout.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.samplefragments;
2 |
3 | import org.osmdroid.R;
4 | import org.osmdroid.views.MapView;
5 |
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | public class SampleFragmentXmlLayout extends BaseSampleFragment {
12 |
13 | // ===========================================================
14 | // Fields
15 | // ===========================================================
16 |
17 | public static final String TITLE = "MapView in XML layout";
18 |
19 | @Override
20 | public String getSampleTitle() {
21 | return TITLE;
22 | }
23 |
24 | @Override
25 | public void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | }
28 |
29 | @Override
30 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
31 | View v = inflater.inflate(R.layout.mapview, null);
32 | mMapView = (MapView) v.findViewById(R.id.mapview);
33 | return v;
34 | // mResourceProxy = new ResourceProxyImpl(inflater.getContext().getApplicationContext());
35 | // mMapView = new MapView(inflater.getContext(), 256, mResourceProxy);
36 | // mMapView.setUseSafeCanvas(true);
37 | // return mMapView;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/samples/SampleOSMContributor.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.samples;
2 |
3 | import android.location.Location;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | /**
8 | * Sample code to show how easy it is to contribute to the OpenStreetMap Project.
9 | *
10 | * @author Nicolas Gramlich
11 | */
12 | public class SampleOSMContributor extends SampleMapActivity {
13 |
14 | /** Called when the activity is first created. */
15 | @Override
16 | public void onCreate(final Bundle savedInstanceState) {
17 | /*
18 | * You need to do exactly nothing, to contribute to the OSM-Project, except extending from
19 | * OpenStreetMapActivity and passing true to its onCreate(...) .
20 | */
21 | super.onCreate(savedInstanceState, false);
22 | final TextView tv = new TextView(this);
23 | tv.setText("While reading this, your GPS position is recorded and when you exit this application, your route will get uploaded to the OpenStreetMap-Project.");
24 | this.setContentView(tv);
25 | }
26 |
27 | @Override
28 | public void onLocationChanged(final Location loc) {
29 | // Nothing to do...
30 | }
31 |
32 | @Override
33 | public void onLocationLost() {
34 | // Nothing to do...
35 | }
36 | }
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/samples/SampleWithTilesOverlay.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.samples;
2 |
3 | import org.osmdroid.tileprovider.MapTileProviderBasic;
4 | import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
5 | import org.osmdroid.util.GeoPoint;
6 | import org.osmdroid.views.MapView;
7 | import org.osmdroid.views.overlay.TilesOverlay;
8 |
9 | import android.app.Activity;
10 | import android.os.Bundle;
11 | import android.widget.RelativeLayout;
12 | import android.widget.RelativeLayout.LayoutParams;
13 |
14 | /**
15 | *
16 | * @author Alex van der Linden
17 | *
18 | */
19 | public class SampleWithTilesOverlay extends Activity {
20 |
21 | // ===========================================================
22 | // Constants
23 | // ===========================================================
24 |
25 | // ===========================================================
26 | // Fields
27 | // ===========================================================
28 |
29 | private MapView mOsmv;
30 | private TilesOverlay mTilesOverlay;
31 | private MapTileProviderBasic mProvider;
32 |
33 | // ===========================================================
34 | // Constructors
35 | // ===========================================================
36 | /** Called when the activity is first created. */
37 | @Override
38 | public void onCreate(final Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 |
41 | // Setup base map
42 | final RelativeLayout rl = new RelativeLayout(this);
43 |
44 | this.mOsmv = new MapView(this, 256);
45 | rl.addView(this.mOsmv, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
46 | LayoutParams.FILL_PARENT));
47 | this.mOsmv.setBuiltInZoomControls(true);
48 |
49 | // zoom to the netherlands
50 | this.mOsmv.getController().setZoom(7);
51 | this.mOsmv.getController().setCenter(new GeoPoint(51500000, 5400000));
52 |
53 | // Add tiles layer
54 | mProvider = new MapTileProviderBasic(getApplicationContext());
55 | mProvider.setTileSource(TileSourceFactory.FIETS_OVERLAY_NL);
56 | this.mTilesOverlay = new TilesOverlay(mProvider, this.getBaseContext());
57 | this.mOsmv.getOverlays().add(this.mTilesOverlay);
58 |
59 | this.setContentView(rl);
60 | }
61 |
62 | // ===========================================================
63 | // Getter & Setter
64 | // ===========================================================
65 |
66 | // ===========================================================
67 | // Methods from SuperClass/Interfaces
68 | // ===========================================================
69 |
70 | // ===========================================================
71 | // Methods
72 | // ===========================================================
73 |
74 | // ===========================================================
75 | // Inner and Anonymous Classes
76 | // ===========================================================
77 | }
78 |
--------------------------------------------------------------------------------
/OpenStreetMapViewer/src/org/osmdroid/views/util/MapTileProviderFactory.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 21:46:22 - 25.09.2008
2 | package org.osmdroid.views.util;
3 |
4 | import org.osmdroid.tileprovider.MapTileProviderBase;
5 | import org.osmdroid.tileprovider.MapTileProviderBasic;
6 | import org.osmdroid.views.MapView;
7 | import org.osmdroid.views.util.constants.MapViewConstants;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 |
11 | import android.content.Context;
12 |
13 | /**
14 | *
15 | * @author Nicolas Gramlich
16 | *
17 | */
18 | public class MapTileProviderFactory implements MapViewConstants {
19 |
20 | private static final Logger logger = LoggerFactory.getLogger(MapTileProviderFactory.class);
21 |
22 | /**
23 | * Get a tile provider. If a tile provider service exists then it will use the service,
24 | * otherwise it'll use a direct tile provider that doesn't use a service. This can be used as
25 | * the tile provider parameter in the {@link MapView} constructor.
26 | */
27 | public static MapTileProviderBase getInstance(final Context aContext) {
28 | logger.info("Using direct tile provider");
29 | return new MapTileProviderBasic(aContext.getApplicationContext());
30 | }
31 |
32 | /**
33 | * This is a utility class with only static members.
34 | */
35 | private MapTileProviderFactory() {
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/osmdroid-android-it/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/osmdroid-android-it/default.properties:
--------------------------------------------------------------------------------
1 | # File used by Eclipse to determine the target system
2 | # Project target.
3 | target=android-16
--------------------------------------------------------------------------------
/osmdroid-android-it/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.osmdroid
7 | osmdroid-parent
8 | 4.2
9 |
10 |
11 | osmdroid-android-it
12 | 4.2
13 | apk
14 | osmdroid-android-it - Integration tests
15 |
16 |
17 |
18 | android
19 | android
20 |
21 |
22 | junit
23 | junit
24 | provided
25 |
26 |
27 | org.osmdroid
28 | OpenStreetMapViewer
29 | apk
30 | 4.2
31 | provided
32 |
33 |
34 | org.osmdroid
35 | OpenStreetMapViewer
36 | jar
37 | 4.2
38 | provided
39 |
40 |
41 | org.osmdroid
42 | osmdroid-android
43 | jar
44 | 4.2
45 | provided
46 |
47 |
48 |
49 |
50 | ${project.artifactId}
51 |
52 |
53 | com.jayway.maven.plugins.android.generation2
54 | android-maven-plugin
55 |
56 |
57 |
58 |
59 | `
60 |
61 |
62 |
63 |
64 |
65 | true
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/osmdroid-android-it/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android-it/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/osmdroid-android-it/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android-it/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/osmdroid-android-it/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android-it/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/osmdroid-android-it/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/osmdroid-android-it/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello osmdroid-android-it!
4 | osmdroid-android-it - tests
5 |
6 |
--------------------------------------------------------------------------------
/osmdroid-android-it/src/main/java/org/osmdroid/ContextResourceProxyTest.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import java.nio.ByteBuffer;
4 |
5 | import android.graphics.Bitmap;
6 | import android.test.AndroidTestCase;
7 |
8 | /**
9 | * @author Neil Boyd
10 | *
11 | */
12 | public class ContextResourceProxyTest extends AndroidTestCase {
13 |
14 | public void test_getString() {
15 | final ResourceProxy rp = new ResourceProxyImpl(getContext());
16 | final String mapnik = rp.getString(ResourceProxy.string.mapnik);
17 | assertEquals("Got string okay", "Mapnik", mapnik);
18 | }
19 |
20 | public void test_getBitmap() {
21 | final ResourceProxy rp = new ResourceProxyImpl(getContext());
22 | final Bitmap center = rp.getBitmap(ResourceProxy.bitmap.person);
23 | assertNotNull("Got bitmap okay", center);
24 | }
25 |
26 | public void test_getBitmap_compare_with_default() {
27 | final ResourceProxy contextResourceProxy = new ResourceProxyImpl(getContext());
28 | final Bitmap contextBitmap = contextResourceProxy.getBitmap(ResourceProxy.bitmap.person);
29 |
30 | final ResourceProxy defaultResourceProxy = new DefaultResourceProxyImpl(getContext());
31 | final Bitmap defaultBitmap = defaultResourceProxy.getBitmap(ResourceProxy.bitmap.person);
32 | // FIXME this throws an exception
33 |
34 | // compare a few things to see if they're the same bitmap
35 | assertEquals("Compare config", contextBitmap.getConfig(), defaultBitmap.getConfig());
36 | assertEquals("Compare width", contextBitmap.getWidth(), defaultBitmap.getWidth());
37 | assertEquals("Compare height", contextBitmap.getHeight(), defaultBitmap.getHeight());
38 |
39 | // compare the total thing
40 | final ByteBuffer bb1 = ByteBuffer.allocate(contextBitmap.getWidth()
41 | * contextBitmap.getHeight() * 4);
42 | contextBitmap.copyPixelsToBuffer(bb1);
43 | final ByteBuffer bb2 = ByteBuffer.allocate(defaultBitmap.getWidth()
44 | * defaultBitmap.getHeight() * 4);
45 | defaultBitmap.copyPixelsToBuffer(bb2);
46 | assertEquals("Compare pixels", bb1, bb2);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/osmdroid-android-it/src/main/java/org/osmdroid/test/MapActivityTest.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.test;
2 |
3 | import org.osmdroid.MapActivity;
4 |
5 | import android.test.ActivityInstrumentationTestCase2;
6 |
7 | public class MapActivityTest extends ActivityInstrumentationTestCase2 {
8 |
9 | public MapActivityTest() {
10 | super("org.osmdroid", MapActivity.class);
11 | }
12 |
13 | public void testActivity() {
14 | MapActivity activity = getActivity();
15 | assertNotNull(activity);
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/osmdroid-android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/osmdroid-android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | osmdroid-android
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/osmdroid-android/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_MODULE := osmdroid-android
5 | LOCAL_STATIC_JAVA_LIBRARIES := slf4j-android
6 | LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java)
7 | LOCAL_SRC_FILES := $(filter-out src/main/java/org/osmdroid/contributor/GpxToPHPUploader.java,$(LOCAL_SRC_FILES))
8 |
9 | include $(BUILD_STATIC_JAVA_LIBRARY)
10 |
--------------------------------------------------------------------------------
/osmdroid-android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | sourceSets {
3 | main.java.srcDirs = ['src\main\java','src\main\resources','src\test\java','src\test\resources']
4 | }
5 |
--------------------------------------------------------------------------------
/osmdroid-android/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.osmdroid
6 | osmdroid-parent
7 | 4.2
8 |
9 |
10 | osmdroid-android
11 | jar
12 |
13 | OSMdroid Android
14 | An Android library to display OpenStreetMap views.
15 |
16 |
17 |
18 |
19 | android
20 | android
21 |
22 |
23 | org.apache.httpcomponents
24 | httpmime
25 |
26 |
27 | org.apache.james
28 | apache-mime4j
29 |
30 |
31 |
32 |
33 | org.slf4j
34 | slf4j-api
35 |
36 |
37 |
38 |
39 | org.slf4j
40 | slf4j-log4j12
41 |
42 |
43 | junit
44 | junit
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/LocationListenerProxy.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import android.location.Location;
4 | import android.location.LocationListener;
5 | import android.location.LocationManager;
6 | import android.os.Bundle;
7 |
8 | public class LocationListenerProxy implements LocationListener {
9 | private final LocationManager mLocationManager;
10 | private LocationListener mListener = null;
11 |
12 | public LocationListenerProxy(final LocationManager pLocationManager) {
13 | mLocationManager = pLocationManager;
14 | }
15 |
16 | public boolean startListening(final LocationListener pListener, final long pUpdateTime,
17 | final float pUpdateDistance) {
18 | boolean result = false;
19 | mListener = pListener;
20 | for (final String provider : mLocationManager.getProviders(true)) {
21 | if (LocationManager.GPS_PROVIDER.equals(provider)
22 | || LocationManager.NETWORK_PROVIDER.equals(provider)) {
23 | result = true;
24 | mLocationManager.requestLocationUpdates(provider, pUpdateTime, pUpdateDistance,
25 | this);
26 | }
27 | }
28 | return result;
29 | }
30 |
31 | public void stopListening() {
32 | mListener = null;
33 | mLocationManager.removeUpdates(this);
34 | }
35 |
36 | @Override
37 | public void onLocationChanged(final Location arg0) {
38 | if (mListener != null) {
39 | mListener.onLocationChanged(arg0);
40 | }
41 | }
42 |
43 | @Override
44 | public void onProviderDisabled(final String arg0) {
45 | if (mListener != null) {
46 | mListener.onProviderDisabled(arg0);
47 | }
48 | }
49 |
50 | @Override
51 | public void onProviderEnabled(final String arg0) {
52 | if (mListener != null) {
53 | mListener.onProviderEnabled(arg0);
54 | }
55 | }
56 |
57 | @Override
58 | public void onStatusChanged(final String arg0, final int arg1, final Bundle arg2) {
59 | if (mListener != null) {
60 | mListener.onStatusChanged(arg0, arg1, arg2);
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/ResourceProxy.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.Drawable;
5 |
6 | public interface ResourceProxy {
7 |
8 | public static enum string {
9 |
10 | // tile sources
11 | mapnik, cyclemap, public_transport, cloudmade_small, cloudmade_standard, mapquest_osm, mapquest_aerial, bing, mapbox,
12 |
13 | // overlays
14 | fiets_nl, base_nl, roads_nl,
15 |
16 | // other stuff
17 | unknown, format_distance_meters, format_distance_kilometers, format_distance_miles, format_distance_nautical_miles, format_distance_feet, online_mode, offline_mode, my_location, compass, map_mode,
18 |
19 | }
20 |
21 | public static enum bitmap {
22 |
23 | /**
24 | * For testing - the image doesn't exist.
25 | */
26 | unknown,
27 |
28 | center, direction_arrow, marker_default, marker_default_focused_base, navto_small, next, previous, person,
29 |
30 | /**
31 | * Menu icons
32 | */
33 | ic_menu_offline, ic_menu_mylocation, ic_menu_compass, ic_menu_mapmode
34 | }
35 |
36 | String getString(string pResId);
37 |
38 | /**
39 | * Use a string resource as a format definition, and format using the supplied format arguments.
40 | */
41 | String getString(string pResId, Object... formatArgs);
42 |
43 | Bitmap getBitmap(bitmap pResId);
44 |
45 | /**
46 | * Get a bitmap as a {@link Drawable}
47 | */
48 | Drawable getDrawable(bitmap pResId);
49 |
50 | /**
51 | * Gets the density from the current screen's DisplayMetrics
52 | *
53 | * @return the screen's density
54 | */
55 | float getDisplayMetricsDensity();
56 | }
57 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/SensorEventListenerProxy.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import android.hardware.Sensor;
4 | import android.hardware.SensorEvent;
5 | import android.hardware.SensorEventListener;
6 | import android.hardware.SensorManager;
7 |
8 | public class SensorEventListenerProxy implements SensorEventListener {
9 | private final SensorManager mSensorManager;
10 | private SensorEventListener mListener = null;
11 |
12 | public SensorEventListenerProxy(final SensorManager pSensorManager) {
13 | mSensorManager = pSensorManager;
14 | }
15 |
16 | public boolean startListening(final SensorEventListener pListener, final int pSensorType,
17 | final int pRate) {
18 | final Sensor sensor = mSensorManager.getDefaultSensor(pSensorType);
19 | if (sensor == null)
20 | return false;
21 | mListener = pListener;
22 | return mSensorManager.registerListener(this, sensor, pRate);
23 | }
24 |
25 | public void stopListening() {
26 | mListener = null;
27 | mSensorManager.unregisterListener(this);
28 | }
29 |
30 | @Override
31 | public void onAccuracyChanged(final Sensor pSensor, final int pAccuracy) {
32 | if (mListener != null) {
33 | mListener.onAccuracyChanged(pSensor, pAccuracy);
34 | }
35 | }
36 |
37 | @Override
38 | public void onSensorChanged(final SensorEvent pEvent) {
39 | if (mListener != null) {
40 | mListener.onSensorChanged(pEvent);
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IGeoPoint.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | /**
4 | * An interface that resembles the Google Maps API GeoPoint class.
5 | */
6 | public interface IGeoPoint {
7 | int getLatitudeE6();
8 | int getLongitudeE6();
9 | double getLatitude();
10 | double getLongitude();
11 | }
12 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IMap.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | /**
4 | * An interface that contains the common features of osmdroid and Google Maps v2.
5 | */
6 | public interface IMap {
7 |
8 | /**
9 | * Get the current zoom level of the map
10 | */
11 | float getZoomLevel();
12 |
13 | /**
14 | * Set the zoom level of the map
15 | */
16 | void setZoom(float zoomLevel);
17 |
18 | /**
19 | * Get the center of the map
20 | */
21 | IGeoPoint getCenter();
22 |
23 | /**
24 | * Set the center of the map
25 | */
26 | void setCenter(double latitude, double longitude);
27 |
28 | /**
29 | * Get the bearing of the map.
30 | * Zero means the top of the map is facing north.
31 | */
32 | float getBearing();
33 |
34 | /**
35 | * Set the bearing of the map.
36 | * Set to zero for the top of the map to face north.
37 | */
38 | void setBearing(float bearing);
39 |
40 | /**
41 | * Set the position of the map
42 | */
43 | void setPosition(IPosition position);
44 |
45 | /**
46 | * Increase zoom level by one
47 | */
48 | boolean zoomIn();
49 |
50 | /**
51 | * Decrease zoom level by one
52 | */
53 | boolean zoomOut();
54 |
55 | /**
56 | * Whether to show the "my location" dot on the map
57 | */
58 | void setMyLocationEnabled(boolean enabled);
59 |
60 | /**
61 | * Whether the map is currently showing the "my location" dot
62 | */
63 | boolean isMyLocationEnabled();
64 |
65 | /**
66 | * Get the map projection
67 | */
68 | IProjection getProjection();
69 |
70 | /**
71 | * Add a marker.
72 | */
73 | void addMarker(Marker marker);
74 |
75 | /**
76 | * Add a polyline.
77 | * This polyline will be added below other polylines, markers and MyLocationOverlay.
78 | * @return an id that can be used for adding points with {@link #addPointsToPolyline}
79 | */
80 | int addPolyline(Polyline polyline);
81 |
82 | /**
83 | * Add points to a polyline
84 | * @param id the id returned from {@link #addPolyline(Polyline)}
85 | * @param points the points to add
86 | * @throws IllegalArgumentException if a polyline with this id was not added
87 | */
88 | void addPointsToPolyline(int id, IGeoPoint... points);
89 |
90 | /**
91 | * Removes one polyline.
92 | * @param id the id returned from {@link #addPolyline(Polyline)}
93 | * @throws IllegalArgumentException if a polyline with this id was not added
94 | *
95 | */
96 | void clearPolyline(int id);
97 |
98 | /**
99 | * Removes all markers, polylines, polygons, overlays, etc from the map.
100 | */
101 | void clear();
102 |
103 | /**
104 | * Sets a callback that's invoked when the map view changes position.
105 | */
106 | void setOnCameraChangeListener(OnCameraChangeListener listener);
107 | }
108 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IMapController.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | import org.osmdroid.views.MapController;
4 |
5 | /**
6 | * An interface that resembles the Google Maps API MapController class and is implemented by the
7 | * osmdroid {@link MapController} class.
8 | *
9 | * @author Neil Boyd
10 | *
11 | */
12 | public interface IMapController {
13 | void animateTo(IGeoPoint geoPoint);
14 | void scrollBy(int x, int y);
15 | void setCenter(IGeoPoint point);
16 | int setZoom(int zoomLevel);
17 | void stopAnimation(boolean jumpToFinish);
18 | void stopPanning();
19 | boolean zoomIn();
20 | boolean zoomInFixing(int xPixel, int yPixel);
21 | boolean zoomOut();
22 | boolean zoomOutFixing(int xPixel, int yPixel);
23 | void zoomToSpan(int latSpanE6, int lonSpanE6);
24 | }
25 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IMapView.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | import org.osmdroid.views.MapView;
4 |
5 | /**
6 | * An interface that resembles the Google Maps API MapView class
7 | * and is implemented by the osmdroid {@link MapView} class.
8 | *
9 | * @author Neil Boyd
10 | *
11 | */
12 | public interface IMapView {
13 |
14 | IMapController getController();
15 | IProjection getProjection();
16 | int getZoomLevel();
17 | int getMaxZoomLevel();
18 | int getLatitudeSpan();
19 | int getLongitudeSpan();
20 | IGeoPoint getMapCenter();
21 |
22 | // some methods from View
23 | // (well, just one for now)
24 | void setBackgroundColor(int color);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IMyLocationOverlay.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | import org.osmdroid.views.overlay.MyLocationOverlay;
4 |
5 | import android.location.Location;
6 | import android.os.Bundle;
7 |
8 | /**
9 | * An interface that resembles the Google Maps API MyLocationOverlay class
10 | * and is implemented by the osmdroid {@link MyLocationOverlay} class.
11 | *
12 | * @author Neil Boyd
13 | *
14 | */
15 | public interface IMyLocationOverlay {
16 |
17 | boolean enableMyLocation();
18 | void disableMyLocation();
19 | boolean isMyLocationEnabled();
20 |
21 | boolean enableCompass();
22 | void disableCompass();
23 | boolean isCompassEnabled() ;
24 |
25 | public float getOrientation();
26 |
27 | boolean runOnFirstFix(Runnable runnable);
28 |
29 | void onStatusChanged(String provider, int status, Bundle extras);
30 |
31 | Location getLastFix();
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IPosition.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | /**
4 | * An interface that is used for simultaneously accessing several properties of the map
5 | */
6 | public interface IPosition {
7 |
8 | /**
9 | * The latitude of the center of the map
10 | */
11 | double getLatitude();
12 |
13 | /**
14 | * The longitude of the center of the map
15 | */
16 | double getLongitude();
17 |
18 | /**
19 | * Whether this position has a bearing
20 | */
21 | boolean hasBearing();
22 |
23 | /**
24 | * The bearing of the map
25 | */
26 | float getBearing();
27 |
28 | /**
29 | * Whether this position has a zoom level
30 | */
31 | boolean hasZoomLevel();
32 |
33 | /**
34 | * The zoom level of the map
35 | */
36 | float getZoomLevel();
37 | }
38 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/IProjection.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | import org.osmdroid.views.Projection;
4 |
5 | import android.graphics.Point;
6 |
7 | /**
8 | * An interface that resembles the Google Maps API Projection interface and is implemented by the
9 | * osmdroid {@link Projection} class.
10 | *
11 | * @author Neil Boyd
12 | *
13 | */
14 | public interface IProjection {
15 |
16 | /**
17 | * Converts the given {@link IGeoPoint} to onscreen pixel coordinates, relative to the top-left
18 | * of the {@link #MapView} that provided this Projection.
19 | *
20 | * @param in
21 | * The latitude/longitude pair to convert.
22 | * @param out
23 | * A pre-existing object to use for the output; if null, a new Point will be
24 | * allocated and returned.
25 | */
26 | Point toPixels(IGeoPoint in, Point out);
27 |
28 | /**
29 | * Create a new GeoPoint from pixel coordinates relative to the top-left of the MapView that
30 | * provided this PixelConverter.
31 | */
32 | IGeoPoint fromPixels(int x, int y);
33 |
34 | /**
35 | * Converts a distance in meters (along the equator) to one in (horizontal) pixels at the
36 | * current zoomlevel. In the default Mercator projection, the actual number of pixels for a
37 | * given distance will get higher as you move away from the equator.
38 | *
39 | * @param meters
40 | * the distance in meters
41 | * @return The number of pixels corresponding to the distance, if measured along the equator, at
42 | * the current zoom level. The return value may only be approximate.
43 | */
44 | float metersToEquatorPixels(float meters);
45 |
46 | /**
47 | * Get the coordinates of the most north-easterly visible point of the map.
48 | */
49 | IGeoPoint getNorthEast();
50 |
51 | /**
52 | * Get the coordinates of the most south-westerly visible point of the map.
53 | */
54 | IGeoPoint getSouthWest();
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/Marker.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public class Marker {
6 |
7 | public enum Anchor {
8 | NONE,
9 | CENTER, BOTTOM_CENTER // these are the only two supported by Google Maps v1
10 | }
11 |
12 | public final double latitude;
13 |
14 | public final double longitude;
15 |
16 | /**
17 | * The title of the marker. If null then marker has no title.
18 | */
19 | public String title;
20 |
21 | /**
22 | * The title of the marker. If null then marker has no title.
23 | * This method returns the marker for convenient method chaining.
24 | */
25 | public Marker title(final String aTitle) {
26 | title = aTitle;
27 | return this;
28 | }
29 |
30 | /**
31 | * Snippet displayed below the title. If null then marker has no snippet.
32 | */
33 | public String snippet;
34 |
35 | /**
36 | * Snippet displayed below the title. If null then marker has no snippet.
37 | * This method returns the marker for convenient method chaining.
38 | */
39 | public Marker snippet(final String aSnippet) {
40 | snippet = aSnippet;
41 | return this;
42 | }
43 |
44 | /**
45 | * Resource id of marker. If zero then use default marker.
46 | */
47 | public int icon;
48 |
49 | /**
50 | * Resource id of marker. If zero then use default marker.
51 | * This method returns the marker for convenient method chaining.
52 | */
53 | public Marker icon(final int aIcon) {
54 | icon = aIcon;
55 | return this;
56 | }
57 |
58 | /**
59 | * Bitmap of marker. If null then use {@link #icon}.
60 | */
61 | public Bitmap bitmap;
62 |
63 | /**
64 | * Bitmap of marker. If null then use {@link #icon}.
65 | * This method returns the marker for convenient method chaining.
66 | */
67 | public Marker bitmap(final Bitmap aBitmap) {
68 | bitmap = aBitmap;
69 | return this;
70 | }
71 |
72 | /*
73 | * Anchor of marker. Default is {@link Anchor#BOTTOM_CENTER}.
74 | */
75 | public Anchor anchor;
76 |
77 | /**
78 | * Anchor of marker. Default is {@link Anchor#BOTTOM_CENTER}.
79 | * This method returns the marker for convenient method chaining.
80 | */
81 | public Marker anchor(final Anchor aAnchor) {
82 | anchor = aAnchor;
83 | return this;
84 | }
85 |
86 | public Marker(final double aLatitude, final double aLongitude) {
87 | latitude = aLatitude;
88 | longitude = aLongitude;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/OnCameraChangeListener.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | public interface OnCameraChangeListener {
4 |
5 | /**
6 | * Called after the map view has changed.
7 | */
8 | void onCameraChange (IPosition position);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/api/Polyline.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | import android.graphics.Color;
8 |
9 | public class Polyline {
10 |
11 | public Polyline() {
12 | points = new ArrayList();
13 | }
14 |
15 | /**
16 | * The color of the polyline. Defaults to black.
17 | */
18 | public int color = Color.BLACK;
19 |
20 | /**
21 | * The color of the polyline. Defaults to black.
22 | * This method returns the polyline for convenient method chaining.
23 | */
24 | public Polyline color(final int aColor) {
25 | color = aColor;
26 | return this;
27 | }
28 |
29 | /**
30 | * The width of the polyline. Defaults to 2.
31 | */
32 | public float width = 2.0f;
33 |
34 | /**
35 | * The width of the polyline. Defaults to 2.
36 | * This method returns the polyline for convenient method chaining.
37 | */
38 | public Polyline width(final float aWidth) {
39 | width = aWidth;
40 | return this;
41 | }
42 |
43 | /**
44 | * The points of the polyline.
45 | */
46 | public List points;
47 |
48 | /**
49 | * The points of the polyline.
50 | * This method returns the polyline for convenient method chaining.
51 | */
52 | public Polyline points(final List aPoints) {
53 | points = aPoints;
54 | return this;
55 | }
56 |
57 | /**
58 | * The points of the polyline.
59 | * This method returns the polyline for convenient method chaining.
60 | */
61 | public Polyline points(final IGeoPoint... aPoints) {
62 | return points(Arrays.asList(aPoints));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/contributor/RouteRecorder.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 12:28:16 - 21.09.2008
2 | package org.osmdroid.contributor;
3 |
4 | import java.util.ArrayList;
5 |
6 | import org.osmdroid.contributor.util.RecordedGeoPoint;
7 | import org.osmdroid.util.GeoPoint;
8 |
9 | import android.location.Location;
10 |
11 | /**
12 | *
13 | * @author Nicolas Gramlich
14 | *
15 | */
16 | public class RouteRecorder {
17 | // ===========================================================
18 | // Constants
19 | // ===========================================================
20 |
21 | // ===========================================================
22 | // Fields
23 | // ===========================================================
24 |
25 | protected final ArrayList mRecords = new ArrayList();
26 |
27 | // ===========================================================
28 | // Constructors
29 | // ===========================================================
30 |
31 | // ===========================================================
32 | // Getter & Setter
33 | // ===========================================================
34 |
35 | public ArrayList getRecordedGeoPoints() {
36 | return this.mRecords;
37 | }
38 |
39 | // ===========================================================
40 | // Methods from SuperClass/Interfaces
41 | // ===========================================================
42 |
43 | // ===========================================================
44 | // Methods
45 | // ===========================================================
46 |
47 | public void add(final Location aLocation, final int aNumSatellites) {
48 | this.mRecords
49 | .add(new RecordedGeoPoint((int) (aLocation.getLatitude() * 1E6), (int) (aLocation
50 | .getLongitude() * 1E6), System.currentTimeMillis(), aNumSatellites));
51 | }
52 |
53 | public void add(final GeoPoint aGeoPoint, final int aNumSatellites) {
54 | this.mRecords.add(new RecordedGeoPoint(aGeoPoint.getLatitudeE6(), aGeoPoint
55 | .getLongitudeE6(), System.currentTimeMillis(), aNumSatellites));
56 | }
57 |
58 | // ===========================================================
59 | // Inner and Anonymous Classes
60 | // ===========================================================
61 | }
62 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/contributor/util/RecordedGeoPoint.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 12:29:23 - 21.09.2008
2 | package org.osmdroid.contributor.util;
3 |
4 | import org.osmdroid.contributor.util.constants.OpenStreetMapContributorConstants;
5 | import org.osmdroid.util.GeoPoint;
6 |
7 | /**
8 | * Extends the {@link GeoPoint} with a timeStamp.
9 | *
10 | * @author Nicolas Gramlich
11 | */
12 | public class RecordedGeoPoint extends GeoPoint implements OpenStreetMapContributorConstants {
13 |
14 | // ===========================================================
15 | // Constants
16 | // ===========================================================
17 |
18 | private static final long serialVersionUID = 7304941424576720318L;
19 |
20 | // ===========================================================
21 | // Fields
22 | // ===========================================================
23 |
24 | protected final long mTimeStamp;
25 | protected final int mNumSatellites;
26 |
27 | // ===========================================================
28 | // Constructors
29 | // ===========================================================
30 |
31 | public RecordedGeoPoint(final int latitudeE6, final int longitudeE6) {
32 | this(latitudeE6, longitudeE6, System.currentTimeMillis(), NOT_SET);
33 | }
34 |
35 | public RecordedGeoPoint(final int latitudeE6, final int longitudeE6, final long aTimeStamp,
36 | final int aNumSatellites) {
37 | super(latitudeE6, longitudeE6);
38 | this.mTimeStamp = aTimeStamp;
39 | this.mNumSatellites = aNumSatellites;
40 | }
41 |
42 | // ===========================================================
43 | // Getter & Setter
44 | // ===========================================================
45 |
46 | public long getTimeStamp() {
47 | return this.mTimeStamp;
48 | }
49 |
50 | public double getLatitudeAsDouble() {
51 | return this.getLatitudeE6() / 1E6;
52 | }
53 |
54 | public double getLongitudeAsDouble() {
55 | return this.getLongitudeE6() / 1E6;
56 | }
57 |
58 | public int getNumSatellites() {
59 | return this.mNumSatellites;
60 | }
61 |
62 | // ===========================================================
63 | // Methods from SuperClass/Interfaces
64 | // ===========================================================
65 |
66 | // ===========================================================
67 | // Methods
68 | // ===========================================================
69 |
70 | // ===========================================================
71 | // Inner and Anonymous Classes
72 | // ===========================================================
73 | }
74 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/contributor/util/Util.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 13:24:05 - 21.09.2008
2 | package org.osmdroid.contributor.util;
3 |
4 | import java.text.SimpleDateFormat;
5 | import java.util.ArrayList;
6 | import java.util.Date;
7 | import java.util.TimeZone;
8 |
9 | import org.osmdroid.contributor.util.constants.OpenStreetMapContributorConstants;
10 | import org.osmdroid.util.BoundingBoxE6;
11 |
12 | /**
13 | *
14 | * @author Nicolas Gramlich
15 | *
16 | */
17 | public class Util implements OpenStreetMapContributorConstants {
18 |
19 | // ===========================================================
20 | // Constants
21 | // ===========================================================
22 |
23 | public static final SimpleDateFormat UTCSimpleDateFormat = new SimpleDateFormat(
24 | "yyyy-MM-dd'T'HH:mm:ss'Z'");
25 | {
26 | UTCSimpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
27 | }
28 |
29 | // ===========================================================
30 | // Fields
31 | // ===========================================================
32 |
33 | // ===========================================================
34 | // Constructors
35 | // ===========================================================
36 |
37 | /**
38 | * This is a utility class with only static members.
39 | */
40 | private Util() {
41 | }
42 |
43 | // ===========================================================
44 | // Getter & Setter
45 | // ===========================================================
46 |
47 | // ===========================================================
48 | // Methods from SuperClass/Interfaces
49 | // ===========================================================
50 |
51 | // ===========================================================
52 | // Methods
53 | // ===========================================================
54 |
55 | public static final String convertTimestampToUTCString(final long aTimestamp) {
56 | return UTCSimpleDateFormat.format(new Date(aTimestamp));
57 | }
58 |
59 | public static boolean isSufficienDataForUpload(
60 | final ArrayList recordedGeoPoints) {
61 | if (recordedGeoPoints == null)
62 | return false;
63 |
64 | if (recordedGeoPoints.size() < MINGEOPOINTS_FOR_OSM_CONTRIBUTION)
65 | return false;
66 |
67 | final BoundingBoxE6 bb = BoundingBoxE6.fromGeoPoints(recordedGeoPoints);
68 | final int diagMeters = bb.getDiagonalLengthInMeters();
69 | if (diagMeters < MINDIAGONALMETERS_FOR_OSM_CONTRIBUTION)
70 | return false;
71 |
72 | return true;
73 | }
74 |
75 | // ===========================================================
76 | // Inner and Anonymous Classes
77 | // ===========================================================
78 | }
79 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/contributor/util/constants/OpenStreetMapContributorConstants.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 14:11:09 - 21.09.2008
2 | package org.osmdroid.contributor.util.constants;
3 |
4 | /**
5 | *
6 | * This class contains constants used by the contributor package.
7 | *
8 | * @author Nicolas Gramlich
9 | *
10 | */
11 | public interface OpenStreetMapContributorConstants {
12 |
13 | // ===========================================================
14 | // Final Fields
15 | // ===========================================================
16 |
17 | public static final int NOT_SET = Integer.MIN_VALUE;
18 |
19 | public static final String OSM_USERNAME = "PUT_YOUR_USERNAME_HERE";
20 | public static final String OSM_PASSWORD = "PUT_YOUR_PASSWORD_HERE";
21 |
22 | public static final int MINGEOPOINTS_FOR_OSM_CONTRIBUTION = 100;
23 | public static final int MINDIAGONALMETERS_FOR_OSM_CONTRIBUTION = 300;
24 |
25 | public static final String OSM_CREATOR_INFO = "AndNav - http://www.andnav.org - Android Navigation System";
26 |
27 | // ===========================================================
28 | // Methods
29 | // ===========================================================
30 | }
31 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/events/DelayedMapListener.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.events;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import android.os.Handler;
7 |
8 | /*
9 | * A MapListener that aggregates multiple events called in quick succession.
10 | * After an event arrives, if another event arrives within delay
milliseconds,
11 | * the original event is discarded. Otherwise, the event is propagated to the wrapped
12 | * MapListener. Note: This class is not thread-safe.
13 | *
14 | * @author Theodore Hong
15 | */
16 | public class DelayedMapListener implements MapListener {
17 |
18 | private static final Logger logger = LoggerFactory.getLogger(DelayedMapListener.class);
19 |
20 | /** Default listening delay */
21 | protected static final int DEFAULT_DELAY = 100;
22 |
23 | /** The wrapped MapListener */
24 | MapListener wrappedListener;
25 |
26 | /** Listening delay, in milliseconds */
27 | protected long delay;
28 |
29 | protected Handler handler;
30 | protected CallbackTask callback;
31 |
32 | /*
33 | * @param wrappedListener The wrapped MapListener
34 | *
35 | * @param delay Listening delay, in milliseconds
36 | */
37 | public DelayedMapListener(final MapListener wrappedListener, final long delay) {
38 | this.wrappedListener = wrappedListener;
39 | this.delay = delay;
40 | this.handler = new Handler();
41 | this.callback = null;
42 | }
43 |
44 | /*
45 | * Constructor with default delay.
46 | *
47 | * @param wrappedListener The wrapped MapListener
48 | */
49 | public DelayedMapListener(final MapListener wrappedListener) {
50 | this(wrappedListener, DEFAULT_DELAY);
51 | }
52 |
53 | @Override
54 | public boolean onScroll(final ScrollEvent event) {
55 | dispatch(event);
56 | return true;
57 | }
58 |
59 | @Override
60 | public boolean onZoom(final ZoomEvent event) {
61 | dispatch(event);
62 | return true;
63 | }
64 |
65 | /*
66 | * Process an incoming MapEvent.
67 | */
68 | protected void dispatch(final MapEvent event) {
69 | // cancel any pending callback
70 | if (callback != null) {
71 | handler.removeCallbacks(callback);
72 | }
73 | callback = new CallbackTask(event);
74 |
75 | // set timer
76 | handler.postDelayed(callback, delay);
77 | }
78 |
79 | // Callback tasks
80 | private class CallbackTask implements Runnable {
81 | private final MapEvent event;
82 |
83 | public CallbackTask(final MapEvent event) {
84 | this.event = event;
85 | }
86 |
87 | @Override
88 | public void run() {
89 | // do the callback
90 | if (event instanceof ScrollEvent) {
91 | wrappedListener.onScroll((ScrollEvent) event);
92 | } else if (event instanceof ZoomEvent) {
93 | wrappedListener.onZoom((ZoomEvent) event);
94 | } else {
95 | // unknown event; discard
96 | logger.debug("Unknown event received: " + event);
97 | }
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/events/MapAdapter.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.events;
2 |
3 | /*
4 | * An abstract adapter class for receiving map events. The methods in this class are empty.
5 | * This class exists as convenience for creating listener objects.
6 | *
7 | * @author Theodore Hong
8 | */
9 | public abstract class MapAdapter implements MapListener {
10 | @Override
11 | public boolean onScroll(final ScrollEvent event) {
12 | // do nothing
13 | return false;
14 | }
15 |
16 | @Override
17 | public boolean onZoom(final ZoomEvent event) {
18 | // do nothing
19 | return false;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/events/MapEvent.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.events;
2 |
3 | /*
4 | * Tagging interface for map events
5 | *
6 | * @author Theodore Hong
7 | */
8 | public interface MapEvent {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/events/MapListener.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.events;
2 |
3 | /*
4 | * The listener interface for receiving map movement events. To process a map event, either implement
5 | * this interface or extend MapAdapter, then register with the MapView using
6 | * setMapListener.
7 | *
8 | * @author Theodore Hong
9 | */
10 | public interface MapListener {
11 | /*
12 | * Called when a map is scrolled.
13 | */
14 | public boolean onScroll(ScrollEvent event);
15 |
16 | /*
17 | * Called when a map is zoomed.
18 | */
19 | public boolean onZoom(ZoomEvent event);
20 | }
21 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/events/ScrollEvent.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.events;
2 |
3 | import org.osmdroid.views.MapView;
4 |
5 | /*
6 | * The event generated when a map has finished scrolling to the coordinates (x
,y
).
7 | *
8 | * @author Theodore Hong
9 | */
10 | public class ScrollEvent implements MapEvent {
11 | protected MapView source;
12 | protected int x;
13 | protected int y;
14 |
15 | public ScrollEvent(final MapView source, final int x, final int y) {
16 | this.source = source;
17 | this.x = x;
18 | this.y = y;
19 | }
20 |
21 | /*
22 | * Return the map which generated this event.
23 | */
24 | public MapView getSource() {
25 | return source;
26 | }
27 |
28 | /*
29 | * Return the x-coordinate scrolled to.
30 | */
31 | public int getX() {
32 | return x;
33 | }
34 |
35 | /*
36 | * Return the y-coordinate scrolled to.
37 | */
38 | public int getY() {
39 | return y;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "ScrollEvent [source=" + source + ", x=" + x + ", y=" + y + "]";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/events/ZoomEvent.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.events;
2 |
3 | import org.osmdroid.views.MapView;
4 |
5 | /*
6 | * The event generated when a map has finished zooming to the level zoomLevel
.
7 | *
8 | * @author Theodore Hong
9 | */
10 | public class ZoomEvent implements MapEvent {
11 | protected MapView source;
12 | protected int zoomLevel;
13 |
14 | public ZoomEvent(final MapView source, final int zoomLevel) {
15 | this.source = source;
16 | this.zoomLevel = zoomLevel;
17 | }
18 |
19 | /*
20 | * Return the map which generated this event.
21 | */
22 | public MapView getSource() {
23 | return source;
24 | }
25 |
26 | /*
27 | * Return the zoom level zoomed to.
28 | */
29 | public int getZoomLevel() {
30 | return zoomLevel;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "ZoomEvent [source=" + source + ", zoomLevel=" + zoomLevel + "]";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/http/HttpClientFactory.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.http;
2 |
3 | import org.apache.http.client.HttpClient;
4 | import org.apache.http.impl.client.DefaultHttpClient;
5 | import org.apache.http.params.CoreProtocolPNames;
6 |
7 | /**
8 | * Factory class for creating an instance of {@link HttpClient}.
9 | * The default implementation returns an instance of {@link DefaultHttpClient}.
10 | * In order to use a different implementation call {@link #setFactoryInstance(IHttpClientFactory)}
11 | * early in your code, for example in onCreate
in your main activity.
12 | * For example to use
13 | * OkHttp/
14 | * use the following code
15 | *
16 | * HttpClientFactory.setFactoryInstance(new IHttpClientFactory() {
17 | * public HttpClient createHttpClient() {
18 | * return new OkApacheClient();
19 | * }
20 | * });
21 | *
22 | */
23 | public class HttpClientFactory {
24 |
25 | private static IHttpClientFactory mFactoryInstance = new IHttpClientFactory() {
26 | @Override
27 | public HttpClient createHttpClient() {
28 | final DefaultHttpClient client = new DefaultHttpClient();
29 | client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "osmdroid");
30 | return client;
31 | }
32 | };
33 |
34 | public static void setFactoryInstance(final IHttpClientFactory aHttpClientFactory) {
35 | mFactoryInstance = aHttpClientFactory;
36 | }
37 |
38 | public static HttpClient createHttpClient() {
39 | return mFactoryInstance.createHttpClient();
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/http/IHttpClientFactory.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.http;
2 |
3 | import org.apache.http.client.HttpClient;
4 |
5 | /**
6 | * Factory class for creating an instance of {@link HttpClient}.
7 | * See {@link HttpClientFactory} for usage.
8 | */
9 | public interface IHttpClientFactory {
10 |
11 | /**
12 | * Create an instance of {@link HttpClient}.
13 | */
14 | HttpClient createHttpClient();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/BitmapPool.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import java.util.LinkedList;
4 |
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.os.Build;
8 |
9 | public class BitmapPool {
10 | final LinkedList mPool = new LinkedList();
11 |
12 | private static BitmapPool sInstance;
13 |
14 | public static BitmapPool getInstance() {
15 | if (sInstance == null)
16 | sInstance = new BitmapPool();
17 |
18 | return sInstance;
19 | }
20 |
21 | public void returnDrawableToPool(ReusableBitmapDrawable drawable) {
22 | Bitmap b = drawable.tryRecycle();
23 | if (b != null && b.isMutable())
24 | synchronized (mPool) {
25 | mPool.addLast(b);
26 | }
27 | }
28 |
29 | public void applyReusableOptions(final BitmapFactory.Options aBitmapOptions) {
30 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
31 | aBitmapOptions.inBitmap = obtainBitmapFromPool();
32 | aBitmapOptions.inSampleSize = 1;
33 | aBitmapOptions.inMutable = true;
34 | }
35 | }
36 |
37 | public Bitmap obtainBitmapFromPool() {
38 | synchronized (mPool) {
39 | if (mPool.isEmpty()) {
40 | return null;
41 | } else {
42 | final Bitmap bitmap = mPool.removeFirst();
43 | if (bitmap.isRecycled()) {
44 | return obtainBitmapFromPool(); // recurse
45 | } else {
46 | return bitmap;
47 | }
48 | }
49 | }
50 | }
51 |
52 | public Bitmap obtainSizedBitmapFromPool(final int aWidth, final int aHeight) {
53 | synchronized (mPool) {
54 | if (mPool.isEmpty()) {
55 | return null;
56 | } else {
57 | for (final Bitmap bitmap : mPool) {
58 | if (bitmap.isRecycled()) {
59 | mPool.remove(bitmap);
60 | return obtainSizedBitmapFromPool(aWidth, aHeight); // recurse to prevent ConcurrentModificationException
61 | } else if (bitmap.getWidth() == aWidth && bitmap.getHeight() == aHeight) {
62 | mPool.remove(bitmap);
63 | return bitmap;
64 | }
65 | }
66 | }
67 | }
68 |
69 | return null;
70 | }
71 |
72 | public void clearBitmapPool() {
73 | synchronized (sInstance.mPool) {
74 | while (!sInstance.mPool.isEmpty()) {
75 | Bitmap bitmap = sInstance.mPool.remove();
76 | bitmap.recycle();
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/ExpirableBitmapDrawable.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.graphics.drawable.Drawable;
6 |
7 | /**
8 | * A {@link BitmapDrawable} for a {@link MapTile} that has a state to indicate that it's expired.
9 | */
10 | public class ExpirableBitmapDrawable extends BitmapDrawable {
11 |
12 | public static final int EXPIRED = -1;
13 |
14 | private int[] mState;
15 |
16 | public ExpirableBitmapDrawable(final Bitmap pBitmap) {
17 | super(pBitmap);
18 | mState = new int[0];
19 | }
20 |
21 | @Override
22 | public int[] getState() {
23 | return mState;
24 | }
25 |
26 | @Override
27 | public boolean isStateful() {
28 | return mState.length > 0;
29 | }
30 |
31 | @Override
32 | public boolean setState(final int[] pStateSet) {
33 | mState = pStateSet;
34 | return true;
35 | }
36 |
37 | public static boolean isDrawableExpired(final Drawable pTile) {
38 | if (!pTile.isStateful()) {
39 | return false;
40 | }
41 | final int[] state = pTile.getState();
42 | for(int i = 0; i < state.length; i++) {
43 | if (state[i] == EXPIRED) {
44 | return true;
45 | }
46 | }
47 | return false;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/IMapTileProviderCallback.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | public interface IMapTileProviderCallback {
6 |
7 | /**
8 | * The map tile request has completed.
9 | *
10 | * @param aState
11 | * a state object
12 | * @param aDrawable
13 | * a drawable
14 | */
15 | void mapTileRequestCompleted(MapTileRequestState aState, final Drawable aDrawable);
16 |
17 | /**
18 | * The map tile request has failed.
19 | *
20 | * @param aState
21 | * a state object
22 | */
23 | void mapTileRequestFailed(MapTileRequestState aState);
24 |
25 | /**
26 | * The map tile request has produced an expired tile.
27 | *
28 | * @param aState
29 | * a state object
30 | */
31 | void mapTileRequestExpiredTile(MapTileRequestState aState, final Drawable aDrawable);
32 |
33 | /**
34 | * Returns true if the network connection should be used, false if not.
35 | *
36 | * @return true if data connection should be used, false otherwise
37 | */
38 | public boolean useDataConnection();
39 | }
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/IRegisterReceiver.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Intent;
5 | import android.content.IntentFilter;
6 |
7 | public interface IRegisterReceiver {
8 |
9 | Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter);
10 |
11 | void unregisterReceiver(BroadcastReceiver receiver);
12 | }
13 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/LRUMapTileCache.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import java.util.LinkedHashMap;
4 |
5 | import org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import android.graphics.Bitmap;
10 | import android.graphics.drawable.BitmapDrawable;
11 | import android.graphics.drawable.Drawable;
12 | import android.os.Build;
13 |
14 | public class LRUMapTileCache extends LinkedHashMap
15 | implements OpenStreetMapTileProviderConstants {
16 |
17 | public interface TileRemovedListener {
18 | void onTileRemoved(MapTile mapTile);
19 | }
20 |
21 | private static final Logger logger = LoggerFactory.getLogger(LRUMapTileCache.class);
22 |
23 | private static final long serialVersionUID = -541142277575493335L;
24 |
25 | private int mCapacity;
26 | private TileRemovedListener mTileRemovedListener;
27 |
28 | public LRUMapTileCache(final int aCapacity) {
29 | super(aCapacity + 2, 0.1f, true);
30 | mCapacity = aCapacity;
31 | }
32 |
33 | public void ensureCapacity(final int aCapacity) {
34 | if (aCapacity > mCapacity) {
35 | logger.info("Tile cache increased from " + mCapacity + " to " + aCapacity);
36 | mCapacity = aCapacity;
37 | }
38 | }
39 |
40 | @Override
41 | public Drawable remove(final Object aKey) {
42 | final Drawable drawable = super.remove(aKey);
43 | // Only recycle if we are running on a project less than 2.3.3 Gingerbread.
44 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
45 | if (drawable instanceof BitmapDrawable) {
46 | final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
47 | if (bitmap != null) {
48 | bitmap.recycle();
49 | }
50 | }
51 | }
52 | if (getTileRemovedListener() != null && aKey instanceof MapTile)
53 | getTileRemovedListener().onTileRemoved((MapTile) aKey);
54 | if (drawable instanceof ReusableBitmapDrawable)
55 | BitmapPool.getInstance().returnDrawableToPool((ReusableBitmapDrawable) drawable);
56 | return drawable;
57 | }
58 |
59 | @Override
60 | public void clear() {
61 | // remove them all individually so that they get recycled
62 | while (!isEmpty()) {
63 | remove(keySet().iterator().next());
64 | }
65 |
66 | // and then clear
67 | super.clear();
68 | }
69 |
70 | @Override
71 | protected boolean removeEldestEntry(final java.util.Map.Entry aEldest) {
72 | if (size() > mCapacity) {
73 | final MapTile eldest = aEldest.getKey();
74 | if (DEBUGMODE) {
75 | logger.debug("Remove old tile: " + eldest);
76 | }
77 | remove(eldest);
78 | // don't return true because we've already removed it
79 | }
80 | return false;
81 | }
82 |
83 | public TileRemovedListener getTileRemovedListener() {
84 | return mTileRemovedListener;
85 | }
86 |
87 | public void setTileRemovedListener(TileRemovedListener tileRemovedListener) {
88 | mTileRemovedListener = tileRemovedListener;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTile.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import org.osmdroid.tileprovider.modules.MapTileModuleProviderBase;
4 | import org.osmdroid.views.overlay.TilesOverlay;
5 |
6 | /**
7 | * A map tile is distributed using the observer pattern. The tile is delivered by a tile provider
8 | * (i.e. a descendant of {@link MapTileModuleProviderBase} or
9 | * {@link MapTileProviderBase} to a consumer of tiles (e.g. descendant of
10 | * {@link TilesOverlay}). Tiles are typically images (e.g. png or jpeg).
11 | */
12 | public class MapTile {
13 |
14 | public static final int MAPTILE_SUCCESS_ID = 0;
15 | public static final int MAPTILE_FAIL_ID = MAPTILE_SUCCESS_ID + 1;
16 |
17 | // This class must be immutable because it's used as the key in the cache hash map
18 | // (ie all the fields are final).
19 | private final int x;
20 | private final int y;
21 | private final int zoomLevel;
22 |
23 | public MapTile(final int zoomLevel, final int tileX, final int tileY) {
24 | this.zoomLevel = zoomLevel;
25 | this.x = tileX;
26 | this.y = tileY;
27 | }
28 |
29 | public int getZoomLevel() {
30 | return zoomLevel;
31 | }
32 |
33 | public int getX() {
34 | return x;
35 | }
36 |
37 | public int getY() {
38 | return y;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return "/" + zoomLevel + "/" + x + "/" + y;
44 | }
45 |
46 | @Override
47 | public boolean equals(final Object obj) {
48 | if (obj == null)
49 | return false;
50 | if (obj == this)
51 | return true;
52 | if (!(obj instanceof MapTile))
53 | return false;
54 | final MapTile rhs = (MapTile) obj;
55 | return zoomLevel == rhs.zoomLevel && x == rhs.x && y == rhs.y;
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | int code = 17;
61 | code *= 37 + zoomLevel;
62 | code *= 37 + x;
63 | code *= 37 + y;
64 | return code;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileCache.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 17:58:57 - 25.09.2008
2 | package org.osmdroid.tileprovider;
3 |
4 | import org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants;
5 |
6 | import android.graphics.drawable.Drawable;
7 |
8 | /**
9 | *
10 | * @author Nicolas Gramlich
11 | *
12 | */
13 | public class MapTileCache implements OpenStreetMapTileProviderConstants {
14 | // ===========================================================
15 | // Constants
16 | // ===========================================================
17 |
18 | // ===========================================================
19 | // Fields
20 | // ===========================================================
21 |
22 | protected final Object mCachedTilesLockObject = new Object();
23 | protected LRUMapTileCache mCachedTiles;
24 |
25 | // ===========================================================
26 | // Constructors
27 | // ===========================================================
28 |
29 | public MapTileCache() {
30 | this(CACHE_MAPTILECOUNT_DEFAULT);
31 | }
32 |
33 | /**
34 | * @param aMaximumCacheSize
35 | * Maximum amount of MapTiles to be hold within.
36 | */
37 | public MapTileCache(final int aMaximumCacheSize) {
38 | this.mCachedTiles = new LRUMapTileCache(aMaximumCacheSize);
39 | }
40 |
41 | // ===========================================================
42 | // Getter & Setter
43 | // ===========================================================
44 |
45 | public void ensureCapacity(final int aCapacity) {
46 | synchronized (mCachedTilesLockObject) {
47 | mCachedTiles.ensureCapacity(aCapacity);
48 | }
49 | }
50 |
51 | public Drawable getMapTile(final MapTile aTile) {
52 | synchronized (mCachedTilesLockObject) {
53 | return this.mCachedTiles.get(aTile);
54 | }
55 | }
56 |
57 | public void putTile(final MapTile aTile, final Drawable aDrawable) {
58 | if (aDrawable != null) {
59 | synchronized (mCachedTilesLockObject) {
60 | this.mCachedTiles.put(aTile, aDrawable);
61 | }
62 | }
63 | }
64 |
65 | // ===========================================================
66 | // Methods from SuperClass/Interfaces
67 | // ===========================================================
68 |
69 | // ===========================================================
70 | // Methods
71 | // ===========================================================
72 |
73 | public boolean containsTile(final MapTile aTile) {
74 | synchronized (mCachedTilesLockObject) {
75 | return this.mCachedTiles.containsKey(aTile);
76 | }
77 | }
78 |
79 | public void clear() {
80 | synchronized (mCachedTilesLockObject) {
81 | this.mCachedTiles.clear();
82 | }
83 | }
84 |
85 | // ===========================================================
86 | // Inner and Anonymous Classes
87 | // ===========================================================
88 | }
89 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileProviderBasic.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import org.osmdroid.tileprovider.modules.INetworkAvailablityCheck;
4 | import org.osmdroid.tileprovider.modules.MapTileDownloader;
5 | import org.osmdroid.tileprovider.modules.MapTileFileArchiveProvider;
6 | import org.osmdroid.tileprovider.modules.MapTileFilesystemProvider;
7 | import org.osmdroid.tileprovider.modules.NetworkAvailabliltyCheck;
8 | import org.osmdroid.tileprovider.modules.TileWriter;
9 | import org.osmdroid.tileprovider.tilesource.ITileSource;
10 | import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
11 | import org.osmdroid.tileprovider.util.SimpleRegisterReceiver;
12 |
13 | import android.content.Context;
14 |
15 | /**
16 | * This top-level tile provider implements a basic tile request chain which includes a
17 | * {@link MapTileFilesystemProvider} (a file-system cache), a {@link MapTileFileArchiveProvider}
18 | * (archive provider), and a {@link MapTileDownloader} (downloads map tiles via tile source).
19 | *
20 | * @author Marc Kurtz
21 | *
22 | */
23 | public class MapTileProviderBasic extends MapTileProviderArray implements IMapTileProviderCallback {
24 |
25 | // private static final Logger logger = LoggerFactory.getLogger(MapTileProviderBasic.class);
26 |
27 | /**
28 | * Creates a {@link MapTileProviderBasic}.
29 | */
30 | public MapTileProviderBasic(final Context pContext) {
31 | this(pContext, TileSourceFactory.DEFAULT_TILE_SOURCE);
32 | }
33 |
34 | /**
35 | * Creates a {@link MapTileProviderBasic}.
36 | */
37 | public MapTileProviderBasic(final Context pContext, final ITileSource pTileSource) {
38 | this(new SimpleRegisterReceiver(pContext), new NetworkAvailabliltyCheck(pContext),
39 | pTileSource);
40 | }
41 |
42 | /**
43 | * Creates a {@link MapTileProviderBasic}.
44 | */
45 | public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
46 | final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource) {
47 | super(pTileSource, pRegisterReceiver);
48 |
49 | final TileWriter tileWriter = new TileWriter();
50 |
51 | final MapTileFilesystemProvider fileSystemProvider = new MapTileFilesystemProvider(
52 | pRegisterReceiver, pTileSource);
53 | mTileProviderList.add(fileSystemProvider);
54 |
55 | final MapTileFileArchiveProvider archiveProvider = new MapTileFileArchiveProvider(
56 | pRegisterReceiver, pTileSource);
57 | mTileProviderList.add(archiveProvider);
58 |
59 | final MapTileDownloader downloaderProvider = new MapTileDownloader(pTileSource, tileWriter,
60 | aNetworkAvailablityCheck);
61 | mTileProviderList.add(downloaderProvider);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileRequestState.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import java.util.Collections;
4 | import java.util.LinkedList;
5 | import java.util.Queue;
6 |
7 | import org.osmdroid.tileprovider.modules.MapTileModuleProviderBase;
8 |
9 | public class MapTileRequestState {
10 |
11 | private final Queue mProviderQueue;
12 | private final MapTile mMapTile;
13 | private final IMapTileProviderCallback mCallback;
14 | private MapTileModuleProviderBase mCurrentProvider;
15 |
16 | public MapTileRequestState(final MapTile mapTile,
17 | final MapTileModuleProviderBase[] providers,
18 | final IMapTileProviderCallback callback) {
19 | mProviderQueue = new LinkedList();
20 | Collections.addAll(mProviderQueue, providers);
21 | mMapTile = mapTile;
22 | mCallback = callback;
23 | }
24 |
25 | public MapTile getMapTile() {
26 | return mMapTile;
27 | }
28 |
29 | public IMapTileProviderCallback getCallback() {
30 | return mCallback;
31 | }
32 |
33 | public boolean isEmpty() {
34 | return mProviderQueue.isEmpty();
35 | }
36 |
37 | public MapTileModuleProviderBase getNextProvider() {
38 | mCurrentProvider = mProviderQueue.poll();
39 | return mCurrentProvider;
40 | }
41 |
42 | public MapTileModuleProviderBase getCurrentProvider() {
43 | return mCurrentProvider;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/ReusableBitmapDrawable.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * A {@link ExpirableBitmapDrawable} class that allows keeping track of usage references. This
7 | * facilitates the ability to reuse the underlying Bitmaps if no references are active. To safely
8 | * use the Drawable first call {@link #beginUsingDrawable()} and then check {@link #isBitmapValid()}
9 | * to ensure that the Drawable is still valid. When done using the Drawable you must call
10 | * {@link #finishUsingDrawable()} to release the reference and allow the Bitmap to be reused later.
11 | *
12 | * @author Marc Kurtz
13 | *
14 | */
15 | public class ReusableBitmapDrawable extends ExpirableBitmapDrawable {
16 |
17 | private boolean mBitmapRecycled = false;
18 | private int mUsageRefCount = 0;
19 |
20 | public ReusableBitmapDrawable(Bitmap pBitmap) {
21 | super(pBitmap);
22 | }
23 |
24 | public void beginUsingDrawable() {
25 | synchronized (this) {
26 | mUsageRefCount++;
27 | }
28 | }
29 |
30 | public void finishUsingDrawable() {
31 | synchronized (this) {
32 | mUsageRefCount--;
33 | if (mUsageRefCount < 0)
34 | throw new IllegalStateException("Unbalanced endUsingDrawable() called.");
35 | }
36 | }
37 |
38 | public Bitmap tryRecycle() {
39 | synchronized (this) {
40 | if (mUsageRefCount == 0) {
41 | mBitmapRecycled = true;
42 | return getBitmap();
43 | }
44 | }
45 | return null;
46 | }
47 |
48 | public boolean isBitmapValid() {
49 | synchronized (this) {
50 | return !mBitmapRecycled;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/constants/OpenStreetMapTileProviderConstants.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.constants;
2 |
3 | import java.io.File;
4 |
5 | import android.os.Environment;
6 |
7 | /**
8 | *
9 | * This class contains constants used by the tile provider.
10 | *
11 | * @author Neil Boyd
12 | *
13 | */
14 | public interface OpenStreetMapTileProviderConstants {
15 |
16 | public static final boolean DEBUGMODE = false;
17 | public static final boolean DEBUG_TILE_PROVIDERS = false;
18 |
19 | /** Minimum Zoom Level */
20 | public static final int MINIMUM_ZOOMLEVEL = 0;
21 |
22 | /**
23 | * Maximum Zoom Level - we use Integers to store zoom levels so overflow happens at 2^32 - 1,
24 | * but we also have a tile size that is typically 2^8, so (32-1)-8-1 = 22
25 | */
26 | public static final int MAXIMUM_ZOOMLEVEL = 22;
27 |
28 | /** Base path for osmdroid files. Zip files are in this folder. */
29 | public static final File OSMDROID_PATH = new File(Environment.getExternalStorageDirectory(),
30 | "osmdroid");
31 |
32 | /** Base path for tiles. */
33 | public static final File TILE_PATH_BASE = new File(OSMDROID_PATH, "tiles");
34 |
35 | /** add an extension to files on sdcard so that gallery doesn't index them */
36 | public static final String TILE_PATH_EXTENSION = ".tile";
37 |
38 | /**
39 | * Initial tile cache size. The size will be increased as required by calling {@link
40 | * LRUMapTileCache.ensureCapacity(int)} The tile cache will always be at least 3x3.
41 | */
42 | public static final int CACHE_MAPTILECOUNT_DEFAULT = 9;
43 |
44 | /**
45 | * number of tile download threads, conforming to OSM policy:
46 | * http://wiki.openstreetmap.org/wiki/Tile_usage_policy
47 | */
48 | public static final int NUMBER_OF_TILE_DOWNLOAD_THREADS = 2;
49 |
50 | public static final int NUMBER_OF_TILE_FILESYSTEM_THREADS = 8;
51 |
52 | public static final long ONE_SECOND = 1000;
53 | public static final long ONE_MINUTE = ONE_SECOND * 60;
54 | public static final long ONE_HOUR = ONE_MINUTE * 60;
55 | public static final long ONE_DAY = ONE_HOUR * 24;
56 | public static final long ONE_WEEK = ONE_DAY * 7;
57 | public static final long ONE_YEAR = ONE_DAY * 365;
58 | public static final long DEFAULT_MAXIMUM_CACHED_FILE_AGE = ONE_WEEK;
59 |
60 | public static final int TILE_DOWNLOAD_MAXIMUM_QUEUE_SIZE = 40;
61 | public static final int TILE_FILESYSTEM_MAXIMUM_QUEUE_SIZE = 40;
62 |
63 | /** 30 days */
64 | public static final long TILE_EXPIRY_TIME_MILLISECONDS = 1000L * 60 * 60 * 24 * 30;
65 |
66 | /** 600 Mb */
67 | public static final long TILE_MAX_CACHE_SIZE_BYTES = 600L * 1024 * 1024;
68 |
69 | /** 500 Mb */
70 | public static final long TILE_TRIM_CACHE_SIZE_BYTES = 500L * 1024 * 1024;
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/ArchiveFileFactory.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import android.database.sqlite.SQLiteException;
10 |
11 | public class ArchiveFileFactory {
12 |
13 | private static final Logger logger = LoggerFactory.getLogger(ArchiveFileFactory.class);
14 |
15 | /**
16 | * Return an implementation of {@link IArchiveFile} for the specified file.
17 | * @return an implementation, or null if there's no suitable implementation
18 | */
19 | public static IArchiveFile getArchiveFile(final File pFile) {
20 |
21 | if (pFile.getName().endsWith(".zip")) {
22 | try {
23 | return ZipFileArchive.getZipFileArchive(pFile);
24 | } catch (final IOException e) {
25 | logger.error("Error opening ZIP file", e);
26 | }
27 | }
28 |
29 | if (pFile.getName().endsWith(".sqlite")) {
30 | try {
31 | return DatabaseFileArchive.getDatabaseFileArchive(pFile);
32 | } catch (final SQLiteException e) {
33 | logger.error("Error opening SQL file", e);
34 | }
35 | }
36 |
37 | if (pFile.getName().endsWith(".mbtiles")) {
38 | try {
39 | return MBTilesFileArchive.getDatabaseFileArchive(pFile);
40 | } catch (final SQLiteException e) {
41 | logger.error("Error opening MBTiles SQLite file", e);
42 | }
43 | }
44 |
45 | if (pFile.getName().endsWith(".gemf")) {
46 | try {
47 | return GEMFFileArchive.getGEMFFileArchive(pFile);
48 | } catch (final IOException e) {
49 | logger.error("Error opening GEMF file", e);
50 | }
51 | }
52 |
53 | return null;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/ConfigurablePriorityThreadFactory.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.util.concurrent.ThreadFactory;
4 |
5 | /**
6 | *
7 | * @author Jastrzab
8 | */
9 |
10 | public class ConfigurablePriorityThreadFactory implements ThreadFactory {
11 |
12 | private final int mPriority;
13 | private final String mName;
14 |
15 | public ConfigurablePriorityThreadFactory(final int pPriority, final String pName) {
16 | mPriority = pPriority;
17 | mName = pName;
18 | }
19 |
20 | @Override
21 | public Thread newThread(final Runnable pRunnable) {
22 | final Thread thread = new Thread(pRunnable);
23 | thread.setPriority(mPriority);
24 | if (mName != null) {
25 | thread.setName(mName);
26 | }
27 | return thread;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/DatabaseFileArchive.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.File;
5 | import java.io.InputStream;
6 |
7 | import org.osmdroid.tileprovider.MapTile;
8 | import org.osmdroid.tileprovider.tilesource.ITileSource;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import android.database.Cursor;
13 | import android.database.sqlite.SQLiteDatabase;
14 | import android.database.sqlite.SQLiteException;
15 |
16 | public class DatabaseFileArchive implements IArchiveFile {
17 |
18 | private static final Logger logger = LoggerFactory.getLogger(DatabaseFileArchive.class);
19 |
20 | private final SQLiteDatabase mDatabase;
21 |
22 | private DatabaseFileArchive(final SQLiteDatabase pDatabase) {
23 | mDatabase = pDatabase;
24 | }
25 |
26 | public static DatabaseFileArchive getDatabaseFileArchive(final File pFile) throws SQLiteException {
27 | return new DatabaseFileArchive(SQLiteDatabase.openOrCreateDatabase(pFile, null));
28 | }
29 |
30 | @Override
31 | public InputStream getInputStream(final ITileSource pTileSource, final MapTile pTile) {
32 | try {
33 | InputStream ret = null;
34 | final String[] tile = {"tile"};
35 | final long x = (long) pTile.getX();
36 | final long y = (long) pTile.getY();
37 | final long z = (long) pTile.getZoomLevel();
38 | final long index = ((z << z) + x << z) + y;
39 | final Cursor cur = mDatabase.query("tiles", tile, "key = " + index + " and provider = '" + pTileSource.name() + "'", null, null, null, null);
40 | if(cur.getCount() != 0) {
41 | cur.moveToFirst();
42 | ret = new ByteArrayInputStream(cur.getBlob(0));
43 | }
44 | cur.close();
45 | if(ret != null) {
46 | return ret;
47 | }
48 | } catch(final Throwable e) {
49 | logger.warn("Error getting db stream: " + pTile, e);
50 | }
51 |
52 | return null;
53 | }
54 |
55 | @Override
56 | public void close() {
57 | mDatabase.close();
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return "DatabaseFileArchive [mDatabase=" + mDatabase.getPath() + "]";
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/GEMFFileArchive.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | import org.osmdroid.tileprovider.MapTile;
9 | import org.osmdroid.tileprovider.tilesource.ITileSource;
10 | import org.osmdroid.util.GEMFFile;
11 |
12 | public class GEMFFileArchive implements IArchiveFile {
13 |
14 | private final GEMFFile mFile;
15 |
16 | private GEMFFileArchive(final File pFile) throws FileNotFoundException, IOException {
17 | mFile = new GEMFFile(pFile);
18 | }
19 |
20 | public static GEMFFileArchive getGEMFFileArchive(final File pFile) throws FileNotFoundException, IOException {
21 | return new GEMFFileArchive(pFile);
22 | }
23 |
24 | @Override
25 | public InputStream getInputStream(final ITileSource pTileSource, final MapTile pTile) {
26 | return mFile.getInputStream(pTile.getX(), pTile.getY(), pTile.getZoomLevel());
27 | }
28 |
29 | @Override
30 | public void close() {
31 | try {
32 | mFile.close();
33 | } catch (IOException e) { }
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "GEMFFileArchive [mGEMFFile=" + mFile.getName() + "]";
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/IArchiveFile.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.InputStream;
4 |
5 | import org.osmdroid.tileprovider.MapTile;
6 | import org.osmdroid.tileprovider.tilesource.ITileSource;
7 |
8 | public interface IArchiveFile {
9 |
10 | /**
11 | * Get the input stream for the requested tile.
12 | * @return the input stream, or null if the archive doesn't contain an entry for the requested tile
13 | */
14 | InputStream getInputStream(ITileSource tileSource, MapTile tile);
15 |
16 | /**
17 | * Closes the archive file and releases resources.
18 | */
19 | void close();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/IFilesystemCache.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.InputStream;
4 |
5 | import org.osmdroid.tileprovider.MapTile;
6 | import org.osmdroid.tileprovider.tilesource.ITileSource;
7 |
8 | /**
9 | * Represents a write-only interface into a file system cache.
10 | *
11 | * @author Marc Kurtz
12 | *
13 | */
14 | public interface IFilesystemCache {
15 | /**
16 | * Save an InputStream as the specified tile in the file system cache for the specified tile
17 | * source.
18 | *
19 | * @param pTileSourceInfo
20 | * a tile source
21 | * @param pTile
22 | * a tile
23 | * @param pStream
24 | * an InputStream
25 | * @return
26 | */
27 | boolean saveFile(final ITileSource pTileSourceInfo, MapTile pTile,
28 | final InputStream pStream);
29 | }
30 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/INetworkAvailablityCheck.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | public interface INetworkAvailablityCheck {
4 |
5 | boolean getNetworkAvailable();
6 |
7 | boolean getWiFiNetworkAvailable();
8 |
9 | boolean getCellularDataNetworkAvailable();
10 |
11 | boolean getRouteToPathExists(int hostAddress);
12 | }
13 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/MBTilesFileArchive.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.File;
5 | import java.io.InputStream;
6 |
7 | import org.osmdroid.tileprovider.MapTile;
8 | import org.osmdroid.tileprovider.tilesource.ITileSource;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import android.database.Cursor;
13 | import android.database.sqlite.SQLiteDatabase;
14 | import android.database.sqlite.SQLiteException;
15 |
16 | public class MBTilesFileArchive implements IArchiveFile {
17 |
18 | private static final Logger logger = LoggerFactory.getLogger(MBTilesFileArchive.class);
19 |
20 | private final SQLiteDatabase mDatabase;
21 |
22 | // TABLE tiles (zoom_level INTEGER, tile_column INTEGER, tile_row INTEGER, tile_data BLOB);
23 | public final static String TABLE_TILES = "tiles";
24 | public final static String COL_TILES_ZOOM_LEVEL = "zoom_level";
25 | public final static String COL_TILES_TILE_COLUMN = "tile_column";
26 | public final static String COL_TILES_TILE_ROW = "tile_row";
27 | public final static String COL_TILES_TILE_DATA = "tile_data";
28 |
29 | private MBTilesFileArchive(final SQLiteDatabase pDatabase) {
30 | mDatabase = pDatabase;
31 | }
32 |
33 | public static MBTilesFileArchive getDatabaseFileArchive(final File pFile) throws SQLiteException {
34 | return new MBTilesFileArchive(
35 | SQLiteDatabase.openDatabase(
36 | pFile.getAbsolutePath(),
37 | null,
38 | SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY));
39 | }
40 |
41 | @Override
42 | public InputStream getInputStream(final ITileSource pTileSource, final MapTile pTile) {
43 | try {
44 | InputStream ret = null;
45 | final String[] tile = { COL_TILES_TILE_DATA };
46 | final String[] xyz = {
47 | Integer.toString(pTile.getX())
48 | , Double.toString(Math.pow(2, pTile.getZoomLevel()) - pTile.getY() - 1) // Use Google Tiling Spec
49 | , Integer.toString(pTile.getZoomLevel())
50 | };
51 |
52 | final Cursor cur = mDatabase.query(TABLE_TILES, tile, "tile_column=? and tile_row=? and zoom_level=?", xyz, null, null, null);
53 |
54 | if(cur.getCount() != 0) {
55 | cur.moveToFirst();
56 | ret = new ByteArrayInputStream(cur.getBlob(0));
57 | }
58 | cur.close();
59 | if(ret != null) {
60 | return ret;
61 | }
62 | } catch(final Throwable e) {
63 | logger.warn("Error getting db stream: " + pTile, e);
64 | }
65 |
66 | return null;
67 | }
68 |
69 | @Override
70 | public void close() {
71 | mDatabase.close();
72 | }
73 |
74 | @Override
75 | public String toString() {
76 | return "DatabaseFileArchive [mDatabase=" + mDatabase.getPath() + "]";
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/MapTileFileStorageProviderBase.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import org.osmdroid.tileprovider.IRegisterReceiver;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | import android.content.BroadcastReceiver;
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.content.IntentFilter;
11 | import android.os.Environment;
12 |
13 | public abstract class MapTileFileStorageProviderBase extends MapTileModuleProviderBase {
14 |
15 | private static final Logger logger = LoggerFactory.getLogger(MapTileFileStorageProviderBase.class);
16 |
17 | /** whether the sdcard is mounted read/write */
18 | private boolean mSdCardAvailable = true;
19 |
20 | private final IRegisterReceiver mRegisterReceiver;
21 | private MyBroadcastReceiver mBroadcastReceiver;
22 |
23 | public MapTileFileStorageProviderBase(final IRegisterReceiver pRegisterReceiver,
24 | final int pThreadPoolSize, final int pPendingQueueSize) {
25 | super(pThreadPoolSize, pPendingQueueSize);
26 |
27 | checkSdCard();
28 |
29 | mRegisterReceiver = pRegisterReceiver;
30 | mBroadcastReceiver = new MyBroadcastReceiver();
31 |
32 | final IntentFilter mediaFilter = new IntentFilter();
33 | mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
34 | mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
35 | mediaFilter.addDataScheme("file");
36 | pRegisterReceiver.registerReceiver(mBroadcastReceiver, mediaFilter);
37 | }
38 |
39 | private void checkSdCard() {
40 | final String state = Environment.getExternalStorageState();
41 | logger.info("sdcard state: " + state);
42 | mSdCardAvailable = Environment.MEDIA_MOUNTED.equals(state);
43 | }
44 |
45 | protected boolean getSdCardAvailable() {
46 | return mSdCardAvailable;
47 | }
48 |
49 | @Override
50 | public void detach() {
51 | if (mBroadcastReceiver != null) {
52 | mRegisterReceiver.unregisterReceiver(mBroadcastReceiver);
53 | mBroadcastReceiver = null;
54 | }
55 | super.detach();
56 | }
57 |
58 | protected void onMediaMounted() {
59 | // Do nothing by default. Override to handle.
60 | }
61 |
62 | protected void onMediaUnmounted() {
63 | // Do nothing by default. Override to handle.
64 | }
65 |
66 | /**
67 | * This broadcast receiver will recheck the sd card when the mount/unmount messages happen
68 | *
69 | */
70 | private class MyBroadcastReceiver extends BroadcastReceiver {
71 |
72 | @Override
73 | public void onReceive(final Context aContext, final Intent aIntent) {
74 |
75 | final String action = aIntent.getAction();
76 |
77 | checkSdCard();
78 |
79 | if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) {
80 | onMediaMounted();
81 | } else if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) {
82 | onMediaUnmounted();
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/NetworkAvailabliltyCheck.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | /**
8 | * A straightforward network check implementation. NOTE: Requires
9 | * android.permission.ACCESS_NETWORK_STATE and android.permission.ACCESS_WIFI_STATE (?) and
10 | * android.permission.INTERNET (?)
11 | *
12 | * @author Marc Kurtz
13 | *
14 | */
15 |
16 | public class NetworkAvailabliltyCheck implements INetworkAvailablityCheck {
17 |
18 | private final ConnectivityManager mConnectionManager;
19 |
20 | public NetworkAvailabliltyCheck(final Context aContext) {
21 | mConnectionManager = (ConnectivityManager) aContext
22 | .getSystemService(Context.CONNECTIVITY_SERVICE);
23 | }
24 |
25 | @Override
26 | public boolean getNetworkAvailable() {
27 | final NetworkInfo networkInfo = mConnectionManager.getActiveNetworkInfo();
28 | return networkInfo != null && networkInfo.isAvailable();
29 | }
30 |
31 | @Override
32 | public boolean getWiFiNetworkAvailable() {
33 | final NetworkInfo wifi = mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
34 | return wifi != null && wifi.isAvailable();
35 | }
36 |
37 | @Override
38 | public boolean getCellularDataNetworkAvailable() {
39 | final NetworkInfo mobile = mConnectionManager
40 | .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
41 | return mobile != null && mobile.isAvailable();
42 | }
43 |
44 | @Override
45 | public boolean getRouteToPathExists(final int hostAddress) {
46 | return (mConnectionManager.requestRouteToHost(ConnectivityManager.TYPE_WIFI, hostAddress) || mConnectionManager
47 | .requestRouteToHost(ConnectivityManager.TYPE_MOBILE, hostAddress));
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/ZipFileArchive.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.modules;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.zip.ZipEntry;
7 | import java.util.zip.ZipException;
8 | import java.util.zip.ZipFile;
9 |
10 | import org.osmdroid.tileprovider.MapTile;
11 | import org.osmdroid.tileprovider.tilesource.ITileSource;
12 | import org.slf4j.Logger;
13 | import org.slf4j.LoggerFactory;
14 |
15 | public class ZipFileArchive implements IArchiveFile {
16 |
17 | private static final Logger logger = LoggerFactory.getLogger(ZipFileArchive.class);
18 |
19 | private final ZipFile mZipFile;
20 |
21 | private ZipFileArchive(final ZipFile pZipFile) {
22 | mZipFile = pZipFile;
23 | }
24 |
25 | public static ZipFileArchive getZipFileArchive(final File pFile) throws ZipException, IOException {
26 | return new ZipFileArchive(new ZipFile(pFile));
27 | }
28 |
29 | @Override
30 | public InputStream getInputStream(final ITileSource pTileSource, final MapTile pTile) {
31 | final String path = pTileSource.getTileRelativeFilenameString(pTile);
32 | try {
33 | final ZipEntry entry = mZipFile.getEntry(path);
34 | if (entry != null) {
35 | return mZipFile.getInputStream(entry);
36 | }
37 | } catch (final IOException e) {
38 | logger.warn("Error getting zip stream: " + pTile, e);
39 | }
40 | return null;
41 | }
42 |
43 | @Override
44 | public void close() {
45 | try {
46 | mZipFile.close();
47 | } catch (IOException e) { }
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return "ZipFileArchive [mZipFile=" + mZipFile.getName() + "]";
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/tilesource/CloudmadeTileSource.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource;
2 |
3 | import org.osmdroid.ResourceProxy;
4 | import org.osmdroid.tileprovider.MapTile;
5 | import org.osmdroid.tileprovider.util.CloudmadeUtil;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | public class CloudmadeTileSource extends OnlineTileSourceBase implements IStyledTileSource {
10 |
11 | private static final Logger logger = LoggerFactory.getLogger(CloudmadeTileSource.class);
12 |
13 | private Integer mStyle = 1;
14 |
15 | public CloudmadeTileSource(final String pName, final ResourceProxy.string pResourceId,
16 | final int pZoomMinLevel, final int pZoomMaxLevel, final int pTileSizePixels,
17 | final String pImageFilenameEnding, final String[] pBaseUrl) {
18 | super(pName, pResourceId, pZoomMinLevel, pZoomMaxLevel, pTileSizePixels,
19 | pImageFilenameEnding, pBaseUrl);
20 | }
21 |
22 | @Override
23 | public String pathBase() {
24 | if (mStyle == null || mStyle <= 1) {
25 | return mName;
26 | } else {
27 | return mName + mStyle;
28 | }
29 | }
30 |
31 | @Override
32 | public String getTileURLString(final MapTile pTile) {
33 | final String key = CloudmadeUtil.getCloudmadeKey();
34 | if (key.length() == 0) {
35 | logger.error("CloudMade key is not set. You should enter it in the manifest and call CloudmadeUtil.retrieveCloudmadeKey()");
36 | }
37 | final String token = CloudmadeUtil.getCloudmadeToken();
38 | return String.format(getBaseUrl(), key, mStyle, getTileSizePixels(), pTile.getZoomLevel(),
39 | pTile.getX(), pTile.getY(), mImageFilenameEnding, token);
40 | }
41 |
42 | @Override
43 | public void setStyle(final Integer pStyle) {
44 | mStyle = pStyle;
45 | }
46 |
47 | @Override
48 | public void setStyle(final String pStyle) {
49 | try {
50 | mStyle = Integer.parseInt(pStyle);
51 | } catch (final NumberFormatException e) {
52 | logger.warn("Error setting integer style: " + pStyle);
53 | }
54 | }
55 |
56 | @Override
57 | public Integer getStyle() {
58 | return mStyle;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/tilesource/IStyledTileSource.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource;
2 |
3 | /**
4 | * Tile sources that have a settable "style" attibute can implement this. After setting this on a
5 | * tile provider, you may need to call clearTileCache() or call setTileSource() again on the tile
6 | * provider to clear the current tiles on the screen that are still in the old style.
7 | */
8 | public interface IStyledTileSource {
9 |
10 | public void setStyle(T style);
11 |
12 | public void setStyle(String style);
13 |
14 | public T getStyle();
15 | }
16 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/tilesource/ITileSource.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource;
2 |
3 | import java.io.InputStream;
4 |
5 | import org.osmdroid.ResourceProxy;
6 | import org.osmdroid.tileprovider.MapTile;
7 | import org.osmdroid.tileprovider.tilesource.BitmapTileSourceBase.LowMemoryException;
8 |
9 | import android.graphics.drawable.Drawable;
10 |
11 | public interface ITileSource {
12 |
13 | /**
14 | * An ordinal identifier for this tile source
15 | *
16 | * @return the ordinal value
17 | */
18 | int ordinal();
19 |
20 | /**
21 | * A human-friendly name for this tile source
22 | *
23 | * @return the tile source name
24 | */
25 | String name();
26 |
27 | /**
28 | * A localized human-friendly name for this tile source
29 | *
30 | * @param proxy
31 | * a resource proxy
32 | * @return the localized tile source name
33 | */
34 | String localizedName(ResourceProxy proxy);
35 |
36 | /**
37 | * Get a unique file path for the tile. This file path may be used to store the tile on a file
38 | * system and performance considerations should be taken into consideration. It can include
39 | * multiple paths. It should not begin with a leading path separator.
40 | *
41 | * @param aTile
42 | * the tile
43 | * @return the unique file path
44 | */
45 | String getTileRelativeFilenameString(MapTile aTile);
46 |
47 | /**
48 | * Get a rendered Drawable from the specified file path.
49 | *
50 | * @param aFilePath
51 | * a file path
52 | * @return the rendered Drawable
53 | */
54 | Drawable getDrawable(String aFilePath) throws LowMemoryException;
55 |
56 | /**
57 | * Get a rendered Drawable from the specified InputStream.
58 | *
59 | * @param aTileInputStream
60 | * an InputStream
61 | * @return the rendered Drawable
62 | */
63 | Drawable getDrawable(InputStream aTileInputStream) throws LowMemoryException;
64 |
65 | /**
66 | * Get the minimum zoom level this tile source can provide.
67 | *
68 | * @return the minimum zoom level
69 | */
70 | public int getMinimumZoomLevel();
71 |
72 | /**
73 | * Get the maximum zoom level this tile source can provide.
74 | *
75 | * @return the maximum zoom level
76 | */
77 | public int getMaximumZoomLevel();
78 |
79 | /**
80 | * Get the tile size in pixels this tile source provides.
81 | *
82 | * @return the tile size in pixels
83 | */
84 | public int getTileSizePixels();
85 | }
86 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/tilesource/OnlineTileSourceBase.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource;
2 |
3 | import org.osmdroid.ResourceProxy.string;
4 | import org.osmdroid.tileprovider.MapTile;
5 |
6 | public abstract class OnlineTileSourceBase extends BitmapTileSourceBase {
7 |
8 | private final String mBaseUrls[];
9 |
10 | /**
11 | * Constructor
12 | * @param aName a human-friendly name for this tile source
13 | * @param aResourceId resource id used to get the localized name of this tile source
14 | * @param aZoomMinLevel the minimum zoom level this tile source can provide
15 | * @param aZoomMaxLevel the maximum zoom level this tile source can provide
16 | * @param aTileSizePixels the tile size in pixels this tile source provides
17 | * @param aImageFilenameEnding the file name extension used when constructing the filename
18 | * @param aBaseUrl the base url(s) of the tile server used when constructing the url to download the tiles
19 | */
20 | public OnlineTileSourceBase(final String aName, final string aResourceId,
21 | final int aZoomMinLevel, final int aZoomMaxLevel, final int aTileSizePixels,
22 | final String aImageFilenameEnding, final String[] aBaseUrl) {
23 | super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
24 | aImageFilenameEnding);
25 | mBaseUrls = aBaseUrl;
26 | }
27 |
28 | public abstract String getTileURLString(MapTile aTile);
29 |
30 | /**
31 | * Get the base url, which will be a random one if there are more than one.
32 | */
33 | protected String getBaseUrl() {
34 | return mBaseUrls[random.nextInt(mBaseUrls.length)];
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/tilesource/QuadTreeTileSource.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource;
2 |
3 | import org.osmdroid.ResourceProxy.string;
4 | import org.osmdroid.tileprovider.MapTile;
5 |
6 | public class QuadTreeTileSource extends OnlineTileSourceBase {
7 |
8 | public QuadTreeTileSource(final String aName, final string aResourceId,
9 | final int aZoomMinLevel, final int aZoomMaxLevel, final int aTileSizePixels,
10 | final String aImageFilenameEnding, final String[] aBaseUrl) {
11 | super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
12 | aImageFilenameEnding, aBaseUrl);
13 | }
14 |
15 | @Override
16 | public String getTileURLString(final MapTile aTile) {
17 | return getBaseUrl() + quadTree(aTile) + mImageFilenameEnding;
18 | }
19 |
20 | /**
21 | * Converts TMS tile coordinates to QuadTree
22 | *
23 | * @param aTile
24 | * The tile coordinates to convert
25 | * @return The QuadTree as String.
26 | */
27 | protected String quadTree(final MapTile aTile) {
28 | final StringBuilder quadKey = new StringBuilder();
29 | for (int i = aTile.getZoomLevel(); i > 0; i--) {
30 | int digit = 0;
31 | final int mask = 1 << (i - 1);
32 | if ((aTile.getX() & mask) != 0)
33 | digit += 1;
34 | if ((aTile.getY() & mask) != 0)
35 | digit += 2;
36 | quadKey.append("" + digit);
37 | }
38 |
39 | return quadKey.toString();
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/tilesource/XYTileSource.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource;
2 |
3 | import org.osmdroid.ResourceProxy.string;
4 | import org.osmdroid.tileprovider.MapTile;
5 |
6 | /**
7 | * An implementation of {@link org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase}
8 | */
9 | public class XYTileSource extends OnlineTileSourceBase {
10 |
11 | public XYTileSource(final String aName, final string aResourceId, final int aZoomMinLevel,
12 | final int aZoomMaxLevel, final int aTileSizePixels, final String aImageFilenameEnding,
13 | final String[] aBaseUrl) {
14 | super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
15 | aImageFilenameEnding, aBaseUrl);
16 | }
17 |
18 | @Override
19 | public String getTileURLString(final MapTile aTile) {
20 | return getBaseUrl() + aTile.getZoomLevel() + "/" + aTile.getX() + "/" + aTile.getY()
21 | + mImageFilenameEnding;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/util/ManifestUtil.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.util;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import android.content.Context;
7 | import android.content.pm.ApplicationInfo;
8 | import android.content.pm.PackageManager;
9 |
10 | /**
11 | * Utility class for reading the manifest
12 | */
13 | public class ManifestUtil {
14 |
15 | private static final Logger logger = LoggerFactory.getLogger(ManifestUtil.class);
16 |
17 | /**
18 | * Retrieve a key from the manifest meta data, or empty string if not found.
19 | */
20 | public static String retrieveKey(final Context aContext, final String aKey) {
21 |
22 | // get the key from the manifest
23 | final PackageManager pm = aContext.getPackageManager();
24 | try {
25 | final ApplicationInfo info = pm.getApplicationInfo(aContext.getPackageName(),
26 | PackageManager.GET_META_DATA);
27 | if (info.metaData == null) {
28 | logger.info("Key %s not found in manifest", aKey);
29 | } else {
30 | final String value = info.metaData.getString(aKey);
31 | if (value == null) {
32 | logger.info("Key %s not found in manifest", aKey);
33 | } else {
34 | return value.trim();
35 | }
36 | }
37 | } catch (final PackageManager.NameNotFoundException e) {
38 | logger.info("Key %s not found in manifest", aKey);
39 | }
40 | return "";
41 | }
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/util/SimpleInvalidationHandler.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.util;
2 |
3 | import org.osmdroid.tileprovider.MapTile;
4 |
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.view.View;
8 |
9 | public class SimpleInvalidationHandler extends Handler {
10 | private final View mView;
11 |
12 | public SimpleInvalidationHandler(final View pView) {
13 | super();
14 | mView = pView;
15 | }
16 |
17 | @Override
18 | public void handleMessage(final Message msg) {
19 | switch (msg.what) {
20 | case MapTile.MAPTILE_SUCCESS_ID:
21 | mView.invalidate();
22 | break;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/util/SimpleRegisterReceiver.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.util;
2 |
3 | import org.osmdroid.tileprovider.IRegisterReceiver;
4 |
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.IntentFilter;
9 |
10 | public class SimpleRegisterReceiver implements IRegisterReceiver {
11 |
12 | private final Context mContext;
13 |
14 | public SimpleRegisterReceiver(final Context pContext) {
15 | super();
16 | mContext = pContext;
17 | }
18 |
19 | @Override
20 | public Intent registerReceiver(final BroadcastReceiver aReceiver, final IntentFilter aFilter) {
21 | return mContext.registerReceiver(aReceiver, aFilter);
22 | }
23 |
24 | @Override
25 | public void unregisterReceiver(final BroadcastReceiver aReceiver) {
26 | mContext.unregisterReceiver(aReceiver);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/tileprovider/util/StreamUtils.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 19:14:08 - 20.10.2008
2 | package org.osmdroid.tileprovider.util;
3 |
4 | import java.io.Closeable;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.OutputStream;
8 |
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | public class StreamUtils {
13 |
14 | // ===========================================================
15 | // Constants
16 | // ===========================================================
17 |
18 | private static final Logger logger = LoggerFactory.getLogger(StreamUtils.class);
19 |
20 | public static final int IO_BUFFER_SIZE = 8 * 1024;
21 |
22 | // ===========================================================
23 | // Fields
24 | // ===========================================================
25 |
26 | // ===========================================================
27 | // Constructors
28 | // ===========================================================
29 |
30 | /**
31 | * This is a utility class with only static members.
32 | */
33 | private StreamUtils() {
34 | }
35 |
36 | // ===========================================================
37 | // Getter & Setter
38 | // ===========================================================
39 |
40 | // ===========================================================
41 | // Methods from SuperClass/Interfaces
42 | // ===========================================================
43 |
44 | // ===========================================================
45 | // Methods
46 | // ===========================================================
47 |
48 | /**
49 | * Copy the content of the input stream into the output stream, using a temporary byte array
50 | * buffer whose size is defined by {@link #IO_BUFFER_SIZE}.
51 | *
52 | * @param in
53 | * The input stream to copy from.
54 | * @param out
55 | * The output stream to copy to.
56 | * @return the total length copied
57 | *
58 | * @throws IOException
59 | * If any error occurs during the copy.
60 | */
61 | public static long copy(final InputStream in, final OutputStream out) throws IOException {
62 | long length = 0;
63 | final byte[] b = new byte[IO_BUFFER_SIZE];
64 | int read;
65 | while ((read = in.read(b)) != -1) {
66 | out.write(b, 0, read);
67 | length += read;
68 | }
69 | return length;
70 | }
71 |
72 | /**
73 | * Closes the specified stream.
74 | *
75 | * @param stream
76 | * The stream to close.
77 | */
78 | public static void closeStream(final Closeable stream) {
79 | if (stream != null) {
80 | try {
81 | stream.close();
82 | } catch (final IOException e) {
83 | logger.error("IO", "Could not close stream", e);
84 | }
85 | }
86 | }
87 |
88 | // ===========================================================
89 | // Inner and Anonymous Classes
90 | // ===========================================================
91 | }
92 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/GeometryMath.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util;
2 |
3 | import android.graphics.Point;
4 | import android.graphics.Rect;
5 |
6 | /**
7 | *
8 | * @author Marc Kurtz
9 | *
10 | */
11 | public class GeometryMath
12 | {
13 | public static final double DEG2RAD = (Math.PI / 180.0);
14 | public static final double RAD2DEG = (180.0 / Math.PI);
15 |
16 | public static final Rect getBoundingBoxForRotatatedRectangle(Rect rect, float angle, Rect reuse) {
17 | return getBoundingBoxForRotatatedRectangle(rect, rect.centerX(), rect.centerY(), angle,
18 | reuse);
19 | }
20 |
21 | public static final Rect getBoundingBoxForRotatatedRectangle(Rect rect, Point centerPoint,
22 | float angle, Rect reuse) {
23 | return getBoundingBoxForRotatatedRectangle(rect, centerPoint.x, centerPoint.y, angle, reuse);
24 | }
25 |
26 | public static final Rect getBoundingBoxForRotatatedRectangle(Rect rect, int centerX,
27 | int centerY, float angle, Rect reuse) {
28 | if (reuse == null)
29 | reuse = new Rect();
30 |
31 | double theta = angle * DEG2RAD;
32 | double sinTheta = Math.sin(theta);
33 | double cosTheta = Math.cos(theta);
34 | double dx1 = rect.left - centerX;
35 | double dy1 = rect.top - centerY;
36 | double newX1 = centerX - dx1 * cosTheta + dy1 * sinTheta;
37 | double newY1 = centerY - dx1 * sinTheta - dy1 * cosTheta;
38 | double dx2 = rect.right - centerX;
39 | double dy2 = rect.top - centerY;
40 | double newX2 = centerX - dx2 * cosTheta + dy2 * sinTheta;
41 | double newY2 = centerY - dx2 * sinTheta - dy2 * cosTheta;
42 | double dx3 = rect.left - centerX;
43 | double dy3 = rect.bottom - centerY;
44 | double newX3 = centerX - dx3 * cosTheta + dy3 * sinTheta;
45 | double newY3 = centerY - dx3 * sinTheta - dy3 * cosTheta;
46 | double dx4 = rect.right - centerX;
47 | double dy4 = rect.bottom - centerY;
48 | double newX4 = centerX - dx4 * cosTheta + dy4 * sinTheta;
49 | double newY4 = centerY - dx4 * sinTheta - dy4 * cosTheta;
50 | reuse.set((int) Min4(newX1, newX2, newX3, newX4), (int) Min4(newY1, newY2, newY3, newY4),
51 | (int) Max4(newX1, newX2, newX3, newX4), (int) Max4(newY1, newY2, newY3, newY4));
52 |
53 | return reuse;
54 | }
55 |
56 | private static double Min4(double a, double b, double c, double d) {
57 | return Math.floor(Math.min(Math.min(a, b), Math.min(c, d)));
58 | }
59 |
60 | private static double Max4(double a, double b, double c, double d) {
61 | return Math.ceil(Math.max(Math.max(a, b), Math.max(c, d)));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/LocationUtils.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util;
2 |
3 | import org.osmdroid.util.constants.UtilConstants;
4 |
5 | import android.location.Location;
6 | import android.location.LocationManager;
7 |
8 | public class LocationUtils implements UtilConstants {
9 |
10 | /**
11 | * This is a utility class with only static members.
12 | */
13 | private LocationUtils() {
14 | }
15 |
16 | /**
17 | * Get the most recent location from the GPS or Network provider.
18 | *
19 | * @return return the most recent location, or null if there's no known location
20 | */
21 | public static Location getLastKnownLocation(final LocationManager pLocationManager) {
22 | if (pLocationManager == null) {
23 | return null;
24 | }
25 | final Location gpsLocation = getLastKnownLocation(pLocationManager, LocationManager.GPS_PROVIDER);
26 | final Location networkLocation = getLastKnownLocation(pLocationManager, LocationManager.NETWORK_PROVIDER);
27 | if (gpsLocation == null) {
28 | return networkLocation;
29 | } else if (networkLocation == null) {
30 | return gpsLocation;
31 | } else {
32 | // both are non-null - use the most recent
33 | if (networkLocation.getTime() > gpsLocation.getTime() + GPS_WAIT_TIME) {
34 | return networkLocation;
35 | } else {
36 | return gpsLocation;
37 | }
38 | }
39 | }
40 |
41 | private static Location getLastKnownLocation(final LocationManager pLocationManager, final String pProvider) {
42 | try {
43 | if (!pLocationManager.isProviderEnabled(pProvider)) {
44 | return null;
45 | }
46 | } catch (final IllegalArgumentException e) {
47 | return null;
48 | }
49 | return pLocationManager.getLastKnownLocation(pProvider);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/MyMath.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 20:36:01 - 26.09.2008
2 | package org.osmdroid.util;
3 |
4 | import org.osmdroid.views.util.constants.MathConstants;
5 |
6 | /**
7 | *
8 | * @author Nicolas Gramlich
9 | *
10 | */
11 | public class MyMath implements MathConstants {
12 | // ===========================================================
13 | // Constants
14 | // ===========================================================
15 |
16 | // ===========================================================
17 | // Fields
18 | // ===========================================================
19 |
20 | // ===========================================================
21 | // Constructors
22 | // ===========================================================
23 |
24 | /**
25 | * This is a utility class with only static members.
26 | */
27 | private MyMath() {
28 | }
29 |
30 | // ===========================================================
31 | // Getter & Setter
32 | // ===========================================================
33 |
34 | // ===========================================================
35 | // Methods from SuperClass/Interfaces
36 | // ===========================================================
37 |
38 | // ===========================================================
39 | // Methods
40 | // ===========================================================
41 |
42 | public static double gudermannInverse(final double aLatitude) {
43 | return Math.log(Math.tan(PI_4 + (DEG2RAD * aLatitude / 2)));
44 | }
45 |
46 | public static double gudermann(final double y) {
47 | return RAD2DEG * Math.atan(Math.sinh(y));
48 | }
49 |
50 | public static int mod(int number, final int modulus) {
51 | if (number > 0)
52 | return number % modulus;
53 |
54 | while (number < 0)
55 | number += modulus;
56 |
57 | return number;
58 | }
59 |
60 | // ===========================================================
61 | // Inner and Anonymous Classes
62 | // ===========================================================
63 | }
64 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/NetworkLocationIgnorer.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util;
2 |
3 | import org.osmdroid.util.constants.UtilConstants;
4 |
5 | import android.location.LocationManager;
6 |
7 | /**
8 | *
9 | * A class to check whether we want to use a location. If there are multiple location providers,
10 | * i.e. network and GPS, then you want to ignore network locations shortly after a GPS location
11 | * because you will get another GPS location soon.
12 | *
13 | * @author Neil Boyd
14 | *
15 | */
16 | public class NetworkLocationIgnorer implements UtilConstants {
17 |
18 | /** last time we got a location from the gps provider */
19 | private long mLastGps = 0;
20 |
21 | /**
22 | * Whether we should ignore this location.
23 | *
24 | * @param pProvider
25 | * the provider that provided the location
26 | * @param pTime
27 | * the time of the location
28 | * @return true if we should ignore this location, false if not
29 | */
30 | public boolean shouldIgnore(final String pProvider, final long pTime) {
31 |
32 | if (LocationManager.GPS_PROVIDER.equals(pProvider)) {
33 | mLastGps = pTime;
34 | } else {
35 | if (pTime < mLastGps + GPS_WAIT_TIME) {
36 | return true;
37 | }
38 | }
39 |
40 | return false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/Position.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util;
2 |
3 | import org.osmdroid.api.IPosition;
4 |
5 | public class Position implements IPosition {
6 | private final double mLatitude;
7 | private final double mLongitude;
8 | private boolean mHasBearing;
9 | private float mBearing;
10 | private boolean mHasZoomLevel;
11 | private float mZoomLevel;
12 |
13 | public Position(final double aLatitude, final double aLongitude) {
14 | mLatitude = aLatitude;
15 | mLongitude = aLongitude;
16 | }
17 |
18 | @Override
19 | public double getLatitude() {
20 | return mLatitude;
21 | }
22 |
23 | @Override
24 | public double getLongitude() {
25 | return mLongitude;
26 | }
27 |
28 | @Override
29 | public boolean hasBearing() {
30 | return mHasBearing;
31 | }
32 |
33 | @Override
34 | public float getBearing() {
35 | return mBearing;
36 | }
37 |
38 | public void setBearing(final float aBearing) {
39 | mHasBearing = true;
40 | mBearing = aBearing;
41 | }
42 |
43 | @Override
44 | public boolean hasZoomLevel() {
45 | return mHasZoomLevel;
46 | }
47 |
48 | @Override
49 | public float getZoomLevel() {
50 | return mZoomLevel;
51 | }
52 |
53 | public void setZoomLevel(final float aZoomLevel) {
54 | mHasZoomLevel = true;
55 | mZoomLevel = aZoomLevel;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/ResourceProxyImpl.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | import org.osmdroid.DefaultResourceProxyImpl;
6 |
7 | import android.content.Context;
8 | import android.content.res.Resources;
9 | import android.graphics.Bitmap;
10 | import android.graphics.BitmapFactory;
11 | import android.graphics.drawable.Drawable;
12 |
13 | /**
14 | * This is an extension of {@link org.osmdroid.DefaultResourceProxyImpl}
15 | * that first tries to get from resources by using reflection to get the id of the resource
16 | * from the package that the context is in.
17 | */
18 | public class ResourceProxyImpl extends DefaultResourceProxyImpl {
19 |
20 | private final Resources mResources;
21 | private final String mResourceNameBase;
22 |
23 | public ResourceProxyImpl(final Context aContext) {
24 | super(aContext);
25 | mResources = aContext.getResources();
26 | mResourceNameBase = aContext.getPackageName() + ".R$";
27 | }
28 |
29 | @Override
30 | public String getString(final string pResId) {
31 | final int id = getId("string", pResId.name());
32 | return id != 0 ? mResources.getString(id) : super.getString(pResId);
33 | }
34 |
35 | @Override
36 | public String getString(final string pResId, final Object... formatArgs) {
37 | final int id = getId("string", pResId.name());
38 | return id != 0 ? mResources.getString(id, formatArgs) : super.getString(pResId, formatArgs);
39 | }
40 |
41 | @Override
42 | public Bitmap getBitmap(final bitmap pResId) {
43 | final int id = getId("drawable", pResId.name());
44 | return id != 0 ? BitmapFactory.decodeResource(mResources, id) : super.getBitmap(pResId);
45 | }
46 |
47 | @Override
48 | public Drawable getDrawable(final bitmap pResId) {
49 | final int id = getId("drawable", pResId.name());
50 | return id != 0 ? mResources.getDrawable(id) : super.getDrawable(pResId);
51 | }
52 |
53 | private int getId(final String aType, final String aName) {
54 | try {
55 | final Class> cls = Class.forName(mResourceNameBase + aType);
56 | final Field field = cls.getDeclaredField(aName);
57 | return field.getInt(null);
58 | } catch (final Exception e) {
59 | return 0;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/TileLooper.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util;
2 |
3 | import org.osmdroid.tileprovider.MapTile;
4 |
5 | import android.graphics.Canvas;
6 | import android.graphics.Point;
7 | import android.graphics.Rect;
8 |
9 | /**
10 | * A class that will loop around all the map tiles in the given viewport.
11 | */
12 | public abstract class TileLooper {
13 |
14 | protected final Point mUpperLeft = new Point();
15 | protected final Point mLowerRight = new Point();
16 |
17 | public final void loop(final Canvas pCanvas, final int pZoomLevel, final int pTileSizePx, final Rect pViewPort) {
18 | // Calculate the amount of tiles needed for each side around the center one.
19 | TileSystem.PixelXYToTileXY(pViewPort.left, pViewPort.top, mUpperLeft);
20 | mUpperLeft.offset(-1, -1);
21 | TileSystem.PixelXYToTileXY(pViewPort.right, pViewPort.bottom, mLowerRight);
22 |
23 | final int mapTileUpperBound = 1 << pZoomLevel;
24 |
25 | initialiseLoop(pZoomLevel, pTileSizePx);
26 |
27 | /* Draw all the MapTiles (from the upper left to the lower right). */
28 | for (int y = mUpperLeft.y; y <= mLowerRight.y; y++) {
29 | for (int x = mUpperLeft.x; x <= mLowerRight.x; x++) {
30 | // Construct a MapTile to request from the tile provider.
31 | final int tileY = MyMath.mod(y, mapTileUpperBound);
32 | final int tileX = MyMath.mod(x, mapTileUpperBound);
33 | final MapTile tile = new MapTile(pZoomLevel, tileX, tileY);
34 | handleTile(pCanvas, pTileSizePx, tile, x, y);
35 | }
36 | }
37 |
38 | finaliseLoop();
39 | }
40 |
41 | public abstract void initialiseLoop(int pZoomLevel, int pTileSizePx);
42 |
43 | public abstract void handleTile(Canvas pCanvas, int pTileSizePx, MapTile pTile, int pX, int pY);
44 |
45 | public abstract void finaliseLoop();
46 | }
47 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/constants/GeoConstants.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 17:41:55 - 16.10.2008
2 | package org.osmdroid.util.constants;
3 |
4 | public interface GeoConstants {
5 | // ===========================================================
6 | // Final Fields
7 | // ===========================================================
8 |
9 | public static final int RADIUS_EARTH_METERS = 6378137; // http://en.wikipedia.org/wiki/Earth_radius#Equatorial_radius
10 | public static final double METERS_PER_STATUTE_MILE = 1609.344; // http://en.wikipedia.org/wiki/Mile
11 | public static final double METERS_PER_NAUTICAL_MILE = 1852; // http://en.wikipedia.org/wiki/Nautical_mile
12 | public static final double FEET_PER_METER = 3.2808399; // http://en.wikipedia.org/wiki/Feet_%28unit_of_length%29
13 | public static final int EQUATORCIRCUMFENCE = (int) (2 * Math.PI * RADIUS_EARTH_METERS);
14 |
15 | // ===========================================================
16 | // Methods
17 | // ===========================================================
18 | }
19 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/util/constants/UtilConstants.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.util.constants;
2 |
3 | public interface UtilConstants {
4 |
5 | /**
6 | * The time we wait after the last gps location before using a non-gps location.
7 | */
8 | public static final long GPS_WAIT_TIME = 20000; // 20 seconds
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/drawing/OsmBitmapShader.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.drawing;
2 |
3 | import org.osmdroid.views.Projection;
4 |
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapShader;
7 | import android.graphics.Matrix;
8 | import android.graphics.Point;
9 |
10 | public class OsmBitmapShader extends BitmapShader {
11 | private static final Point sPoint = new Point();
12 |
13 | private final Matrix mMatrix = new Matrix();
14 | private int mBitmapWidth;
15 | private int mBitmapHeight;
16 |
17 | public OsmBitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) {
18 | super(bitmap, tileX, tileY);
19 | mBitmapWidth = bitmap.getWidth();
20 | mBitmapHeight = bitmap.getHeight();
21 | }
22 |
23 | public void onDrawCycle(Projection projection) {
24 | projection.toMercatorPixels(0, 0, sPoint);
25 | mMatrix.setTranslate(-sPoint.x % mBitmapWidth, -sPoint.y % mBitmapHeight);
26 | setLocalMatrix(mMatrix);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/drawing/OsmPath.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.drawing;
2 |
3 | import org.osmdroid.util.GeoPoint;
4 | import org.osmdroid.views.Projection;
5 |
6 | import android.graphics.Path;
7 | import android.graphics.Point;
8 |
9 | /**
10 | * Since the osmdroid canvas coordinate system is changing with every scroll, the x/y coordinates of
11 | * lat/long points is also always changing. Converting from lat/long to pixel values is a
12 | * potentially expensive operation and shouldn't be performed in the draw() cycle. Instead of
13 | * recalculating your {@link Path} points every draw cycle, you can use an OsmPath and call
14 | * {@link #onDrawCycle(Projection)} at the start of your draw call. This will simply shift the Path
15 | * the proper amount so that it is in the correct pixel position.
16 | *
17 | * @author Marc Kurtz
18 | *
19 | */
20 | public class OsmPath extends Path {
21 |
22 | private final static GeoPoint sReferenceGeoPoint = new GeoPoint(0, 0);
23 | protected final Point mReferencePoint = new Point();
24 | private int mLastZoomLevel = -1;
25 |
26 | public OsmPath() {
27 | super();
28 | }
29 |
30 | public OsmPath(Path src) {
31 | super(src);
32 | }
33 |
34 | /**
35 | * Call this method at the beginning of every draw() call.
36 | */
37 | public void onDrawCycle(Projection proj) {
38 | if (mLastZoomLevel != proj.getZoomLevel()) {
39 | proj.toPixels(sReferenceGeoPoint, mReferencePoint);
40 | mLastZoomLevel = proj.getZoomLevel();
41 | } else {
42 | int x = mReferencePoint.x;
43 | int y = mReferencePoint.y;
44 | proj.toPixels(sReferenceGeoPoint, mReferencePoint);
45 | int deltaX = mReferencePoint.x - x;
46 | int deltaY = mReferencePoint.y - y;
47 |
48 | offset(deltaX, deltaY);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/overlay/IOverlayMenuProvider.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.overlay;
2 |
3 | import org.osmdroid.views.MapView;
4 |
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 |
8 | public interface IOverlayMenuProvider {
9 | public boolean onCreateOptionsMenu(final Menu pMenu, final int pMenuIdOffset,
10 | final MapView pMapView);
11 |
12 | public boolean onPrepareOptionsMenu(final Menu pMenu, final int pMenuIdOffset,
13 | final MapView pMapView);
14 |
15 | public boolean onOptionsItemSelected(final MenuItem pItem, final int pMenuIdOffset,
16 | final MapView pMapView);
17 |
18 | /**
19 | * Can be used to signal to external callers that this Overlay should not be used for providing
20 | * option menu items.
21 | *
22 | */
23 | public boolean isOptionsMenuEnabled();
24 |
25 | public void setOptionsMenuEnabled(final boolean pOptionsMenuEnabled);
26 | }
27 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/overlay/compass/IOrientationConsumer.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.overlay.compass;
2 |
3 |
4 | public interface IOrientationConsumer
5 | {
6 | void onOrientationChanged(float orientation, IOrientationProvider source);
7 | }
8 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/overlay/compass/IOrientationProvider.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.overlay.compass;
2 |
3 |
4 | public interface IOrientationProvider
5 | {
6 | boolean startOrientationProvider(IOrientationConsumer orientationConsumer);
7 |
8 | void stopOrientationProvider();
9 |
10 | float getLastKnownOrientation();
11 | }
12 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/overlay/compass/InternalCompassOrientationProvider.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.overlay.compass;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 |
9 | public class InternalCompassOrientationProvider implements SensorEventListener, IOrientationProvider
10 | {
11 | private IOrientationConsumer mOrientationConsumer;
12 | private final SensorManager mSensorManager;
13 | private float mAzimuth;
14 |
15 | public InternalCompassOrientationProvider(Context context)
16 | {
17 | mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
18 | }
19 |
20 | //
21 | // IOrientationProvider
22 | //
23 |
24 | /**
25 | * Enable orientation updates from the internal compass sensor and show the compass.
26 | */
27 | @Override
28 | public boolean startOrientationProvider(IOrientationConsumer orientationConsumer)
29 | {
30 | mOrientationConsumer = orientationConsumer;
31 | boolean result = false;
32 |
33 | final Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
34 | if (sensor != null) {
35 | result = mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI);
36 | }
37 | return result;
38 | }
39 |
40 | @Override
41 | public void stopOrientationProvider()
42 | {
43 | mOrientationConsumer = null;
44 | mSensorManager.unregisterListener(this);
45 | }
46 |
47 | @Override
48 | public float getLastKnownOrientation()
49 | {
50 | return mAzimuth;
51 | }
52 |
53 | //
54 | // SensorEventListener
55 | //
56 |
57 | @Override
58 | public void onAccuracyChanged(final Sensor sensor, final int accuracy)
59 | {
60 | // This is not interesting for us at the moment
61 | }
62 |
63 | @Override
64 | public void onSensorChanged(final SensorEvent event)
65 | {
66 | if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
67 | if (event.values != null) {
68 | mAzimuth = event.values[0];
69 | if (mOrientationConsumer != null)
70 | mOrientationConsumer.onOrientationChanged(mAzimuth, this);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/overlay/mylocation/IMyLocationConsumer.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.overlay.mylocation;
2 |
3 | import android.location.Location;
4 |
5 | public interface IMyLocationConsumer {
6 | /**
7 | * Call when a provider has a new location to consume. This can be called on any thread.
8 | */
9 | void onLocationChanged(Location location, IMyLocationProvider source);
10 | }
11 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/overlay/mylocation/IMyLocationProvider.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.overlay.mylocation;
2 |
3 | import android.location.Location;
4 |
5 | public interface IMyLocationProvider {
6 | boolean startLocationProvider(IMyLocationConsumer myLocationConsumer);
7 |
8 | void stopLocationProvider();
9 |
10 | Location getLastKnownLocation();
11 | }
12 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/util/MyMath.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 20:36:01 - 26.09.2008
2 | package org.osmdroid.views.util;
3 |
4 | /**
5 | *
6 | * @author Nicolas Gramlich
7 | *
8 | */
9 | public class MyMath {
10 | // ===========================================================
11 | // Constants
12 | // ===========================================================
13 |
14 | // ===========================================================
15 | // Fields
16 | // ===========================================================
17 |
18 | // ===========================================================
19 | // Constructors
20 | // ===========================================================
21 |
22 | /**
23 | * This is a utility class with only static members.
24 | */
25 | private MyMath() {
26 | }
27 |
28 | // ===========================================================
29 | // Getter & Setter
30 | // ===========================================================
31 |
32 | // ===========================================================
33 | // Methods from SuperClass/Interfaces
34 | // ===========================================================
35 |
36 | // ===========================================================
37 | // Methods
38 | // ===========================================================
39 |
40 | /**
41 | * Calculates i.e. the increase of zoomlevel needed when the visible latitude needs to be bigger
42 | * by factor
.
43 | *
44 | * Assert.assertEquals(1, getNextSquareNumberAbove(1.1f)); Assert.assertEquals(2,
45 | * getNextSquareNumberAbove(2.1f)); Assert.assertEquals(2, getNextSquareNumberAbove(3.9f));
46 | * Assert.assertEquals(3, getNextSquareNumberAbove(4.1f)); Assert.assertEquals(3,
47 | * getNextSquareNumberAbove(7.9f)); Assert.assertEquals(4, getNextSquareNumberAbove(8.1f));
48 | * Assert.assertEquals(5, getNextSquareNumberAbove(16.1f));
49 | *
50 | * Assert.assertEquals(-1, - getNextSquareNumberAbove(1 / 0.4f) + 1); Assert.assertEquals(-2, -
51 | * getNextSquareNumberAbove(1 / 0.24f) + 1);
52 | *
53 | * @param factor
54 | * @return
55 | */
56 | public static int getNextSquareNumberAbove(final float factor) {
57 | int out = 0;
58 | int cur = 1;
59 | int i = 1;
60 | while (true) {
61 | if (cur > factor)
62 | return out;
63 |
64 | out = i;
65 | cur *= 2;
66 | i++;
67 | }
68 | }
69 |
70 | // ===========================================================
71 | // Inner and Anonymous Classes
72 | // ===========================================================
73 | }
74 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/util/constants/MapViewConstants.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 18:00:24 - 25.09.2008
2 | package org.osmdroid.views.util.constants;
3 |
4 | /**
5 | *
6 | * This class contains constants used by the map view.
7 | *
8 | * @author Nicolas Gramlich
9 | *
10 | */
11 | public interface MapViewConstants {
12 | // ===========================================================
13 | // Final Fields
14 | // ===========================================================
15 |
16 | public static final boolean DEBUGMODE = false;
17 |
18 | public static final int NOT_SET = Integer.MIN_VALUE;
19 |
20 | public static final int ANIMATION_SMOOTHNESS_LOW = 4;
21 | public static final int ANIMATION_SMOOTHNESS_DEFAULT = 10;
22 | public static final int ANIMATION_SMOOTHNESS_HIGH = 20;
23 |
24 | public static final int ANIMATION_DURATION_SHORT = 500;
25 | public static final int ANIMATION_DURATION_DEFAULT = 1000;
26 | public static final int ANIMATION_DURATION_LONG = 2000;
27 |
28 | /** Minimum Zoom Level */
29 | public static final int MINIMUM_ZOOMLEVEL = 0;
30 |
31 | /**
32 | * Maximum Zoom Level - we use Integers to store zoom levels so overflow happens at 2^32 - 1,
33 | * but we also have a tile size that is typically 2^8, so (32-1)-8-1 = 22
34 | */
35 | public static final int MAXIMUM_ZOOMLEVEL = 22;
36 | }
37 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/util/constants/MathConstants.java:
--------------------------------------------------------------------------------
1 | // Created by plusminus on 17:27:54 - 30.09.2008
2 | package org.osmdroid.views.util.constants;
3 |
4 | /**
5 | *
6 | * @author Nicolas Gramlich
7 | *
8 | */
9 | public interface MathConstants {
10 | // ===========================================================
11 | // Final Fields
12 | // ===========================================================
13 |
14 | public static final float DEG2RAD = (float) (Math.PI / 180.0);
15 | public static final float RAD2DEG = (float) (180.0 / Math.PI);
16 |
17 | public static final float PI = (float) Math.PI;
18 | public static final float PI_2 = PI / 2.0f;
19 | public static final float PI_4 = PI / 4.0f;
20 |
21 | // ===========================================================
22 | // Methods
23 | // ===========================================================
24 | }
25 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/java/org/osmdroid/views/util/constants/OverlayConstants.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.views.util.constants;
2 |
3 | /**
4 | * This class contains constants used by the overlays.
5 | */
6 | public interface OverlayConstants {
7 | // ===========================================================
8 | // Final Fields
9 | // ===========================================================
10 |
11 | public static final boolean DEBUGMODE = false;
12 |
13 | public static final int NOT_SET = Integer.MIN_VALUE;
14 |
15 | public static final int DEFAULT_ZOOMLEVEL_MINIMAP_DIFFERENCE = 3;
16 | }
17 |
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/center.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/center.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/direction_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/direction_arrow.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_compass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_compass.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_mapmode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_mapmode.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_mylocation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_mylocation.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_offline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/ic_menu_offline.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/marker_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/marker_default.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/marker_default_focused_base.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/marker_default_focused_base.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/navto_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/navto_small.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/next.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/person.png
--------------------------------------------------------------------------------
/osmdroid-android/src/main/resources/org/osmdroid/previous.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_external_osmdroid/d6f88f61a55057303696a66c698d56f0bcfd8e22/osmdroid-android/src/main/resources/org/osmdroid/previous.png
--------------------------------------------------------------------------------
/osmdroid-android/src/test/java/org/osmdroid/DefaultResourceProxyTest.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import org.junit.Test;
7 |
8 | import android.graphics.Bitmap;
9 |
10 | public class DefaultResourceProxyTest {
11 |
12 | @Test
13 | public void test_getString() {
14 | final ResourceProxy rp = new DefaultResourceProxyImpl(null);
15 | final String mapnik = rp.getString(ResourceProxy.string.mapnik);
16 | assertEquals("Got string okay", "Mapnik", mapnik);
17 | }
18 |
19 | @Test(expected = RuntimeException.class)
20 | public void test_getBitmap_stub() {
21 | final ResourceProxy rp = new DefaultResourceProxyImpl(null);
22 | final Bitmap center = rp.getBitmap(ResourceProxy.bitmap.person);
23 | assertNotNull("Got bitmap okay", center);
24 | }
25 |
26 | @Test(expected = IllegalArgumentException.class)
27 | public void test_getBitmap_not_found() {
28 | final ResourceProxy rp = new DefaultResourceProxyImpl(null);
29 | final Bitmap center = rp.getBitmap(ResourceProxy.bitmap.unknown);
30 | assertNotNull("Got bitmap okay", center);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/osmdroid-third-party/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/osmdroid-third-party/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | osmdroid-third-party
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/osmdroid-third-party/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | sourceSets {
3 | main.java.srcDirs = ['src\main\java','src\main\resources','src\test\java','src\test\resources']
4 | }
5 |
--------------------------------------------------------------------------------
/osmdroid-third-party/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.osmdroid
6 | osmdroid-parent
7 | 4.2
8 |
9 |
10 | osmdroid-third-party
11 | jar
12 |
13 | OSMdroid Third Party
14 |
15 | TODO
16 |
17 |
18 |
19 |
20 | android
21 | android
22 |
23 |
24 | android.support
25 | compatibility-v4
26 |
27 |
28 | com.google.android.maps
29 | maps
30 |
31 |
32 | com.google.android.gms
33 | google-play-services
34 | jar
35 |
36 |
37 | org.json
38 | json
39 |
40 |
41 | org.apache.httpcomponents
42 | httpmime
43 |
44 |
45 | org.apache.james
46 | apache-mime4j
47 |
48 |
49 |
50 |
51 | ${project.groupId}
52 | osmdroid-android
53 | ${project.version}
54 |
55 |
56 |
57 |
58 | org.slf4j
59 | slf4j-api
60 |
61 |
62 |
63 |
64 | org.slf4j
65 | slf4j-log4j12
66 |
67 |
68 | junit
69 | junit
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/overlay/GoogleItemizedOverlay.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.overlay;
2 |
3 | import java.util.ArrayList;
4 |
5 | import com.google.android.maps.ItemizedOverlay;
6 | import com.google.android.maps.OverlayItem;
7 |
8 | import android.graphics.drawable.Drawable;
9 |
10 | public class GoogleItemizedOverlay extends ItemizedOverlay {
11 |
12 | private ArrayList mOverlays = new ArrayList();
13 |
14 | public GoogleItemizedOverlay(final Drawable aDefaultMarker) {
15 | super(boundCenterBottom(aDefaultMarker));
16 | }
17 |
18 | public void addOverlay(final OverlayItem aOverlayItem) {
19 | mOverlays.add(aOverlayItem);
20 | populate();
21 | }
22 |
23 | /**
24 | * Use this method instead of
25 | * {@link com.google.android.maps.OverlayItem#setMarker(android.graphics.drawable.Drawable)}
26 | * to set a marker that is anchored center.
27 | */
28 | public static void setOverlayMarkerCentered(final OverlayItem aOverlayItem, final Drawable aMarker) {
29 | aOverlayItem.setMarker(boundCenter(aMarker));
30 | }
31 |
32 | @Override
33 | protected OverlayItem createItem(final int aIndex) {
34 | return mOverlays.get(aIndex);
35 | }
36 |
37 | @Override
38 | public int size() {
39 | return mOverlays.size();
40 | }
41 |
42 | public void removeAllItems() {
43 | mOverlays.clear();
44 | // TODO do we need to call populate() here ???
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/GeoPoint.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper;
2 |
3 | import org.osmdroid.api.IGeoPoint;
4 |
5 | /**
6 | * A wrapper for the Google {@link com.google.android.maps.GeoPoint} class.
7 | * This implements {@link IGeoPoint}, which is also implemented by the osmdroid
8 | * {@link org.osmdroid.util.GeoPoint}.
9 | *
10 | * @author Neil Boyd
11 | *
12 | */
13 | public class GeoPoint implements IGeoPoint {
14 |
15 | private final com.google.android.maps.GeoPoint mGeoPoint;
16 |
17 | public GeoPoint(final com.google.android.maps.GeoPoint pGeoPoint) {
18 | mGeoPoint = pGeoPoint;
19 | }
20 |
21 | @Override
22 | public int getLatitudeE6() {
23 | return mGeoPoint.getLatitudeE6();
24 | }
25 |
26 | @Override
27 | public int getLongitudeE6() {
28 | return mGeoPoint.getLongitudeE6();
29 | }
30 |
31 | @Override
32 | public double getLatitude() {
33 | return mGeoPoint.getLatitudeE6() * 1E-6;
34 | }
35 |
36 | @Override
37 | public double getLongitude() {
38 | return mGeoPoint.getLongitudeE6() * 1E-6;
39 | }
40 |
41 | @Override
42 | public boolean equals(final Object obj) {
43 | if (obj == null) {
44 | return false;
45 | }
46 | if (obj == this) {
47 | return true;
48 | }
49 | if (obj.getClass() != getClass()) {
50 | return false;
51 | }
52 | final GeoPoint rhs = (GeoPoint) obj;
53 | return rhs.mGeoPoint.equals(this.mGeoPoint);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/MapController.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper;
2 |
3 | import org.osmdroid.api.IGeoPoint;
4 | import org.osmdroid.api.IMapController;
5 |
6 | /**
7 | * A wrapper for the Google {@link com.google.android.maps.MapController} class.
8 | * This implements {@link IMapController}, which is also implemented by the osmdroid
9 | * {@link org.osmdroid.views.MapController}.
10 | *
11 | * @author Neil Boyd
12 | *
13 | */
14 | public class MapController implements IMapController {
15 |
16 | private final com.google.android.maps.MapController mController;
17 |
18 | public MapController(final com.google.android.maps.MapController pController) {
19 | mController = pController;
20 | }
21 |
22 | @Override
23 | public void animateTo(final IGeoPoint pGeoPoint) {
24 | mController.animateTo(new com.google.android.maps.GeoPoint(pGeoPoint.getLatitudeE6(), pGeoPoint.getLongitudeE6()));
25 | }
26 |
27 | @Override
28 | public void setCenter(final IGeoPoint pGeoPoint) {
29 | mController.setCenter(new com.google.android.maps.GeoPoint(pGeoPoint.getLatitudeE6(), pGeoPoint.getLongitudeE6()));
30 | }
31 |
32 | @Override
33 | public int setZoom(final int pZoomLevel) {
34 | return mController.setZoom(pZoomLevel);
35 | }
36 |
37 | @Override
38 | public boolean zoomIn() {
39 | return mController.zoomIn();
40 | }
41 |
42 | @Override
43 | public boolean zoomInFixing(final int xPixel, final int yPixel) {
44 | return mController.zoomInFixing(xPixel, yPixel);
45 | }
46 |
47 | @Override
48 | public boolean zoomOut() {
49 | return mController.zoomOut();
50 | }
51 |
52 | @Override
53 | public boolean zoomOutFixing(final int xPixel, final int yPixel) {
54 | return mController.zoomOutFixing(xPixel, yPixel);
55 | }
56 |
57 | @Override
58 | public void zoomToSpan(final int pLatSpanE6, final int pLonSpanE6) {
59 | mController.zoomToSpan(pLatSpanE6, pLonSpanE6);
60 | }
61 |
62 | @Override
63 | public void scrollBy(int x, int y) {
64 | mController.scrollBy(x, y);
65 | }
66 |
67 | @Override
68 | public void stopAnimation(boolean jumpToFinish) {
69 | mController.stopAnimation(jumpToFinish);
70 | }
71 |
72 | @Override
73 | public void stopPanning() {
74 | mController.stopPanning();
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/MapView.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper;
2 |
3 | import org.osmdroid.api.IGeoPoint;
4 | import org.osmdroid.api.IMapController;
5 | import org.osmdroid.api.IMapView;
6 | import org.osmdroid.api.IProjection;
7 |
8 | import android.content.Context;
9 | import android.util.AttributeSet;
10 |
11 | /**
12 | * A wrapper for the Google {@link com.google.android.maps.MapView} class.
13 | * This implements {@link IMapView}, which is also implemented by the osmdroid
14 | * {@link org.osmdroid.views.MapView}.
15 | *
16 | * @author Neil Boyd
17 | *
18 | */
19 | public class MapView implements IMapView {
20 |
21 | private final com.google.android.maps.MapView mMapView;
22 |
23 | public MapView(final com.google.android.maps.MapView pMapView) {
24 | mMapView = pMapView;
25 | }
26 |
27 | public MapView(final Context pContext, final AttributeSet pAttrs, final int pDefStyle) {
28 | this(new com.google.android.maps.MapView(pContext, pAttrs, pDefStyle));
29 | }
30 |
31 | public MapView(final Context pContext, final AttributeSet pAttrs) {
32 | this(new com.google.android.maps.MapView(pContext, pAttrs));
33 | }
34 |
35 | public MapView(final Context pContext, final String pApiKey) {
36 | this(new com.google.android.maps.MapView(pContext, pApiKey));
37 | }
38 |
39 | @Override
40 | public IMapController getController() {
41 | return new MapController(mMapView.getController());
42 | }
43 |
44 | @Override
45 | public IProjection getProjection() {
46 | return new Projection(mMapView);
47 | }
48 |
49 | @Override
50 | public int getZoomLevel() {
51 | return mMapView.getZoomLevel();
52 | }
53 |
54 | @Override
55 | public int getLatitudeSpan() {
56 | return mMapView.getLatitudeSpan();
57 | }
58 |
59 | @Override
60 | public int getLongitudeSpan() {
61 | return mMapView.getLongitudeSpan();
62 | }
63 |
64 | @Override
65 | public IGeoPoint getMapCenter() {
66 | return new GeoPoint(mMapView.getMapCenter());
67 | }
68 |
69 | @Override
70 | public int getMaxZoomLevel() {
71 | return mMapView.getMaxZoomLevel();
72 | }
73 |
74 | @Override
75 | public void setBackgroundColor(final int pColor) {
76 | // this doesn't seem to have any visible effect on the Google MapView
77 | mMapView.setBackgroundColor(pColor);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/MyLocationOverlay.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper;
2 |
3 | import org.osmdroid.api.IMyLocationOverlay;
4 |
5 | import android.content.Context;
6 |
7 | import com.google.android.maps.MapView;
8 |
9 | /**
10 | * A wrapper for the Google {@link com.google.android.maps.MyLocationOverlay} class.
11 | * This implements {@link IMyLocationOverlay}, which is also implemented by the osmdroid
12 | * {@link org.osmdroid.views.overlay.MyLocationOverlay}.
13 | *
14 | * @author Neil Boyd
15 | *
16 | */
17 | public class MyLocationOverlay
18 | extends com.google.android.maps.MyLocationOverlay
19 | implements IMyLocationOverlay {
20 |
21 | public MyLocationOverlay(final Context pContext, final MapView pMapView) {
22 | super(pContext, pMapView);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/Projection.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper;
2 |
3 | import org.osmdroid.api.IGeoPoint;
4 | import org.osmdroid.api.IProjection;
5 |
6 | import android.graphics.Point;
7 |
8 | /**
9 | * A wrapper for the Google {@link com.google.android.maps.Projection} implementation.
10 | * This implements {@link IProjection}, which is also implemented by the osmdroid
11 | * {@link org.osmdroid.views.MapView.Projection}.
12 | *
13 | * @author Neil Boyd
14 | *
15 | */
16 | public class Projection implements IProjection {
17 |
18 | private final com.google.android.maps.Projection mProjection;
19 | private final int mWidth;
20 | private final int mHeight;
21 |
22 | public Projection(final com.google.android.maps.MapView aMapView) {
23 | mProjection = aMapView.getProjection();
24 | mWidth = aMapView.getWidth();
25 | mHeight = aMapView.getHeight();
26 | }
27 |
28 | @Override
29 | public Point toPixels(final IGeoPoint in, final Point out) {
30 | final com.google.android.maps.GeoPoint googleGeoPoint =
31 | new com.google.android.maps.GeoPoint(in.getLatitudeE6(), in.getLongitudeE6());
32 | return mProjection.toPixels(googleGeoPoint, out);
33 | }
34 |
35 | @Override
36 | public IGeoPoint fromPixels(final int x, final int y) {
37 | final com.google.android.maps.GeoPoint googleGeoPoint = mProjection.fromPixels(x, y);
38 | return new GeoPoint(googleGeoPoint);
39 | }
40 |
41 | @Override
42 | public float metersToEquatorPixels(final float meters) {
43 | return mProjection.metersToEquatorPixels(meters);
44 | }
45 |
46 | @Override
47 | public IGeoPoint getNorthEast() {
48 | return fromPixels(mWidth, 0);
49 | }
50 |
51 | @Override
52 | public IGeoPoint getSouthWest() {
53 | return fromPixels(0, mHeight);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/GeoPoint.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper.v2;
2 |
3 | import com.google.android.gms.maps.model.LatLng;
4 | import org.osmdroid.api.IGeoPoint;
5 |
6 | public class GeoPoint implements IGeoPoint {
7 |
8 | private final LatLng mLatLng;
9 |
10 | public GeoPoint(final LatLng aLatLng) {
11 | mLatLng = aLatLng;
12 | }
13 |
14 | @Override
15 | public int getLatitudeE6() {
16 | return (int) (mLatLng.latitude * 1E6);
17 | }
18 |
19 | @Override
20 | public int getLongitudeE6() {
21 | return (int) (mLatLng.longitude * 1E6);
22 | }
23 |
24 | @Override
25 | public double getLatitude() {
26 | return mLatLng.latitude;
27 | }
28 |
29 | @Override
30 | public double getLongitude() {
31 | return mLatLng.longitude;
32 | }
33 |
34 | @Override
35 | public boolean equals(final Object obj) {
36 | if (obj == null) {
37 | return false;
38 | }
39 | if (obj == this) {
40 | return true;
41 | }
42 | if (obj.getClass() != getClass()) {
43 | return false;
44 | }
45 | final GeoPoint rhs = (GeoPoint) obj;
46 | return rhs.mLatLng.equals(this.mLatLng);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/Projection.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.google.wrapper.v2;
2 |
3 | import com.google.android.gms.maps.model.LatLng;
4 | import com.google.android.gms.maps.model.LatLngBounds;
5 | import org.osmdroid.api.IGeoPoint;
6 | import org.osmdroid.api.IProjection;
7 |
8 | import android.graphics.Point;
9 |
10 | public class Projection implements IProjection {
11 |
12 | private final com.google.android.gms.maps.Projection mProjection;
13 |
14 | private final Point mPoint = new Point();
15 |
16 | public Projection(final com.google.android.gms.maps.Projection aProjection) {
17 | mProjection = aProjection;
18 | }
19 |
20 | @Override
21 | public Point toPixels(final IGeoPoint in, final Point out) {
22 | final LatLng latLng = new LatLng(in.getLatitude(), in.getLongitude());
23 | final Point point = mProjection.toScreenLocation(latLng);
24 | if (out != null) {
25 | out.x = point.x;
26 | out.y = point.y;
27 | }
28 | return point;
29 | }
30 |
31 | @Override
32 | public IGeoPoint fromPixels(final int x, final int y) {
33 | mPoint.x = x;
34 | mPoint.y = y;
35 | final LatLng latLng = mProjection.fromScreenLocation(mPoint);
36 | return new GeoPoint(latLng);
37 | }
38 |
39 | @Override
40 | public float metersToEquatorPixels(final float meters) {
41 | return 0; // TODO implement this
42 | }
43 |
44 | @Override
45 | public IGeoPoint getNorthEast() {
46 | final LatLngBounds bounds = mProjection.getVisibleRegion().latLngBounds;
47 | return new GeoPoint(bounds.northeast);
48 | }
49 |
50 | @Override
51 | public IGeoPoint getSouthWest() {
52 | final LatLngBounds bounds = mProjection.getVisibleRegion().latLngBounds;
53 | return new GeoPoint(bounds.southwest);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/osmdroid-third-party/src/main/java/org/osmdroid/tileprovider/tilesource/bing/imagerymetadata/ImageryMetaData.java:
--------------------------------------------------------------------------------
1 | package org.osmdroid.tileprovider.tilesource.bing.imagerymetadata;
2 |
3 | import org.json.JSONArray;
4 | import org.json.JSONObject;
5 |
6 | /**
7 | * ImageryMetaData storage. Class used to decode valid ImageryMetaData.
8 | *
9 | */
10 | public class ImageryMetaData {
11 |
12 | // Useful fields found in ImageryMetaData response
13 | private final static String STATUS_CODE="statusCode";
14 | private final static String AUTH_RESULT_CODE="authenticationResultCode";
15 | private final static String AUTH_RESULT_CODE_VALID="ValidCredentials";
16 | private final static String RESOURCE_SETS="resourceSets";
17 | private final static String ESTIMATED_TOTAL="estimatedTotal";
18 | private final static String RESOURCE = "resources";
19 |
20 | /**
21 | * Parse a JSON string containing ImageryMetaData response
22 | * @param a_jsonContent the JSON content string
23 | * @return ImageryMetaDataResource object containing parsed information
24 | * @throws Exception
25 | */
26 | static public ImageryMetaDataResource getInstanceFromJSON(final String a_jsonContent) throws Exception
27 | {
28 |
29 | if(a_jsonContent==null) {
30 | throw new Exception("JSON to parse is null");
31 | }
32 |
33 | /// response code should be 200 and authorization should be valid (valid BingMap key)
34 | final JSONObject jsonResult = new JSONObject(a_jsonContent);
35 | final int statusCode = jsonResult.getInt(STATUS_CODE);
36 | if(statusCode!=200) {
37 | throw new Exception("Status code = "+statusCode);
38 | }
39 |
40 | if(AUTH_RESULT_CODE_VALID.compareToIgnoreCase(jsonResult.getString(AUTH_RESULT_CODE))!=0) {
41 | throw new Exception("authentication result code = "+jsonResult.getString(AUTH_RESULT_CODE));
42 | }
43 |
44 | // get first valid resource information
45 | final JSONArray resultsSet = jsonResult.getJSONArray(RESOURCE_SETS);
46 | if(resultsSet==null || resultsSet.length()<1) {
47 | throw new Exception("No results set found in json response");
48 | }
49 |
50 | if(resultsSet.getJSONObject(0).getInt(ESTIMATED_TOTAL)<=0) {
51 | throw new Exception("No resource found in json response");
52 | }
53 |
54 | final JSONObject resource = resultsSet.getJSONObject(0).getJSONArray(RESOURCE).getJSONObject(0);
55 |
56 | return ImageryMetaDataResource.getInstanceFromJSON(resource);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------