diff --git a/MapsForgeForOsmdroid/build.gradle b/MapsForgeForOsmdroid/build.gradle index 46d989fe..ade5afad 100644 --- a/MapsForgeForOsmdroid/build.gradle +++ b/MapsForgeForOsmdroid/build.gradle @@ -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" } diff --git a/OSMBonusPack/build.gradle b/OSMBonusPack/build.gradle index d146bfc2..edf43a99 100644 --- a/OSMBonusPack/build.gradle +++ b/OSMBonusPack/build.gradle @@ -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" } diff --git a/OSMBonusPackTuto/build.gradle b/OSMBonusPackTuto/build.gradle index 3bb1d0ff..e76de4ae 100644 --- a/OSMBonusPackTuto/build.gradle +++ b/OSMBonusPackTuto/build.gradle @@ -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" } @@ -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' } diff --git a/OSMBonusPackTuto/src/main/AndroidManifest.xml b/OSMBonusPackTuto/src/main/AndroidManifest.xml index 3e4ff3c4..043361b8 100644 --- a/OSMBonusPackTuto/src/main/AndroidManifest.xml +++ b/OSMBonusPackTuto/src/main/AndroidManifest.xml @@ -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" > diff --git a/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java b/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java index aa5bcdf5..79f89e7b 100644 --- a/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java +++ b/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java @@ -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; @@ -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); diff --git a/OSMBonusPackTuto/src/main/res/layout/main.xml b/OSMBonusPackTuto/src/main/res/layout/main.xml index 3c9b441b..b78c8209 100644 --- a/OSMBonusPackTuto/src/main/res/layout/main.xml +++ b/OSMBonusPackTuto/src/main/res/layout/main.xml @@ -4,9 +4,19 @@ android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> - + + + - + android:layout_width="fill_parent" + android:layout_height="fill_parent" + /> + + diff --git a/OSMBonusPackTuto/src/main/res/values/colors.xml b/OSMBonusPackTuto/src/main/res/values/colors.xml new file mode 100644 index 00000000..429a3b19 --- /dev/null +++ b/OSMBonusPackTuto/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #E91E63 + #C2185B + #03A9F4 + \ No newline at end of file diff --git a/OSMBonusPackTuto/src/main/res/values/styles.xml b/OSMBonusPackTuto/src/main/res/values/styles.xml new file mode 100644 index 00000000..d261b015 --- /dev/null +++ b/OSMBonusPackTuto/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/OSMNavigator/build.gradle b/OSMNavigator/build.gradle index 70df6957..f55b83d9 100644 --- a/OSMNavigator/build.gradle +++ b/OSMNavigator/build.gradle @@ -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" } @@ -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' } diff --git a/OSMNavigator/src/main/AndroidManifest.xml b/OSMNavigator/src/main/AndroidManifest.xml index 0d98646b..5bb06a18 100644 --- a/OSMNavigator/src/main/AndroidManifest.xml +++ b/OSMNavigator/src/main/AndroidManifest.xml @@ -8,13 +8,12 @@ - + + android:label="@string/app_name"> diff --git a/OSMNavigator/src/main/java/com/osmnavigator/MapActivity.java b/OSMNavigator/src/main/java/com/osmnavigator/MapActivity.java index d2664a9e..6af30e35 100644 --- a/OSMNavigator/src/main/java/com/osmnavigator/MapActivity.java +++ b/OSMNavigator/src/main/java/com/osmnavigator/MapActivity.java @@ -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 @@ -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. */ @@ -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("")) @@ -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(); @@ -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
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 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>() { + @Override + public void call(List
foundAdresses) { + onGeocodingSuccess(foundAdresses, index); + } + }, new Action1() { + @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
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 polygon = extras.getParcelableArrayList("polygonpoints"); + //Log.d("DEBUG", "polygon:"+polygon.size()); + updateUIWithPolygon(polygon, addressDisplayName); + } else { + updateUIWithPolygon(null, ""); + } + } + } + + private Observable> getAddressesForLocation(final String locationAddress) { + return Observable.create( + new Observable.OnSubscribe>() { + @Override + public void call(Subscriber> subscriber) { + GeocoderNominatim geocoder = new GeocoderNominatim(MapActivity.this, userAgent); + geocoder.setOptions(true); //ask for enclosing polygon (if any) + + BoundingBoxE6 viewbox = map.getBoundingBox(); + List
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 diff --git a/OSMNavigator/src/main/res/values/colors.xml b/OSMNavigator/src/main/res/values/colors.xml new file mode 100644 index 00000000..429a3b19 --- /dev/null +++ b/OSMNavigator/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #E91E63 + #C2185B + #03A9F4 + \ No newline at end of file diff --git a/OSMNavigator/src/main/res/values/styles.xml b/OSMNavigator/src/main/res/values/styles.xml new file mode 100644 index 00000000..d261b015 --- /dev/null +++ b/OSMNavigator/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file