diff --git a/zhuike/src/main/assets/font/bysong.ttf b/zhuike/src/main/assets/font/bysong.ttf deleted file mode 100644 index 9c1fb90..0000000 Binary files a/zhuike/src/main/assets/font/bysong.ttf and /dev/null differ diff --git a/zhuike/src/main/assets/font/fzkatong.ttf b/zhuike/src/main/assets/font/fzkatong.ttf deleted file mode 100644 index fb69743..0000000 Binary files a/zhuike/src/main/assets/font/fzkatong.ttf and /dev/null differ diff --git a/zhuike/src/main/assets/font/qihei.ttf b/zhuike/src/main/assets/font/qihei.ttf deleted file mode 100644 index f12b964..0000000 Binary files a/zhuike/src/main/assets/font/qihei.ttf and /dev/null differ diff --git a/zhuike/src/main/java/com/deiniu/zhuike/Config.java b/zhuike/src/main/java/com/deiniu/zhuike/Config.java index a059571..e6222cb 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/Config.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/Config.java @@ -92,13 +92,14 @@ public class Config { } public Typeface getTypeface(String typeFacePath){ - Typeface mTypeface; + return Typeface.DEFAULT; + /* Typeface mTypeface; if (typeFacePath.equals(FONTTYPE_DEFAULT)){ mTypeface = Typeface.DEFAULT; }else{ mTypeface = Typeface.createFromAsset(mContext.getAssets(),typeFacePath); } - return mTypeface; + return mTypeface;*/ } public void setTypeface(String typefacePath){ diff --git a/zhuike/src/main/java/com/deiniu/zhuike/Fragments/Fragment_Shelf.java b/zhuike/src/main/java/com/deiniu/zhuike/Fragments/Fragment_Shelf.java index d30eb45..dfe46d2 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/Fragments/Fragment_Shelf.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/Fragments/Fragment_Shelf.java @@ -117,6 +117,7 @@ public class Fragment_Shelf extends BasicFragment { } @Override public void initViews(){ + initData(); initReceyleView(); } @@ -265,6 +266,11 @@ public class Fragment_Shelf extends BasicFragment { public void onResume() { super.onResume(); + // initData(); + // mAdapter.notifyDataSetChanged(); + // synchronized (mAdapter) { + + // Refresh the state of the +1 button each time the activity receives focus. // ((Main2Activity)getActivity()).swithToolbarItems(); diff --git a/zhuike/src/main/java/com/deiniu/zhuike/dialog/SettingDialog.java b/zhuike/src/main/java/com/deiniu/zhuike/dialog/SettingDialog.java index a339c6b..2bc8a6a 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/dialog/SettingDialog.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/dialog/SettingDialog.java @@ -13,6 +13,7 @@ import android.widget.SeekBar; import android.widget.TextView; +import com.baidu.android.common.logging.Log; import com.deiniu.zhuike.Config; import com.deiniu.zhuike.R; import com.deiniu.zhuike.utils.DisplayUtils; @@ -115,8 +116,8 @@ public class SettingDialog extends Dialog { tv_default.setTypeface(config.getTypeface(Config.FONTTYPE_DEFAULT)); tv_qihei.setTypeface(config.getTypeface(Config.FONTTYPE_QIHEI)); // tv_fzxinghei.setTypeface(config.getTypeface(Config.FONTTYPE_FZXINGHEI)); - tv_fzkatong.setTypeface(config.getTypeface(Config.FONTTYPE_FZKATONG)); - tv_bysong.setTypeface(config.getTypeface(Config.FONTTYPE_BYSONG)); + // tv_fzkatong.setTypeface(config.getTypeface(Config.FONTTYPE_FZKATONG)); + // tv_bysong.setTypeface(config.getTypeface(Config.FONTTYPE_BYSONG)); // tv_xinshou.setTypeface(config.getTypeface(Config.FONTTYPE_XINSHOU)); // tv_wawa.setTypeface(config.getTypeface(Config.FONTTYPE_WAWA)); selectTypeface(config.getTypefacePath()); @@ -239,10 +240,14 @@ public class SettingDialog extends Dialog { //设置字体 public void setTypeface(String typeface) { - config.setTypeface(typeface); - Typeface tface = config.getTypeface(typeface); - if (mSettingListener != null) { - mSettingListener.changeTypeFace(tface); + try { + config.setTypeface(typeface); + Typeface tface = config.getTypeface(typeface); + if (mSettingListener != null) { + mSettingListener.changeTypeFace(tface); + } + }catch (Exception e){ + Log.e("SettingDialog",e.getMessage()); } } @@ -301,16 +306,22 @@ public class SettingDialog extends Dialog { setTypeface(Config.FONTTYPE_QIHEI); break; case R.id.tv_fzxinghei: - selectTypeface(Config.FONTTYPE_FZXINGHEI); - setTypeface(Config.FONTTYPE_FZXINGHEI); + selectTypeface(Config.FONTTYPE_QIHEI); + setTypeface(Config.FONTTYPE_QIHEI); + // selectTypeface(Config.FONTTYPE_FZXINGHEI); + // setTypeface(Config.FONTTYPE_FZXINGHEI); break; case R.id.tv_fzkatong: - selectTypeface(Config.FONTTYPE_FZKATONG); - setTypeface(Config.FONTTYPE_FZKATONG); + selectTypeface(Config.FONTTYPE_QIHEI); + setTypeface(Config.FONTTYPE_QIHEI); + //selectTypeface(Config.FONTTYPE_FZKATONG); + //setTypeface(Config.FONTTYPE_FZKATONG); break; case R.id.tv_bysong: - selectTypeface(Config.FONTTYPE_BYSONG); - setTypeface(Config.FONTTYPE_BYSONG); + // selectTypeface(Config.FONTTYPE_BYSONG); + // setTypeface(Config.FONTTYPE_BYSONG); + selectTypeface(Config.FONTTYPE_QIHEI); + setTypeface(Config.FONTTYPE_QIHEI); break; // case R.id.tv_xinshou: // selectTypeface(Config.FONTTYPE_XINSHOU); diff --git a/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java b/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java index 78996cd..87a56df 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java @@ -5,6 +5,7 @@ import android.os.Environment; import android.text.TextUtils; +import android.util.Log; import com.deiniu.zhuike.bean.Cache; import com.deiniu.zhuike.db.BookChapter; @@ -25,11 +26,13 @@ import java.util.List; public class BookUtil { - private static final String cachedPath = Environment.getExternalStorageDirectory() + "/treader/"; + public static final String TAG ="BookUtil"; + private static final String cachedPath = Environment.getExternalStorageDirectory() + "/zhuike/"; //存储的字符数 public static final int cachedSize = 30000; // protected final ArrayList> myArray = new ArrayList<>(); + public static final String lineBreakChar ="\n"; protected final ArrayList myArray = new ArrayList<>(); //目录 private List directoryList = new ArrayList<>(); @@ -41,6 +44,10 @@ public class BookUtil { private long position; private Book bookList; + public String getLineBreakChar(){ + return "\n"; + } + public BookUtil(){ File file = new File(cachedPath); if (!file.exists()){ @@ -52,6 +59,8 @@ public class BookUtil { this.bookList = bookList; //如果当前缓存不是要打开的书本就缓存书本同时删除缓存 + //TODO 构建新的缓存策略,几个选项,1:每本书一个缓存 2:控制缓存总大小,超过限制删除旧缓存 3:网络小说的缓存 + if (bookPath == null || !bookPath.equals(bookList.getBookpath())) { cleanCacheFile(); this.bookPath = bookList.getBookpath(); @@ -96,7 +105,7 @@ public class BookUtil { break; } char wordChar = (char) word; - if ((wordChar + "").equals("\r") && (((char)next(true)) + "").equals("\n")){ + if ((wordChar + "").equals("\r") ){// if ((wordChar + "").equals("\r") && (((char)next(true)) + "").equals("\n")){ next(false); break; } @@ -116,7 +125,7 @@ public class BookUtil { break; } char wordChar = (char) word; - if ((wordChar + "").equals("\n") && (((char)pre(true)) + "").equals("\r")){ + if ((wordChar + "").equals("\n") ){ // if ((wordChar + "").equals("\n") && (((char)pre(true)) + "").equals("\r")){ pre(false); // line = "\r\n" + line; break; @@ -196,15 +205,17 @@ public class BookUtil { } String bufStr = new String(buf); -// bufStr = bufStr.replaceAll("\r\n","\r\n\u3000\u3000"); + + // Log.e(TAG,String.format("缓存的内容是\n %s",bufStr)); + bufStr = bufStr.replaceAll("\r\n","\n"); // bufStr = bufStr.replaceAll("\u3000\u3000+[ ]*","\u3000\u3000"); - bufStr = bufStr.replaceAll("\r\n+\\s*","\r\n\u3000\u3000"); + bufStr = bufStr.replaceAll("\n+\\s*","\n\u3000");// bufStr = bufStr.replaceAll("\r\n+\\s*","\r\n\u3000\u3000"); // bufStr = bufStr.replaceAll("\r\n[ {0,}]","\r\n\u3000\u3000"); // bufStr = bufStr.replaceAll(" ",""); bufStr = bufStr.replaceAll("\u0000",""); buf = bufStr.toCharArray(); bookLen += buf.length; - + // Log.e(TAG,String.format("缓存的内容脱空格处理后\n %s",bufStr)); Cache cache = new Cache(); cache.setSize(buf.length); cache.setData(new WeakReference(buf)); @@ -213,12 +224,14 @@ public class BookUtil { myArray.add(cache); // myArray.add(new WeakReference(buf)); // myArray.set(index,); + // Log.e(TAG,String.format("缓存的内容写入文件\n %s",fileName(index))); + // Log.e(TAG,"---------------------------------------------------------------------------------------------------------"); try { File cacheBook = new File(fileName(index)); if (!cacheBook.exists()){ cacheBook.createNewFile(); } - final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileName(index)), "UTF-16LE"); + final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileName(index)), "UTF-16LE"); // UTF-16LE 比 utf-8 文件小 writer.write(buf); writer.close(); } catch (IOException e) { @@ -242,15 +255,19 @@ public class BookUtil { for (int i = 0; i < myArray.size(); i++) { char[] buf = block(i); String bufStr = new String(buf); - String[] paragraphs = bufStr.split("\r\n"); + String[] paragraphs = bufStr.split(lineBreakChar); // String[] paragraphs = bufStr.split("\r\n"); for (String str : paragraphs) { - if (str.length() <= 30 && (str.matches(".*第.{1,8}章.*") || str.matches(".*第.{1,8}节.*"))) { + + // if (str.length() <= 30 && (str.matches(".*第.{1,8}章.*") || str.matches(".*第.{1,8}节.*"))) { + if(isChapterTitle(str)) { BookChapter bookCatalogue = new BookChapter(); bookCatalogue.setBookChapterStartPos(size); - bookCatalogue.setChapterName(str); + bookCatalogue.setChapterName(str.replaceAll("###","")); bookCatalogue.setBookpath(bookPath); directoryList.add(bookCatalogue); + } + // Log.e(TAG,String.format("当前行\n %s",str)); if (str.contains("\u3000\u3000")) { size += str.length() + 2; }else if (str.contains("\u3000")){ @@ -309,5 +326,7 @@ public class BookUtil { } return block; } - + public boolean isChapterTitle(String line){ + return (line.length() <= 30 && (line.matches(".*第.{1,8}章.*") || line.matches(".*第.{1,8}节.*"))) ; + } } diff --git a/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java b/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java index d376bfb..e49dbea 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java @@ -32,7 +32,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -import static com.baidu.tts.loopj.AsyncHttpClient.log; +//import static com.baidu.tts.loopj.AsyncHttpClient.log; public class PageFactory { @@ -298,7 +298,7 @@ public class PageFactory { super.run(); values.put("begin",currentPage.getBegin()); int rows = LitePal.update(Book.class,values,bookList.getId()); - log.e(TAG,String.format("update book %s bigin %s, result %s",bookList.getBookname(),currentPage.getBegin(),rows) ); + Log.e(TAG,String.format("update book %s bigin %s, result %s",bookList.getBookname(),currentPage.getBegin(),rows) ); } }.start(); } @@ -534,9 +534,13 @@ public class PageFactory { while (mBookUtil.next(true) != -1){ char word = (char) mBookUtil.next(false); //判断是否换行 - if ((word + "" ).equals("\r") && (((char) mBookUtil.next(true)) + "").equals("\n")){ + if ((word + "" ).equals("\n") ){// if ((word + "" ).equals("\r") && (((char) mBookUtil.next(true)) + "").equals("\n")){ mBookUtil.next(false); if (!line.isEmpty()){ + if (mBookUtil.isChapterTitle(line)) { + Log.e(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition() )); + // break; + } lines.add(line); line = ""; width = 0; @@ -550,6 +554,9 @@ public class PageFactory { width += widthChar; if (width > mVisibleWidth) { width = widthChar; + if (mBookUtil.isChapterTitle(line)) { + // break; + } lines.add(line); line = word + ""; } else { @@ -566,11 +573,17 @@ public class PageFactory { } if (!line.isEmpty() && lines.size() < mLineCount){ + /* if (!mBookUtil.isChapterTitle(line)) { + lines.add(line); + }else + { + mBookUtil.setPostition(mBookUtil.getPosition() - line.length()); + }*/ lines.add(line); } - for (String str : lines){ - Log.e(TAG,str + " "); - } + //for (String str : lines){ + // Log.e(TAG,str + " "); + // } return lines; } diff --git a/zhuike/src/main/java/com/deiniu/zhuike/view/animation/AnimationProvider.java b/zhuike/src/main/java/com/deiniu/zhuike/view/animation/AnimationProvider.java index b4d9832..68402c5 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/view/animation/AnimationProvider.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/view/animation/AnimationProvider.java @@ -36,7 +36,7 @@ public abstract class AnimationProvider { // private Mode myMode = Mode.NoScrolling; - protected int duation =300;//翻页动画速度 + protected int duation =200;//翻页动画速度 protected Bitmap mCurPageBitmap,mNextPageBitmap; protected float myStartX; protected float myStartY; diff --git a/zhuike/src/main/res/layout/zdialog_setting.xml b/zhuike/src/main/res/layout/zdialog_setting.xml index 5ca8038..7b283ca 100644 --- a/zhuike/src/main/res/layout/zdialog_setting.xml +++ b/zhuike/src/main/res/layout/zdialog_setting.xml @@ -99,7 +99,9 @@ + android:orientation="horizontal" + android:visibility="gone" + >