adjust ad
This commit is contained in:
parent
bdd6eff8c1
commit
4ff9cc763a
|
@ -32,6 +32,7 @@ import com.bytedance.sdk.openadsdk.TTAdNative;
|
||||||
import com.bytedance.sdk.openadsdk.TTAppDownloadListener;
|
import com.bytedance.sdk.openadsdk.TTAppDownloadListener;
|
||||||
import com.bytedance.sdk.openadsdk.TTBannerAd;
|
import com.bytedance.sdk.openadsdk.TTBannerAd;
|
||||||
|
|
||||||
|
import com.bytedance.sdk.openadsdk.TTFeedAd;
|
||||||
import com.bytedance.sdk.openadsdk.TTImage;
|
import com.bytedance.sdk.openadsdk.TTImage;
|
||||||
import com.bytedance.sdk.openadsdk.TTInteractionAd;
|
import com.bytedance.sdk.openadsdk.TTInteractionAd;
|
||||||
import com.bytedance.sdk.openadsdk.TTNativeAd;
|
import com.bytedance.sdk.openadsdk.TTNativeAd;
|
||||||
|
@ -358,7 +359,7 @@ public abstract class Activity_base extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
//----toutiao ad ----
|
//----toutiao ad ----
|
||||||
boolean mShowAd =false;
|
// boolean mShowAd =false;
|
||||||
public void loadBannerAd(FrameLayout bannerContainer, String codeId, int width, int height) {
|
public void loadBannerAd(FrameLayout bannerContainer, String codeId, int width, int height) {
|
||||||
//step4:创建广告请求参数AdSlot,具体参数含义参考文档
|
//step4:创建广告请求参数AdSlot,具体参数含义参考文档
|
||||||
if(!Constants.SHOWAD || getTTAdNative()==null ){return;}
|
if(!Constants.SHOWAD || getTTAdNative()==null ){return;}
|
||||||
|
@ -624,7 +625,7 @@ public abstract class Activity_base extends AppCompatActivity {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nativeAd == null || !mShowAd) {
|
if (nativeAd == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
adCache.remove(i);
|
adCache.remove(i);
|
||||||
|
@ -893,4 +894,41 @@ public abstract class Activity_base extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载 toutiao feed广告
|
||||||
|
*/
|
||||||
|
public void loadListAd(BookListAdapter adapter, int adCnt, boolean addFooter) {
|
||||||
|
//feed广告请求类型参数
|
||||||
|
AdSlot adSlot = new AdSlot.Builder()
|
||||||
|
.setCodeId(BuildConfig.AD_SLOT_TOUTIAO_FEEDAD_ID)
|
||||||
|
.setSupportDeepLink(true)
|
||||||
|
.setImageAcceptedSize(228, 150)
|
||||||
|
.setAdCount(adCnt)
|
||||||
|
.build();
|
||||||
|
//调用feed广告异步请求接口
|
||||||
|
getAdNative().loadFeedAd(adSlot, new TTAdNative.FeedAdListener() {
|
||||||
|
@Override
|
||||||
|
public void onError(int code, String message) {
|
||||||
|
|
||||||
|
Log.e(TAG, String.format("loadListAd onError: code %s,msg %s",code,message) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFeedAdLoad(List<TTFeedAd> ads) {
|
||||||
|
// myAdapter.changeMoreStatus(2);
|
||||||
|
if (ads == null || ads.isEmpty()) {
|
||||||
|
Log.e(TAG, "on FeedAdLoaded: ad is null!" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(addFooter) {
|
||||||
|
adapter.AddFooterItem(ads);
|
||||||
|
}else{
|
||||||
|
adapter.AddHeaderItem(ads);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -128,6 +129,8 @@ public class BookActivity extends Activity_base {
|
||||||
@BindView(R.id.imageViewHead)
|
@BindView(R.id.imageViewHead)
|
||||||
ImageView imageViewHead;
|
ImageView imageViewHead;
|
||||||
|
|
||||||
|
@BindView(R.id.ll_others)
|
||||||
|
LinearLayout llAuthorMore;
|
||||||
@BindView(R.id.tvAuthorMore)
|
@BindView(R.id.tvAuthorMore)
|
||||||
TextView tvAuthorMore;
|
TextView tvAuthorMore;
|
||||||
@BindView(R.id.tvTonglei)
|
@BindView(R.id.tvTonglei)
|
||||||
|
@ -158,9 +161,9 @@ public class BookActivity extends Activity_base {
|
||||||
rvBooklistRelated.setVisibility(View.GONE);
|
rvBooklistRelated.setVisibility(View.GONE);
|
||||||
rvBooklistAuthor.setVisibility(View.GONE);
|
rvBooklistAuthor.setVisibility(View.GONE);
|
||||||
tvTonglei.setVisibility(View.GONE);
|
tvTonglei.setVisibility(View.GONE);
|
||||||
|
llAuthorMore. setVisibility(View.GONE);
|
||||||
tvAuthorMore.setText( "");
|
tvAuthorMore.setText( "");
|
||||||
initiDownloadReceiver();
|
initiDownloadReceiver();
|
||||||
mShowAd =Constants.SHOWAD;
|
|
||||||
if(Constants.SHOWAD){
|
if(Constants.SHOWAD){
|
||||||
loadNativeBannerAd(mBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID);
|
loadNativeBannerAd(mBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID);
|
||||||
mBannerContainer.setVisibility(View.VISIBLE);
|
mBannerContainer.setVisibility(View.VISIBLE);
|
||||||
|
@ -237,7 +240,7 @@ public class BookActivity extends Activity_base {
|
||||||
|
|
||||||
if(mDataAuthor!=null && mDataAuthor.size() >0){
|
if(mDataAuthor!=null && mDataAuthor.size() >0){
|
||||||
tvAuthorMore.setText(mNovel.getAuthor()+ " 还写过");
|
tvAuthorMore.setText(mNovel.getAuthor()+ " 还写过");
|
||||||
|
llAuthorMore .setVisibility(View.VISIBLE);
|
||||||
} else{
|
} else{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -248,6 +251,7 @@ public class BookActivity extends Activity_base {
|
||||||
rvBooklistAuthor.setLayoutManager(new LinearLayoutManager(this));
|
rvBooklistAuthor.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
|
||||||
rvBooklistAuthor.setAdapter(mAdapterAuthor);
|
rvBooklistAuthor.setAdapter(mAdapterAuthor);
|
||||||
|
loadListAd(mAdapterAuthor, 1 ,false);
|
||||||
|
|
||||||
}
|
}
|
||||||
private void setNovelsRelated(){
|
private void setNovelsRelated(){
|
||||||
|
@ -265,6 +269,9 @@ public class BookActivity extends Activity_base {
|
||||||
mAdapterRelated = getBookListAdapter(mDataRelated,R.layout.recycle_list_item_horizon);
|
mAdapterRelated = getBookListAdapter(mDataRelated,R.layout.recycle_list_item_horizon);
|
||||||
rvBooklistRelated.setLayoutManager(new LinearLayoutManager(this));
|
rvBooklistRelated.setLayoutManager(new LinearLayoutManager(this));
|
||||||
rvBooklistRelated.setAdapter(mAdapterRelated);
|
rvBooklistRelated.setAdapter(mAdapterRelated);
|
||||||
|
|
||||||
|
loadListAd(mAdapterRelated, 1 ,false);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 设置服务器传来的详细信息
|
* 设置服务器传来的详细信息
|
||||||
|
|
|
@ -45,6 +45,7 @@ import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.novelbook.android.AD.toutiao.TToast;
|
import com.novelbook.android.AD.toutiao.TToast;
|
||||||
import com.novelbook.android.Activity_base;
|
import com.novelbook.android.Activity_base;
|
||||||
|
import com.novelbook.android.Activity_base_ViewBinding;
|
||||||
import com.novelbook.android.Activity_paihangbang;
|
import com.novelbook.android.Activity_paihangbang;
|
||||||
import com.novelbook.android.Activity_shudan;
|
import com.novelbook.android.Activity_shudan;
|
||||||
import com.novelbook.android.BookActivity;
|
import com.novelbook.android.BookActivity;
|
||||||
|
@ -97,7 +98,7 @@ public abstract class BasicFragment extends Fragment {
|
||||||
protected Gson gson = new Gson();
|
protected Gson gson = new Gson();
|
||||||
// protected MyImageLoader imgloader = new MyImageLoader();
|
// protected MyImageLoader imgloader = new MyImageLoader();
|
||||||
// Main2Activity activity;
|
// Main2Activity activity;
|
||||||
FragmentActivity activity;
|
Activity_base activity;
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.swipeLayout)
|
@BindView(R.id.swipeLayout)
|
||||||
SwipeRefreshLayout mSwipeRefresh;
|
SwipeRefreshLayout mSwipeRefresh;
|
||||||
|
@ -118,7 +119,7 @@ public abstract class BasicFragment extends Fragment {
|
||||||
setFTag();
|
setFTag();
|
||||||
// Log.d(TAG,"fragment onCreate ");
|
// Log.d(TAG,"fragment onCreate ");
|
||||||
// activity =(Main2Activity)getActivity();
|
// activity =(Main2Activity)getActivity();
|
||||||
activity = getActivity();
|
activity = (Activity_base)getActivity();
|
||||||
processArguments();
|
processArguments();
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +142,7 @@ public abstract class BasicFragment extends Fragment {
|
||||||
initData();
|
initData();
|
||||||
initViews();
|
initViews();
|
||||||
initSwipeRefreshLayout();
|
initSwipeRefreshLayout();
|
||||||
showBanner(mBannerContainer,(int) getResources().getDimension(R.dimen.topBannerHeight) );
|
|
||||||
return view;
|
return view;
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
|
|
||||||
|
@ -427,6 +428,7 @@ void initTabs(){
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
error_try=0;
|
error_try=0;
|
||||||
|
showBanner(mBannerContainer,(int) getResources().getDimension(R.dimen.topBannerHeight) );
|
||||||
// MobclickAgent.onPageStart(TAG);
|
// MobclickAgent.onPageStart(TAG);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -449,16 +451,17 @@ void initTabs(){
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------toutiao ad------
|
//---------toutiao ad------
|
||||||
public void showBanner(FrameLayout bannerContainer , int adHeight ) {
|
public void showBanner( FrameLayout bannerContainer , int adHeight ) {
|
||||||
if(bannerContainer==null){
|
if(bannerContainer==null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bannerContainer.setVisibility(View.GONE);
|
// bannerContainer.setVisibility(View.GONE);
|
||||||
if (!Constants.SHOWAD) {
|
if (!Constants.SHOWAD) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((Main2Activity) activity).loadBannerAd(bannerContainer, BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID,600, adHeight);
|
activity .loadBannerAd(bannerContainer, BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID,(int)(adHeight*5.9), adHeight);
|
||||||
|
if( mBannerContainer.getVisibility() !=View.VISIBLE)
|
||||||
mBannerContainer.setVisibility(View.VISIBLE);
|
mBannerContainer.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,36 +469,6 @@ void initTabs(){
|
||||||
* 加载 toutiao feed广告
|
* 加载 toutiao feed广告
|
||||||
*/
|
*/
|
||||||
void loadListAd( BookListAdapter adapter, int adCnt, boolean addFooter) {
|
void loadListAd( BookListAdapter adapter, int adCnt, boolean addFooter) {
|
||||||
//feed广告请求类型参数
|
activity.loadListAd(adapter, adCnt ,addFooter);
|
||||||
AdSlot adSlot = new AdSlot.Builder()
|
|
||||||
.setCodeId(BuildConfig.AD_SLOT_TOUTIAO_FEEDAD_ID)
|
|
||||||
.setSupportDeepLink(true)
|
|
||||||
.setImageAcceptedSize(228, 150)
|
|
||||||
.setAdCount(adCnt)
|
|
||||||
.build();
|
|
||||||
//调用feed广告异步请求接口
|
|
||||||
((Activity_base)getActivity()).getAdNative().loadFeedAd(adSlot, new TTAdNative.FeedAdListener() {
|
|
||||||
@Override
|
|
||||||
public void onError(int code, String message) {
|
|
||||||
|
|
||||||
Log.e(TAG, String.format("loadListAd onError: code %s,msg %s",code,message) );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFeedAdLoad(List<TTFeedAd> ads) {
|
|
||||||
// myAdapter.changeMoreStatus(2);
|
|
||||||
if (ads == null || ads.isEmpty()) {
|
|
||||||
Log.e(TAG, "on FeedAdLoaded: ad is null!" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(addFooter) {
|
|
||||||
adapter.AddFooterItem(ads);
|
|
||||||
}else{
|
|
||||||
adapter.AddHeaderItem(ads);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class Fragment_booklist extends BasicFragment {
|
||||||
keyWord =bundle.getString(EXTR_SEARCH);
|
keyWord =bundle.getString(EXTR_SEARCH);
|
||||||
history =bundle.getString(EXTR_HISTORY);
|
history =bundle.getString(EXTR_HISTORY);
|
||||||
if(!TextUtils.isEmpty(history)){
|
if(!TextUtils.isEmpty(history)){
|
||||||
listItem = listItem =R.layout.recycle_list_item_history;
|
listItem =R.layout.recycle_list_item_history;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -376,6 +376,9 @@ public class Fragment_booklist extends BasicFragment {
|
||||||
mMoreData = Novel.getNovelsHistory();
|
mMoreData = Novel.getNovelsHistory();
|
||||||
pageCount=1;
|
pageCount=1;
|
||||||
handler.sendEmptyMessage(1);
|
handler.sendEmptyMessage(1);
|
||||||
|
if(mMoreData!=null && mMoreData.size()>2) {
|
||||||
|
loadListAd(mAdapter, 2, mData.size() > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -787,7 +787,7 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
||||||
Intent intent = new Intent(context, ReadActivity.class);
|
Intent intent = new Intent(context, ReadActivity.class);
|
||||||
intent.putExtra(EXTRA_BOOK, book);
|
intent.putExtra(EXTRA_BOOK, book);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
context.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
|
//context.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -884,8 +884,8 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
||||||
rl_bottom.setVisibility(View.VISIBLE);
|
rl_bottom.setVisibility(View.VISIBLE);
|
||||||
appbar.setVisibility(View.VISIBLE);
|
appbar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
tvUrl.setVisibility(View.VISIBLE);
|
/* tvUrl.setVisibility(View.VISIBLE);
|
||||||
tvUrl.setText("abcd+" + pageFactory.getChapter().getChapterUrl());
|
tvUrl.setText("abcd+" + pageFactory.getChapter().getChapterUrl());*/
|
||||||
|
|
||||||
if(pageFactory.getChapter()!=null && !TextUtils.isEmpty(pageFactory.getChapter().getChapterUrl())) {
|
if(pageFactory.getChapter()!=null && !TextUtils.isEmpty(pageFactory.getChapter().getChapterUrl())) {
|
||||||
tvUrl.setVisibility(View.VISIBLE);
|
tvUrl.setVisibility(View.VISIBLE);
|
||||||
|
@ -1129,7 +1129,7 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d(TAG, String.format("loadBannerAd:showNativeBannerInLines width %s, adY %s ",Constants.SCREEN_WIDTH_PIX-50, adY/Constants.ONE_DP_SIZE ));
|
Log.d(TAG, String.format("loadBannerAd:showNativeBannerInLines width %s, adY %s ",Constants.SCREEN_WIDTH_PIX-50, adY/Constants.ONE_DP_SIZE ));
|
||||||
if( adY >400*Constants.ONE_DP_SIZE){
|
if( adY >390*Constants.ONE_DP_SIZE){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d(TAG, String.format("loadBannerAd:showNativeBannerInLines width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,height,adY));
|
Log.d(TAG, String.format("loadBannerAd:showNativeBannerInLines width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,height,adY));
|
||||||
|
@ -1169,10 +1169,10 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
||||||
final int contentAdHight=80;
|
final int contentAdHight=80;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showStatusAd(boolean showAd ,int adHeight,int adY) {
|
public void showStatusAd(int adHeight,int adY) {
|
||||||
|
|
||||||
// hideSystemUI();
|
// hideSystemUI();
|
||||||
mShowAd =showAd;
|
// mShowAd =showAd;
|
||||||
// mBannerContainer.setVisibility(View.GONE);
|
// mBannerContainer.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1181,10 +1181,6 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!showAd){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s,showAd %s",Constants.SCREEN_WIDTH_PIX-50,adHeight/Constants.ONE_DP_SIZE,adY/Constants.ONE_DP_SIZE, showAd));
|
// Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s,showAd %s",Constants.SCREEN_WIDTH_PIX-50,adHeight/Constants.ONE_DP_SIZE,adY/Constants.ONE_DP_SIZE, showAd));
|
||||||
|
|
||||||
|
|
||||||
|
@ -1196,8 +1192,8 @@ 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));
|
// Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY));
|
||||||
|
|
||||||
if(adHeight>150*Constants.ONE_DP_SIZE && adY <400*Constants.ONE_DP_SIZE){
|
if(adHeight>150*Constants.ONE_DP_SIZE && adY <400*Constants.ONE_DP_SIZE){
|
||||||
Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s,showAd %s",Constants.SCREEN_WIDTH_PIX-50,adHeight/Constants.ONE_DP_SIZE,adY/Constants.ONE_DP_SIZE, showAd));
|
Log.d(TAG, String.format("loadBannerAd:width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight/Constants.ONE_DP_SIZE,adY/Constants.ONE_DP_SIZE ));
|
||||||
// hideAdSlot(mNative_banner_container);
|
hideAdSlot(mNative_banner_container_in_lines);
|
||||||
// hideAdSlot(mTopBannerContainer);
|
// hideAdSlot(mTopBannerContainer);
|
||||||
|
|
||||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mNative_status_banner_container.getLayoutParams();
|
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mNative_status_banner_container.getLayoutParams();
|
||||||
|
|
|
@ -6,7 +6,7 @@ public interface AdInterface {
|
||||||
* @param height
|
* @param height
|
||||||
* @param adY
|
* @param adY
|
||||||
*/
|
*/
|
||||||
public void showStatusAd(boolean showAd,int height,int adY);
|
public void showStatusAd(int height,int adY);
|
||||||
public void showTopBanner(int height,int adY);
|
public void showTopBanner(int height,int adY);
|
||||||
public void showNativeBannerInLines(int height,int adY);
|
public void showNativeBannerInLines(int height,int adY);
|
||||||
public void hideSystemUI();
|
public void hideSystemUI();
|
||||||
|
|
|
@ -47,4 +47,5 @@ public class Constants {
|
||||||
public static int version =0;
|
public static int version =0;
|
||||||
public static int serverVersion =0;
|
public static int serverVersion =0;
|
||||||
public static String updateUrl="http://xiaoshuofenxiang.com/version.xml";;
|
public static String updateUrl="http://xiaoshuofenxiang.com/version.xml";;
|
||||||
|
public static final String BAD_CHAR =" ";
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
public class PageFactory implements ChangeSource{
|
public class PageFactory implements ChangeSource{
|
||||||
private static final String TAG = "PageFactory";
|
private static final String TAG = "PageFactory";
|
||||||
private static PageFactory pageFactory;
|
private static PageFactory pageFactory;
|
||||||
|
private float mBannerNaviHeight;
|
||||||
|
private float mBannerTopHeight;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Config config;
|
private Config config;
|
||||||
//当前的书本
|
//当前的书本
|
||||||
|
@ -506,28 +507,28 @@ public class PageFactory implements ChangeSource{
|
||||||
|
|
||||||
TRPage trPage = new TRPage();
|
TRPage trPage = new TRPage();
|
||||||
totalPageCnt++;
|
totalPageCnt++;
|
||||||
float bannerH = 0;
|
|
||||||
// Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT = 4;
|
// Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT = 4;
|
||||||
if (Constants.SHOWAD && pageNo > 1) {
|
if (Constants.SHOWAD && pageNo > 1) {
|
||||||
// Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT = 1;
|
// Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT = 1;
|
||||||
|
|
||||||
if (Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT > 0 && totalPageCnt % Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT == 0) {
|
if (Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT > 0 && totalPageCnt % Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT == 0) {
|
||||||
bannerH = mContext.getResources().getDimension(R.dimen.nativeBannerHeight) + 4 * Constants.ONE_DP_SIZE;
|
|
||||||
calculateLineCount();
|
calculateLineCount();
|
||||||
int adLines = (int) (bannerH / ((m_fontSize + lineSpace)));
|
int adLines = (int) (mBannerNaviHeight / ((m_fontSize + lineSpace)));
|
||||||
|
|
||||||
int adLine = new Random().nextInt(mLineCount - adLines - 1);
|
int adLine = new Random().nextInt(mLineCount - adLines - 1);
|
||||||
adLine = adLine < mLineCount ? adLine : mLineCount - 2;
|
adLine = adLine < mLineCount ? adLine : mLineCount - 2;
|
||||||
if (adLine > 0) {
|
if (adLine > 0) {
|
||||||
trPage.setNativeBannerStartLine(adLine);
|
trPage.setNativeBannerStartLine(adLine);
|
||||||
//trPage.setNativeBannerHeight(Constants.AD_CHAPT_NATIVE_BANNER_HEIGHT);
|
//trPage.setNativeBannerHeight(Constants.AD_CHAPT_NATIVE_BANNER_HEIGHT);
|
||||||
trPage.setNativeBannerHeight((int) bannerH);
|
trPage.setNativeBannerHeight((int) mBannerNaviHeight);
|
||||||
}
|
}
|
||||||
Log.d(TAG, String.format("getNextChapterPage: pageNo %s, topBannerHeight %s, adLines %s,adLine %s, nativeBannerHeight %s",
|
Log.d(TAG, String.format("getNextChapterPage: pageNo %s, topBannerHeight %s, adLines %s,adLine %s, nativeBannerHeight %s",
|
||||||
pageNo, trPage.getTopBannerHeight(), adLines, adLine, trPage.getNativeBannerHeight()));
|
pageNo, trPage.getTopBannerHeight(), adLines, adLine, trPage.getNativeBannerHeight()));
|
||||||
} else if (Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT > 0 && totalPageCnt % Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT == 0) {
|
} else if (Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT > 0 && totalPageCnt % Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT == 0) {
|
||||||
bannerH = mContext.getResources().getDimension(R.dimen.topBannerHeight) + 0 * Constants.ONE_DP_SIZE;
|
|
||||||
trPage.setTopBannerHeight((int) bannerH);
|
trPage.setTopBannerHeight((int) mBannerTopHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trPage.setPageNo(pageNo);
|
trPage.setPageNo(pageNo);
|
||||||
|
@ -688,7 +689,8 @@ private void hideSysUI(){
|
||||||
sdf = new SimpleDateFormat("HH:mm");//HH:mm为24小时制,hh:mm为12小时制
|
sdf = new SimpleDateFormat("HH:mm");//HH:mm为24小时制,hh:mm为12小时制
|
||||||
date = sdf.format(new java.util.Date());
|
date = sdf.format(new java.util.Date());
|
||||||
df = new DecimalFormat("#0.0");
|
df = new DecimalFormat("#0.0");
|
||||||
|
mBannerNaviHeight = mContext.getResources().getDimension(R.dimen.nativeBannerHeight) + 4 * Constants.ONE_DP_SIZE;
|
||||||
|
mBannerTopHeight = mContext.getResources().getDimension(R.dimen.topBannerHeight) + 0 * Constants.ONE_DP_SIZE;
|
||||||
marginWidth = mContext.getResources().getDimension(R.dimen.readingMarginWidth);
|
marginWidth = mContext.getResources().getDimension(R.dimen.readingMarginWidth);
|
||||||
marginHeight = mContext.getResources().getDimension(R.dimen.readingMarginHeight);
|
marginHeight = mContext.getResources().getDimension(R.dimen.readingMarginHeight);
|
||||||
// Log.d(TAG, "getNavigationBarSize: orignal marginHeight +" +marginHeight);
|
// Log.d(TAG, "getNavigationBarSize: orignal marginHeight +" +marginHeight);
|
||||||
|
@ -1046,19 +1048,27 @@ private void hideSysUI(){
|
||||||
float space =m_fontSize + lineSpace;
|
float space =m_fontSize + lineSpace;
|
||||||
paragraphSpace = prate * lineSpace;
|
paragraphSpace = prate * lineSpace;
|
||||||
|
|
||||||
|
// if(showAd && mAd!=null){
|
||||||
if(showAd && mAd!=null){
|
|
||||||
mAdHeight=trPage.getTopBannerHeight();
|
mAdHeight=trPage.getTopBannerHeight();
|
||||||
mAdY=(int)marginHeight;
|
mAdY=(int)marginHeight;
|
||||||
mAdType =AdTpye.TOPBANNER;
|
mAdType =AdTpye.TOPBANNER;
|
||||||
|
|
||||||
// mAd.showTopBanner(trPage.getTopBannerHeight(),(int)(marginHeight));
|
// mAd.showTopBanner(trPage.getTopBannerHeight(),(int)(marginHeight));
|
||||||
// mAd.showNativeBannerInLines(0,0);
|
// mAd.showNativeBannerInLines(0,0);
|
||||||
}
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
/* if(trPage.getPageNo()>1 && m_lines.size() <= mLineCount/2+1){
|
||||||
|
if(trPage.getTopBannerHeight() + trPage.getNativeBannerHeight() ==0){
|
||||||
|
mAdHeight=(int)mBannerNaviHeight;
|
||||||
|
mAdY=(int)marginHeight;
|
||||||
|
mAdType =AdTpye.NATIVEINLINES;
|
||||||
|
|
||||||
|
}
|
||||||
|
}*/
|
||||||
if (m_lines.size() > 0) {
|
if (m_lines.size() > 0) {
|
||||||
|
|
||||||
float y = marginHeight +(trPage.getTopBannerHeight() >0 ? trPage.getTopBannerHeight() :0);
|
float y = marginHeight +mAdHeight;
|
||||||
String lastLine ="";
|
String lastLine ="";
|
||||||
int lineNo =0;
|
int lineNo =0;
|
||||||
for (String strLine : m_lines) {
|
for (String strLine : m_lines) {
|
||||||
|
@ -1068,15 +1078,16 @@ private void hideSysUI(){
|
||||||
// Log.d(TAG, strLine);
|
// Log.d(TAG, strLine);
|
||||||
// Log.d(TAG,"最后字符 。。。" +strLine.charAt(strLine.length()-1) + "");
|
// Log.d(TAG,"最后字符 。。。" +strLine.charAt(strLine.length()-1) + "");
|
||||||
lastLine =strLine;
|
lastLine =strLine;
|
||||||
|
strLine = strLine.replace("<EFBFBD>","");
|
||||||
|
|
||||||
if(lineNo==trPage.getNativeBannerStartLine()){
|
if(lineNo==trPage.getNativeBannerStartLine()){
|
||||||
if(showAd && mAd!=null){
|
if(showAd && mAd!=null){
|
||||||
mAdHeight=trPage.getNativeBannerHeight();
|
mAdHeight=trPage.getNativeBannerHeight();
|
||||||
mAdY=(int)y;
|
mAdY=(int)y +(int)( +lineSpace*0.5);
|
||||||
mAdType =AdTpye.NATIVEINLINES;
|
mAdType =AdTpye.NATIVEINLINES;
|
||||||
// mAd.showNativeBannerInLines(trPage.getNativeBannerHeight(),(int)y);
|
// mAd.showNativeBannerInLines(trPage.getNativeBannerHeight(),(int)y);
|
||||||
}
|
}
|
||||||
y+=trPage.getNativeBannerHeight() +m_fontSize*1.1;
|
y+=trPage.getNativeBannerHeight() +m_fontSize +lineSpace ;
|
||||||
Log.d(TAG, String.format("onDraw showNativeBannerInLines : lineno %s,strline %s ",lineNo,strLine));
|
Log.d(TAG, String.format("onDraw showNativeBannerInLines : lineno %s,strline %s ",lineNo,strLine));
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
|
@ -1101,11 +1112,13 @@ private void hideSysUI(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log.d(TAG,String.format("getNavigationBarSize mHeight is %s ,last line height %s, power %s, %s",
|
// Log.d(TAG,String.format("getNavigationBarSize mHeight is %s ,last line height %s, power %s, %s", //
|
||||||
// mHeight,y,mHeight - CommonUtil.convertDpToPixel(mContext,10) + mBorderWidth - statusMarginBottom, lastLine));
|
// mHeight,y,mHeight - CommonUtil.convertDpToPixel(mContext,10) + mBorderWidth - statusMarginBottom, lastLine));
|
||||||
|
// lastLine =lastLine.trim().replace(Constants.BAD_CHAR,"");
|
||||||
|
Log.d(TAG, String.format("onDraw: last line lenth %s,%s, ",lastLine.length() ,lastLine));
|
||||||
float adHeight = mHeight -y - space -marginHeight-statusMarginBottom;
|
float adHeight = mHeight -y - space -marginHeight-statusMarginBottom;
|
||||||
float adY =y +space;
|
float adY =y ;//+space;
|
||||||
|
adY= lastLine.length()==0 ?adY-m_fontSize - lineSpace :adY;
|
||||||
if(mAdHeight ==0 && showAd ) {
|
if(mAdHeight ==0 && showAd ) {
|
||||||
mAdY=(int)adY;
|
mAdY=(int)adY;
|
||||||
mAdHeight =(int) adHeight;
|
mAdHeight =(int) adHeight;
|
||||||
|
@ -1201,6 +1214,9 @@ private void hideSysUI(){
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAd(){
|
public void showAd(){
|
||||||
|
if(mStatus == Status.LASTPAGE){
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log.d(TAG, String.format("loadBannerAd showAd: mAdType %s",mAdType));
|
Log.d(TAG, String.format("loadBannerAd showAd: mAdType %s",mAdType));
|
||||||
if(mAdType ==AdTpye.TOPBANNER){
|
if(mAdType ==AdTpye.TOPBANNER){
|
||||||
mAd.showTopBanner(mAdHeight,mAdY);
|
mAd.showTopBanner(mAdHeight,mAdY);
|
||||||
|
@ -1216,8 +1232,8 @@ private void hideSysUI(){
|
||||||
boolean showAd = showingStatusAd || getCurrentPage()==null || getCurrentPage().getPageNo() > 1;
|
boolean showAd = showingStatusAd || getCurrentPage()==null || getCurrentPage().getPageNo() > 1;
|
||||||
|
|
||||||
// boolean showAd =true;
|
// boolean showAd =true;
|
||||||
if (mAd != null) {
|
if (showAd && mAd != null) {
|
||||||
mAd.showStatusAd(showAd,adHeight, adY);
|
mAd.showStatusAd(adHeight, adY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1610,6 +1626,9 @@ private void hideSysUI(){
|
||||||
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 ));
|
||||||
|
if((word+"").equals(Constants.BAD_CHAR)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//判断是否换行
|
//判断是否换行
|
||||||
if ((word + "" ).equals("\n") ){// if ((word + "" ).equals("\r") && (((char) mBookUtil.next(true)) + "").equals("\n")){
|
if ((word + "" ).equals("\n") ){// if ((word + "" ).equals("\r") && (((char) mBookUtil.next(true)) + "").equals("\n")){
|
||||||
// mBookUtil.next(false);
|
// mBookUtil.next(false);
|
||||||
|
@ -1635,9 +1654,15 @@ private void hideSysUI(){
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
float widthChar = mPaint.measureText(word + "");
|
float widthChar = mPaint.measureText(word + "");
|
||||||
|
|
||||||
|
if(widthChar==0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
width += widthChar;
|
width += widthChar;
|
||||||
// Log.d(TAG, String.format(" loadchapt getNextLines(),widthChar %s ,width %s,mVisibleWidth %s",widthChar, width ,mVisibleWidth ));
|
// Log.d(TAG, String.format(" loadchapt getNextLines(),widthChar %s ,width %s,mVisibleWidth %s",widthChar, width ,mVisibleWidth ));
|
||||||
|
|
||||||
|
|
||||||
if (width > mVisibleWidth) {
|
if (width > mVisibleWidth) {
|
||||||
width = widthChar;
|
width = widthChar;
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
app:search_baground="@drawable/search_baground_shap"
|
app:search_baground="@drawable/search_baground_shap"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_weight="0"
|
|
||||||
android:gravity="bottom"
|
|
||||||
style="@style/frmBannerContainer"
|
|
||||||
android:layout_height="400dp"
|
|
||||||
android:id="@+id/banner_container"/>
|
|
||||||
<LinearLayout style="@style/llGraySplit" />
|
<LinearLayout style="@style/llGraySplit" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/banner_container"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -208,10 +208,12 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
android:layout_marginTop="1dp"
|
||||||
|
android:layout_marginBottom="1dp"
|
||||||
style="@style/frmBannerContainer"
|
style="@style/frmBannerContainer"
|
||||||
android:layout_height="310dp"
|
android:layout_height="@dimen/nativeBannerHeight"
|
||||||
android:id="@+id/banner_container"/>
|
android:id="@+id/banner_container"/>
|
||||||
<LinearLayout style="@style/llGraySplit" />
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -267,10 +269,11 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_others"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
<LinearLayout style="@style/llGraySplit" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvAuthorMore"
|
android:id="@+id/tvAuthorMore"
|
||||||
style="@style/NovelBlockTitle"
|
style="@style/NovelBlockTitle"
|
||||||
|
|
|
@ -456,7 +456,7 @@
|
||||||
<item name="android:layout_centerInParent">true</item>
|
<item name="android:layout_centerInParent">true</item>
|
||||||
<!--<item name="android:background">@color/mintcream</item>-->
|
<!--<item name="android:background">@color/mintcream</item>-->
|
||||||
<item name="android:background">@color/transparent</item>
|
<item name="android:background">@color/transparent</item>
|
||||||
<item name="android:visibility">gone</item>
|
<item name="android:visibility">visible</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue