working on txt import

This commit is contained in:
mwang 2019-03-07 23:07:27 +08:00
parent afe62ea40e
commit bca7b2f4bb
1 changed files with 35 additions and 32 deletions

View File

@ -71,6 +71,8 @@ public class PageFactory {
private float lineSpace;
//段间距
private float paragraphSpace;
//段间距相对行间距的倍数
private final float prate = 1.3f;
//字高度
private float fontHeight;
//字体
@ -165,12 +167,12 @@ public class PageFactory {
while(length <chars.length ) {
pageNo++;
TRPage page = getNextChapterPage(length);
Log.e(TAG,"page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getBookLen());
Log.d(TAG,"page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getBookLen());
if(page.getBegin() == mBookUtil.getBookLen() ){ //最后一页空白的情况
// if(page.getBegin() == mBookUtil.getBookLen() ){ //最后一页空白的情况
break;
}
// break;
// }
page.setPageNo(pageNo);
@ -184,9 +186,9 @@ public class PageFactory {
TRPage trPage = new TRPage();
trPage.setBegin(position +1);
Log.e(TAG,"page postion next begin:" + (position + 1) + "");
Log.d(TAG,"page postion next begin:" + (position + 1) + "");
trPage.setLines(getNextLines());
Log.e(TAG,"page postion next end:" +mBookUtil.getPosition() + "");
Log.d(TAG,"page postion next end:" +mBookUtil.getPosition() + "");
trPage.setEnd(mBookUtil.getPosition());
return trPage;
}
@ -239,7 +241,7 @@ public class PageFactory {
typeface = config.getTypeface();
m_fontSize = config.getFontSize();
lineSpace =config.getLineSpace();
paragraphSpace = (long)(1.15 * lineSpace);
paragraphSpace = prate * lineSpace ;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);// 画笔
mPaint.setTextAlign(Paint.Align.LEFT);// 左对齐
mPaint.setTextSize(m_fontSize);// 字体大小
@ -308,7 +310,7 @@ public class PageFactory {
}
private void calculateLineCount(float paragrapheight){
mLineCount = (int) ((mVisibleHeight - paragrapheight ) / (m_fontSize + lineSpace));// 可显示的行数
Log.e(TAG,"line count is " + mLineCount +" paragrapheight is " +paragrapheight);
Log.d(TAG,"line count is " + mLineCount +" paragrapheight is " +paragrapheight);
}
private void drawStatus(Bitmap bitmap){
String status = "";
@ -350,9 +352,9 @@ public class PageFactory {
super.run();
values.put("begin",currentPage.getBegin());
values.put("biginChapt",currentChapter);
Log.e(TAG,String.format("begin to update book %s chapter%s bigin %s ",bookList.getBookname(),currentChapter, currentPage.getBegin() ) );
Log.d(TAG,String.format("begin to update book %s chapter%s bigin %s ",bookList.getBookname(),currentChapter, currentPage.getBegin() ) );
int rows = LitePal.update(Book.class,values,bookList.getId());
Log.e(TAG,String.format("update book %s chapter%s bigin %s, result %s",bookList.getBookname(),currentChapter, currentPage.getBegin(),rows) );
Log.d(TAG,String.format("update book %s chapter%s bigin %s, result %s",bookList.getBookname(),currentChapter, currentPage.getBegin(),rows) );
}
}.start();
}
@ -367,22 +369,23 @@ public class PageFactory {
return;
}
float space =m_fontSize + lineSpace;
paragraphSpace = prate * lineSpace;
if (m_lines.size() > 0) {
float y = marginHeight;
for (String strLine : m_lines) {
// if(strLine.endsWith("\n")) {
// if(strLine.charAt(strLine.length()-1) == ('\n' )) {
// Log.e("TAG", strLine);
// Log.e("TAG","最后字符 。。。" +strLine.charAt(strLine.length()-1) + "");
// Log.d("TAG", strLine);
// Log.d("TAG","最后字符 。。。" +strLine.charAt(strLine.length()-1) + "");
if(( strLine.charAt(strLine.length()-1) + "" ).equals("\n")){
strLine =strLine.replace("\n","");
y += space;
space =m_fontSize + paragraphSpace;
Log.e("TAG",String.format("开始新段落 %s, y plus is %s" ,strLine, m_fontSize + paragraphSpace));
Log.d("TAG",String.format("开始新段落 %s, y plus is %s" ,strLine, m_fontSize + paragraphSpace));
}else{
y += space;
space =m_fontSize + lineSpace;
Log.e("TAG",String.format("%s,y plus is %s" ,strLine, m_fontSize + lineSpace));
Log.d("TAG",String.format("%s,y plus is %s" ,strLine, m_fontSize + lineSpace));
}
c.drawText(strLine, measureMarginWidth, y, mPaint);
// word.append(strLine);
@ -446,7 +449,7 @@ public class PageFactory {
//向前翻页
public void prePage(){
if (currentPage.getBegin() <= 0) {
Log.e(TAG,"当前是本章第一页");
Log.d(TAG,"当前是本章第一页");
m_isfirstPage =currentChapter ==1;
if ( m_isfirstPage){
Toast.makeText(mContext, "当前是第一页", Toast.LENGTH_SHORT).show();
@ -464,7 +467,7 @@ public class PageFactory {
//向后翻页
public void nextPage(){
if (currentPage.getEnd() >= mBookUtil.getBookLen()) {
Log.e(TAG,"已经是本章最后一页了");
Log.d(TAG,"已经是本章最后一页了");
m_islastPage =currentChapter == mBookUtil.getDirectoryList().size();
if ( m_islastPage){
@ -481,7 +484,7 @@ public class PageFactory {
currentPage = getNextPage();
// currentPage = currentChaptPages.get(currentPage.getPageNo()-1);
onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true);
Log.e("nextPage","nextPagenext");
Log.d("nextPage","nextPagenext");
}
//取消翻页
@ -520,7 +523,7 @@ public class PageFactory {
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
Log.e("onPostExecute",isCancelled() + "");
Log.d("onPostExecute",isCancelled() + "");
if (isCancelled()){
return;
}
@ -575,9 +578,9 @@ public class PageFactory {
TRPage trPage = new TRPage();
trPage.setBegin(currentPage.getEnd() +1);
Log.e(TAG,"page postion next begin:" + (currentPage.getEnd() + 1) + "");
Log.d(TAG,"page postion next begin:" + (currentPage.getEnd() + 1) + "");
trPage.setLines(getNextLines());
Log.e(TAG,"page postion next end:" +mBookUtil.getPosition() + "");
Log.d(TAG,"page postion next end:" +mBookUtil.getPosition() + "");
trPage.setEnd(mBookUtil.getPosition());
return trPage;
*/
@ -598,9 +601,9 @@ public class PageFactory {
TRPage trPage = new TRPage();
trPage.setEnd(mBookUtil.getPosition() -1);
Log.e(TAG,"page postion pre end:" + (mBookUtil.getPosition() - 1 )+ "");
Log.d(TAG,"page postion pre end:" + (mBookUtil.getPosition() - 1 )+ "");
trPage.setLines(getPreLines());
Log.e(TAG,"page postion pre begin:" +mBookUtil.getPosition() + "");
Log.d(TAG,"page postion pre begin:" +mBookUtil.getPosition() + "");
trPage.setBegin(mBookUtil.getPosition() );
return trPage;
*/
@ -657,7 +660,7 @@ public class PageFactory {
// mBookUtil.next(false);
if ( !line.isEmpty()){
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.d(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition() ));
break;
}
lines.add(line+word);
@ -667,7 +670,7 @@ public class PageFactory {
height += paragraphSpace - lineSpace;
calculateLineCount(height);
if (lines.size()>= mLineCount){
Log.e(TAG,String.format("lines count limit a %s,lines size %s",mLineCount,lines.size()));
Log.d(TAG,String.format("lines count limit a %s,lines size %s",mLineCount,lines.size()));
line ="";
break;
}
@ -679,7 +682,7 @@ public class PageFactory {
width = widthChar;
lines.add(line);
/* if (lines.size() == mLineCount){
Log.e(TAG,String.format("lines count limit b %s,lines size %s",mLineCount,lines.size()));
Log.d(TAG,String.format("lines count limit b %s,lines size %s",mLineCount,lines.size()));
line ="";
break;
}
@ -691,7 +694,7 @@ public class PageFactory {
}
if (lines.size() == mLineCount){
Log.e(TAG,String.format("lines count limit c %s,lines size %s",mLineCount,lines.size()));
Log.d(TAG,String.format("lines count limit c %s,lines size %s",mLineCount,lines.size()));
if (!line.isEmpty()){
// mBookUtil.setPostition(mBookUtil.getPosition() - line.length()-2);// mBookUtil.setPostition(mBookUtil.getPosition() - 1);
mBookUtil.setPostition(mBookUtil.getPosition() - 1);
@ -701,8 +704,8 @@ public class PageFactory {
}
/*
if (lines.size() == mLineCount) {
Log.e(TAG, String.format("lines count limit d %s,lines size %s", mLineCount, lines.size()));
Log.e(TAG, String.format("lines count limit d %s,line is \n %s", mLineCount, line));
Log.d(TAG, String.format("lines count limit d %s,lines size %s", mLineCount, lines.size()));
Log.d(TAG, String.format("lines count limit d %s,line is \n %s", mLineCount, line));
if (!line.isEmpty()) {
mBookUtil.setPostition(mBookUtil.getPosition() - line.length() - 2);// mBookUtil.setPostition(mBookUtil.getPosition() - 1);
}
@ -719,7 +722,7 @@ public class PageFactory {
// lines.add(line);
}
for (String str : lines){
Log.e(TAG,str + " ");
Log.d(TAG,str + " ");
}
return lines;
}
@ -743,7 +746,7 @@ public class PageFactory {
} else {
line += word;
}
// Log.e(TAG,"preLine is \n" + line);
// Log.d(TAG,"preLine is \n" + line);
}
/* if ( mBookUtil.isChapterTitle(line)) {
@ -753,7 +756,7 @@ public class PageFactory {
}*/
// lines.add(line);
// Log.e(TAG,"preLine is \n" + line);
// Log.d(TAG,"preLine is \n" + line);
if (!line.isEmpty()){
preLines.add(line);
}
@ -776,7 +779,7 @@ public class PageFactory {
}else{
num = num + lines.get(i).length();
}
Log.e(TAG,lines.get(i) + " ");
Log.d(TAG,lines.get(i) + " ");
}
if (num > 0){