引导页面,多个城市的天气,可以通过滑动来翻阅。

先看下截图:

1、城市天气界面

2、引导界面

应用引导页面

package org.qxj.iweather.page;

import org.qxj.iweather.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ViewFlipper; public class Welcome extends Activity { private static final String TAG = "Welcome";
private SharedPreferences shared = null;
private SharedPreferences.Editor edit = null;
private LinearLayout layout = null;
private ViewFlipper flip = null;
private LayoutParams match = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
private String isFirst = "false";
private Intent intent = null; class TurnPage implements Runnable { @Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
TurnToMain();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} } @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.shared = super.getSharedPreferences("IWeather", MODE_PRIVATE);
this.edit = this.shared.edit(); this.layout = new LinearLayout(this);
this.layout.setOrientation(LinearLayout.VERTICAL); this.flip = new ViewFlipper(this);
this.layout.addView(this.flip, match);
this.layout.setBackgroundResource(R.drawable.welcome);
super.addContentView(this.layout, match); isFirst = this.shared.getString("isFirst", "true");
Log.i(TAG, "isFirst: " + isFirst);
if ("true".equals(isFirst)) {
this.edit.putString("isFirst", "false");
this.edit.commit();
new Thread(new TurnPage()).start();
} else {
// 进行跳转
TurnToMain();
} } public void TurnToMain() {
// 进行跳转
intent = new Intent(Welcome.this, Main.class);
startActivity(intent);
// 销毁该Activity,返回的时候,不会返回该界面。
this.finish();
} }

主页面

package org.qxj.iweather.page;

import org.qxj.iweather.R;
import org.qxj.iweather.Contents.IWeather;
import org.qxj.iweather.net.HttpHelper; import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout; public class Main extends Activity implements OnGestureListener { private IWeather iWeather = null;
private LinearLayout layout = null;
private GestureDetector detector;
private LayoutParams match = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT); @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.layout = new LinearLayout(this);
detector = new GestureDetector(this);
this.iWeather = new IWeather(this);
this.layout.addView(this.iWeather.flip, match);
this.addContentView(this.layout, match);
iWeather.flip.addView(new PageLayout(this, "101301301"));
iWeather.flip.addView(new PageLayout(this, "101010100"));
iWeather.flip.addView(new PageLayout(this, "101260101"));
iWeather.flip.addView(new PageLayout(this, "101190501"));
iWeather.flip.addView(new PageLayout(this, "101190101"));
iWeather.flip.addView(new PageLayout(this, "101170101"));
} @Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
} @Override
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
} @Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
if (e1.getX() - e2.getX() > 80) {
iWeather.flip.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
iWeather.flip.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
iWeather.flip.showNext();
return true;
} else if (e1.getX() - e2.getX() < -80) {
iWeather.flip.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_in));
iWeather.flip.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_out));
iWeather.flip.showPrevious();
return true;
}
return false;
} @Override
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub } @Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
} @Override
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub } @Override
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
} }

自定义的pageLayout

package org.qxj.iweather.page;

import org.qxj.iweather.R;
import org.qxj.iweather.model.Weather;
import org.qxj.iweather.net.HttpHelper; import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast; public class PageLayout extends LinearLayout { private Weather weather = null;
private Context context = null;
private TextView temperature = null;
private TextView city = null;
private TextView statues = null;
private TextView date = null;
public Handler hander = new Handler() { @Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
weather = (Weather) msg.obj;
init();
break;
case 0:
Toast.makeText(context, "数据操作失败!", Toast.LENGTH_SHORT).show();
break;
}
} }; public PageLayout(Context context, String city) {
super(context);
this.context = context;
new Thread(new HttpHelper(city, this)).start();
} public PageLayout(Context context, AttributeSet attrs, String city) {
super(context, attrs);
this.context = context;
new Thread(new HttpHelper(city, this)).start();
} public PageLayout(Context context, AttributeSet attrs, int defStyle, String city) {
super(context, attrs, defStyle);
this.context = context;
new Thread(new HttpHelper(city, this)).start();
} private void init() {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.page_layout, this);
this.temperature = (TextView) findViewById(R.id.tempearture);
this.city = (TextView) findViewById(R.id.city);
this.statues = (TextView) findViewById(R.id.statues);
this.date = (TextView) findViewById(R.id.date); this.temperature.setText(this.weather.getTemp1());
this.city.setText(this.weather.getCity());
this.statues.setText(this.weather.getWeather1());
this.date.setText(this.weather.getDate_y());
this.setBackgroundByWeather(this.weather.getWeather1());
} /**
* 设置屏幕背景
*/
private void setBackgroundByWeather(String w) {
if (w.indexOf("雪") != -1) {
// 有雪的天气
this.setBackgroundResource(R.drawable.snow);
} else if (w.indexOf("雨") != -1) {
// 下雨天
this.setBackgroundResource(R.drawable.rain);
} else if (w.indexOf("晴") != -1) {
// 晴
this.setBackgroundResource(R.drawable.sun);
} else if (w.indexOf("阴") != -1) {
// 阴天
this.setBackgroundResource(R.drawable.water);
} else {
this.setBackgroundResource(R.drawable.sun);
}
} }

