版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
大作业报告书课程名:Android开发题目:天气预报APP院系:数学与信息科学学院专业:计算机科学与技术班级:学生姓名:指导教师:职称:二○二一年六月摘要天气预报为人们了解天气状况和出行安排带来了方便,但是,大多数天气预报软件都是基于PC端,查询起来并不是很便捷。而随着智能手机的普及和网络技术的发展,手机端实现天气查询成为了可能,因此,实现手机端的天气预报系统成为了人们迫切需要且切实可行的需求。本设计使用Android设计技术开发了一种运用在Android系统上的手机天气预报软件系统,本系统通过选择城市来获得天气,风向,温度等信息。基于手机的天气预报系统软件可以使用户对于各地的天气情况的实时掌握,极大的方便了用户的出行和行程安排,避免了不必要的麻烦,具有很强的实用性。本论文首先进行了项目的背景介绍,开发的目的及意义,接着进行系统分析(包括需求分析、研究目标和内容),接着分析了Android系统的框架,然后介绍了本系统的用到的技术以及平台的搭建,最后论述了本系统的详细设计(包括功能模块设计、数据库设计等),接着进行了项目的测试用例分析,最后给出了结论以及展望。关键词:天气预报;Android;linux内核指导老师:xx
AbstractWeatherforecastforpeopletounderstandtheweatherconditionsandtravelarrangementshasbroughtconvenience,butmostoftheweatherforecastsoftwareisbasedonthePCterminal,queryisnotveryconvenient.Withthepopularizationofsmartphonesandthedevelopmentofnetworktechnology,ithasbecomepossibletorealizetheweatherqueryonmobilephones.Therefore,ithasbecomeanurgentandfeasibledemandtorealizetheweatherforecastsystemonmobilephones.ThisdesignusestheAndroiddesigntechnologytodevelopamobilephoneweatherforecastsoftwaresystem.Thissystemobtainsweather,winddirection,temperatureandotherinformationbyselectingthecity.Weatherforecastsystemsoftwarebasedonmobilephonecanhelpuserstograspthereal-timeweatherconditionsaroundtheplace,greatlyconvenientforuserstotravelanditineraryarrangement,avoidunnecessarytrouble,hasastrongpracticability.Thispaperfirstintroducesthebackgroundoftheproject,thepurposeandsignificanceofthedevelopment,andthencarriesoutthesystemanalysis(includingdemandanalysis,researchobjectivesandcontent).ThenitanalyzestheframeworkoftheAndroidsystem,andthenintroducesthetechnologyusedinthesystemandtheconstructionoftheplatform.Finally,thedetaileddesignofthesystem(includingfunctionalmoduledesign,databasedesign,etc.)isdiscussed,andthenthetestcaseanalysisoftheprojectiscarriedout.Finally,theconclusionsandprospectsaregiven.Keywords:Weatherforecast;Android.TheLinuxkernelInstructor:GongJin
前言手机是已经成为了生活中不可少的通信设备,没有手机有时会让人觉得寸步难行,手机将脱离传统的打电话,发短信等基本功能,而基于智能手机的处理能力和可扩展能力,基于网络高速数据传输,越来越多的功能和业务将被开发出来并大规模的应用。正基于此,当全世界的目光聚集在此的时候,Google于2007年11月5日宣布推出基于 linux平台的开源手机操作系统,号称首个为移动终端打造的真正开发和完整的移动软析android[1]。现有的移动互联网技术的快速发展,智能手机功能的不断增强,让基于Android平台的查询需求越来越多。本软件就是利用现有的网络快速获取网络上的天气信息并显示到手机终端上,为用户提供实时的天气查询和近期天气查询服务,为工作、出行等带来便利。本文的结构如下:第一章是绪论部分,叙述了本系统的开发背景、开发目标、开发意义以及国内外的一些比较。第二章介绍了本系统的开发环境及开发技术。第三章是系统需求分析与前台设计,阐述了在系统开发前的分析工作、系统的整体设计以及数据库设计。第四章是系统的详细设计与功能实现。第五章总结和展望,对整个项目的过程和感悟进行总结,并对项目未来的开发做出展望。
第一章绪论1.1研究背景天气是和人们的日常生活密不可分的一个话题,它关乎大家的日常出行、工作生活等方方面面。因此就要求我们能够对未来的天气有一定的预测来相应的安排我们的工作与生活,于是天气预报就应运而生。天气预报就是对未来时期内的天气变化的预先估计和报告。他是根据大气科学的基本理论和技术对每一地区的未来天气做出分析和预测,这是大气科学为国民经济建设和提升人民生活服务的重要手段,准确及时的天气预报对于经济建设和国防建设的趋利避害、保障人民生命财产安全等有极大的社会和经济效益。但是由于大气过程的混乱以及当今科学并没有最终透彻的了解大气过程,因此天气预报总是有一定的误差。既然天气关系到人们的日常生活,而且如今气象学上也有了能够较为准确的预测天气的技术,那为了进一步方便人们的工作生活及时获取天气信息也变得十分重要,移动端的天气预报软件便被开发出来了。天气预报软件是一种非常简单实用的信息服务软件。它方便易用且功能强大,能够提供各方面天气相关信息和贴心的出行建议等。目前国内基于Android的天气预报软件相当多且发展水平相当。这次课题设计的天气预报软件是一个操作简单、功能完善、界面美观、手机资源占用小的软件。通过这次天气预报软件的设计将自己学习到的知识运用到解决生活中遇到的实际问题当中去,充分了解一个安卓程序的开发的所有流程,熟练掌握JAVA语言和移动端软件开发方法,将大学四年所学的知识融会贯通。本次课题的研究希望能够通过天气预报软件的开发进一步的扩大气象信息的覆盖面,让广大人民能够在第一时间方便快捷地获取最新的气象预报信息,以便能够提前预防,把气象灾害造成的损失降到最低,同时也可以强化气象公共服务的职能,完善公共服务体系、改善公共服务手段、增加公共服务产品、提高公共服务质量,更好地发挥气象事业对经济社会发展的现实性作用。1.2设计目标应设计一个实用稳定的天气预报系统,在比较廉价的前提下使其能滿足大部分用户的需求。针对上述要求,本设计应满足如下条件:
(1)系统能及时反馈指定预报城市的天气情况;
(2)可以进行对使用者需要的城市天气进行查询;
(3)节省流量开销,按指定的时间间隔更新天气,其它时段则显示缓存的天气;
(4)操作方便快捷,界面设计美观大方;1.3本文结构本文的章节安排如下:第一章绪论部分,说明本文的研究背景和设计目标。为接下来的系统后台的分析与设计做基础准备。第二章背景技术,简单介绍系统实现所用到的平台与技术。如JavaSDK、Eclipse、AndroidSDK、ADT、SQLite等第三章系统分析与设计,对系统进行需求分析,根据需求分析设计相应的功能与表结构。第四章系统实现,给出系统后台的具体实现,包括实现效果和核心代码说明。第五章总结与展望,对本文所做的工作进行总结,并针对目前工作中的不足对未来工作的展望。
第二章系统开发环境与技术2.1系统开发环境简言之,需要以下软件,才能搭建Android开发环境,从而进行Android应用程序的开发。(1)JavaSDK(2)AndroidSDK(3)AndroidStudio(4)SQlite2.1.1SQlite介绍SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。SQLite第一个Alpha版本诞生于2000年5月。至今已经有12个年头,SQLite也迎来了一个版本SQLite3已经发布。不像常见的客户-服务器范例,SQLite引擎不是个程序与之通信的独立进程,而是连接到程序中成为它的一个主要部分。所以主要的通信协议是在编程语言内的直接API调用。这在消耗总量、延迟时间和整体简单性上有积极的作用。整个数据库(定义、表、索引和数据本身)都在宿主主机上存储在一个单一的文件中。它的简单的设计是通过在开始一个事务的时候锁定整个数据文件而完成的[9]。2.1.2SQlite特性(1)比一些流行的数据库在大部分普通数据库操作要快(2)简单,轻松的API(3)包含TCL绑定,同时通过Wrapper支持其他语言的绑定(4)良好注释的源代码,并且有着90%以上的测试覆盖率(5)独立:没有额外依赖(6)Source完全的Open,你可以用于任何用途,包括出售它(7)支持多种开发语言,C,PHP,Perl,Java,C#,Python,Ruby2.1.3SQlite功能SQLite虽然很小巧,但是支持的SQL语句不会逊色于其他开源数据库,它支持的SQL包括:ATTACHDATABASEBEGINTRANSACTIONCOMMENTCOMMITTRANSACTION等等。同时它还支持事务处理功能等等。也有人说它像Microsoft的Access,有时候真的觉得有点像,但是事实上它们区别很大。比如SQLite支持跨平台,操作简单,能够使用很多语言直接创建数据库,而不像Access一样需要Office的支持。如果你是个很小型的应用,或者你想做嵌入式开发,没有合适的数据库系统,那么你可以考虑使用SQLite。2.1.4SQlite类型SQLite的数据类型,首先你会接触到一个让你惊讶的名词:Typelessness(无类型)。对!SQLite是无类型的.这意味着你可以保存任何类型的数据到你所想要保存的任何表的任何列中,无论这列声明的数据类型是什么(只有在一种情况下不是,稍后解释)。对于SQLite来说对字段不指定类型是完全有效的。如:CreateTableex1(a,b,c);诚然SQLite允许忽略数据类型,但是仍然建议在你的CreateTable语句中指定数据类型。因为数据类型对于你和其他的程序员交流,或者你准备换掉你的数据库引擎时能起到个提示或帮助的作用[11]。2.2系统开发技术本软件是基于andriod的手机天气预报系统。首先天气预报功能是调用国家气象局的免费接口:本软件使用到的中国国家气象局天气预报接口总共有两个:/data/sk/101010100.html/data/101010100.html上面url中的101010100是城市代码,这里是北京的城市代码。只需要改变城市代码,就可以得到所在城市的天气信息。在浏览器上输入url:/data/sk/101010100.html得到信息,天气信息是json的数据格式。第一个接口主要是获取当天天气的具体信息,实时温度信息。第二个接口主要是获取当天及未来几天的粗略天气信息。2.2.1json数据解析:JavaScriptObjectNotation,但是独立于语言。类似XML,可以用来文本信息的存储和J交换,是数据的载体。从天气预报接口获得天气信息时需要对天气进行解析,解析出自己需要的天气信息。2.2.2Handler:Handler:主要接受子线程发送的数据,并用此数据配合主线程更新UI.当应用程序启动时,Android首先会开启一个主线程(也就是UI线程),主线程为管理界面中的UI控件,进行事件分发,比如说,要是点击一个Button,Android会分发事件到Button上来响应操作。如果此时需要一个耗时的操作,例如:联网读取数据,或者读取本地较大的一个文件的时候,不能把这些操作放在主线程中,如果放在主线程中的话,界面会出现假死现象,如果5秒钟还没有完成的话,会收到Android系统的一个错误提示“强制关闭”。这个时候需要把这些耗时的操作,放在一个子线程中,因为子线程涉及到UI更新,Android主线程是线程不安全的,也就是说,更新UI只能在主线程中更新,子线程中操作是危险的。这个时候,Handler就可以解决这个问题,由于Handler运行在主线程中(UI线程中),它与子线程可以通过Message对象来传递数据,Handler就承担着接受子线程传过来的(子线程用sedMessage)方法传弟)Message对象,(里面包含数据),把这些消息放入主线程队列中,配合主线程进行更新UI。Handler可以分发Message对象和Runnable对象到主线程中,每个Handler实例,都会绑定到创建他的线程中(一般是位于主线程),它有两个作用:安排消息或Runnable在某个主线程中某个地方执行;安排一个动作在不同的线程中执行。第三章系统概要分析3.1系统需求分析设计完成一个实用稳定的天气预报系统,同时要廉价使其能滿足大部分用户的需求,因此针对上述要本设计应滿足:(1)加载界面程序开始运行时显示加载界面,此界面是应用程序最先展现的窗口,应尽量保持界面信息简洁。(2)天气显示界面显示指定城市三天内的天气状况,包括日期、城市名称、温度、风力与当日的建议,用户可通过按菜单键来显示更新当前天气与设置天气显示的界面背景,以及跳转至设置预报城市界面来更换预报城市。(3)预报城市设置由用户通过可伸展性下拉列表单击选择系统数据库中预存的城市来进行设置,同时为了方便用户查找,支持以输入框的形式来过滤查询预报城市。当单击选中城市时跳转至天气显示界面,来显示该城市三天内的天气状况;在天气界面用户可通过菜单键选择城市,更新天气与更换背景,第一次运行时自动跳到该界面。3.2性能需求分析为了保证软件能够长期、安全、稳定、可靠、高效地在Android设备上运行,本系统应该满足以下原则。1.实用性原则该软件充分利用手机的网络,为本软件提供信息支持,在简洁实用的基础上对软件界面层级进行布局。2.可扩展性与可维护性原则系统设计尽可能模块化、组件化。有一个较好的应用平台——Android设备,能容易地安装和卸载。3.安全可靠性原则本软件是基于手机设备使用的,不会残留用户任何的隐私信息。4.用户界面美观原则界面经过对用户心理的调研并参考时下流行的软件风格进行设计,加入了对用户具有诱导性的按键设计。5.准确性原则本软件的核心技术是通过与互联网上提供的接口进行交互,保证了信息的准确性。6.易用性原则本软件平易近人,不需要额外学习,每个界面都会有不同含义的图标进行提示下一步操作,保证用户使用时不会感到迷惑。3.3系统前台简要设计概述该图3-3表示前台页面主菜单结构图:图3-3前台页面主菜单3.4系统用例图图3-2总体用例图图3-2-1选择城市用例图图3-2-2查询天气信息用例图图3-2-3分享天气信息用例图图3-2-4查询更多信息用例图3.5系统设计在这个系统中,总体结构可以用结构模块图表示出来,根据需求分析可以将系统分为以下两个模块:天气模块和城市模块,各个模块紧密联系,各个模块本身又是独立的,有自己的逻辑。如图3-5所示是系统的总体结构模块图,根据需求分析中对系统的功能进行分析,以及业务流程的分析可以得出这个系统的大概整体结构,以及其中的各个子模块。从系统的主界面开始,可以看到系统结构的顶层图有两个模块(天气模块和城市模块),再依据各个主模块功能进行分解,逐步划分出各个功能子模块,从而得出清晰的结构模块图,对系统的实现逻辑有很大的帮助。图3-5系统总体结构模块图3.6系统流程本系统的流程比较清晰,首先天气数据每更新一次,系统就会通过HTTP向指定的地址发出数据请求,若请求成功,则返回天气数据并通过JSON格式来解析数据,最终把解析到的数据显示在手机界面上。这样就完成了一次天气数据的更新,这一过程的流程图如图3-6所示:图3-6系统流程图图3-6-1选择城市流程图图3-6-2查询天气信息流程图图3-6-3分享天气信息流程图图3-6-4查询更多信息流程图3.7数据库设计3.7.1数据库概念设计图3-7-1天气信息E-R图图3-7-2省份E-R图图3-7-3城市E-R图图3-7-4地区E-R图3.7.2数据库逻辑设计本软件选择SQLite数据库作为数据存储的载体,建立数据库forecast.db,此数据库记录查询城市的天气信息,用户请求天气接口后将数据保存到本地,以便在无网的时候展示,建立一个info表数据库建立的info表如下:数据库字段字段名数据类型名称_idInteger城市ID(primarykey)cityvarchar城市名contenttext天气详情第四章系统详细设计与功能实现4.1系统项目的文件夹结构为了使代码文件结构更加清晰,工程设置了多个命名空间,分别保存了用户界面、常用类库和实体多个包Adapter适配器功能Base向数据库请求获取数据Bean应用实体Citymanager城市管理DB数据管理Utiljava集成包,里面包含事件模型、日期、时间设置、遗留的collections类Layout各个界面UI设计Mipmap存放各种小图标、背景图片Values各种参数统一定值4.2启动界面显示城市当前的实时天气状况,包括城市名称、城市名片、天气状况、温度高低、星期、风力、预测未来天气、24小时预报,风力等级等信息,同时界面下方有生活指数信息提供出行建议activity_main.xml<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="/apk/res/android"android:id="@+id/main_out_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#88000000"><ImageViewandroid:id="@+id/bing_pic_img"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="centerCrop"android:src="@mipmap/night"/><Buttonandroid:id="@+id/btn_cut"android:layout_width="30dp"android:layout_height="30dp"android:scaleType="centerCrop"android:layout_alignParentRight="true"android:layout_marginRight="10dp"android:background="@mipmap/share"/><ImageViewandroid:clickable="true"android:id="@+id/main_share_weather"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginRight="10dp"android:visibility="gone"android:src="@mipmap/share"/><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="42dp"android:layout_alignParentTop="true"android:visibility="gone"></RelativeLayout><RelativeLayoutandroid:id="@+id/main_bottom_layout"android:layout_width="match_parent"android:layout_height="42dp"android:background="#66000000"android:layout_alignParentBottom="true"><ImageViewandroid:id="@+id/main_iv_add"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_marginLeft="10dp"android:src="@mipmap/city_icon"/><ImageViewandroid:id="@+id/main_iv_more"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_alignParentRight="true"android:layout_marginRight="10dp"android:src="@mipmap/menu"/><LinearLayoutandroid:id="@+id/main_layout_point"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:orientation="horizontal"></LinearLayout></RelativeLayout><androidx.viewpager.widget.ViewPagerandroid:id="@+id/main_vp"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@id/main_bottom_layout"></androidx.viewpager.widget.ViewPager></RelativeLayout>fragment_city_weather.xml<?xmlversion="1.0"encoding="utf-8"?><ScrollViewxmlns:android="/apk/res/android"android:id="@+id/out_layout"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:id="@+id/frag_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#33000000"android:orientation="vertical"><ImageViewandroid:id="@+id/bing_pic_img"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="centerCrop"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="#66000000"android:orientation="vertical"><TextViewandroid:id="@+id/frag_tv_city"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="2dp"android:text="南昌"android:textColor="@color/main_background"android:textSize="22sp"/><TextViewandroid:id="@+id/frag_tv_date"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="2019-11-05"android:textColor="@color/main_background"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="80dp"android:gravity="left"><TextViewandroid:id="@+id/frag_tv_currenttemp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom"android:layout_marginLeft="20dp"android:text="29°"android:textColor="@color/main_background"android:textSize="80sp"/><TextViewandroid:id="@+id/frag_tv_condition"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom"android:text="多云"android:textColor="@color/main_background"android:textSize="25sp"/><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="5dp"android:layout_marginBottom="10dp"><TextViewandroid:id="@+id/frag_tv_wind"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="12dp"android:drawableLeft="@mipmap/icon_wind"android:drawablePadding="2dp"android:text="西南风2级"android:textColor="@color/main_background"android:textSize="17sp"/><TextViewandroid:id="@+id/frag_tv_humidity"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="12dp"android:drawableLeft="@mipmap/icon_humidity"android:drawablePadding="2dp"android:text="湿度75%"android:textColor="@color/main_background"android:textSize="17sp"/><TextViewandroid:id="@+id/frag_tv_temprange"android:layout_width="wrap_content"android:layout_height="wrap_content"android:drawableLeft="@mipmap/icon_pressure"android:drawablePadding="2dp"android:text="气压1002hPa"android:textColor="@color/main_background"android:textSize="17sp"/></LinearLayout><TextViewandroid:id="@+id/frag_tv_tips"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_margin="10dp"android:text="天暗下来,你就是阳光~"android:textSize="20sp"android:visibility="gone"/></LinearLayout><!--兵哥24小时预报--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/frag_bg"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="10dp"android:text="24小时预报"android:textColor="@color/main_background"android:textSize="16sp"android:textStyle="bold"/><Viewandroid:layout_width="match_parent"android:layout_height="0.3dp"android:background="@color/main_background"/><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recycler_view"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="5dp"/></LinearLayout><!--兵哥用于显示未来七天的天气情况--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/frag_bg"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="10dp"android:text="未来三天"android:textColor="@color/main_background"android:textSize="16sp"android:textStyle="bold"/><Viewandroid:layout_width="match_parent"android:layout_height="0.3dp"android:background="@color/main_background"/><!--显示七天的线性布局--><LinearLayoutandroid:id="@+id/frag_center_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:padding="10dp"></LinearLayout></LinearLayout><!--用于表示指数信息的线性布局--><LinearLayoutandroid:id="@+id/frag_index_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/frag_bg"android:orientation="vertical"><TextViewstyle="@style/indextext"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="left"android:padding="10dp"android:text="生活指数"/><Viewandroid:layout_width="match_parent"android:layout_height="0.3dp"android:background="@color/main_background"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:padding="16dp"><TextViewandroid:id="@+id/frag_index_tv_dress"style="@style/indextext"android:drawableTop="@mipmap/icon_cloth1"android:text="穿衣炎热"/><TextViewandroid:id="@+id/frag_index_tv_washcar"style="@style/indextext"android:drawableTop="@mipmap/xicar"android:text="洗车不宜"/><TextViewandroid:id="@+id/frag_index_tv_cold"style="@style/indextext"android:drawableTop="@mipmap/cold"android:text="感冒易发"/></LinearLayout><!--<ImageViewandroid:layout_width="match_parent"android:layout_height="2dp"android:background="#2E8B57"/>--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:padding="18dp"><TextViewandroid:id="@+id/frag_index_tv_sport"style="@style/indextext"android:drawableTop="@mipmap/sports"android:text="运动较不宜"/><TextViewandroid:id="@+id/frag_index_tv_rays"style="@style/indextext"android:drawableTop="@mipmap/light1"android:text="紫外线强"/><TextViewandroid:id="@+id/frag_index_tv_umbrella"style="@style/indextext"android:drawableTop="@mipmap/icon_yusan"android:text="雨伞不带伞"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:padding="16dp"><TextViewandroid:id="@+id/frag_index_tv_fish"style="@style/indextext"android:drawableTop="@mipmap/ico_fish"android:text="钓鱼较不宜"/><TextViewandroid:id="@+id/frag_index_tv_traffic"style="@style/indextext"android:drawableTop="@mipmap/icon_traffic"android:text="交通较不宜"/><TextViewandroid:id="@+id/frag_index_tv_tourism"style="@style/indextext"android:drawableTop="@mipmap/icon_tourism"android:text="旅游较不宜"/></LinearLayout></LinearLayout></LinearLayout></ScrollView>privatevoidparseShowData(Stringresult)throwsParseException{//使用gson解析数据WeatherBeanweatherBean=newGson().fromJson(result,WeatherBean.class);WeatherBean.DataBeanresultsBean=weatherBean.getData();index=resultsBean.getIndex();//设置TextViewcityTv.setText(city);tipTv.setText(resultsBean.getTips().getObserve().get_$0());//获取今日天气情况WeatherBean.DataBean.ObserveBeantodayDataBean=resultsBean.getObserve();//获取天气图标代码/*Stringweather_code=todayDataBean.getWeather_code();StringimgUrl="/pingjs/ext2020/weather/pc/icon/currentweather/day/"+weather_code+".png";Glide.with(this.getActivity()).load(imgUrl).into(dayIv);*///兵clothIndexTv,//carIndexTv,coldIndexTv,sportIndexTv,raysIndexTv,tipTv,umbrellaTv,fishTv,traffic,lunarclothIndexTv.setText("穿衣"+index.getClothes().getInfo());coldIndexTv.setText("感冒"+index.getCold().getInfo());sportIndexTv.setText("运动"+index.getSports().getInfo());raysIndexTv.setText("紫外线"+index.getUltraviolet().getInfo());umbrellaTv.setText("雨伞"+index.getUmbrella().getInfo());fishTv.setText("钓鱼"+index.getFish().getInfo());traffic.setText("交通"+index.getTraffic().getInfo());carIndexTv.setText("洗车"+index.getCarwash().getInfo());tourism.setText("旅游"+index.getTourism().getInfo());Stringtime=changeTime(todayDataBean.getUpdate_time());dateTv.setText("发布时间"+time);windTv.setText(resultsBean.getForecast_24h().get_$1().getDay_wind_direction()+""+todayDataBean.getWind_power()+"级");humidityTv.setText("湿度"+todayDataBean.getHumidity()+"%");tempRangeTv.setText("气压"+todayDataBean.getPressure()+"hPa");conditionTv.setText(todayDataBean.getWeather_short());//获取实时天气温度情况,需要处理字符串tempTv.setText(todayDataBean.getDegree()+"°");//获取未来三天的天气情况,加载到layout当中WeatherBean.DataBean.Forecast24hBeanfutureList=resultsBean.getForecast_24h();//================今天ViewitemView=LayoutInflater.from(getActivity()).inflate(R.layout.item_main_center,null);itemView.setLayoutParams(newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));futureLayout.addView(itemView);TextViewidateTv=itemView.findViewById(R.id.item_center_tv_date);TextViewiconTv=itemView.findViewById(R.id.item_center_tv_con);TextViewitemprangeTv=itemView.findViewById(R.id.item_center_tv_temp);TextViewwind=itemView.findViewById(R.id.item_center_tv_winddirection);//获取对应的位置的天气情况idateTv.setText(futureList.get_$1().getTime().substring(5).replace("-","/")+""+"今天");iconTv.setText(futureList.get_$1().getDay_weather());wind.setText(futureList.get_$1().getDay_wind_direction());itemprangeTv.setText(futureList.get_$1().getMin_degree()+"~"+futureList.get_$1().getMax_degree()+"°C");//================今天ViewitemView0=LayoutInflater.from(getActivity()).inflate(R.layout.item_main_center,null);itemView.setLayoutParams(newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));futureLayout.addView(itemView0);TextViewidateTv0=itemView0.findViewById(R.id.item_center_tv_date);TextViewiconTv0=itemView0.findViewById(R.id.item_center_tv_con);TextViewitemprangeTv0=itemView0.findViewById(R.id.item_center_tv_temp);TextViewwind0=itemView0.findViewById(R.id.item_center_tv_winddirection);//获取对应的位置的天气情况idateTv0.setText(futureList.get_$2().getTime().substring(5).replace("-","/")+""+DateUtil.dateToWeek(futureList.get_$2().getTime()));iconTv0.setText(futureList.get_$2().getDay_weather());wind0.setText(futureList.get_$2().getDay_wind_direction());itemprangeTv0.setText(futureList.get_$2().getMin_degree()+"~"+futureList.get_$2().getMax_degree()+"°C");ViewitemView3=LayoutInflater.from(getActivity()).inflate(R.layout.item_main_center,null);itemView.setLayoutParams(newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));futureLayout.addView(itemView3);TextViewidateTv3=itemView3.findViewById(R.id.item_center_tv_date);TextViewiconTv3=itemView3.findViewById(R.id.item_center_tv_con);TextViewitemprangeTv3=itemView3.findViewById(R.id.item_center_tv_temp);TextViewwind3=itemView3.findViewById(R.id.item_center_tv_winddirection);//获取对应的位置的天气情况idateTv3.setText(futureList.get_$3().getTime().substring(5).replace("-","/")+""+DateUtil.dateToWeek(futureList.get_$3().getTime()));iconTv3.setText(futureList.get_$3().getDay_weather());
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 商品选品员岗位适应能力知识考核试卷含答案
- 水解酵母分离工安全实操强化考核试卷含答案
- 修笔工安全防护知识考核试卷含答案
- 化工自动控制技术员岗中可持续发展考核试卷含答案
- 装配式建筑施工员安全管理水平考核试卷含答案
- 职业发展规划师指导手册
- 消防安全与灭火技术
- 普通货运公司实习报告
- 变电站直流系统安装施工方案
- 危险化学品经营企业焊工检修维修安全操作规程
- R-R(X-R)控制图的模板
- 口腔医患沟通工作制度
- 八年级田径下压式接力跑课后反思和点评
- CB37安全技术交底(钻孔灌注桩)
- C语言试讲演示文稿
- 绝缘珊场效应管MOS课件
- 寺庙建设项目立项可行性研究报告
- MLCC配料工序工艺基础知识及设备培训课件
- GB/T 26202-2010纸管纸板
- GB/T 24218.1-2009纺织品非织造布试验方法第1部分:单位面积质量的测定
- 远景培训学习1-风机检修基础
评论
0/150
提交评论