From f823f1956558790d74c8cfc1cf460f927f45abe4 Mon Sep 17 00:00:00 2001 From: mwang <8205347@qq.com> Date: Tue, 4 Jun 2019 00:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=B9=BF=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhuike/build.gradle | 25 ++- .../novelbook/android/AD/SplashAdManager.java | 6 +- .../android/AD/toutiao/SplashActivity.java | 20 ++- .../android/AD/toutiao/TTAdManagerHolder.java | 4 +- .../com/novelbook/android/Activity_base.java | 137 ++++++++++++++-- .../com/novelbook/android/BookActivity.java | 8 +- .../android/Fragments/BasicFragment.java | 4 +- .../com/novelbook/android/Main2Activity.java | 2 +- .../java/com/novelbook/android/MyApp.java | 10 +- .../com/novelbook/android/ReadActivity.java | 27 ++- .../android/adapter/BookListAdapter.java | 3 + .../novelbook/android/netutils/NetUtil.java | 19 +++ .../com/novelbook/android/utils/BookUtil.java | 2 +- .../com/novelbook/android/utils/Config.java | 17 +- .../novelbook/android/utils/Constants.java | 4 +- .../novelbook/android/utils/PageFactory.java | 155 +++++++++++++++--- zhuike/src/main/res/layout/zactivity_read.xml | 13 +- zhuike/src/main/res/values/dimens.xml | 2 + zhuike/src/main/res/values/styles.xml | 3 +- zhuike/zhuike.iml | 6 + 20 files changed, 397 insertions(+), 70 deletions(-) diff --git a/zhuike/build.gradle b/zhuike/build.gradle index d3d5fec..8ac0bdd 100644 --- a/zhuike/build.gradle +++ b/zhuike/build.gradle @@ -31,7 +31,7 @@ android { multiDexEnabled true //突破65535 manifestPlaceholders = [UMENG_CHANNEL_CALUE: "umeng"] //默认为uMeng - // flavorDimensions "default" //debug时注销 + flavorDimensions "default" //debug时注销 } buildTypes { debug { @@ -44,6 +44,7 @@ android { buildConfigField "String","AD_SLOT_TOUTIAO_SPLASH_ID",'"819267134"' buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_ID",'"919267016"' buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_NATIVE_ID",'"919267816"' + buildConfigField "String","AD_SLOT_TOUTIAO_INTERACTION_ID",'"919267451"' // buildConfigField "String", "API_HOST", '""' versionNameSuffix "-debug" minifyEnabled false @@ -62,7 +63,7 @@ android { shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - /* applicationVariants.all { variant -> + /* applicationVariants.all { variant -> variant.outputs.all { output -> def outFile = output.outputFile if (outFile != null && outFile.name.endsWith(".apk")) { @@ -77,9 +78,23 @@ android { } } //渠道 - /* productFlavors { + /*productFlavors { // googleplay {} - kuan { + ali { + applicationId "com.novelbook.android" + versionName "v-qxs-1.0" + buildConfigField "String", "MAIN_HOST", '"http://chqxs.xiaoshuofenxiang.com/api/"' + buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/qxs.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + + buildConfigField "String","AD_TOUTIAO_APP_ID",'"5019267"' + buildConfigField "String","AD_SLOT_TOUTIAO_FEEDAD_ID",'"919267464"' + buildConfigField "String","AD_SLOT_TOUTIAO_SPLASH_ID",'"819267134"' + buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_ID",'"919267016"' + buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_NATIVE_ID",'"919267816"' + buildConfigField "String","AD_SLOT_TOUTIAO_INTERACTION_ID",'"919267451"' + } + + *//* kuan { applicationId "com.novelbook.android" versionName "v-kuan-1.0" buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' @@ -131,7 +146,7 @@ android { buildConfigField "String", "MAIN_HOST", '"http://chg.xiaoshuofenxiang.com/api/"' buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' // buildConfigField "String", "API_HOST", '""' - } + }*//* //批量配置 productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] diff --git a/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java b/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java index 6980510..1de8c0d 100644 --- a/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java +++ b/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java @@ -63,7 +63,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, if (mIsBackground) { mIsBackground = false; - showAd(activity); + // showAd(activity); Log.d("zzr", "从广告页回到前台"); } @@ -108,7 +108,9 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, public void onLowMemory() { } + static void showInterAd(Activity activity){ + } static void showAd(Activity activity){ if(canShowAd()) { lastAd = new Date().getTime(); @@ -129,7 +131,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks, public static void plusPage(Activity activity){ pages++; if(pages >Constants.AD_SPLASH_PAGES){ - showAd(activity); + showInterAd(activity); } } diff --git a/zhuike/src/main/java/com/novelbook/android/AD/toutiao/SplashActivity.java b/zhuike/src/main/java/com/novelbook/android/AD/toutiao/SplashActivity.java index b9ffeae..d554b4f 100644 --- a/zhuike/src/main/java/com/novelbook/android/AD/toutiao/SplashActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/AD/toutiao/SplashActivity.java @@ -49,11 +49,20 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if(!Constants.SHOWAD){ + goToMainActivity(); + return; + } setContentView(R.layout.ad_toutiao_activity_splash); ButterKnife.bind(this); mSplashContainer = (FrameLayout) findViewById(R.id.splash_container); //step2:创建TTAdNative对象 - mTTAdNative = TTAdManagerHolder.get().createAdNative(this); + try { + mTTAdNative = TTAdManagerHolder.get().createAdNative(this); + }catch (Exception e){ + goToMainActivity(); + return; + } //在合适的时机申请权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题 //在开屏时候申请不太合适,因为该页面倒计时结束或者请求超时会跳转,在该页面申请权限,体验不好 // TTAdManagerHolder.getInstance(this).requestPermissionIfNecessary(this); @@ -173,11 +182,12 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler { * 跳转到主页面 */ private void goToMainActivity() { - if( !getIntent().hasExtra(EXTR_LUNCHER)){ - Intent intent = new Intent(SplashActivity.this, Main2Activity.class); - startActivity(intent); + + Intent intent = new Intent(SplashActivity.this, Main2Activity.class); + startActivity(intent); + if(mSplashContainer!=null) { + mSplashContainer.removeAllViews(); } - mSplashContainer.removeAllViews(); SplashAdManager.clearPages(); this.finish(); } diff --git a/zhuike/src/main/java/com/novelbook/android/AD/toutiao/TTAdManagerHolder.java b/zhuike/src/main/java/com/novelbook/android/AD/toutiao/TTAdManagerHolder.java index 63f3219..5298a63 100644 --- a/zhuike/src/main/java/com/novelbook/android/AD/toutiao/TTAdManagerHolder.java +++ b/zhuike/src/main/java/com/novelbook/android/AD/toutiao/TTAdManagerHolder.java @@ -25,7 +25,9 @@ public class TTAdManagerHolder { } public static void init(Context context) { - doInit(context); + if( Constants.SHOWAD) { + doInit(context); + } } //step1:接入网盟广告sdk的初始化操作,详情见接入文档和穿山甲平台说明 diff --git a/zhuike/src/main/java/com/novelbook/android/Activity_base.java b/zhuike/src/main/java/com/novelbook/android/Activity_base.java index 74f05f4..29f95cd 100644 --- a/zhuike/src/main/java/com/novelbook/android/Activity_base.java +++ b/zhuike/src/main/java/com/novelbook/android/Activity_base.java @@ -33,6 +33,7 @@ import com.bytedance.sdk.openadsdk.TTAppDownloadListener; import com.bytedance.sdk.openadsdk.TTBannerAd; import com.bytedance.sdk.openadsdk.TTImage; +import com.bytedance.sdk.openadsdk.TTInteractionAd; import com.bytedance.sdk.openadsdk.TTNativeAd; import com.google.gson.Gson; import com.novelbook.android.AD.toutiao.TTAdManagerHolder; @@ -44,6 +45,7 @@ import com.novelbook.android.netutils.NetUtil; import com.novelbook.android.upgrade.UpdateManager; import com.novelbook.android.utils.CommonUtil; +import com.novelbook.android.utils.Constants; import com.novelbook.android.utils.ImageUtil; import com.novelbook.android.utils.OnItemClickListener; @@ -331,16 +333,32 @@ public abstract class Activity_base extends AppCompatActivity { Button mCreativeButton; TTAdNative mTTAdNative; void initAD_TouTiao(){ - mTTAdNative = TTAdManagerHolder.get().createAdNative(this); - //step3:(可选,强烈建议在合适的时机调用):申请部分权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题。 - TTAdManagerHolder.get().requestPermissionIfNecessary(this); - this.mAQuery = new AQuery2(this); + if(Constants.SHOWAD) + try { + mTTAdNative = TTAdManagerHolder.get().createAdNative(this); + //step3:(可选,强烈建议在合适的时机调用):申请部分权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题。 + TTAdManagerHolder.get().requestPermissionIfNecessary(this); + this.mAQuery = new AQuery2(this); + }catch (Exception er){ + Log.e(TAG, "initAD_TouTiao: ", er); + } } -//----toutiao ad ---- + TTAdNative getTTAdNative(){ + if(mTTAdNative== null){ + if(Constants.SHOWAD){ + TTAdManagerHolder.init(MyApp.applicationContext); + initAD_TouTiao(); + } + } + return mTTAdNative; + } + +//----toutiao ad ---- + boolean mShowAd =false; public void loadBannerAd(FrameLayout bannerContainer, String codeId, int width, int height) { //step4:创建广告请求参数AdSlot,具体参数含义参考文档 - + if(!Constants.SHOWAD || getTTAdNative()==null ){return;} /* if(height >390){ width =(int)(height*1.78); @@ -351,9 +369,9 @@ public abstract class Activity_base extends AppCompatActivity { }else if(height >150){ width =(int)(height*1.78); }*/ - width =690; + // width =690; //height=150; - height=height > 500 ? 500: height; + // height=height > 500 ? 500: height; Log.d(TAG, String.format("loadBannerAd:finial width %s, height %s ",width,height)); AdSlot adSlot = new AdSlot.Builder() .setCodeId(codeId) //广告位id @@ -361,18 +379,19 @@ public abstract class Activity_base extends AppCompatActivity { .setImageAcceptedSize(width, height) .build(); //step5:请求广告,对请求回调的广告作渲染处理 - mTTAdNative.loadBannerAd(adSlot, new TTAdNative.BannerAdListener() { + getTTAdNative().loadBannerAd(adSlot, new TTAdNative.BannerAdListener() { @Override public void onError(int code, String message) { // TToast.show(oContext, "load error : " + code + ", " + message); Log.e(TAG, String.format("loadBannerAd:code %s, message %s ", code,message)); bannerContainer.removeAllViews(); + // bannerContainer.setVisibility(View.GONE); } @Override public void onBannerAdLoad(final TTBannerAd ad) { - if (ad == null) { + if (ad == null ) { return; } View bannerView = ad.getBannerView(); @@ -383,6 +402,9 @@ public abstract class Activity_base extends AppCompatActivity { ad.setSlideIntervalTime(30 * 1000); bannerContainer.removeAllViews(); bannerContainer.addView(bannerView); + // bannerContainer.setVisibility(View.VISIBLE); + Log.d(TAG, "loadBannerAd: set banner VISIBLE"); + // mTTAdNative.loadBannerAd(adSlot,null); //设置广告互动监听回调 ad.setBannerInteractionListener(new TTBannerAd.AdInteractionListener() { @Override @@ -476,6 +498,10 @@ public abstract class Activity_base extends AppCompatActivity { //-------------native toutiao ad void loadNativeBannerAd(FrameLayout bannerContainer,String codeId) { //step4:创建广告请求参数AdSlot,注意其中的setNativeAdtype方法,具体参数含义参考文档 + + if(!Constants.SHOWAD || getTTAdNative()==null ){ + return; + } if(bannerContainer==null) return; final AdSlot adSlot = new AdSlot.Builder() .setCodeId(codeId) @@ -486,7 +512,7 @@ public abstract class Activity_base extends AppCompatActivity { .build(); //step5:请求广告,对请求回调的广告作渲染处理 - mTTAdNative.loadNativeAd(adSlot, new TTAdNative.NativeAdListener() { + getTTAdNative().loadNativeAd(adSlot, new TTAdNative.NativeAdListener() { @Override public void onError(int code, String message) { // TToast.show(oContext, "load error : " + code + ", " + message); @@ -495,7 +521,7 @@ public abstract class Activity_base extends AppCompatActivity { @Override public void onNativeAdLoad(List ads) { - if (ads.get(0) == null) { + if (ads.get(0) == null||!mShowAd) { return; } View bannerView = LayoutInflater.from(oContext).inflate(R.layout.ad_toutiao_native_ad , bannerContainer, false); @@ -508,8 +534,11 @@ public abstract class Activity_base extends AppCompatActivity { } bannerContainer.removeAllViews(); bannerContainer.addView(bannerView); + // bannerContainer.setVisibility(View.VISIBLE); + Log.d(TAG, "loadBannerAd: set banner VISIBLE,mShowAd " +mShowAd); //绑定原生广告的数据 setAdData(bannerContainer,bannerView, ads.get(0)); + // mTTAdNative.loadNativeAd(adSlot,null); } }); } @@ -668,5 +697,89 @@ public abstract class Activity_base extends AppCompatActivity { public TTAdNative getAdNative(){ return mTTAdNative; } + void loadInteractionAd(String codeId) { + //step4:创建插屏广告请求参数AdSlot,具体参数含义参考文档 + if(getAdNative()==null){ + return; + } + AdSlot adSlot = new AdSlot.Builder() + .setCodeId(codeId) + .setSupportDeepLink(true) + .setImageAcceptedSize(600, 600) //根据广告平台选择的尺寸,传入同比例尺寸 + .build(); + //step5:请求广告,调用插屏广告异步请求接口 + getAdNative().loadInteractionAd(adSlot, new TTAdNative.InteractionAdListener() { + @Override + public void onError(int code, String message) { + Log.e(TAG, String.format("loadInteractionAd onError: code %s ,message %s",code,message) ); + } + + @Override + public void onInteractionAdLoad(TTInteractionAd ttInteractionAd) { + // TToast.show(getApplicationContext(), "type: " + ttInteractionAd.getInteractionType()); + ttInteractionAd.setAdInteractionListener(new TTInteractionAd.AdInteractionListener() { + @Override + public void onAdClicked() { + Log.d(TAG, "被点击"); + // TToast.show(mContext, "广告被点击"); + } + + @Override + public void onAdShow() { + Log.d(TAG, "被展示"); + // TToast.show(mContext, "广告被展示"); + } + + @Override + public void onAdDismiss() { + Log.d(TAG, "插屏广告消失"); + // TToast.show(mContext, "广告消失"); + } + }); + //如果是下载类型的广告,可以注册下载状态回调监听 + if (ttInteractionAd.getInteractionType() == TTAdConstant.INTERACTION_TYPE_DOWNLOAD) { + ttInteractionAd.setDownloadListener(new TTAppDownloadListener() { + @Override + public void onIdle() { + Log.d(TAG, "点击开始下载"); + // TToast.show(mContext, "点击开始下载"); + } + + @Override + public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) { + Log.d(TAG, "下载中"); + // TToast.show(mContext, "下载中"); + } + + @Override + public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) { + Log.d(TAG, "下载暂停"); + // TToast.show(mContext, "下载暂停"); + } + + @Override + public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) { + Log.d(TAG, "下载失败"); + // TToast.show(mContext, "下载失败"); + } + + @Override + public void onDownloadFinished(long totalBytes, String fileName, String appName) { + Log.d(TAG, "下载完成"); + // TToast.show(mContext, "下载完成"); + } + + @Override + public void onInstalled(String fileName, String appName) { + Log.d(TAG, "安装完成"); + // TToast.show(mContext, "安装完成"); + } + }); + } + //弹出插屏广告 + ttInteractionAd.showInteractionAd(oContext); + } + }); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/BookActivity.java b/zhuike/src/main/java/com/novelbook/android/BookActivity.java index 736f8a6..7633171 100644 --- a/zhuike/src/main/java/com/novelbook/android/BookActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/BookActivity.java @@ -160,7 +160,13 @@ public class BookActivity extends Activity_base { tvTonglei.setVisibility(View.GONE); tvAuthorMore.setText( ""); initiDownloadReceiver(); - loadNativeBannerAd(mBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID); + mShowAd =Constants.SHOWAD; + if(Constants.SHOWAD){ + loadNativeBannerAd(mBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID); + mBannerContainer.setVisibility(View.VISIBLE); + }else{ + mBannerContainer.setVisibility(View.GONE); + } } @Override diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java b/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java index 1296ed6..4ac9a22 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java @@ -141,7 +141,7 @@ public abstract class BasicFragment extends Fragment { initData(); initViews(); initSwipeRefreshLayout(); - showBanner(mBannerContainer,185); + showBanner(mBannerContainer,260); return view; // Inflate the layout for this fragment @@ -458,7 +458,7 @@ void initTabs(){ return; } - ((Main2Activity) activity).loadBannerAd(bannerContainer, BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID, Constants.SCREEN_WIDTH_PIX, adHeight); + ((Main2Activity) activity).loadBannerAd(bannerContainer, BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID,600, adHeight); mBannerContainer.setVisibility(View.VISIBLE); } diff --git a/zhuike/src/main/java/com/novelbook/android/Main2Activity.java b/zhuike/src/main/java/com/novelbook/android/Main2Activity.java index cad470a..36cd3f2 100644 --- a/zhuike/src/main/java/com/novelbook/android/Main2Activity.java +++ b/zhuike/src/main/java/com/novelbook/android/Main2Activity.java @@ -444,7 +444,7 @@ private int bottomSelectedIndex; // return super.onKeyUp(keyCode, event); // return false; - // finish(); + finish(); app.exit(); } } diff --git a/zhuike/src/main/java/com/novelbook/android/MyApp.java b/zhuike/src/main/java/com/novelbook/android/MyApp.java index 155dccc..bba482f 100644 --- a/zhuike/src/main/java/com/novelbook/android/MyApp.java +++ b/zhuike/src/main/java/com/novelbook/android/MyApp.java @@ -3,6 +3,7 @@ package com.novelbook.android; import android.app.Activity; import android.app.Application; import android.content.Context; +import android.provider.SyncStateContract; import android.util.Log; import com.bytedance.sdk.openadsdk.TTAdConfig; @@ -45,8 +46,10 @@ public class MyApp extends Application { initAD(); } private void initialConstants(){ - Config.createConfig(this); - Constants.SEX = Config.getInstance().getSexOption(); + Config confg= Config.createConfig(this); + Constants.SEX = confg.getSexOption(); + Constants.SHOWAD =confg.isShowAd(); + Constants.PRE_LOAD_CHAPT =confg.isPreLoadChapter(); } private void initUmengApi(){ UMConfigure.init(applicationContext,UMConfigure.DEVICE_TYPE_PHONE,null); @@ -62,9 +65,10 @@ public class MyApp extends Application { public boolean exit() { - removeALLActivity_(); System.exit(-1); + removeALLActivity_(); + return true; } /** diff --git a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java index 30aecb4..6b0f858 100644 --- a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java @@ -13,6 +13,7 @@ import android.graphics.Typeface; import android.os.Build; import android.os.Handler; import android.os.Message; +import android.support.annotation.Nullable; import android.support.design.widget.AppBarLayout; import android.support.v7.widget.Toolbar; import android.util.Log; @@ -128,6 +129,10 @@ public class ReadActivity extends Activity_base implements AdInterface { @BindView(R.id.imgLoading) pl.droidsonroids.gif.GifImageView imgLoading; + + @BindView(R.id.native_banner_container ) + FrameLayout mNative_banner_container; + private Config config; private WindowManager.LayoutParams lp; private Novel book; @@ -873,6 +878,13 @@ public class ReadActivity extends Activity_base implements AdInterface { @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); } @@ -1000,8 +1012,9 @@ public class ReadActivity extends Activity_base implements AdInterface { @Override public void showAd(boolean showAd ,int adHeight,int adY) { - hideSystemUI(); + hideSystemUI(); mShowAd =showAd; mBannerContainer.setVisibility(View.GONE); + mNative_banner_container.setVisibility(View.GONE); if(!Constants.SHOWAD){ return; } @@ -1018,17 +1031,21 @@ public class ReadActivity extends Activity_base implements AdInterface { // Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY)); if(adHeight>500 && adY <500){ - loadNativeBannerAd(mBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID); - params.setMargins(20, adY-30, 20, 50); + loadNativeBannerAd(mNative_banner_container,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID); + params.setMargins(20, adY-30, 20, 150); + mNative_banner_container.setLayoutParams(params); + mNative_banner_container.setVisibility(View.VISIBLE); + }else { loadBannerAd(mBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID, Constants.SCREEN_WIDTH_PIX-50,adHeight); params.setMargins(20, adY-10, 20, 15); + mBannerContainer.setLayoutParams(params); + mBannerContainer.setVisibility(View.VISIBLE); } - mBannerContainer.setLayoutParams(params); - mBannerContainer.setVisibility(View.VISIBLE); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java b/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java index 89e6250..75111f0 100644 --- a/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java +++ b/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java @@ -470,6 +470,9 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol } } public void AddHeaderItem(List items) { + if(mDatas.size()>3 &&( mDatas.get(3) instanceof TTFeedAd) ){ + return; + } int p = mDatas.size()>3?3:0; mDatas.addAll(p, items); notifyDataSetChanged(); diff --git a/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java b/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java index 4288510..de97b2f 100644 --- a/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java @@ -10,6 +10,7 @@ import android.util.Log; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.novelbook.android.AD.toutiao.TTAdManagerHolder; import com.novelbook.android.BookActivity; import com.novelbook.android.Main2Activity; import com.novelbook.android.MyApp; @@ -371,6 +372,9 @@ public class NetUtil { Constants.AD_SPLASH_INVTERVAL =(long) 1000 * ads.getInt("splashInterval"); Constants.AD_SPLASH_PAGES = ads.getInt("splashPageCount"); + + + Log.d(TAG, String.format("initHostConstants: Constants.AD_SPLASH_INVTERVAL %s,AD_SPLASH_PAGES %s",Constants.AD_SPLASH_INVTERVAL,Constants.AD_SPLASH_PAGES )); // try { Constants.version = CommonUtil.getVersionCode(MyApp.applicationContext); @@ -382,6 +386,21 @@ public class NetUtil { // }catch (Exception er){ // Log.e(TAG, "initHostConstants: update error ",er ); // } + + if( ads.getBoolean("showAdsense")){ + if(!Constants.SHOWAD ){ + Constants.SHOWAD = ads.getBoolean("showAdsense"); + TTAdManagerHolder.init(MyApp.applicationContext); + } + } + Constants.SHOWAD = ads.getBoolean("showAdsense"); + Constants.PRE_LOAD_CHAPT= false;//jsonObject.getBoolean("preLoadChapter"); + Config.getInstance().setShowAd(Constants.SHOWAD); + Config.getInstance().setPreLoadChapter(Constants.PRE_LOAD_CHAPT); + Log.d(TAG, String.format("initHostConstants: Constants.AD_SPLASH_INVTERVAL %s,AD_SPLASH_PAGES %s, Constants.SHOWAD %s,Constants.AD_PRE_LOAD_CHAPT %s " + ,Constants.AD_SPLASH_INVTERVAL,Constants.AD_SPLASH_PAGES, Constants.SHOWAD, Constants.PRE_LOAD_CHAPT )); + + } public static void checkUpdate(boolean isSilence){ diff --git a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java index da3f0a1..fe487e9 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java @@ -1601,7 +1601,7 @@ int muluRetryCount =0; return error.toCharArray(); } - if( Constants.AD_PRE_LOAD_CHAPT) { + if( Constants.PRE_LOAD_CHAPT) { if (mChapters.size() > index && NetUtil.isNetworkConnected()) { diff --git a/zhuike/src/main/java/com/novelbook/android/utils/Config.java b/zhuike/src/main/java/com/novelbook/android/utils/Config.java index d2cf6bd..bd9ac6a 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/Config.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/Config.java @@ -40,7 +40,9 @@ public class Config { public final static int PAGE_MODE_COVER = 1; public final static int PAGE_MODE_SLIDE = 2; public final static int PAGE_MODE_NONE = 3; - + public final static boolean SHOW_AD = false; + public final static String SHOW_AD_KEY = "showAd"; + private static final String PRE_LOAD_CHAPT_KEY ="preloadchapt" ; private Context mContext; private static Config config; private SharedPreferences sp; @@ -210,5 +212,16 @@ public class Config { sp.edit().putString(KEY_ROOT_URL,baseUrl).commit(); } - + public Boolean isShowAd(){ + return sp.getBoolean(SHOW_AD_KEY,true); + } + public void setShowAd(boolean isShowAd){ + sp.edit().putBoolean(SHOW_AD_KEY,isShowAd).commit(); + } + public Boolean isPreLoadChapter(){ + return sp.getBoolean(PRE_LOAD_CHAPT_KEY,false); + } + public void setPreLoadChapter(boolean isPreloadChapt){ + sp.edit().putBoolean(PRE_LOAD_CHAPT_KEY,isPreloadChapt).commit(); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java index 7ebb398..de925ee 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java @@ -13,8 +13,8 @@ public class Constants { public static final int MAXAGE_MAX =60*60*24*28; //28 天 ; public static final int MAXAGE_MULU = 60*60*24*7*2; //2周;; public static final String VERSION_ADDRESS ="version.xml"; - public static final boolean SHOWAD =true ; - public static boolean AD_PRE_LOAD_CHAPT = false; + public static boolean SHOWAD =false ; + public static boolean PRE_LOAD_CHAPT = false; public static long AD_SPLASH_INVTERVAL = 5*60*1000;//间隔5分钟 public static int AD_SPLASH_PAGES = 15; public static int SCREEN_HEIGHT_PIX =1920 ; diff --git a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java index 835a48d..f4859cd 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java @@ -186,6 +186,8 @@ public class PageFactory implements ChangeSource{ private final int MSG_NEXTPAGE=2; private final int MSG_HIDEPROGRESS=3; private final int MSG_NEXTPAGE_FAIL=4; + private final int MSG_HID_AD=5; + private final int MSG_SHOW_LOADING=5; public AdInterface getmAd() { return mAd; } @@ -233,8 +235,31 @@ public class PageFactory implements ChangeSource{ if(mAd!=null) { mAd.showRefresh(View.GONE); // mAd.hideProgressbar(); - mAd.showLoading(false); + + mAd.showLoading(false); + Log.d(TAG, "showloading: case MSG_HIDEPROGRESS: false" ); } + }else if (msg.what == MSG_HID_AD) { + + /* Log.d(TAG, "loadBannerAd: set banner gone 0, showingStatusAd " +showingStatusAd); + if(showingStatusAd) { + if (mAd != null) { + mAd.showAd(false, 0, 0); + Log.d(TAG, "loadBannerAd: set banner gone 1"); + } + showingStatusAd = false; + Log.d(TAG, "loadBannerAd: set banner gone 2"); + }*/ + }else if (msg.what == MSG_SHOW_LOADING) { + + + if(mAd!=null) { + + mAd.showLoading(true); + Log.d(TAG, "showloading: case MSG_SHOW_LOADING: true" ); + + } + } } Map fileRetryCnt = new HashMap(); @@ -327,7 +352,7 @@ public class PageFactory implements ChangeSource{ @Override public void run() { Log.d(TAG, String.format("prepare book to download chapter %s ,thread.name %s",chid,Thread.currentThread().getName() ) ); - mBookUtil.chaptChars(chid); //TODO: 读取到上一章block后,file还是不存在的,现在就死循环了 fixed + mBookUtil.chaptChars(chid); super.run(); }}.start(); @@ -392,7 +417,7 @@ public class PageFactory implements ChangeSource{ void preReadChaptCache(final int chaptId){ - if(!Constants.AD_PRE_LOAD_CHAPT){ + if(!Constants.PRE_LOAD_CHAPT){ return; } if(chaptMap==null) { @@ -552,6 +577,7 @@ public class PageFactory implements ChangeSource{ case SERVERERROR:return true; case CHANGESOURCE:return false; case NETWORKFAILE:return true; + case LASTPAGE:return true; } return false; } @@ -583,7 +609,8 @@ public class PageFactory implements ChangeSource{ NETWORKFAILE, SERVERERROR, CHANGESOURCE , - LOCALFAIL; + LOCALFAIL, + LASTPAGE; } private void hideSysUI(){ if(mAd!=null){ @@ -722,20 +749,24 @@ private void hideSysUI(){ hideSysUI(); mAd.showRefresh(View.VISIBLE); mAd.hideProgressbar(); - mAd.showLoading(false); + // mAd.showLoading(false); String status = ""; + boolean showAd =true; switch (mStatus){ case OPENING: status = "正在拼命加载" + loadingTxt; mAd.showRefresh(View.GONE); // mAd.showProgressbar(false,status); - mAd.showLoading(true); + mAd.showLoading(true); + Log.d(TAG, "showloading: case OPENING: true" ); + //handler.sendEmptyMessage(MSG_SHOW_LOADING); // showProgressDialog(); break; case FAIL: status = "读取错误,请稍后重试"; mAd.showRefresh(View.VISIBLE); mAd.showReadSetting(); + mAd.showLoading(false); try { throw new Exception("error on reading"); } catch (Exception e) { @@ -744,25 +775,43 @@ private void hideSysUI(){ } break; case NETWORKFAILE: + mAd.showLoading(false); + Log.d(TAG, "showloading: case NETWORKFAILE: false" ); + showAd =false; status = "请开启网络"; break; case SERVERERROR: + mAd.showLoading(false); + Log.d(TAG, "showloading: case SERVERERROR: false" ); status = "服务器故障"; break; case FINISH: + mAd.showLoading(false); + Log.d(TAG, "showloading: case FINISH: false" ); status = "加载成功"; mAd.showRefresh(View.GONE); mAd.hideProgressbar(); + showAd =false; break; case CHANGESOURCE: + mAd.showLoading(true); + Log.d(TAG, "showloading: case CHANGESOURCE: true" ); status = statusChangeSource; mAd.showRefresh(View.GONE); break; case LOCALFAIL: + mAd.showLoading(false); + Log.d(TAG, "showloading: case LOCALFAIL: false" ); status = "本地缓存加载错误"; mAd.showRefresh(View.GONE); break; + case LASTPAGE: + status = "看完了,没有了"; + mAd.showRefresh(View.GONE); + mAd.showLoading(false); + Log.d(TAG, "showloading: case LASTPAGE: false" ); + break; } Canvas c = new Canvas(bitmap); @@ -787,7 +836,7 @@ private void hideSysUI(){ StaticLayout myStaticLayout = new StaticLayout(status, tp, c.getWidth(), Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); myStaticLayout.draw(c);*/ - mBookPageWidget.postInvalidate(); + // hideSysUI(); /* float adHeight = mHeight - baseline -marginHeight-statusMarginBottom-30; float adY =targetRect.top +10;*/ @@ -795,15 +844,52 @@ private void hideSysUI(){ float adHeight = baseline -100; float adY =targetRect.top +250; + if(showAd) while(!showingStatusAd || new Date().getTime() - showStatusAdTime > 2000) { showingStatusAd =true; showStatusAdTime = new Date().getTime(); showAd((int) adHeight, (int) adY); - Log.d(TAG, "loadBannerAd: AD is requested"); + Log.d(TAG, "loadBannerAd: AD is requested, mStatus:" +mStatus); } + if (mStatus==Status.OPENING ) { + String url = mBookUtil.getChapter(currentChapter).getChapterUrl(); + if(!TextUtils.isEmpty(url)) { + if(url.length()>100) + url =url.substring(0,100); + waitPaint.setTextSize(mContext.getResources().getDimension(R.dimen.reading_medu_text_size));// 字体大小 + waitPaint.setColor(getTextColor()); + waitPaint.setTextAlign(Paint.Align.CENTER); + + targetRect = new Rect(0, 0, mWidth, mHeight); + + fontMetrics = waitPaint.getFontMetricsInt(); + baseline = baseline +150; + // 下面这行是实现水平居中,drawText对应改为传入targetRect.centerX() + waitPaint.setTextAlign(Paint.Align.CENTER); + c.drawText("转向第三方网站 " + getSite().getName() , targetRect.centerX(), baseline, waitPaint); + baseline+=40; + c.drawText(url , targetRect.centerX(), baseline, waitPaint); + + String chaptName= mBookUtil.getChapter(currentChapter).getChapterName(); + if(!TextUtils.isEmpty(chaptName)) { + if(chaptName.length()>100) + chaptName =chaptName.substring(0,100); + + chaptName ="正为您搜索加载 " +chaptName +" ..."; + + baseline = 80; + // 下面这行是实现水平居中,drawText对应改为传入targetRect.centerX() + waitPaint.setTextAlign(Paint.Align.CENTER); + c.drawText(chaptName, targetRect.centerX(), baseline, waitPaint); + } + + } + } + mBookPageWidget.postInvalidate(); + } @@ -813,9 +899,19 @@ private void hideSysUI(){ public void onDraw(Bitmap bitmap,List m_lines,Boolean updateChapter,Boolean showAd) { hideSysUI(); // mAd.showRefresh(View.GONE); - if(m_lines.size()==0){ + if(m_lines.size()==0 ){ return; } + /* Log.d(TAG, "showloading: ondraw showAd: " +showAd ); + try{ + throw new Exception("showloading: ondraw mStatus: " +mStatus ); + }catch (Exception e){ + Log.e(TAG, "showloading: ", e); + }*/ + if(showAd && mAd!=null){ + handler.sendEmptyMessage(MSG_HID_AD); + handler.sendEmptyMessage(MSG_HIDEPROGRESS); + } mStatus =Status.FINISH; // Log.d(TAG, String.format(" prepare book onDraw chapter %s, getChapters().size() %s ",currentChapter ,getChapters().size() ) ); if (getChapters().size() > 0 && updateChapter) { @@ -825,11 +921,10 @@ private void hideSysUI(){ } // Log.d(TAG, String.format(" prepare book onDraw chapter _____________ %s ",currentChapter ) ); - showingStatusAd =false; - if(mAd!=null){ - handler.sendEmptyMessage(MSG_HIDEPROGRESS); - } + + + //更新数据库进度 if ( mStatus ==Status.FINISH && currentPage != null && getNovel() != null) { @@ -1048,14 +1143,21 @@ private void hideSysUI(){ if(mBookPageWidget==null){ return; } - Log.d(TAG, " prePage() onDraw: mBookPageWidget.getCurPage() "); - onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false); - currentPage = getPrePage(); - if(mBookPageWidget==null){ - return; + if(mStatus ==Status.LASTPAGE) { + onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false); + if(mBookPageWidget==null){ + return; + } + Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); + onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); + }else{ + if(mBookPageWidget==null){ + return; + } + Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); + currentPage = getPrePage(); + onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); } - Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); - onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); } @@ -1114,8 +1216,11 @@ private void hideSysUI(){ } m_islastPage =currentChapter == mBookUtil.getChapters().size();// ||mBookUtil.getChapters().size()==0; if ( m_islastPage){ - Toast.makeText(mContext, "已经是最后一页了", Toast.LENGTH_SHORT).show(); - currentPage(false); + + Toast.makeText(mContext, "已经是最后一页了", Toast.LENGTH_SHORT).show(); + mStatus = Status.LASTPAGE; + drawStatus(); + // currentPage(false); return; } else { @@ -1173,7 +1278,9 @@ private void hideSysUI(){ } }else{ Log.d(TAG, "prepare book: has been prepared, return.... " + book.getName()); - return; + if(mBookUtil!=null) { + return; + } } } @@ -1198,7 +1305,7 @@ private void hideSysUI(){ if(book.isLocalBook()){ //离线书籍重新初始化加载mBookUtil mBookUtil = new BookUtil(); mBookUtil.setNovel(book); - }else if(getNovle()==null){ + }else if(mBookUtil ==null || getNovle()==null){ Log.d(TAG, "prepare book: preparing in openBook method" + book.getName()); prepareBook(book); } diff --git a/zhuike/src/main/res/layout/zactivity_read.xml b/zhuike/src/main/res/layout/zactivity_read.xml index 16d8e90..932f325 100644 --- a/zhuike/src/main/res/layout/zactivity_read.xml +++ b/zhuike/src/main/res/layout/zactivity_read.xml @@ -45,8 +45,8 @@ /> --> + diff --git a/zhuike/src/main/res/values/dimens.xml b/zhuike/src/main/res/values/dimens.xml index d0fc361..d49639d 100644 --- a/zhuike/src/main/res/values/dimens.xml +++ b/zhuike/src/main/res/values/dimens.xml @@ -25,6 +25,8 @@ 20sp 10sp + + 12sp 30sp diff --git a/zhuike/src/main/res/values/styles.xml b/zhuike/src/main/res/values/styles.xml index ce61eea..46da4b2 100644 --- a/zhuike/src/main/res/values/styles.xml +++ b/zhuike/src/main/res/values/styles.xml @@ -451,10 +451,11 @@ diff --git a/zhuike/zhuike.iml b/zhuike/zhuike.iml index b187046..bbaaaa7 100644 --- a/zhuike/zhuike.iml +++ b/zhuike/zhuike.iml @@ -104,14 +104,19 @@ + + + + + @@ -121,6 +126,7 @@ +