Погода в городе
Weather | 3.4MB
Appendix "The weather in the city - Weather Viewer" free uses the REST-compliant Web services OpenWeatherMap.org for 16-day weather forecast for a specific city. The application retrieves the data in JSON format. The results are displayed in a ListView - the component to display a list that supports scrolling. In this application used a custom format for the entries:
- Weather icon
- Day of the week with a text description of the weather that day,
- The highest and the lowest temperature of the day (Celsius) and
humidity in percent.
To access the web service URL string has been converted into a URL object.
Then the URL object used to open HttpUrlConnection object, resulting in a call to a Web service through an HTTP request.
The application reads all the data from the stream InputStream class HttpUrlConnection and puts them in a line, and then converts the string in JSONObject for processing.
The application demonstrates how to organize the implementation of extensive operations outside the GUI thread and getting results in the GUI thread using AsyncTask objects. This is especially important for calls to web services, execution of which the time is not determined. Weather data is displayed in a ListView component, and the data for each ListView item delivered using subclass ArrayAdapter.
Show how to improve performance by using ListView pattern View-Holder, in which the representation of existing elements ListView used again when you exit the elements of the screen.
Finally, we use some means of material design of Android Design Support Library Library - TextInputLayout component leaves EditText hint on the screen even after the user started to enter text;
FloatingActionButton floating button is used to send user input data; Snackbar component displays an informational message to the user.
# REST-compliant Web services,
# Processing data in JSON format, JSONObject, JSONArray,
#ListView, ArrayAdapter, pattern View-Holder,