working on txt import

This commit is contained in:
mwang 2019-02-26 23:02:27 +08:00
parent 9ddeeec4bc
commit 0c77fe2756
10 changed files with 85 additions and 33 deletions

View File

@ -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){

View File

@ -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();

View File

@ -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);

View File

@ -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<WeakReference<char[]>> myArray = new ArrayList<>();
public static final String lineBreakChar ="\n";
protected final ArrayList<Cache> myArray = new ArrayList<>();
//目录
private List<BookChapter> 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<char[]>(buf));
@ -213,12 +224,14 @@ public class BookUtil {
myArray.add(cache);
// myArray.add(new WeakReference<char[]>(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}节.*"))) ;
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -99,7 +99,9 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/setting_height"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone"
>
<TextView
android:id="@+id/tv_default"
style="@style/setting_dialog_button"