多线程问题
This commit is contained in:
parent
bd17a920c0
commit
b3eb69339a
|
@ -313,7 +313,7 @@ public class BookActivity extends Activity_base {
|
|||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
|
||||
pageFactory.prepareBook(mNovel, BookActivity.this);
|
||||
pageFactory.prepareBook(mNovel );
|
||||
|
||||
// Toast.makeText(BookActivity.this,"Novel 请求成功:"+result,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ public class BookActivity extends Activity_base {
|
|||
mNovel = Novel.getNovelBySvrId(novelId);
|
||||
if(null != mNovel) {
|
||||
handler.sendEmptyMessage(1);
|
||||
pageFactory.prepareBook(mNovel, BookActivity.this);
|
||||
pageFactory.prepareBook(mNovel );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -157,7 +157,8 @@ public abstract class BasicFragment extends Fragment {
|
|||
|
||||
nv= LitePal.find(Novel.class,id);
|
||||
|
||||
PageFactory.getInstance().prepareBook(nv, getActivity());
|
||||
PageFactory.getInstance().prepareBook(nv ); //打开本地小说内容
|
||||
ReadActivity.openBook(nv ,activity);
|
||||
|
||||
}
|
||||
|
||||
|
@ -165,7 +166,8 @@ public abstract class BasicFragment extends Fragment {
|
|||
public void onFault(String errorMsg) {
|
||||
//失败
|
||||
Toast.makeText(getActivity(),"Novel 请求失败:"+errorMsg,Toast.LENGTH_SHORT).show();
|
||||
PageFactory.getInstance().prepareBook(novel, getActivity()); //打开本地小说内容
|
||||
PageFactory.getInstance().prepareBook(novel ); //打开本地小说内容
|
||||
ReadActivity.openBook(novel ,activity);
|
||||
}
|
||||
},getActivity()));
|
||||
|
||||
|
@ -183,7 +185,7 @@ public abstract class BasicFragment extends Fragment {
|
|||
|
||||
if(!book.isLocalBook()){
|
||||
getBookInfo(book);
|
||||
ReadActivity.openBook(book ,activity);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.novelbook.android.Fragments;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -30,7 +31,20 @@ public class CatalogFragment extends BasicFragment {
|
|||
|
||||
@BindView(R.id.lv_catalogue)
|
||||
ListView lv_catalogue;
|
||||
private ProgressDialog progressDialog;
|
||||
private void showProgressDialog() {
|
||||
if ( null == progressDialog) {
|
||||
progressDialog =new ProgressDialog(getActivity());
|
||||
}
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
|
||||
private void dismissProgressDialog() {
|
||||
if ( null != progressDialog) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected int getLayoutRes() {
|
||||
return R.layout.fragment_catalog;
|
||||
|
@ -50,7 +64,9 @@ public class CatalogFragment extends BasicFragment {
|
|||
lv_catalogue.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
showProgressDialog();
|
||||
pageFactory.changeChapter(position+1);
|
||||
dismissProgressDialog();
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.novelbook.android;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -24,6 +25,7 @@ import android.view.View;
|
|||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
|
@ -40,6 +42,7 @@ import com.novelbook.android.db.Novel;
|
|||
import com.novelbook.android.db.BookMarks;
|
||||
import com.novelbook.android.dialog.PageModeDialog;
|
||||
import com.novelbook.android.dialog.SettingDialog;
|
||||
import com.novelbook.android.utils.AdInterface;
|
||||
import com.novelbook.android.utils.BrightnessUtil;
|
||||
import com.novelbook.android.utils.PageFactory;
|
||||
import com.novelbook.android.view.PageWidget;
|
||||
|
@ -57,7 +60,7 @@ import butterknife.BindView;
|
|||
import butterknife.OnClick;
|
||||
|
||||
|
||||
public class ReadActivity extends Activity_base implements SpeechSynthesizerListener {
|
||||
public class ReadActivity extends Activity_base implements SpeechSynthesizerListener , AdInterface {
|
||||
private static final String TAG = "ReadActivity";
|
||||
private final static String EXTRA_BOOK = "book";
|
||||
// private final static String EXTRA_CHAPTER = "chapter";
|
||||
|
@ -172,6 +175,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
|
||||
config = Config.getInstance();
|
||||
pageFactory = PageFactory.getInstance();
|
||||
pageFactory.setAd(this);
|
||||
|
||||
IntentFilter mfilter = new IntentFilter();
|
||||
mfilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
|
@ -322,9 +326,13 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
|
||||
@Override
|
||||
public Boolean prePage() {
|
||||
if (isShow || isSpeaking){
|
||||
if (isShow) {
|
||||
hideReadSetting();
|
||||
return false;
|
||||
}
|
||||
if (isShow || isSpeaking){
|
||||
// return false;
|
||||
}
|
||||
|
||||
pageFactory.prePage();
|
||||
if (pageFactory.isfirstPage()) {
|
||||
|
@ -337,9 +345,13 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
@Override
|
||||
public Boolean nextPage() {
|
||||
Log.e("setTouchListener", "nextPage");
|
||||
if (isShow || isSpeaking){
|
||||
if (isShow) {
|
||||
hideReadSetting();
|
||||
return false;
|
||||
}
|
||||
if (isShow || isSpeaking){
|
||||
// return false;
|
||||
}
|
||||
|
||||
pageFactory.nextPage();
|
||||
if (pageFactory.islastPage()) {
|
||||
|
@ -708,7 +720,9 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
*/
|
||||
}
|
||||
|
||||
@OnClick({R.id.tv_progress, R.id.rl_progress, R.id.tv_pre, R.id.sb_progress, R.id.tv_next, R.id.tv_directory, R.id.tv_dayornight,R.id.tv_pagemode, R.id.tv_setting, R.id.bookpop_bottom, R.id.rl_bottom,R.id.tv_stop_read})
|
||||
@OnClick({R.id.tv_progress, R.id.rl_progress, R.id.tv_pre, R.id.sb_progress, R.id.tv_next, R.id.tv_directory,
|
||||
R.id.tv_dayornight,R.id.tv_pagemode, R.id.tv_setting, R.id.bookpop_bottom, R.id.rl_bottom,R.id.tv_stop_read
|
||||
,R.id.llTopAd})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
// case R.id.btn_return:
|
||||
|
@ -753,10 +767,36 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
isSpeaking = false;
|
||||
hideReadSetting();
|
||||
}
|
||||
case R.id.llTopAd:
|
||||
Toast.makeText(this,"ad is clicked ",Toast.LENGTH_LONG).show();
|
||||
Log.d(TAG,"Ad is clicked");
|
||||
showProgressDialog();// sleep 结束后才显示,dismiss 不工作
|
||||
/* try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
dismissProgressDialog();
|
||||
break;
|
||||
}
|
||||
}
|
||||
ProgressDialog progressDialog;
|
||||
private void showProgressDialog() {
|
||||
if ( null == progressDialog) {
|
||||
progressDialog =ProgressDialog.show(this,"测试","你点了广告",false,true); //new ProgressDialog(this);
|
||||
}else{
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void dismissProgressDialog() {
|
||||
if ( null != progressDialog) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* @param arg0
|
||||
*/
|
||||
|
@ -838,4 +878,19 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
Log.e(TAG,error.description);
|
||||
}
|
||||
|
||||
final int contentAdHight=350;
|
||||
|
||||
@Override
|
||||
public void showAd(int adHeight,int adY) {
|
||||
|
||||
|
||||
llTopAd.setVisibility(View.GONE);
|
||||
if(adHeight >contentAdHight){
|
||||
|
||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) llTopAd.getLayoutParams();
|
||||
params.setMargins(20, adY, 20, 10);
|
||||
llTopAd.setLayoutParams(params);
|
||||
llTopAd.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,11 +244,12 @@ public class HttpMethods {
|
|||
public Response intercept(Chain chain) throws IOException {
|
||||
Response originalResponse = chain.proceed(chain.request());
|
||||
String cacheControl = originalResponse.header("Cache-Control");
|
||||
int maxAge =60*60; //一小时
|
||||
if (cacheControl == null || cacheControl.contains("no-store") || cacheControl.contains("no-cache") ||
|
||||
cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) {
|
||||
cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) { //目标网站禁用cache则设置为1小时
|
||||
return originalResponse.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, max-age=" + 5000)
|
||||
.header("Cache-Control", "public, max-age=" + maxAge)
|
||||
.build();
|
||||
} else {
|
||||
return originalResponse;
|
||||
|
@ -261,9 +262,10 @@ public class HttpMethods {
|
|||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (!NetUtil.isNetworkConnected()) {
|
||||
int maxStale = 60 * 60 * 24 * 28;
|
||||
request = request.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, only-if-cached")
|
||||
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
|
||||
.build();
|
||||
}
|
||||
return chain.proceed(request);
|
||||
|
|
|
@ -50,8 +50,10 @@ public class OnSuccessAndFaultSub extends DisposableObserver<ResponseBody>
|
|||
*/
|
||||
public OnSuccessAndFaultSub(OnSuccessAndFaultListener mOnSuccessAndFaultListener, Context context) {
|
||||
this.mOnSuccessAndFaultListener = mOnSuccessAndFaultListener;
|
||||
this.context = context;
|
||||
progressDialog = new ProgressDialog(context);
|
||||
if(context!=null) {
|
||||
this.context = context;
|
||||
progressDialog = new ProgressDialog(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.novelbook.android.utils;
|
||||
|
||||
public interface AdInterface {
|
||||
/**
|
||||
* 显示activity 上的广告
|
||||
* @param height
|
||||
* @param adY
|
||||
*/
|
||||
public void showAd(int height,int adY);
|
||||
}
|
|
@ -133,7 +133,7 @@ public class BookUtil {
|
|||
}
|
||||
mNovel.setDomain(mSite.getDomain());
|
||||
mNovel.setMuluUrl(mSite.getMuluUrl());
|
||||
mNovel.save();
|
||||
mNovel.update(mNovel.getId());
|
||||
}
|
||||
|
||||
public void getTargetSites(){
|
||||
|
@ -151,15 +151,15 @@ public class BookUtil {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Toast.makeText(mContext,"getMuluInfo 请求成功 " ,Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(mContext,"getMuluInfo 请求成功 " ,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault(String errorMsg) {
|
||||
//失败
|
||||
Toast.makeText(mContext,"getMuluInfo 请求失败"+errorMsg,Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(mContext,"getMuluInfo 请求失败"+errorMsg,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
},mContext));
|
||||
},null));
|
||||
}
|
||||
private void getSiteRule() {
|
||||
mSiteRule = null;
|
||||
|
@ -235,6 +235,7 @@ public class BookUtil {
|
|||
progressDialog =new ProgressDialog(mContext);
|
||||
}
|
||||
progressDialog.show();
|
||||
// progressDialog.show(mContext,"网络不给力","正努力加载",false,true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -260,7 +261,7 @@ public class BookUtil {
|
|||
boolean isLocalImport = TextUtils.isEmpty( novel.getNovelId());
|
||||
boolean isOnShelf = isLocalImport || novel.isOnShelf();
|
||||
boolean isLoadChaptsFromRemote = !isLocalImport ;// && !novel.isFinished() ; //是否从目标网站下载目录
|
||||
showProgressDialog();
|
||||
// showProgressDialog();
|
||||
if(isLocalImport) {
|
||||
|
||||
mChapters = LitePal.where("novelId=?", mNovel.getId() + "").find(Chapter.class);
|
||||
|
@ -287,12 +288,13 @@ public class BookUtil {
|
|||
Thread.sleep(50);
|
||||
Log.d(TAG,String.format("waiting for mulu downloading ,mMuluStatus %s" ,mMuluStatus));
|
||||
if(mMuluStatus == MuluStatus.failed){
|
||||
dismissProgressDialog();
|
||||
throw new RuntimeException("读取资源失败,请检查网络");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
dismissProgressDialog();
|
||||
// dismissProgressDialog();
|
||||
}
|
||||
|
||||
// String getMuluUrl() {
|
||||
|
@ -500,7 +502,12 @@ public class BookUtil {
|
|||
}
|
||||
public char chaptCurrent(){
|
||||
|
||||
|
||||
char[] charArray = chaptChars(chapterNo);
|
||||
|
||||
|
||||
|
||||
|
||||
return charArray[(int)position-1];
|
||||
}
|
||||
public char current(){
|
||||
|
@ -750,7 +757,7 @@ public class BookUtil {
|
|||
return cachedPath + mNovel.getName() + index ;
|
||||
}
|
||||
protected String fileChapterName(int chaptId ) {
|
||||
if(TextUtils.isEmpty(mNovel.getDomain())){
|
||||
if(!TextUtils.isEmpty(mNovel.getDomain())){
|
||||
|
||||
return getChapterPath() +mNovel.getDomain()+"/"+ chaptId ;
|
||||
}
|
||||
|
@ -799,21 +806,27 @@ public class BookUtil {
|
|||
}
|
||||
|
||||
boolean isDownloadChapt =false;
|
||||
|
||||
void setDownloadFlag(boolean flag){
|
||||
synchronized boolean getDownloadStatus(){
|
||||
return isDownloadChapt;
|
||||
}
|
||||
synchronized void setDownloadFlag(boolean flag){
|
||||
isDownloadChapt = flag;
|
||||
Log.d("loadChaptContent",String.format("set download flat",isDownloadChapt) );
|
||||
}
|
||||
|
||||
Handler handler = new Handler() {
|
||||
final Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
|
||||
int wt = msg.what;
|
||||
|
||||
dismissProgressDialog();
|
||||
|
||||
if (msg.what == 123) {
|
||||
isDownloadChapt =true;
|
||||
Log.d("loadChaptContent",String.format("handler msg, download %s",isDownloadChapt) );
|
||||
}else if(msg.what==1){
|
||||
|
||||
isDownloadChapt =true;
|
||||
Toast.makeText(mContext,"网络错误",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
@ -842,22 +855,34 @@ public class BookUtil {
|
|||
|
||||
Log.d(TAG,String.format("loadChaptContent----start %s" ,new Date().toString() ));
|
||||
|
||||
loadChaptContent(index);
|
||||
//showProgressDialog();//why not show
|
||||
|
||||
// showProgressDialog();//why not show
|
||||
Log.d( "loadChaptContent",String.format("begin to load content for chapter %s",index));
|
||||
Log.d( "loadChaptContent",String.format("isDownloadChapt: %s",isDownloadChapt));
|
||||
|
||||
if(getDownloadStatus() ) {
|
||||
loadChaptContent(index);
|
||||
}
|
||||
|
||||
Log.d( "loadChaptContent",String.format("showing dialog " ));
|
||||
// Log.d(TAG,String.format("showing progress diaglog......"));
|
||||
int maxSleep =6000;
|
||||
int slepttime =0;
|
||||
while(!isDownloadChapt){
|
||||
// while(!file.exists() && !getDownloadStatus()){//&& slepttime <maxSleep){
|
||||
while( !getDownloadStatus() && slepttime <maxSleep){
|
||||
Thread.sleep(50);
|
||||
slepttime+=50;
|
||||
Log.d(TAG,String.format("loadChaptContent slept %s for downloading ",slepttime ) );
|
||||
Log.d("loadChaptContent",String.format("loadChaptContent slept %s for downloading,isDownload %s ",slepttime,getDownloadStatus() ) );
|
||||
}
|
||||
// dismissProgressDialog();
|
||||
// Log.d(TAG,String.format("loadChaptContent slept %s for downloading %s ",slepttime, mChapters.get(index -1).getChapterName() ));
|
||||
Log.d("loadChaptContent",String.format("loadChaptContent slept %s for downloading ",slepttime ) );
|
||||
Log.d( "loadChaptContent",String.format("dismissing dialog " ));
|
||||
dismissProgressDialog();
|
||||
Log.d(TAG,String.format("loadChaptContent slept %s for downloading chaptercontent ",slepttime ));
|
||||
}
|
||||
|
||||
Log.d( "loadChaptContent",String.format(" %s, file.exists()? %s", file.getPath(),file.exists()));
|
||||
if(!file.exists()) {
|
||||
String error = "网络错误";
|
||||
|
||||
String error = "万里长城";
|
||||
return error.toCharArray();
|
||||
}
|
||||
if(mChapters.size() > index ) {
|
||||
|
@ -893,6 +918,8 @@ public class BookUtil {
|
|||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
dismissProgressDialog();
|
||||
}
|
||||
Cache cache = new Cache();
|
||||
cache.setSize(block.length);
|
||||
|
@ -920,6 +947,7 @@ private void loadChaptContent(int index) throws JSONException, InterruptedExcept
|
|||
|
||||
setDownloadFlag(false);
|
||||
|
||||
Log.d( "loadChaptContent",String.format("loadChaptContent isDownloadChapt: %s",isDownloadChapt));
|
||||
JSONObject siteJson = new JSONObject();
|
||||
siteJson.put("chapterContentRegex", mSiteRule.getChapterContentRegex());
|
||||
siteJson.put("chapterContentDumpRegex", mSiteRule.getChapterContentDumpRegex());
|
||||
|
@ -928,9 +956,11 @@ private void loadChaptContent(int index) throws JSONException, InterruptedExcept
|
|||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
handler.sendEmptyMessage(123);
|
||||
handler.sendEmptyMessage(1);
|
||||
setDownloadFlag(true);
|
||||
Log.d(TAG, "loadChaptContent---- onFailure: " + e.getMessage());
|
||||
throw new RuntimeException("Error during writing " + fileChapterName( index));
|
||||
Log.d( "loadChaptContent",String.format("loadChaptContent fail, isDownloadChapt: %s",isDownloadChapt));
|
||||
e.printStackTrace();
|
||||
// throw new RuntimeException("Error during writing " + fileChapterName( index));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -938,8 +968,9 @@ private void loadChaptContent(int index) throws JSONException, InterruptedExcept
|
|||
ResponseBody body = response.body();
|
||||
if (body != null ) {
|
||||
if(response.code()!=200){
|
||||
|
||||
Log.d(TAG, "loadChaptContent----network failure returnCode " + response.code());
|
||||
setDownloadFlag(true);
|
||||
Log.d( "loadChaptContent",String.format("loadChaptContent error %s ,isDownloadChapt: %s", response.code(),isDownloadChapt));
|
||||
handler.sendEmptyMessage(1);
|
||||
return;
|
||||
}
|
||||
|
@ -955,6 +986,9 @@ private void loadChaptContent(int index) throws JSONException, InterruptedExcept
|
|||
final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileChapterName(index)), charachterType);//"UTF-16LE"); // UTF-16LE 比 utf-8 文件小
|
||||
writer.write(buf);
|
||||
writer.close();
|
||||
Log.d( "loadChaptContent",String.format("loadChaptContent file created: %s", file.getPath()));
|
||||
handler.sendEmptyMessage(123);
|
||||
setDownloadFlag(true);
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Error during writing " + fileChapterName( index));
|
||||
|
@ -963,12 +997,12 @@ private void loadChaptContent(int index) throws JSONException, InterruptedExcept
|
|||
body.close();
|
||||
|
||||
handler.sendEmptyMessage(123);
|
||||
setDownloadFlag(true);
|
||||
setDownloadFlag(true);
|
||||
}
|
||||
chapter.setNovelId(mNovel.getId());
|
||||
chapter.setChapterPath(fileChapterName(index));
|
||||
chapter.save();
|
||||
|
||||
setDownloadFlag(true);
|
||||
Log.d(TAG,String.format("loadChaptContent---- finished download %s, cost time %s ,content path %s ", chapter.getChapterName(), new Date().getTime() -startTime ,chapter.getChapterPath() ));
|
||||
|
||||
}
|
||||
|
|
|
@ -163,11 +163,16 @@ public class PageFactory {
|
|||
private List<TRPage> nextChaptPages;
|
||||
private List<TRPage> preChaptPages;
|
||||
|
||||
|
||||
private AdInterface mAd;
|
||||
public void setAd(AdInterface ad){
|
||||
mAd =ad;
|
||||
}
|
||||
private List<TRPage> loadCurrentChapt(int chaptId){
|
||||
List<TRPage> chaptPages = new ArrayList<TRPage>();
|
||||
|
||||
|
||||
char[] chars = mBookUtil.chaptChars(chaptId);
|
||||
|
||||
mBookUtil.setBookLen(chars.length);
|
||||
mBookUtil.setChapterNo(chaptId);
|
||||
// TRPage page = new TRPage();
|
||||
|
@ -183,11 +188,14 @@ public class PageFactory {
|
|||
// break;
|
||||
// }
|
||||
|
||||
|
||||
page.setChapterNo(chaptId);
|
||||
page.setLastPage(page.getEnd()==chars.length);
|
||||
page.setFirstPage(pageNo==1);
|
||||
page.setPageNo(pageNo);
|
||||
chaptPages.add(page);
|
||||
length= page.getEnd();
|
||||
}
|
||||
|
||||
return chaptPages;
|
||||
}
|
||||
public TRPage getNextChapterPage(long position){
|
||||
|
@ -359,11 +367,18 @@ public class PageFactory {
|
|||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
if(mBook.getLastReadChapt() !=currentChapter || mBook.getLastReadPos()!=currentPage.getBegin()) {
|
||||
mBook.setLastReadChapt(currentChapter);
|
||||
mBook.setLastReadPos(currentPage.getBegin());
|
||||
mBook.update(mBook.getId());
|
||||
}
|
||||
/*
|
||||
values.put("lastReadPos",currentPage.getBegin());
|
||||
values.put("lastReadChapt",currentChapter);
|
||||
Log.d(TAG,String.format("begin to update book %s chapter%s bigin %s ",mBook.getName(),currentChapter, currentPage.getBegin() ) );
|
||||
int rows = LitePal.update(Novel.class,values,mBook.getId());
|
||||
Log.d(TAG,String.format("update book %s chapter%s bigin %s, result %s",mBook.getName(),currentChapter, currentPage.getBegin(),rows) );
|
||||
*/
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
@ -379,6 +394,7 @@ public class PageFactory {
|
|||
}
|
||||
float space =m_fontSize + lineSpace;
|
||||
paragraphSpace = prate * lineSpace;
|
||||
|
||||
if (m_lines.size() > 0) {
|
||||
float y = marginHeight;
|
||||
for (String strLine : m_lines) {
|
||||
|
@ -399,6 +415,12 @@ public class PageFactory {
|
|||
c.drawText(strLine, measureMarginWidth, y, mPaint);
|
||||
// word.append(strLine);
|
||||
}
|
||||
|
||||
float adHeight = mHeight -y - space -marginHeight-statusMarginBottom;
|
||||
float adY =y +space;
|
||||
showAd((int)adHeight,(int)adY);
|
||||
Log.d(TAG,String.format("ad + statusMarginBottom %s ",200+ statusMarginBottom));
|
||||
Log.d(TAG,String.format("adHeight %s, adY %s",adHeight,adY));
|
||||
}
|
||||
|
||||
//画进度及时间
|
||||
|
@ -460,8 +482,19 @@ public class PageFactory {
|
|||
mBookPageWidget.postInvalidate();
|
||||
}
|
||||
|
||||
//向前翻页
|
||||
private void showAd(int adHeight,int adY) {
|
||||
if(mAd!=null){
|
||||
mAd.showAd(adHeight,adY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//向前翻页
|
||||
public void prePage(){
|
||||
if(null == currentPage){
|
||||
return;
|
||||
}
|
||||
m_isfirstPage = false;
|
||||
if (currentPage.getBegin() <= 1) {
|
||||
Log.d(TAG,"当前是本章第一页");
|
||||
|
@ -481,6 +514,9 @@ public class PageFactory {
|
|||
|
||||
//向后翻页
|
||||
public void nextPage(){
|
||||
if(null == currentPage){
|
||||
return;
|
||||
}
|
||||
m_islastPage = false;
|
||||
if (currentPage.getEnd() >= mBookUtil.getBookLen()) {
|
||||
Log.d(TAG,"已经是本章最后一页了");
|
||||
|
@ -505,15 +541,24 @@ public class PageFactory {
|
|||
|
||||
//取消翻页
|
||||
public void cancelPage(){
|
||||
if(cancelPage.isLastPage() || cancelPage.isFirstPage()){
|
||||
mBookUtil.setChapterNo(cancelPage.getChapterNo());
|
||||
currentChaptPages = loadCurrentChapt(cancelPage.getChapterNo());
|
||||
currentPage = getPageForBegin(cancelPage.getBegin()) ;// currentChaptPages.get(0);
|
||||
// currentPage = getPageForBegin(begin);
|
||||
if (mBookPageWidget != null) {
|
||||
currentPage(true);
|
||||
}
|
||||
}
|
||||
currentPage = cancelPage;
|
||||
}
|
||||
|
||||
public void prepareBook(Novel book, Context context){
|
||||
public void prepareBook(Novel book){
|
||||
if(mBook!=null &&mBook.getNovelId() !=book.getNovelId()){ //取消未上本书完成的web请求,待验证效果
|
||||
NetUtil.cancelRequest(mBook.getNovelId());
|
||||
}
|
||||
mBookUtil = new BookUtil();
|
||||
this.mBookUtil.setContext(context);
|
||||
//this.mBookUtil.setContext(context);
|
||||
this.mBookUtil.setNovel(book);
|
||||
this.mBookUtil.getTargetSites();
|
||||
}
|
||||
|
@ -525,9 +570,9 @@ public class PageFactory {
|
|||
public void openBook(Novel book ,Context context) throws IOException {
|
||||
if(book.isLocalBook() ){ //离线书籍重新初始化加载mBookUtil
|
||||
mBookUtil = new BookUtil();
|
||||
mBookUtil.setContext(context);
|
||||
}
|
||||
|
||||
}
|
||||
mBookUtil.setContext(context);
|
||||
//清空数据
|
||||
currentChapter = 0;
|
||||
// m_mbBufLen = 0;
|
||||
|
@ -645,6 +690,7 @@ public class PageFactory {
|
|||
trPage.setBegin(mBookUtil.getPosition() );
|
||||
return trPage;
|
||||
*/
|
||||
|
||||
int prePageNo =currentPage.getPageNo()-1;
|
||||
Log.d(TAG,String.format("currentPageno %s,total pagno %s",currentPage.getPageNo(),currentChaptPages.size()));
|
||||
if(prePageNo <=0){
|
||||
|
|
|
@ -7,8 +7,41 @@ import java.util.List;
|
|||
public class TRPage {
|
||||
private long begin;
|
||||
private long end;
|
||||
private int pageNo;
|
||||
private int chapterNo;
|
||||
private boolean isLastPage;
|
||||
private boolean isFirstPage;
|
||||
private List<String> lines = new ArrayList<>();
|
||||
|
||||
public int getChapterNo() {
|
||||
return chapterNo;
|
||||
}
|
||||
|
||||
public void setChapterNo(int chapterNo) {
|
||||
this.chapterNo = chapterNo;
|
||||
}
|
||||
|
||||
public boolean isLastPage() {
|
||||
return isLastPage;
|
||||
}
|
||||
|
||||
public void setLastPage(boolean lastPage) {
|
||||
isLastPage = lastPage;
|
||||
}
|
||||
|
||||
public boolean isFirstPage() {
|
||||
return isFirstPage;
|
||||
}
|
||||
|
||||
public void setFirstPage(boolean firstPage) {
|
||||
isFirstPage = firstPage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int getPageNo() {
|
||||
return pageNo;
|
||||
}
|
||||
|
@ -17,7 +50,7 @@ public class TRPage {
|
|||
this.pageNo = pageNo;
|
||||
}
|
||||
|
||||
private int pageNo;
|
||||
|
||||
|
||||
public long getBegin() {
|
||||
return begin;
|
||||
|
|
|
@ -219,7 +219,7 @@ public class PageWidget extends View {
|
|||
if (!isMove){
|
||||
cancelPage = false;
|
||||
//是否点击了中间
|
||||
if (downX > mScreenWidth / 5 && downX < mScreenWidth * 4 / 5 && downY > mScreenHeight / 3 && downY < mScreenHeight * 2 / 3){
|
||||
if (downX > mScreenWidth / 3 && downX < mScreenWidth * 2 / 3 && downY > mScreenHeight / 3 && downY < mScreenHeight * 2 / 3){
|
||||
if (mTouchListener != null){
|
||||
mTouchListener.center();
|
||||
}
|
||||
|
|
|
@ -4,120 +4,122 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#000000">
|
||||
android:background="#000000"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.novelbook.android.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:id="@+id/bookpage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@mipmap/side_bg"
|
||||
<LinearLayout
|
||||
android:id="@+id/llTopAd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
||||
android:layout_marginTop="520dp"
|
||||
android:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@mipmap/side_bg"
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</FrameLayout>
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:theme="@style/AppTheme.AppBarOverlay"
|
||||
android:layout_alignParentTop="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:fitsSystemWindows="true"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<!--<LinearLayout-->
|
||||
<!--android:id="@+id/ll_status"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:background="?attr/colorPrimary"-->
|
||||
<!--android:fitsSystemWindows="true"-->
|
||||
<!--android:orientation="vertical"-->
|
||||
<!--android:visibility="invisible">-->
|
||||
<!--</LinearLayout>-->
|
||||
<!--<LinearLayout-->
|
||||
<!--android:id="@+id/ll_status"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:background="?attr/colorPrimary"-->
|
||||
<!--android:fitsSystemWindows="true"-->
|
||||
<!--android:orientation="vertical"-->
|
||||
<!--android:visibility="invisible">-->
|
||||
<!--</LinearLayout>-->
|
||||
|
||||
<!--<LinearLayout-->
|
||||
<!--android:id="@+id/ll_top"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:background="?attr/colorPrimary"-->
|
||||
<!--android:orientation="horizontal"-->
|
||||
<!--android:layout_below="@id/ll_status"-->
|
||||
<!--android:visibility="gone">-->
|
||||
<!--<LinearLayout-->
|
||||
<!--android:id="@+id/ll_top"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:background="?attr/colorPrimary"-->
|
||||
<!--android:orientation="horizontal"-->
|
||||
<!--android:layout_below="@id/ll_status"-->
|
||||
<!--android:visibility="gone">-->
|
||||
|
||||
<!--<ImageButton-->
|
||||
<!--android:id="@+id/btn_return"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:background="@mipmap/return_button"-->
|
||||
<!--android:layout_marginLeft="10dp"-->
|
||||
<!--android:layout_gravity="center_vertical" />-->
|
||||
<!--<ImageButton-->
|
||||
<!--android:id="@+id/btn_return"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:background="@mipmap/return_button"-->
|
||||
<!--android:layout_marginLeft="10dp"-->
|
||||
<!--android:layout_gravity="center_vertical" />-->
|
||||
|
||||
<!--<LinearLayout-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:gravity="right"-->
|
||||
<!--android:orientation="horizontal">-->
|
||||
<!--<ImageButton-->
|
||||
<!--android:id="@+id/btn_light"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_gravity="center_vertical"-->
|
||||
<!--android:background="@color/black" />-->
|
||||
<!--<LinearLayout-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:gravity="right"-->
|
||||
<!--android:orientation="horizontal">-->
|
||||
<!--<ImageButton-->
|
||||
<!--android:id="@+id/btn_light"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_gravity="center_vertical"-->
|
||||
<!--android:background="@color/black" />-->
|
||||
|
||||
<!--<ImageButton-->
|
||||
<!--android:id="@+id/btn_listener_book"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_gravity="center_vertical"-->
|
||||
<!--android:layout_marginRight="10dp"-->
|
||||
<!--android:background="@mipmap/img_tts" />-->
|
||||
<!--</LinearLayout>-->
|
||||
<!--</LinearLayout>-->
|
||||
<!--<ImageButton-->
|
||||
<!--android:id="@+id/btn_listener_book"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_gravity="center_vertical"-->
|
||||
<!--android:layout_marginRight="10dp"-->
|
||||
<!--android:background="@mipmap/img_tts" />-->
|
||||
<!--</LinearLayout>-->
|
||||
<!--</LinearLayout>-->
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rl_read_bottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:background="@color/read_dialog_bg"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/read_dialog_bg"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_stop_read"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_centerInParent="true"
|
||||
android:textSize="20dp"
|
||||
android:text="停止语音播放" />
|
||||
android:text="停止语音播放"
|
||||
android:textSize="20dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
|
@ -127,18 +129,20 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rl_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:padding="20dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:padding="20dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
|
@ -146,67 +150,67 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="00.00%"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:text="00.00%"/>
|
||||
android:textSize="16sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bookpop_bottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/bookpop_bottom"
|
||||
android:baselineAligned="false"
|
||||
android:background="@color/read_dialog_bg"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_pre"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/read_setting_pre"
|
||||
android:textAlignment="center"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/white"
|
||||
android:layout_gravity="center_vertical"
|
||||
/>
|
||||
android:textSize="16sp" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/sb_progress"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:max="10000"
|
||||
android:layout_gravity="center_vertical">
|
||||
</SeekBar>
|
||||
android:max="10000"></SeekBar>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/read_setting_next"
|
||||
android:textAlignment="center"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/white"
|
||||
android:layout_gravity="center_vertical"
|
||||
/>
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="5dp"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<TextView
|
||||
style="@style/text_style"
|
||||
android:id="@+id/tv_directory"
|
||||
style="@style/text_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
@ -215,8 +219,8 @@
|
|||
android:text="@string/read_setting_directory" />
|
||||
|
||||
<TextView
|
||||
style="@style/text_style"
|
||||
android:id="@+id/tv_dayornight"
|
||||
style="@style/text_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
@ -225,8 +229,8 @@
|
|||
android:text="@string/read_setting_night" />
|
||||
|
||||
<TextView
|
||||
style="@style/text_style"
|
||||
android:id="@+id/tv_pagemode"
|
||||
style="@style/text_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
@ -235,8 +239,8 @@
|
|||
android:text="@string/read_setting_pagemode" />
|
||||
|
||||
<TextView
|
||||
style="@style/text_style"
|
||||
android:id="@+id/tv_setting"
|
||||
style="@style/text_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
|
Loading…
Reference in New Issue