2013/07/30

小說閱讀器 v 1.3.5

BUGS:
* 修正金沙中文網搜尋後資料無法開啟的問題
> 如果已經加入書籤者, 請移除後再加入.

Google Play: 小說閱讀器 v1.3.5

2013/07/29

java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. !!

環境: android-17

java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification.
Make sure the content of your adapter is not modified from a background thread,
but only from the UI thread. [in ListView(16908298, class android.widget.ListView)
with Adapter(class android.widget.HeaderViewListAdapter)]

反覆檢查了一下所有使用 ListView, 確定都是在 UI Thread 改動, 但是卻一樣發生上面問題. 查看 Listview source code.

} else if (mItemCount != mAdapter.getCount()) {
                throw new IllegalStateException("The content of the adapter has changed but "
                        + "ListView did not receive a notification. Make sure the content of "
                        + "your adapter is not modified from a background thread, but only "
                        + "from the UI thread. [in ListView(" + getId() + ", " + getClass() 
                        + ") with Adapter(" + mAdapter.getClass() + ")]");
            }

裡面判斷 mItemCount 是否等於 mAdapter.getCount(), 而 mItemCount 在以下兩個地方取得:
1. setAdapter 的時候
2. onMeasure 的時候, 也就是 UI 有變動的時候.

