Android Programming Weather Forecast Small instance source demo and effect display--1

Source: Internet
Author: User

Many times we go out, but because there is no control of the weather conditions, often encountered distress, become drowned, today I will take everyone to write

A weather report on the Android APP, I will be in detail to divide it into several parts to explain in detail, I hope you like the top one,

At the same time, I hope more people to join my blog, learn together, communicate together, progress together, thank you!


If you have free time after you finish the weather report, you can talk about File Manager and other useful app development, so that we could learn and communicate


Before the development of the weather forecast, the first to prepare a weather information to get the API key, here, I recommend a URL to you, more practical

Key application Address: HTTP://WWW.WUnderground. com

After getting the key we can start our development, in order to make our interface look more streamlined and beautiful, I used the Android.support.v4.jar third-party library Picasso-2.2.0.jar, No child shoes can go to HTTP// download.csdn.net/detail/jspping/8084689 self-download


After downloading them to the Project Libs folder, no one can create a new libs on their own, after the creation of an Android project, then start our programming bar, first we want to add the corresponding permissions to our application in the manifest file XML, We need to use the network access, network status, GPS permissions, etc., the configuration list is as follows:

    <uses-permission android:name= "Android.permission.INTERNET"/>    <uses-permission android:name= " Android.permission.ACCESS_NETWORK_STATE "/>    <uses-permission android:name=" android.permission.RECEIVE_ Boot_completed "/>    <!--GPS, network-to     <uses-permission android:name=" android.permission.ACCESS_ Fine_location "/>    <uses-permission android:name=" Android.permission.ACCESS_COARSE_LOCATION "/>

Right configuration, began programming, the author here to application added a welcome Animation, in order to give users a more friendly experience, the following look at the code:

Package com.newer.myweather;/** * Animation Welcome animation * @author Engineer-jsp * @date 2014.10.27 * */import android.app.Activity ; import Android.app.alertdialog;import Android.app.alertdialog.builder;import android.content.ComponentName; Import Android.content.dialoginterface;import Android.content.dialoginterface.onclicklistener;import Android.content.intent;import Android.content.pm.packageinfo;import Android.content.pm.packagemanager.namenotfoundexception;import Android.net.connectivitymanager;import Android.net.networkinfo;import Android.os.bundle;import Android.os.handler;import Android.view.animation.alphaanimation;import Android.widget.linearlayout;import Android.widget.TextView;public Class Splashactivity extends Activity {private TextView versionnumber;private linearlayout mlinearlayout;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.splash); mlinearlayout = (linearlayout) Findviewbyid (r.id.linearlayout01); versionnUmber = (TextView) Findviewbyid (R.id.versionnumber); Versionnumber.settext (GetVersion ()); if (isnetworkconnected ()) { Alphaanimation AA = new Alphaanimation (0.5f, 1.0f); aa.setduration (+); mlinearlayout.setanimation (AA); Mlinearlayout.startanimation (AA);//animation thread, with jump delay set, I am here to set 3000ms, i.e. 3 seconds new Handler (). postdelayed (New Runnable () {@ overridepublic void Run () {//Start weather services Intent service = new Intent (splashactivity.this,weatherservice.class); StartService (service);//Welcome to the end of the animation jump to the main activity intent intent = new Intent (Splashactivity.this,mainactivity.class); StartActivity ( Intent);}}, 3000);}    else {showsetnetworkdialog ();}} Pop-up network status window private void Showsetnetworkdialog () {Alertdialog.builder builder = new Builder (this); Builder.settitle ("Set up network Builder.setmessage ("Network error Check network status"), Builder.setpositivebutton ("Set Network", new Onclicklistener () {public void OnClick ( Dialoginterface dialog, int which) {Intent Intent = null;//Judging the version of the mobile phone system is the API greater than 10 is 3.0 or later if (Android.os.Build.VERSION.SDK _int >) {intent = new INTENT (Android.provider.Settings.ACTION_WIRELESS_SETTINGS);} else {intent = new intent (); ComponentName component = new ComponentName ("Com.android.settings", "com.android.settings.WirelessSettings"); Intent.setcomponent (component); Intent.setaction ("Android.intent.action.VIEW");} StartActivity (intent); Finish ();}); Builder.setnegativebutton ("Cancel", new Onclicklistener () {public void OnClick (Dialoginterface dialog, int which) {finish () ;}});    Builder.create (). Show (); Network status Condition Private Boolean isnetworkconnected () {Connectivitymanager manager = (Connectivitymanager) getsystemservice ( Connectivity_service); Networkinfo networkinfo = Manager.getactivenetworkinfo (); return (Networkinfo! = null &&    Networkinfo.isconnected ());} Take the version number private String getversion () {try {packageinfo info = Getpackagemanager (). Getpackageinfo (Getpackagename (), 0); Return "Version" + info.versionname;} catch (Namenotfoundexception e) {e.printstacktrace (); return "Version";}}}

Load the Splash.xml code:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/linearlayout01" Android:layout_width= "Fill_parent" android:layout_height= "fill_parent" android:background= "@drawable/home_ Gradiend "android:gravity=" center "android:orientation=" vertical "> <imageview android:id=" @+id/logo        "Android:layout_width=" 150DP "android:layout_height=" 150DP "android:layout_margintop=" 60dip " android:paddingleft= "20dip" android:paddingright= "20dip" android:scaletype= "Centerinside" android:src = "@drawable/logo" > </ImageView> <textview android:layout_width= "Wrap_content" Android:lay out_height= "Wrap_content" android:layout_margintop= "20dip" android:gravity= "Bottom" android:shadowcol Or= "#FFFFFF" android:shadowdx= "0" android:shadowdy= "2" android:shadowradius= "1" android:text= " @string/app_name "Android:textcoloR= "#444444" android:textsize= "35dip" android:typeface= "serif" > </TextView> <textview         Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_margintop= "20dip" android:gravity= "Bottom" android:shadowcolor= "#FFFFFF" android:shadowdx= "0" android:shadowdy= "2" android:shadowradius= "1" android:text= "(Weather forecast client)" android:textcolor= "#444444" Android:text Size= "25dip" android:typeface= "serif" > </TextView> <textview android:id= "@+id/versionnumb Er "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:layout_margintop = "20dip" android:gravity= "Bottom" android:shadowcolor= "#FFFFFF" android:shadowdx= "0" android:s Hadowdy= "2" android:shadowradius= "1" android:text= "version number" android:textcolor= "#444444" Android:te Xtsize= "20dip" android:typeface= "serif" > </TextView></LinearLayout> 

Welcome Screen display:


Before entering the activity and the service, will judge the user's current network status, if the user current network status is not good, or no network, will pop up the network setting interface for the user to choose, if the network is not a problem, after playing this animation, will start an intention to open the service, jump to the main activity

The next article will explain the service and the use of the main activities, this content is not a lot of knowledge, good digestion, we continue to say

Android Programming Weather Forecast Small instance source demo and effect display--1

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.