working on txt import

This commit is contained in:
mwang 2019-02-27 16:36:15 +08:00
parent 0c77fe2756
commit 37e87afbbe
2 changed files with 29 additions and 13 deletions

View File

@ -126,12 +126,13 @@ public class BookUtil {
} }
char wordChar = (char) word; char wordChar = (char) word;
if ((wordChar + "").equals("\n") ){ // if ((wordChar + "").equals("\n") && (((char)pre(true)) + "").equals("\r")){ if ((wordChar + "").equals("\n") ){ // if ((wordChar + "").equals("\n") && (((char)pre(true)) + "").equals("\r")){
pre(false); // pre(false); // /r/n ->/n 不需要再往前读一个字符了
// line = "\r\n" + line; // line = "\r\n" + line;
break; break;
} }
line = wordChar + line; line = wordChar + line;
} }
return line.toCharArray(); return line.toCharArray();
} }

View File

@ -390,7 +390,13 @@ public class PageFactory {
cancelPage = currentPage; cancelPage = currentPage;
onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true); onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true);
currentPage = getPrePage(); currentPage = getPrePage();
onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true); onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true);
} }
//向后翻页 //向后翻页
@ -526,6 +532,7 @@ public class PageFactory {
return trPage; return trPage;
} }
boolean showChapTitleOnTopWhenNextPage =false;
public List<String> getNextLines(){ public List<String> getNextLines(){
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
float width = 0; float width = 0;
@ -536,10 +543,10 @@ public class PageFactory {
//判断是否换行 //判断是否换行
if ((word + "" ).equals("\n") ){// 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); mBookUtil.next(false);
if (!line.isEmpty()){ if ( !line.isEmpty()){
if (mBookUtil.isChapterTitle(line)) { if (showChapTitleOnTopWhenNextPage && lines.size() >0 && mBookUtil.isChapterTitle(line)) {
Log.e(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition() )); Log.e(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition() ));
// break; break;
} }
lines.add(line); lines.add(line);
line = ""; line = "";
@ -554,9 +561,6 @@ public class PageFactory {
width += widthChar; width += widthChar;
if (width > mVisibleWidth) { if (width > mVisibleWidth) {
width = widthChar; width = widthChar;
if (mBookUtil.isChapterTitle(line)) {
// break;
}
lines.add(line); lines.add(line);
line = word + ""; line = word + "";
} else { } else {
@ -573,13 +577,14 @@ public class PageFactory {
} }
if (!line.isEmpty() && lines.size() < mLineCount){ if (!line.isEmpty() && lines.size() < mLineCount){
/* if (!mBookUtil.isChapterTitle(line)) {
if (!(showChapTitleOnTopWhenNextPage && mBookUtil.isChapterTitle(line) ) ) {
lines.add(line); lines.add(line);
}else }else
{ {
mBookUtil.setPostition(mBookUtil.getPosition() - line.length()); mBookUtil.setPostition(mBookUtil.getPosition() - line.length()-2);
}*/ }
lines.add(line); // lines.add(line);
} }
//for (String str : lines){ //for (String str : lines){
// Log.e(TAG,str + " "); // Log.e(TAG,str + " ");
@ -606,7 +611,17 @@ public class PageFactory {
} else { } else {
line += word; line += word;
} }
// Log.e(TAG,"preLine is \n" + line);
} }
/* if ( mBookUtil.isChapterTitle(line)) {
mBookUtil.setPostition(mBookUtil.getPosition() - line.length()-2);
break;
}*/
// lines.add(line);
// Log.e(TAG,"preLine is \n" + line);
if (!line.isEmpty()){ if (!line.isEmpty()){
preLines.add(line); preLines.add(line);
} }
@ -634,7 +649,7 @@ public class PageFactory {
if (num > 0){ if (num > 0){
if ( mBookUtil.getPosition() > 0) { if ( mBookUtil.getPosition() > 0) {
mBookUtil.setPostition(mBookUtil.getPosition() + num + 2); mBookUtil.setPostition(mBookUtil.getPosition() + num + 1);//mBookUtil.setPostition(mBookUtil.getPosition() + num + 2); // /r/n -> /n,只需要回退1个字符
}else{ }else{
mBookUtil.setPostition(mBookUtil.getPosition() + num ); mBookUtil.setPostition(mBookUtil.getPosition() + num );
} }