Ultimate quasi-materialized air quality Detector for Android

Source: Internet
Author: User

Disclaimer: Please indicate the source for reprinting this article! Source creative from: https://play.google.com/store/apps/details? Id = us. bestapp. PM25

Source: http://download.csdn.net/detail/weidi1989/5789763

(The source code is packaged Based on the Eclipse project and UTF-8 encoding. If you encounter an import error, please contact du Niang or Gu Ge for help. Thank you for your cooperation !)


Today, I would like to share with you a heavyweight little tool, which can be said to be extremely materialized. Although the function is simple, the effect is very realistic and cool! Let's step on it ~

Let's take a look:

1. display the current AQI in Beijing. You can use the next key to switch between AQi and PM2.5 values.

2. Click print, and a quality inspection report will be displayed in the same animation as the printer. We can also click the share button to share it with our friends.

3. You can slide the paper and have a realistic tear sound. (Note: The following machines in android3.0 do not support Paper Tearing)

4. Long press print to display the feedback interface. Please fill in what you want to say, and then confirm with the Enter key on the soft keyboard. The feedback will be sent to me via email.

 

 


Description
It provides real-time query of air quality monitoring data from 76 cities (509 monitoring sites in total) in China to provide guidance for healthy living. Supports sharing to social networks.
Operation prompt]
* Press Next: Switch to display the "AQI Index" and "PM2.5 concentration value]
* Print by print: print the air quality details
* Long press Next: enter the city selection mode
*......
* For more operations, explore the following:
I forgot when to start and use color to represent the air;
I don't know when I can use sweetness to describe the air.
PM2.5 air quality monitor is so simple and exquisite!


Well, the next focus to tell you about the source code, in fact, the function is very simple, is the quasi materialized animation effect spent a little thought, here, I introduced the third-party library of nineoldandroids-2.4.0.jar, some animations are not supported in Apis below android3.0.

Let's take a look at the source code structure:

 

In this example, all animations are encapsulated in a class. Let's take a look:

/*** Therefore, the animation encapsulation uses the animator, animatorset, and objectanimator *** @ author way **/public final class pm25anim {/*** horizontal translation animation ** in the third-party package nineoldandroids ** @ Param view * @ Param x * @ return */public static animator add (final view, float X) {objectanimator = objectanimator. offloat (View, "translationx", new float [] {X, 0.0f}); objectanimator. setduration (1000l); objectanimator. addlistener (New animator. animatorlistener () {public void Merge (animator merge) {} public void onanimationend (animator) {} public void Merge (animator) {} public void onanimationstart (animator) {view. setvisibility (view. visible) ;}}); Return objectanimator ;} /*** move the animation downward from the origin ** @ Param view * the view to be added to the animation * @ Param y * The axis coordinate to be moved * @ return the animation object animator */public static animator down (view, float y) {objectanimator localobjectanimator = objectanimator. offloat (View, "translationy", new float [] {0.0f, y}); localobjectanimator. setduration (2000l); Return localobjectanimator ;} /*** move up from the Y axis origin to the specified y coordinate ** @ Param view * view to be added to the animation * @ Param y * end y axis coordinate * @ return animation object animator */Public static animator up (view, float y) {objectanimator = objectanimator. offloat (View, "translationy", new float [] {0.0f, y}); objectanimator. setduration (2000l); Return objectanimator ;} /*** move up the animation ** @ Param view * view to be added to the animation * @ Param fromy * Start Y axis coordinate * @ Param toy * terminate Y axis coordinate * @ return the animation object animator */public static animator up (view, float fromy, float toy) {objectanimator = objectanimator. offloat (View, "translationy", new float [] {fromy, toy}); objectanimator. setduration (2000l); Return objectanimator ;} /*** move up and gradually disappear ** @ Param view * the distance between the view to be added to the animation * @ Param y * move up * @ return animation object animator */public static animator upandvanish (view, float y) {animatorset = new animatorset (); animator [] arrayofanimator = new animator [2]; float [] floats = new float [2]; floats [0] = y; floats [1] = (3.0f * Y); arrayofanimator [0] = objectanimator. offloat (View, "translationy", floats); arrayofanimator [1] = objectanimator. offloat (View, "Alpha", new float [] {1.0f, 0.0f}); animatorset. playtogether (arrayofanimator); animatorset. setduration (2000l); Return animatorset ;}}


Then we instantiate these animations in our pm25activity, including printing paper, simulating downward movement of the image, and tearing up the paper (I only paste part of the animation code here ):

Mbodytranslate = pm25anim. down (this. mbodylayout, getresources (). getdimension (R. dimen. paper_anim_down); // when the paper is printed, the animation mpaperuptitle = pm25anim is moved down. up (this. mpaperlayout, getresources (). getdimension (R. dimen. paper_anim_up_one); // when a title is first printed, the paper moves up to the animation mpaperupall = pm25anim. up (this. mpaperlayout, getresources (). getdimension (R. dimen. paper_anim_up_one), getresources (). getdimension (R. dimen. paper_anim_up_two); // print the up animation mfeedbacksended = pm25anim. upandvanish (this. mpaperlayout, getresources (). getdimension (R. dimen. paper_anim_up_two); // when the feedback message is sent, the paper gradient animation mbodyreset = pm25anim. up (this. mbodylayout, getresources (). getdimension (R. dimen. paper_anim_down), 0.0f); // restores the upward animation when the paper is torn off.

OK, the animation effect is summarized here. Next we will analyze the principle of automatic positioning: currently, most domestic software positioning systems use Baidu lightweight package positioning directly, this is also true for the simple weather I used. Here, I use Google positioning to find a new way, a new mood, and a more skillful way. The main method is to use the provider available on the mobile phone, including passive_provider, network_provider, and gps_provider. Select an optimal method to locate the location, obtain the coordinates of the current location, and then send an HTTP request, get the current city name, for example: http://maps.googleapis.com/maps/api/geocode/json? Latlng = 22.5329294, 114.019329 & sensor = true. We can replace the latlng parameter with the geographical coordinates obtained by the mobile phone to obtain the city name. Although it is more troublesome than the Baidu jar package, but it is also the most primitive method. When we access this website through the webpage, we find that a lot of data is returned, which requires resolution. Here I also post the code for parsing the city:

JSONArray jsonArray = new JSONObject(result).getJSONArray("results").getJSONObject(0).getJSONArray("address_components");for (int i = 0; i < jsonArray.length(); ++i) {JSONObject jsonObject = jsonArray.getJSONObject(i);String types = jsonObject.getJSONArray("types").toString();if ((types.contains("locality"))&& (types.contains("political"))&& (!types.contains("sublocality"))) {Log.d(LogTag, jsonObject.toString());city = jsonObject.getString("short_name");Log.d(LogTag, city);}}

In addition, in fact, we can also http request Baidu server, the geographic coordinate conversion into a city, I here only mention, the Resolution Principle is similar, are returned data in JSON format: http://api.map.baidu.com/geocoder/v2? Ak = 1919b4b56ae680127f8d1dfa5f7244d9 & location = 22.5329294, 114.019329 & Output = JSON.


OK, this is the general content of this article. If you have any children's shoes, you can download the source code for reference. Finally, we will remind you that due to time and manpower problems, bugs are inevitable. Currently we know bugs:

1. click the button frequently, including long press and short press, which can cause confusion of Boolean flag spaces.

2. When the paper is torn, if the paper angle is large and it remains on the touch screen, the paper will rotate cyclically.

3. Occasionally, the animation gets stuck.

4. The screen resolution may be unsuitable.

5 .......


Related Article

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.