1253 lines
		
	
	
		
			44 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			1253 lines
		
	
	
		
			44 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| package com.novelbook.android;
 | ||
| 
 | ||
| import android.app.Activity;
 | ||
| import android.app.AlertDialog;
 | ||
| import android.content.BroadcastReceiver;
 | ||
| import android.content.Context;
 | ||
| import android.content.DialogInterface;
 | ||
| import android.content.Intent;
 | ||
| import android.content.IntentFilter;
 | ||
| import android.database.SQLException;
 | ||
| import android.graphics.Point;
 | ||
| import android.graphics.Typeface;
 | ||
| import android.os.Build;
 | ||
| import android.os.Handler;
 | ||
| import android.os.Message;
 | ||
| import android.support.annotation.Nullable;
 | ||
| import android.support.constraint.solver.GoalRow;
 | ||
| import android.support.design.widget.AppBarLayout;
 | ||
| import android.support.v7.widget.Toolbar;
 | ||
| import android.text.TextUtils;
 | ||
| import android.util.Log;
 | ||
| import android.view.Display;
 | ||
| import android.view.KeyEvent;
 | ||
| import android.view.LayoutInflater;
 | ||
| import android.view.Menu;
 | ||
| import android.view.MenuItem;
 | ||
| import android.view.View;
 | ||
| import android.view.ViewGroup;
 | ||
| import android.view.WindowManager;
 | ||
| import android.view.animation.Animation;
 | ||
| import android.view.animation.AnimationUtils;
 | ||
| import android.widget.Button;
 | ||
| import android.widget.FrameLayout;
 | ||
| 
 | ||
| import android.widget.ImageView;
 | ||
| import android.widget.LinearLayout;
 | ||
| import android.widget.RelativeLayout;
 | ||
| import android.widget.SeekBar;
 | ||
| import android.widget.TextView;
 | ||
| import android.widget.Toast;
 | ||
| 
 | ||
| import com.androidquery.callback.AQuery2;
 | ||
| import com.androidquery.callback.ImageOptions;
 | ||
| import com.bytedance.sdk.openadsdk.AdSlot;
 | ||
| import com.bytedance.sdk.openadsdk.TTAdConstant;
 | ||
| import com.bytedance.sdk.openadsdk.TTAdDislike;
 | ||
| import com.bytedance.sdk.openadsdk.TTAdNative;
 | ||
| import com.bytedance.sdk.openadsdk.TTAppDownloadListener;
 | ||
| import com.bytedance.sdk.openadsdk.TTBannerAd;
 | ||
| import com.bytedance.sdk.openadsdk.TTImage;
 | ||
| import com.bytedance.sdk.openadsdk.TTNativeAd;
 | ||
| import com.novelbook.android.AD.SplashAdManager;
 | ||
| import com.novelbook.android.AD.toutiao.TTAdManagerHolder;
 | ||
| import com.novelbook.android.AD.toutiao.TToast;
 | ||
| import com.novelbook.android.db.Chapter;
 | ||
| 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.Config;
 | ||
| import com.novelbook.android.utils.Constants;
 | ||
| import com.novelbook.android.utils.PageFactory;
 | ||
| import com.novelbook.android.view.PageWidget;
 | ||
| import com.umeng.analytics.MobclickAgent;
 | ||
| 
 | ||
| import org.litepal.LitePal;
 | ||
| 
 | ||
| import java.io.IOException;
 | ||
| import java.text.DecimalFormat;
 | ||
| import java.text.SimpleDateFormat;
 | ||
| import java.util.ArrayList;
 | ||
| import java.util.Date;
 | ||
| import java.util.HashMap;
 | ||
| import java.util.List;
 | ||
| import java.util.Map;
 | ||
| 
 | ||
| import butterknife.BindView;
 | ||
| import butterknife.OnClick;
 | ||
| 
 | ||
| 
 | ||
| public class ReadActivity extends  Activity_base implements   AdInterface {
 | ||
|     private static final String TAG = ReadActivity.class.getSimpleName();
 | ||
|     private final static String EXTRA_BOOK = "book";
 | ||
|     private final static String EXTRA_CHAPTER = "chapter";
 | ||
|     private final static int MESSAGE_CHANGEPROGRESS = 1;
 | ||
| 
 | ||
|     @BindView(R.id.btnRefresh)
 | ||
|     Button btnRefresh;
 | ||
|     @BindView(R.id.bookpage)
 | ||
|     PageWidget bookpage;
 | ||
| //    @BindView(R.id.btn_return)
 | ||
| //    ImageButton btn_return;
 | ||
| //    @BindView(R.id.ll_top)
 | ||
| //    LinearLayout ll_top;
 | ||
|     @BindView(R.id.tv_progress)
 | ||
|     TextView tv_progress;
 | ||
|     @BindView(R.id.rl_progress)
 | ||
|     RelativeLayout rl_progress;
 | ||
|     @BindView(R.id.tv_pre)
 | ||
|     TextView tv_pre;
 | ||
|     @BindView(R.id.sb_progress)
 | ||
|     SeekBar sb_progress;
 | ||
|     @BindView(R.id.tv_next)
 | ||
|     TextView tv_next;
 | ||
|     @BindView(R.id.tv_directory)
 | ||
|     TextView tv_directory;
 | ||
|     @BindView(R.id.tv_dayornight)
 | ||
|     TextView tv_dayornight;
 | ||
|     @BindView(R.id.tv_pagemode)
 | ||
|     TextView tv_pagemode;
 | ||
|     @BindView(R.id.tv_setting)
 | ||
|     TextView tv_setting;
 | ||
|     @BindView(R.id.bookpop_bottom)
 | ||
|     LinearLayout bookpop_bottom;
 | ||
|     @BindView(R.id.rl_bottom)
 | ||
|     RelativeLayout rl_bottom;
 | ||
|     @BindView(R.id.tv_stop_read)
 | ||
|     TextView tv_stop_read;
 | ||
|     @BindView(R.id.rl_read_bottom)
 | ||
|     RelativeLayout rl_read_bottom;
 | ||
|     @BindView(R.id.toolbar)
 | ||
|     Toolbar toolbar;
 | ||
|     @BindView(R.id.appbar)
 | ||
|     AppBarLayout appbar;
 | ||
| 
 | ||
|     @BindView(R.id.tvUrl)
 | ||
|     TextView tvUrl;
 | ||
| 
 | ||
|       @BindView(R.id.top_banner_container)
 | ||
|       FrameLayout mTopBannerContainer;
 | ||
| 
 | ||
|     @BindView(R.id.imgLoading)
 | ||
|     pl.droidsonroids.gif.GifImageView imgLoading;
 | ||
|     @BindView(R.id.frmAD)
 | ||
|     FrameLayout frmAD;
 | ||
| 
 | ||
|    @BindView(R.id.native_banner_container )
 | ||
|     FrameLayout mNative_status_banner_container;
 | ||
|   @BindView(R.id.banner_container )
 | ||
|     FrameLayout mBannerContainer;
 | ||
|    @BindView(R.id.llShelfBottom)
 | ||
|     LinearLayout llShelf;
 | ||
|     private Config config;
 | ||
|     private WindowManager.LayoutParams lp;
 | ||
|     private Novel book;
 | ||
|     private  Chapter  mChapter;
 | ||
|     private PageFactory pageFactory;
 | ||
|     private int screenWidth, screenHeight;
 | ||
|     // popwindow是否显示
 | ||
|     private Boolean isShow = false;
 | ||
|     private SettingDialog mSettingDialog;
 | ||
|     private PageModeDialog mPageModeDialog;
 | ||
|     private Boolean mDayOrNight;
 | ||
|     // 语音合成客户端
 | ||
|   //  private SpeechSynthesizer mSpeechSynthesizer;
 | ||
|     private boolean isSpeaking = false;
 | ||
| 
 | ||
| 
 | ||
|     // 接收电池信息更新的广播
 | ||
|     private BroadcastReceiver myReceiver = new BroadcastReceiver(){
 | ||
|         @Override
 | ||
|         public void onReceive(Context context, Intent intent) {
 | ||
|             if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
 | ||
|                 Log.e(TAG,Intent.ACTION_BATTERY_CHANGED);
 | ||
|                 int level = intent.getIntExtra("level", 0);
 | ||
|                 Log.d(TAG, String.format("updateBattery onReceive: Intent.ACTION_BATTERY_CHANGED level %s ",level));
 | ||
| 
 | ||
|                 pageFactory.updateBattery(level);
 | ||
|             }else if (intent.getAction().equals(Intent.ACTION_TIME_TICK)){
 | ||
|                 Log.e(TAG,Intent.ACTION_TIME_TICK);
 | ||
|                 pageFactory.updateTime();
 | ||
|             }
 | ||
|         }
 | ||
|     };
 | ||
