</intent-filter>
</activity>
+ <activity
+ android:name=".WeatherInformationSpecificDataActivity"
+ android:parentActivityName="de.example.exampletdd.WeatherInformationActivity">
+ <intent-filter >
+ <action android:name="android.intent.action.WEATHERINFORMATIONSPECIFICDATA" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value=""/>
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
import java.io.StreamCorruptedException;
import android.app.ActionBar;
import de.example.exampletdd.activityinterface.GetWeather;
import de.example.exampletdd.fragment.overview.WeatherInformationOverviewFragment;
import de.example.exampletdd.model.GeocodingData;
+import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationActivity extends Activity {
- private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
private static final String TAG = "WeatherInformationActivity";
private GetWeather mGetWeather;
+ private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
protected void onCreate(final Bundle savedInstanceState) {
// this.getFragmentManager().beginTransaction()
// .add(R.id.container, weatherDataFragment).commit();
// }
- final WeatherInformationOverviewFragment weatherDataFragment = (WeatherInformationOverviewFragment) this
+ final WeatherInformationOverviewFragment weatherOverviewFragment = (WeatherInformationOverviewFragment) this
.getFragmentManager().findFragmentById(R.id.weather_overview_fragment);
- this.mGetWeather = weatherDataFragment;
+ this.mGetWeather = weatherOverviewFragment;
+
+ this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(
+ this);
}
@Override
GeocodingData geocodingData = null;
try {
- geocodingData = this.restoreGeocodingDataFromFile();
+ geocodingData = this.mWeatherServicePersistenceFile
+ .getGeocodingData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onCreate exception: ", e);
} catch (final FileNotFoundException e) {
public void getWeather() {
this.mGetWeather.getWeather();
}
-
- private GeocodingData restoreGeocodingDataFromFile()
- throws StreamCorruptedException, FileNotFoundException,
- IOException, ClassNotFoundException {
- final InputStream persistenceFile = this.openFileInput(
- WEATHER_GEOCODING_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (GeocodingData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
}
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.StreamCorruptedException;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
import android.app.DialogFragment;
-import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import de.example.exampletdd.fragment.ErrorDialogFragment;
import de.example.exampletdd.fragment.ProgressDialogFragment;
import de.example.exampletdd.model.GeocodingData;
+import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationMapActivity extends Activity {
- private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
private static final String TAG = "WeatherInformationMapActivity";
private GoogleMap mMap;
private Marker mMarker;
+ private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
protected void onCreate(final Bundle savedInstanceState) {
this.mMap.getUiSettings().setCompassEnabled(false);
this.mMap.setOnMapLongClickListener(new LongClickListener());
+ this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
+
GeocodingData geocodingData = null;
try {
- geocodingData = this.restoreGeocodingDataFromFile();
+ geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
}
}
- private void storeGeocodingDataToFile(final GeocodingData geocodingData)
- throws FileNotFoundException, IOException {
- final OutputStream persistenceFile = this.openFileOutput(
- WEATHER_GEOCODING_FILE, Context.MODE_PRIVATE);
-
- ObjectOutputStream oos = null;
- try {
- oos = new ObjectOutputStream(persistenceFile);
-
- oos.writeObject(geocodingData);
- } finally {
- if (oos != null) {
- oos.close();
- }
- }
- }
-
- private GeocodingData restoreGeocodingDataFromFile()
- throws StreamCorruptedException, FileNotFoundException,
- IOException, ClassNotFoundException {
- final InputStream persistenceFile = this
- .openFileInput(WEATHER_GEOCODING_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (GeocodingData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
-
private class LongClickListener implements OnMapLongClickListener {
@Override
private void onPostExecuteThrowable(final GeocodingData geocodingData)
throws FileNotFoundException, IOException {
- WeatherInformationMapActivity.this.storeGeocodingDataToFile(geocodingData);
+ WeatherInformationMapActivity.this.mWeatherServicePersistenceFile
+ .storeGeocodingData(geocodingData);
final String city = (geocodingData.getCity() == null) ?
WeatherInformationMapActivity.this.getString(R.string.city_not_found)
: geocodingData.getCity();
- final String country = (geocodingData.getCountry() == null) ?
- WeatherInformationMapActivity.this.getString(R.string.country_not_found)
- : geocodingData.getCountry();
- final TextView cityCountry = (TextView) WeatherInformationMapActivity.this
+ final String country = (geocodingData.getCountry() == null) ?
+ WeatherInformationMapActivity.this.getString(R.string.country_not_found)
+ : geocodingData.getCountry();
+ final TextView cityCountry = (TextView) WeatherInformationMapActivity.this
.findViewById(R.id.weather_map_citycountry_data);
- cityCountry.setText(city + "," + country);
+ cityCountry.setText(city + "," + country);
- final LatLng point = new LatLng(geocodingData.getLatitude(), geocodingData.getLongitude());
- if (WeatherInformationMapActivity.this.mMarker == null) {
- WeatherInformationMapActivity.this.mMarker =
- WeatherInformationMapActivity.this.mMap.addMarker
+ 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));
- } else {
- WeatherInformationMapActivity.this.mMarker.setPosition(point);
- }
+ } else {
+ WeatherInformationMapActivity.this.mMarker.setPosition(point);
+ }
}
private GeocodingData getGeocodingData(final double latitude, final double longitude) throws IOException {
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
import java.io.StreamCorruptedException;
import android.app.ActionBar;
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 WEATHER_GEOCODING_FILE = "weathergeocoding.file";
private static final String TAG = "WeatherInformationSpecificDataActivity";
+ private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
protected void onCreate(final Bundle savedInstanceState) {
.add(R.id.container, fragment).commit();
}
+ this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
}
@Override
GeocodingData geocodingData = null;
try {
- geocodingData = this.restoreGeocodingDataFromFile();
+ geocodingData = this.mWeatherServicePersistenceFile
+ .getGeocodingData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onCreate exception: ", e);
} catch (final FileNotFoundException e) {
}
}
-
- private GeocodingData restoreGeocodingDataFromFile()
- throws StreamCorruptedException, FileNotFoundException,
- IOException, ClassNotFoundException {
- final InputStream persistenceFile = this.openFileInput(
- WEATHER_GEOCODING_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (GeocodingData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
}
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.StreamCorruptedException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import android.app.DialogFragment;
import android.app.ListFragment;
import android.content.ComponentName;
-import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import de.example.exampletdd.parser.IJPOSWeatherParser;
import de.example.exampletdd.parser.JPOSWeatherParser;
import de.example.exampletdd.service.WeatherService;
+import de.example.exampletdd.service.WeatherServicePersistenceFile;
-public class WeatherInformationOverviewFragment extends ListFragment implements
-GetWeather {
- private static final String WEATHER_DATA_FILE = "weatherdata.file";
- private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
+public class WeatherInformationOverviewFragment extends ListFragment implements GetWeather {
private static final String TAG = "WeatherInformationOverviewFragment";
private boolean mIsFahrenheit;
private String mLanguage;
+ private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- this.getActivity().deleteFile(WEATHER_DATA_FILE);
-
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this.getActivity());
final String keyPreference = this.getResources().getString(
R.string.weather_preferences_language_key);
this.mLanguage = sharedPreferences.getString(
keyPreference, "");
+
+ this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(
+ this.getActivity());
+ this.mWeatherServicePersistenceFile.removeWeatherData();
}
@Override
final WeatherData weatherData = (WeatherData) savedInstanceState
.getSerializable("weatherData");
try {
- this.storeWeatherDataToFile(weatherData);
+ this.mWeatherServicePersistenceFile
+ .storeWeatherData(weatherData);
} catch (final IOException e) {
final DialogFragment newFragment = ErrorDialogFragment
.newInstance(R.string.error_dialog_generic_error);
@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
- final WeatherInformationSpecificDataFragment fragment = (WeatherInformationSpecificDataFragment) getFragmentManager()
+ final WeatherInformationSpecificDataFragment fragment = (WeatherInformationSpecificDataFragment) this.getFragmentManager()
.findFragmentById(R.id.weather_specific_data__fragment);
if (fragment == null) {
// handset layout
final Intent intent = new Intent("de.example.exampletdd.WEATHERINFO").
setComponent(new ComponentName("de.example.exampletdd",
- "de.example.exampletdd.specific.WeatherInformationSpecificDataActivity"));
+ "de.example.exampletdd.WeatherInformationSpecificDataActivity"));
WeatherInformationOverviewFragment.this.getActivity().startActivity(intent);
} else {
// tablet layout
// Save state
WeatherData weatherData = null;
try {
- weatherData = this.restoreWeatherDataFromFile();
+ weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
GeocodingData geocodingData = null;
try {
- geocodingData = this.restoreGeocodingDataFromFile();
+ geocodingData = this.mWeatherServicePersistenceFile
+ .getGeocodingData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
// 2. Update current data on display.
WeatherData weatherData = null;
try {
- weatherData = this.restoreWeatherDataFromFile();
+ weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
private void onPostExecuteThrowable(final WeatherData weatherData)
throws FileNotFoundException, IOException {
- WeatherInformationOverviewFragment.this.storeWeatherDataToFile(weatherData);
+ WeatherInformationOverviewFragment.this.mWeatherServicePersistenceFile
+ .storeWeatherData(weatherData);
WeatherInformationOverviewFragment.this.updateWeatherData(weatherData);
}
return entries;
}
-
- private void storeWeatherDataToFile(final WeatherData weatherData)
- throws FileNotFoundException, IOException {
- final OutputStream persistenceFile = this.getActivity().openFileOutput(
- WEATHER_DATA_FILE, Context.MODE_PRIVATE);
-
- ObjectOutputStream oos = null;
- try {
- oos = new ObjectOutputStream(persistenceFile);
-
- oos.writeObject(weatherData);
- } finally {
- if (oos != null) {
- oos.close();
- }
- }
- }
-
- private WeatherData restoreWeatherDataFromFile() throws StreamCorruptedException,
- FileNotFoundException, IOException, ClassNotFoundException {
- final InputStream persistenceFile = this.getActivity().openFileInput(
- WEATHER_DATA_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (WeatherData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
-
- private GeocodingData restoreGeocodingDataFromFile()
- throws StreamCorruptedException, FileNotFoundException,
- IOException, ClassNotFoundException {
- final InputStream persistenceFile = this.getActivity()
- .openFileInput(WEATHER_GEOCODING_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (GeocodingData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
}
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.StreamCorruptedException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.DialogFragment;
import android.app.Fragment;
-import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import de.example.exampletdd.activityinterface.GetWeather;
import de.example.exampletdd.fragment.ErrorDialogFragment;
import de.example.exampletdd.model.WeatherData;
+import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationSpecificDataFragment extends Fragment implements GetWeather {
- private static final String WEATHER_DATA_FILE = "weatherdata.file";
private static final String TAG = "WeatherInformationDataFragment";
private boolean mIsFahrenheit;
private String mLanguage;
+ private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- this.getActivity().deleteFile(WEATHER_DATA_FILE);
+ this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(
+ this.getActivity());
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this.getActivity());
final WeatherData weatherData = (WeatherData) savedInstanceState
.getSerializable("weatherData");
try {
- this.storeWeatherDataToFile(weatherData);
+ this.mWeatherServicePersistenceFile.storeWeatherData(weatherData);
} catch (final IOException e) {
final DialogFragment newFragment = ErrorDialogFragment
.newInstance(R.string.error_dialog_generic_error);
// Save state
WeatherData weatherData = null;
try {
- weatherData = this.restoreWeatherDataFromFile();
+ weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
public void getWeather() {
WeatherData weatherData = null;
try {
- weatherData = this.restoreWeatherDataFromFile();
+ weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
// 2. Update current data on display.
WeatherData weatherData = null;
try {
- weatherData = this.restoreWeatherDataFromFile();
+ weatherData = this.mWeatherServicePersistenceFile.getWeatherData();
} catch (final StreamCorruptedException e) {
Log.e(TAG, "onResume exception: ", e);
} catch (final FileNotFoundException e) {
return entries;
}
-
- private void storeWeatherDataToFile(final WeatherData weatherData)
- throws FileNotFoundException, IOException {
- final OutputStream persistenceFile = this.getActivity().openFileOutput(
- WEATHER_DATA_FILE, Context.MODE_PRIVATE);
-
- ObjectOutputStream oos = null;
- try {
- oos = new ObjectOutputStream(persistenceFile);
-
- oos.writeObject(weatherData);
- } finally {
- if (oos != null) {
- oos.close();
- }
- }
- }
-
- private WeatherData restoreWeatherDataFromFile() throws StreamCorruptedException,
- FileNotFoundException, IOException, ClassNotFoundException {
- final InputStream persistenceFile = this.getActivity().openFileInput(
- WEATHER_DATA_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (WeatherData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
}
+++ /dev/null
-package de.example.exampletdd.service;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.StreamCorruptedException;
-
-import android.content.Context;
-import de.example.exampletdd.model.GeocodingData;
-import de.example.exampletdd.model.WeatherData;
-
-public class WeatherServicePersistence {
- private static final String WEATHER_DATA_FILE = "weatherdata.file";
- private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
- private final Context context;
-
- public WeatherServicePersistence(final Context context) {
- this.context = context;
- }
-
- public void storeGeocodingDataToFile(final GeocodingData geocodingData)
- throws FileNotFoundException, IOException {
- final OutputStream persistenceFile = context.openFileOutput(
- WEATHER_GEOCODING_FILE, Context.MODE_PRIVATE);
-
- ObjectOutputStream oos = null;
- try {
- oos = new ObjectOutputStream(persistenceFile);
-
- oos.writeObject(geocodingData);
- } finally {
- if (oos != null) {
- oos.close();
- }
- }
- }
-
- public GeocodingData restoreGeocodingDataFromFile()
- throws StreamCorruptedException, FileNotFoundException,
- IOException, ClassNotFoundException {
- final InputStream persistenceFile = context.openFileInput(
- WEATHER_GEOCODING_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (GeocodingData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
-
- public void storeWeatherDataToFile(final WeatherData weatherData)
- throws FileNotFoundException, IOException {
- final OutputStream persistenceFile = context.openFileOutput(
- WEATHER_DATA_FILE, Context.MODE_PRIVATE);
-
- ObjectOutputStream oos = null;
- try {
- oos = new ObjectOutputStream(persistenceFile);
-
- oos.writeObject(weatherData);
- } finally {
- if (oos != null) {
- oos.close();
- }
- }
- }
-
- public WeatherData restoreWeatherDataFromFile()
- throws StreamCorruptedException,
- FileNotFoundException, IOException, ClassNotFoundException {
- final InputStream persistenceFile = context.openFileInput(
- WEATHER_DATA_FILE);
-
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(persistenceFile);
-
- return (WeatherData) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
- }
- }
-}
--- /dev/null
+package de.example.exampletdd.service;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.StreamCorruptedException;
+
+import android.content.Context;
+import de.example.exampletdd.model.GeocodingData;
+import de.example.exampletdd.model.WeatherData;
+
+public class WeatherServicePersistenceFile {
+ private static final String WEATHER_DATA_FILE = "weatherdata.file";
+ private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
+ private final Context context;
+
+ public WeatherServicePersistenceFile(final Context context) {
+ this.context = context;
+ }
+
+ public void storeGeocodingData(final GeocodingData geocodingData)
+ throws FileNotFoundException, IOException {
+ final OutputStream persistenceFile = this.context.openFileOutput(
+ WEATHER_GEOCODING_FILE, Context.MODE_PRIVATE);
+
+ ObjectOutputStream oos = null;
+ try {
+ oos = new ObjectOutputStream(persistenceFile);
+
+ oos.writeObject(geocodingData);
+ } finally {
+ if (oos != null) {
+ oos.close();
+ }
+ }
+ }
+
+ public GeocodingData getGeocodingData()
+ throws StreamCorruptedException, FileNotFoundException,
+ IOException, ClassNotFoundException {
+ final InputStream persistenceFile = this.context.openFileInput(
+ WEATHER_GEOCODING_FILE);
+
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream(persistenceFile);
+
+ return (GeocodingData) ois.readObject();
+ } finally {
+ if (ois != null) {
+ ois.close();
+ }
+ }
+ }
+
+ public void removeGeocodingData() {
+ this.context.deleteFile(WEATHER_GEOCODING_FILE);
+ }
+
+ public void storeWeatherData(final WeatherData weatherData)
+ throws FileNotFoundException, IOException {
+ final OutputStream persistenceFile = this.context.openFileOutput(
+ WEATHER_DATA_FILE, Context.MODE_PRIVATE);
+
+ ObjectOutputStream oos = null;
+ try {
+ oos = new ObjectOutputStream(persistenceFile);
+
+ oos.writeObject(weatherData);
+ } finally {
+ if (oos != null) {
+ oos.close();
+ }
+ }
+ }
+
+ public WeatherData getWeatherData()
+ throws StreamCorruptedException,
+ FileNotFoundException, IOException, ClassNotFoundException {
+ final InputStream persistenceFile = this.context.openFileInput(
+ WEATHER_DATA_FILE);
+
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream(persistenceFile);
+
+ return (WeatherData) ois.readObject();
+ } finally {
+ if (ois != null) {
+ ois.close();
+ }
+ }
+ }
+
+ public void removeWeatherData() {
+ this.context.deleteFile(WEATHER_DATA_FILE);
+ }
+}