Skip to content

Commit cc29760

Browse files
committed
去掉引导界面
1 parent 2477d2f commit cc29760

File tree

7 files changed

+153
-21
lines changed

7 files changed

+153
-21
lines changed

src/com/dreamteam/app/adapter/CategoryDetailAdapter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import android.content.Context;
66
import android.content.Intent;
7+
import android.database.sqlite.SQLiteDatabase;
78
import android.view.LayoutInflater;
89
import android.view.View;
910
import android.view.View.OnClickListener;
@@ -125,7 +126,9 @@ public void onClick(View v)
125126
intent.setAction(Main.ACTION_ADD_SECTION);
126127
context.sendBroadcast(intent);
127128
//加入section表
128-
SectionHelper.insert(mgr.getWritableDatabase(), tableName, title, url);
129+
SQLiteDatabase db = mgr.getWritableDatabase();
130+
SectionHelper.insert(db, tableName, title, url);
131+
db.close();
129132
//更新feed.db中所对应表的状态为1
130133
FeedDBManager feedHelper = new FeedDBManager(context, FeedDBManager.DB_NAME, null, 1);
131134
feedHelper.updateState(tableName,state, url);

src/com/dreamteam/app/commons/HtmlFilter.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.dreamteam.app.commons;
22

3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
37
import java.util.ArrayList;
48
import java.util.regex.Matcher;
59
import java.util.regex.Pattern;
@@ -19,6 +23,8 @@ public class HtmlFilter
1923
public static final String regexpForImgUrl = "http://([^\"]+)\"";
2024
//过滤<>中的style
2125
public static final String regexpForStyle = "\\s*style=\"([^\"]*)\"";
26+
//获取encoding
27+
public static final String regexpForEncoding = "\\s*encoding=\"([^\"]*)\"";
2228

2329

