diff --git a/app/app.iml b/app/app.iml
index 1b5c13c..5a04741 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -74,6 +74,8 @@
+
+
@@ -91,14 +93,18 @@
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 550cba8..41ca929 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -29,4 +29,7 @@
compile files('libs/mapsforge-map-reader-release-0.5.2.jar')
compile files('libs/mapsforge-map-release-0.5.2.jar')
compile files('libs/androidsvg-1.2.1.jar')
+ compile 'com.survivingwithandroid:weatherlib:1.5.8'
+ compile 'com.survivingwithandroid:weatherlib_okhttpclient:1.5.8'
+ compile 'com.squareup.okhttp:okhttp:2.0.+'
}
diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java
index e26e625..7eefbeb 100644
--- a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java
+++ b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java
@@ -40,6 +40,14 @@
import android.widget.TextView;
import android.widget.Toast;
+import com.survivingwithandroid.weather.lib.WeatherClient;
+import com.survivingwithandroid.weather.lib.WeatherConfig;
+import com.survivingwithandroid.weather.lib.exception.WeatherLibException;
+import com.survivingwithandroid.weather.lib.exception.WeatherProviderInstantiationException;
+import com.survivingwithandroid.weather.lib.model.CurrentWeather;
+import com.survivingwithandroid.weather.lib.provider.openweathermap.OpenweathermapProviderType;
+import com.survivingwithandroid.weather.lib.request.WeatherRequest;
+
import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.android.util.AndroidUtil;
@@ -75,6 +83,8 @@
private FloatingActionButton fab;
+ private WeatherClient weatherClient;
+
private MapView mapView;
private TileCache tileCache;
private TileRendererLayer tileRendererLayer;
@@ -136,10 +146,43 @@
R.drawable.lift
};
+ WeatherClient.ClientBuilder weatherBuilder = new WeatherClient.ClientBuilder();
+ WeatherConfig weatherConfig = new WeatherConfig();
+ weatherConfig.unitSystem = WeatherConfig.UNIT_SYSTEM.M;
+
+ weatherClient = null;
+ try {
+ weatherClient = weatherBuilder.attach(getApplicationContext())
+ .provider(new OpenweathermapProviderType())
+ .httpClient(com.survivingwithandroid.weather.lib.client.okhttp.WeatherDefaultClient.class)
+ .config(weatherConfig)
+ .build();
+ } catch (WeatherProviderInstantiationException e) {
+ e.printStackTrace();
+ }
+
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
+ weatherClient.getCurrentCondition(new WeatherRequest(23.7277, 37.9777), new WeatherClient.WeatherEventListener() {
+ @Override
+ public void onWeatherRetrieved(CurrentWeather weather) {
+ Log.d(TAG, "City [" + weather.weather.location.getCity() + "] Current temp: " + weather.weather.temperature.getTemp());
+ }
+
+ @Override
+ public void onWeatherError(WeatherLibException wle) {
+ Log.e(TAG, "Weather error - parsing data");
+ wle.printStackTrace();
+ }
+
+ @Override
+ public void onConnectionError(Throwable t) {
+ Log.e(TAG, "Connection Error");
+ t.printStackTrace();
+ }
+ });
//TODO check if gps position is != null, toast and return if not
AddPoiDialog addPoiDialog = new AddPoiDialog();
addPoiDialog.show(getFragmentManager(), "Add POI Dialog");