From: gu.martinm@gmail.com Date: Tue, 2 Sep 2014 16:04:44 +0000 (+0200) Subject: WeatherInformation Android X-Git-Tag: weatherinformation-1.0~156 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5d11fc7c48068017d51ada8136179faa15f0f68f;p=AndroidWeatherInformation WeatherInformation Android specific fragment: without fragmentlist android manifest: supported screens --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 856b325..7fe4e82 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -13,6 +13,13 @@ + + + + + + + @@ -33,7 +40,8 @@ android:label="@string/app_name" android:logo="@drawable/ic_launcher" android:theme="@style/AppTheme" - android:name="de.example.exampletdd.WeatherInformationApplication" > + android:name="de.example.exampletdd.WeatherInformationApplication" + android:supportsRtl="false"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 46edf0e..624d86d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -50,7 +50,5 @@ Section 1 Section 2 Section 3 - MasterDetails - MasterDetail Detail diff --git a/src/de/example/exampletdd/SpecificActivity.java b/src/de/example/exampletdd/SpecificActivity.java index d0e131a..0079600 100644 --- a/src/de/example/exampletdd/SpecificActivity.java +++ b/src/de/example/exampletdd/SpecificActivity.java @@ -10,7 +10,7 @@ public class SpecificActivity extends FragmentActivity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - this.setContentView(R.layout.weather_specific_data); + this.setContentView(R.layout.weather_specific); final ActionBar actionBar = this.getActionBar(); diff --git a/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java b/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java deleted file mode 100644 index 21277cc..0000000 --- a/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.example.exampletdd; - -import android.app.ActionBar; -import android.app.Activity; -import android.os.Bundle; -import de.example.exampletdd.model.GeocodingData; -import de.example.exampletdd.service.ServicePersistenceStorage; - -public class WeatherInformationCurrentDataActivity extends Activity { - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.setContentView(R.layout.weather_current_data); - - final ActionBar actionBar = this.getActionBar(); - - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); - actionBar.setDisplayHomeAsUpEnabled(true); - - } - - @Override - public void onResume() { - super.onResume(); - - final ActionBar actionBar = this.getActionBar(); - - actionBar.setTitle("Current weather information"); - - final ServicePersistenceStorage weatherServicePersistenceFile = new ServicePersistenceStorage(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); - actionBar.setSubtitle("CURRENTLY"); - } - - } -} diff --git a/src/de/example/exampletdd/fragment/current/CurrentFragment.java b/src/de/example/exampletdd/fragment/current/CurrentFragment.java index 8f3bd53..c0d4c03 100644 --- a/src/de/example/exampletdd/fragment/current/CurrentFragment.java +++ b/src/de/example/exampletdd/fragment/current/CurrentFragment.java @@ -321,6 +321,7 @@ public class CurrentFragment extends ListFragment { if (current == null) { // Nothing to do + // TODO: Should I show some error message? I am not doing it on WP8 Should I do it on WP8? return; } diff --git a/src/de/example/exampletdd/fragment/overview/OverviewFragment.java b/src/de/example/exampletdd/fragment/overview/OverviewFragment.java index d2cfbc1..0de0cf5 100644 --- a/src/de/example/exampletdd/fragment/overview/OverviewFragment.java +++ b/src/de/example/exampletdd/fragment/overview/OverviewFragment.java @@ -309,6 +309,7 @@ public class OverviewFragment extends ListFragment { if (forecast == null) { // Nothing to do + // TODO: Should I show some error message? I am not doing it on WP8 Should I do it on WP8? return; } diff --git a/src/de/example/exampletdd/fragment/specific/SpecificAdapter.java b/src/de/example/exampletdd/fragment/specific/SpecificAdapter.java deleted file mode 100644 index 9a8dabf..0000000 --- a/src/de/example/exampletdd/fragment/specific/SpecificAdapter.java +++ /dev/null @@ -1,223 +0,0 @@ -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 SpecificAdapter 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 SpecificAdapter(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 SpecificDataEntryFirst entry = (SpecificDataEntryFirst) 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 SpecificDataEntrySecond entry = (SpecificDataEntrySecond) this - .getItem(position); - viewHolder.weatherDescription.setText(entry.getWeatherDescription()); - } else if (viewType == THIRD) { - final ViewThirdHolder viewHolder = this.getViewThirdHolder(view); - final SpecificDataEntryThird entry = (SpecificDataEntryThird) 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 SpecificDataEntryFourth entry = (SpecificDataEntryFourth) 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/SpecificDataEntryFirst.java b/src/de/example/exampletdd/fragment/specific/SpecificDataEntryFirst.java deleted file mode 100644 index ccd50dc..0000000 --- a/src/de/example/exampletdd/fragment/specific/SpecificDataEntryFirst.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.example.exampletdd.fragment.specific; - -import android.graphics.Bitmap; - -public class SpecificDataEntryFirst { - private final Bitmap picture; - private final String tempMax; - private final String tempMin; - - public SpecificDataEntryFirst(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/SpecificDataEntryFourth.java b/src/de/example/exampletdd/fragment/specific/SpecificDataEntryFourth.java deleted file mode 100644 index c0c33ce..0000000 --- a/src/de/example/exampletdd/fragment/specific/SpecificDataEntryFourth.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.example.exampletdd.fragment.specific; - -public class SpecificDataEntryFourth { - private final String morningTemp; - private final String dayTemp; - private final String eveTemp; - private final String nightTemp; - - public SpecificDataEntryFourth(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/SpecificDataEntrySecond.java b/src/de/example/exampletdd/fragment/specific/SpecificDataEntrySecond.java deleted file mode 100644 index 6471b17..0000000 --- a/src/de/example/exampletdd/fragment/specific/SpecificDataEntrySecond.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.example.exampletdd.fragment.specific; - -public class SpecificDataEntrySecond { - private final String weatherDescription; - - public SpecificDataEntrySecond(final String weatherDescription) { - this.weatherDescription = weatherDescription; - } - - public String getWeatherDescription() { - return this.weatherDescription; - } - -} diff --git a/src/de/example/exampletdd/fragment/specific/SpecificDataEntryThird.java b/src/de/example/exampletdd/fragment/specific/SpecificDataEntryThird.java deleted file mode 100644 index d33ed13..0000000 --- a/src/de/example/exampletdd/fragment/specific/SpecificDataEntryThird.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.example.exampletdd.fragment.specific; - -public class SpecificDataEntryThird { - private final String humidityValue; - private final String pressureValue; - private final String windValue; - private final String rainValue; - private final String cloudsValue; - - public SpecificDataEntryThird(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/SpecificFragment.java b/src/de/example/exampletdd/fragment/specific/SpecificFragment.java index 7339dd4..e0d67fd 100644 --- a/src/de/example/exampletdd/fragment/specific/SpecificFragment.java +++ b/src/de/example/exampletdd/fragment/specific/SpecificFragment.java @@ -13,20 +13,32 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v4.app.ListFragment; -import android.widget.ListView; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; import de.example.exampletdd.R; import de.example.exampletdd.WeatherInformationApplication; import de.example.exampletdd.model.forecastweather.Forecast; import de.example.exampletdd.service.IconsList; -public class SpecificFragment extends ListFragment { +public class SpecificFragment extends Fragment { private int mChosenDay; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + // Inflate the layout for this fragment + return inflater.inflate(R.layout.weather_specific_fragment, container, false); + } @Override public void onConfigurationChanged(final Configuration newConfig) { @@ -41,7 +53,7 @@ public class SpecificFragment extends ListFragment { this.mChosenDay = extras.getInt("CHOSEN_DAY", 0); } else { // tablet layout - // Always 0 when tablet layout. + // Always 0 when tablet layout (by default shows the first day) this.mChosenDay = 0; } } @@ -50,9 +62,6 @@ public class SpecificFragment extends ListFragment { public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - final ListView listWeatherView = this.getListView(); - listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); - if (savedInstanceState != null) { // Restore UI state final Forecast forecast = (Forecast) savedInstanceState.getSerializable("Forecast"); @@ -68,13 +77,6 @@ public class SpecificFragment extends ListFragment { this.mChosenDay = savedInstanceState.getInt("Chosen day"); // TODO: Why don't I need mListState? } - - // TODO: Why don't I need Adapter? - - // TODO: string static resource - this.setEmptyText("No data available"); - // TODO: Why is it different to Current and Overview fragments? - this.setListShownNoAnimation(false); } @Override @@ -142,14 +144,6 @@ public class SpecificFragment extends ListFragment { // 3. Prepare data for UI. - 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 SpecificAdapter adapter = new SpecificAdapter(this.getActivity(), layouts); - - final de.example.exampletdd.model.forecastweather.List forecast = forecastWeatherData .getList().get((chosenDay)); @@ -157,16 +151,14 @@ public class SpecificFragment extends ListFragment { final Calendar calendar = Calendar.getInstance(); final Long forecastUNIXDate = (Long) forecast.getDt(); calendar.setTimeInMillis(forecastUNIXDate * 1000L); - final Date date = calendar.getTime(); - this.getActivity().getActionBar().setSubtitle(dayFormatter.format(date).toUpperCase()); - + final Date date = calendar.getTime(); String tempMax = ""; if (forecast.getTemp().getMax() != null) { double conversion = (Double) forecast.getTemp().getMax(); conversion = conversion - tempUnits; tempMax = tempFormatter.format(conversion) + symbol; - } + } String tempMin = ""; if (forecast.getTemp().getMin() != null) { double conversion = (Double) forecast.getTemp().getMin(); @@ -182,25 +174,22 @@ public class SpecificFragment extends ListFragment { } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); - } - final SpecificDataEntryFirst entryFirst = new SpecificDataEntryFirst(tempMax, - tempMin, picture); - adapter.add(entryFirst); + } + // TODO: string resource String description = "no description available"; if (forecast.getWeather().size() > 0) { description = forecast.getWeather().get(0).getDescription(); } - final SpecificDataEntrySecond entrySecond = new SpecificDataEntrySecond( - description); - adapter.add(entrySecond); - + final TextView descriptionView = (TextView) getActivity().findViewById(R.id.weather_specific_description); + descriptionView.setText(description); + // TODO: units!!!! 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(); @@ -221,9 +210,6 @@ public class SpecificFragment extends ListFragment { final double conversion = (Double) forecast.getClouds(); cloudsValue = tempFormatter.format(conversion); } - final SpecificDataEntryThird entryThird = new SpecificDataEntryThird( - humidityValue, pressureValue, windValue, rainValue, cloudsValue); - adapter.add(entryThird); String tempDay = ""; if (forecast.getTemp().getDay() != null) { @@ -242,21 +228,44 @@ public class SpecificFragment extends ListFragment { 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 SpecificDataEntryFourth entryFourth = new SpecificDataEntryFourth( - tempMorn, tempDay, tempEve, tempNight); - adapter.add(entryFourth); + } // 4. Update UI. - // TODO: Why am I not doing the same as in OverviewFragment? - this.setListAdapter(adapter); + this.getActivity().getActionBar().setSubtitle(dayFormatter.format(date).toUpperCase()); + + final TextView tempMaxView = (TextView) getActivity().findViewById(R.id.weather_specific_temp_max); + tempMaxView.setText(tempMax); + final TextView tempMinView = (TextView) getActivity().findViewById(R.id.weather_specific_temp_min); + tempMinView.setText(tempMin); + final ImageView pictureView = (ImageView) getActivity().findViewById(R.id.weather_specific_picture); + pictureView.setImageBitmap(picture); + + final TextView humidityValueView = (TextView) getActivity().findViewById(R.id.weather_specific_humidity_value); + humidityValueView.setText(humidityValue); + final TextView pressureValueView = (TextView) getActivity().findViewById(R.id.weather_specific_pressure_value); + pressureValueView.setText(pressureValue); + final TextView windValueView = (TextView) getActivity().findViewById(R.id.weather_specific_wind_value); + windValueView.setText(windValue); + final TextView rainValueView = (TextView) getActivity().findViewById(R.id.weather_specific_rain_value); + rainValueView.setText(rainValue); + final TextView cloudsValueView = (TextView) getActivity().findViewById(R.id.weather_specific_clouds_value); + cloudsValueView.setText(cloudsValue); + + final TextView tempDayView = (TextView) getActivity().findViewById(R.id.weather_specific_day_temperature); + tempDayView.setText(tempDay); + final TextView tempMornView = (TextView) getActivity().findViewById(R.id.weather_specific_morn_temperature); + tempMornView.setText(tempMorn); + final TextView tempEveView = (TextView) getActivity().findViewById(R.id.weather_specific_eve_temperature); + tempEveView.setText(tempEve); + final TextView tempNightView = (TextView) getActivity().findViewById(R.id.weather_specific_night_temperature); + tempNightView.setText(tempNight); } @Override