2430
/**
@@ -71,4 +77,26 @@ public static ArrayList<String> getImageSrcs(String input)
7177
}
7278
return srcs;
7379
}
80+
81+
public static String getEncoding(InputStream is)
82+
{
83+
String encoding = null;
84+
InputStreamReader isr = new InputStreamReader(is);
85+
BufferedReader br = new BufferedReader(isr);
86+
String context;
87+
try
88+
{
89+
context = br.readLine();
90+
Pattern p = Pattern.compile(regexpForEncoding);
91+
Matcher m = p.matcher(context);
92+
if(m.find())
93+
{
94+
encoding = m.group();
95+
}
96+
} catch (IOException e)
97+
{
98+
e.printStackTrace();
99+
}
100+
return encoding.replace("encoding=", "").replace("\"", "");
101+
}
74102
}

src/com/dreamteam/app/commons/ItemListEntityParser.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.FileNotFoundException;
44
import java.io.IOException;
55
import java.io.InputStream;
6+
import java.io.InputStreamReader;
67
import java.util.ArrayList;
78

89
import javax.xml.parsers.ParserConfigurationException;
@@ -15,16 +16,13 @@
1516
import org.xml.sax.XMLReader;
1617
import org.xml.sax.helpers.DefaultHandler;
1718

19+
import android.util.Log;
20+
1821
import com.dreamteam.app.entity.FeedItem;
1922
import com.dreamteam.app.entity.ItemListEntity;
2023
import com.dreamteam.app.utils.DateUtils;
2124
import com.dreamteam.app.utils.HttpUtils;
2225

23-
import android.util.Log;
24-
25-
26-
27-
2826
public class ItemListEntityParser extends DefaultHandler
2927
{
3028
private String tag = "ItemListEntityParser";
@@ -56,7 +54,7 @@ public void startElement(String uri, String localName, String qName,
5654
Attributes attributes) throws SAXException
5755
{
5856
sb.setLength(0);
59-
if(qName.equalsIgnoreCase("item"))
57+
if(localName.trim().equalsIgnoreCase("item"))
6058
{
6159
feedItem = new FeedItem();
6260
items.add(feedItem);
@@ -71,17 +69,17 @@ public void endElement(String uri, String localName, String qName)
7169
throws SAXException
7270
{
7371
String content = sb.toString();
74-
75-
if(!isFeedLink && qName.equalsIgnoreCase("link"))
72+
Log.d(qName, content);
73+
if(!isFeedLink && localName.trim().equalsIgnoreCase("link"))
7674
{
7775
feedItem.setLink(content);
7876
}
79-
if(!isFeedTitle && qName.equalsIgnoreCase("title"))
77+
if(!isFeedTitle && localName.trim().equalsIgnoreCase("title"))
8078
{
8179
feedItem.setTitle(content);
8280
return;
8381
}
84-
if(!isFeedDesc && qName.equalsIgnoreCase("description"))
82+
if(!isFeedDesc && localName.trim().equalsIgnoreCase("description"))
8583
{
8684
feedItem.setDescription(content);
8785
ArrayList<String> srcs = HtmlFilter.getImageSrcs(content);
@@ -91,13 +89,13 @@ public void endElement(String uri, String localName, String qName)
9189
isFeedDesc = false;
9290
return;
9391
}
94-
if(qName.equalsIgnoreCase("pubDate"))
92+
if(localName.trim().equalsIgnoreCase("pubDate"))
9593
{
9694
content = DateUtils.rfcNormalDate(content);
9795
if(feedItem != null)
9896
feedItem.setPubdate(content);
9997
}
100-
if(qName.equalsIgnoreCase("content:encoded"))
98+
if(localName.trim().equalsIgnoreCase("content:encoded"))
10199
{
102100
feedItem.setContentEncoded(content);
103101
ArrayList<String> srcs = HtmlFilter.getImageSrcs(content);
@@ -124,15 +122,18 @@ public ItemListEntity parse(String url)
124122
SAXParserFactory saxpf = SAXParserFactory.newInstance();
125123
SAXParser saxp = null;
126124
InputStream inputStream = null;
125+
InputSource inputSource = null;
127126

128127
try
129128
{
130129
inputStream = HttpUtils.getInputStream(url);
131-
130+
// String encoding = HtmlFilter.getEncoding(inputStream);
131+
// Log.d(tag, encoding);
132+
// InputStreamReader isr = new InputStreamReader(inputStream, encoding);不可用
133+
inputSource = new InputSource(inputStream);
132134
saxp = saxpf.newSAXParser();
133135
XMLReader xmlr = saxp.getXMLReader();
134136
xmlr.setContentHandler(this);
135-
InputSource inputSource = new InputSource(inputStream);
136137
xmlr.parse(inputSource);
137138
return itemListEntity;
138139
}
@@ -176,4 +177,5 @@ public ItemListEntity parse(String url)
176177
}
177178
}
178179
}
180+
179181
}

src/com/dreamteam/app/commons/SectionHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public static void insert(SQLiteDatabase db, String tableName, String title, Str
2424
values.put("title", title);
2525
values.put("url", url);
2626
db.insert(DbManager.SECTION_TABLE_NAME, null, values);
27-
db.close();
2827
}
2928

3029
public static File newSdCache(String url)

src/com/dreamteam/app/ui/ItemList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public void onSpeakBegin() throws RemoteException
134134
@Override
135135
public void onCompleted(int arg0) throws RemoteException
136136
{
137-
Log.d(tag, "--------->>onCompleted()");
138137
speechCount++;
139138
if (speechCount > speechTextList.size())
140139
return;
@@ -213,6 +212,9 @@ public void onItemClick(AdapterView<?> parent, View view,
213212
// 改变阅读状态
214213
if (!item.isReaded())
215214
{
215+
item.setReaded(true);
216+
mAdapter.notifyDataSetChanged();
217+
216218
new Thread()
217219
{
218220
@Override

src/com/dreamteam/app/ui/SplashActivity.java

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package com.dreamteam.app.ui;
22

3+
import java.io.File;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
39
import android.annotation.SuppressLint;
410
import android.app.Activity;
511
import android.content.Intent;
612
import android.content.SharedPreferences;
13+
import android.content.SharedPreferences.Editor;
14+
import android.database.sqlite.SQLiteDatabase;
715
import android.os.Bundle;
816
import android.os.Handler;
917
import android.os.Message;
18+
import android.util.Log;
1019

20+
import com.dreamteam.app.commons.SectionHelper;
21+
import com.dreamteam.app.db.DbManager;
22+
import com.dreamteam.app.db.FeedDBManager;
1123
import com.dreateam.app.ui.R;
1224

1325
/**
@@ -51,7 +63,10 @@ public void handleMessage(Message msg)
5163
goHome();
5264
break;
5365
case GO_GUIDE:
54-
goGuide();
66+
// goGuide();
67+
writeDB();
68+
initSection();
69+
goHome();
5570
break;
5671
}
5772
super.handleMessage(msg);
@@ -95,6 +110,9 @@ private void init()
95110
}
96111
else
97112
{
113+
Editor editor = preferences.edit();
114+
editor.putBoolean("isFirstIn", false);
115+
editor.commit();
98116
mHandler.sendEmptyMessageDelayed(GO_GUIDE, SPLASH_DELAY_MILLIS);
99117
}
100118

@@ -113,4 +131,77 @@ private void goGuide()
113131
SplashActivity.this.startActivity(intent);
114132
SplashActivity.this.finish();
115133
}
134+
135+
/**
136+
* 土办法
137+
*/
138+
private void initSection()
139+
{
140+
DbManager mgr = new DbManager(this, DbManager.DB_NAME, null, 1);
141+
SQLiteDatabase db = mgr.getWritableDatabase();
142+
SectionHelper.insert(db, "news", "国内新闻", "http://n.rss.qq.com/rss/qqmail_rss.php?id=2");
143+
SectionHelper.insert(db, "news", "国际时事", "http://n.rss.qq.com/rss/qqmail_rss.php?id=3");
144+
SectionHelper.insert(db, "science", "科技松鼠会", "http://songshuhui.net/feed");
145+
SectionHelper.insert(db, "science", "36氪", "http://www.36kr.com/feed");
146+
db.close();
147+
}
148+
149+
private void writeDB()
150+
{
151+
InputStream inputStream = null;
152+
try
153+
{
154+
inputStream = getAssets().open("feed.db");
155+
FeedDBManager helper = new FeedDBManager(this, FeedDBManager.DB_NAME, null, 1);
156+
SQLiteDatabase db = helper.getWritableDatabase();
157+
File dbFile = new File(db.getPath());
158+
if(dbFile.exists())
159+
{
160+
dbFile.delete();
161+
}
162+
FileOutputStream fos = null;
163+
164+
try
165+
{
166+
fos = new FileOutputStream(dbFile);
167+
byte buffer[] = new byte[1024 * 4];
168+
while((inputStream.read(buffer)) != -1)
169+
{
170+
fos.write(buffer);
171+
}
172+
}
173+
catch(FileNotFoundException e)
174+
{
175+
e.printStackTrace();
176+
}
177+
catch(IOException e)
178+
{
179+
e.printStackTrace();
180+
}
181+
finally
182+
{
183+
try
184+
{
185+
if(inputStream != null)
186+
{
187+
inputStream.close();
188+
inputStream = null;
189+
}
190+
if(fos != null)
191+
{
192+
fos.close();
193+
fos = null;
194+
}
195+
} catch (IOException e)
196+
{
197+
e.printStackTrace();
198+
}
199+
db.close();
200+
}
201+
}
202+
catch(IOException e)
203+
{
204+
e.printStackTrace();
205+
}
206+
}
116207
}

src/com/dreamteam/app/utils/HttpUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import org.apache.http.HttpStatus;
88

9+
import android.util.Log;
10+
911
/**
1012
* @author: zcloud
1113
*
@@ -18,23 +20,28 @@ public class HttpUtils
1820
{
1921
private static HttpURLConnection conn = null;
2022
public static final String tag = "HttpUtils";
23+
private static final int TIMEOUT = 1000*10;
2124

2225
/**
2326
* @param url
2427
* @return InputStream
25-
* @throws Exception
28+
* @throws Exception
2629
*/
2730
public static InputStream getInputStream(String url) throws Exception
2831
{
32+
InputStream is = null;
2933
URL httpURL = null;
3034

3135
httpURL = new URL(url);
3236
conn = (HttpURLConnection) httpURL.openConnection();
37+
conn.setConnectTimeout(TIMEOUT);
38+
conn.setReadTimeout(TIMEOUT);
3339
if(conn.getResponseCode() == HttpStatus.SC_OK)
3440
{
35-
return conn.getInputStream();
41+
Log.d(tag, "connected!");
42+
is = conn.getInputStream();
3643
}
37-
return null;
44+
return is;
3845
}
3946

4047
public static void disConnect()

0 commit comments

Comments
 (0)