| 
 | ||
|     @Override
 | ||
|     public int getLayoutRes() {
 | ||
|         return R.layout.zactivity_read;
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     protected void initViews() {
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     protected void setTitle() {
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     protected void initData() {
 | ||
|         if(Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 19){
 | ||
|             bookpage.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
 | ||
|         }
 | ||
| 
 | ||
|         toolbar.setTitle("");
 | ||
|         setSupportActionBar(toolbar);
 | ||
|         //toolbar.setNavigationIcon(R.mipmap.return_button);
 | ||
|         toolbar.setNavigationOnClickListener(new View.OnClickListener() {
 | ||
|             @Override
 | ||
|             public void onClick(View v) {
 | ||
|                 finish();
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         config = Config.getInstance();
 | ||
|         pageFactory = PageFactory.getInstance(getApplicationContext());
 | ||
|         pageFactory.clear();
 | ||
|         pageFactory.setAd(this);
 | ||
|       //  mBannerContainer.setVisibility(View.GONE);
 | ||
| 
 | ||
|       //  showProgress (false,"读取目录信息");
 | ||
|      /*   int slept = 0;
 | ||
|         while(slept <100 && (pageFactory.getChapters() == null || pageFactory.getChapters().size()==0)){
 | ||
|             try {
 | ||
|                 Thread.sleep(50);
 | ||
|                 slept++;
 | ||
|             } catch (InterruptedException e) {
 | ||
|                 e.printStackTrace();
 | ||
|             }
 | ||
|         }
 | ||
|         hideProgress() ;*/
 | ||
| 
 | ||
|         IntentFilter mfilter = new IntentFilter();
 | ||
|         mfilter.addAction(Intent.ACTION_BATTERY_CHANGED);
 | ||
|         mfilter.addAction(Intent.ACTION_TIME_TICK);
 | ||
|         registerReceiver(myReceiver, mfilter);
 | ||
| 
 | ||
|         mSettingDialog = new SettingDialog(this);
 | ||
|         mPageModeDialog = new PageModeDialog(this);
 | ||
|         //获取屏幕宽高
 | ||
|         WindowManager manage = getWindowManager();
 | ||
|         Display display = manage.getDefaultDisplay();
 | ||
|         Point displaysize = new Point();
 | ||
|         display.getSize(displaysize);
 | ||
|         screenWidth = displaysize.x;
 | ||
|         screenHeight = displaysize.y;
 | ||
|         //保持屏幕常亮
 | ||
|         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 | ||
|         //隐藏
 | ||
|         hideSystemUI();
 | ||
|         //改变屏幕亮度
 | ||
|         if (!config.isSystemLight()) {
 | ||
|             BrightnessUtil.setBrightness(this, config.getLight());
 | ||
|         }
 | ||
|         //获取intent中的携带的信息
 | ||
|         Intent intent = getIntent();
 | ||
|         if(intent.hasExtra(EXTRA_BOOK)){
 | ||
|             book = (Novel) intent.getSerializableExtra(EXTRA_BOOK);
 | ||
|         }
 | ||
| 
 | ||
|         if(intent.hasExtra(EXTRA_CHAPTER)){
 | ||
|             mChapter = ( Chapter ) intent.getSerializableExtra(EXTRA_CHAPTER);
 | ||
|         }
 | ||
|     //    mChapter = ( Chapter ) intent.getSerializableExtra(EXTRA_CHAPTER);
 | ||
|         bookpage.setPageMode(config.getPageMode());
 | ||
|         pageFactory.setPageWidget(bookpage);
 | ||
|         sb_progress.setVisibility(book.isLocalBook()?View.VISIBLE:View.INVISIBLE);
 | ||
|         Log.d(TAG, String .format("prepare book: set pagewidget %s, to open book" ,  book.getName()));
 | ||
|         try {
 | ||
| 
 | ||
|             hideSystemUI();
 | ||
|             pageFactory.openBook(book, this);
 | ||
| 
 | ||
|             /*showProgressDialog(true, "正在加载");
 | ||
|             new Thread() {
 | ||
|                 @Override
 | ||
|                 public void run() {
 | ||
|                     super.run();
 | ||
|                     int slepttime =0;
 | ||
|                     int chapid = book.getLastReadChapt();
 | ||
| 
 | ||
|                     while( pageFactory.getChapters().size() ==0 ||(chapid-1 < pageFactory.getChapters().size() ) && pageFactory.getChapters().get(chapid-1).getId() ==0 ){
 | ||
|                         try {
 | ||
| 
 | ||
|                             if(!NetUtil.isNetworkConnected()){
 | ||
|                                 break;
 | ||
|                             }
 | ||
| 
 | ||
|                             sleep(50);
 | ||
|                             slepttime+=1;
 | ||
|                             if(pageFactory.getChapters().size()>0){
 | ||
|                              //   Log.d(TAG, String .format("prepare Book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
 | ||
| 
 | ||
|                             }else{
 | ||
|                              //   Log.d(TAG, String .format("prepare Book: slept %s for loading  pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
 | ||
| 
 | ||
|                             }
 | ||
|                         } catch (Exception e) {
 | ||
|                             e.printStackTrace();
 | ||
|                         }
 | ||
|                         if(slepttime>40)
 | ||
|                         {
 | ||
|                             break;
 | ||
|                         }
 | ||
|                     }
 | ||
|                     Log.d(TAG, String .format("prepare Book: total slept %s for loading chapter content %s,  " , slepttime*50, chapid  ));
 | ||
| 
 | ||
|                     mHandler.sendEmptyMessage(1);
 | ||
| 
 | ||
|                 }
 | ||
|             }.start();
 | ||
| */
 | ||
| 
 | ||
|             hideSystemUI();
 | ||
| 
 | ||
|         }catch (IOException e) {
 | ||
|             e.printStackTrace();
 | ||
|             Toast.makeText(this, "打开电子书失败", Toast.LENGTH_SHORT).show();
 | ||
|         }
 | ||
| 
 | ||
|         initDayOrNight();
 | ||
| 
 | ||
| //        new Thread(){
 | ||
| //            @Override
 | ||
| //            public void run() {
 | ||
| //                super.run();
 | ||
| //                initialTts();
 | ||
| //            }
 | ||
| //        }.start();
 | ||
| //        initialTts();
 | ||
| 
 | ||
|         initListener();
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     protected void initListener() {
 | ||
|         sb_progress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
 | ||
|             float pro;
 | ||
|             // 触发操作,拖动
 | ||
|             @Override
 | ||
|             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
 | ||
|                 pro = (float) (progress / 10000.0);
 | ||
|                 showProgressBar(pro);
 | ||
|             }
 | ||
| 
 | ||
|             // 表示进度条刚开始拖动,开始拖动时候触发的操作
 | ||
|             @Override
 | ||
|             public void onStartTrackingTouch(SeekBar seekBar) {
 | ||
| 
 | ||
|             }
 | ||
| 
 | ||
|             // 停止拖动时候
 | ||
|             @Override
 | ||
|             public void onStopTrackingTouch(SeekBar seekBar) {
 | ||
|                 pageFactory.changeProgress(pro);
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         mPageModeDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
 | ||
|             @Override
 | ||
|             public void onCancel(DialogInterface dialog) {
 | ||
|                 hideSystemUI();
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         mPageModeDialog.setPageModeListener(new PageModeDialog.PageModeListener() {
 | ||
|             @Override
 | ||
|             public void changePageMode(int pageMode) {
 | ||
|                 bookpage.setPageMode(pageMode);
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         mSettingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
 | ||
|             @Override
 | ||
|             public void onCancel(DialogInterface dialog) {
 | ||
|                 hideSystemUI();
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         mSettingDialog.setSettingListener(new SettingDialog.SettingListener() {
 | ||
|             @Override
 | ||
|             public void changeSystemBright(Boolean isSystem, float brightness) {
 | ||
|                 if (!isSystem) {
 | ||
|                     BrightnessUtil.setBrightness(ReadActivity.this, brightness);
 | ||
|                 } else {
 | ||
|                     int bh = BrightnessUtil.getScreenBrightness(ReadActivity.this);
 | ||
|                     BrightnessUtil.setBrightness(ReadActivity.this, bh);
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void changeFontSize(int fontSize) {
 | ||
|                 pageFactory.changeFontSize(fontSize);
 | ||
|                 showSystemUI();
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void changeTypeFace(Typeface typeface) {
 | ||
|                 pageFactory.changeTypeface(typeface);
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void changeBookBg(int type) {
 | ||
|                 pageFactory.changeBookBg(type);
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void changeLineHeight(int lineHeight) {
 | ||
|                 pageFactory.changeLineHight(lineHeight);
 | ||
|                 showSystemUI();
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         pageFactory.setPageEvent(new PageFactory.PageEvent() {
 | ||
|             @Override
 | ||
|             public void changeProgress(float progress) {
 | ||
|                 Message message = new Message();
 | ||
|                 message.what = MESSAGE_CHANGEPROGRESS;
 | ||
|                 message.obj = progress;
 | ||
|                 mHandler.sendMessage(message);
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|         bookpage.setTouchListener(new PageWidget.TouchListener() {
 | ||
|             @Override
 | ||
|             public void center() {
 | ||
|                 if (isShow) {
 | ||
|                     hideReadSetting();
 | ||
|                 } else {
 | ||
|                     showReadSetting();
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public Boolean prePage() {
 | ||
| 
 | ||
|                 if (isShow) {
 | ||
|                     hideReadSetting();
 | ||
|                     return false;
 | ||
|                 }
 | ||
|                 if (isShow || isSpeaking){
 | ||
|                   //  return false;
 | ||
|                 }
 | ||
| 
 | ||
|                 pageFactory.prePage();
 | ||
|                 SplashAdManager.plusPage(ReadActivity.this);
 | ||
|                 if (pageFactory.isfirstPage() || !pageFactory.isReady()) {
 | ||
|                     return false;
 | ||
|                 }
 | ||
| 
 | ||
|                 return true;
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public Boolean nextPage() {
 | ||
|                 Log.e("setTouchListener", "nextPage");
 | ||
|                 if (isShow) {
 | ||
|                     hideReadSetting();
 | ||
|                     return false;
 | ||
| 
 | ||
|                 }
 | ||
|                 if (isShow || isSpeaking){
 | ||
|                 //    return false;
 | ||
|                 }
 | ||
| 
 | ||
|                 pageFactory.nextPage();
 | ||
|                 SplashAdManager.plusPage(ReadActivity.this);
 | ||
|                 if (pageFactory.islastPage() || !pageFactory.isReady())   {
 | ||
|                     return false;
 | ||
|                 }
 | ||
|                 return true;
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void cancel() {
 | ||
|                 pageFactory.cancelPage();
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public Boolean canCancel() {
 | ||
|                // Log.d(TAG, "canCancel: cancelPage canCancel ?" + pageFactory.canCancelPage());
 | ||
|                 return true;//pageFactory.canCancelPage();
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void showAdAfterIni() {
 | ||
|              //  if(frmAD.getVisibility()== View.INVISIBLE)
 | ||
|              //    frmAD.setVisibility(View.VISIBLE);
 | ||
|                  /* if(mBannerContainer.getVisibility()== View.GONE)
 | ||
|                       mBannerContainer.setVisibility(View.VISIBLE);*/
 | ||
|               //  Log.d(TAG, "pageAnimation showAdAfterIni: ");
 | ||
|                 pageFactory.showAd();
 | ||
|             }
 | ||
| 
 | ||
|             @Override
 | ||
|             public void hideAdBeforeIni() {
 | ||
|             //    if(frmAD.getVisibility()== View.VISIBLE)
 | ||
|           //      frmAD.setVisibility(View.INVISIBLE);
 | ||
|                /* if(mBannerContainer.getVisibility()== View.VISIBLE)
 | ||
|                     mBannerContainer.setVisibility(View.GONE);*/
 | ||
|                // mBannerContainer.removeAllViews();
 | ||
|                // Log.d(TAG, "pageAnimation hideAdBeforeIni: ");
 | ||
| 
 | ||
| 
 | ||
|             }
 | ||
|         });
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     private Handler mHandler = new Handler() {
 | ||
|         @Override
 | ||
|         public void handleMessage(Message msg) {
 | ||
|             super.handleMessage(msg);
 | ||
|             /*switch (msg.what) {
 | ||
|                 case MESSAGE_CHANGEPROGRESS:
 | ||
|                     float progress = (float) msg.obj;
 | ||
|                     setSeekBarProgress(progress);
 | ||
|                     break;
 | ||
|             }*/
 | ||
|             hideProgress();
 | ||
|         }
 | ||
|     };
 | ||
| 
 | ||
| 
 | ||
|     int startTime =0;
 | ||
|     @Override
 | ||
|     protected void onResume(){
 | ||
|         super.onResume();
 | ||
|         if (!isShow){
 | ||
|             hideSystemUI();
 | ||
|         }
 | ||
|       /*  if (mSpeechSynthesizer != null){
 | ||
|             mSpeechSynthesizer.resume();
 | ||
|         }*/
 | ||
|         startTime  = (int) new Date().getTime();
 | ||
|    /*     if (book != null) {
 | ||
|             Intent intent = getIntent();
 | ||
|             if (intent.hasExtra(EXTRA_BOOK)) {
 | ||
|                 Novel novel = (Novel) intent.getSerializableExtra(EXTRA_BOOK);
 | ||
|                 if (!pageFactory.isWorking() || novel.getId() != book.getId()) {
 | ||
|                     initData();
 | ||
|                 }else{
 | ||
|                     if( novel.getLastReadChapt()!=pageFactory.getCurrentChapter()){
 | ||
|                         pageFactory.changeChapter(novel.getLastReadChapt());
 | ||
|                      //   hideReadSetting();
 | ||
|                     }
 | ||
|                 }
 | ||
|                 hideReadSetting();
 | ||
|             }
 | ||
|         }*/
 | ||
| 
 | ||
|         hideReadSetting();
 | ||
|         pageFactory.updateTime();
 | ||
|         pageFactory.showAd();
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public void onPause() {
 | ||
|         super.onPause();
 | ||
|         Map<String, String> map_value = new HashMap<String, String>();
 | ||
|         map_value.put("bookname" , book!=null ?  book.getName():"noname" );
 | ||
|         MobclickAgent.onEventValue(MyApp.applicationContext, "novel_reading_time" , map_value, (int) new Date().getTime() - startTime);
 | ||
| 
 | ||
|     }
 | ||
|     @Override
 | ||
|     protected void onStop(){
 | ||
|         super.onStop();
 | ||
|      /*   if (mSpeechSynthesizer != null){
 | ||
|             mSpeechSynthesizer.stop();
 | ||
|         }*/
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     protected void onDestroy() {
 | ||
|         super.onDestroy();
 | ||
|        // pageFactory.clear();
 | ||
|         bookpage = null;
 | ||
|         unregisterReceiver(myReceiver);
 | ||
|         isSpeaking = false;
 | ||
|        /* if (mSpeechSynthesizer != null){
 | ||
|             mSpeechSynthesizer.release();
 | ||
|         }*/
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public boolean onKeyDown(int keyCode, KeyEvent event) {
 | ||
| 
 | ||
|         Log.d(TAG, "onKeyDown: pressed key");
 | ||
|         if (keyCode == KeyEvent.KEYCODE_BACK) {
 | ||
|             Log.d(TAG, "onKeyDown: pressed back");
 | ||
|         /*    if (isShow){
 | ||
|                 hideReadSetting();
 | ||
|                 return true;
 | ||
|             }
 | ||
|             if (mSettingDialog.isShowing()){
 | ||
|                 mSettingDialog.hide();
 | ||
|                 return true;
 | ||
|             }
 | ||
|             if (mPageModeDialog.isShowing()){
 | ||
|                 mPageModeDialog.hide();
 | ||
|                 return true;
 | ||
|             }*/
 | ||
| 
 | ||
|         if(isShow){
 | ||
|             hideReadSetting();
 | ||
|             return  true;
 | ||
|         }
 | ||
| 
 | ||
|             if(!pageFactory.canExitSilent()){
 | ||
|                 if(book.isOnShelf()){
 | ||
|                     finish();
 | ||
|                 }else {
 | ||
|                    // showNormalDialog();
 | ||
|                     Animation bottomAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_enter);
 | ||
|                     llShelf.startAnimation(bottomAnim);
 | ||
|                     llShelf.setVisibility(View.VISIBLE);
 | ||
|                     return true;
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
|         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) {
 | ||
| 
 | ||
|                         book.setOnShelf(true);
 | ||
|                         book.update(book.getId());
 | ||
|                         finish();
 | ||
| 
 | ||
|                     }
 | ||
|                 });
 | ||
|         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.
 | ||
|         getMenuInflater().inflate(R.menu.read, menu);
 | ||
| 
 | ||
|         if(book!=null && book.isLocalBook()){
 | ||
|             menu.findItem(R.id.action_change_source).setEnabled(false);
 | ||
|             menu.findItem(R.id.action_refresh).setEnabled(false);
 | ||
|             menu.findItem(R.id.action_bookdetail).setEnabled(false);
 | ||
|         }
 | ||
| 
 | ||
|         return true;
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public boolean onOptionsItemSelected(MenuItem item) {
 | ||
|         // Handle action bar item clicks here. The action bar will
 | ||
|         // automatically handle clicks on the Home/Up button, so long
 | ||
|         // as you specify a parent activity in AndroidManifest.xml.
 | ||
|         int id = item.getItemId();
 | ||
|         pageFactory.setPageWidget(bookpage);
 | ||
|         if (id == R.id.action_add_bookmark){
 | ||
|             if( pageFactory.isReady())
 | ||
|             if (pageFactory.getCurrentPage() != null) {
 | ||
|                 List<BookMarks> bookMarksList = LitePal.where("novelId = ? and chapt = ? " +
 | ||
|                         " and begin = ?", pageFactory.getNovle().getId()+"",pageFactory.getCurrentChapter()+"",pageFactory.getCurrentPage().getBegin() + "").find(BookMarks.class);
 | ||
| 
 | ||
|                 if (!bookMarksList.isEmpty()){
 | ||
|                     Toast.makeText(ReadActivity.this, "该书签已存在", Toast.LENGTH_SHORT).show();
 | ||
|                 }else {
 | ||
|                     BookMarks bookMarks = new BookMarks();
 | ||
|                     String word = "";
 | ||
|                     for (String line : pageFactory.getCurrentPage().getLines()) {
 | ||
|                         word += line;
 | ||
|                     }
 | ||
|                     try {
 | ||
|                         SimpleDateFormat sf = new SimpleDateFormat(
 | ||
|                                 "yyyy-MM-dd HH:mm ss");
 | ||
|                         String time = sf.format(new Date());
 | ||
|                         bookMarks.setTime(time);
 | ||
|                         bookMarks.setBegin(pageFactory.getCurrentPage().getBegin());
 | ||
|                         bookMarks.setText(word);
 | ||
|                         bookMarks.setNovelId(pageFactory.getNovle().getId());
 | ||
|                         bookMarks.setChapt(pageFactory.getCurrentChapter());
 | ||
|                         bookMarks.setChaptName(((pageFactory.getChapters().get(bookMarks.getChapt()-1).getChapterName())));
 | ||
|                         if(!book.isLocalBook()) {
 | ||
|                             bookMarks.setDomain(pageFactory.getSite().getDomain());
 | ||
|                         }
 | ||
|                         bookMarks.save();
 | ||
| 
 | ||
|                         Toast.makeText(ReadActivity.this, "书签添加成功", Toast.LENGTH_SHORT).show();
 | ||
|                     } catch (SQLException e) {
 | ||
|                         Toast.makeText(ReadActivity.this, "该书签已存在", Toast.LENGTH_SHORT).show();
 | ||
|                     } catch (Exception e) {
 | ||
|                         e.printStackTrace();
 | ||
|                         Toast.makeText(ReadActivity.this, "添加书签失败", Toast.LENGTH_SHORT).show();
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
|             hideReadSetting();
 | ||
|         }
 | ||
|        /* else if (id == R.id.action_read_book){
 | ||
|             initialTts();
 | ||
|             if (mSpeechSynthesizer != null){
 | ||
|                 mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "5");
 | ||
|                 mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEED, "5");
 | ||
|                 mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "5");
 | ||
|                 mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEAKER, "0");
 | ||
| //                mSpeechSynthesizer.setParam(SpeechSynthesizer. MIX_MODE_DEFAULT);
 | ||
| //                mSpeechSynthesizer.setParam(SpeechSynthesizer. AUDIO_ENCODE_AMR);
 | ||
| //                mSpeechSynthesizer.setParam(SpeechSynthesizer. AUDIO_BITRA TE_AMR_15K85);
 | ||
|                 mSpeechSynthesizer.setParam(SpeechSynthesizer. PARAM_VOCODER_OPTIM_LEVEL, "0");
 | ||
|                 int result = mSpeechSynthesizer.speak(pageFactory.getCurrentPage().getLineToString());
 | ||
|                 if (result < 0) {
 | ||
|                     Log.e(TAG,"error,please look up error code in doc or URL:http://yuyin.baidu.com/docs/tts/122 ");
 | ||
|                 }else{
 | ||
|                     hideReadSetting();
 | ||
|                     isSpeaking = true;
 | ||
|                 }
 | ||
|             }
 | ||
|         }*/
 | ||
|         else if (id == R.id.action_change_source) {
 | ||
|          //   if(  pageFactory.getChapters().size()>0) {
 | ||
|                Intent intent = new Intent(ReadActivity.this, Activity_ChgSource.class);
 | ||
|                intent.putExtra(Activity_ChgSource.EXTR_ID, pageFactory.getChapter().getIndex());
 | ||
|                intent.putExtra(Activity_ChgSource.EXTR_TITLE, pageFactory.getChapter().getChapterName());
 | ||
|                intent.putExtra(Activity_ChgSource.EXTR_SITE, pageFactory.getChapter().getDomain());
 | ||
|            //    intent.putExtra(Activity_ChgSource.EXTR_NAME, pageFactory.getSite().getName());
 | ||
|                startActivity(intent);
 | ||
|                hideReadSetting();
 | ||
|            // }else{
 | ||
|           //  Toast.makeText(this,"换源不可用,请返回重试...",Toast.LENGTH_SHORT);
 | ||
|           // }
 | ||
|         }else if(id == R.id.action_refresh){
 | ||
|             pageFactory.refreshChapter();
 | ||
|             hideReadSetting();
 | ||
| 
 | ||
|         }else if(id == R.id.action_bookdetail){
 | ||
|             showBookDetail(this.book);
 | ||
|             finish();
 | ||
|         }
 | ||
| 
 | ||
|         return super.onOptionsItemSelected(item);
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public void fillData() {
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     protected void onNewIntent(Intent intent) {
 | ||
|         super.onNewIntent(intent);
 | ||
|         Log.e("tag", "onNewINtent执行了");
 | ||
|         setIntent(intent);
 | ||
|         initData();
 | ||
|     }
 | ||
| 
 | ||
|     public static boolean openBook(final Novel book, Activity context) {
 | ||
|         if (book == null){
 | ||
|             throw new NullPointerException("Novel can not be null");
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         Intent intent = new Intent(context, ReadActivity.class);
 | ||
|         intent.putExtra(EXTRA_BOOK, book);
 | ||
|         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 | ||
|         //context.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
 | ||
|         context.startActivity(intent);
 | ||
|         return true;
 | ||
|     }
 | ||
|     public static boolean openChapter(final Novel book, final Chapter chapter, Activity context) {
 | ||
|         if (book == null){
 | ||
|             throw new NullPointerException("Novel can not be null");
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         Intent intent = new Intent(context, ReadActivity.class);
 | ||
|         intent.putExtra(EXTRA_BOOK, book);
 | ||
|         intent.putExtra(EXTRA_CHAPTER, chapter);
 | ||
| 
 | ||
|         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 | ||
|         context.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
 | ||
|         context.startActivity(intent);
 | ||
|         return true;
 | ||
|     }
 | ||
| 
 | ||
| //    public BookPageWidget getPageWidget() {
 | ||
| //        return bookpage;
 | ||
| //    }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|     //显示书本进度
 | ||
|     public void showProgressBar(float progress){
 | ||
|         if (rl_progress.getVisibility() != View.VISIBLE) {
 | ||
|             rl_progress.setVisibility(View.VISIBLE);
 | ||
|         }
 | ||
|         setProgress(progress);
 | ||
|     }
 | ||
| 
 | ||
|     //隐藏书本进度
 | ||
|     public void hideProgressBar(){
 | ||
|         rl_progress.setVisibility(View.GONE);
 | ||
|     }
 | ||
| 
 | ||
|     public void initDayOrNight(){
 | ||
|         mDayOrNight = config.getDayOrNight();
 | ||
|         if (mDayOrNight){
 | ||
|             tv_dayornight.setText(getResources().getString(R.string.read_setting_day));
 | ||
|         }else{
 | ||
|             tv_dayornight.setText(getResources().getString(R.string.read_setting_night));
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     //改变显示模式
 | ||
|     public void changeDayOrNight(){
 | ||
|         if (mDayOrNight){
 | ||
|             mDayOrNight = false;
 | ||
|             tv_dayornight.setText(getResources().getString(R.string.read_setting_night));
 | ||
|         }else{
 | ||
|             mDayOrNight = true;
 | ||
|             tv_dayornight.setText(getResources().getString(R.string.read_setting_day));
 | ||
|         }
 | ||
|         config.setDayOrNight(mDayOrNight);
 | ||
|         pageFactory.setDayOrNight(mDayOrNight);
 | ||
|     }
 | ||
| 
 | ||
|     private void setProgress(float progress){
 | ||
|         DecimalFormat decimalFormat=new DecimalFormat("00.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
 | ||
|         String p=decimalFormat.format(progress * 100.0);//format 返回的是字符串
 | ||
|         tv_progress.setText(p + "%");
 | ||
|     }
 | ||
| 
 | ||
|     public void setSeekBarProgress(float progress){
 | ||
|         sb_progress.setProgress((int) (progress * 10000));
 | ||
|     }
 | ||
| 
 | ||
|     public void showReadSetting(){
 | ||
|         isShow = true;
 | ||
|        // rl_progress.setVisibility(View.GONE);
 | ||
|         Animation topAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_top_enter);
 | ||
|         Animation botoomAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_exit);
 | ||
| 
 | ||
|         if (llShelf.getVisibility() == View.VISIBLE) {
 | ||
|             llShelf.startAnimation(botoomAnim);
 | ||
|             llShelf.setVisibility(View.GONE);
 | ||
|         }
 | ||
| 
 | ||
|         if (isSpeaking){
 | ||
| 
 | ||
|             rl_read_bottom.startAnimation(topAnim);
 | ||
|             rl_read_bottom.setVisibility(View.VISIBLE);
 | ||
|         }else {
 | ||
|             showSystemUI();
 | ||
| 
 | ||
|            // Animation bottomAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_enter);
 | ||
| 
 | ||
|              rl_bottom.startAnimation(topAnim);
 | ||
|              appbar.startAnimation(topAnim);
 | ||
| //        ll_top.startAnimation(topAnim);//        ll_top.setVisibility(View.VISIBLE);
 | ||
|             rl_bottom.setVisibility(View.VISIBLE);
 | ||
|             appbar.setVisibility(View.VISIBLE);
 | ||
| 
 | ||
|           /*  tvUrl.setVisibility(View.VISIBLE);
 | ||
|             tvUrl.setText("abcd+" + pageFactory.getChapter().getChapterUrl());*/
 | ||
| 
 | ||
|             if(Constants.SHOW_NOVEL_CHAPTER_URL) {
 | ||
|                 if(pageFactory.getChapter()!=null && !TextUtils.isEmpty(pageFactory.getChapter().getChapterUrl())) {
 | ||
|                     tvUrl.setVisibility(View.VISIBLE);
 | ||
|                     tvUrl.setText(pageFactory.getChapter().getChapterUrl());
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
| 
 | ||
|         }
 | ||
|     }
 | ||
|     /**
 | ||
|      * 隐藏菜单。沉浸式阅读
 | ||
|      */
 | ||
|     public void hideSystemUI() {
 | ||
|         // Set the IMMERSIVE flag.
 | ||
|         // Set the content to appear under the system bars so that the content
 | ||
|         // doesn't resize when the system bars hide and show.
 | ||
|         getWindow().getDecorView().setSystemUiVisibility(
 | ||
|                 View.SYSTEM_UI_FLAG_LAYOUT_STABLE
 | ||
|                         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
 | ||
|                         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
 | ||
|                         | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
 | ||
|                          | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
 | ||
|                         | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
 | ||
|                       //  | View.SYSTEM_UI_FLAG_IMMERSIVE
 | ||
|         );
 | ||
| 
 | ||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
 | ||
|             getWindow().setNavigationBarColor(getResources().getColor(R.color.read_dialog_bg));
 | ||
|         }
 | ||
|         pageFactory.setBusy(false);
 | ||
| 
 | ||
|         if (llShelf.getVisibility() == View.VISIBLE) {
 | ||
|             Animation topAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_exit);
 | ||
|             llShelf.startAnimation(topAnim);
 | ||
|             llShelf.setVisibility(View.GONE);
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public void showRefresh(int visible) {
 | ||
|         btnRefresh.setVisibility(visible);
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public void showProgressbar(boolean dismissAble,String msg) {
 | ||
|         showProgressDialog(dismissAble,msg);
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public void hideProgressbar() {
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     public void showLoading(boolean isShow) {
 | ||
|   /*      if(!isShow){
 | ||
|             try {
 | ||
|                 throw  new Exception("why not show");
 | ||
|             } catch (Exception e) {
 | ||
|                 Log.e(TAG, "showLoading: ",e );
 | ||
|             }
 | ||
|         }*/
 | ||
|         imgLoading.setVisibility(isShow?View.VISIBLE:View.GONE);
 | ||
|     }
 | ||
| 
 | ||
|     private void showSystemUI() {
 | ||
|         getWindow().getDecorView().setSystemUiVisibility(
 | ||
|                 View.SYSTEM_UI_FLAG_LAYOUT_STABLE
 | ||
|                         // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
 | ||
|                         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
 | ||
|                          | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
 | ||
|                 // | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
 | ||
|         );
 | ||
|         pageFactory.setBusy(true);
 | ||
|     }
 | ||
|     public void hideReadSetting() {
 | ||
|         isShow = false;
 | ||
|         Animation bottomAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_exit);
 | ||
|         Animation topAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_top_exit);
 | ||
|         if (rl_bottom.getVisibility() == View.VISIBLE) {
 | ||
|             rl_bottom.startAnimation(topAnim);
 | ||
|         }
 | ||
|         if (appbar.getVisibility() == View.VISIBLE) {
 | ||
|             appbar.startAnimation(topAnim);
 | ||
|         }
 | ||
|         if (rl_read_bottom.getVisibility() == View.VISIBLE) {
 | ||
|             rl_read_bottom.startAnimation(topAnim);
 | ||
|         }
 | ||
| //        ll_top.startAnimation(topAnim);
 | ||
|         rl_bottom.setVisibility(View.GONE);
 | ||
|         rl_read_bottom.setVisibility(View.GONE);
 | ||
| //        ll_top.setVisibility(View.GONE);
 | ||
|         appbar.setVisibility(View.GONE);
 | ||
|         tvUrl.setVisibility(View.GONE);
 | ||
|         hideSystemUI();
 | ||
|        // Animation bottomAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_enter);
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     @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.btnRefresh,R.id.btnCancel,R.id.btnShelf})
 | ||
|     public void onClick(View view) {
 | ||
|         pageFactory.setPageWidget(bookpage);
 | ||
|       //  if( pageFactory.isReady())
 | ||
|         switch (view.getId()) {
 | ||
| //            case R.id.btn_return:
 | ||
| //                finish();
 | ||
| //                break;
 | ||
| //            case R.id.ll_top:
 | ||
| //                break;
 | ||
|             case R.id.tv_progress:
 | ||
|                 break;
 | ||
|             case R.id.rl_progress:
 | ||
|                 break;
 | ||
|             case R.id.tv_pre:
 | ||
|                 pageFactory.preChapter();
 | ||
|                 break;
 | ||
|             case R.id.sb_progress:
 | ||
|                 break;
 | ||
|             case R.id.tv_next:
 | ||
|                 pageFactory.nextChapter();
 | ||
|                 break;
 | ||
|             case R.id.tv_directory:
 | ||
|                 Intent intent = new Intent(ReadActivity.this, MarkActivity.class);
 | ||
|                 startActivity(intent);
 | ||
| 
 | ||
|                // finish();
 | ||
|                 break;
 | ||
|             case R.id.tv_dayornight:
 | ||
|                 changeDayOrNight();
 | ||
|                 break;
 | ||
|             case R.id.tv_pagemode:
 | ||
|                hideReadSetting();
 | ||
|                 mPageModeDialog.show();
 | ||
|                 showSystemUI();
 | ||
|                // getWindow().setNavigationBarColor(getResources().getColor(R.color.read_dialog_bg));
 | ||
|                 break;
 | ||
|             case R.id.tv_setting:
 | ||
|                  hideReadSetting();
 | ||
|                 mSettingDialog.show();
 | ||
|                 showSystemUI();
 | ||
|                 break;
 | ||
|             case R.id.bookpop_bottom:
 | ||
|                 break;
 | ||
|           /*  case R.id.rl_bottom:
 | ||
|                 break;*/
 | ||
|             case R.id.tv_stop_read:
 | ||
|               /*  if (mSpeechSynthesizer!=null){
 | ||
|                     mSpeechSynthesizer.stop();
 | ||
|                     isSpeaking = false;
 | ||
|                     hideReadSetting();
 | ||
|                 }*/
 | ||
|         /*    case R.id.mBannerContainer:
 | ||
|                 Toast.makeText(this,"ad is clicked ",Toast.LENGTH_LONG).show();
 | ||
|                 Log.d(TAG,"Ad is clicked");
 | ||
| 
 | ||
|                 break;*/
 | ||
|             case R.id.btnRefresh:
 | ||
|                 pageFactory.retryChapt(pageFactory.getCurrentChapter());
 | ||
|                 btnRefresh.setVisibility(View.GONE);
 | ||
|                 break;
 | ||
|             case R.id.btnShelf:
 | ||
|                 book.setOnShelf(true);
 | ||
|                 book.update(book.getId());
 | ||
|                 finish();
 | ||
|                 break;
 | ||
|             case R.id.btnCancel:
 | ||
|                 finish();
 | ||
|                 break;
 | ||
| 
 | ||
|         }
 | ||
|       //  hideSystemUI();
 | ||
|     }
 | ||
|     /*
 | ||
|     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();
 | ||
|         }
 | ||
|     }
 | ||
|     */
 | ||
| 
 | ||
|     FrameLayout tmpFrame =mBannerContainer;
 | ||
|     @Override
 | ||
|     FrameLayout getNativeContainer(){
 | ||
|         return tmpFrame;
 | ||
|     }
 | ||
| 
 | ||
|     @Override
 | ||
|     void initNaviBanner() {
 | ||
| 
 | ||
|     }
 | ||
|     public void hideStatusAds(){
 | ||
| 
 | ||
|      /*   try{
 | ||
|             throw new Exception("");
 | ||
|         }catch (Exception e){
 | ||
|             Log.e(TAG, "loadBannerAd: ", e);
 | ||
|         }*/
 | ||
|         if(mNative_status_banner_container.getVisibility() ==View.VISIBLE) {
 | ||
|              Log.d(TAG, "loadBannerAd: hideStatusAds()");
 | ||
|              mNative_status_banner_container.setVisibility(View.GONE);
 | ||
|         }
 | ||
|         // mBannerContainer.removeAllViews();
 | ||
| //        mBannerContainer.setBackgroundResource(R.color.transparent);
 | ||
|     }
 | ||
|     private void hideAdSlot(ViewGroup view){
 | ||
| 
 | ||
|         if(view.getVisibility() ==View.VISIBLE) {
 | ||
|             view.setVisibility(View.GONE);
 | ||
|         }
 | ||
| /*        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
 | ||
|         params.width =0;
 | ||
|         view.setLayoutParams(params);*/
 | ||
|       //  view.setBackgroundResource(R.color.transparent);
 | ||
| 
 | ||
|         //mBannerContainer.removeAllViews();
 | ||
|       //  mBannerContainer.setBackgroundResource(R.color.transparent);
 | ||
| 
 | ||
|     }
 | ||
|     private void showAdSlot(ViewGroup view){
 | ||
|         Log.d(TAG, "loadBannerAd: showAdSlot()");
 | ||
|      if(view.getVisibility() ==View.GONE) {
 | ||
|             view.setVisibility(View.VISIBLE);
 | ||
|         }
 | ||
|    /*     FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
 | ||
| 
 | ||
|         params.width =-1;
 | ||
|         view.setLayoutParams(params);*/
 | ||
| 
 | ||
|     }
 | ||
|     public void showNativeBannerInLines(int height,int adY){
 | ||
|        // hideSystemUI();
 | ||
|   //      hideAdSlot(mNative_banner_container);
 | ||
|   //      hideAdSlot(mBannerContainer);
 | ||
|         // mBannerContainer.removeAllViews();
 | ||
|      //   mBannerContainer.removeAllViews();
 | ||
|       //  mBannerContainer.setBackgroundResource(R.color.transparent);
 | ||
| 
 | ||
|        Log.d(TAG, String.format("loadBannerAd:showNativeBannerInLines height %s, adY %s ",height, adY/Constants.ONE_DP_SIZE ));
 | ||
| 
 | ||
|         hideAdSlot(mBannerContainer);
 | ||
|         hideAdSlot(mNative_status_banner_container);
 | ||
|         if(height<=0){
 | ||
|             return;
 | ||
|         }
 | ||
| 
 | ||
|         if(  adY >390*Constants.ONE_DP_SIZE){
 | ||
|             return;
 | ||
|         }
 | ||
| 
 | ||
|        // hideAdSlot(mTopBannerContainer);
 | ||
|         if(mBannerContainer.getChildCount()>0) {
 | ||
|             mBannerContainer.removeAllViews();
 | ||
|         }
 | ||
|         tmpFrame =mBannerContainer;
 | ||
|         mLastBannerTime=0;
 | ||
|         Log.d(TAG, String.format("loadBannerAd:showNativeBannerInLines to get ad, width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,height,adY));
 | ||
|         loadNativeBannerAd(mBannerContainer);
 | ||
|         FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams();
 | ||
|         params.setMargins(10*Constants.ONE_DP_SIZE, adY+5*Constants.ONE_DP_SIZE,  10*Constants.ONE_DP_SIZE, 0*Constants.ONE_DP_SIZE);
 | ||
|         params.width =-1;
 | ||
|         params.height = (int) getResources().getDimension(R.dimen.nativeBannerHeight);
 | ||
|         mBannerContainer.setLayoutParams(params);
 | ||
|          showAdSlot(mBannerContainer);
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|     }
 | ||
|     @Override
 | ||
|     public void showTopBanner( int adHeight,int adY) {
 | ||
|        // hideSystemUI();
 | ||
|        // mTopBannerContainer.setVisibility(View.INVISIBLE);//翻页引起抖动
 | ||
|         //mTopBannerContainer.removeAllViews();
 | ||
|       //  Log.d(TAG, String.format("loadBannerAd:showTopBanner width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY));
 | ||
|         tmpFrame =mTopBannerContainer;
 | ||
|        // hideAdSlot(mBannerContainer);
 | ||
|         Log.d(TAG, String.format("loadBannerAd:showTopBanner width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY));
 | ||
|         //hideAdSlot(mBannerContainer);
 | ||
|         hideAdSlot(mNative_status_banner_container);
 | ||
|         if(adHeight<=0){
 | ||
|             hideAdSlot(mTopBannerContainer);
 | ||
|             return;
 | ||
|         }
 | ||
| 
 | ||
|         int topMargin = adY >200*Constants.ONE_DP_SIZE ? adY -15*Constants.ONE_DP_SIZE :adY -5*Constants.ONE_DP_SIZE;
 | ||
| 
 | ||
|         FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTopBannerContainer.getLayoutParams();
 | ||
|         loadBanner(mTopBannerContainer, Constants.SCREEN_WIDTH_PIX-50,adHeight);
 | ||
|       //  loadNativeBannerAd(mTopBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID,   304,200);
 | ||
|         params.setMargins(10*Constants.ONE_DP_SIZE, topMargin, 10*Constants.ONE_DP_SIZE, 0  );
 | ||
|         params.width =-1;
 | ||
|          params.height = (int) getResources().getDimension(R.dimen.topBannerHeight);
 | ||
|         mTopBannerContainer.setLayoutParams(params);
 | ||
|         showAdSlot(mTopBannerContainer);
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     final int contentAdHight=80;
 | ||
| 
 | ||
|     @Override
 | ||
|     public void showStatusAd(int adHeight,int adY) {
 | ||
| 
 | ||
|        // hideSystemUI();
 | ||
|        // mShowAd =showAd;
 | ||
|      //   mBannerContainer.setVisibility(View.GONE);
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         if(!Constants.AD_SETTING.isShowAdsense()){
 | ||
|             return;
 | ||
|         }
 | ||
| 
 | ||
|       //  Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s,showAd %s",Constants.SCREEN_WIDTH_PIX-50,adHeight/Constants.ONE_DP_SIZE,adY/Constants.ONE_DP_SIZE, showAd));
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         if(adHeight >contentAdHight){
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         //    Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY));
 | ||
| 
 | ||
|             if(adHeight>150*Constants.ONE_DP_SIZE && adY <400*Constants.ONE_DP_SIZE){
 | ||
|                 Log.d(TAG, String.format("loadBannerAd: showStatusAd width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight/Constants.ONE_DP_SIZE,adY/Constants.ONE_DP_SIZE  ));
 | ||
|                  hideAdSlot(mBannerContainer);
 | ||
| //                hideAdSlot(mTopBannerContainer);
 | ||
|                 tmpFrame =mNative_status_banner_container;
 | ||
|                 FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mNative_status_banner_container.getLayoutParams();
 | ||
|                 hideAdSlot(mNative_status_banner_container);
 | ||
| 
 | ||
|               //  mBannerContainer.removeAllViews();
 | ||
|              //   mBannerContainer.setBackgroundResource(R.color.transparent);
 | ||
| 
 | ||
|                 loadNativeBannerAd(mNative_status_banner_container);
 | ||
|                 params.setMargins(10*Constants.ONE_DP_SIZE, adY-20*Constants.ONE_DP_SIZE, 10*Constants.ONE_DP_SIZE, 50*Constants.ONE_DP_SIZE);
 | ||
|                // params.height=-1;
 | ||
|                 mNative_status_banner_container.setLayoutParams(params);
 | ||
|                 showAdSlot(mNative_status_banner_container);
 | ||
|                // mNative_banner_container.setVisibility(View.VISIBLE);
 | ||
|               //  showTopBanner(0,0);
 | ||
|             }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
| }
 |