--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+</lint>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/container"
+ android:id="@+id/weather_current_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
tools:context="de.example.exampletdd.WeatherInformationCurrentDataActivity"
tools:ignore="MergeRootFrame" >
+ <ImageView
+ android:id="@+id/weather_current_picture"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@string/icon_weather_description"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_launcher" />
+
<fragment
- android:id="@+id/weather_specific_data_fragment"
+ android:id="@+id/weather_current_data_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="de.example.exampletdd.fragment.current.WeatherInformationCurrentDataFragment" />
-</FrameLayout>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/container"
+ android:id="@+id/weather_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.example.exampletdd.WeatherInformationActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
tools:context="de.example.exampletdd.WeatherInformationMapActivity" >
<TextView
- android:id="@+id/weather_map_citycountry_header"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="top"
- android:text="City,country:"
- android:textAlignment="textStart"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:textIsSelectable="false"
- android:textStyle="normal" />
-
- <TextView
android:id="@+id/weather_map_citycountry_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_below="@+id/weather_map_citycountry_header"
android:gravity="top"
android:text="City,country"
android:textAlignment="textStart"
android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textIsSelectable="false"
android:textStyle="bold|normal" />
<fragment
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/container"
+ android:id="@+id/weather_specific_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
tools:context="de.example.exampletdd.WeatherInformationSpecificDataActivity"
tools:ignore="MergeRootFrame" >
+ <ImageView
+ android:id="@+id/weather_specific_picture"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@string/icon_weather_description"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_launcher" />
+
<fragment
android:id="@+id/weather_specific_data_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment" />
-</FrameLayout>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
android:visible="true"
android:checkable="false"
android:enabled="true"
- android:icon="@drawable/ic_action_import_export"
+ android:icon="@drawable/ic_action_refresh"
android:showAsAction="ifRoom|withText">
</item>
<item
<item>Ukrainian</item>
<item>Vietnamese</item>
</string-array>
+ <string-array name="weather_preferences_day_forecast">
+ <item>5</item>
+ <item>10</item>
+ <item>14</item>
+ </string-array>
+ <string-array name="weather_preferences_day_forecast_human_value">
+ <item>5-Day Forecast</item>
+ <item>10-Day Forecast</item>
+ <item>14-Day Forecast</item>
+ </string-array>
</resources>
<string name="weather_preferences_units">Unit of measurement for temperature</string>
<string name="weather_preferences_language_key">weather_preferences_language</string>
<string name="weather_preferences_language">Language</string>
+ <string name="weather_preferences_day_forecast_key">weather_preferences_day_forecast</string>
+ <string name="weather_preferences_day_forecast">Forecast days number</string>
<string name="city_not_found">city not found</string>
<string name="country_not_found">country not found</string>
<string name="progress_dialog_get_remote_data">Downloading remote data</string>
android:persistent="true"
android:selectable="true"
android:summary="English"/>
+ <ListPreference
+ android:key="@string/weather_preferences_day_forecast_key"
+ android:title="@string/weather_preferences_day_forecast"
+ android:entries="@array/weather_preferences_day_forecast_human_value"
+ android:entryValues="@array/weather_preferences_day_forecast"
+ android:selectable="true"
+ android:persistent="true"
+ android:defaultValue="14"
+ android:summary="14-Day Forecast" />
</PreferenceScreen>
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
public class WeatherInformationActivity extends Activity {
private GetWeather mGetWeather;
- private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
protected void onCreate(final Bundle savedInstanceState) {
this.mGetWeather = weatherOverviewFragment;
- this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(
- this);
}
@Override
return true;
case R.id.weather_menu_map:
intent = new Intent("de.example.exampletdd.WEATHERINFO")
- .setComponent(new ComponentName("de.example.exampletdd",
- "de.example.exampletdd.WeatherInformationMapActivity"));
+ .setComponent(new ComponentName("de.example.exampletdd",
+ "de.example.exampletdd.WeatherInformationMapActivity"));
this.startActivity(intent);
return true;
case R.id.weather_menu_current:
final ActionBar actionBar = this.getActionBar();
- final GeocodingData geocodingData =
- this.mWeatherServicePersistenceFile.getGeocodingData();
+ final WeatherServicePersistenceFile weatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
+ final GeocodingData geocodingData = weatherServicePersistenceFile.getGeocodingData();
if (geocodingData != null) {
final String city = (geocodingData.getCity() == null) ? this.getString(R.string.city_not_found)
actionBar.setTitle(city + "," + country);
}
+
+ final SharedPreferences sharedPreferences = PreferenceManager
+ .getDefaultSharedPreferences(this);
+ final String keyPreference = this.getResources().getString(
+ R.string.weather_preferences_day_forecast_key);
+ final String value = sharedPreferences.getString(keyPreference, "");
+ String humanValue = "";
+ if (value.equals("5")) {
+ humanValue = "5-Day Forecast";
+ } else if (value.equals("10")) {
+ humanValue = "10-Day Forecast";
+ } else if (value.equals("14")) {
+ humanValue = "14-Day Forecast";
+ }
+ actionBar.setSubtitle(humanValue);
+
}
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
-import android.preference.PreferenceManager;
-import de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment;
import de.example.exampletdd.model.GeocodingData;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherInformationCurrentDataActivity extends Activity {
- private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
protected void onCreate(final Bundle savedInstanceState) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setDisplayHomeAsUpEnabled(true);
- final WeatherInformationSpecificDataFragment fragment = new WeatherInformationSpecificDataFragment();
-
- if (savedInstanceState == null) {
- this.getFragmentManager().beginTransaction().add(R.id.container, fragment).commit();
- }
-
- this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
}
@Override
actionBar.setTitle("Current weather information");
- final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
+ final WeatherServicePersistenceFile weatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
+ final GeocodingData geocodingData = weatherServicePersistenceFile.getGeocodingData();
if (geocodingData != null) {
final String city = (geocodingData.getCity() == null) ? this
import java.util.List;
import java.util.Locale;
+import android.app.ActionBar;
import android.app.Activity;
import android.app.DialogFragment;
import android.location.Address;
}
}
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ final ActionBar actionBar = this.getActionBar();
+
+ actionBar.setTitle("Mark your location");
+ }
+
private class LongClickListener implements OnMapLongClickListener {
@Override
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
-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 WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
protected void onCreate(final Bundle savedInstanceState) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setDisplayHomeAsUpEnabled(true);
- final WeatherInformationSpecificDataFragment fragment =
- new WeatherInformationSpecificDataFragment();
-
- if (savedInstanceState == null) {
- this.getFragmentManager().beginTransaction()
- .add(R.id.container, fragment).commit();
- }
-
- this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
}
@Override
final ActionBar actionBar = this.getActionBar();
- final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData();
+ final WeatherServicePersistenceFile weatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
+ final GeocodingData geocodingData = weatherServicePersistenceFile.getGeocodingData();
if (geocodingData != null) {
- final String city = (geocodingData.getCity() == null) ? this.getString(R.string.city_not_found)
- : geocodingData.getCity();
- final String country = (geocodingData.getCountry() == null) ? this.getString(R.string.country_not_found)
- : geocodingData.getCountry();
- actionBar.setTitle(city + "," + country);
- }
+ final String city = (geocodingData.getCity() == null) ? this
+ .getString(R.string.city_not_found) : geocodingData.getCity();
+ final String country = (geocodingData.getCountry() == null) ? this
+ .getString(R.string.country_not_found) : geocodingData.getCountry();
+ actionBar.setTitle("Specific weather data information");
+ actionBar.setSubtitle(city + "," + country);
+ }
}
}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.apache.http.client.ClientProtocolException;
import android.app.DialogFragment;
-import android.app.Fragment;
+import android.app.ListFragment;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
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 android.widget.ImageView;
import android.widget.ListView;
import de.example.exampletdd.service.WeatherServiceParser;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
-public class WeatherInformationCurrentDataFragment extends Fragment {
+public class WeatherInformationCurrentDataFragment extends ListFragment {
private boolean mIsFahrenheit;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
}
@Override
- public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
- final Bundle savedInstanceState) {
- final View rootView = inflater.inflate(R.layout.weather_data_list, container, false);
-
- return rootView;
- }
-
- @Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- final ListView listWeatherView = (ListView) this.getActivity().findViewById(
- R.id.weather_data_list_view);
-
- final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(
- this.getActivity(), R.layout.weather_data_entry_list);
+ final ListView listWeatherView = this.getListView();
+ listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE);
if (savedInstanceState != null) {
// Restore state
}
}
- final Collection<WeatherSpecificDataEntry> entries = this.createEmptyEntriesList();
+ this.setHasOptionsMenu(false);
- adapter.addAll(entries);
- listWeatherView.setAdapter(adapter);
+ final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(
+ this.getActivity(), R.layout.weather_data_entry_list);
+
+
+ this.setEmptyText("No data available");
+
+ this.setListAdapter(adapter);
+ this.setListShown(true);
+ this.setListShownNoAnimation(true);
}
this.updateCurrentWeatherData(currentWeatherData);
} else {
// 2.1 Empty list by default
- final List<WeatherSpecificDataEntry> entries = this.createEmptyEntriesList();
-
- final ListView listWeatherView = (ListView) this.getActivity().findViewById(
- R.id.weather_data_list_view);
-
final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(
this.getActivity(), R.layout.weather_data_entry_list);
- adapter.addAll(entries);
- listWeatherView.setAdapter(adapter);
+ this.setListAdapter(adapter);
// 2.2. Try to update weather data on display with remote
// information.
final List<WeatherSpecificDataEntry> entries = this.createEmptyEntriesList();
- final ListView listWeatherView = (ListView) this.getActivity().findViewById(
- R.id.weather_data_list_view);
-
final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(
this.getActivity(), R.layout.weather_data_entry_list);
imageIcon.setImageBitmap(icon);
}
- listWeatherView.setAdapter(null);
adapter.addAll(entries);
- listWeatherView.setAdapter(adapter);
+ this.setListAdapter(adapter);
}
public class CurrentWeatherTask extends AsyncTask<Object, Void, CurrentWeatherData> {
throws FileNotFoundException, IOException {
WeatherInformationCurrentDataFragment.this.mWeatherServicePersistenceFile
- .storeCurrentWeatherData(currentWeatherData);
+ .storeCurrentWeatherData(currentWeatherData);
WeatherInformationCurrentDataFragment.this.updateCurrentWeatherData(currentWeatherData);
}
public class WeatherInformationOverviewFragment extends ListFragment implements GetWeather {
private boolean mIsFahrenheit;
+ private String mDayForecast;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // final SharedPreferences sharedPreferences = PreferenceManager
- // .getDefaultSharedPreferences(this.getActivity());
- // final String keyPreference = this.getResources().getString(
- // R.string.weather_preferences_language_key);
- // this.mLanguage = sharedPreferences.getString(
- // keyPreference, "");
+ final SharedPreferences sharedPreferences = PreferenceManager
+ .getDefaultSharedPreferences(this.getActivity());
+ final String keyPreference = this.getResources().getString(
+ R.string.weather_preferences_day_forecast_key);
+ this.mDayForecast = sharedPreferences.getString(keyPreference, "");
this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this.getActivity());
this.mWeatherServicePersistenceFile.removeForecastWeatherData();
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
-
-
final ListView listWeatherView = this.getListView();
-
listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE);
if (savedInstanceState != null) {
.getDefaultSharedPreferences(this.getActivity());
// 1. Update units of measurement.
- final String keyPreference = this.getResources().getString(
+ String keyPreference = this.getResources().getString(
R.string.weather_preferences_units_key);
final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
final String celsius = this.getResources().getString(
this.mIsFahrenheit = true;
}
+ // 2. Update number day forecast.
+ keyPreference = this.getResources().getString(
+ R.string.weather_preferences_day_forecast_key);
+ this.mDayForecast = sharedPreferences.getString(keyPreference, "");
+
- // 2. Update forecast weather data on display.
+ // 3. Update forecast weather data on display.
final ForecastWeatherData forecastWeatherData = this.mWeatherServicePersistenceFile
.getForecastWeatherData();
if (forecastWeatherData != null) {
this.updateForecastWeatherData(forecastWeatherData);
}
-
- // 3. If language changed, try to retrieve new data for new language
- // (new strings with the chosen language)
- // keyPreference = this.getResources().getString(
- // R.string.weather_preferences_language_key);
- // final String languagePreferenceValue = sharedPreferences.getString(
- // keyPreference, "");
- // if (!languagePreferenceValue.equals(this.mLanguage)) {
- // this.mLanguage = languagePreferenceValue;
- // this.getWeather();
- // }
}
public class ForecastWeatherTask extends AsyncTask<Object, Void, ForecastWeatherData> {
final String urlAPI = WeatherInformationOverviewFragment.this.getResources()
.getString(R.string.uri_api_weather_forecast);
final String url = this.weatherService.createURIAPIForecastWeather(urlAPI, APIVersion,
- geocodingData.getLatitude(), geocodingData.getLongitude(), "14");
+ geocodingData.getLatitude(), geocodingData.getLongitude(), WeatherInformationOverviewFragment.this.mDayForecast);
final String jsonData = this.weatherHTTPClient.retrieveDataAsString(new URL(url));
final ForecastWeatherData forecastWeatherData = this.weatherService
.retrieveForecastWeatherDataFromJPOS(jsonData);
private void onPostExecuteThrowable(final ForecastWeatherData forecastWeatherData)
throws FileNotFoundException, IOException {
WeatherInformationOverviewFragment.this.mWeatherServicePersistenceFile
- .storeForecastWeatherData(forecastWeatherData);
+ .storeForecastWeatherData(forecastWeatherData);
WeatherInformationOverviewFragment.this.updateForecastWeatherData(forecastWeatherData);
}
connectionPref = this.findPreference(keyPreference);
connectionPref.setSummary(this.getPreferenceManager()
.getSharedPreferences().getString(keyPreference, ""));
+
+ keyPreference = this.getActivity().getString(
+ R.string.weather_preferences_day_forecast_key);
+ connectionPref = this.findPreference(keyPreference);
+ final String value = this.getPreferenceManager().getSharedPreferences().getString(keyPreference, "");
+ String humanValue = "";
+ if (value.equals("5")) {
+ humanValue = "5-Day Forecast";
+ } else if (value.equals("10")) {
+ humanValue = "10-Day Forecast";
+ } else if (value.equals("14")) {
+ humanValue = "14-Day Forecast";
+ }
+ connectionPref.setSummary(humanValue);
}
@Override
if (key.equals(keyValue)) {
final Preference connectionPref = this.findPreference(key);
connectionPref.setSummary(sharedPreferences.getString(key, ""));
+ return;
}
keyValue = this.getActivity().getString(
if (key.equals(keyValue)) {
final Preference connectionPref = this.findPreference(key);
connectionPref.setSummary(sharedPreferences.getString(key, ""));
+ return;
+ }
+
+ keyValue = this.getActivity().getString(
+ R.string.weather_preferences_day_forecast_key);
+ if (key.equals(keyValue)) {
+ final Preference connectionPref = this.findPreference(key);
+ final String value = sharedPreferences.getString(key, "");
+ String humanValue = "";
+ if (value.equals("5")) {
+ humanValue = "5-Day Forecast";
+ } else if (value.equals("10")) {
+ humanValue = "10-Day Forecast";
+ } else if (value.equals("14")) {
+ humanValue = "14-Day Forecast";
+ }
+ connectionPref.setSummary(humanValue);
+ return;
}
}
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Locale;
import android.app.DialogFragment;
-import android.app.Fragment;
+import android.app.ListFragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
import android.widget.ListView;
import de.example.exampletdd.R;
import de.example.exampletdd.activityinterface.GetWeather;
import de.example.exampletdd.model.forecastweather.ForecastWeatherData;
import de.example.exampletdd.service.WeatherServicePersistenceFile;
-public class WeatherInformationSpecificDataFragment extends Fragment implements GetWeather {
+public class WeatherInformationSpecificDataFragment extends ListFragment implements GetWeather {
private boolean mIsFahrenheit;
private int mChosenDay;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
}
@Override
- public View onCreateView(final LayoutInflater inflater,
- final ViewGroup container, final Bundle savedInstanceState) {
- final View rootView = inflater.inflate(R.layout.weather_data_list,
- container, false);
-
- return rootView;
- }
-
- @Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- final ListView listWeatherView = (ListView) this.getActivity().findViewById(
- R.id.weather_data_list_view);
+ final ListView listWeatherView = this.getListView();
+ listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE);
final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(this.getActivity(),
R.layout.weather_data_entry_list);
- final Collection<WeatherSpecificDataEntry> entries = this.createEmptyEntriesList();
+ this.setEmptyText("No data available");
- adapter.addAll(entries);
- listWeatherView.setAdapter(adapter);
+ this.setListAdapter(adapter);
+ this.setListShown(true);
+ this.setListShownNoAnimation(true);
if (savedInstanceState != null) {
// Restore state
final double tempUnits = this.mIsFahrenheit ? 0 : 273.15;
final List<WeatherSpecificDataEntry> entries = this.createEmptyEntriesList();
- final ListView listWeatherView = (ListView) this.getActivity().findViewById(
- R.id.weather_data_list_view);
+
final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(
this.getActivity(), R.layout.weather_data_entry_list);
tempFormatter.format(cloudiness)));
}
- listWeatherView.setAdapter(null);
adapter.addAll(entries);
- listWeatherView.setAdapter(adapter);
+ this.setListAdapter(adapter);
}
@Override
.getForecastWeatherData();
if (forecastWeatherData != null) {
this.updateForecastWeatherData(forecastWeatherData, this.mChosenDay);
+ } else {
+ // 2.1 Empty list by default
+ final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(
+ this.getActivity(), R.layout.weather_data_entry_list);
+ this.setListAdapter(adapter);
}