/*************************************************************************
Copyright 2014 MagicMod Project
This file is part of MagicMod Weather.
MagicMod Weather is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MagicMod Weather is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MagicMod Weather. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/
package com.magicmod.mmweather;
import android.location.Location;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import com.magicmod.mmweather.config.PreferenceUI;
import com.magicmod.mmweather.config.Preferences;
import com.magicmod.mmweather.engine.WeatherEngine;
import com.magicmod.mmweather.engine.WeatherInfo;
import com.magicmod.mmweather.engine.WeatherProvider;
import com.magicmod.mmweather.engine.WeatherResProvider;
import com.magicmod.mmweather.engine.WeatherInfo.DayForecast;
import com.magicmod.mmweather.engine.WeatherProvider.LocationResult;
import com.magicmod.mmweather.utils.Constants;
import com.magicmod.mmweather.utils.ImageUtils;
import com.magicmod.mmweather.utils.widget.RotateImageView;
import com.magicmod.mmweather.utils.widget.CirclePageIndicator;
import java.nio.MappedByteBuffer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class MainActivity extends FragmentActivity implements OnClickListener {
private static final String TAG = "MainActivity";
private static final boolean DBG = Constants.DEBUG;
/*private static final int LOACTION_OK = 0;
private static final int UPDATE_EXISTS_CITY = 2;
public static final int GET_WEATHER_SCUESS = 3;
public static final int GET_WEATHER_FAIL = 4;*/
//Title
private ImageView mCityManagerBtn, mLocationBtn, mShareBtn;
private TextView mTitleCityName;
private RotateImageView mUpdateProgressBar;
//Today's view
private TextView mCountryTextView;
private TextView mCityTextView, mSyncTimeTextView, mWeatherSourceTextView, mPm25TextView, mAqiDataTextView;
private TextView mTodayWeekTextView, mTodayMonthTextView, mTempTextView, mHumidityTextView, mWeatherConditionTextView, mWindTextView;
private ImageView mWeatherImageView, mAqiImageView;
private View mAqiRootView;
private ViewPager mViewPager;
private List<Fragment> fragments;
private NextDaysWeatherPagerAdapter mWeatherPagerAdapter;
private WeatherEngine mWeatherEngine;
private Context mContext;
//private WeatherApplication mApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getApplicationContext();
setContentView(R.layout.activity_main);
final WeatherApplication mApplication = (WeatherApplication) this.getApplication();
mWeatherEngine = mApplication.getWeatherEngine();
initViews();
initWeatherData();
initFragments();
/*Intent intent = new Intent(mContext, WeatherUpdateServices.class);
mContext.startService(intent);*/
}
@Override
protected void onResume() {
super.onResume();
//initWeatherData();
}
private void initViews() {
mCityManagerBtn = (ImageView) findViewById(R.id.title_city_manager);
mCityManagerBtn.setOnClickListener(this);
mLocationBtn = (ImageView) findViewById(R.id.title_location);
mLocationBtn.setOnClickListener(this);
mShareBtn = (ImageView) findViewById(R.id.title_share);
mShareBtn.setOnClickListener(this);
mUpdateProgressBar = (RotateImageView) findViewById(R.id.title_update_progress);
mUpdateProgressBar.setOnClickListener(this);
mTitleCityName = (TextView) findViewById(R.id.title_city_name);
mTitleCityName.setOnClickListener(this);
mCountryTextView = (TextView) findViewById(R.id.country);
mCityTextView = (TextView) findViewById(R.id.city);
mWeatherSourceTextView = (TextView) findViewById(R.id.weather_source_view);
mSyncTimeTextView = (TextView) findViewById(R.id.sync_time);
mPm25TextView = (TextView) findViewById(R.id.pm_data);
mAqiDataTextView = (TextView) findViewById(R.id.pm2_5_quality);
mTodayWeekTextView = (TextView) findViewById(R.id.week_today);
mTodayMonthTextView = (TextView) findViewById(R.id.month_today);
mTempTextView = (TextView) findViewById(R.id.temperature);
mHumidityTextView = (TextView) findViewById(R.id.humidity);
mWeatherConditionTextView = (TextView) findViewById(R.id.weather_condition);
mWindTextView = (TextView) findViewById(R.id.wind);
mWeatherImageView = (ImageView) findViewById(R.id.weather_img);
mAqiImageView = (ImageView) findViewById(R.id.pm2_5_img);
mAqiImageView.setOnClickListener(this);
}
/**
* First data adapter when app opened
* 2014年1月19日
*/
private void initWeatherData() {
if (DBG)
Log.d(TAG, "init weather data");
WeatherInfo info = mWeatherEngine.getCache(); //get weather info from cache
if (info == null) { //open a dialog to let user select their city
if (DBG)
Log.d(TAG, "get cache fail, start the city input dialog");
showCityInputDialog(true);
}
updateWeatherView(info,false);
}
private void initFragments() {
fragments = new ArrayList<Fragment>();
fragments.add(new NextDaysFirstWeatherFragment(mContext, mWeatherEngine.getCache(),
mWeatherEngine.getWeatherProvider().getWeatherResProvider()));
fragments.add(new NextDaysSecondWeatherFragment(mContext, mWeatherEngine.getCache(),
mWeatherEngine.getWeatherProvider().getWeatherResProvider()));
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mWeatherPagerAdapter = new NextDaysWeatherPagerAdapter(getSupportFragmentManager(),
fragments);
mViewPager.setAdapter(mWeatherPagerAdapter);
((CirclePageIndicator) findViewById(R.id.indicator)).setViewPager(mViewPager);
}
private void updateWeatherView(WeatherInfo weatherInfo, boolean refreshFragment) {
if (weatherInfo == null) {
return;
}
WeatherProvider provider = mWeatherEngine.getWeatherProvider();
WeatherResProvider res = provider.getWeatherResProvider();
if (refreshFragment) {
if (fragments.size() > 0) {
((NextDaysFirstWeatherFragment) mWeatherPagerAdapter.getItem(0)).updateWeather(
weatherInfo, res, mContext);
((NextDaysSecondWeatherFragment) mWeatherPagerAdapter.getItem(1)).updateWeather(
没有合适的资源?快使用搜索试试~ 我知道了~
android教程源码简洁天气项目源码
共323个文件
png:265个
xml:28个
java:25个
5星 · 超过95%的资源 需积分: 9 10 下载量 175 浏览量
2018-05-05
00:05:44
上传
评论 1
收藏 2.1MB ZIP 举报
温馨提示
android教程源码简洁天气项目源码,程序员在编程的过程中可以参考学习使用,希望对IT程序员有用,此源码程序简单易懂、方便阅读,有很好的学习价值!
资源推荐
资源详情
资源评论
收起资源包目录
android教程源码简洁天气项目源码 (323个子文件)
COPYING 34KB
proguard.flags 44B
.gitignore 416B
MainActivity.java 22KB
WeatherUpdateService.java 17KB
YahooWeatherProvider.java 17KB
CirclePageIndicator.java 16KB
WeatherEngine.java 11KB
YahooWeatherResProvider.java 7KB
Lunar.java 7KB
WeatherInfo.java 7KB
NextDaysSecondWeatherFragment.java 7KB
NextDaysFirstWeatherFragment.java 7KB
PreferenceUI.java 5KB
WeatherWidget.java 4KB
Preferences.java 4KB
ImageUtils.java 3KB
TimeUtil.java 2KB
WeatherResProvider.java 2KB
WeatherProvider.java 2KB
RotateImageView.java 2KB
NetUtil.java 2KB
PageIndicator.java 2KB
WeatherApplication.java 2KB
HttpRetriever.java 2KB
Constants.java 1KB
NextDaysWeatherPagerAdapter.java 1KB
WeatherDataChangedListener.java 732B
Android.mk 967B
mm_plugin_weather_bg.png 647KB
bg.png 245KB
ic_launcher-web.png 50KB
widget_preview.png 41KB
weather_8.png 21KB
weather_8.png 21KB
weather_10.png 21KB
weather_10.png 21KB
weather_37.png 21KB
weather_39.png 21KB
weather_37.png 21KB
weather_39.png 21KB
weather_43.png 21KB
weather_43.png 21KB
weather_15.png 20KB
weather_15.png 20KB
weather_25.png 20KB
weather_25.png 20KB
weather_40.png 20KB
weather_40.png 20KB
weather_na.png 20KB
weather_na.png 20KB
weather_9.png 20KB
weather_9.png 20KB
weather_47.png 20KB
weather_38.png 20KB
weather_47.png 20KB
weather_38.png 20KB
weather_35.png 20KB
weather_35.png 20KB
weather_42.png 20KB
weather_42.png 20KB
weather_36.png 20KB
weather_36.png 20KB
weather_28.png 20KB
weather_30.png 20KB
weather_28.png 20KB
weather_30.png 20KB
weather_12.png 20KB
weather_11.png 20KB
weather_12.png 20KB
weather_11.png 20KB
weather_17.png 20KB
weather_17.png 20KB
weather_3.png 20KB
weather_4.png 20KB
weather_45.png 20KB
weather_3.png 20KB
weather_4.png 20KB
weather_45.png 20KB
weather_16.png 20KB
weather_41.png 20KB
weather_16.png 20KB
weather_41.png 20KB
weather_27.png 20KB
weather_29.png 20KB
weather_44.png 20KB
weather_27.png 20KB
weather_29.png 20KB
weather_44.png 20KB
weather_26.png 20KB
weather_26.png 20KB
weather_6.png 20KB
weather_18.png 20KB
weather_7.png 20KB
weather_5.png 20KB
weather_6.png 20KB
weather_18.png 20KB
weather_7.png 20KB
weather_5.png 20KB
weather_46.png 20KB
共 323 条
- 1
- 2
- 3
- 4
资源评论
- number_1234562018-05-11我觉得很OK
七月半夏
- 粉丝: 242
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python+FFmpeg的视频和音频的处理+剪辑+源码+开发文档+项目解析(高分优秀项目)
- 母亲节祝福html源码示例.pdf
- 基于51单片机DS1302实时时钟LCD1602显示
- (54节)视频号0粉起号课,逻辑梳理,技能提升,完整版-课程网盘链接提取码下载 .txt
- Mendix5-添加自定义逻辑
- 基于java的图片浏览小程序源码.zip
- 陈呵keyshot产品渲染第2期-课程网盘链接提取码下载 .txt
- 分层MPC控制器的实时车辆最优控制和避障Hierarchical MPC controller for real time ve
- 基于QT+C++实现微动背景,界面看似静态实则动态+源码
- 非线性弹簧质量系统的简单模型预测控制(MPC)Simple Model Predictive Control (MPC) for
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功