首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

从Foursquare视手机端程序设计(1)

2012-08-22 
从Foursquare看手机端程序设计(1)public final T parse(XmlPullParser parser) throws FoursquareParseExc

从Foursquare看手机端程序设计(1)

public final T parse(XmlPullParser parser) throws FoursquareParseException, FoursquareError {///算法模板try {if (parser.getEventType() == XmlPullParser.START_DOCUMENT) {parser.nextTag();if (parser.getName().equals("error")) {throw new FoursquareError(parser.nextText());}}return parseInner(parser); //调用子类具体实现} catch (IOException e) {if (DEBUG) LOG.log(Level.FINE, "IOException", e);throw new FoursquareParseException(e.getMessage());} catch (XmlPullParserException e) {if (DEBUG) LOG.log(Level.FINE, "XmlPullParserException", e);throw new FoursquareParseException(e.getMessage());}}

<?xml version=”1.0”?><city>< geolat ></ geolat >< geolong ></ geolong >< id ></ id >< name ></ name >< shortname ></ shortname >< timezone ></ timezone >< cityid ></ cityid ></city>CityParser中的parseInner解析过程parser.require(XmlPullParser.START_TAG, null, null);City city = new City(); //解析结果while (parser.nextTag() == XmlPullParser.START_TAG) {String name = parser.getName();if ("geolat".equals(name)) {city.setGeolat(parser.nextText());} else if ("geolong".equals(name)) {city.setGeolong(parser.nextText());} else if ("id".equals(name)) {city.setId(parser.nextText());} else if ("name".equals(name)) {city.setName(parser.nextText());} else if ("shortname".equals(name)) {city.setShortname(parser.nextText());} else if ("timezone".equals(name)) {city.setTimezone(parser.nextText());} else if ("cityid".equals(name)) {city.setId(parser.nextText());} else {skipSubTree(parser);}}return city

public void store(String key, InputStream is) { if (DEBUG) Log.d(TAG, "store: " + key); is = new BufferedInputStream(is); try { OutputStream os = new BufferedOutputStream(new FileOutputStream(getFile(key)));//获取存放路径 byte[] b = new byte[2048]; int count; int total = 0; while ((count = is.read(b)) > 0) { os.write(b, 0, count); total += count; } os.close(); if (DEBUG) Log.d(TAG, "store complete: " + key); } catch (IOException e) { if (DEBUG) Log.d(TAG, "store failed to store: " + key, e); return; }}//获取路径public File getFile(String hash) { return new File(mStorageDirectory.toString() + File.separator + hash); //存放路径}

?

1 楼 xiaonan900214 2011-02-26   现在Foursquare是不是不开源了~不能下载了 2 楼 leesazhang 2011-10-27   谢谢!Foursquare好像是不开源了呢。

热点排行