package de.example.exampletdd;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.StreamCorruptedException;
-
import android.app.ActionBar;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import de.example.exampletdd.activityinterface.GetWeather;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationActivity extends Activity {
- private static final String TAG = "WeatherInformationActivity";
private GetWeather mGetWeather;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
final ActionBar actionBar = this.getActionBar();
- GeocodingData geocodingData = null;
- try {
- geocodingData = this.mWeatherServicePersistenceFile
- .getGeocodingData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onCreate exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onCreate exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onCreate exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onCreate exception: ", e);
- }
+ final GeocodingData geocodingData =
+ this.mWeatherServicePersistenceFile.getGeocodingData();
+
if (geocodingData != null) {
final String city = (geocodingData.getCity() == null) ? this.getString(R.string.city_not_found)
: geocodingData.getCity();
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.StreamCorruptedException;
import java.util.List;
import java.util.Locale;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationMapActivity extends Activity {
- private static final String TAG = "WeatherInformationMapActivity";
private GoogleMap mMap;
private Marker mMarker;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
- GeocodingData geocodingData = null;
- try {
- geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
if (geocodingData != null) {
final LatLng point = new LatLng(
throws FileNotFoundException, IOException {
WeatherInformationMapActivity.this.mWeatherServicePersistenceFile
- .storeGeocodingData(geocodingData);
+ .storeGeocodingData(geocodingData);
final String city = (geocodingData.getCity() == null) ?
WeatherInformationMapActivity.this.getString(R.string.city_not_found)
final LatLng point = new LatLng(geocodingData.getLatitude(), geocodingData.getLongitude());
if (WeatherInformationMapActivity.this.mMarker == null) {
WeatherInformationMapActivity.this.mMarker = WeatherInformationMapActivity.this.mMap.addMarker
- (new MarkerOptions().position(point).draggable(true));
+ (new MarkerOptions().position(point).draggable(true));
} else {
WeatherInformationMapActivity.this.mMarker.setPosition(point);
}
package de.example.exampletdd;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.StreamCorruptedException;
-
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.util.Log;
import de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment;
import de.example.exampletdd.model.GeocodingData;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationSpecificDataActivity extends Activity {
- private static final String TAG = "WeatherInformationSpecificDataActivity";
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
final ActionBar actionBar = this.getActionBar();
- GeocodingData geocodingData = null;
- try {
- geocodingData = this.mWeatherServicePersistenceFile
- .getGeocodingData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onCreate exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onCreate exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onCreate exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onCreate exception: ", e);
- }
+ final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
+
if (geocodingData != null) {
final String city = (geocodingData.getCity() == null) ? this.getString(R.string.city_not_found)
: geocodingData.getCity();
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.StreamCorruptedException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationOverviewFragment extends ListFragment implements GetWeather {
- private static final String TAG = "WeatherInformationOverviewFragment";
private boolean mIsFahrenheit;
private String mLanguage;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
public void onSaveInstanceState(final Bundle savedInstanceState) {
// Save state
- WeatherData weatherData = null;
- try {
- weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final WeatherData weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
if (weatherData != null) {
savedInstanceState.putSerializable("weatherData", weatherData);
@Override
public void getWeather() {
- GeocodingData geocodingData = null;
- try {
- geocodingData = this.mWeatherServicePersistenceFile
- .getGeocodingData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
if (geocodingData != null) {
final IJPOSWeatherParser JPOSWeatherParser = new JPOSWeatherParser();
// 2. Update current data on display.
- WeatherData weatherData = null;
- try {
- weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final WeatherData weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
+
if (weatherData != null) {
this.updateWeatherData(weatherData);
}
private void onPostExecuteThrowable(final WeatherData weatherData)
throws FileNotFoundException, IOException {
WeatherInformationOverviewFragment.this.mWeatherServicePersistenceFile
- .storeWeatherData(weatherData);
+ .storeWeatherData(weatherData);
WeatherInformationOverviewFragment.this.updateWeatherData(weatherData);
}
package de.example.exampletdd.fragment.specific;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.StreamCorruptedException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationSpecificDataFragment extends Fragment implements GetWeather {
- private static final String TAG = "WeatherInformationDataFragment";
private boolean mIsFahrenheit;
private String mLanguage;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
public void onSaveInstanceState(final Bundle savedInstanceState) {
// Save state
- WeatherData weatherData = null;
- try {
- weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final WeatherData weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
+
if (weatherData != null) {
savedInstanceState.putSerializable("weatherData", weatherData);
@Override
public void getWeather() {
- WeatherData weatherData = null;
- try {
- weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final WeatherData weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
+
if (weatherData != null) {
this.updateWeatherData(weatherData);
}
// 2. Update current data on display.
- WeatherData weatherData = null;
- try {
- weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
- } catch (final StreamCorruptedException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final FileNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final IOException e) {
- Log.e(TAG, "onResume exception: ", e);
- } catch (final ClassNotFoundException e) {
- Log.e(TAG, "onResume exception: ", e);
- }
+ final WeatherData weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
+
if (weatherData != null) {
this.updateWeatherData(weatherData);
}
}
private GeocodingData(final Builder builder) {
- super();
this.city = builder.mCity;
this.country = builder.mCountry;
this.latitude = builder.mLatitude;
package de.example.exampletdd.model;
import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Date;
public class WeatherData implements Serializable {
- private static final long serialVersionUID = -9174787242150282821L;
+ private static final long serialVersionUID = -3521472950666173278L;
private final Main main;
private final Wind wind;
private final Rain rain;
private final Clouds clouds;
private final Weather weather;
private byte[] iconData;
+ private final Date date;
public static class Builder {
private System mSystem;
private Clouds mClouds;
private Weather mWeather;
+ private Date mDate;
public Builder setMain(final Main main) {
return this;
}
+ public Builder setDate(final Date date) {
+ this.mDate = date;
+ return this;
+ }
+
public WeatherData build() {
return new WeatherData(this);
}
this.system = builder.mSystem;
this.clouds = builder.mClouds;
this.weather = builder.mWeather;
+ this.date = builder.mDate;
}
@Override
public String toString() {
- final StringBuilder builder2 = new StringBuilder();
- builder2.append("WeatherData [main=").append(this.main)
- .append(", wind=").append(this.wind).append(", rain=")
- .append(this.rain).append(", coord=").append(this.coord)
- .append(", dataReceivingTime=").append(this.dataReceivingTime)
- .append(", stationName=").append(this.stationName)
- .append(", system=").append(this.system).append(", clouds=")
- .append(this.clouds).append(", weather=").append(this.weather)
- .append("]");
- return builder2.toString();
+ final StringBuilder builder = new StringBuilder();
+ builder.append("WeatherData [main=").append(main)
+ .append(", wind=").append(wind).append(", rain=").append(rain)
+ .append(", coord=").append(coord).append(", dataReceivingTime=")
+ .append(dataReceivingTime).append(", stationName=").append(stationName)
+ .append(", system=").append(system).append(", clouds=")
+ .append(clouds).append(", weather=").append(weather)
+ .append(", iconData=").append(Arrays.toString(iconData))
+ .append(", date=").append(date).append("]");
+ return builder.toString();
}
public Main getMain() {
return this.iconData;
}
+ public Date getDate() {
+ return this.date;
+ }
+
public static class Main implements Serializable {
private static final long serialVersionUID = -1632181871917583409L;
private final double temp;
import java.io.StreamCorruptedException;
import android.content.Context;
+import android.util.Log;
import de.example.exampletdd.model.GeocodingData;
import de.example.exampletdd.model.WeatherData;
public class WeatherServicePersistenceFile {
+ private static final String TAG = "WeatherServicePersistenceFile";
private static final String WEATHER_DATA_FILE = "weatherdata.file";
private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
private final Context context;
}
}
- public GeocodingData getGeocodingData()
+ public GeocodingData getGeocodingData() {
+ GeocodingData geocodingData = null;
+
+ try {
+ geocodingData = this.getGeocodingDataThrowable();
+ } catch (final StreamCorruptedException e) {
+ Log.e(TAG, "getGeocodingData exception: ", e);
+ } catch (final FileNotFoundException e) {
+ Log.e(TAG, "getGeocodingData exception: ", e);
+ } catch (final IOException e) {
+ Log.e(TAG, "getGeocodingData exception: ", e);
+ } catch (final ClassNotFoundException e) {
+ Log.e(TAG, "getGeocodingData exception: ", e);
+ }
+
+ return geocodingData;
+ }
+
+ private GeocodingData getGeocodingDataThrowable()
throws StreamCorruptedException, FileNotFoundException,
IOException, ClassNotFoundException {
final InputStream persistenceFile = this.context.openFileInput(
}
}
- public WeatherData getWeatherData()
+ public WeatherData getWeatherData() {
+ WeatherData weatherData = null;
+
+ try {
+ weatherData = getWeatherDataThrowable();
+ } catch (final StreamCorruptedException e) {
+ Log.e(TAG, "getWeatherData exception: ", e);
+ } catch (final FileNotFoundException e) {
+ Log.e(TAG, "getWeatherData exception: ", e);
+ } catch (final IOException e) {
+ Log.e(TAG, "getWeatherData exception: ", e);
+ } catch (final ClassNotFoundException e) {
+ Log.e(TAG, "getWeatherData exception: ", e);
+ }
+
+ return weatherData;
+ }
+
+ private WeatherData getWeatherDataThrowable()
throws StreamCorruptedException,
FileNotFoundException, IOException, ClassNotFoundException {
final InputStream persistenceFile = this.context.openFileInput(