Android Practice Project Report (summary)

Source: Internet
Author: User

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 Performance 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 performance 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

2 system 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 System Modules

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 System implementation

3.1 UI Interface Implementation

3.1.1 Main interface Implementation

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, define the TextView, button, Exittext, these three basic controls, which represent text display, button switch, text input TextView to show the nature of the software, button 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 Setting the Weather class weather

Set a weather class weather to query and display the weather.

3.2.1 Defining 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.

3.2.2 Constructor function

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.2.3 provides a method for fetching values

Using the method of reflection mechanism GetClass and SetClass, the method of obtaining weather specific data is provided.

3.3 Days Gas Query function realization

3.3.1 Interpreting 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 the 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).

3.3.2 Getting 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.4 Main Program implementation

3.4.1 Setting the Activity interface

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, where the drop-down bar spinner the adapter corresponding to the display list ListView binding. The corresponding list is as follows:

Main program Mainactivity

Activity_main interface

Currentcitytv

CurrentCity

City_et

Cityet

City_spr

Cityspinner

Mlistview

Mlistview

3.4.2 Show 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 inherits the Baseadapter class, when the ListView starts drawing, the system first calls the GetCount () function, according to his return is worth to the length of the ListView, and then according to that length, calls GetView () Draw each row one by one. GetItem returns the object itself, Getitemid returns the index of the object. GetView () has three parameters, position indicates that the first line will be displayed, Covertview is the layout inflate from the layout file, that 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.4.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

1. Enter the city in the text field

2. Select a city in the drop-down bar

3. Enter a city that does not exist in the input field

4. 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.

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.