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