调整广告

This commit is contained in:
mwang 2019-06-04 00:13:32 +08:00
parent 577a1acf4a
commit f823f19565
20 changed files with 397 additions and 70 deletions

View File

@ -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
@ -79,7 +80,21 @@ android {
//
/*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]

View File

@ -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);
}
}

View File

@ -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对象
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);
}
if(mSplashContainer!=null) {
mSplashContainer.removeAllViews();
}
SplashAdManager.clearPages();
this.finish();
}

View File

@ -25,8 +25,10 @@ public class TTAdManagerHolder {
}
public static void init(Context context) {
if( Constants.SHOWAD) {
doInit(context);
}
}
//step1:接入网盟广告sdk的初始化操作详情见接入文档和穿山甲平台说明
private static void doInit(Context context) {

View File

@ -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(){
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,13 +379,14 @@ 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
@ -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<TTNativeAd> 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);
}
});
}
}

View File

@ -160,7 +160,13 @@ public class BookActivity extends Activity_base {
tvTonglei.setVisibility(View.GONE);
tvAuthorMore.setText( "");
initiDownloadReceiver();
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

View File

@ -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);
}

View File

@ -444,7 +444,7 @@ private int bottomSelectedIndex;
// return super.onKeyUp(keyCode, event);
// return false;
// finish();
finish();
app.exit();
}
}

View File

@ -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;
}
/**

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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){

View File

@ -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()) {

View File

@ -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();
}
}

View File

@ -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 ;

View File

@ -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);
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<Integer,Integer> fileRetryCnt = new HashMap<Integer,Integer>();
@ -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);
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();
}
@ -816,6 +902,16 @@ private void hideSysUI(){
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() ");
if(mStatus ==Status.LASTPAGE) {
onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false);
currentPage = getPrePage();
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);
}
}
@ -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);
mStatus = Status.LASTPAGE;
drawStatus();
// currentPage(false);
return;
} else {
@ -1173,8 +1278,10 @@ private void hideSysUI(){
}
}else{
Log.d(TAG, "prepare book: has been prepared, return.... " + book.getName());
if(mBookUtil!=null) {
return;
}
}
}
mBookUtil = new BookUtil();
@ -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);
}

View File

@ -45,8 +45,8 @@
/>
<pl.droidsonroids.gif.GifImageView
android:id="@+id/imgLoading"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/loading"
android:scaleType="centerCrop"
android:layout_gravity="center_horizontal|bottom"
@ -80,6 +80,13 @@
style="@style/frmBannerContainer"
android:layout_height="wrap_content"
android:id="@+id/banner_container"
android:visibility="gone"
/>
<FrameLayout
style="@style/frmBannerContainer"
android:layout_height="wrap_content"
android:id="@+id/native_banner_container"
android:visibility="gone"
/>
</FrameLayout>

View File

@ -25,6 +25,8 @@
<dimen name="reading_default_text_size">20sp</dimen>
<!-- 书本字体最小大小 -->
<dimen name="reading_min_text_size">10sp</dimen>
<!-- 书本字体中大小 -->
<dimen name="reading_medu_text_size">12sp</dimen>
<!-- 书本字体最大大小 -->
<dimen name="reading_max_text_size">30sp</dimen>
<!-- 设置行高 -->

View File

@ -451,10 +451,11 @@
</style>
<style name="frmBannerContainer">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">50dp</item>
<item name="android:layout_centerInParent">true</item>
<item name="android:background">@color/mintcream</item>
<item name="android:visibility">gone</item>
</style>

View File

@ -104,14 +104,19 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/legacy_multidex_aapt_derived_proguard_rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/legacy_multidex_main_dex_list" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged-not-compiled-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/metadata_feature_manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processed_res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-files" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res_stripped" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shader_assets" />
@ -121,6 +126,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />