package cn.vesns.sunweather.activity;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.qweather.sdk.bean.IndicesBean;
import com.qweather.sdk.bean.air.AirNowBean;
import com.qweather.sdk.bean.base.Code;
import com.qweather.sdk.bean.base.IndicesType;
import com.qweather.sdk.bean.base.Lang;
import com.qweather.sdk.bean.geo.GeoBean;
import com.qweather.sdk.bean.weather.WeatherDailyBean;
import com.qweather.sdk.bean.weather.WeatherHourlyBean;
import com.qweather.sdk.bean.weather.WeatherNowBean;
import com.qweather.sdk.view.QWeather;
import java.io.IOException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.vesns.sunweather.R;
import cn.vesns.sunweather.adapter.ViewPagerAdapter;
import cn.vesns.sunweather.entity.City;
import cn.vesns.sunweather.entity.CityList;
import cn.vesns.sunweather.fragment.OneFragment;
import cn.vesns.sunweather.util.CommonUtil;
import cn.vesns.sunweather.util.DisplayUtil;
import cn.vesns.sunweather.util.HttpUtil;
import cn.vesns.sunweather.util.SpUtils;
import cn.vesns.sunweather.util.WeekUtil;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* created by vesns on 2021/06/06.
*/
public class WeatherActivity extends AppCompatActivity {
private static final String TAG = "WeatherActivity.class";
private final int REQUEST_GPS = 1;
private int mNum = 0;
private List<Fragment> fragments;
CityList cityList = new CityList();
private List<String> locaitons;
private List<String> cityIds;
private LinearLayout llRound;
public SwipeRefreshLayout swipeRefresh;
private ImageView navButton;
private TextView titleCity;
private TextView degreeText;
private TextView weatherInfoText;
private TextView cloudageText;
private TextView humidityText;
private LinearLayout forecastLayout;
private TextView comfortText;
private TextView carWashText;
private TextView sportText;
private ImageView backBingImg;
private ProgressBar progressBar;
private TextView progressBar_text;
private TextView gradle_air_text;
private TextView traffic_text;
private TextView fish_text;
private TextView travel_text;
private LinearLayout linearLayout;
private int[] image = {R.mipmap.cloudy, R.mipmap.fine, R.mipmap.rain, R.mipmap.thunder, R.mipmap.dawu, R.mipmap.haze, R.mipmap.fog};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weather);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
init();
// initFragment();
loadBingPic();
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_GPS);
swipeRefresh.setColorSchemeResources(R.color.colorPrimary);
requestWeather(CommonUtil.CITY_ID);
swipeRefresh.setOnRefreshListener(() -> {
requestWeather(CommonUtil.CITY_ID);
loadBingPic();
});
navButton.setOnClickListener(v->{
if (v.getId() == R.id.nav_button) {
startActivity(new Intent(this,SearchActivity.class));
}
});
}
public void init() {
swipeRefresh = findViewById(R.id.swipe_refresh);
titleCity = findViewById(R.id.title_city);
degreeText = findViewById(R.id.degree_text);
weatherInfoText = findViewById(R.id.weather_info_text);
cloudageText = findViewById(R.id.cloudage_text);
humidityText = findViewById(R.id.humidity_text);
forecastLayout = findViewById(R.id.forecast_layout);
comfortText = findViewById(R.id.comfort_text);
carWashText = findViewById(R.id.car_wash_text);
sportText = findViewById(R.id.sport_text);
backBingImg = findViewById(R.id.bing_pic_img);
swipeRefresh = findViewById(R.id.swipe_refresh);
swipeRefresh.setColorSchemeResources(R.color.colorPrimary);
// drawerLayout = findViewById(R.id.drawer_layout);
navButton = findViewById(R.id.nav_button);
progressBar = findViewById(R.id.progressBar);
progressBar_text = findViewById(R.id.progressBar_text);
gradle_air_text = findViewById(R.id.gradle_air);
linearLayout = findViewById(R.id.linear);
travel_text = findViewById(R.id.travel_text);
fish_text = findViewById(R.id.fish_text);
traffic_text = findViewById(R.id.traffic_text);
navButton = findViewById(R.id.nav_button);
llRound = findViewById(R.id.ll_round);
}
private void initFragment() {
cityList = SpUtils.getBean(WeatherActivity.this, "cityBean", CityList.class);
CityList cityBean = SpUtils.getBean(WeatherActivity.this, "cityBean", CityList.class);
locaitons = new ArrayList<>();
if (cityBean != null) {
for (City city : cityBean.getCityBeans()) {
String cityName = city.getCityName();
locaitons.add(cityName);
}
}
cityIds = new ArrayList<>();
fragments = new ArrayList<>();
}
/**
* 根据天气id差城市天气信息
*
* @param weatherId
*/
public void requestWeather(final String weatherId) {
/**
* 实况天气数据
* @param location 所查询的地区,可通过该地区名称、ID、IP和经纬度进行查询经纬度格式:经度,纬度
* (英文,分隔,十进制格式,北纬东经为正,南纬西经为负)
* @param lang (选填)多语言,可以不使用该参数,默认为简体中文
* @param unit (选填)单位选择,公制(m)或英制(i),默认为公制单位
* @param listener 网络访问结果回调
*/
QWeather.getGeoCityLookup(WeatherActivity.this, CommonUtil.CITY_INITIAL, new QWeather.OnResultGeoListener() {
@Override
public void onError(Throwable throwable) {
runOnUiThread(() -> {
// Toast.makeText(WeatherActivity.this, CommonUtil.CITY_INITIAL, Toast.LENGTH_SHORT).show();
swipeRefresh.setRefreshing(false);
});
Log.i(TAG, "getGeoCityLookup onError: " + throwable);
}
@Override
public void onSuccess(GeoBean geoBean) {
Log.i(TAG, "getGeoCityLookup onSuccess: " + new Gson().toJson(geoBean));
if (Code.OK == geoBean.getCode()) {
List<GeoBean.LocationBean> locationBean = geoBean.getLocationBean();
List<City> cityBeans = new ArrayList<>();
City cityBean = new City();
for (GeoBean.LocationBean bean : locationBean) {
cityBean.setCityName(bean.getName())
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
新开发项目_Android毕设基于Android开发的天气预报app系统java源码+项目说明 该项目主要针对计算机相关专业的正在做毕设的学生和需要项目实战的Java学习者。 也可作为课程设计、期末大作业。包含:项目源码、数据库脚本、项目说明等,该项目可以直接作为毕设使用,也可以参考学习借鉴! 【特别强调】 1、csdn上资源保证是完整最新,会不定期更新优化; 2、请用自己的账号在csdn官网下载,若通过第三方代下,博主不对您下载的资源作任何保证,且不提供任何形式的技术支持和答疑!!!
资源推荐
资源详情
资源评论
收起资源包目录
新开发项目-Android毕设基于Android开发的天气预报app系统java源码+项目说明.zip (109个子文件)
app-release.apk 4.49MB
gradlew.bat 2KB
thunderstorm.gif 173KB
.gitignore 225B
.gitignore 47B
.gitignore 6B
build.gradle 2KB
build.gradle 530B
settings.gradle 46B
gradlew 5KB
AMap_Location_V5.3.1_20210331.jar 374KB
QWeather_Public_Android_V4.5.jar 212KB
gradle-wrapper.jar 53KB
WeatherActivity.java 21KB
OneFragment.java 19KB
SpUtils.java 17KB
SearchAdapter.java 7KB
SearchActivity.java 6KB
MainActivity.java 3KB
AMapService.java 3KB
DisplayUtil.java 2KB
ViewPagerAdapter.java 2KB
City.java 2KB
CommonUtil.java 950B
WeekUtil.java 868B
SunApplication.java 801B
ExampleInstrumentedTest.java 752B
DataUtil.java 647B
ExampleUnitTest.java 426B
HttpUtil.java 379B
CityList.java 289B
DataInterface.java 176B
weather.jks 2KB
vesns.jpg 923KB
th.jpg 324KB
th.jpg 324KB
backg.jpg 295KB
gcd.jpg 35KB
output-metadata.json 340B
replay_pid5704.log 438KB
hs_err_pid5704.log 30KB
项目说明.md 58B
ic_launcher_round.png 16KB
ic_launcher_round.png 12KB
ic_launcher.png 10KB
fine.png 10KB
app.png 10KB
haze.png 8KB
fog.png 8KB
ic_launcher.png 8KB
ic_launcher_round.png 7KB
thunder.png 6KB
weather.png 6KB
cloudy.png 6KB
rain.png 6KB
ic_launcher_round.png 5KB
ic_launcher.png 5KB
addaddress.png 4KB
ic_launcher.png 4KB
ic_launcher_round.png 3KB
dawu.png 3KB
add.png 3KB
left_icon.png 3KB
ic_launcher.png 3KB
icon_search.png 2KB
icon_back.png 1KB
disable.png 429B
enable.png 381B
proguard-rules.pro 952B
gradle.properties 1KB
gradle-wrapper.properties 230B
ic_launcher_background.xml 5KB
activity_search.xml 4KB
markdown-navigator.xml 3KB
activity_weather.xml 3KB
AndroidManifest.xml 3KB
activity_weather.xml 3KB
now.xml 3KB
markdown-navigator-enh.xml 2KB
suggestion.xml 2KB
fragment_one.xml 2KB
ic_launcher_foreground.xml 2KB
title.xml 1KB
forecast_item.xml 1KB
title.xml 1KB
day_weather_item.xml 1KB
jarRepositories.xml 1KB
gradle.xml 1KB
themes.xml 949B
forecast.xml 901B
item_search_history.xml 887B
item_searching.xml 887B
themes.xml 832B
aqi.xml 751B
activity_main.xml 738B
progress_bar.xml 737B
colors.xml 574B
title_fragment.xml 484B
misc.xml 372B
radio.xml 358B
共 109 条
- 1
- 2
onnx
- 粉丝: 9625
- 资源: 5597
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页