Weather Client Development Report
1 System Requirements Analysis
1.1 Functional Requirements Analysis
Weather forecast client, the most basic is to provide users with accurate weather information. There are two kinds of weather query results: One is the day weather information, information results more detailed, in addition to temperature, weather conditions can also prompt clothing advice, humidity, wind direction and other information, so that the weather information more perfect; one is the weather information for the next few days, to provide weather conditions for the next few days, convenient for the user's travel.
1.2 Non-functional requirements analysis
In order to ensure the long-term, safe, stable, reliable and efficient operation of the client, the weather client should meet the following requirements:
1) Accuracy and timeliness of system processing
2) Openness of the system and scalability of the system
3) Ease of use and serviceability of the system
4) Low resource consumption of the system
1.3 UML Use case diagram
|
Use case name: Menu interface |
|
Contributor: User |
|
Brief description: After the user selects the city, clicks the query, can display the weather information on the homepage |
|
Pre-conditions: Users have entered the weather query software |
|
Basic stream of events: 1. Enter the city name in the input field and click on the query to get the weather information for the city.
2. The user selects the city name in the drop-down bar, clicks the query, obtains the city weather information
3. Use case termination |
|
Other event streams: Enter or select any city name before clicking on the query to display no results |
|
Exception stream: When weather information gets failed, the interface prompts for error messages |
|
Post condition: Show city weather information within one week |
2 System Architecture Design
2.1 Interface Architecture
In combination with the user query habits, we can provide two kinds of query methods in the main interface:
1. Enter the query:
Enter the name of the city you want to query in the City input field and click the Query button to display the weather information.
2. Select the query:
For the common large and medium-sized cities, such as Beijing, Shanghai and so on, in order to facilitate user inquiries, as long as the default city in the dropdown bar to find the city users find, click the Query button to display the weather information.
The interface design drawing with Axure RP is as follows:
2.2 Function Modules
From the module structure diagram can be seen, background service is the core of the whole program, mainly data acquisition module, responsible for obtaining weather information from the Haoserver Weather Service interface. Background services can be started by querying the service.
3 Detailed system Design
3.1 UI Interface Design
3.1.1 Main interface Design
The Android user layout is in the layout in the XML file, these XML files are placed under the engineering/res/layout. In Android, the developer defines the user interface in an XML document, allowing the XML document to be dedicated to the user UI interface design, while the Java program is responsible for the implementation of the function, which reduces the program coupling and facilitates the maintenance and expansion of the program.
Most of the interface controls are in Android.view and android.widget packages, Android.view.View are their parent classes.
In the Activity.main main interface XML file, the TextView, button, Exittext, three basic controls are defined, which represent text display, button toggle, and text input, respectively. TextView is used to display the static text display, the button is used to control the "query" key, Exittext used to enter the queried city name.
The main interface XML file also defines the ListView, spinner, and LinearLayout, relativelayout layout files that require adapters. The ListView and spinner are used to display the list of weather query results, the cities in the dropdown, LinearLayout, Relativelayout, respectively, represent the linear layout and relative layout, and control the layout of the entire main interface.
3.1.2 Weather Content Interface implementation
In List_item. The format of the following table of weather results is displayed in the XML file through the settings of the LinearLayout layout file
|
Date |
Week |
|
Weather |
Tempt |
|
Wind |
|
Dressing_advice |
3.2 System Module Design
The entire system consists of four modules
|
System module |
module functions |
|
Constdata |
Store a preset city |
|
Weather |
Set the day and the next few days weather classes |
|
Chacun |
Parse and get weather information |
|
Mainactivity |
Weather Query Main interface |
3.2.1 Setting Weather class weather
Set a weather class weather to query and display the weather.
(1) Define private variables
Use private to define private members city, date, week, weather, temperature, wind, dressing_advice, so that users can not extract the weather data, can only be extracted according to their own construction method.
(2) Constructors
The use of overloaded constructors weather to create both parameters and non-parametric objects, which enhances the flexibility of the system. It is possible to use the reflection mechanism to generate objects and make it easy to invoke the weather class constructor with the ability to inherit.
(3) Provide a value method
Using the method of reflection mechanism GetClass and SetClass, the method of obtaining weather specific data is provided.
3.2.2 Weather Query function design
(1) Analysis of weather information
Weather forecast System The most important thing is to get the weather information, in order to get real-time weather information, we have to visit the special weather information on the website to resolve the information returned.
The system takes a httpurlconnection access method to contact the Web client and returns it as a byte array. The URLPath consists of three parts:
|
Information Source URL |
CityName |
Key |
The information source URL is provided by Haoservice service platform, CityName is the name of the queried city, and key represents the user identification.
I get weather information for a given city by http://apis.haoservice.com/weather the parameters provided by this website. It primarily uses the JSON (JavaScript object Notation) Data Interchange Format, which allows strings to be passed from the WEB client to the server side in an asynchronous application, with object objects and arrays of two data structures. An object is an unordered collection of "name/value pairs", which is an ordered collection of values (value).
(2) Get weather information
The parsed JSON-formatted weather data is assigned to the defined Todayweather class and we, which are instantiated weather class weather, which represent the day's weather information and future weather information, and finally add to the array list weathers. This will get the weather information.
3.2.3 Master Program Design
(1) Setting the Activity interface
Use the OnCreate method in activity to initialize the activity instance object, build the parameter saveinsancestate save the instance state.
The main program mainactivity with Activity_main layout via Setcontentview (R.layout.activity_main). Use the Findviewbyid function to correspond the main program button to the layout file one by one, the corresponding list is as follows:
|
Main program Mainactivity |
Activity_main interface |
|
Currentcitytv |
CurrentCity |
|
City_et |
Cityet |
|
City_spr |
Cityspinner |
|
Mlistview |
Mlistview |
The drop-down bar spinner the adapter corresponding to the display list ListView binding. The adapter connects the layout file to the data.
(2) Show The weather
For the weather results display list, the ListView binds an adapter Myadapter, and the ListView is displayed by myadapter.notifydatasetchanged notification mainactivity Update. The adapter Myadapter class diagram is as follows:
Adapter Myadapter is an instantiated myadapter that inherits the Baseadapter class. When the ListView starts drawing, the system first calls the GetCount () function, which is worth the length of the ListView according to his return, and then, based on that length, calls GetView () to draw each row one at a time. GetItem returns the object itself, Getitemid returns the index of the object. GetView () has three parameters: int position, View Convertview, ViewGroup parent. Position indicates that the first line will be displayed, Covertview is the layout inflate from the layout file, which is List_item. The layout in the XML file.
The use of Viewholder in the getView function is used to optimize the display efficiency, that is, the previously shown no longer read from the layout file, read directly from the cache. It is just a static class, its role is to reduce unnecessary calls to Findviewbyid, to thebottom of the control reference exists Viewholder inside, and then use Convertview.settag (Holder) put it in the view , next time you can use (Viewholder) Convertview.gettag () was taken directly.
(3) using handler to update weather information
The handler is in the same thread as the caller, and if the handler takes a time-consuming action, the caller thread blocks and the thread is unsafe. Therefore this procedure takes the calling thread thread (Runnable), which processes the operation in the threads. The thread thread issues an handler message, notifies the update, and handler handles the update based on the received message.
The thread thread sends MSG messages after querying the weather, and handler displays the query results based on the received message.
4 System Testing
4.1 Purpose of testing
1. Determine the quality of the software and ensure that the software runs correctly.
2. Determine the correctness of the information and ensure that the weather conditions are in accordance with actual.
4.2 Test Content
|
Number |
Permissions |
Test page |
Description / input / operation |
Expected results |
Real Results |
Note |
| "
|
None
|
List page
|
Enter city in text field |
Show Input city |
Show input city
|
Test diagram 1 |
|
02 |
Select a city in the drop-down bar |
Show Select City |
Show Select City |
Test Diagram 2 |
|
03 |
Enter the city in the text field
Click Query
|
Show input city and corresponding weather information |
Show input city and corresponding weather information |
Test Diagram 3 |
|
04 |
Select a city in the drop-down bar
Click Query
|
Show Select city and weather information |
Show Select city and weather information |
Test Diagram 4 |
|
05 |
Enter the non-existent city click Query in the input field |
Display query errors and their causes |
Display query errors and their causes: the city name is wrong or does not support the city |
Test Diagram 5 |
|
06 |
Do not enter city query
|
Display query errors and their causes |
Display query errors and their causes: query errors cannot be empty |
Test Diagram 6 |
1. Enter the city in the text field
2. Select a city in the drop-down bar
3. Enter the city in the Text field and click on the query
4. Select city from the dropdown and click on the query
5. Enter a city that does not exist in the input field
6. Do not enter city query
5 Summary
This experiment mainly completed the design and implementation of a weather forecast software based on the Android platform. This paper puts forward the method of designing, acquiring and parsing the city list data by the Android user interface, gives the principle and realization process in the user interface, and finally the debugging of the application through the simulator.
From the beginning, I don't know what to do. This software has been harvested a lot, mainly familiar with the Android environment, interface control layout, access to data and overall design solutions. The final implementation selects the city and displays the weather forecast result function. In the development of a lot of problems: the data source does not provide interface services, code is not strong enough, the JSON data display is incomplete, key expires, the final problem is resolved.
This program can achieve the same day and the next one weeks of weather forecast, there is good stability and scalability, but there are still many areas to be perfected, the future can be considered when the improvement of the time: to join the international city, according to the different weather conditions of the dynamic change background image; You can add the software to a small desktop window for easy query. These functions need to be explored in the future to establish a practical weather forecast system.
Thank Lou teachers and classmates to give me the help!
Android Practice Project Report (summary)-Modify