当前位置:  编程技术>移动开发
本页文章导读:
    ▪上拉刷新        下拉刷新 下拉刷新     参考代码 https://github.com/johannilsson/android-pulltorefresh ......
    ▪ 替menu 等触控按键添加震动        为menu 等触控按键添加震动 froyo\frameworks\policies\base\phone\com\android\internal\policy\impl\PhoneWindowManager.java     line 1957 加入     }else if(code == KeyEvent.KEYCODE_MENU ||            code ==KeyEvent.KEYCODE_BACK.........
    ▪ 补上中国天候网城市编码抓取代码 很一般的抓取代码.嘿嘿       补上中国天气网城市编码抓取代码 很一般的抓取代码.....嘿嘿 import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLC.........

[1]上拉刷新
    来源: 互联网  发布时间: 2014-02-18
下拉刷新

下拉刷新

 

 

参考代码 https://github.com/johannilsson/android-pulltorefresh


    
[2] 替menu 等触控按键添加震动
    来源: 互联网  发布时间: 2014-02-18
为menu 等触控按键添加震动

froyo\frameworks\policies\base\phone\com\android\internal\policy\impl\PhoneWindowManager.java

 

 

line 1957 加入

 

 

}else if(code == KeyEvent.KEYCODE_MENU ||
            code ==KeyEvent.KEYCODE_BACK || code ==KeyEvent.KEYCODE_SEARCH || code ==KeyEvent.KEYCODE_HOME){
    if (down){
              performHapticFeedbackLw(null, HapticFeedbackConstants.KEYBOARD_TAP, false);
    }else{

    }
   }


    
[3] 补上中国天候网城市编码抓取代码 很一般的抓取代码.嘿嘿
    来源: 互联网  发布时间: 2014-02-18
补上中国天气网城市编码抓取代码 很一般的抓取代码.....嘿嘿
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

/***
 * 抓取天气网 城市编码
 * @author wu
 *
 */
public class GetWeatherCode {

