working on txt import
This commit is contained in:
parent
f1f1c6ecc8
commit
afe62ea40e
|
@ -10,6 +10,7 @@ public class Config {
|
|||
private final static String BOOK_BG_KEY = "bookbg";
|
||||
private final static String FONT_TYPE_KEY = "fonttype";
|
||||
private final static String FONT_SIZE_KEY = "fontsize";
|
||||
private final static String LINE_SPACE_KEY = "linespace";
|
||||
private final static String NIGHT_KEY = "night";
|
||||
private final static String LIGHT_KEY = "light";
|
||||
private final static String SYSTEM_LIGHT_KEY = "systemlight";
|
||||
|
@ -41,6 +42,9 @@ public class Config {
|
|||
private Typeface typeface;
|
||||
//字体大小
|
||||
private float mFontSize = 0;
|
||||
|
||||
//行间距
|
||||
private float mLineSpace =0;
|
||||
//亮度值
|
||||
private float light = 0;
|
||||
private int bookBG;
|
||||
|
@ -118,7 +122,17 @@ public class Config {
|
|||
mFontSize = fontSize;
|
||||
sp.edit().putFloat(FONT_SIZE_KEY,fontSize).commit();
|
||||
}
|
||||
public float getLineSpace(){
|
||||
if (mLineSpace == 0){
|
||||
mLineSpace = sp.getFloat(LINE_SPACE_KEY, mContext.getResources().getDimension(R.dimen.reading_line_spacing));
|
||||
}
|
||||
return mLineSpace;
|
||||
}
|
||||
|
||||
public void setLineSpace(float lineSpace){
|
||||
mLineSpace = lineSpace;
|
||||
sp.edit().putFloat(LINE_SPACE_KEY,lineSpace).commit();
|
||||
}
|
||||
/**
|
||||
* 获取夜间还是白天阅读模式,true为夜晚,false为白天
|
||||
*/
|
||||
|
|
|
@ -139,8 +139,10 @@ public abstract class BasicFragment extends Fragment {
|
|||
//从新从数据库抓取该书的最新阅读进度
|
||||
|
||||
Book book1 = (Book)LitePal.find(Book.class,book.getId());
|
||||
book.setBegin(book1.getBegin());
|
||||
book.setBiginChapt(book1.getBiginChapt());
|
||||
if(book1!=null) { //读取本地最新进度
|
||||
book.setBegin(book1.getBegin());
|
||||
book.setBiginChapt(book1.getBiginChapt());
|
||||
}
|
||||
Toast.makeText(activity, book.getBookname() + "加载", Toast.LENGTH_SHORT).show();
|
||||
|
||||
final String path = book.getBookpath();
|
||||
|
|
|
@ -58,7 +58,7 @@ public class BookMarkFragment extends BasicFragment {
|
|||
lv_bookmark.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
pageFactory.changeChapter(bookMarksList.get(position).getBegin());
|
||||
pageFactory.changeChapter(position+1);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -50,7 +50,7 @@ public class CatalogFragment extends BasicFragment {
|
|||
lv_catalogue.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
pageFactory.changeChapter(catalogueList.get(position).getBookChapterStartPos());
|
||||
pageFactory.changeChapter(position+1);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.deiniu.zhuike.Fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -51,7 +52,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
LinearLayout llShelfBottom;
|
||||
@BindView(R.id.id_recyclerview)
|
||||
RecyclerView mRecyclerView;
|
||||
private List<Book> mDatas;
|
||||
// private List<Book> mDatas;
|
||||
private BookListAdapter mAdapter;
|
||||
|
||||
private List<Book> bookLists;
|
||||
|
@ -82,7 +83,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
public void initData() {
|
||||
|
||||
flag = new boolean[100];
|
||||
mDatas = initData(mDatas,'X');
|
||||
// mDatas = initData(mDatas,'X');
|
||||
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
|
||||
|
@ -120,8 +121,32 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
initData();
|
||||
initReceyleView();
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
if(hidden){
|
||||
//pause
|
||||
}else{
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
//相当于Fragment的onResume,为true时,Fragment已经可见
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
//相当于Fragment的onPause,为false时,Fragment不可见
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void initReceyleView() {
|
||||
|
||||
// mRecyclerView.setLayoutManager(new LinearLayoutManager(this.activity));
|
||||
|
@ -152,17 +177,21 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
public void onClick(View view) {
|
||||
bottomSheetDialog.dismiss();
|
||||
Intent intent = new Intent(activity, FileChooserActivity.class);
|
||||
startActivity(intent);
|
||||
startActivityForResult(intent, Activity.RESULT_FIRST_USER);
|
||||
// startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||
// bookLists = LitePal.findAll(Book.class);
|
||||
// mAdapter.notifyDataSetChanged();
|
||||
initViews();
|
||||
}
|
||||
|
||||
private void initDialog(int position) {
|
||||
|
||||
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this.activity);
|
||||
|
@ -172,7 +201,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
.setBackgroundColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
TextView tv =(TextView) bottomSheetDialog.findViewById(R.id.bdTitle);
|
||||
tv.setText(mDatas.get(position).getBookname());
|
||||
tv.setText(bookLists.get(position).getBookname());
|
||||
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
|
@ -199,9 +228,10 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
isSelectAll =!isSelectAll;
|
||||
mChkAdapter.notifyDataSetChanged();
|
||||
}else if(view.getId()== R.id.btnDelete){
|
||||
for (int i = 0; i < mDatas.size(); i++) {
|
||||
for (int i = 0; i < bookLists.size(); i++) {
|
||||
if(flag[i] ){
|
||||
mDatas.remove(i);
|
||||
bookLists.get(i).delete();
|
||||
bookLists.remove(i);
|
||||
}
|
||||
}
|
||||
mChkAdapter.notifyDataSetChanged();
|
||||
|
@ -266,8 +296,8 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// initData();
|
||||
// mAdapter.notifyDataSetChanged();
|
||||
// bookLists = LitePal.findAll(Book.class);
|
||||
// mAdapter.notifyDataSetChanged();
|
||||
// synchronized (mAdapter) {
|
||||
|
||||
|
||||
|
@ -284,7 +314,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
|
||||
CheckAdapter mChkAdapter;
|
||||
void zhengliShelf(){
|
||||
mChkAdapter = new CheckAdapter(activity,mDatas,R.layout.recycle_list_item,new OnItemClickListener()
|
||||
mChkAdapter = new CheckAdapter(activity,bookLists,R.layout.recycle_list_item,new OnItemClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,6 +51,7 @@ public class Main2Activity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app =(MyApp) getApplicationContext();
|
||||
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
|
||||
setContentView(R.layout.activity_main2);
|
||||
ButterKnife.bind(this);
|
||||
|
@ -392,6 +393,7 @@ private int bottomSelectedIndex;
|
|||
long firstTime =0;
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if( navigationView.isShown()){
|
||||
|
||||
|
@ -407,9 +409,11 @@ private int bottomSelectedIndex;
|
|||
|
||||
return true;
|
||||
} else {
|
||||
|
||||
app.exit();
|
||||
return false;
|
||||
// return super.onKeyUp(keyCode, event);
|
||||
app.exit();
|
||||
// return super.onKeyUp(keyCode, event);
|
||||
// return false;
|
||||
finish();
|
||||
}
|
||||
}
|
||||
try{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.deiniu.zhuike;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -96,6 +97,9 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
@BindView(R.id.appbar)
|
||||
AppBarLayout appbar;
|
||||
|
||||
@BindView(R.id.llTopAd)
|
||||
LinearLayout llTopAd;
|
||||
|
||||
private Config config;
|
||||
private WindowManager.LayoutParams lp;
|
||||
private Book book;
|
||||
|
@ -110,6 +114,12 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
private SpeechSynthesizer mSpeechSynthesizer;
|
||||
private boolean isSpeaking = false;
|
||||
|
||||
public void showTopAd(boolean show){
|
||||
llTopAd.setVisibility(show? View.VISIBLE:View.GONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 接收电池信息更新的广播
|
||||
private BroadcastReceiver myReceiver = new BroadcastReceiver(){
|
||||
@Override
|
||||
|
@ -279,6 +289,11 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
public void changeBookBg(int type) {
|
||||
pageFactory.changeBookBg(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeLineHeight(int lineHeight) {
|
||||
pageFactory.changeLineHight(lineHeight);
|
||||
}
|
||||
});
|
||||
|
||||
pageFactory.setPageEvent(new PageFactory.PageEvent() {
|
||||
|
@ -398,11 +413,47 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
mPageModeDialog.hide();
|
||||
return true;
|
||||
}
|
||||
finish();
|
||||
|
||||
showNormalDialog();//finish();
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
private void showNormalDialog(){
|
||||
/* @setIcon 设置对话框图标
|
||||
* @setTitle 设置对话框标题
|
||||
* @setMessage 设置对话框消息提示
|
||||
* setXXX方法返回Dialog对象,因此可以链式设置属性
|
||||
*/
|
||||
final AlertDialog.Builder normalDialog =
|
||||
new AlertDialog.Builder(ReadActivity.this);
|
||||
|
||||
normalDialog.setTitle("退出阅读");
|
||||
normalDialog.setMessage("确定退出阅读吗?");
|
||||
normalDialog.setPositiveButton("继续阅读",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
hideSystemUI();
|
||||
}
|
||||
});
|
||||
normalDialog.setNegativeButton("退出阅读",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
normalDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
hideSystemUI();
|
||||
}
|
||||
});
|
||||
// 显示
|
||||
normalDialog.show();
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
|
|
|
@ -62,6 +62,8 @@ public class SettingDialog extends Dialog {
|
|||
TextView tv_fzkatong;
|
||||
@BindView(R.id.tv_bysong)
|
||||
TextView tv_bysong;
|
||||
@BindView(R.id.tv_lhsize)
|
||||
TextView tv_lineSpace;
|
||||
|
||||
|
||||
private Config config;
|
||||
|
@ -71,6 +73,11 @@ public class SettingDialog extends Dialog {
|
|||
private int FONT_SIZE_MAX;
|
||||
private int currentFontSize;
|
||||
|
||||
private int LINE_SPACE_MIN;
|
||||
private int LINE_SPACE_MAX;
|
||||
private int currentLineSpace;
|
||||
|
||||
|
||||
private SettingDialog(Context context, boolean flag, OnCancelListener listener) {
|
||||
super(context, flag, listener);
|
||||
}
|
||||
|
@ -101,6 +108,8 @@ public class SettingDialog extends Dialog {
|
|||
FONT_SIZE_MIN = (int) getContext().getResources().getDimension(R.dimen.reading_min_text_size);
|
||||
FONT_SIZE_MAX = (int) getContext().getResources().getDimension(R.dimen.reading_max_text_size);
|
||||
|
||||
LINE_SPACE_MAX =60;
|
||||
LINE_SPACE_MIN =10;
|
||||
config = Config.getInstance();
|
||||
|
||||
//初始化亮度
|
||||
|
@ -112,6 +121,10 @@ public class SettingDialog extends Dialog {
|
|||
currentFontSize = (int) config.getFontSize();
|
||||
tv_size.setText(currentFontSize + "");
|
||||
|
||||
//初始化行间距
|
||||
currentLineSpace =(int) config.getLineSpace();
|
||||
tv_lineSpace.setText(currentLineSpace+"");
|
||||
|
||||
//初始化字体
|
||||
tv_default.setTypeface(config.getTypeface(Config.FONTTYPE_DEFAULT));
|
||||
tv_qihei.setTypeface(config.getTypeface(Config.FONTTYPE_QIHEI));
|
||||
|
@ -281,7 +294,7 @@ public class SettingDialog extends Dialog {
|
|||
|
||||
|
||||
@OnClick({R.id.tv_dark, R.id.tv_bright, R.id.tv_xitong, R.id.tv_subtract, R.id.tv_add, R.id.tv_size_default, R.id.tv_qihei, R.id.tv_fzxinghei, R.id.tv_fzkatong,R.id.tv_bysong,
|
||||
R.id.tv_default, R.id.iv_bg_default, R.id.iv_bg_1, R.id.iv_bg_2, R.id.iv_bg_3, R.id.iv_bg_4})
|
||||
R.id.tv_default, R.id.iv_bg_default, R.id.iv_bg_1, R.id.iv_bg_2, R.id.iv_bg_3, R.id.iv_bg_4,R.id.tv_lhadd,R.id.tv_lhreduct,R.id.tv_lhsize_default})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.tv_dark:
|
||||
|
@ -355,8 +368,49 @@ public class SettingDialog extends Dialog {
|
|||
setBookBg(Config.BOOK_BG_4);
|
||||
selectBg(Config.BOOK_BG_4);
|
||||
break;
|
||||
case R.id.tv_lhadd:
|
||||
addLineSpace();
|
||||
break;
|
||||
case R.id.tv_lhreduct:
|
||||
subtractLineSpace();
|
||||
break;
|
||||
case R.id.tv_lhsize_default:
|
||||
defaultLineSpace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
//变大行间距
|
||||
private void addLineSpace() {
|
||||
if (currentLineSpace < LINE_SPACE_MAX) {
|
||||
currentLineSpace += 1;
|
||||
tv_lineSpace.setText(currentLineSpace + "");
|
||||
config.setLineSpace(currentLineSpace);
|
||||
if (mSettingListener != null) {
|
||||
mSettingListener.changeLineHeight(currentLineSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
//默认行间距
|
||||
private void defaultLineSpace() {
|
||||
currentLineSpace = (int) getContext().getResources().getDimension(R.dimen.reading_line_spacing);
|
||||
tv_lineSpace.setText(currentLineSpace + "");
|
||||
config.setLineSpace(currentLineSpace);
|
||||
if (mSettingListener != null) {
|
||||
mSettingListener.changeLineHeight(currentLineSpace);
|
||||
}
|
||||
}
|
||||
//变小行间距
|
||||
private void subtractLineSpace() {
|
||||
if (currentLineSpace > LINE_SPACE_MIN) {
|
||||
currentLineSpace -= 1;
|
||||
tv_lineSpace.setText(currentLineSpace + "");
|
||||
config.setLineSpace(currentLineSpace);
|
||||
if (mSettingListener != null) {
|
||||
mSettingListener.changeLineHeight(currentLineSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//变大书本字体
|
||||
private void addFontSize() {
|
||||
|
@ -414,6 +468,8 @@ public class SettingDialog extends Dialog {
|
|||
void changeTypeFace(Typeface typeface);
|
||||
|
||||
void changeBookBg(int type);
|
||||
|
||||
void changeLineHeight(int lineHeight);
|
||||
}
|
||||
|
||||
}
|
|
@ -261,7 +261,7 @@ public class BookUtil {
|
|||
// Log.e(TAG,String.format("缓存的内容是\n %s",bufStr));
|
||||
bufStr = bufStr.replaceAll("\r\n","\n");
|
||||
// bufStr = bufStr.replaceAll("\u3000\u3000+[ ]*","\u3000\u3000");
|
||||
bufStr = bufStr.replaceAll("\n+\\s*","\n\u3000");// bufStr = bufStr.replaceAll("\r\n+\\s*","\r\n\u3000\u3000");
|
||||
bufStr = bufStr.replaceAll("\n+\\s*","\n\u3000\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","");
|
||||
|
|
|
@ -165,6 +165,14 @@ public class PageFactory {
|
|||
while(length <chars.length ) {
|
||||
pageNo++;
|
||||
TRPage page = getNextChapterPage(length);
|
||||
Log.e(TAG,"page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getBookLen());
|
||||
|
||||
if(page.getBegin() == mBookUtil.getBookLen() ){ //最后一页空白的情况。。。
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
page.setPageNo(pageNo);
|
||||
chaptPages.add(page);
|
||||
length= page.getEnd();
|
||||
|
@ -186,6 +194,8 @@ public class PageFactory {
|
|||
|
||||
private static Status mStatus = Status.OPENING;
|
||||
|
||||
|
||||
|
||||
public enum Status {
|
||||
OPENING,
|
||||
FINISH,
|
||||
|
@ -228,6 +238,8 @@ public class PageFactory {
|
|||
|
||||
typeface = config.getTypeface();
|
||||
m_fontSize = config.getFontSize();
|
||||
lineSpace =config.getLineSpace();
|
||||
paragraphSpace = (long)(1.15 * lineSpace);
|
||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);// 画笔
|
||||
mPaint.setTextAlign(Paint.Align.LEFT);// 左对齐
|
||||
mPaint.setTextSize(m_fontSize);// 字体大小
|
||||
|
@ -294,7 +306,10 @@ public class PageFactory {
|
|||
private void calculateLineCount(){
|
||||
mLineCount = (int) (mVisibleHeight / (m_fontSize + lineSpace));// 可显示的行数
|
||||
}
|
||||
|
||||
private void calculateLineCount(float paragrapheight){
|
||||
mLineCount = (int) ((mVisibleHeight - paragrapheight ) / (m_fontSize + lineSpace));// 可显示的行数
|
||||
Log.e(TAG,"line count is " + mLineCount +" paragrapheight is " +paragrapheight);
|
||||
}
|
||||
private void drawStatus(Bitmap bitmap){
|
||||
String status = "";
|
||||
switch (mStatus){
|
||||
|
@ -335,10 +350,11 @@ 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() ) );
|
||||
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) );
|
||||
}
|
||||
}.start();
|
||||
Log.e(TAG,String.format("update book %s chapter%s bigin %s, result %s",bookList.getBookname(),currentChapter, currentPage.getBegin(),rows) );
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
Canvas c = new Canvas(bitmap);
|
||||
|
@ -350,11 +366,24 @@ public class PageFactory {
|
|||
if (m_lines.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
float space =m_fontSize + lineSpace;
|
||||
if (m_lines.size() > 0) {
|
||||
float y = marginHeight;
|
||||
for (String strLine : m_lines) {
|
||||
y += m_fontSize + lineSpace;
|
||||
// if(strLine.endsWith("\n")) {
|
||||
// if(strLine.charAt(strLine.length()-1) == ('\n' )) {
|
||||
// Log.e("TAG", strLine);
|
||||
// Log.e("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));
|
||||
}else{
|
||||
y += space;
|
||||
space =m_fontSize + lineSpace;
|
||||
Log.e("TAG",String.format("%s,y plus is %s" ,strLine, m_fontSize + lineSpace));
|
||||
}
|
||||
c.drawText(strLine, measureMarginWidth, y, mPaint);
|
||||
// word.append(strLine);
|
||||
}
|
||||
|
@ -362,13 +391,15 @@ public class PageFactory {
|
|||
|
||||
//画进度及时间
|
||||
int dateWith = (int) (mBatterryPaint.measureText(date)+mBorderWidth);//时间宽度
|
||||
float fPercent = (float) (currentPage.getBegin() * 1.0 / mBookUtil.getBookLen());//进度
|
||||
// float fPercent = (float) (currentPage.getBegin() * 1.0 / mBookUtil.getBookLen());//进度
|
||||
float fPercent = (float) (currentPage.getPageNo() * 1.0 /currentChaptPages.size());//进度
|
||||
currentProgress = fPercent;
|
||||
if (mPageEvent != null){
|
||||
mPageEvent.changeProgress(fPercent);
|
||||
}
|
||||
String strPercent = df.format(fPercent * 100) + "%";//进度文字
|
||||
int nPercentWidth = (int) mBatterryPaint.measureText("999.9%") + 1; //Paint.measureText直接返回參數字串所佔用的寬度
|
||||
// String strPercent = df.format(fPercent * 100) + "%";//进度文字
|
||||
String strPercent = String.format("%s/%s",currentPage.getPageNo(),currentChaptPages.size()) + "页";//进度文字
|
||||
int nPercentWidth = (int) mBatterryPaint.measureText("10/25页") + 50; //Paint.measureText直接返回參數字串所佔用的寬度
|
||||
c.drawText(strPercent, mWidth - nPercentWidth, mHeight - statusMarginBottom, mBatterryPaint);//x y为坐标值
|
||||
c.drawText(date, marginWidth ,mHeight - statusMarginBottom, mBatterryPaint);
|
||||
// 画电池
|
||||
|
@ -498,7 +529,7 @@ public class PageFactory {
|
|||
// m_mbBufLen = mBookUtil.getBookLen();
|
||||
mBookUtil.setChapterNo((int)chapter);
|
||||
currentChaptPages = loadCurrentChapt((int)chapter);
|
||||
currentPage = currentChaptPages.get(0);
|
||||
currentPage = getPageForBegin(begin) ;// currentChaptPages.get(0);
|
||||
// currentPage = getPageForBegin(begin);
|
||||
if (mBookPageWidget != null) {
|
||||
currentPage(true);
|
||||
|
@ -574,7 +605,8 @@ public class PageFactory {
|
|||
return trPage;
|
||||
*/
|
||||
int prePageNo =currentPage.getPageNo()-1;
|
||||
if(prePageNo ==0){
|
||||
Log.d(TAG,String.format("currentPageno %s,total pagno %s",currentPage.getPageNo(),currentChaptPages.size()));
|
||||
if(prePageNo <=0){
|
||||
nextChaptPages =currentChaptPages;
|
||||
currentChapter--;
|
||||
if(currentChapter ==0) {
|
||||
|
@ -614,6 +646,10 @@ public class PageFactory {
|
|||
float width = 0;
|
||||
float height = 0;
|
||||
String line = "";
|
||||
if(mBookUtil.getPosition()==0) {
|
||||
lines.add("\n");lines.add("\n");
|
||||
}
|
||||
calculateLineCount();
|
||||
while (mBookUtil.next(true) != -1){
|
||||
char word = (char) mBookUtil.next(false);
|
||||
//判断是否换行
|
||||
|
@ -624,11 +660,13 @@ public class PageFactory {
|
|||
Log.e(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition() ));
|
||||
break;
|
||||
}
|
||||
lines.add(line);
|
||||
lines.add(line+word);
|
||||
// lines.add("\n");
|
||||
line = "";
|
||||
width = 0;
|
||||
// height += paragraphSpace;
|
||||
if (lines.size() == mLineCount){
|
||||
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()));
|
||||
line ="";
|
||||
break;
|
||||
|
@ -752,6 +790,7 @@ public class PageFactory {
|
|||
return reLines;
|
||||
}
|
||||
|
||||
|
||||
//上一章
|
||||
public void preChapter(){
|
||||
if (mBookUtil.getDirectoryList().size() > 0){
|
||||
|
@ -761,10 +800,14 @@ public class PageFactory {
|
|||
}
|
||||
num --;
|
||||
if (num >= 0){
|
||||
long begin = mBookUtil.getDirectoryList().get(num).getBookChapterStartPos();
|
||||
currentPage = getPageForBegin(begin);
|
||||
currentPage(true);
|
||||
|
||||
nextChaptPages =currentChaptPages;
|
||||
currentChapter = num;
|
||||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
currentPage = getPageForBegin(0);
|
||||
currentPage(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -777,10 +820,14 @@ public class PageFactory {
|
|||
}
|
||||
num ++;
|
||||
if (num < getDirectoryList().size()){
|
||||
long begin = getDirectoryList().get(num).getBookChapterStartPos();
|
||||
currentPage = getPageForBegin(begin);
|
||||
currentPage(true);
|
||||
|
||||
preChaptPages =currentChaptPages;
|
||||
currentChapter = num;
|
||||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
currentPage = getPageForBegin(0);
|
||||
currentPage(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -835,17 +882,36 @@ public class PageFactory {
|
|||
}
|
||||
|
||||
//改变进度
|
||||
public void changeChapter(long begin){
|
||||
currentPage = getPageForBegin(begin);
|
||||
public void changeChapter(int chapNum){
|
||||
|
||||
preChaptPages =currentChaptPages;
|
||||
currentChapter = chapNum;
|
||||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
currentPage = getPageForBegin(0);
|
||||
currentPage(true);
|
||||
|
||||
}
|
||||
|
||||
//改变行间距
|
||||
public void changeLineHight(int lineSpace) {
|
||||
|
||||
this.lineSpace = lineSpace;
|
||||
mPaint.setTextSize(m_fontSize);
|
||||
calculateLineCount();
|
||||
measureMarginWidth();
|
||||
currentChaptPages = loadCurrentChapt(currentChapter );
|
||||
currentPage = getPageForBegin(currentPage.getBegin());
|
||||
currentPage(true);
|
||||
|
||||
}
|
||||
//改变字体大小
|
||||
public void changeFontSize(int fontSize){
|
||||
this.m_fontSize = fontSize;
|
||||
mPaint.setTextSize(m_fontSize);
|
||||
calculateLineCount();
|
||||
measureMarginWidth();
|
||||
currentChaptPages = loadCurrentChapt(currentChapter );
|
||||
currentPage = getPageForBegin(currentPage.getBegin());
|
||||
currentPage(true);
|
||||
}
|
||||
|
@ -857,6 +923,7 @@ public class PageFactory {
|
|||
mBatterryPaint.setTypeface(typeface);
|
||||
calculateLineCount();
|
||||
measureMarginWidth();
|
||||
|
||||
currentPage = getPageForBegin(currentPage.getBegin());
|
||||
currentPage(true);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,34 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#000000">
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.deiniu.zhuike.view.PageWidget
|
||||
<com.deiniu.zhuike.view.PageWidget
|
||||
android:id="@+id/bookpage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
<LinearLayout
|
||||
android:id="@+id/llTopAd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_gravity="top"
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@mipmap/side_bg"
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -95,7 +95,44 @@
|
|||
android:layout_marginLeft="20dp"
|
||||
android:text="@string/setting_default" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/setting_height"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/tv_lhreduct"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_weight="1"
|
||||
android:textSize="30sp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/read_dialog_button_select"
|
||||
android:text="@string/setting_subtract_line_space" />
|
||||
<TextView
|
||||
android:id="@+id/tv_lhsize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:text="30" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_lhadd"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_weight="1"
|
||||
android:textSize="30sp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/read_dialog_button_select"
|
||||
android:text="@string/setting_add_line_space" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_lhsize_default"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text="@string/setting_default" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/setting_height"
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
<!-- 状态栏离底部距离 -->
|
||||
<dimen name="reading_status_margin_bottom">3dp</dimen>
|
||||
<!-- 行间距 -->
|
||||
<dimen name="reading_line_spacing">10dp</dimen>
|
||||
<dimen name="reading_line_spacing">15dp</dimen>
|
||||
<!-- 段间距 -->
|
||||
<dimen name="reading_paragraph_spacing">30dp</dimen>
|
||||
<dimen name="reading_paragraph_spacing">35dp</dimen>
|
||||
<!-- 书本字体默认大小 -->
|
||||
<dimen name="reading_default_text_size">20sp</dimen>
|
||||
<!-- 书本字体最小大小 -->
|
||||
|
|
|
@ -162,8 +162,10 @@
|
|||
<string name="setting_system">系统</string>
|
||||
<string name="setting_dark">暗</string>
|
||||
<string name="setting_bright">亮</string>
|
||||
<string name="setting_add">A+</string>
|
||||
<string name="setting_subtract">A-</string>
|
||||
<string name="setting_add">字体+</string>
|
||||
<string name="setting_subtract">字体-</string>
|
||||
<string name="setting_add_line_space">行高+</string>
|
||||
<string name="setting_subtract_line_space">行高-</string>
|
||||
<string name="setting_default">默认</string>
|
||||
|
||||
<string name="font_default">系统默认</string>
|
||||
|
|
Loading…
Reference in New Issue