完整代码:

http://download.csdn.net/detail/niitqin/6472535

Android 实现简单天气应用的更多相关文章

  1. Android 实现简单音乐播放器(二)

    在Android 实现简单音乐播放器(一)中,我介绍了MusicPlayer的页面设计. 现在,我简单总结一些功能实现过程中的要点和有趣的细节,结合MainActivity.java代码进行说明(写出 ...

  2. Android 实现简单音乐播放器(一)

    今天掐指一算,学习Android长达近两个月了,今天开始,对过去一段时间的学习收获以及遇到的疑难杂症做一些总结. 简单音乐播放器是我自己完成的第一个功能较为完整的APP,可以说是我的Android学习 ...

  3. Android课程---Android Studio简单设置

    Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings-->Appearance-->Theme, ...

  4. Android实现简单音乐播放器(MediaPlayer)

    Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能 ...

  5. Android实现简单拨号器

    Android实现简单拨号器 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 代码实现 界面布局只有GridLayout和EditText两个控件,全部 ...

  6. 【转】Android Studio简单设置

    原文网址:http://ask.android-studio.org/?/article/14 Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以 ...

  7. Android发展简单介绍

    Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...

  8. android JNI 简单demo(2)它JNI demo 写

    android JNI 简单demo(2)它JNI demo 写 一.搭建Cygwin 环境:http://blog.csdn.net/androidolblog/article/details/25 ...

  9. Android Studio简单设置(转)

    Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings --> Appearance --> Th ...

随机推荐

  1. hadoop 配置文件注意问题

    一定要配置成hostname形式: 如伪分布:配成localhost:9000 完全分布:配成big1:9000

  2. The type javax.servlet.http.HttpServletRequest cannot be resolved.

    The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from ...

  3. javaTemplates-学习笔记二

    配置PlayFramework环境 下载jar包[Play with Activator],这一步有点晕是JAVA程序员CMD执行的步骤;运行了jar包下载了很多配置文件什么的,有的资源没有VPN链接 ...

  4. hdu 4289 Control 网络流

    题目链接 给出一些点, 每个点有一个权值, 给出一些边, 起点以及终点, 去掉一些点使得起点和终点不连通, 求最小的val. 拆点, 把一个点s拆成s和s', 之间建一条边, 权值为点权. 对于一条边 ...

  5. 为什么Java项目前会出现一个红色感叹号!

    先看看问题,如下图所示: 造成这个问题的原因是,我把一个 jar 包删除了,然后又配了个新的进去,然后就一直有这个错误,刚开始很郁闷,怎么已经配置过儿,还出现这个问题?关键是代码里面没有报错的.郁闷的 ...

  6. poj 2689 大范围内素数筛选

    /** 给定一定范围求其内的素数 注意: **/ #include <iostream> #include <math.h> #include <cstring> ...

  7. Spring 装配Bean

    Spring 装配Bean 装配解释: 创建应用对象之间协作关系的的行为通常称为装配(wiring),这也是依赖注入的本质 依赖注入是Spring的基础要素 一 : 使用spring装配Bean基础介 ...

  8. 设置cmd的codepage的方法

    设置cmd的codepage的方法 有时候,我们的cmd.exe的codepage和字体等会变化,比如突然由中文变成英文的codepage(因为一些sh程序的干扰). 下面是修正方法: [HKEY_C ...

  9. 一維條碼 EAN13 的編碼方式

    何謂 EAN-13碼 ? ▲ 國家代號(3位數) 中華民國的國家代號為471. ▲ 廠商代號(6位數) 由本會核發給廠商6位數的廠商代號. ▲ 商品代號(3位數) 由廠商自行編定,按一物一號的原則,不 ...

  10. Windows Azure Camp---漫步云端,创意无限

    不再需要一系列繁杂的网银密码,一键搞定所有的支付:与朋友约会时通过实时分享地理位置迅速找到对方,这些都可以在WindowsAzure平台得以实现.在刚刚结束的2013年微软学生夏令营中,来自全国30所 ...