	/**
	 * 通过域名或IP地址取得网站数据
	 * 
	 * @param strUrl
	 *            example:http://www.baidu.com
	 * @return
	 */
	public String getContent(String strUrl) {
		try {

			URL url = new URL(/blog_article/strUrl/index.html);
			System.out.println(strUrl);
			URLConnection urlconn = url.openConnection(); // 试图连接并取得返回状态码
			urlconn.connect();
			HttpURLConnection httpConn = (HttpURLConnection) urlconn;
			httpConn = (HttpURLConnection) url.openConnection();
			HttpURLConnection.setFollowRedirects(true);
			httpConn.setRequestMethod("GET");
			//模拟浏览器
			httpConn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 (.NET CLR 3.5.30729)");
			httpConn.setConnectTimeout(60000);//超时设置...
			int httpResult = httpConn.getResponseCode();// 获得相应代码
			if (httpResult != HttpURLConnection.HTTP_OK) { // 不等于HTTP_OK说明连接不成功
				System.out.println("fail连接失败!!!");
				return null;
			} else {
				InputStream ins = urlconn.getInputStream();
				BufferedReader br = new BufferedReader(new InputStreamReader(ins));
				String s = "";
				StringBuffer sb = new StringBuffer("");
				while ((s = br.readLine()) != null) {
					sb.append(s + "\r\n");
				}
				br.close();
				return sb.toString();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 踢掉 json格式
	 * @param str
	 * @return
	 */
	private String rplaceCode(String str){
		if(str != null){
			str = str.replaceAll("\\{", "");
			str = str.replaceAll("\\}", "");
			str = str.replaceAll("\\\"", "");
			str = str.replaceAll(",", "\n");
			str = str.replaceAll(":", "    ");
			return str;
		}
		return null;
	}
	/**
	 * 踢掉json格式
	 * @param str
	 * @return
	 */
	private String outCode(String str){
		if(str != null){
			str = str.replaceAll("\\{", "");
			str = str.replaceAll("\\}", "");
			str = str.replaceAll("\\\"", "");
			str = str.substring(0,str.indexOf(":"));
			return str;
		}
		return null;
	}

	/**
	 * 最初实现 输出不够好 所以不用了...
	 */
	@Deprecated
	public void oneImplements(){
		ArrayList<String> arry1 = new ArrayList<String>();
		ArrayList<String> arry2 = new ArrayList<String>();
		
		for (int i = 10101; i <= 10134; i++) {
			String rs = getContent("http://www.weather.com.cn/data/city3jdata/provshi/" + i + ".html");
			if (rs != null) {
				if(!rs.contains("<")){
					System.out.println("市级:\n" + "  " + rs);
					arry1.add("市级:\n" +rs);
					arry2.add("市级:\n" +rs);
					String[] shij = rs.split(",");
					int ct = shij.length;
					if (ct > 0) {
						int start = i * 100;
						int end = i * 100 + ct;
						for (int j = start; j <= end; j++) {
	
							String rs2 = getContent("http://www.weather.com.cn/data/city3jdata/station/" + j + ".html");
							if (rs2 != null && !rs2.contains("<")) {
								String jieguo = "  市级【" + shij[(j-i*100-1)>0?(j-i*100-1):0] + "】以下的:\n" + rs2;
								arry1.add(jieguo+"\n http://www.weather.com.cn/data/city3jdata/station/" + j + ".html");
								arry2.add(jieguo);
								System.out.println(jieguo);
								System.out.println("");
							}
						}
					}
				}
			}

		}
		System.out.println("带地址的:");
		for (String jg : arry1) {
			System.out.println(rplaceCode(jg));
		}
		System.out.println("不带地址的:");
		for (String jg : arry2) {
			System.out.println(rplaceCode(jg));
		}
	}
	public static void main(String args[]) {
		// // 具体使用方法
		// 省级{"10101":"北京","10102":"上海","10103":"天津","10104":"重庆","10105":"黑龙江","10106":"吉林","10107":"辽宁","10108":"内蒙古","10109":"河北","10110":"山西","10111":"陕西","10112":"山东","10113":"新疆","10114":"西藏","10115":"青海","10116":"甘肃","10117":"宁夏","10118":"河南","10119":"江苏","10120":"湖北","10121":"浙江","10122":"安徽","10123":"福建","10124":"江西","10125":"湖南","10126":"贵州","10127":"四川","10128":"广东","10129":"云南","10130":"广西","10131":"海南","10132":"香港","10133":"澳门","10134":"台湾"}
		GetWeatherCode ou = new GetWeatherCode();
		ArrayList<String> arry1 = new ArrayList<String>();//带地址的
		ArrayList<String> arry2 = new ArrayList<String>();//不带地址的
		//firebug 分析出的 首要城市请求地址
		String sourceUrl = "http://www.weather.com.cn/data/city3jdata/china.html";
		
		String src = ou.getContent(sourceUrl);//读取内容
		if(src != null && !src.contains("<")){
			String[] sheng = src.split(",");//省级分割

			for (String sh : sheng) {
				String outCode = ou.outCode(sh);
			    String rs = ou.getContent("http://www.weather.com.cn/data/city3jdata/provshi/" + outCode + ".html");
				if (rs != null) {
					if (!rs.contains("<")) {
						arry1.add("市级:"+sh+"\n" + rs);
						arry2.add("市级:"+sh+"\n" + rs);
						String[] shij = rs.split(",");//市级分割
						for (String sj : shij) {
							String shjiOutCode = ou.outCode(sj);
							String rs2 = ou.getContent("http://www.weather.com.cn/data/city3jdata/station/" + (outCode + shjiOutCode) + ".html");
							if (rs2 != null && !rs2.contains("<")) {
								String jieguo = "  市级【" + sj + "】以下的:\n" + rs2;
								arry1.add(jieguo + "http://www.weather.com.cn/data/city3jdata/station/" + (outCode + shjiOutCode) + ".html");
								arry2.add(jieguo);
							}
						}
					}
				}

			}
		}
		System.out.println("带地址的:");
		for (String jg : arry1) {
			System.out.println(ou.rplaceCode(jg));
		}
		System.out.println("不带地址的:");
		for (String jg : arry2) {
			System.out.println(ou.rplaceCode(jg));
		}
		//简单测试
		//System.out.println(ou.rplaceCode("{\"10101\":\"北京\",\"10102\":\"上海\",\"10103\":\"天津\",\"10104\":\"重庆\",\"10105\":\"黑龙江\",\"10106\":\"吉林\",\"10107\":\"辽宁\",\"10108\":\"内蒙古\",\"10109\":\"河北\",\"10110\":\"山西\",\"10111\":\"陕西\",\"10112\":\"山东\",\"10113\":\"新疆\",\"10114\":\"西藏\",\"10115\":\"青海\",\"10116\":\"甘肃\",\"10117\":\"宁夏\",\"10118\":\"河南\",\"10119\":\"江苏\",\"10120\":\"湖北\",\"10121\":\"浙江\",\"10122\":\"安徽\",\"10123\":\"福建\",\"10124\":\"江西\",\"10125\":\"湖南\",\"10126\":\"贵州\",\"10127\":\"四川\",\"10128\":\"广东\",\"10129\":\"云南\",\"10130\":\"广西\",\"10131\":\"海南\",\"10132\":\"香港\",\"10133\":\"澳门\",\"10134\":\"台湾\"}"));

	}
}

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android程序设计之AIDL实例详解 iis7站长之家
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3