From: gu.martinm@gmail.com Date: Sun, 20 Apr 2014 03:57:08 +0000 (+0200) Subject: No time for comments X-Git-Tag: weatherinformation-1.0~170 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=7cc7ce9398ebffce9d2fe88f96b9259cd680730c;p=AndroidWeatherInformation No time for comments --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8b5e56e..bcfb02b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -86,11 +86,6 @@ android:value="@integer/google_play_services_version" /> - - diff --git a/res/drawable-hdpi/ic_action_map.png b/res/drawable-hdpi/ic_action_map.png new file mode 100644 index 0000000..370cf5c Binary files /dev/null and b/res/drawable-hdpi/ic_action_map.png differ diff --git a/res/drawable-mdpi/ic_action_map.png b/res/drawable-mdpi/ic_action_map.png new file mode 100644 index 0000000..50a9100 Binary files /dev/null and b/res/drawable-mdpi/ic_action_map.png differ diff --git a/res/drawable-xhdpi/ic_action_map.png b/res/drawable-xhdpi/ic_action_map.png new file mode 100644 index 0000000..537c5a4 Binary files /dev/null and b/res/drawable-xhdpi/ic_action_map.png differ diff --git a/res/drawable-xxhdpi/ic_action_map.png b/res/drawable-xxhdpi/ic_action_map.png new file mode 100644 index 0000000..ed72ce9 Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_map.png differ diff --git a/res/layout/activity_test_scroll.xml b/res/layout/activity_test_scroll.xml deleted file mode 100644 index 5ad3eba..0000000 --- a/res/layout/activity_test_scroll.xml +++ /dev/null @@ -1,331 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/fragment_test_scroll.xml b/res/layout/fragment_test_scroll.xml deleted file mode 100644 index cccb845..0000000 --- a/res/layout/fragment_test_scroll.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/res/layout/weather_current_data_entry_first.xml b/res/layout/weather_current_data_entry_first.xml new file mode 100644 index 0000000..bbfb715 --- /dev/null +++ b/res/layout/weather_current_data_entry_first.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + diff --git a/res/layout/weather_current_data_entry_fourth.xml b/res/layout/weather_current_data_entry_fourth.xml new file mode 100644 index 0000000..19d3488 --- /dev/null +++ b/res/layout/weather_current_data_entry_fourth.xml @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/weather_current_data_entry_second.xml b/res/layout/weather_current_data_entry_second.xml new file mode 100644 index 0000000..7c2fa49 --- /dev/null +++ b/res/layout/weather_current_data_entry_second.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/res/layout/weather_current_data_entry_third.xml b/res/layout/weather_current_data_entry_third.xml new file mode 100644 index 0000000..9f7094c --- /dev/null +++ b/res/layout/weather_current_data_entry_third.xml @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/weather_main_entry_list.xml b/res/layout/weather_main_entry_list.xml index f11a2ac..017f8d0 100644 --- a/res/layout/weather_main_entry_list.xml +++ b/res/layout/weather_main_entry_list.xml @@ -1,70 +1,96 @@ - + + + + + + - + + + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/res/layout/weather_specific_data.xml b/res/layout/weather_specific_data.xml index e6a25e5..2e0d4fe 100644 --- a/res/layout/weather_specific_data.xml +++ b/res/layout/weather_specific_data.xml @@ -9,13 +9,6 @@ tools:context="de.example.exampletdd.WeatherInformationSpecificDataActivity" tools:ignore="MergeRootFrame" > - - - - - diff --git a/res/menu/weather_main_menu.xml b/res/menu/weather_main_menu.xml index e2c28f0..26ff96f 100644 --- a/res/menu/weather_main_menu.xml +++ b/res/menu/weather_main_menu.xml @@ -28,7 +28,7 @@ country not found Downloading remote data Please wait… - TestScrollActivity Section 1 Section 2 Section 3 diff --git a/src/de/example/exampletdd/TestScrollActivity.java b/src/de/example/exampletdd/TestScrollActivity.java deleted file mode 100644 index b894a94..0000000 --- a/src/de/example/exampletdd/TestScrollActivity.java +++ /dev/null @@ -1,122 +0,0 @@ -package de.example.exampletdd; - -import android.app.ActionBar; -import android.app.Activity; -import android.app.Fragment; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -public class TestScrollActivity extends Activity implements ActionBar.OnNavigationListener { - - /** - * The serialization (saved instance state) Bundle key representing the - * current dropdown position. - */ - private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.setContentView(R.layout.activity_test_scroll); - - // Set up the action bar to show a dropdown list. - final ActionBar actionBar = this.getActionBar(); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - - // Set up the dropdown list navigation in the action bar. - actionBar.setListNavigationCallbacks( - // Specify a SpinnerAdapter to populate the dropdown list. - new ArrayAdapter(actionBar.getThemedContext(), - android.R.layout.simple_list_item_1, android.R.id.text1, new String[] { - this.getString(R.string.title_section1), - this.getString(R.string.title_section2), - this.getString(R.string.title_section3), }), this); - } - - @Override - public void onRestoreInstanceState(final Bundle savedInstanceState) { - // Restore the previously serialized current dropdown position. - if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { - this.getActionBar().setSelectedNavigationItem( - savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); - } - } - - @Override - public void onSaveInstanceState(final Bundle outState) { - // Serialize the current dropdown position. - outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, this.getActionBar().getSelectedNavigationIndex()); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - - // Inflate the menu; this adds items to the action bar if it is present. - this.getMenuInflater().inflate(R.menu.test_scroll, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - final int id = item.getItemId(); - if (id == R.id.action_settings) { - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - public boolean onNavigationItemSelected(final int position, final long id) { - // When the given dropdown item is selected, show its contents in the - // container view. - // getFragmentManager().beginTransaction() - // .replace(R.id.container, PlaceholderFragment.newInstance(position + - // 1)).commit(); - return true; - } - - /** - * A placeholder fragment containing a simple view. - */ - public static class PlaceholderFragment extends Fragment { - /** - * The fragment argument representing the section number for this - * fragment. - */ - private static final String ARG_SECTION_NUMBER = "section_number"; - - /** - * Returns a new instance of this fragment for the given section number. - */ - public static PlaceholderFragment newInstance(final int sectionNumber) { - final PlaceholderFragment fragment = new PlaceholderFragment(); - final Bundle args = new Bundle(); - args.putInt(ARG_SECTION_NUMBER, sectionNumber); - fragment.setArguments(args); - return fragment; - } - - public PlaceholderFragment() { - } - - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - final View rootView = inflater.inflate(R.layout.fragment_test_scroll, container, false); - final TextView textView = (TextView) rootView.findViewById(R.id.section_label); - textView.setText(Integer.toString(this.getArguments().getInt(ARG_SECTION_NUMBER))); - return rootView; - } - } - -} diff --git a/src/de/example/exampletdd/WeatherInformationActivity.java b/src/de/example/exampletdd/WeatherInformationActivity.java index b45a6ff..de41348 100644 --- a/src/de/example/exampletdd/WeatherInformationActivity.java +++ b/src/de/example/exampletdd/WeatherInformationActivity.java @@ -79,7 +79,7 @@ public class WeatherInformationActivity extends Activity { } else if (itemId == R.id.weather_menu_current) { intent = new Intent("de.example.exampletdd.WEATHERINFO") .setComponent(new ComponentName("de.example.exampletdd", - "de.example.exampletdd.TestScrollActivity")); + "de.example.exampletdd.WeatherInformationCurrentDataActivity")); this.startActivity(intent); return true; } else { diff --git a/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java b/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java index 834f705..4fd78f8 100644 --- a/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java +++ b/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java @@ -37,8 +37,8 @@ public class WeatherInformationCurrentDataActivity extends Activity { .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("Current weather data information"); - actionBar.setSubtitle(city + "," + country); + actionBar.setTitle(city + "," + country); + actionBar.setSubtitle("CURRENTLY"); } } diff --git a/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java b/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java index b122d8f..0fbe153 100644 --- a/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java +++ b/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java @@ -52,13 +52,6 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { 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, ""); - this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this.getActivity()); this.mWeatherServicePersistenceFile.removeCurrentWeatherData(); } @@ -88,16 +81,9 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { this.setHasOptionsMenu(false); - 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.setListShownNoAnimation(false); } @Override @@ -125,28 +111,9 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { if (currentWeatherData != null) { this.updateCurrentWeatherData(currentWeatherData); } else { - // 2.1 Empty list by default - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( - this.getActivity(), R.layout.weather_data_entry_list); - this.setListAdapter(adapter); - - // 2.2. Try to update weather data on display with remote - // information. + // 3. Try to update weather data on display with remote this.getRemoteCurrentWeatherInformation(); } - - - - // 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(); - // } } @Override @@ -297,6 +264,7 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { try { this.onPostExecuteThrowable(currentWeatherData); } catch (final IOException e) { + WeatherInformationCurrentDataFragment.this.setListShown(true); Log.e(TAG, "WeatherTask onPostExecute exception: ", e); final DialogFragment newFragment = ErrorDialogFragment .newInstance(R.string.error_dialog_generic_error); @@ -305,6 +273,7 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { "errorDialog"); } } else { + WeatherInformationCurrentDataFragment.this.setListShown(true); final DialogFragment newFragment = ErrorDialogFragment .newInstance(R.string.error_dialog_generic_error); newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(), @@ -325,16 +294,6 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { private CurrentWeatherData doInBackgroundThrowable(final Object... params) throws ClientProtocolException, MalformedURLException, URISyntaxException, JsonParseException, IOException { - // final SharedPreferences sharedPreferences = PreferenceManager - // .getDefaultSharedPreferences(WeatherInformationCurrentDataFragment.this - // .getActivity()); - // - // final String keyPreference = - // WeatherInformationCurrentDataFragment.this - // .getActivity().getString( - // R.string.weather_preferences_language_key); - // final String languagePreferenceValue = - // sharedPreferences.getString(keyPreference, ""); // 1. Coordinates final GeocodingData geocodingData = (GeocodingData) params[0]; diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java new file mode 100644 index 0000000..e118a3c --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java @@ -0,0 +1,223 @@ +package de.example.exampletdd.fragment.specific; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; +import de.example.exampletdd.R; + +public class WeatherCurrentDataAdapter extends ArrayAdapter { + private static final int FIRST = 0; + private static final int SECOND = 1; + private static final int THIRD = 2; + private static final int FOURTH = 3; + private final int[] resources; + + public WeatherCurrentDataAdapter(final Context context, final int[] resources) { + super(context, 0); + + this.resources = resources; + } + + + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + + final View view = this.getWorkingView(position, convertView); + final int viewType = this.getItemViewType(position); + + if (viewType == FIRST) { + + final ViewFirstHolder viewHolder = this.getViewFirstHolder(view); + final WeatherCurrentDataEntryFirst entry = (WeatherCurrentDataEntryFirst) this + .getItem(position); + viewHolder.picture.setImageBitmap(entry.getPicture()); + viewHolder.tempMax.setText(entry.getTempMax()); + viewHolder.tempMin.setText(entry.getTempMin()); + } else if (viewType == SECOND) { + final ViewSecondHolder viewHolder = this.getViewSecondHolder(view); + final WeatherCurrentDataEntrySecond entry = (WeatherCurrentDataEntrySecond) this + .getItem(position); + viewHolder.weatherDescription.setText(entry.getWeatherDescription()); + } else if (viewType == THIRD) { + final ViewThirdHolder viewHolder = this.getViewThirdHolder(view); + final WeatherCurrentDataEntryThird entry = (WeatherCurrentDataEntryThird) this + .getItem(position); + viewHolder.humidityValue.setText(entry.getHumidityValue()); + viewHolder.pressureValue.setText(entry.getPressureValue()); + viewHolder.rainValue.setText(entry.getRainValue()); + viewHolder.cloudsValue.setText(entry.getCloudsValue()); + viewHolder.windValue.setText(entry.getWindValue()); + } else if (viewType == FOURTH) { + final ViewFourthHolder viewHolder = this.getViewFourthHolder(view); + final WeatherCurrentDataEntryFourth entry = (WeatherCurrentDataEntryFourth) this + .getItem(position); + viewHolder.dayTemp.setText(entry.getDayTemp()); + viewHolder.morningTemp.setText(entry.getEveTemp()); + viewHolder.eveTemp.setText(entry.getEveTemp()); + viewHolder.nightTemp.setText(entry.getNightTemp()); + } + + return view; + } + + @Override + public int getItemViewType(final int position) { + int type = 0; + + if (position == 0) { + type = FIRST; + } else if (position == 1) { + type = SECOND; + } else if (position == 2) { + type = THIRD; + } else if (position == 3) { + type = FOURTH; + } + + return type; + } + + @Override + public int getViewTypeCount() { + return 4; + } + + private View getWorkingView(final int position, final View convertView) { + View workingView = null; + + if (convertView == null) { + final int viewType = this.getItemViewType(position); + final Context context = this.getContext(); + final LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + workingView = inflater.inflate(this.resources[viewType], null); + } else { + workingView = convertView; + } + + return workingView; + } + + private ViewFirstHolder getViewFirstHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewFirstHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewFirstHolder)) { + viewHolder = new ViewFirstHolder(); + + viewHolder.picture = (ImageView) workingView + .findViewById(R.id.weather_current_data_picture); + viewHolder.tempMax = (TextView) workingView + .findViewById(R.id.weather_current_data_temp_max); + viewHolder.tempMin = (TextView) workingView + .findViewById(R.id.weather_current_data_temp_min); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewFirstHolder) tag; + } + + return viewHolder; + } + + private ViewSecondHolder getViewSecondHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewSecondHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewSecondHolder)) { + viewHolder = new ViewSecondHolder(); + + viewHolder.weatherDescription = (TextView) workingView + .findViewById(R.id.weather_current_data_description); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewSecondHolder) tag; + } + + return viewHolder; + } + + private ViewThirdHolder getViewThirdHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewThirdHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewThirdHolder)) { + viewHolder = new ViewThirdHolder(); + + viewHolder.humidityValue = (TextView) workingView + .findViewById(R.id.weather_current_data_humidity_value); + viewHolder.pressureValue = (TextView) workingView + .findViewById(R.id.weather_current_data_pressure_value); + viewHolder.rainValue = (TextView) workingView + .findViewById(R.id.weather_current_data_rain_value); + viewHolder.cloudsValue = (TextView) workingView + .findViewById(R.id.weather_current_data_clouds_value); + viewHolder.windValue = (TextView) workingView + .findViewById(R.id.weather_current_data_wind_value); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewThirdHolder) tag; + } + + return viewHolder; + } + + private ViewFourthHolder getViewFourthHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewFourthHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewFourthHolder)) { + viewHolder = new ViewFourthHolder(); + + viewHolder.morningTemp = (TextView) workingView + .findViewById(R.id.weather_morn_temperature); + viewHolder.dayTemp = (TextView) workingView.findViewById(R.id.weather_day_temperature); + viewHolder.eveTemp = (TextView) workingView.findViewById(R.id.weather_eve_temperature); + viewHolder.nightTemp = (TextView) workingView + .findViewById(R.id.weather_night_temperature); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewFourthHolder) tag; + } + + return viewHolder; + } + + + private static class ViewFirstHolder { + public ImageView picture; + public TextView tempMax; + public TextView tempMin; + } + + private static class ViewSecondHolder { + public TextView weatherDescription; + } + + private static class ViewThirdHolder { + public TextView humidityValue; + public TextView pressureValue; + public TextView windValue; + public TextView rainValue; + public TextView cloudsValue; + } + + private static class ViewFourthHolder { + private TextView morningTemp; + private TextView dayTemp; + private TextView eveTemp; + private TextView nightTemp; + } +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java new file mode 100644 index 0000000..732e682 --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java @@ -0,0 +1,28 @@ +package de.example.exampletdd.fragment.specific; + +import android.graphics.Bitmap; + +public class WeatherCurrentDataEntryFirst { + private final Bitmap picture; + private final String tempMax; + private final String tempMin; + + public WeatherCurrentDataEntryFirst(final String tempMax, final String tempMin, + final Bitmap picture) { + this.tempMax = tempMax; + this.tempMin = tempMin; + this.picture = picture; + } + + public Bitmap getPicture() { + return this.picture; + } + + public String getTempMax() { + return this.tempMax; + } + + public String getTempMin() { + return this.tempMin; + } +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java new file mode 100644 index 0000000..4aa2e8d --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java @@ -0,0 +1,33 @@ +package de.example.exampletdd.fragment.specific; + +public class WeatherCurrentDataEntryFourth { + private final String morningTemp; + private final String dayTemp; + private final String eveTemp; + private final String nightTemp; + + public WeatherCurrentDataEntryFourth(final String morningTemp, final String dayTemp, + final String eveTemp, final String nightTemp) { + this.morningTemp = morningTemp; + this.dayTemp = dayTemp; + this.eveTemp = eveTemp; + this.nightTemp = nightTemp; + } + + public String getMorningTemp() { + return this.morningTemp; + } + + public String getDayTemp() { + return this.dayTemp; + } + + public String getEveTemp() { + return this.eveTemp; + } + + public String getNightTemp() { + return this.nightTemp; + } + +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java new file mode 100644 index 0000000..ca6a073 --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java @@ -0,0 +1,14 @@ +package de.example.exampletdd.fragment.specific; + +public class WeatherCurrentDataEntrySecond { + private final String weatherDescription; + + public WeatherCurrentDataEntrySecond(final String weatherDescription) { + this.weatherDescription = weatherDescription; + } + + public String getWeatherDescription() { + return this.weatherDescription; + } + +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java new file mode 100644 index 0000000..62d2f01 --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java @@ -0,0 +1,39 @@ +package de.example.exampletdd.fragment.specific; + +public class WeatherCurrentDataEntryThird { + private final String humidityValue; + private final String pressureValue; + private final String windValue; + private final String rainValue; + private final String cloudsValue; + + public WeatherCurrentDataEntryThird(final String humidityValue, final String pressureValue, + final String windValue, final String rainValue, final String cloudsValue) { + this.humidityValue = humidityValue; + this.pressureValue = pressureValue; + this.windValue = windValue; + this.rainValue = rainValue; + this.cloudsValue = cloudsValue; + } + + public String getHumidityValue() { + return this.humidityValue; + } + + public String getPressureValue() { + return this.pressureValue; + } + + public String getWindValue() { + return this.windValue; + } + + public String getRainValue() { + return this.rainValue; + } + + public String getCloudsValue() { + return this.cloudsValue; + } + +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java b/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java index aecda8a..5e34202 100644 --- a/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java +++ b/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java @@ -4,21 +4,22 @@ import java.io.IOException; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; import java.util.Locale; import android.app.DialogFragment; 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.widget.ListView; import de.example.exampletdd.R; import de.example.exampletdd.activityinterface.GetWeather; import de.example.exampletdd.fragment.ErrorDialogFragment; +import de.example.exampletdd.fragment.overview.IconsList; import de.example.exampletdd.model.forecastweather.ForecastWeatherData; import de.example.exampletdd.service.WeatherServicePersistenceFile; @@ -41,13 +42,6 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile( this.getActivity()); - - // final SharedPreferences sharedPreferences = PreferenceManager - // .getDefaultSharedPreferences(this.getActivity()); - // final String keyPreference = this.getResources().getString( - // R.string.weather_preferences_language_key); - // this.mLanguage = sharedPreferences.getString( - // keyPreference, ""); } @Override @@ -57,14 +51,9 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme final ListView listWeatherView = this.getListView(); listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); - 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.setListShownNoAnimation(false); if (savedInstanceState != null) { // Restore state @@ -121,11 +110,16 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme .getDefault()); tempFormatter.applyPattern("#####.#####"); final double tempUnits = this.mIsFahrenheit ? 0 : 273.15; + final String symbol = this.mIsFahrenheit ? "ºF" : "ºC"; - final List entries = this.createEmptyEntriesList(); - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( - this.getActivity(), R.layout.weather_data_entry_list); + final int[] layouts = new int[4]; + layouts[0] = R.layout.weather_current_data_entry_first; + layouts[1] = R.layout.weather_current_data_entry_second; + layouts[2] = R.layout.weather_current_data_entry_third; + layouts[3] = R.layout.weather_current_data_entry_fourth; + final WeatherCurrentDataAdapter adapter = new WeatherCurrentDataAdapter(this.getActivity(), + layouts); final de.example.exampletdd.model.forecastweather.List forecast = forecastWeatherData @@ -138,42 +132,99 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme final Date date = calendar.getTime(); this.getActivity().getActionBar().setSubtitle(dayFormatter.format(date).toUpperCase()); - if (forecast.getWeather().size() > 0) { - entries.set(0, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_description), - forecast.getWeather().get(0).getDescription())); - } - - if (forecast.getTemp().getDay() != null) { - double conversion = (Double) forecast.getTemp().getDay(); - conversion = conversion - tempUnits; - entries.set(1, new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem), - tempFormatter.format(conversion))); - } + String tempMax = ""; if (forecast.getTemp().getMax() != null) { double conversion = (Double) forecast.getTemp().getMax(); conversion = conversion - tempUnits; - entries.set(2, new WeatherSpecificDataEntry( - this.getString(R.string.text_field_tem_max), tempFormatter.format(conversion))); + tempMax = tempFormatter.format(conversion) + symbol; } - + String tempMin = ""; if (forecast.getTemp().getMin() != null) { double conversion = (Double) forecast.getTemp().getMin(); conversion = conversion - tempUnits; - entries.set(3, new WeatherSpecificDataEntry( - this.getString(R.string.text_field_tem_min), tempFormatter.format(conversion))); + tempMin = tempFormatter.format(conversion) + symbol; + } + Bitmap picture; + if ((forecast.getWeather().size() > 0) && (forecast.getWeather().get(0).getIcon() != null) + && (IconsList.getIcon(forecast.getWeather().get(0).getIcon()) != null)) { + final String icon = forecast.getWeather().get(0).getIcon(); + picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon) + .getResourceDrawable()); + } else { + picture = BitmapFactory.decodeResource(this.getResources(), + R.drawable.weather_severe_alert); } + final WeatherCurrentDataEntryFirst entryFirst = new WeatherCurrentDataEntryFirst(tempMax, + tempMin, picture); + adapter.add(entryFirst); + String description = "no description available"; + if (forecast.getWeather().size() > 0) { + description = forecast.getWeather().get(0).getDescription(); + } + final WeatherCurrentDataEntrySecond entrySecond = new WeatherCurrentDataEntrySecond( + description); + adapter.add(entrySecond); + + + String humidityValue = ""; + if (forecast.getHumidity() != null) { + final double conversion = (Double) forecast.getHumidity(); + humidityValue = tempFormatter.format(conversion); + } + String pressureValue = ""; + if (forecast.getPressure() != null) { + final double conversion = (Double) forecast.getPressure(); + pressureValue = tempFormatter.format(conversion); + } + String windValue = ""; + if (forecast.getSpeed() != null) { + final double conversion = (Double) forecast.getSpeed(); + windValue = tempFormatter.format(conversion); + } + String rainValue = ""; + if (forecast.getRain() != null) { + final double conversion = (Double) forecast.getRain(); + rainValue = tempFormatter.format(conversion); + } + String cloudsValue = ""; + if (forecast.getRain() != null) { + final double conversion = (Double) forecast.getClouds(); + cloudsValue = tempFormatter.format(conversion); + } + final WeatherCurrentDataEntryThird entryThird = new WeatherCurrentDataEntryThird( + humidityValue, pressureValue, windValue, rainValue, cloudsValue); + adapter.add(entryThird); - if (forecast.getClouds() != null) { - final double cloudiness = (Double) forecast.getClouds(); - entries.set(6, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_cloudiness), - tempFormatter.format(cloudiness))); + String tempDay = ""; + if (forecast.getTemp().getDay() != null) { + double conversion = (Double) forecast.getTemp().getDay(); + conversion = conversion - tempUnits; + tempDay = tempFormatter.format(conversion) + symbol; + } + String tempMorn = ""; + if (forecast.getTemp().getMorn() != null) { + double conversion = (Double) forecast.getTemp().getMorn(); + conversion = conversion - tempUnits; + tempMorn = tempFormatter.format(conversion) + symbol; + } + String tempEve = ""; + if (forecast.getTemp().getEve() != null) { + double conversion = (Double) forecast.getTemp().getEve(); + conversion = conversion - tempUnits; + tempEve = tempFormatter.format(conversion) + symbol; } + String tempNight = ""; + if (forecast.getTemp().getNight() != null) { + double conversion = (Double) forecast.getTemp().getNight(); + conversion = conversion - tempUnits; + tempNight = tempFormatter.format(conversion) + symbol; + } + final WeatherCurrentDataEntryFourth entryFourth = new WeatherCurrentDataEntryFourth( + tempMorn, tempDay, tempEve, tempNight); + adapter.add(entryFourth); - adapter.addAll(entries); this.setListAdapter(adapter); } @@ -198,46 +249,10 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme // 2. Update weather data on display. - final ForecastWeatherData forecastWeatherData = this.mWeatherServicePersistenceFile .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); } - - - - // 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(); - // } - } - - private List createEmptyEntriesList() { - final List entries = new ArrayList(); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_description), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem_max), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem_min), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_sun_rise), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_sun_set), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_cloudiness), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_rain_time), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_rain_amount), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_wind_speed), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_humidity), null)); - - return entries; } } diff --git a/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java b/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java index 0b9491d..a354c92 100644 --- a/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java +++ b/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java @@ -7,7 +7,6 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import de.example.exampletdd.R; -import de.example.exampletdd.fragment.specific.WeatherSpecificDataEntry; public class WeatherSpecificDataAdapter extends ArrayAdapter { private final int resource;