update ad
This commit is contained in:
		
							parent
							
								
									f823f19565
								
							
						
					
					
						commit
						ad7ed7317d
					
				|  | @ -497,6 +497,10 @@ public abstract  class Activity_base extends AppCompatActivity { | ||||||
|     } |     } | ||||||
|     //-------------native toutiao ad |     //-------------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方法,具体参数含义参考文档 |         //step4:创建广告请求参数AdSlot,注意其中的setNativeAdtype方法,具体参数含义参考文档 | ||||||
| 
 | 
 | ||||||
|          if(!Constants.SHOWAD || getTTAdNative()==null ){ |          if(!Constants.SHOWAD || getTTAdNative()==null ){ | ||||||
|  | @ -506,7 +510,7 @@ public abstract  class Activity_base extends AppCompatActivity { | ||||||
|         final AdSlot adSlot = new AdSlot.Builder() |         final AdSlot adSlot = new AdSlot.Builder() | ||||||
|                 .setCodeId(codeId) |                 .setCodeId(codeId) | ||||||
|                 .setSupportDeepLink(true) |                 .setSupportDeepLink(true) | ||||||
|                 .setImageAcceptedSize(690, 388) |                 .setImageAcceptedSize(width, height) | ||||||
|                 .setNativeAdType(AdSlot.TYPE_BANNER) //请求原生广告时候,请务必调用该方法,设置参数为TYPE_BANNER或TYPE_INTERACTION_AD |                 .setNativeAdType(AdSlot.TYPE_BANNER) //请求原生广告时候,请务必调用该方法,设置参数为TYPE_BANNER或TYPE_INTERACTION_AD | ||||||
|                 .setAdCount(1) |                 .setAdCount(1) | ||||||
|                 .build(); |                 .build(); | ||||||
|  |  | ||||||
|  | @ -124,8 +124,10 @@ public class ReadActivity extends  Activity_base implements   AdInterface { | ||||||
|     @BindView(R.id.appbar) |     @BindView(R.id.appbar) | ||||||
|     AppBarLayout appbar; |     AppBarLayout appbar; | ||||||
| 
 | 
 | ||||||
| //    @BindView(R.id.banner_container) | 
 | ||||||
| //    FrameLayout mBannerContainer; |      @BindView(R.id.top_banner_container) | ||||||
|  |     FrameLayout mTopBannerContainer; | ||||||
|  | 
 | ||||||
|     @BindView(R.id.imgLoading) |     @BindView(R.id.imgLoading) | ||||||
|     pl.droidsonroids.gif.GifImageView 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; |     final int contentAdHight=80; | ||||||
|  | @ -1024,6 +1042,11 @@ public class ReadActivity extends  Activity_base implements   AdInterface { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         if(adHeight >contentAdHight){ |         if(adHeight >contentAdHight){ | ||||||
| 
 | 
 | ||||||
|             FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams(); |             FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams(); | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ public interface AdInterface { | ||||||
|      * @param adY |      * @param adY | ||||||
|      */ |      */ | ||||||
|     public void showAd(boolean showAd,int height,int adY); |     public void showAd(boolean showAd,int height,int adY); | ||||||
|  |     public void showTopBanner(int height,int adY); | ||||||
|     public void hideSystemUI(); |     public void hideSystemUI(); | ||||||
|     public void showRefresh(int visible); |     public void showRefresh(int visible); | ||||||
|     public void showProgressbar(boolean dismissAble,String msg); |     public void showProgressbar(boolean dismissAble,String msg); | ||||||
|  |  | ||||||
|  | @ -19,6 +19,8 @@ public class Constants { | ||||||
|     public static int AD_SPLASH_PAGES = 15; |     public static int AD_SPLASH_PAGES = 15; | ||||||
|     public static  int SCREEN_HEIGHT_PIX =1920 ; |     public static  int SCREEN_HEIGHT_PIX =1920 ; | ||||||
|     public static int SCREEN_WIDTH_PIX = 1080; |     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 LAST_G = 0;//主目录API上次访问时间 | ||||||
|     public static long MAXAGE_G = 3600;//主目录API上次访问时间 |     public static long MAXAGE_G = 3600;//主目录API上次访问时间 | ||||||
|     public static   String[] HOT_KEYS_VALUE = {}; |     public static   String[] HOT_KEYS_VALUE = {}; | ||||||
|  |  | ||||||
|  | @ -467,7 +467,7 @@ public class PageFactory implements ChangeSource{ | ||||||
|         while(length <chars.length ) { |         while(length <chars.length ) { | ||||||
|             long starttime1 = new Date().getTime(); |             long starttime1 = new Date().getTime(); | ||||||
|             pageNo++; |             pageNo++; | ||||||
|             TRPage page  = getNextChapterPage(chaptId,length); |             TRPage page  = getNextChapterPage(chaptId,length ,pageNo); | ||||||
|             // Log.d(TAG,"prepare book  page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getChapterLen()); |             // Log.d(TAG,"prepare book  page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getChapterLen()); | ||||||
| 
 | 
 | ||||||
|             // if(page.getBegin() == mBookUtil.getChapterLen() ){ //最后一页空白的情况。。。 |             // if(page.getBegin() == mBookUtil.getChapterLen() ){ //最后一页空白的情况。。。 | ||||||
|  | @ -490,13 +490,17 @@ public class PageFactory implements ChangeSource{ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public TRPage getNextChapterPage(int chaptId,long position){ |     public TRPage getNextChapterPage(int chaptId,long position,int pageNo){ | ||||||
|         mBookUtil.setPostition(chaptId,position); |         mBookUtil.setPostition(chaptId,position); | ||||||
| 
 |         int topAdH =0; | ||||||
|  |         if(Constants.SHOWAD && pageNo >1 && pageNo%Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT==0){ | ||||||
|  |             topAdH =Constants.AD_CHAPT_TOP_BANNER_HEIGHT; | ||||||
|  |         } | ||||||
|         TRPage trPage = new TRPage(); |         TRPage trPage = new TRPage(); | ||||||
|         trPage.setBegin(position +1); |         trPage.setBegin(position +1); | ||||||
|  |         trPage.setTopBannerHeight(topAdH); | ||||||
|       // Log.d(TAG,"page postion next begin:" +  (position + 1) + ""); |       // 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() + ""); |      //  Log.d(TAG,"page postion next end:" +mBookUtil.getPosition() + ""); | ||||||
|         trPage.setEnd(mBookUtil.getPosition(chaptId)); |         trPage.setEnd(mBookUtil.getPosition(chaptId)); | ||||||
|         return trPage; |         return trPage; | ||||||
|  | @ -896,8 +900,9 @@ private void hideSysUI(){ | ||||||
|     //上次翻书时间 |     //上次翻书时间 | ||||||
|     private long lastPageTime; |     private long lastPageTime; | ||||||
| 
 | 
 | ||||||
|     public void onDraw(Bitmap bitmap,List<String> m_lines,Boolean updateChapter,Boolean showAd) { |     public void onDraw(Bitmap bitmap,TRPage trPage,Boolean updateChapter,Boolean showAd) { | ||||||
|         hideSysUI(); |         hideSysUI(); | ||||||
|  |         List<String> m_lines = trPage.getLines(); | ||||||
|        // mAd.showRefresh(View.GONE); |        // mAd.showRefresh(View.GONE); | ||||||
|         if(m_lines.size()==0 ){ |         if(m_lines.size()==0 ){ | ||||||
|             return; |             return; | ||||||
|  | @ -987,9 +992,16 @@ private void hideSysUI(){ | ||||||
|         paragraphSpace = prate * lineSpace; |         paragraphSpace = prate * lineSpace; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |         if(mAd!=null){ | ||||||
|  |             mAd.showTopBanner(trPage.getTopBannerHeight(),(int)(marginHeight + space)); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|         if (m_lines.size() > 0) { |         if (m_lines.size() > 0) { | ||||||
|             float y = marginHeight; | 
 | ||||||
|  |             float y = marginHeight +trPage.getTopBannerHeight(); | ||||||
|             String lastLine =""; |             String lastLine =""; | ||||||
|             for (String strLine : m_lines) { |             for (String strLine : m_lines) { | ||||||
|              //   if(strLine.endsWith("\n")) { |              //   if(strLine.endsWith("\n")) { | ||||||
|  | @ -1144,19 +1156,19 @@ private void hideSysUI(){ | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         if(mStatus ==Status.LASTPAGE) { |         if(mStatus ==Status.LASTPAGE) { | ||||||
|             onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false); |             onDraw(mBookPageWidget.getCurPage(),currentPage ,true,false); | ||||||
|             if(mBookPageWidget==null){ |             if(mBookPageWidget==null){ | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); |             Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); | ||||||
|             onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); |             onDraw(mBookPageWidget.getNextPage(),currentPage ,true,true); | ||||||
|         }else{ |         }else{ | ||||||
|             if(mBookPageWidget==null){ |             if(mBookPageWidget==null){ | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); |             Log.d(TAG, " prePage() onDraw: mBookPageWidget.getNextPage() "); | ||||||
|             currentPage = getPrePage(); |             currentPage = getPrePage(); | ||||||
|             onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); |             onDraw(mBookPageWidget.getNextPage(),currentPage ,true,true); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | @ -1232,7 +1244,7 @@ private void hideSysUI(){ | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         Log.d(TAG, "nextPage() onDraw: mBookPageWidget.getCurPage() "); |         Log.d(TAG, "nextPage() onDraw: mBookPageWidget.getCurPage() "); | ||||||
|         onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true,false); |         onDraw(mBookPageWidget.getCurPage(),currentPage ,true,false); | ||||||
|         prePage = currentPage; |         prePage = currentPage; | ||||||
|          currentPage = getNextPage(); |          currentPage = getNextPage(); | ||||||
|         // currentPage = currentChaptPages.get(currentPage.getPageNo()-1); |         // currentPage = currentChaptPages.get(currentPage.getPageNo()-1); | ||||||
|  | @ -1240,7 +1252,7 @@ private void hideSysUI(){ | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         Log.d(TAG, "nextPage() onDraw: mBookPageWidget.getNextPage() "); |         Log.d(TAG, "nextPage() onDraw: mBookPageWidget.getNextPage() "); | ||||||
|         onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true,true); |         onDraw(mBookPageWidget.getNextPage(),currentPage ,true,true); | ||||||
|        Log.d("nextPage","nextPagenext"); |        Log.d("nextPage","nextPagenext"); | ||||||
| 
 | 
 | ||||||
|         HashMap<String,String> map = new HashMap<String,String>(); |         HashMap<String,String> map = new HashMap<String,String>(); | ||||||
|  | @ -1487,7 +1499,7 @@ private void hideSysUI(){ | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     boolean showChapTitleOnTopWhenNextPage =false; |     boolean showChapTitleOnTopWhenNextPage =false; | ||||||
|     public List<String> getNextLines(int chaptId){ |     public List<String> getNextLines(int chaptId,int topAdHeight){ | ||||||
|         List<String> lines = new ArrayList<>(); |         List<String> lines = new ArrayList<>(); | ||||||
|         float width = 0; |         float width = 0; | ||||||
|         float height = 0; |         float height = 0; | ||||||
|  | @ -1497,7 +1509,8 @@ private void hideSysUI(){ | ||||||
|         if(mBookUtil.getPosition(chaptId)==0) { |         if(mBookUtil.getPosition(chaptId)==0) { | ||||||
|             lines.add("\n");//lines.add("\n"); |             lines.add("\n");//lines.add("\n"); | ||||||
|         } |         } | ||||||
|         calculateLineCount(); | 
 | ||||||
|  |         calculateLineCount(topAdHeight); | ||||||
|         while (mBookUtil.next(true,chaptId) != -1){ |         while (mBookUtil.next(true,chaptId) != -1){ | ||||||
|             char word = (char) mBookUtil.next(false,chaptId); |             char word = (char) mBookUtil.next(false,chaptId); | ||||||
|         //    Log.d(TAG, String.format(" loadchapt  getNextLines(), chaptId %s, word '%s'", chaptId,word  )); |         //    Log.d(TAG, String.format(" loadchapt  getNextLines(), chaptId %s, word '%s'", chaptId,word  )); | ||||||
|  | @ -1517,7 +1530,7 @@ private void hideSysUI(){ | ||||||
|                     line = ""; |                     line = ""; | ||||||
|                     width = 0; |                     width = 0; | ||||||
|                      height +=  paragraphSpace - lineSpace; |                      height +=  paragraphSpace - lineSpace; | ||||||
|                     calculateLineCount(height); |                     calculateLineCount(topAdHeight+height); | ||||||
|                     if (lines.size()>=   mLineCount +firstPageLine){ |                     if (lines.size()>=   mLineCount +firstPageLine){ | ||||||
|                      //  Log.d(TAG,String.format("lines count limit a %s,lines size %s",mLineCount,lines.size())); |                      //  Log.d(TAG,String.format("lines count limit a %s,lines size %s",mLineCount,lines.size())); | ||||||
|                         line =""; |                         line =""; | ||||||
|  | @ -1726,9 +1739,9 @@ private void hideSysUI(){ | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         Log.d(TAG, "currentPage onDraw: mBookPageWidget.getCurPage() "); |         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() "); |         Log.d(TAG, "currentPage onDraw: mBookPageWidget.getNextPage() "); | ||||||
|         onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),updateChapter,true); |         onDraw(mBookPageWidget.getNextPage(),currentPage ,updateChapter,true); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     //更新电量 |     //更新电量 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ public class TRPage { | ||||||
|     private boolean isLastPage; |     private boolean isLastPage; | ||||||
|     private boolean isFirstPage; |     private boolean isFirstPage; | ||||||
|     private List<String> lines = new ArrayList<>(); |     private List<String> lines = new ArrayList<>(); | ||||||
|  |     private int topBannerHeight=0; | ||||||
|     public TRPage( ){ |     public TRPage( ){ | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | @ -19,6 +20,13 @@ public class TRPage { | ||||||
|         lines.add(line); |         lines.add(line); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public int getTopBannerHeight() { | ||||||
|  |         return topBannerHeight; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setTopBannerHeight(int topBannerHeight) { | ||||||
|  |         this.topBannerHeight = topBannerHeight; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     public int getChapterNo() { |     public int getChapterNo() { | ||||||
|         return chapterNo; |         return chapterNo; | ||||||
|  |  | ||||||
|  | @ -75,7 +75,12 @@ | ||||||
| 
 | 
 | ||||||
|         </LinearLayout>--> |         </LinearLayout>--> | ||||||
| 
 | 
 | ||||||
| 
 |         <FrameLayout | ||||||
|  |             style="@style/frmBannerContainer" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:id="@+id/top_banner_container" | ||||||
|  |             android:visibility="gone" | ||||||
|  |             /> | ||||||
|         <FrameLayout |         <FrameLayout | ||||||
|         style="@style/frmBannerContainer" |         style="@style/frmBannerContainer" | ||||||
|         android:layout_height="wrap_content" |         android:layout_height="wrap_content" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue