Back to project page AerisAndroidLibrary.
The source code is released under:
Apache License
If you think the Android project AerisAndroidLibrary listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.fragment; /*from ww w .ja v a 2s .c om*/ import java.util.List; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.example.demoaerisproject.R; import com.example.listview.ForecastAdapter; import com.hamweather.aeris.communication.EndpointType; import com.hamweather.aeris.model.AerisBatchResponse; import com.hamweather.aeris.model.ForecastPeriod; import com.hamweather.aeris.model.Observation; import com.hamweather.aeris.model.Place; import com.hamweather.aeris.response.ForecastsResponse; import com.hamweather.aeris.response.ObservationResponse; import com.hamweather.aeris.response.PlacesResponse; import com.hamweather.aeris.util.FileUtil; import com.hamweather.aeris.util.WeatherUtil; public class OverviewFragment extends AerisFragment { ListView listView; ForecastAdapter adapter; private List<ForecastPeriod> periods; private TextView placeTextView; private TextView tempTextView; private ImageView iconImageView; private TextView weatherShortTextView; private TextView feelslikeTextView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_overview, container, false); listView = (ListView) rootView.findViewById(R.id.lvOverview); placeTextView = (TextView) rootView.findViewById(R.id.tvPlace); tempTextView = (TextView) rootView.findViewById(R.id.tvTemperature); iconImageView = (ImageView) rootView.findViewById(R.id.ivWeatherIcon); weatherShortTextView = (TextView) rootView .findViewById(R.id.tvWeatherShort); feelslikeTextView = (TextView) rootView.findViewById(R.id.tvFeelsLike); return rootView; } private void setObservation(Observation ob) { tempTextView.setText(WeatherUtil.appendDegree(ob.tempF)); weatherShortTextView.setText(ob.weatherShort); feelslikeTextView.setText("Feels like " + WeatherUtil.appendDegree(ob.feelslikeF)); iconImageView.setImageResource(FileUtil.getDrawableByName(ob.icon, getActivity())); } private void setPlace(Place place) { String temp = String.format("%s, %s, %s", place.name, place.state, place.country); placeTextView.setText(temp); } @Override public void onBatchResponse(AerisBatchResponse response) { if (listView == null) { return; } if (response.isSuccessful() && response.getError() == null) { ObservationResponse obResponse = new ObservationResponse( response.responses.get(0).getFirstResponse()); Observation ob = obResponse.getObservation(); setObservation(ob); PlacesResponse pResponse = new PlacesResponse(response.responses .get(1).getFirstResponse()); setPlace(pResponse.getPlace()); ForecastsResponse fResponse = new ForecastsResponse( response.responses.get(2).getFirstResponse()); periods = fResponse.getPeriods(); if (adapter == null) { adapter = new ForecastAdapter(periods, getActivity()); listView.setAdapter(adapter); } else { adapter.notifyDataSetChanged(); } } else { handleError(response.getError()); } } @Override void performRequest() { headlessFragment.performWeatherOverview(this); } @Override EndpointType getEndpointType() { return null; } @Override String getKey() { return HeadlessFragment.OVERVIEW; } }