而我所使用的 Adapter 都是從 ArrayAdapter 來. 在 add object 時, 都會通知一下資料變動, 理論上, ListView 也會收到通知,
所以跟著 mItemCount 會跟著修改, 但實際上 .... 一樣出現上面錯誤 !!!!
public void add(T object) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                mOriginalValues.add(object);
            } else {
                mObjects.add(object);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

Google 了半天, 最後我自己歸納以下結果, 當 setAdapter 後, 在大量新增 item 時, 有可能 ListView Upate 會跟不上 Adapter 的 Update.
所以當使用者捲動或者點擊時, 就有可能會出現這種狀況. (發生機率不高, 但從 Acra report, 我卻還滿常看到這 exception).

以下是我的解決方法, 到目前為止沒有在看到此 exception

import android.content.Context;
import android.widget.ArrayAdapter;

import java.util.List;

public class MyArrayAdapter extends ArrayAdapter {

    private List mObjects;
    private int count = 0;
    private boolean mNotifyOnChange = true;

    public MyArrayAdapter(Context context, int textViewResourceId, List objects) {
        super(context, textViewResourceId, objects);
        mObjects = objects;
        count = objects.size();
    }

    final public void beginTrans() {
        setNotifyOnChange(false);
        mNotifyOnChange = false;
    }


    final public void endTrans() {
        setNotifyOnChange(true);
        notifyDataSetChanged();
    }

    @Override
    final public int getCount() {
        return count;
    }

    @Override
    final public void notifyDataSetChanged() {
        count = mObjects.size();
        mNotifyOnChange = true;
        super.notifyDataSetChanged();
    }

    @Override
    final public T getItem(int position) {
        if (position >= getCount()) {
            return null;
        }
        if (position >= mObjects.size()) {
            return null;
        }
        return super.getItem(position);
    }

}


當要加入大量的 item 時, 則做以下動作.
1. call beginTrans
2. start to batch add items.
3. call endTrans

總算解決一個問題 :D

小說閱讀器 v 1.3.4

v 1.3.4
* 修正部份金沙中文網載入方式
> 原有金沙中文網站暫存會失效, 建議清除暫存

BUGS:
* 修正'起點vip'文章處理錯誤問題(顯示文章為 vip 文章)
> 本軟體不提供 vip 文章閱讀, 也不會提供 vip 文章下載.
* 修正部份起點文章暫存時的處理錯誤
* 修正圖檔文章開啟錯誤的問題
* 修正離線閱讀的部份問題
* 修正金沙中文網, 選擇簡體無法載入的問題


Google Play: 小說閱讀器 v1.3.4

2013/07/28

小說閱讀器 v 1.3.3

v 1.3.3
* 新增 起點中文網, 起點女生網 支援

BUGS:
* 修正載入小說清單的問題
* 修正部份 FC 問題
* 修正部份精品小說載入失敗問題
* 再度試著修正容易出現 FC 問題
* 再度修正在某些狀況載入小說集數錯誤的問題.


Google Play: 小說閱讀器 v1.3.3

2013/07/26

論壇瀏覽器 v2.2.8

v 2.2.8 -
**BUGS:**
* 修正 JKforum 部份FC 問題

Google play store: v2.2.8

小說閱讀器 v 1.2.8

v 1.2.8
BUGS:
* 修正卡提諾開啟就會 FC 問題.


Google Play: 小說閱讀器 v1.2.8

小說閱讀器 v 1.2.7

v 1.2.7
* 閱讀畫面 UI 部份修改
1. 使用者可以左右切畫面話, 或者從選單跳至目錄頁面.
2. 如果此集小說有暫存或者有下載, 此集小說右上角會有提示符號.
3. 下載時, 正在下載目錄頁面會動態更新(右上角提示符號顯示代表以下載完畢)

* 小說最後一頁優先從網路下載, 如果沒有有效的網路, 則會從暫存抓取.
* txt 檔新增編碼選項, 請按選單選取文字編碼
> 預設使用 utf-8 編碼

BUGS:
* 修正搜尋畫面選單(用瀏覽器開啟)無效的問題
* 修正我的書櫃畫面無法跳至上層目錄問題
* 修正閱讀 txt 檔時, 改變文字大小必須跳出再進或者重新整理才會生效的問題
* 修正卡提諾登入進度視窗顯示錯誤的問題
* 修正部份開啟 txt 檔導致 FC 的問題


Google Play: 小說閱讀器 v1.2.7

2013/07/19

小說閱讀器 v 1.2.6

v 1.2.6
* 新增支援 txt 檔的閱讀
使用方式:
1. 先去設定裡面設定我的書櫃的位置(請勿指向小說閱讀下載的目錄.)
2. 主畫面開啟選單, 選擇我的書櫃, 就會列出你設定目錄下的檔案.
3. 在書櫃畫面, 向左滑動可關閉, 在閱讀畫面, 向左滑動可切換到書櫃畫面

BUGS:
* 修正平板在小說清單顯示, 右下角圖示顯示錯誤的問題
* 修正閱讀小說部份錯誤
* 修正閱讀小說時部份選單錯誤問題


Google Play: 小說閱讀器 v1.2.6

2013/07/17

Ask password when release using gradle

總算移轉到 Gradle 來, 但卻出現一個 release sign 的問題.
之前使用 ant 在 sign release 會跳出提示來問密碼, 但是 gradle 卻不知該怎麼做.
Google 一番, 找到以下連結.
assemblerelease-task-dependency-ask-for-keystore-password

但這卻有一個問題, 雖然會提示輸入密碼, 但是最後出來的 apk 一樣沒有 sign.

以下是我的解決方法:
task('readPasswordFromInput') << {
def console = System.console()

ext.keystorePassword = console.readLine('\n\n\n> Enter keystore password: ')

android.signingConfigs.release.storePassword = ext.keystorePassword
android.signingConfigs.release.keyPassword = ext.keystorePassword
}

tasks.whenTaskAdded { task ->
if (task.name.matches("validateReleaseSigning")) {
task.dependsOn('readPasswordFromInput')
}
}

另外在 build type release 那邊加上以下
    signingConfigs {
debug {
storeFile file("my-debug-key.keystore")
}

release {
storeFile file("my-release-key.keystore")
storePassword ""
keyAlias "release_key"
keyPassword ""
}
}

這樣當 release 時就可以輸入密碼也成功的 sign 了.

2013/07/16

小說閱讀器 v 1.2.4

愚蠢的錯誤, 2.3.x 版本資料庫處理又搞出問題

v 1.2.4

BUGS:
* 修正 2.3.x 版本資料庫處理錯誤問題

Google Play: 小說閱讀器 v1.2.4

2013/07/15

XGallery v1.09

v 1.0.9
* Add Basic authorization support
* Fix some bugs.

中文說明

Google Play: XGallery v1.0.9






v 1.0.9
* 支援 Http Basic 認證
* 修正部份錯誤

Implement ImageLoader with picasso

之前發表了一篇使用 volley 來當作 ImageLoader, 但是實際上我自己都是使用 Picasso,
至少作為基本的 Loader 而言, 我認為 Picasso 好用多了.

環境:
SDK: android-17
IDE: android-studio
Device: Moto Atrix with 4.2.2
External Libraries: picasso

本篇跟之前一樣, 使用簡單的 gridview 當作 main layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:alwaysDrawnWithCache="false"
android:fadeScrollbars="true"
android:cacheColorHint="@android:color/transparent"
android:numColumns="3"
android:columnWidth="160dp"/>

</RelativeLayout>

gridview row 的 layout 跟之前稍微有點不一樣.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/imageview"
android:layout_width="160dp"
android:layout_height="240dp"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:contentDescription="@null"/>

</RelativeLayout>

這邊我並不使用 Picasso 內建的 loader, 而是根據自己的需求實作.
此範例中我只是很簡單的實作 Disk Cache 的機制.
MyURLConnectionLoader.java
package tw.clotai.picassoexample;

import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;

import com.squareup.picasso.Loader;

import java.io.*;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
* A {@link com.squareup.picasso.Loader} which uses {@link java.net.HttpURLConnection} to chapter_main images. A disk cache of 10MB
* will automatically be installed in the application's cache directory, when available.
*/
public class MyURLConnectionLoader implements Loader {

private static final String HASH_ALGORITHM = "MD5";
private static final int RADIX = 10 + 26;

private final Context context;

public MyURLConnectionLoader(Context context) {
this.context = context.getApplicationContext();
}

protected HttpURLConnection openConnection(String path) throws IOException {
return (HttpURLConnection) new URL(path).openConnection();
}

@Override
public Response load(Uri uri, boolean b) throws IOException {
Response res = null;

String cacahePath = PicassoHelper.getCachePath(context);
if (cacahePath == null) {
return res;
}

String url = uri.toString();

if (url == null) {
return res;
}

String key = generateUniqueID(url);
if (key == null) {
return res;
}

if (!url.startsWith("http")) {
File f = new File(url);
if (f.exists()) {
FileInputStream fin = new FileInputStream(f);
res = new Response(fin, true);
}
return res;
}

File f = new File(cacahePath, key);
if (f.exists()) {
FileInputStream fin = new FileInputStream(f);
res = new Response(fin, true);

} else {
InputStream in = null;
try {
HttpURLConnection connection = openConnection(url);
connection.setRequestProperty("User-Agent",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.91 Safari/537.11");
connection.setRequestProperty("Accept-Language", "en-US,en;q=0.8");
connection.setUseCaches(true);
connection.setDoInput(true);
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
connection.setRequestMethod("GET");
connection.connect();

in = connection.getInputStream();
copyToFile(in, f);
} finally {
if (in != null) {
in.close();
}
}

if (f.exists()) {
FileInputStream fin = new FileInputStream(f);
res = new Response(fin, false);
}
}
return res;
}



private String generateUniqueID(String url) {

StringBuilder sb = new StringBuilder();

byte[] md5;
BigInteger bi = null;

try {
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
digest.update(url.getBytes());
md5 = digest.digest();

bi = new BigInteger(md5).abs();

} catch (NoSuchAlgorithmException e) {
}

if (bi == null) {
return null;
}

sb.append(bi.toString(RADIX));
return sb.toString();
}

private void copyToFile(InputStream in, File dest) throws IOException {
FileOutputStream fos = null;
BufferedInputStream bin = null;
BufferedOutputStream bout = null;

try {
fos = new FileOutputStream(dest);
bin = new BufferedInputStream(in, 8192);
bout = new BufferedOutputStream(fos, 8192);

byte[] rdata = new byte[8192];
int count = 0;
while ((count = bin.read(rdata)) != -1) {
bout.write(rdata, 0, count);
}
bout.flush();

} finally {
if (bin != null) {
bin.close();
}
if (fos != null) {
if (fos.getFD() != null) {
fos.getFD().sync();
}
}

if (bout != null) {
bout.close();
}
if (fos != null) {
fos.close();
}
}
}


}

另外為了方便使用, 建立一個 singleton PicassoHelper.
以下為部份內容
public static PicassoHelper getInstance(Context c) {
if (helper == null) {
if (c == null) {
return null;
}
synchronized (PicassoHelper.class) {
if (helper == null) {
helper = new PicassoHelper(c);
}
}
}
return helper;
}

private PicassoHelper(Context c) {
mContext = c.getApplicationContext();

Picasso.Builder builder = new Picasso.Builder(c);
builder.loader(new MyURLConnectionLoader(c));

mPicasso = builder.build();
mPicasso.setDebugging(false);
PicassoHelper.getCachePath(mContext);
}

public void load(String url, ImageView v) {
v.setImageResource(R.drawable.ic_launcher);

if (url == null) {
return;
}

mPicasso.load(url)
.resize(160, 240)
.error(R.drawable.ic_launcher)
.centerCrop()
.into(v);
}

這樣大致上完成了.
同樣使用上次的範例, 執行結果如下:



原始碼下載:
PicassoExampleProject.zip

參考資料:
#1 Picasso v1.1.1

小說閱讀器 v 1.2.2

v 1.2.2
* 移除部份的確認視窗
* 移除清除最近閱讀的確認視窗
* Dropbox 備份功能 (Beta)
> 使用方式, 選單-設定, 連結 Dropbox, 就會自動備份了.


BUGS:
* 修改部份 FC 問題
* 修正 Nch(小說頻道) 只載入部份目錄的問題
* 修正 Ck101(卡提諾) 文內其他小說連結點擊錯誤問題
* 修正簡潔小說網搜尋無法觀看, 加入書籤等問題


Google Play: 小說閱讀器 v1.2.2

2013/07/11

論壇瀏覽器 v2.2.5

v 2.2.5 -
* 對於不支援的論壇, 顯示原本網頁畫面
* 首頁論壇新增使用瀏覽器開啟
> 遇到使用app無法連上,可以試著用瀏覽器開啟看是否有問題

* 支援論壇加入收藏功能
> Discuz6 目前不支援, 還有部份論壇不支援

* 增加自動檢查更新的功能

**BUGS:**
* 修改部份 FC 問題
* 修正部份下載問題
* 修正 A4TW 標題顯示問題
* 修正在論壇裡面收藏選項不見的問題
* 修正 JKForum 看不到的問題
* 修正 ck101 載入部份話題的問題
* 修正 PADHz 登入問題


Google play store: v2.2.5

2013/07/10

小說閱讀器 v 1.2.1

v 1.2.1
* 支援簡潔小說網(http://www.jianjie.me/)

* 修改上下頁滑動方式. 滑動更流暢
* 優化部份記憶體使用
* 內文內的連結加上粗體, 底線識別

BUGS:
* 修改部份 FC 問題
* 修正 ck101 顯示的問題
* 修正點擊內文, 連結錯誤的問題
* 修正設定裡的清除暫存的問題
* 修正簡繁轉換的問題

Google Play: 小說閱讀器 v1.2.1

2013/07/07

小說閱讀器 v 1.2.0

v 1.2.0
* 新增自動檢查更新的功能

BUGS:
* 再度增對某些機型的下載目錄修改
> 如果一樣不能使用, 可否回報機型. Thanks.

Google Play: 小說閱讀器 v1.2.0

2013/07/06

小說閱讀器 v 1.1.9

v 1.1.9
* 加強錯誤處理, 顯示更多資訊.
* 使用者可以自訂下載目錄
> 設定裡的下載目錄
* 小說清單新增可用網頁開啟小說
> 長按小說或點擊右下角, 選擇使用瀏覽器開啟


BUGS:
* 修正部份載入問題
* 修正部份 FC 問題
* 修正部份機型無法開啟的問題
> 有些機型不能使用預設的下載目錄, 所以請更改下載目錄
* 修正部份金沙中文網小說無法開啟的問題

Google Play: 小說閱讀器 v1.1.9

2013/07/05

論壇瀏覽器 v2.2.4

v 2.2.4 -
* 移除 Bookmarks 功能, 使用 最近閱讀和各論壇的收藏替代.
* 新增可自訂下載目錄, 之後下載直接下載到此目錄
> 選單點選設定
* 移除每個網站的字體設定

**BUGS:**
* 修正部份 FC 的問題
* 修正更新後第一次開啟可能會 FC 的問題
* 恢復自訂論壇的功能
* 修正找樂子無法感謝的問題


Google play store: v2.2.4

2013/07/04

小說閱讀器 v 1.1.8

v 1.1.8
* 調整字體大小設定到 1000%
* 調整內文行間距設定到 500%
* 新增離線暫存圖片
> 設定中可啟用, 下載時也會下載圖片

* 新增離線瀏覽圖片小說
* 新增功能在瀏覽小說時, 跳至上次閱讀位置
> 如果瀏覽小說時, 載入閱讀位置不對, 可以使用此功能跳至上次閱讀位置
> 選單 > 跳至上次閱讀位置

BUGS:
修正金沙中文網改版載入不到的問題
* 修正搜尋時, 按下載沒有反應的問題
* 修正部份載入下載清單, 清單錯誤的問題
* 修正匯出或者匯入可能 FC 的問題

* 修正開啟時沒有跳至上次閱讀位置的問題
> 如果還是有發生, 麻煩請告知
* 修正部份閱讀小說時產生 FC 的問題

* 修正金沙網修正金沙中文網離線閱讀的問題
> 如果更新此版本後一樣有問題, 請先清除暫存和清除閱讀紀錄


Google Play: 小說閱讀器 v1.1.8

2013/07/02

小說閱讀器 v 1.1.7

嗚 .. 一天改版兩次 :~

v 1.1.7

BUGS:
* 修正ck101載入問題


Google Play: 小說閱讀器 v1.1.7

小說閱讀器 v 1.1.6

v 1.1.6
** 由於新功能的增加, 會影響原本有的閱讀紀錄, 請見諒 **

* 調整預設字體大小
* 可設定每行文字的間距

BUGS:
* 修正閱讀紀錄錯誤的問題


Google Play: 小說閱讀器 v1.1.6

2013/07/01