《蘇州科技學(xué)院移動(dòng)互聯(lián)網(wǎng)開(kāi)發(fā)技術(shù)大作業(yè).doc》由會(huì)員分享,可在線閱讀,更多相關(guān)《蘇州科技學(xué)院移動(dòng)互聯(lián)網(wǎng)開(kāi)發(fā)技術(shù)大作業(yè).doc(21頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
蘇州科技學(xué)院電子與信息工程學(xué)院
移動(dòng)互聯(lián)網(wǎng)開(kāi)發(fā)技術(shù) 大作業(yè)報(bào)告
專業(yè)年級(jí)
班 級(jí)
學(xué) 號(hào)
姓 名
成 績(jī)
2015年6月19日
大作業(yè)任務(wù)
完成以下任務(wù)(時(shí)間一周)。
1、剪刀石頭布游戲
要求:
(1)人-機(jī)對(duì)弈;
(2)人-人對(duì)弈;
2、新聞閱讀軟件
要求:
(1)讀取新浪國(guó)內(nèi)新聞欄目的新聞列表;
(2)閱讀指定列表項(xiàng)的新聞;
【任務(wù)1】
1 需求分析
1.1用戶需求
不同年齡段的人都可以玩這款游戲
界面友好、簡(jiǎn)單易用
1.2功能需求
人和人之間能進(jìn)行對(duì)戰(zhàn)
人和計(jì)算機(jī)之間能進(jìn)行對(duì)戰(zhàn)
人人對(duì)戰(zhàn)和人機(jī)對(duì)戰(zhàn)界面可以切回主界面
2 系統(tǒng)分析與建模
2.1概要設(shè)計(jì)
2.1.1系統(tǒng)用例圖
2.1.2系統(tǒng)類圖
2.1.3系統(tǒng)時(shí)序圖
2.1.4系統(tǒng)活動(dòng)圖
3 系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)
人人對(duì)戰(zhàn)界面
Second_main.xml
3.1界面設(shè)計(jì)
模式選擇界面
Activity_main.xml
人機(jī)對(duì)戰(zhàn)界面
Third_main.xml
3.2模塊設(shè)計(jì)
3.2.1模式選擇模塊
本模塊是用戶進(jìn)入程序的入口??梢赃x擇人機(jī)對(duì)戰(zhàn)或者人人對(duì)戰(zhàn)。
3.2.2人機(jī)對(duì)戰(zhàn)模塊
為了保證公平性,人人對(duì)戰(zhàn)模塊只有一個(gè)界面,點(diǎn)擊"開(kāi)始游戲"按鈕人人對(duì)戰(zhàn)的雙方同時(shí)由系統(tǒng)隨機(jī)出拳,其中一人點(diǎn)擊"結(jié)束"按鈕結(jié)束本局游戲并計(jì)算比分
3.2.3人人對(duì)戰(zhàn)模塊
點(diǎn)擊剪刀/石頭/布按鈕后人出相應(yīng)的拳,系統(tǒng)隨機(jī)出拳,雙方出拳后本局游戲自動(dòng)結(jié)束并計(jì)算比分,"結(jié)束"按鈕變成"開(kāi)始"按鈕
【任務(wù)2】
1 需求分析
1.1用戶需求
使人們隨時(shí)了解國(guó)內(nèi)新聞;
簡(jiǎn)單易用;
1.2功能需求
讀取新浪國(guó)內(nèi)新聞欄目的新聞列表;
閱讀指定列表項(xiàng)的新聞;
2 系統(tǒng)分析與建模
2.1概要設(shè)計(jì)
2.1.1系統(tǒng)用例圖
2.1.2系統(tǒng)類圖
2.1.3系統(tǒng)時(shí)序圖
2.1.4系統(tǒng)活動(dòng)圖
3 系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)
3.1界面設(shè)計(jì)
閱讀新聞界面
Activity_show_news.xml
主界面
Activity_main.xml
News_item.xml
3.2 模塊設(shè)計(jì)
3.2.1讀取新聞列表模塊
讀取新聞列表模塊通過(guò)解析新浪新聞的XML文件獲取新聞標(biāo)題
3.2.2 閱讀新聞模塊
閱讀新聞模塊通過(guò)解析新浪新聞的XML文件讀取新聞的部分內(nèi)容,并提供新聞原文鏈接供用戶查閱,另有返回按鈕可返回主界面查看其他新聞
3.3 核心模塊的實(shí)現(xiàn)代碼
MainActivity.java
package com.example.sinanews;
import java.io.ByteArrayInputStream;
import java.util.List;
import com.example.sinanews.R;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
public final String RSS_URL = "http://rss.sina.com.cn/news/china/focus15.xml";
private ListView lv_news;
private List
newsInfos;
private class NewsAdapter extends BaseAdapter{
@Override
public int getCount() {
return newsInfos.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view=View.inflate(MainActivity.this, R.layout.news_item, null);
TextView tv_title=(TextView) view.findViewById(R.id.tv_title);
NewsInfo newsInfo=newsInfos.get(position);
tv_title.setText(newsInfo.getTitle());
return view;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv_news=(ListView) findViewById(R.id.lv_news);
//創(chuàng)建AsyncHttpClient實(shí)例
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
//使用GET方式請(qǐng)求
asyncHttpClient.get(RSS_URL,
new AsyncHttpResponseHandler() {
public void onSuccess(String content) {
//訪問(wèn)成功
super.onSuccess(content);
byte[] bytes = content.getBytes();
//將Byte數(shù)組轉(zhuǎn)換成輸入流
ByteArrayInputStream bais = new ByteArrayInputStream(
bytes);
//調(diào)用NewsInfoService工具類解析xml文件
newsInfos = NewsInfoService.getNews(bais);
if (newsInfos == null) {
// 解析失敗 彈出toast
Toast.makeText(MainActivity.this,
"解析失敗", 0).show();
} else {
// 更新界面
lv_news.setAdapter(new NewsAdapter());
lv_news.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent,
View view, int position, long id) {
Intent intent = new Intent(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);
}
});
}
}
//請(qǐng)求失敗
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, "請(qǐng)求失敗", 0).show();
}
});
}
private void fillData() {
//創(chuàng)建AsyncHttpClient實(shí)例
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
//使用GET方式請(qǐng)求
asyncHttpClient.get(RSS_URL,
new AsyncHttpResponseHandler() {
public void onSuccess(String content) {
//訪問(wèn)成功
super.onSuccess(content);
byte[] bytes = content.getBytes();
//將Byte數(shù)組轉(zhuǎn)換成輸入流
ByteArrayInputStream bais = new ByteArrayInputStream(
bytes);
//調(diào)用NewsInfoService工具類解析xml文件
newsInfos = NewsInfoService.getNews(bais);
if (newsInfos == null) {
// 解析失敗 彈出toast
Toast.makeText(MainActivity.this,
"解析失敗", 0).show();
} else {
// 更新界面
lv_news.setAdapter(new NewsAdapter());
}
}
//請(qǐng)求失敗
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, "請(qǐng)求失敗", 0).show();
}
});
}
}
NewsInfo.java
package com.example.sinanews;
public class NewsInfo {
private String title;// 標(biāo)題
private String description;// 描述
private String link;// 鏈接
private String pubdate;// 出版時(shí)間
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.java
package com.example.sinanews;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class NewsInfoService {
public static List getNews(InputStream is)
{
NewsInfo i = null;
List list = null;
XmlPullParserFactory factory;
try
{
factory = XmlPullParserFactory.newInstance();
XmlPullParser parser;
parser = factory.newPullParser();
parser.setInput(is, "UTF-8");
int eventType = parser.getEventType(); //產(chǎn)生第一個(gè)事件
while (eventType != XmlPullParser.END_DOCUMENT)
{
// 只要不是文檔結(jié)束
String name = parser.getName(); // 獲取解析器當(dāng)前指向的元素名稱
switch (eventType)
{
case XmlPullParser.START_DOCUMENT:
list = new ArrayList();
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();// 進(jìn)入下一個(gè)元素
}
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return list;
}
}
ShowActivity.java
package com.example.sinanews;
import com.example.sinanews.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ShowActivity extends Activity {
private TextView textView;
private Button backbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_news);
textView = (TextView) findViewById(R.id.tv_content);
String content = null;
Intent intent = getIntent();
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle == null) {
content = "程序錯(cuò)誤";
} else {
content = bundle.getString("title") + "\n\n"
+ bundle.getString("pubdate") + "\n\n"
+bundle.getString("discription")+"\n\n"
+ "\n\n詳情:\n"
+ bundle.getString("link");
}
} else {
content = "程序錯(cuò)誤";
}
textView.setText(content);
backbutton = (Button) findViewById(R.id.btn_back);
backbutton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
4 測(cè)試
鏈接地址:http://kudomayuko.com/p-8618691.html