package com.example.finalexamcovid_19situations;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class wuZiXuan1 extends AppCompatActivity {
Button button,button2,button3,button4,button5;
//爬取绘图和json的变量
JSONArray historyListJson;
String url="https://news.sina.com.cn/project/fymap/ncp2020_full_data.json" +
"?_=1653210512520&callback=jsoncallback";//新浪疫情数据的网址,要确定虚拟机有网
JSONArray cityData;
//北京 上海 广州 深圳 成都 重庆 杭州 武汉 青岛 天津 东莞
int [][] cityIndex={{1}, {15}, {3, 3}, {3, 4}, {9, 3},
{7}, {4, 3},{2, 3}, {10, 4},{23},
{3, 5}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wu_zi_xuan1);
//调取爬取函数,并创建数据库
volleyRequest();
button=(Button) findViewById(R.id.button5);
button2=(Button) findViewById(R.id.button3);
button3=(Button) findViewById(R.id.button11);
button4=(Button) findViewById(R.id.button2);
button5=(Button) findViewById(R.id.button22);
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//调取爬取函数,更新数据库
volleyRequest();
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(wuZiXuan1.this,maDaWei.class);
startActivity(intent);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(wuZiXuan1.this,jiangYongKe.class);
startActivity(intent);
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(wuZiXuan1.this,liuJiaQi.class);
startActivity(intent);
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(wuZiXuan1.this,wuZiXuan2.class);
startActivity(intent);
}
});
}
//volley爬取网页
void volleyRequest(){
/*
创建一个请求队列,不能直接在代码开始那边创建,会报错
volley是一个和线程有关的函数,所以相关代码最简单的是写道volley里面
我个傻子,非想把volley和string转换json代码分开写,浪费了很多时间
*/
//爬取代码
StringBuffer stringBufferData=new StringBuffer();
RequestQueue requestQueue= Volley.newRequestQueue(wuZiXuan1.this); //创建RequestQueue放Request类
/*
新浪json代码有一个函数,volley不能直接爬取json所以使用stringRequest爬取,
用StringBuffer删除函数,用jsonObject转json
*/
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, //创建stringRequest爬取url
new Response.Listener<String>() {
@Override
public void onResponse(String response) { //将赋值stingData,方便之后判空减少等待
//将爬取的新浪string转标准格式json
stringBufferData.append(response); //将string放到stringBuffer中方便处理
stringBufferData.delete(0,13); //删除前14个字符
stringBufferData.delete(stringBufferData.length()-2,stringBufferData.length()); //删除后四个字符
try {
//转化String为JSONObject,并提取历史记录到historyListJson
JSONObject jsonData =new JSONObject(stringBufferData.toString());
JSONObject dataJson=jsonData.getJSONObject("data");
historyListJson=dataJson.getJSONArray("historylist");
//城市爬取
//jsonStr转json
// cityIndexJson=new JSONArray(jsonStr);
cityData=dataJson.getJSONArray("list");
String[][] data=new String[cityIndex.length][2];
for (int i = 0; i<cityIndex.length; i++) {
//现有econNum,增加conadd
if (cityIndex[i].length==1){
data[i][0]=cityData.
getJSONObject(cityIndex[i][0]-1).
get("econNum").toString();
data[i][1]=cityData.
getJSONObject(cityIndex[i][0]-1).
get("conadd").toString();
}else {
data[i][0]=cityData.getJSONObject(cityIndex[i][0]-1).
getJSONArray("city").
getJSONObject(cityIndex[i][1]-3).
get("econNum").toString();
data[i][1]=cityData.getJSONObject(cityIndex[i][0]-1).
getJSONArray("city").
getJSONObject(cityIndex[i][1]-3).
get("conadd").toString();
}
}
openOrCreateCitySQL("china.db","city");
insertCitySQL("china.db","city",data);
} catch (JSONException e) {
e.printStackTrace();
}
String[][] data=getRecentDays(historyListJson,7);
openOrCreateSQL("china.db","total");
insertSQL("china.db","total",data);
// String[][] ii= querySQL("china.db","total");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// textView.setText("爬取错误");
Toast.makeText(wuZiXuan1.this, "获取数据失败!", Toast.LENGTH_SHORT).show();
}
});
//将创建的string请求添加到请求队列当中
requestQueue.add(stringRequest);
}
//已摸清json的省份序列,并写出了json文件见sfxx.json
//todo 寻找以下省份代码和城市代码,并构建string二维数组
//北京、上海、广州、深圳 成都、重庆、杭州、武汉、西安、郑州、青岛、长沙、天津、苏州、南京、东莞、沈阳、合肥、佛山
//1,1 15,1 3,3
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用Android Studio开发的Android端疫情数据整合系统 安装教程: 1.开发者可下载后使用Android studio进行代码调试,项目api为21 2.release内有编译好的安装包,下载后即可安装 功能介绍 欢迎界面 实在找不到广播的使用,只能使用欢迎界面进行广播的显示。 刷新疫情数据 虽然进入软件后会自动刷新数据,但不排除从无网络到有网络的切换的问题,所以增加了手动刷新按钮。 全国疫情走势 点击后进入数据显示的选择界面,可供选择项有感染总人数和新增感染总人数。选择一项后点击查看疫情折线图即可查看疫情数据。 各大城市疫情 在此界面有很多以城市为名字的按钮,点击后会出现相应城市的Toast显示当前城市的感染总人数和新增感染总人数。关于更多按钮:由于新浪的数据不匹配,需要人工进行json数据分析,工程量太大,因此敬请期待。 摇一摇祈福 在该页面可以摇一摇进行祈福,摇一摇后会出现Toast进行提示。该部分的编程者刘佳奇做出了很花哨的界面效果,但是由于有些许bug所以进行了阉割。
资源推荐
资源详情
资源评论
收起资源包目录
用Android Studio开发的Android端疫情数据整合系统源码.zip (78个子文件)
android-covid_19-situations-master
.gitignore 225B
gradle
wrapper
gradle-wrapper.jar 58KB
gradle-wrapper.properties 232B
build.gradle 291B
gradlew.bat 3KB
gradlew 6KB
image
人员分配.png 175KB
软件计划.png 383KB
LICENSE 11KB
app
.gitignore 6B
build.gradle 1KB
proguard-rules.pro 750B
libs
volley-1.2.1.aar 137KB
src
test
java
com
example
finalexamcovid_19situations
ExampleUnitTest.java 400B
main
AndroidManifest.xml 2KB
java
com
example
finalexamcovid_19situations
wuZiXuan2.java 347B
MaDaWeiDraw.java 7KB
maDaWeiCnvas.java 2KB
maDaWei.java 3KB
YvJiaReceiver.java 535B
jiangYongKe.java 5KB
liuJiaQi.java 3KB
wuZiXuan1.java 12KB
yvJia.java 2KB
ic_launcher-playstore.png 134KB
res
values
colors.xml 378B
themes.xml 848B
strings.xml 80B
ic_launcher_background.xml 120B
mipmap-xxhdpi
ic_launcher_round.png 18KB
ic_launcher_foreground.png 31KB
ic_launcher.png 12KB
layout
activity_ma_da_wei_cnvas.xml 425B
yv_jia.xml 3KB
wu_zi_xuan2.xml 10KB
jiang_yong_ke.xml 4KB
ma_da_wei.xml 2KB
wu_zi_xuan1.xml 5KB
liu_jia_qi.xml 1KB
xml
data_extraction_rules.xml 551B
backup_rules.xml 478B
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-xhdpi
ic_launcher_round.png 10KB
ic_launcher_foreground.png 15KB
ic_launcher.png 6KB
raw
sfxx.json 7KB
mipmap-hdpi
ic_launcher_round.png 6KB
ic_launcher_foreground.png 9KB
ic_launcher.png 4KB
values-night
themes.xml 848B
drawable
refresh.png 141KB
ii.jpg 47KB
cc.png 29KB
io.png 28KB
iio.png 22KB
t1p.png 2.35MB
iii.png 21KB
ic_launcher_background.xml 5KB
tb.png 63KB
mipmap-mdpi
ic_launcher_round.png 4KB
ic_launcher_foreground.png 5KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 29KB
ic_launcher_foreground.png 51KB
ic_launcher.png 19KB
androidTest
java
com
example
finalexamcovid_19situations
ExampleInstrumentedTest.java 792B
release
app-release.apk 5.35MB
output-metadata.json 393B
debug
app-debug.apk 6.17MB
output-metadata.json 389B
gradle.properties 1KB
.idea
.gitignore 47B
vcs.xml 167B
misc.xml 2KB
.name 30B
compiler.xml 169B
gradle.xml 680B
settings.gradle 347B
共 78 条
- 1
资源评论
- weixin_583970372022-12-24怎么能有这么好的资源!只能用感激涕零来形容TAT...
- qq_579391542023-05-16感谢大佬,让我及时解决了当下的问题,解燃眉之急,必须支持!
- m0_652887922022-10-24感谢资源主分享的资源解决了我当下的问题,非常有用的资源。
「已注销」
- 粉丝: 795
- 资源: 3612
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功