苏州科技学院电子与信息工程学院移动互联网开发技术大作业报告专业年级班级学号姓名成绩2015年6月19日大作业任务完成以下任务(时间一周)。
1、剪刀石头布游戏要求:(1)人-机对弈;(2)人-人对弈;2、新闻阅读软件要求:(1)读取新浪国内新闻栏目的新闻列表;(2)阅读指定列表项的新闻;【任务1】1 需求分析1.1用户需求不同年龄段的人都可以玩这款游戏界面友好、简单易用1.2功能需求人和人之间能进行对战人和计算机之间能进行对战人人对战和人机对战界面可以切回主界面2 系统分析与建模2.1概要设计3 系统设计与实现3.1界面设计"按钮人人对战的双方同时由系统随机出拳,其中一人点击"结束"按钮结束本局游戏并计算比分点击剪刀/石头/布按钮后人出相应的拳,系统随机出拳,双方出拳后本局游戏自动结束并计算比分,"结束"按钮变成"开始"按钮【任务2】1 需求分析1.1用户需求使人们随时了解国内新闻;简单易用;1.2功能需求读取新浪国内新闻栏目的新闻列表;阅读指定列表项的新闻;2 系统分析与建模2.1概要设计3 系统设计与实现3.1界面设计阅读新闻模块通过解析新浪新闻的XML文件读取新闻的部分内容,并提供新闻原文链接供用户查阅,另有返回按钮可返回主界面查看其他新闻3.3 核心模块的实现代码MainActivity.javapackage ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;public class MainActivity extends Activity {public final String RSS_URL = ".cn/news/china/focus15.xml";private ListView lv_news;private List<NewsInfo> newsInfos;private class NewsAdapter extends BaseAdapter{@Overridepublic int getCount() {return newsInfos.size();}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn null;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn 0;}@Overridepublic View getView(int position, View convertView,ViewGroup parent) {View view=View.inflate(MainActivity.this, , null);TextView tv_title=(TextView) view.findViewById(;NewsInfo newsInfo=newsInfos.get(position);tv_title.setText(newsInfo.getTitle());return view;}}@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(;lv_news=(ListView) findViewById(;//创建AsyncHttpClient实例AsyncHttpClient asyncHttpClient = new AsyncHttpClient();//使用GET方式请求asyncHttpClient.get(RSS_URL,new AsyncHttpResponseHandler() {public void onSuccess(String content) {//访问成功super.onSuccess(content);byte[] bytes = content.getBytes();//将Byte数组转换成输入流ByteArrayInputStream bais = new ByteArrayInputStream(bytes);//调用NewsInfoService工具类解析xml文件newsInfos = NewsInfoService.getNews(bais);if (newsInfos == null) {// 解析失败弹出toastToast.makeText(MainActivity.this,"解析失败", 0).show();} else {// 更新界面lv_news.setAdapter(new NewsAdapter());lv_news.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent,View view, int position, long id) {Intent intent = newIntent(MainActivity.this,ShowActivity.class);Bundle b = new Bundle();b.putString("title",newsInfos.get(position).getTitle());b.putString("discription", newsInfos.get(position).getDescription());b.putString("link",newsInfos.get(position).getLink());b.putString("pubdate", newsInfos.get(position).getPubdate());intent.putExtras(b);startActivity(intent);}});}}//请求失败public void onFailure(Throwable error, String content) {super.onFailure(error, content);Log.e("error",RSS_URL);Log.e("error", error.toString());Toast.makeText(MainActivity.this, "请求失败", 0).show();}});}private void fillData() {//创建AsyncHttpClient实例AsyncHttpClient asyncHttpClient = new AsyncHttpClient();//使用GET方式请求asyncHttpClient.get(RSS_URL,new AsyncHttpResponseHandler() {public void onSuccess(String content) {//访问成功super.onSuccess(content);byte[] bytes = content.getBytes();//将Byte数组转换成输入流ByteArrayInputStream bais = new ByteArrayInputStream(bytes);//调用NewsInfoService工具类解析xml文件newsInfos = NewsInfoService.getNews(bais);if (newsInfos == null) {// 解析失败弹出toastToast.makeText(MainActivity.this,"解析失败", 0).show();} else {// 更新界面lv_news.setAdapter(new NewsAdapter());}}//请求失败public void onFailure(Throwable error, String content) {super.onFailure(error, content);Log.e("error",RSS_URL);Log.e("error", error.toString());Toast.makeText(MainActivity.this, "请求失败", 0).show();}});}}NewsInfo.javapackage ;public class NewsInfo {private String title;// 标题private String description;// 描述private String link;// 链接private String pubdate;// 出版时间public NewsInfo() {super();}public NewsInfo(String title, String description, String link, String pubdate) {super();this.title = title;this.description = description;this.link = link;this.pubdate = pubdate;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}public String getLink() {return link;}public void setLink(String link) {this.link = link;}public String getPubdate() {return pubdate;}public void setPubdate(String pubdate) {this.pubdate = pubdate;}}NewsInfoServices.javapackage ;import ;import ;import ;import ;import ;import ;import ;public class NewsInfoService {public static List<NewsInfo> getNews(InputStream is){NewsInfo i = null;List<NewsInfo> list = null;XmlPullParserFactory factory;try{factory = XmlPullParserFactory.newInstance();XmlPullParser parser;parser = factory.newPullParser();parser.setInput(is, "UTF-8");int eventType = parser.getEventType(); //产生第一个事件while (eventType != XmlPullParser.END_DOCUMENT) {// 只要不是文档结束String name = parser.getName(); // 获取解析器当前指向的元素名称switch (eventType){case XmlPullParser.START_DOCUMENT: list = new ArrayList<NewsInfo>();break;case XmlPullParser.START_TAG:if ("item".equals(name)){i = new NewsInfo();}if (i != null){if ("title".equals(name)) {i.setTitle(parser.nextText());}if ("link".equals(name)) {i.setLink(parser.nextText());}if ("pubDate".equals(name)) {i.setPubdate(parser.nextText());}if ("description".equals(name)) {i.setDescription(parser.nextText());}}break;case XmlPullParser.END_TAG:if ("item".equals(name)){list.add(i);i = null;}}eventType = parser.next();// 进入下一个元素 }}catch (XmlPullParserException e){e.printStackTrace();}catch (IOException e){e.printStackTrace();}return list;}}ShowActivity.javapackage ;import ;import ;import ;import ;import ;import ;import ;import ;import ;public class ShowActivity extends Activity {private TextView textView;private Button backbutton;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(;textView = (TextView) findViewById(;String content = null;Intent intent = getIntent();if (intent != null) {Bundle bundle = intent.getExtras();if (bundle == null) {content = "程序错误";} else {content = bundle.getString("title") + "\n\n"+ bundle.getString("pubdate") + "\n\n"+bundle.getString("discription")+"\n\n"文档来源为:从网络收集整理.word版本可编辑.欢迎下载支持.+ "\n\n详情:\n"+ bundle.getString("link");}} else {content = "程序错误";}textView.setText(content);backbutton = (Button) findViewById(;backbutton.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {finish();}});}}4 测试9文档来源为:从网络收集整理.word版本可编辑.。