package cn.hhs.activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.location.Location;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import cn.hhs.util.DataUtil;
import cn.hhs.util.HttpService;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.LocationListener;
import com.baidu.mapapi.MKAddrInfo;
import com.baidu.mapapi.MKBusLineResult;
import com.baidu.mapapi.MKDrivingRouteResult;
import com.baidu.mapapi.MKLocationManager;
import com.baidu.mapapi.MKPoiResult;
import com.baidu.mapapi.MKSearch;
import com.baidu.mapapi.MKSearchListener;
import com.baidu.mapapi.MKTransitRouteResult;
import com.baidu.mapapi.MKWalkingRouteResult;
/**
* @author 家铄
* @QQ 1466181491
*
*/
public class WeatherScreen extends Activity implements OnClickListener {
BMapManager mBMapMan = null;
LocationListener mLocationListener = null;
MKSearch mSearch = null;
String npCityId = "";
EditText dialogCity;
String provinceName, cityName;
boolean flag = true;
ProgressDialog progressDialog;
LinearLayout ll_yes, ll_no;
TextView tv_city, tv_today, tv_attr1, tv_attr2, tv_attr3, tv_noresult;
TextView tv_date1, tv_date2, tv_wd1, tv_wd2;
ImageView ima, ima1, ima2;
Button btn_return, btn_other;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.weather_screen);
initView();
initBaiDuMap();
}
@Override
protected void onPause() {
mBMapMan.getLocationManager().removeUpdates(mLocationListener);
mBMapMan.stop();
super.onPause();
}
@Override
protected void onResume() {
mBMapMan.getLocationManager().requestLocationUpdates(mLocationListener);
mBMapMan.getLocationManager().enableProvider(
MKLocationManager.MK_GPS_PROVIDER);
mBMapMan.start();
super.onResume();
}
/**
*
* 方法名:initBaiDuMap 功能:初始化百度地图 参数:
*/
private void initBaiDuMap() {
mBMapMan = new BMapManager(getApplication());
mBMapMan.init("14A97FC2DDF678193F61C19C0A20EA29C49DEF5C", null);// 14A97FC2DDF678193F61C19C0A20EA29C49DEF5C
mBMapMan.start();
initMyLocation();
}
/**
*
* 方法名:initMyLocation 功能:启动定位 参数:
*/
private void initMyLocation() {
progressDialog = ProgressDialog
.show(this, null, "城市定位中...", true, true);
mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (location != null && flag) {
progressDialog.dismiss();
flag = false;
GeoPoint myPt = new GeoPoint(
(int) (location.getLatitude() * 1e6),
(int) (location.getLongitude() * 1e6));
initMapSerach();
// 将当前坐标转化为地址获取当前城市名称
mSearch.reverseGeocode(myPt);
} else {
}
}
};
}
private void initMapSerach() {
// 初始化搜索模块,注册事件监听
mSearch = new MKSearch();
mSearch.init(mBMapMan, new MKSearchListener() {
public void onGetPoiResult(MKPoiResult res, int type, int error) {
}
public void onGetDrivingRouteResult(MKDrivingRouteResult res,
int error) {
}
public void onGetTransitRouteResult(MKTransitRouteResult res,
int error) {
}
public void onGetWalkingRouteResult(MKWalkingRouteResult res,
int error) {
}
public void onGetAddrResult(MKAddrInfo res, int error) {
if (error != 0 || res == null) {
} else {
String city = res.addressComponents.city;
String pro = res.addressComponents.province;
if (city != null) {
provinceName = pro.substring(0, pro.length() - 1);
cityName = city.substring(0, city.length() - 1);
progressDialog = ProgressDialog.show(
WeatherScreen.this, null, "天气查询中...", true,
true);
QueryAsyncTask asyncTask = new QueryAsyncTask();
asyncTask.execute("");
} else {
Toast.makeText(WeatherScreen.this, "定位不到当前城市,无法查询天气",
Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) {
}
});
}
/**
*
* 方法名:initView 功能:初始化控件 参数:
*/
private void initView() {
ll_yes = (LinearLayout) this.findViewById(R.id.ws2_ll_yes);
ll_no = (LinearLayout) this.findViewById(R.id.ws2_ll_no);
tv_city = (TextView) this.findViewById(R.id.ws2_tv_city);
ima = (ImageView) this.findViewById(R.id.ws2_iv_image);
tv_attr1 = (TextView) this.findViewById(R.id.ws2_tv_attr1);
tv_attr2 = (TextView) this.findViewById(R.id.ws2_tv_attr2);
tv_attr3 = (TextView) this.findViewById(R.id.ws2_tv_attr3);
tv_noresult = (TextView) this.findViewById(R.id.ws2_tv_noresult);
tv_date1 = (TextView) this.findViewById(R.id.ws2_tv_1_date);
tv_date2 = (TextView) this.findViewById(R.id.ws2_tv_2_date);
tv_wd1 = (TextView) this.findViewById(R.id.ws2_tv_1_wd);
tv_wd2 = (TextView) this.findViewById(R.id.ws2_tv_2_wd);
ima1 = (ImageView) this.findViewById(R.id.ws2_iv_1_image);
ima2 = (ImageView) this.findViewById(R.id.ws2_iv_2_image);
btn_return = (Button) this.findViewById(R.id.ws2_btn_return);
btn_return.setOnClickListener(this);
btn_other = (Button) this.findViewById(R.id.ws2_btn_submit);
btn_other.setOnClickListener(this);
}
private class QueryAsyncTask extends AsyncTask {
@Override
protected void onPostExecute(Object result) {
progressDialog.dismiss();
if (result != null) {
String weatherResult = (String) result;
if (weatherResult.split(";").length > 1) {
String a = weatherResult.split(";")[1];
if (a.split("=").length > 1) {
String b = a.split("=")[1];
String c = b.substring(1, b.length() - 1);
String[] resultArr = c.split("\\}");
if (resultArr.length > 0) {
todayParse(resultArr[0]);
tommrowParse(resultArr[1]);
thirddayParse(resultArr[2]);
ll_yes.setVisibility(View.VISIBLE);
tv_city.setText(cityName);
}
} else {
DataUtil.Alert(WeatherScreen.this, "查无天气信息");
}
} else {
DataUtil.Alert(WeatherScreen.this, "查无天气信息");
}
} else {
DataUtil.Alert(WeatherScreen.this, "查无天气信息");
}
super.onPostExecute(result);
}
@Override
protected Object doInBackground(Object... params) {
return HttpService.getWeather(cityName);
}
}
/**
*
* 方法名:todayParse 功能:今天天气 参数:
*
* @param weather
*/
private void todayParse(String weather) {
String temp = weather.replace("'", "");
String[] tempArr = temp.split(",");
String wd = "";
String tq = "";
String fx = "";
if (tempArr.length > 0) {
for (int i = 0; i < tempArr.length; i++) {
if (tempArr[i].indexOf("t1:") != -1) {
wd = tempArr[i].substring(3, tempArr[i].length()) + "℃";
} else if (tempArr[i].indexOf("t2:") != -1) {
wd = wd + "~"
+ tempArr[i].substring(3, tempArr[i].length())
+ "℃";
} else if (tempArr[i].indexOf("d1:") != -1) {
fx = tempArr[i].substring(3, tempArr[i].length());
} else if (tempArr[i].indexOf("s1:") != -1) {
tq = tempArr[i].substring(4, tempArr[i].length());
}
}
tv_attr1
没有合适的资源?快使用搜索试试~ 我知道了~
android调用天气demo
共100个文件
png:54个
class:16个
xml:8个
5星 · 超过95%的资源 需积分: 15 93 下载量 191 浏览量
2016-08-11
15:49:36
上传
评论 1
收藏 2.31MB RAR 举报
温馨提示
android调用天气的demo实例,非常好用的例子,可以直接运行,本例子有一个bug,就是城市输入的时候,如果出现非城市名或者非法字符会出现闪退
资源推荐
资源详情
资源评论
收起资源包目录
android调用天气demo (100个子文件)
resources.ap_ 110KB
WeatherDemo.apk 899KB
jarlist.cache 120B
proguard.cfg 1KB
WeatherScreen.class 9KB
HttpService.class 4KB
WeatherScreen$2.class 3KB
WeatherScreen$QueryAsyncTask.class 2KB
WeatherScreen$3.class 2KB
WeatherScreen$1.class 1KB
DataUtil.class 1KB
R$id.class 995B
R$drawable.class 961B
WeatherScreen$4.class 850B
DataUtil$1.class 756B
R.class 510B
R$layout.class 500B
R$string.class 418B
BuildConfig.class 339B
R$attr.class 331B
.classpath 534B
classes.dex 140KB
baidumapapi.jar 225KB
baidumapapi-ff40d2942c83d62cf495ec5d08dc97d1.jar 188KB
baidumapapi-6bfec2ef735f6d8c2ddf0f862292e19d.jar 188KB
annotations-87bd6017633eaca0eb88e79414e1aff7.jar 943B
WeatherScreen.java 13KB
HttpService.java 4KB
R.java 3KB
DataUtil.java 564B
BuildConfig.java 157B
btn_normal_g.jpg 18KB
btn_return_g.jpg 12KB
index_bottom_g.jpg 1KB
s_6.png 7KB
s_11.png 7KB
s_1.png 6KB
s_7.png 6KB
s_6.png 6KB
s_6.png 6KB
s_10.png 6KB
s_4.png 6KB
s_5.png 6KB
s_7.png 5KB
s_7.png 5KB
s_13.png 5KB
s_10.png 5KB
s_10.png 5KB
s_9.png 5KB
s_11.png 5KB
s_11.png 5KB
s_12.png 5KB
main_bg.png 5KB
s_9.png 5KB
s_9.png 5KB
s_1.png 5KB
s_1.png 5KB
s_3.png 5KB
s_8.png 5KB
s_4.png 5KB
s_4.png 5KB
s_5.png 5KB
s_5.png 5KB
s_13.png 4KB
s_13.png 4KB
s_8.png 4KB
s_8.png 4KB
icon.png 4KB
s_3.png 4KB
s_3.png 4KB
icon.png 4KB
icon.png 4KB
s_2.png 4KB
s_12.png 3KB
s_12.png 3KB
s_2.png 3KB
s_2.png 3KB
listview_line.png 3KB
icon.png 3KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
main_bg.png 1KB
main_bg.png 1KB
listview_line.png 73B
listview_line.png 73B
org.eclipse.jdt.core.prefs 177B
.project 847B
project.properties 563B
libBMapApiEngine_v1_3_2.so 991KB
weather_screen.xml 10KB
AndroidManifest.xml 1KB
AndroidManifest.xml 1KB
weather_other_city.xml 528B
common_line.xml 390B
main.xml 382B
top_bg_g_repe.xml 199B
strings.xml 181B
共 100 条
- 1
资源评论
- softwaremaker_S2016-10-09新浪的天气网站,可以用!
- qq_423161022018-06-03你这个app一打开就闪退是怎么回事啊,我还没有输入城市,一打开就闪退了
勘察加熊人
- 粉丝: 160
- 资源: 79
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于yolov5识别算法实现的DNF自动脚本源码.zip
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功