From: gu.martinm@gmail.com Date: Thu, 10 Apr 2014 07:41:30 +0000 (+0200) Subject: New overview list. WIP: implementation for tabs and phones. X-Git-Tag: weatherinformation-1.0~179 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5a02a44d28a61e9523323b0dbe4f0d9fa81931e3;p=AndroidWeatherInformation New overview list. WIP: implementation for tabs and phones. --- diff --git a/res/drawable-hdpi/ic_02d.png b/res/drawable-hdpi/ic_02d.png new file mode 100644 index 0000000..3451b4a Binary files /dev/null and b/res/drawable-hdpi/ic_02d.png differ diff --git a/res/drawable-mdpi/ic_02d.png b/res/drawable-mdpi/ic_02d.png new file mode 100644 index 0000000..482afa3 Binary files /dev/null and b/res/drawable-mdpi/ic_02d.png differ diff --git a/res/drawable-xhdpi/ic_02d.png b/res/drawable-xhdpi/ic_02d.png new file mode 100644 index 0000000..775ee02 Binary files /dev/null and b/res/drawable-xhdpi/ic_02d.png differ diff --git a/res/drawable-xxhdpi/ic_02d.png b/res/drawable-xxhdpi/ic_02d.png new file mode 100644 index 0000000..54649c6 Binary files /dev/null and b/res/drawable-xxhdpi/ic_02d.png differ diff --git a/res/layout/weather_main.xml b/res/layout/weather_main.xml index 8ce309b..db32dde 100644 --- a/res/layout/weather_main.xml +++ b/res/layout/weather_main.xml @@ -11,7 +11,6 @@ android:id="@+id/weather_overview_fragment" android:layout_width="match_parent" android:layout_height="match_parent" - class="de.example.exampletdd.fragment.overview.WeatherInformationOverviewFragment" - tools:layout="@layout/weather_main_list" /> + class="de.example.exampletdd.fragment.overview.WeatherInformationOverviewFragment" /> \ No newline at end of file diff --git a/res/layout/weather_main_entry_list.xml b/res/layout/weather_main_entry_list.xml index 56ea95e..6802af1 100644 --- a/res/layout/weather_main_entry_list.xml +++ b/res/layout/weather_main_entry_list.xml @@ -4,20 +4,18 @@ android:layout_height="match_parent" android:orientation="vertical" > - - + android:textAllCaps="true" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textStyle="bold" /> - - - - - - - - diff --git a/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java b/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java index 82945a8..2c973d9 100644 --- a/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java +++ b/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java @@ -24,7 +24,7 @@ import org.apache.http.client.ClientProtocolException; import org.json.JSONException; import android.app.DialogFragment; -import android.app.Fragment; +import android.app.ListFragment; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; @@ -34,9 +34,10 @@ import android.os.AsyncTask; 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.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.AbsListView.MultiChoiceModeListener; import android.widget.ListView; import de.example.exampletdd.R; import de.example.exampletdd.activityinterface.ErrorMessage; @@ -49,7 +50,8 @@ import de.example.exampletdd.parser.IJPOSWeatherParser; import de.example.exampletdd.parser.JPOSWeatherParser; import de.example.exampletdd.service.WeatherService; -public class WeatherInformationOverviewFragment extends Fragment implements GetWeather { +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"; private static final String TAG = "WeatherInformationOverviewFragment"; @@ -71,31 +73,42 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW } @Override - public View onCreateView(final LayoutInflater inflater, - final ViewGroup container, final Bundle savedInstanceState) { - // TODO: In activity_main.xml you can see: tools:layout="@layout/weather_data_list" - // So, probably this line is not required. I guess you can do the same - // by xml or by means of this code. Test it!!! - final View rootView = inflater.inflate(R.layout.weather_main_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_main_list_view); + final ListView listWeatherView = this.getListView(); - final WeatherOverviewAdapter adapter = new WeatherOverviewAdapter(this.getActivity(), - R.layout.weather_main_entry_list); + listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); + listWeatherView.setMultiChoiceModeListener(new MultiChoiceModeListener() { - final Collection entries = this.createEmptyEntriesList(); + @Override + public boolean onCreateActionMode(final ActionMode mode, + final Menu menu) { + return false; + } - adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + @Override + public boolean onPrepareActionMode(final ActionMode mode, + final Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(final ActionMode mode, + final MenuItem item) { + return false; + } + + @Override + public void onDestroyActionMode(final ActionMode mode) { + } + + @Override + public void onItemCheckedStateChanged( + final ActionMode mode, final int position, + final long id, final boolean checked) { + } + }); if (savedInstanceState != null) { // Restore state @@ -109,6 +122,20 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW .createErrorDialog(R.string.error_dialog_generic_error); } } + + this.setHasOptionsMenu(false); + + final WeatherOverviewAdapter adapter = new WeatherOverviewAdapter( + this.getActivity(), R.layout.weather_main_entry_list); + + final Collection entries = this + .createEmptyEntriesList(); + + this.setListAdapter(null); + adapter.addAll(entries); + this.setListAdapter(adapter); + this.setListShown(true); + this.setListShownNoAnimation(true); } @Override @@ -170,40 +197,45 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW @Override public void updateWeatherData(final WeatherData weatherData) { final List entries = this.createEmptyEntriesList(); - final ListView listWeatherView = (ListView) this.getActivity().findViewById( - R.id.weather_main_list_view); final WeatherOverviewAdapter adapter = new WeatherOverviewAdapter(this.getActivity(), R.layout.weather_main_entry_list); - Bitmap picture = null; - - if (weatherData.getWeather().getIcon() != null) { - picture= BitmapFactory.decodeByteArray( - weatherData.getIconData(), 0, - weatherData.getIconData().length); - } + // Bitmap picture = null; + // + // if (weatherData.getWeather().getIcon() != null) { + // picture= BitmapFactory.decodeByteArray( + // weatherData.getIconData(), 0, + // weatherData.getIconData().length); + // } + final Bitmap picture = BitmapFactory.decodeResource( + this.getResources(), R.drawable.ic_02d); final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.getDefault()); - tempFormatter.applyPattern("#####.#####"); - final SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd", Locale.getDefault()); + tempFormatter.applyPattern("#####.##"); + final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d", Locale.getDefault()); final double tempUnits = this.mIsFahrenheit ? 0 : 273.15; - double conversion = weatherData.getMain().getTemp(); - conversion = conversion - tempUnits; + double temp = weatherData.getMain().getTemp(); + temp = temp - tempUnits; + double maxTemp = weatherData.getMain().getMaxTemp(); + maxTemp = maxTemp - tempUnits; + double minTemp = weatherData.getMain().getMinTemp(); + minTemp = minTemp - tempUnits; final Calendar now = Calendar.getInstance(); if (weatherData.getWeather() != null) { for (int i = 0; i<15; i++) { final Date day = now.getTime(); - entries.set(i, new WeatherOverviewEntry( - "DATE: " + dateFormat.format(day), - tempFormatter.format(conversion), picture)); - now.add(Calendar.DAY_OF_MONTH, -1); + entries.set(i, new WeatherOverviewEntry(dateFormat.format(day), + tempFormatter.format(temp), tempFormatter + .format(maxTemp), tempFormatter + .format(minTemp), picture)); + now.add(Calendar.DAY_OF_MONTH, 1); } } - listWeatherView.setAdapter(null); + this.setListAdapter(null); adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + this.setListAdapter(adapter); } @Override @@ -381,14 +413,14 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW private List createEmptyEntriesList() { final List entries = new ArrayList(); - final SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd", Locale.getDefault()); + final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d", Locale.getDefault()); final Calendar now = Calendar.getInstance(); for (int i = 0; i<15; i++) { final Date day = now.getTime(); - entries.add(i, new WeatherOverviewEntry( - "DATE: " + dateFormat.format(day), null, null)); - now.add(Calendar.DAY_OF_MONTH, -1); + entries.add(i, new WeatherOverviewEntry(dateFormat.format(day), + null, null, null, null)); + now.add(Calendar.DAY_OF_MONTH, 1); } return entries; diff --git a/src/de/example/exampletdd/fragment/overview/WeatherOverviewAdapter.java b/src/de/example/exampletdd/fragment/overview/WeatherOverviewAdapter.java index 43fae28..7f101d5 100644 --- a/src/de/example/exampletdd/fragment/overview/WeatherOverviewAdapter.java +++ b/src/de/example/exampletdd/fragment/overview/WeatherOverviewAdapter.java @@ -32,7 +32,15 @@ public class WeatherOverviewAdapter extends ArrayAdapter { // Setting the text view viewHolder.dateView.setText(entry.getDate()); - viewHolder.temperatureView.setText(entry.getTemperature()); + String maxTemp = ""; + if (entry.getMaxTemp() != null) { + maxTemp = entry.getMaxTemp() + "º"; + } + String minTemp = ""; + if (entry.getMinTemp() != null) { + minTemp = "/" + entry.getMinTemp() + "º"; + } + viewHolder.temperatureView.setText(maxTemp + minTemp); // Set image view viewHolder.pictureView.setImageBitmap(entry.getPicture()); diff --git a/src/de/example/exampletdd/fragment/overview/WeatherOverviewEntry.java b/src/de/example/exampletdd/fragment/overview/WeatherOverviewEntry.java index f56fce6..2d2c710 100644 --- a/src/de/example/exampletdd/fragment/overview/WeatherOverviewEntry.java +++ b/src/de/example/exampletdd/fragment/overview/WeatherOverviewEntry.java @@ -5,12 +5,16 @@ import android.graphics.Bitmap; public class WeatherOverviewEntry { private final String date; private final String temperature; + private final String maxTemp; + private final String minTemp; private final Bitmap picture; public WeatherOverviewEntry(final String date, final String temperature, - final Bitmap picture) { + final String maxTemp, final String minTemp, final Bitmap picture) { this.date = date; this.temperature = temperature; + this.maxTemp = maxTemp; + this.minTemp = minTemp; this.picture = picture; } @@ -22,6 +26,14 @@ public class WeatherOverviewEntry { return this.temperature; } + public String getMaxTemp() { + return this.maxTemp; + } + + public String getMinTemp() { + return this.minTemp; + } + public Bitmap getPicture() { return this.picture; }