Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions MapsForgeForOsmdroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 4
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 4
targetSdkVersion 4
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions OSMBonusPack/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 4
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 4
targetSdkVersion 4
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
Expand Down
12 changes: 6 additions & 6 deletions OSMBonusPackTuto/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 4
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.example.osmbonuspacktuto"
minSdkVersion 4
targetSdkVersion 4
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
Expand All @@ -29,13 +29,13 @@ repositories {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile(name:'OSMBonusPack-release', ext:'aar')
// compile project(":OSMBonusPack")
// compile(name:'OSMBonusPack-release', ext:'aar')
compile project(":OSMBonusPack")

compile 'org.osmdroid:osmdroid-android:4.3'
compile 'org.slf4j:slf4j-android:1.6.1-RC1'

compile "com.android.support:support-v4:22.2.0"
compile "com.android.support:appcompat-v7:22.2.0"
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'com.google.code.gson:gson:2.3'
}
2 changes: 1 addition & 1 deletion OSMBonusPackTuto/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme" >
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
Expand All @@ -62,16 +64,21 @@
* @author M.Kergall
*
*/
public class MainActivity extends Activity implements MapEventsReceiver {
public class MainActivity extends AppCompatActivity implements MapEventsReceiver {

MapView map;
KmlDocument mKmlDocument;
Toolbar toolbar;

@Override protected void onCreate(Bundle savedInstanceState) {

//Introduction
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

map = (MapView) findViewById(R.id.map);
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
Expand Down
18 changes: 14 additions & 4 deletions OSMBonusPackTuto/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">


<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:title="@string/app_name"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

<org.osmdroid.views.MapView android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>


</LinearLayout>
6 changes: 6 additions & 0 deletions OSMBonusPackTuto/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#E91E63</color>
<color name="primary_dark">#C2185B</color>
<color name="accent">#03A9F4</color>
</resources>
8 changes: 8 additions & 0 deletions OSMBonusPackTuto/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
</resources>
10 changes: 7 additions & 3 deletions OSMNavigator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 4
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.osmnavigator"
minSdkVersion 4
targetSdkVersion 4
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
Expand All @@ -25,6 +25,10 @@ dependencies {
compile project(":OSMBonusPack")
compile project(":MapsForgeForOsmdroid")

compile "com.android.support:appcompat-v7:22.2.0"
compile 'org.osmdroid:osmdroid-android:4.3'
compile 'org.slf4j:slf4j-android:1.6.1-RC1'

compile 'io.reactivex:rxjava:1.0.11'
compile 'io.reactivex:rxandroid:0.24.0'
}
5 changes: 2 additions & 3 deletions OSMNavigator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/AppTheme">

<meta-data android:name="MAPBOX_MAPID" android:value="dennisl.map-6g3jtnzm" />

<activity android:name="com.osmnavigator.MapActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
133 changes: 92 additions & 41 deletions OSMNavigator/src/main/java/com/osmnavigator/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
import android.widget.TextView;
import android.widget.Toast;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import rx.subscriptions.Subscriptions;

/**
* Simple and general-purpose map/navigation Android application, including a KML viewer and editor.
* It is based on osmdroid and OSMBonusPack
Expand Down Expand Up @@ -148,6 +156,8 @@ public class MapActivity extends Activity implements MapEventsReceiver, Location
static String PREF_LOCATIONS_KEY = "PREF_LOCATIONS";

OnlineTileSourceBase MAPBOXSATELLITELABELLED;

private Subscription addressSubscription = Subscriptions.empty();

/** IMPORTANT - these API keys and accounts have been provided EXCLUSIVELY to OSMNavigator application.
* Developers of other applications must request their own API key from the corresponding service provider. */
Expand Down Expand Up @@ -309,8 +319,7 @@ public void onClick(View view) {
setPOITagButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Hide the soft keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(poiTagText.getWindowToken(), 0);
hideKeyboard(poiTagText);
//Start search:
String feature = poiTagText.getText().toString();
if (!feature.equals(""))
Expand Down Expand Up @@ -516,11 +525,10 @@ public String getAddress(GeoPoint p){
/**
* Geocoding of the departure or destination address
*/
public void handleSearchButton(int index, int editResId){
public void handleSearchButton(final int index, int editResId){
EditText locationEdit = (EditText)findViewById(editResId);
//Hide the soft keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(locationEdit.getWindowToken(), 0);
hideKeyboard(locationEdit);

String locationAddress = locationEdit.getText().toString();

Expand All @@ -532,43 +540,86 @@ public void handleSearchButton(int index, int editResId){

Toast.makeText(this, "Searching:\n"+locationAddress, Toast.LENGTH_LONG).show();
AutoCompleteOnPreferences.storePreference(this, locationAddress, SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
GeocoderNominatim geocoder = new GeocoderNominatim(this, userAgent);
geocoder.setOptions(true); //ask for enclosing polygon (if any)
try {
BoundingBoxE6 viewbox = map.getBoundingBox();
List<Address> foundAdresses = geocoder.getFromLocationName(locationAddress, 1,
viewbox.getLatSouthE6()*1E-6, viewbox.getLonEastE6()*1E-6,
viewbox.getLatNorthE6()*1E-6, viewbox.getLonWestE6()*1E-6, false);
if (foundAdresses.size() == 0) { //if no address found, display an error
Toast.makeText(this, "Address not found.", Toast.LENGTH_SHORT).show();
} else {
Address address = foundAdresses.get(0); //get first address
String addressDisplayName = address.getExtras().getString("display_name");
if (index == START_INDEX){
startPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerStart = updateItineraryMarker(markerStart, startPoint, START_INDEX,
R.string.departure, R.drawable.marker_departure, -1, addressDisplayName);
map.getController().setCenter(startPoint);
} else if (index == DEST_INDEX){
destinationPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerDestination = updateItineraryMarker(markerDestination, destinationPoint, DEST_INDEX,
R.string.destination, R.drawable.marker_destination, -1, addressDisplayName);
map.getController().setCenter(destinationPoint);
}
getRoadAsync();
//get and display enclosing polygon:
Bundle extras = address.getExtras();
if (extras != null && extras.containsKey("polygonpoints")){
ArrayList<GeoPoint> polygon = extras.getParcelableArrayList("polygonpoints");
//Log.d("DEBUG", "polygon:"+polygon.size());
updateUIWithPolygon(polygon, addressDisplayName);
} else {
updateUIWithPolygon(null, "");

addressSubscription = getAddressesForLocation(locationAddress)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Address>>() {
@Override
public void call(List<Address> foundAdresses) {
onGeocodingSuccess(foundAdresses, index);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Toast.makeText(MapActivity.this, "Geocoding error", Toast.LENGTH_SHORT).show();
}
});

}

private void hideKeyboard(EditText locationEdit) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(locationEdit.getWindowToken(), 0);
}

private void onGeocodingSuccess(List<Address> foundAdresses, int index) {
if (foundAdresses.size() == 0) { //if no address found, display an error
Toast.makeText(MapActivity.this, "Address not found.", Toast.LENGTH_SHORT).show();
} else {
Address address = foundAdresses.get(0); //get first address
String addressDisplayName = address.getExtras().getString("display_name");
if (index == START_INDEX){
startPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerStart = updateItineraryMarker(markerStart, startPoint, START_INDEX,
R.string.departure, R.drawable.marker_departure, -1, addressDisplayName);
map.getController().setCenter(startPoint);
} else if (index == DEST_INDEX){
destinationPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerDestination = updateItineraryMarker(markerDestination, destinationPoint, DEST_INDEX,
R.string.destination, R.drawable.marker_destination, -1, addressDisplayName);
map.getController().setCenter(destinationPoint);
}
getRoadAsync();
//get and display enclosing polygon:
Bundle extras = address.getExtras();
if (extras != null && extras.containsKey("polygonpoints")){
ArrayList<GeoPoint> polygon = extras.getParcelableArrayList("polygonpoints");
//Log.d("DEBUG", "polygon:"+polygon.size());
updateUIWithPolygon(polygon, addressDisplayName);
} else {
updateUIWithPolygon(null, "");
}
}
}

private Observable<List<Address>> getAddressesForLocation(final String locationAddress) {
return Observable.create(
new Observable.OnSubscribe<List<Address>>() {
@Override
public void call(Subscriber<? super List<Address>> subscriber) {
GeocoderNominatim geocoder = new GeocoderNominatim(MapActivity.this, userAgent);
geocoder.setOptions(true); //ask for enclosing polygon (if any)

BoundingBoxE6 viewbox = map.getBoundingBox();
List<Address> addressList = null;
try {
addressList = geocoder.getFromLocationName(locationAddress, 1,
viewbox.getLatSouthE6() * 1E-6, viewbox.getLonEastE6() * 1E-6,
viewbox.getLatNorthE6() * 1E-6, viewbox.getLonWestE6() * 1E-6, false);
} catch (IOException e) {
subscriber.onError(e);
}

if (addressList == null) {
return;
}
subscriber.onNext(addressList);
subscriber.onCompleted();

}
}
}
} catch (Exception e) {
Toast.makeText(this, "Geocoding error", Toast.LENGTH_SHORT).show();
}
);
}

//add or replace the polygon overlay
Expand Down
6 changes: 6 additions & 0 deletions OSMNavigator/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#E91E63</color>
<color name="primary_dark">#C2185B</color>
<color name="accent">#03A9F4</color>
</resources>
8 changes: 8 additions & 0 deletions OSMNavigator/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
</resources>