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 29f95cd..c6cb964 100644 --- a/zhuike/src/main/java/com/novelbook/android/Activity_base.java +++ b/zhuike/src/main/java/com/novelbook/android/Activity_base.java @@ -496,7 +496,11 @@ public abstract class Activity_base extends AppCompatActivity { }); } //-------------native toutiao ad - void loadNativeBannerAd(FrameLayout bannerContainer,String codeId) { + void loadNativeBannerAd(FrameLayout bannerContainer,String codeId) { + + loadNativeBannerAd(bannerContainer,codeId,690,388); + } + void loadNativeBannerAd(FrameLayout bannerContainer,String codeId,int width,int height) { //step4:创建广告请求参数AdSlot,注意其中的setNativeAdtype方法,具体参数含义参考文档 if(!Constants.SHOWAD || getTTAdNative()==null ){ @@ -506,7 +510,7 @@ public abstract class Activity_base extends AppCompatActivity { final AdSlot adSlot = new AdSlot.Builder() .setCodeId(codeId) .setSupportDeepLink(true) - .setImageAcceptedSize(690, 388) + .setImageAcceptedSize(width, height) .setNativeAdType(AdSlot.TYPE_BANNER) //请求原生广告时候,请务必调用该方法,设置参数为TYPE_BANNER或TYPE_INTERACTION_AD .setAdCount(1) .build(); diff --git a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java index 6b0f858..0f99efc 100644 --- a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java @@ -124,8 +124,10 @@ public class ReadActivity extends Activity_base implements AdInterface { @BindView(R.id.appbar) AppBarLayout appbar; -// @BindView(R.id.banner_container) -// FrameLayout mBannerContainer; + + @BindView(R.id.top_banner_container) + FrameLayout mTopBannerContainer; + @BindView(R.id.imgLoading) pl.droidsonroids.gif.GifImageView imgLoading; @@ -1005,6 +1007,22 @@ public class ReadActivity extends Activity_base implements AdInterface { } */ + @Override + public void showTopBanner( int adHeight,int adY) { + hideSystemUI(); + mTopBannerContainer.setVisibility(View.GONE); + if(adHeight<=0){ + return; + } + Log.d(TAG, String.format("loadBannerAd:showTopBanner width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY)); + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTopBannerContainer.getLayoutParams(); + loadBannerAd(mTopBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID, 690,adHeight); + // loadNativeBannerAd(mTopBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID, 304,200); + params.setMargins(20, adY-10, 20, 10); + params.width =-1; + mTopBannerContainer.setLayoutParams(params); + mTopBannerContainer.setVisibility(View.VISIBLE); + } final int contentAdHight=80; @@ -1024,6 +1042,11 @@ public class ReadActivity extends Activity_base implements AdInterface { return; } + + + + + if(adHeight >contentAdHight){ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams(); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java b/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java index 4b4b853..f271d32 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java @@ -7,6 +7,7 @@ public interface AdInterface { * @param adY */ public void showAd(boolean showAd,int height,int adY); + public void showTopBanner(int height,int adY); public void hideSystemUI(); public void showRefresh(int visible); public void showProgressbar(boolean dismissAble,String msg); 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 de925ee..3d694ae 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java @@ -19,6 +19,8 @@ public class Constants { public static int AD_SPLASH_PAGES = 15; public static int SCREEN_HEIGHT_PIX =1920 ; public static int SCREEN_WIDTH_PIX = 1080; + public static int AD_CHAPT_TOP_BANNER_HEIGHT=200; + public static int AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT=1; //每几页show topbanner public static long LAST_G = 0;//主目录API上次访问时间 public static long MAXAGE_G = 3600;//主目录API上次访问时间 public static String[] HOT_KEYS_VALUE = {}; 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 f4859cd..70ddb2f 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java @@ -467,7 +467,7 @@ public class PageFactory implements ChangeSource{ while(length 1 && pageNo%Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT==0){ + topAdH =Constants.AD_CHAPT_TOP_BANNER_HEIGHT; + } TRPage trPage = new TRPage(); trPage.setBegin(position +1); + trPage.setTopBannerHeight(topAdH); // Log.d(TAG,"page postion next begin:" + (position + 1) + ""); - trPage.setLines(getNextLines(chaptId)); + trPage.setLines(getNextLines(chaptId,topAdH)); // Log.d(TAG,"page postion next end:" +mBookUtil.getPosition() + ""); trPage.setEnd(mBookUtil.getPosition(chaptId)); return trPage; @@ -896,8 +900,9 @@ private void hideSysUI(){ //上次翻书时间 private long lastPageTime; - public void onDraw(Bitmap bitmap,List m_lines,Boolean updateChapter,Boolean showAd) { + public void onDraw(Bitmap bitmap,TRPage trPage,Boolean updateChapter,Boolean showAd) { hideSysUI(); + List m_lines = trPage.getLines(); // mAd.showRefresh(View.GONE); if(m_lines.size()==0 ){ return; @@ -987,9 +992,16 @@ private void hideSysUI(){ paragraphSpace = prate * lineSpace; + if(mAd!=null){ + mAd.showTopBanner(trPage.getTopBannerHeight(),(int)(marginHeight + space)); + } + + + if (m_lines.size() > 0) { - float y = marginHeight; + + float y = marginHeight +trPage.getTopBannerHeight(); String lastLine =""; for (String strLine : m_lines) { // if(strLine.endsWith("\n")) { @@ -1144,19 +1156,19 @@ private void hideSysUI(){ return; } if(mStatus ==Status.LASTPAGE) { - onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false); + onDraw(mBookPageWidget.getCurPage(),currentPage ,true,false); if(mBookPageWidget==null){ return; } Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); - onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); + onDraw(mBookPageWidget.getNextPage(),currentPage ,true,true); }else{ if(mBookPageWidget==null){ return; } Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); currentPage = getPrePage(); - onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); + onDraw(mBookPageWidget.getNextPage(),currentPage ,true,true); } } @@ -1232,7 +1244,7 @@ private void hideSysUI(){ return; } Log.d(TAG, "nextPage() onDraw: mBookPageWidget.getCurPage() "); - onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false); + onDraw(mBookPageWidget.getCurPage(),currentPage ,true,false); prePage = currentPage; currentPage = getNextPage(); // currentPage = currentChaptPages.get(currentPage.getPageNo()-1); @@ -1240,7 +1252,7 @@ private void hideSysUI(){ return; } Log.d(TAG, "nextPage() onDraw: mBookPageWidget.getNextPage() "); - onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); + onDraw(mBookPageWidget.getNextPage(),currentPage ,true,true); Log.d("nextPage","nextPagenext"); HashMap map = new HashMap(); @@ -1487,7 +1499,7 @@ private void hideSysUI(){ } boolean showChapTitleOnTopWhenNextPage =false; - public List getNextLines(int chaptId){ + public List getNextLines(int chaptId,int topAdHeight){ List lines = new ArrayList<>(); float width = 0; float height = 0; @@ -1497,7 +1509,8 @@ private void hideSysUI(){ if(mBookUtil.getPosition(chaptId)==0) { lines.add("\n");//lines.add("\n"); } - calculateLineCount(); + + calculateLineCount(topAdHeight); while (mBookUtil.next(true,chaptId) != -1){ char word = (char) mBookUtil.next(false,chaptId); // Log.d(TAG, String.format(" loadchapt getNextLines(), chaptId %s, word '%s'", chaptId,word )); @@ -1517,7 +1530,7 @@ private void hideSysUI(){ line = ""; width = 0; height += paragraphSpace - lineSpace; - calculateLineCount(height); + calculateLineCount(topAdHeight+height); if (lines.size()>= mLineCount +firstPageLine){ // Log.d(TAG,String.format("lines count limit a %s,lines size %s",mLineCount,lines.size())); line =""; @@ -1726,9 +1739,9 @@ private void hideSysUI(){ return; } Log.d(TAG, "currentPage onDraw: mBookPageWidget.getCurPage() "); - onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),updateChapter,false); + onDraw(mBookPageWidget.getCurPage(),currentPage ,updateChapter,false); Log.d(TAG, "currentPage onDraw: mBookPageWidget.getNextPage() "); - onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),updateChapter,true); + onDraw(mBookPageWidget.getNextPage(),currentPage ,updateChapter,true); } //更新电量 diff --git a/zhuike/src/main/java/com/novelbook/android/utils/TRPage.java b/zhuike/src/main/java/com/novelbook/android/utils/TRPage.java index 98d6a5c..c4a2599 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/TRPage.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/TRPage.java @@ -12,6 +12,7 @@ public class TRPage { private boolean isLastPage; private boolean isFirstPage; private List lines = new ArrayList<>(); + private int topBannerHeight=0; public TRPage( ){ } @@ -19,6 +20,13 @@ public class TRPage { lines.add(line); } + public int getTopBannerHeight() { + return topBannerHeight; + } + + public void setTopBannerHeight(int topBannerHeight) { + this.topBannerHeight = topBannerHeight; + } public int getChapterNo() { return chapterNo; diff --git a/zhuike/src/main/res/layout/zactivity_read.xml b/zhuike/src/main/res/layout/zactivity_read.xml index 932f325..ea61652 100644 --- a/zhuike/src/main/res/layout/zactivity_read.xml +++ b/zhuike/src/main/res/layout/zactivity_read.xml @@ -75,7 +75,12 @@ --> - +