adjust ad

This commit is contained in:
mwang 2019-06-13 00:37:00 +08:00
parent 7d2a6467db
commit a06e45c303
23 changed files with 962 additions and 456 deletions

View File

@ -13,7 +13,8 @@ android {
compileSdkVersion 28 compileSdkVersion 28
buildToolsVersion "28.0.3" buildToolsVersion "28.0.3"
defaultConfig { defaultConfig {
applicationId "com.qq.e.union.demo" // applicationId "com.qq.e.union.demo"
applicationId "com.novelbook.android"
minSdkVersion 19 //target 19 Android 4.4 4.1% minSdkVersion 19 //target 19 Android 4.4 4.1%
targetSdkVersion 28 targetSdkVersion 28
versionCode 5 versionCode 5
@ -39,12 +40,12 @@ android {
buildConfigField "boolean", "LOG_DEBUG", "true" buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' buildConfigField "String", "MAIN_HOST", '"http://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", '"{\\"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","AD_TOUTIAO_APP_ID",'"5019267"' /* buildConfigField "String","AD_TOUTIAO_APP_ID",'"5019267"'
buildConfigField "String","AD_SLOT_TOUTIAO_FEEDAD_ID",'"919267464"' buildConfigField "String","AD_SLOT_TOUTIAO_FEEDAD_ID",'"919267464"'
buildConfigField "String","AD_SLOT_TOUTIAO_SPLASH_ID",'"819267134"' buildConfigField "String","AD_SLOT_TOUTIAO_SPLASH_ID",'"819267134"'
buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_ID",'"919267016"' buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_ID",'"919267016"'
buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_NATIVE_ID",'"919267816"' buildConfigField "String","AD_SLOT_TOUTIAO_BANNER_NATIVE_ID",'"919267816"'
buildConfigField "String","AD_SLOT_TOUTIAO_INTERACTION_ID",'"919267451"' buildConfigField "String","AD_SLOT_TOUTIAO_INTERACTION_ID",'"919267451"'*/
// buildConfigField "String", "API_HOST", '""' // buildConfigField "String", "API_HOST", '""'
versionNameSuffix "-debug" versionNameSuffix "-debug"
minifyEnabled false minifyEnabled false

View File

@ -66,10 +66,18 @@
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/ToolBarTheme.NoActionBar"> android:theme="@style/ToolBarTheme.NoActionBar">
</activity>
<activity
android:name=".AD.SplashActivity"
android:configChanges="keyboard|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/Theme.Splash">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".FileActivity" android:name=".FileActivity"
@ -147,7 +155,7 @@
</provider> <!-- qq ad end --> </provider> <!-- qq ad end -->
<!-- chuanshanjia ad --> <!-- chuanshanjia ad -->
<activity <!--<activity
android:name=".AD.toutiao.SplashActivity" android:name=".AD.toutiao.SplashActivity"
android:configChanges="keyboard|orientation|screenSize" android:configChanges="keyboard|orientation|screenSize"
android:screenOrientation="portrait" android:screenOrientation="portrait"
@ -155,7 +163,7 @@
</activity> </activity>
-->
<uses-library <uses-library
android:name="org.apache.http.legacy" android:name="org.apache.http.legacy"
android:required="false" /> android:required="false" />

View File

@ -0,0 +1,487 @@
package com.novelbook.android.AD;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTSplashAd;
import com.novelbook.android.AD.toutiao.TTAdManagerHolder;
import com.novelbook.android.AD.toutiao.WeakHandler;
import com.novelbook.android.BuildConfig;
import com.novelbook.android.Main2Activity;
import com.novelbook.android.R;
import com.novelbook.android.utils.Constants;
import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener;
import com.qq.e.comm.util.AdError;
import org.litepal.util.Const;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.novelbook.android.utils.AdUtil.getAppID;
/**
* 开屏广告Activity示例
*/
public class SplashActivity extends Activity implements WeakHandler.IHandler, SplashADListener {
private static final String TAG = SplashActivity.class.getSimpleName();
@BindView(R.id.splash_container)
ViewGroup mSplashContainer;
//--------tencent--->
private SplashAD splashAD;
@Nullable
@BindView(R.id.skip_view)
TextView skipView;
//private ImageView splashHolder;
@Nullable
@BindView(R.id.splash_holder)
TextView splashHolder;
private static final String SKIP_TEXT = "点击跳过 %d";
public boolean canJump = false;
/**
* 为防止无广告时造成视觉上类似于"闪退"的情况设定无广告时页面跳转根据需要延迟一定时间demo
* 给出的延时逻辑是从拉取广告开始算开屏最少持续多久仅供参考开发者可自定义延时逻辑如果开发者采用demo
* 中给出的延时逻辑也建议开发者考虑自定义minSplashTimeWhenNoAD的值单位ms
**/
private int minSplashTimeWhenNoAD = 2000;
/**
* 记录拉取广告的时间
*/
private long fetchSplashADTime = 0;
private Handler handler = new Handler(Looper.getMainLooper());
//<-----tencent-----
//------toutiao--->
private TTAdNative mTTAdNative;
//是否强制跳转到主页面
private boolean mForceGoMain;
public static final String EXTR_LUNCHER="luncher";
//开屏广告加载发生超时但是SDK没有及时回调结果的时候做的一层保护
private final WeakHandler mHandler = new WeakHandler(this);
//开屏广告加载超时时间,建议大于1000,这里为了冷启动第一次加载到广告并且展示,示例设置了2000ms
private static final int AD_TIME_OUT = 2000;
private static final int MSG_GO_MAIN = 1;
//开屏广告是否已经加载
private boolean mHasLoaded;
//-toutiao---<---
@BindView(R.id.textTile)
TextView tvTitle;
@SuppressWarnings("RedundantCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!Constants.AD_SETTING.isShowAdsense() ||!Constants.AD_SETTING.getSplash().isShow() ){
goToMainActivity();
return;
}
int rid =R.layout.ad_toutiao_activity_splash;
if(Constants.AD_SETTING.getSplash().getSource() == Constants.AD_TENCENT_QQ ){
rid = R.layout.ad_qq_activity_splash;
}else if(Constants.AD_SETTING.getSplash().getSource() == Constants.AD_TOUTIAO ){
rid = R.layout.ad_toutiao_activity_splash;
}
setContentView(rid);
ButterKnife.bind(this);
//在合适的时机申请权限如read_phone_state,防止获取不了imei时候下载类广告没有填充的问题
//在开屏时候申请不太合适因为该页面倒计时结束或者请求超时会跳转在该页面申请权限体验不好
// TTAdManagerHolder.getInstance(this).requestPermissionIfNecessary(this);
//定时AD_TIME_OUT时间到时执行如果开屏广告没有加载则跳转到主页面
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// | View.SYSTEM_UI_FLAG_IMMERSIVE
);
tvTitle.setText(R.string.app_name);
//加载开屏广告
if(Constants.AD_SETTING.getSplash().getSource() == Constants.AD_TOUTIAO ) {
mHandler.sendEmptyMessageDelayed(MSG_GO_MAIN, AD_TIME_OUT);
//step2:创建TTAdNative对象
try {
mTTAdNative = TTAdManagerHolder.get().createAdNative(this);
} catch (Exception e) {
goToMainActivity();
return;
}
loadSplashAd();
}else if(Constants.AD_SETTING.getSplash().getSource() == Constants.AD_TENCENT_QQ ){
if (Build.VERSION.SDK_INT >= 23) {
checkAndRequestPermission();
} else {
// 如果是Android6.0以下的机器默认在安装时获得了所有权限可以直接调用SDK
fetchSplashAD(this, mSplashContainer, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
}
}
}
/**
* 跳转到主页面
*/
private void goToMainActivity() {
boolean isGoToMain= getIntent().getBooleanExtra(EXTR_LUNCHER,true);
if(isGoToMain) {
Intent intent = new Intent(SplashActivity.this, Main2Activity.class);
startActivity(intent);
}
if(mSplashContainer!=null) {
mSplashContainer.removeAllViews();
}
SplashAdManager.clearPages();
this.finish();
}
@Override
protected void onResume() {
//判断是否该跳转到主页面
if (mForceGoMain) {
mHandler.removeCallbacksAndMessages(null);
goToMainActivity();
}
super.onResume();
if (canJump) {
next();
}
canJump = true;
}
@Override
protected void onStop() {
super.onStop();
mForceGoMain = true;
}
@Override
protected void onPause() {
super.onPause();
canJump = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacksAndMessages(null);
}
/**
* 加载开屏广告
*/
private void loadSplashAd() {
//step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(Constants.AD_SETTING.getSplash().getSlotId(Constants.AD_TOUTIAO) )
.setSupportDeepLink(true)
.setImageAcceptedSize(Constants.SCREEN_WIDTH_PIX, Constants.SCREEN_HEIGHT_PIX)
.build();
//step4:请求广告调用开屏广告异步请求接口对请求回调的广告作渲染处理
mTTAdNative.loadSplashAd(adSlot, new TTAdNative.SplashAdListener() {
@Override
@MainThread
public void onError(int code, String message) {
Log.d(TAG, message);
mHasLoaded = true;
showToast(message);
goToMainActivity();
}
@Override
@MainThread
public void onTimeout() {
mHasLoaded = true;
showToast("开屏广告加载超时");
goToMainActivity();
}
@Override
@MainThread
public void onSplashAdLoad(TTSplashAd ad) {
Log.d(TAG, "开屏广告请求成功");
SplashAdManager.setSplashTime();
mHasLoaded = true;
mHandler.removeCallbacksAndMessages(null);
if (ad == null) {
return;
}
//获取SplashView
View view = ad.getSplashView();
mSplashContainer.removeAllViews();
//把SplashView 添加到ViewGroup中,注意开屏广告viewwidth >=70%屏幕宽height >=50%屏幕宽
mSplashContainer.addView(view);
//设置不开启开屏广告倒计时功能以及不显示跳过按钮,如果这么设置您需要自定义倒计时逻辑
//ad.setNotAllowSdkCountdown();
//设置SplashView的交互监听器
ad.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
@Override
public void onAdClicked(View view, int type) {
Log.d(TAG, "onAdClicked");
showToast("开屏广告点击");
}
@Override
public void onAdShow(View view, int type) {
Log.d(TAG, "onAdShow");
showToast("开屏广告展示");
}
@Override
public void onAdSkip() {
Log.d(TAG, "onAdSkip");
showToast("开屏广告跳过");
goToMainActivity();
}
@Override
public void onAdTimeOver() {
Log.d(TAG, "onAdTimeOver");
showToast("开屏广告倒计时结束");
goToMainActivity();
}
});
}
}, AD_TIME_OUT);
}
private void showToast(String msg) {
//TToast.show(this, msg);
Log.d(TAG, "loadBannerAd: " + msg);
}
@Override
public void handleMsg(Message msg) {
if (msg.what == MSG_GO_MAIN) {
if (!mHasLoaded) {
showToast("广告已超时,跳到主页面");
goToMainActivity();
}
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK|| keyCode == KeyEvent.KEYCODE_HOME) {
return true;
}
return super.onKeyUp(keyCode,event);
}
//-----qq ad begin------>
/**
*
* ----------非常重要----------
*
* Android6.0以上的权限适配简单示例
*
* 如果targetSDKVersion >= 23那么必须要申请到所需要的权限再调用广点通SDK否则广点通SDK不会工作
*
* Demo代码里是一个基本的权限申请示例请开发者根据自己的场景合理地编写这部分代码来实现权限申请
* 注意下面的`checkSelfPermission``requestPermissions`方法都是在Android6.0的SDK中增加的API如果您的App还没有适配到Android6.0以上则不需要调用这些方法直接调用广点通SDK即可
*/
@TargetApi(Build.VERSION_CODES.M)
private void checkAndRequestPermission() {
List<String> lackedPermission = new ArrayList<String>();
if (!(checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.READ_PHONE_STATE);
}
if (!(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
// 权限都已经有了那么直接调用SDK
if (lackedPermission.size() == 0) {
fetchSplashAD(this, mSplashContainer, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else {
// 请求所缺少的权限在onRequestPermissionsResult中再看是否获得权限如果获得权限就可以调用SDK否则不要调用SDK
String[] requestPermissions = new String[lackedPermission.size()];
lackedPermission.toArray(requestPermissions);
requestPermissions(requestPermissions, 1024);
}
}
private boolean hasAllPermissionsGranted(int[] grantResults) {
for (int grantResult : grantResults) {
if (grantResult == PackageManager.PERMISSION_DENIED) {
return false;
}
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) {
fetchSplashAD(this, mSplashContainer, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else {
// 如果用户没有授权那么应该说明意图引导用户去设置里面授权
Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
finish();
goToMainActivity();
}
}
/**
* 拉取开屏广告开屏广告的构造方法有3种详细说明请参考开发者文档
*
* @param activity 展示广告的activity
* @param adContainer 展示广告的大容器
* @param skipContainer 自定义的跳过按钮传入该view给SDK后SDK会自动给它绑定点击跳过事件SkipView的样式可以由开发者自由定制其尺寸限制请参考activity_splash.xml或者接入文档中的说明
* @param appId 应用ID
* @param posId 广告位ID
* @param adListener 广告状态监听器
* @param fetchDelay 拉取广告的超时时长取值范围[3000, 5000]设为0表示使用广点通SDK默认的超时时长
*/
private void fetchSplashAD(Activity activity, ViewGroup adContainer, View skipContainer,
String appId, String posId, SplashADListener adListener, int fetchDelay) {
fetchSplashADTime = System.currentTimeMillis();
Map<String, String> tags = new HashMap<>();
tags.put("tag_s1", "value_s1");
tags.put("tag_s2", "value_s2");
splashAD = new SplashAD(activity, adContainer, skipContainer, appId, posId, adListener,
fetchDelay, tags);
// 如果不需要传tag使用如下构造函数
// splashAD = new SplashAD(activity, adContainer, skipContainer, appId, posId, adListener, fetchDelay);
}
@Override
public void onADPresent() {
Log.i("AD_DEMO", "SplashADPresent");
SplashAdManager.setSplashTime();
splashHolder.setVisibility(View.INVISIBLE); // 广告展示后一定要把预设的开屏图片隐藏起来
}
@Override
public void onADClicked() {
Log.i("AD_DEMO", "SplashADClicked clickUrl: "
+ (splashAD.getExt() != null ? splashAD.getExt().get("clickUrl") : ""));
}
/**
* 倒计时回调返回广告还将被展示的剩余时间
* 通过这个接口开发者可以自行决定是否显示倒计时提示或者还剩几秒的时候显示倒计时
*
* @param millisUntilFinished 剩余毫秒数
*/
@Override
public void onADTick(long millisUntilFinished) {
Log.i("AD_DEMO", "SplashADTick " + millisUntilFinished + "ms");
skipView.setText(String.format(SKIP_TEXT, Math.round(millisUntilFinished / 1000f)));
}
@Override
public void onADExposure() {
Log.i("AD_DEMO", "SplashADExposure");
}
@Override
public void onADDismissed() {
Log.i("AD_DEMO", "SplashADDismissed");
next();
}
@Override
public void onNoAD(AdError error) {
Log.i(
"AD_DEMO",
String.format("LoadSplashADFail, eCode=%d, errorMsg=%s", error.getErrorCode(),
error.getErrorMsg()));
/**
* 为防止无广告时造成视觉上类似于"闪退"的情况设定无广告时页面跳转根据需要延迟一定时间demo
* 给出的延时逻辑是从拉取广告开始算开屏最少持续多久仅供参考开发者可自定义延时逻辑如果开发者采用demo
* 中给出的延时逻辑也建议开发者考虑自定义minSplashTimeWhenNoAD的值
**/
long alreadyDelayMills = System.currentTimeMillis() - fetchSplashADTime;//从拉广告开始到onNoAD已经消耗了多少时间
long shouldDelayMills = alreadyDelayMills > minSplashTimeWhenNoAD ? 0 : minSplashTimeWhenNoAD
- alreadyDelayMills;//为防止加载广告失败后立刻跳离开屏可能造成的视觉上类似于"闪退"的情况根据设置的minSplashTimeWhenNoAD
// 计算出还需要延时多久
handler.postDelayed(new Runnable() {
@Override
public void run() {
SplashActivity.this.finish();
goToMainActivity();
}
}, shouldDelayMills);
}
/**
* 设置一个变量来控制当前开屏页面是否可以跳转当开屏广告为普链类广告时点击会打开一个广告落地页此时开发者还不能打开自己的App主页当从广告落地页返回以后
* 才可以跳转到开发者自己的App主页当开屏广告是App类广告时只会下载App
*/
private void next() {
if (canJump) {
goToMainActivity();
this.finish();
} else {
canJump = true;
}
}
private String getPosId() {
return Constants.AD_SETTING.getSplash().getSlotId(Constants.AD_TENCENT_QQ);
}
//----qq ad end <---
}

View File

@ -9,7 +9,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import com.novelbook.android.AD.toutiao.SplashActivity;
import com.novelbook.android.Main2Activity; import com.novelbook.android.Main2Activity;
import com.novelbook.android.utils.Constants; import com.novelbook.android.utils.Constants;
@ -21,7 +21,7 @@ import static com.novelbook.android.utils.Constants.AD_TOUTIAO;
public class SplashAdManager implements Application.ActivityLifecycleCallbacks, ComponentCallbacks2 { public class SplashAdManager implements Application.ActivityLifecycleCallbacks, ComponentCallbacks2 {
private boolean mIsBackground; private boolean mIsBackground;
private static long lastAd =0; private static long lastAd =0;
private static long interVal = Constants.AD_SPLASH_INVTERVAL; //private static long interVal = 5000;//Constants.AD_SPLASH_INVTERVAL;
private static int pages =0; private static int pages =0;
@ -51,7 +51,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if(activity instanceof Main2Activity){ if(activity instanceof Main2Activity){
showAd(activity); //showAd(activity);
Log.d("zzr", " 启动应用"); Log.d("zzr", " 启动应用");
} }
} }
@ -66,7 +66,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
if (mIsBackground) { if (mIsBackground) {
mIsBackground = false; mIsBackground = false;
// showAd(activity); showSplashAd(activity);
Log.d("zzr", "从广告页回到前台"); Log.d("zzr", "从广告页回到前台");
} }
@ -112,26 +112,30 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
} }
static void showInterAd(Activity activity){ static void showInterAd(Activity activity){
clearPages();
} }
static void showAd(Activity activity){ static void showSplashAd(Activity activity){
if(canShowAd()) { if(canShowAd()) {
lastAd = new Date().getTime(); lastAd = new Date().getTime();
Intent intent =null; Intent intent = new Intent(activity, SplashActivity.class);
if(Constants.AD_SPLASH_SOURCE ==AD_TENCENT_QQ) { intent.putExtra(SplashActivity.EXTR_LUNCHER, false);
/* if(Constants.AD_SPLASH_SOURCE ==AD_TENCENT_QQ) {
intent = new Intent(activity, com.novelbook.android.AD.qq.SplashActivity.class); intent = new Intent(activity, com.novelbook.android.AD.qq.SplashActivity.class);
}else if(Constants.AD_SPLASH_SOURCE ==AD_TOUTIAO){ }else if(Constants.AD_SPLASH_SOURCE ==AD_TOUTIAO){
intent = new Intent(activity, SplashActivity.class); intent = new Intent(activity, SplashActivity.class);
intent.putExtra(SplashActivity.EXTR_LUNCHER, false); intent.putExtra(SplashActivity.EXTR_LUNCHER, false);
} }*/
activity.startActivity(intent); activity.startActivity(intent);
} }
} }
static boolean canShowAd(){ static boolean canShowAd(){
if(!Constants.SHOWAD){ if(!Constants.AD_SETTING.isShowAdsense()){
return false; return false;
} }
long in = new Date().getTime() -lastAd; long in = new Date().getTime() -lastAd;
int interVal =60000;//Constants.AD_SETTING.getSplash2().getInterval4Display()*1000;
Log.d("zzr", "canShowAd: interval is, " +in + ", canshow? "+ (in >interVal)); Log.d("zzr", "canShowAd: interval is, " +in + ", canshow? "+ (in >interVal));
return in >interVal; return in >interVal;
} }
@ -141,7 +145,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
} }
public static void plusPage(Activity activity){ public static void plusPage(Activity activity){
pages++; pages++;
if(pages >Constants.AD_SPLASH_PAGES){ if(pages >Constants.AD_SETTING.getSplash2().getPageCount4Display()){
showInterAd(activity); showInterAd(activity);
} }

View File

@ -1,25 +0,0 @@
package com.novelbook.android.AD.qq;
public class Constants {
public static final String APPID = "1101152570";
public static final String BannerPosID = "9079537218417626401";
public static final String InterteristalPosID = "8575134060152130849";
public static final String SplashPosID = "8863364436303842593";
public static final String NativePosID = "5010320697302671";
public static final String NativeVideoPosID = "5090421627704602";
public static final String NativeExpressPosID = "7030020348049331"; //如果选择支持视频的模版样式请使用NativeExpressSupportVideoPosID测试广告位拉取
public static final String NativeUnifiedPosID = "6040749702835933";
public static final String NativeExpressSupportVideoPosID = "2000629911207832"; //支持视频模版样式的广告位
public static final String ContentADPosID = "5060323935699523";
public static final String RewardVideoADPosIDSupportH = "2090845242931421";//支持竖版出横版视频
public static final String RewardVideoADPosIDUnsupportH = "5040942242835423";//不支持竖版出横版视频
public static final String IEGRewardVideoADPosID = "6000625736289442";//内广激励视频广告位id
public static final String UNIFIED_BANNER_POS_ID = "4080052898050840";
public static final String UNIFIED_INTERSTITIAL_ID_LARGE_SMALL = "3040652898151811";// 大小规格
public static final String UNIFIED_INTERSTITIAL_ID_ONLY_SMALL = "8020259898964453";// 只小规格
public static final String POS_ID = "pos_id";
public static final String MAX_VIDEO_DURATION = "maxVideoDuration";
public static final int VIDEO_DURATION_SETTING_MIN = 5;
public static final int VIDEO_DURATION_SETTING_MAX = 60;
}

View File

@ -22,6 +22,7 @@ import android.widget.Toast;
import com.novelbook.android.Main2Activity; import com.novelbook.android.Main2Activity;
import com.novelbook.android.R; import com.novelbook.android.R;
import com.novelbook.android.utils.Constants;
import com.qq.e.ads.splash.SplashAD; import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener; import com.qq.e.ads.splash.SplashADListener;
import com.qq.e.comm.util.AdError; import com.qq.e.comm.util.AdError;
@ -31,6 +32,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.novelbook.android.utils.AdUtil.getAppID;
/** /**
* 这是demo工程的入口Activity在这里会首次调用广点通的SDK * 这是demo工程的入口Activity在这里会首次调用广点通的SDK
* *
@ -47,7 +50,7 @@ public class SplashActivity extends Activity implements SplashADListener {
private static final String SKIP_TEXT = "点击跳过 %d"; private static final String SKIP_TEXT = "点击跳过 %d";
public boolean canJump = false; public boolean canJump = false;
private boolean needStartDemoList = true;
/** /**
* 为防止无广告时造成视觉上类似于"闪退"的情况设定无广告时页面跳转根据需要延迟一定时间demo * 为防止无广告时造成视觉上类似于"闪退"的情况设定无广告时页面跳转根据需要延迟一定时间demo
@ -91,13 +94,12 @@ public class SplashActivity extends Activity implements SplashADListener {
checkAndRequestPermission(); checkAndRequestPermission();
} else { } else {
// 如果是Android6.0以下的机器默认在安装时获得了所有权限可以直接调用SDK // 如果是Android6.0以下的机器默认在安装时获得了所有权限可以直接调用SDK
fetchSplashAD(this, container, skipView, Constants.APPID, getPosId(), this, 0); fetchSplashAD(this, container, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} }
} }
private String getPosId() { private String getPosId() {
String posId = getIntent().getStringExtra("pos_id"); return Constants.AD_SETTING.getSplash().getSlotId(Constants.AD_TENCENT_QQ);
return TextUtils.isEmpty(posId) ? Constants.SplashPosID : posId;
} }
/** /**
@ -128,7 +130,7 @@ public class SplashActivity extends Activity implements SplashADListener {
// 权限都已经有了那么直接调用SDK // 权限都已经有了那么直接调用SDK
if (lackedPermission.size() == 0) { if (lackedPermission.size() == 0) {
fetchSplashAD(this, container, skipView, Constants.APPID, getPosId(), this, 0); fetchSplashAD(this, container, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else { } else {
// 请求所缺少的权限在onRequestPermissionsResult中再看是否获得权限如果获得权限就可以调用SDK否则不要调用SDK // 请求所缺少的权限在onRequestPermissionsResult中再看是否获得权限如果获得权限就可以调用SDK否则不要调用SDK
String[] requestPermissions = new String[lackedPermission.size()]; String[] requestPermissions = new String[lackedPermission.size()];
@ -150,7 +152,7 @@ public class SplashActivity extends Activity implements SplashADListener {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) { if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) {
fetchSplashAD(this, container, skipView, Constants.APPID, getPosId(), this, 0); fetchSplashAD(this, container, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else { } else {
// 如果用户没有授权那么应该说明意图引导用户去设置里面授权 // 如果用户没有授权那么应该说明意图引导用户去设置里面授权
Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show(); Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show();

View File

@ -1,220 +0,0 @@
package com.novelbook.android.AD.toutiao;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.MainThread;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTSplashAd;
import com.novelbook.android.AD.SplashAdManager;
import com.novelbook.android.BuildConfig;
import com.novelbook.android.Main2Activity;
import com.novelbook.android.R;
import com.novelbook.android.utils.Constants;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* 开屏广告Activity示例
*/
public class SplashActivity extends Activity implements WeakHandler.IHandler {
private static final String TAG = SplashActivity.class.getSimpleName();
private TTAdNative mTTAdNative;
private FrameLayout mSplashContainer;
//是否强制跳转到主页面
private boolean mForceGoMain;
public static final String EXTR_LUNCHER="luncher";
//开屏广告加载发生超时但是SDK没有及时回调结果的时候做的一层保护
private final WeakHandler mHandler = new WeakHandler(this);
//开屏广告加载超时时间,建议大于1000,这里为了冷启动第一次加载到广告并且展示,示例设置了2000ms
private static final int AD_TIME_OUT = 2000;
private static final int MSG_GO_MAIN = 1;
//开屏广告是否已经加载
private boolean mHasLoaded;
@BindView(R.id.textTile)
TextView tvTitle;
@SuppressWarnings("RedundantCast")
@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);
//定时AD_TIME_OUT时间到时执行如果开屏广告没有加载则跳转到主页面
mHandler.sendEmptyMessageDelayed(MSG_GO_MAIN, AD_TIME_OUT);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// | View.SYSTEM_UI_FLAG_IMMERSIVE
);
tvTitle.setText(R.string.app_name);
//加载开屏广告
loadSplashAd();
}
@Override
protected void onResume() {
//判断是否该跳转到主页面
if (mForceGoMain) {
mHandler.removeCallbacksAndMessages(null);
goToMainActivity();
}
super.onResume();
}
@Override
protected void onStop() {
super.onStop();
mForceGoMain = true;
}
/**
* 加载开屏广告
*/
private void loadSplashAd() {
//step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(BuildConfig.AD_SLOT_TOUTIAO_SPLASH_ID)
.setSupportDeepLink(true)
.setImageAcceptedSize(Constants.SCREEN_WIDTH_PIX, Constants.SCREEN_HEIGHT_PIX)
.build();
//step4:请求广告调用开屏广告异步请求接口对请求回调的广告作渲染处理
mTTAdNative.loadSplashAd(adSlot, new TTAdNative.SplashAdListener() {
@Override
@MainThread
public void onError(int code, String message) {
Log.d(TAG, message);
mHasLoaded = true;
showToast(message);
goToMainActivity();
}
@Override
@MainThread
public void onTimeout() {
mHasLoaded = true;
showToast("开屏广告加载超时");
goToMainActivity();
}
@Override
@MainThread
public void onSplashAdLoad(TTSplashAd ad) {
Log.d(TAG, "开屏广告请求成功");
SplashAdManager.setSplashTime();
mHasLoaded = true;
mHandler.removeCallbacksAndMessages(null);
if (ad == null) {
return;
}
//获取SplashView
View view = ad.getSplashView();
mSplashContainer.removeAllViews();
//把SplashView 添加到ViewGroup中,注意开屏广告viewwidth >=70%屏幕宽height >=50%屏幕宽
mSplashContainer.addView(view);
//设置不开启开屏广告倒计时功能以及不显示跳过按钮,如果这么设置您需要自定义倒计时逻辑
//ad.setNotAllowSdkCountdown();
//设置SplashView的交互监听器
ad.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
@Override
public void onAdClicked(View view, int type) {
Log.d(TAG, "onAdClicked");
showToast("开屏广告点击");
}
@Override
public void onAdShow(View view, int type) {
Log.d(TAG, "onAdShow");
showToast("开屏广告展示");
}
@Override
public void onAdSkip() {
Log.d(TAG, "onAdSkip");
showToast("开屏广告跳过");
goToMainActivity();
}
@Override
public void onAdTimeOver() {
Log.d(TAG, "onAdTimeOver");
showToast("开屏广告倒计时结束");
goToMainActivity();
}
});
}
}, AD_TIME_OUT);
}
/**
* 跳转到主页面
*/
private void goToMainActivity() {
/* Intent intent = new Intent(SplashActivity.this, Main2Activity.class);
startActivity(intent);*/
if(mSplashContainer!=null) {
mSplashContainer.removeAllViews();
}
SplashAdManager.clearPages();
this.finish();
}
private void showToast(String msg) {
//TToast.show(this, msg);
Log.d(TAG, "loadBannerAd: " + msg);
}
@Override
public void handleMsg(Message msg) {
if (msg.what == MSG_GO_MAIN) {
if (!mHasLoaded) {
showToast("广告已超时,跳到主页面");
goToMainActivity();
}
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK|| keyCode == KeyEvent.KEYCODE_HOME) {
return true;
}
return super.onKeyUp(keyCode,event);
}
}

View File

@ -1,6 +1,7 @@
package com.novelbook.android.AD.toutiao; package com.novelbook.android.AD.toutiao;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.bytedance.sdk.openadsdk.TTAdConfig; import com.bytedance.sdk.openadsdk.TTAdConfig;
@ -10,6 +11,8 @@ import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.novelbook.android.BuildConfig; import com.novelbook.android.BuildConfig;
import com.novelbook.android.utils.Constants; import com.novelbook.android.utils.Constants;
import static com.novelbook.android.utils.AdUtil.getAppID;
/** /**
* 可以用一个单例来保存TTAdManager实例在需要初始化sdk的时候调用 * 可以用一个单例来保存TTAdManager实例在需要初始化sdk的时候调用
*/ */
@ -25,7 +28,8 @@ public class TTAdManagerHolder {
} }
public static void init(Context context) { public static void init(Context context) {
if( Constants.SHOWAD) { if( Constants.AD_SETTING.isShowAdsense() &&
!TextUtils.isEmpty(getAppID(Constants.AD_TOUTIAO)) ) {
doInit(context); doInit(context);
} }
} }
@ -42,13 +46,13 @@ public class TTAdManagerHolder {
Log.d("adinit", "buildConfig:Constants.SEX= "+Constants.SEX ); Log.d("adinit", "buildConfig:Constants.SEX= "+Constants.SEX );
return new TTAdConfig.Builder() return new TTAdConfig.Builder()
.appId(BuildConfig.AD_TOUTIAO_APP_ID) .appId(getAppID(Constants.AD_TOUTIAO))
.useTextureView(false) //使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景可以使用TextureView .useTextureView(false) //使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景可以使用TextureView
.appName("如意小说") .appName("如意小说")
.titleBarTheme(TTAdConstant.TITLE_BAR_THEME_DARK) .titleBarTheme(TTAdConstant.TITLE_BAR_THEME_DARK)
.allowShowNotify(true) //是否允许sdk展示通知栏提示 .allowShowNotify(true) //是否允许sdk展示通知栏提示
.allowShowPageWhenScreenLock(true) //是否在锁屏场景支持展示广告落地页 .allowShowPageWhenScreenLock(true) //是否在锁屏场景支持展示广告落地页
.debug(true) //测试阶段打开可以通过日志排查问题上线时去除该调用 // .debug(true) //测试阶段打开可以通过日志排查问题上线时去除该调用
.directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_4G) //允许直接下载的网络状态集合 .directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_4G) //允许直接下载的网络状态集合
.supportMultiProcess(false) //是否支持多进程true支持 .supportMultiProcess(false) //是否支持多进程true支持
.gender(Constants.SEX==1 ? TTAdConstant.GENDER_MALE : TTAdConstant.GENDER_FEMALE) // TTAdConstant.GENDER_UNKNOWN) .gender(Constants.SEX==1 ? TTAdConstant.GENDER_MALE : TTAdConstant.GENDER_FEMALE) // TTAdConstant.GENDER_UNKNOWN)

View File

@ -59,6 +59,7 @@ import com.novelbook.android.adapter.BookListAdapter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -83,6 +84,7 @@ import org.litepal.util.Const;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import static com.novelbook.android.utils.AdUtil.getAppID;
import static com.novelbook.android.utils.Constants.AD_TENCENT_QQ; import static com.novelbook.android.utils.Constants.AD_TENCENT_QQ;
import static com.novelbook.android.utils.Constants.AD_TOUTIAO; import static com.novelbook.android.utils.Constants.AD_TOUTIAO;
@ -93,7 +95,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
private MyApp application; private MyApp application;
private Activity_base oContext; private Activity_base oContext;
protected Gson gson = new Gson(); protected Gson gson = new Gson();
protected long mLastBannerTime =0;
//---qq ad----> //---qq ad---->
private NativeExpressAD nativeExpressAD; private NativeExpressAD nativeExpressAD;
private NativeExpressADView nativeExpressADView; private NativeExpressADView nativeExpressADView;
@ -177,7 +179,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
if(mBannerContainer==null){ if(mBannerContainer==null){
return; return;
} }
if(Constants.SHOWAD){ if(Constants.AD_SETTING.isShowAdsense()){
loadNativeBannerAd(); loadNativeBannerAd();
mBannerContainer.setVisibility(View.VISIBLE); mBannerContainer.setVisibility(View.VISIBLE);
}else{ }else{
@ -410,14 +412,19 @@ public abstract class Activity_base extends AppCompatActivity implements Native
mBannerContainer.setVisibility(View.VISIBLE); mBannerContainer.setVisibility(View.VISIBLE);
} }
*/ */
if(!Constants.AD_SETTING.isShowAdsense() ){return;}
mLastBannerTime=0;//复位小banner请求时间戳否则会在小banner位置显示nati banner 信息
if (mBannerContainer.getChildCount() > 0) { if (mBannerContainer.getChildCount() > 0) {
mBannerContainer.removeAllViews(); mBannerContainer.removeAllViews();
} }
if(!Constants.SHOWAD ){return;}
if(Constants.AD_NATIVE_BANNER_SOURCE == AD_TENCENT_QQ) { if(Constants.AD_SETTING.getChapterContentBanner().getSource() == AD_TENCENT_QQ) {
loadNativeBanner_qq(-1, 388); loadNativeBanner_qq(-1, 388);
}else if(Constants.AD_NATIVE_BANNER_SOURCE == AD_TOUTIAO) { }else if(Constants.AD_SETTING.getChapterContentBanner().getSource() == AD_TOUTIAO) {
loadNativeBanner_toutiao(mBannerContainer ,690,388); loadNativeBanner_toutiao(mBannerContainer ,690,388);
} }
} }
@ -428,10 +435,17 @@ public abstract class Activity_base extends AppCompatActivity implements Native
} }
private void loadBanner( int width, int height){ private void loadBanner( int width, int height){
if(Constants.AD_BANNER_SOURCE == AD_TENCENT_QQ) {
if(mBannerContainer.getChildCount()>0)
if (new Date().getTime() - mLastBannerTime < Constants.AD_SETTING.getChapterBanner().getLifeCycleSecond()*1000){
Log.d(TAG, String.format("loadBanner:mLastBannerTime %s ,timepassed %s",mLastBannerTime,(new Date().getTime() - mLastBannerTime)/1000));
return;
}
Log.d(TAG, "loadBanner:mLastBannerTime start new banner request");
if(Constants.AD_SETTING.getChapterBanner().getSource()== AD_TENCENT_QQ) {
getBanner_qq(); getBanner_qq();
// loadNativeBanner_qq(-1, 388); }else if(Constants.AD_SETTING.getChapterBanner().getSource()== AD_TOUTIAO) {
}else if(Constants.AD_BANNER_SOURCE == AD_TOUTIAO) {
loadBanner_toutiao(mBannerContainer, width,height); loadBanner_toutiao(mBannerContainer, width,height);
} }
@ -444,7 +458,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
Button mCreativeButton; Button mCreativeButton;
TTAdNative mTTAdNative; TTAdNative mTTAdNative;
void initAD_TouTiao(){ void initAD_TouTiao(){
if(Constants.SHOWAD) if(Constants.AD_SETTING.isShowAdsense())
try { try {
mTTAdNative = TTAdManagerHolder.get().createAdNative(this); mTTAdNative = TTAdManagerHolder.get().createAdNative(this);
//step3:(可选强烈建议在合适的时机调用):申请部分权限如read_phone_state,防止获取不了imei时候下载类广告没有填充的问题 //step3:(可选强烈建议在合适的时机调用):申请部分权限如read_phone_state,防止获取不了imei时候下载类广告没有填充的问题
@ -457,7 +471,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
TTAdNative getTTAdNative(){ TTAdNative getTTAdNative(){
if(mTTAdNative== null){ if(mTTAdNative== null){
if(Constants.SHOWAD){ if(Constants.AD_SETTING.isShowAdsense()){
TTAdManagerHolder.init(MyApp.applicationContext); TTAdManagerHolder.init(MyApp.applicationContext);
initAD_TouTiao(); initAD_TouTiao();
} }
@ -473,8 +487,8 @@ public abstract class Activity_base extends AppCompatActivity implements Native
// boolean mShowAd =false; // boolean mShowAd =false;
void loadBanner_toutiao(FrameLayout bannerContainer,int width, int height) { void loadBanner_toutiao(FrameLayout bannerContainer,int width, int height) {
//step4:创建广告请求参数AdSlot,具体参数含义参考文档 //step4:创建广告请求参数AdSlot,具体参数含义参考文档
if(!Constants.SHOWAD || getTTAdNative()==null ){return;} if(!Constants.AD_SETTING.isShowAdsense() || getTTAdNative()==null ){return;}
String codeId =BuildConfig.AD_SLOT_TOUTIAO_BANNER_ID; String codeId = Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_TOUTIAO) ;
/* if(height >390){ /* if(height >390){
width =(int)(height*1.78); width =(int)(height*1.78);
if(width > Constants.SCREEN_WIDTH_PIX-50 ){ if(width > Constants.SCREEN_WIDTH_PIX-50 ){
@ -513,8 +527,9 @@ public abstract class Activity_base extends AppCompatActivity implements Native
if (bannerView == null) { if (bannerView == null) {
return; return;
} }
mLastBannerTime =new Date().getTime();
//设置轮播的时间间隔 间隔在30s到120秒之间的值不设置默认不轮播 //设置轮播的时间间隔 间隔在30s到120秒之间的值不设置默认不轮播
ad.setSlideIntervalTime(30 * 1000); // ad.setSlideIntervalTime(30 * 1000);
bannerContainer.removeAllViews(); bannerContainer.removeAllViews();
bannerContainer.addView(bannerView); bannerContainer.addView(bannerView);
// bannerContainer.setVisibility(View.VISIBLE); // bannerContainer.setVisibility(View.VISIBLE);
@ -619,11 +634,11 @@ public abstract class Activity_base extends AppCompatActivity implements Native
void loadNativeBanner_toutiao(FrameLayout bannerContainer,int width,int height) { void loadNativeBanner_toutiao(FrameLayout bannerContainer,int width,int height) {
//step4:创建广告请求参数AdSlot,注意其中的setNativeAdtype方法具体参数含义参考文档 //step4:创建广告请求参数AdSlot,注意其中的setNativeAdtype方法具体参数含义参考文档
if (!Constants.SHOWAD || getTTAdNative() == null) { if (!Constants.AD_SETTING.isShowAdsense()|| getTTAdNative() == null) {
return; return;
} }
String codeId =BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID; String codeId =Constants.AD_SETTING.getChapterContentBanner().getSlotId(Constants.AD_TOUTIAO);
final String key =width+"_"+height; final String key =width+"_"+height;
List<TTNativeAd> adCache =null; List<TTNativeAd> adCache =null;
@ -651,7 +666,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
.setSupportDeepLink(true) .setSupportDeepLink(true)
.setImageAcceptedSize(width, height) .setImageAcceptedSize(width, height)
.setNativeAdType(AdSlot.TYPE_BANNER) //请求原生广告时候请务必调用该方法设置参数为TYPE_BANNER或TYPE_INTERACTION_AD .setNativeAdType(AdSlot.TYPE_BANNER) //请求原生广告时候请务必调用该方法设置参数为TYPE_BANNER或TYPE_INTERACTION_AD
.setAdCount(3) .setAdCount(1)
.build(); .build();
//step5:请求广告对请求回调的广告作渲染处理 //step5:请求广告对请求回调的广告作渲染处理
@ -1010,7 +1025,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
public void loadListAd_toutiao(BookListAdapter adapter, int adCnt, boolean addFooter) { public void loadListAd_toutiao(BookListAdapter adapter, int adCnt, boolean addFooter) {
//feed广告请求类型参数 //feed广告请求类型参数
AdSlot adSlot = new AdSlot.Builder() AdSlot adSlot = new AdSlot.Builder()
.setCodeId(BuildConfig.AD_SLOT_TOUTIAO_FEEDAD_ID) .setCodeId( Constants.AD_SETTING.getInformationFlow().getSlotId(Constants.AD_TOUTIAO) )
.setSupportDeepLink(true) .setSupportDeepLink(true)
.setImageAcceptedSize(228, 150) .setImageAcceptedSize(228, 150)
.setAdCount(adCnt) .setAdCount(adCnt)
@ -1047,6 +1062,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
BannerView bv; BannerView bv;
private void getBanner_qq() { private void getBanner_qq() {
@ -1054,8 +1070,13 @@ public abstract class Activity_base extends AppCompatActivity implements Native
mBannerContainer.removeView(bv); mBannerContainer.removeView(bv);
bv.destroy(); bv.destroy();
} }
if( mBannerContainer.getChildCount()>0){
mBannerContainer.removeAllViews();
}
this.bv = new BannerView(this, com.qq.e.ads.banner.ADSize.BANNER,com.novelbook.android.AD.qq.Constants. APPID,com.novelbook.android.AD.qq.Constants.BannerPosID); this.bv = new BannerView(this, com.qq.e.ads.banner.ADSize.BANNER,
getAppID(Constants.AD_TENCENT_QQ),
Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_TENCENT_QQ));
// 注意如果开发者的banner不是始终展示在屏幕中的话请关闭自动刷新否则将导致曝光率过低 // 注意如果开发者的banner不是始终展示在屏幕中的话请关闭自动刷新否则将导致曝光率过低
// 并且应该自行处理当banner广告区域出现在屏幕后再手动loadAD // 并且应该自行处理当banner广告区域出现在屏幕后再手动loadAD
// bv.setRefresh(0); // bv.setRefresh(0);
@ -1076,6 +1097,8 @@ public abstract class Activity_base extends AppCompatActivity implements Native
}); });
mBannerContainer.addView(bv); mBannerContainer.addView(bv);
this.bv.loadAD(); this.bv.loadAD();
mLastBannerTime =new Date().getTime();
} }
@ -1092,7 +1115,9 @@ public abstract class Activity_base extends AppCompatActivity implements Native
}*/ }*/
nativeExpressAD = new NativeExpressAD(this, getMyADSize(adWidth, adHeight), com.novelbook.android.AD.qq.Constants.APPID, com.novelbook.android.AD.qq.Constants.NativeExpressPosID, this); // 这里的Context必须为Activity nativeExpressAD = new NativeExpressAD(this, getMyADSize(adWidth, adHeight),
getAppID(Constants.AD_TENCENT_QQ),
Constants.AD_SETTING.getChapterContentBanner().getSlotId(Constants.AD_TENCENT_QQ), this); // 这里的Context必须为Activity
/* nativeExpressAD.setVideoOption(new VideoOption.Builder() /* nativeExpressAD.setVideoOption(new VideoOption.Builder()
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // 设置什么网络环境下可以自动播放视频 .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // 设置什么网络环境下可以自动播放视频
.setAutoPlayMuted(true) // 设置自动播放视频时是否静音 .setAutoPlayMuted(true) // 设置自动播放视频时是否静音
@ -1171,6 +1196,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
}*/ }*/
bindAD(adList); bindAD(adList);
} }
void bindAD(List<NativeExpressADView> adList){ void bindAD(List<NativeExpressADView> adList){
if (nativeExpressADView != null) { if (nativeExpressADView != null) {

View File

@ -85,6 +85,8 @@ import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import static com.novelbook.android.utils.AdUtil.getAppID;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
@ -157,7 +159,7 @@ public abstract class BasicFragment extends Fragment implements NativeADUnifie
initData(); initData();
initViews(); initViews();
initSwipeRefreshLayout(); initSwipeRefreshLayout();
if (mBannerContainer!=null && !Constants.SHOWAD) { if (mBannerContainer!=null && !Constants.AD_SETTING.isShowAdsense()) {
if( mBannerContainer.getVisibility() !=View.GONE) { if( mBannerContainer.getVisibility() !=View.GONE) {
mBannerContainer.setVisibility(View.GONE); mBannerContainer.setVisibility(View.GONE);
} }
@ -444,19 +446,6 @@ void initTabs(){
initData(); initData();
} //on tab changed } //on tab changed
@Override
public void onResume() {
super.onResume();
error_try=0;
showBanner(mBannerContainer,(int) getResources().getDimension(R.dimen.topBannerHeight) );
// MobclickAgent.onPageStart(TAG);
}
@Override
public void onPause(){
super.onPause();
hideProgress();
// MobclickAgent.onPageEnd(TAG);
}
void retryErorr(int msg){ void retryErorr(int msg){
if(error_try<error_try_max){ if(error_try<error_try_max){
@ -476,7 +465,7 @@ void initTabs(){
return; return;
} }
// bannerContainer.setVisibility(View.GONE); // bannerContainer.setVisibility(View.GONE);
if (!Constants.SHOWAD) { if (!Constants.AD_SETTING.isShowAdsense()) {
return; return;
} }
@ -490,24 +479,28 @@ void initTabs(){
private List<NativeUnifiedADData> mAds = new ArrayList<>(); private List<NativeUnifiedADData> mAds = new ArrayList<>();
public void loadListAd_qq(BookListAdapter adapter, int adCnt, boolean addFooter) { public void loadListAd_qq(BookListAdapter adapter, int adCnt, boolean addFooter) {
if(mAdManager==null) { if(mAdManager==null) {
mAdManager = new NativeUnifiedAD(activity, com.novelbook.android.AD.qq.Constants.APPID, mAdManager = new NativeUnifiedAD(activity,
com.novelbook.android.AD.qq.Constants.UNIFIED_INTERSTITIAL_ID_ONLY_SMALL, this); getAppID(Constants.AD_TENCENT_QQ),
Constants.AD_SETTING.getInformationFlow().getSlotId(Constants.AD_TENCENT_QQ),
this);
} }
mAdManager.loadData(adCnt); mAdManager.loadData(adCnt);
qqAdapter =adapter; qqAdapter =adapter;
qqAddFooter=addFooter; qqAddFooter=addFooter;
Log.d(TAG, "loadListAd_qq: ad requested");
} }
private boolean qqAddFooter; private boolean qqAddFooter;
private BookListAdapter qqAdapter; private BookListAdapter qqAdapter;
@Override @Override
public void onADLoaded(List<NativeUnifiedADData> ads) { public void onADLoaded(List<NativeUnifiedADData> ads) {
Log.d(TAG, "loadListAd_qq: ad onADLoaded,qqAddFooter? "+qqAddFooter);
// mIsLoading = false; // mIsLoading = false;
// 防止在onDestory后网络回包 // 防止在onDestory后网络回包
if(qqAdapter==null){ if(qqAdapter==null){
return; return;
} }
if(qqAddFooter) { if(qqAddFooter) {
qqAdapter.AddFooterItem(ads); qqAdapter.AddFooterItem(ads);
}else{ }else{
@ -516,6 +509,7 @@ void initTabs(){
} }
@Override @Override
public void onNoAD(AdError adError) { public void onNoAD(AdError adError) {
Log.d(TAG, "loadListAd_qq: ad onNoAD " );
Log.i( Log.i(
TAG, TAG,
String.format("onNoAD, error code: %d, error msg: %s", adError.getErrorCode(), String.format("onNoAD, error code: %d, error msg: %s", adError.getErrorCode(),
@ -528,11 +522,26 @@ void initTabs(){
* 加载 toutiao feed广告 * 加载 toutiao feed广告
*/ */
void loadListAd( BookListAdapter adapter, int adCnt, boolean addFooter) { void loadListAd( BookListAdapter adapter, int adCnt, boolean addFooter) {
if(Constants.AD_UNIFIED_RECYCLE_SOURCE==1) { if(Constants.AD_SETTING.getInformationFlow().getSource()==Constants.AD_TENCENT_QQ) {
loadListAd_qq(adapter, adCnt, addFooter); loadListAd_qq(adapter, adCnt, addFooter);
}else if(Constants.AD_UNIFIED_RECYCLE_SOURCE==2){ }else if(Constants.AD_SETTING.getInformationFlow().getSource()==Constants.AD_TOUTIAO){
activity.loadListAd_toutiao(adapter, adCnt, addFooter); activity.loadListAd_toutiao(adapter, adCnt, addFooter);
} }
} }
@Override
public void onResume() {
super.onResume();
error_try=0;
showBanner(mBannerContainer,(int) getResources().getDimension(R.dimen.topBannerHeight) );
// MobclickAgent.onPageStart(TAG);
}
@Override
public void onPause(){
super.onPause();
hideProgress();
// MobclickAgent.onPageEnd(TAG);
}
} }

View File

@ -467,7 +467,22 @@ public class Fragment_Shelf extends BasicFragment {
isSelectAll = !isSelectAll; isSelectAll = !isSelectAll;
mChkAdapter.notifyDataSetChanged(); mChkAdapter.notifyDataSetChanged();
} else if (view.getId() == R.id.btnDelete) { } else if (view.getId() == R.id.btnDelete) {
List<Integer> toRemove = new ArrayList<Integer>();
new AlertDialog.Builder(activity)
.setTitle(this.getString(R.string.app_name))
.setMessage( "您将从书架移除选中的书籍,是否继续?")
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < bookLists.size(); i++) { for (int i = 0; i < bookLists.size(); i++) {
if (flag[i]) { if (flag[i]) {
Novel nv = bookLists.get(i); Novel nv = bookLists.get(i);
@ -485,12 +500,24 @@ public class Fragment_Shelf extends BasicFragment {
nv.update(nv.getId()); nv.update(nv.getId());
// nv.update(nv.getId()); //not work,,,If you set a default value to a field, the corresponding column won't be updated. // nv.update(nv.getId()); //not work,,,If you set a default value to a field, the corresponding column won't be updated.
} }
bookLists = Novel.getNovelsOnShelf();
flag = new boolean[bookLists.size()];
zhengliShelf();
initData();
// flag = new boolean[bookLists.size()]; // flag = new boolean[bookLists.size()];
// bookLists.remove(i); // bookLists.remove(i);
} }
} }
}
})
.setCancelable(false).show();
// List<Integer> toRemove = new ArrayList<Integer>();
/*for (int i = 0; i < bookLists.size(); i++) { /*for (int i = 0; i < bookLists.size(); i++) {
if (flag[i]) { if (flag[i]) {
bookLists.remove(i); bookLists.remove(i);
@ -498,10 +525,7 @@ public class Fragment_Shelf extends BasicFragment {
} }
} }
*/ */
bookLists = Novel.getNovelsOnShelf();
flag = new boolean[bookLists.size()];
zhengliShelf();
initData();
// mChkAdapter.notifyDataSetChanged(); // mChkAdapter.notifyDataSetChanged();
} }

View File

@ -9,7 +9,9 @@ import android.util.Log;
import com.bytedance.sdk.openadsdk.TTAdConfig; import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant; import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdSdk; import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.google.gson.Gson;
import com.novelbook.android.AD.toutiao.TTAdManagerHolder; import com.novelbook.android.AD.toutiao.TTAdManagerHolder;
import com.novelbook.android.bean.AdSetting;
import com.novelbook.android.netutils.HttpMethods; import com.novelbook.android.netutils.HttpMethods;
import com.novelbook.android.netutils.NetUtil; import com.novelbook.android.netutils.NetUtil;
import com.novelbook.android.utils.Config; import com.novelbook.android.utils.Config;
@ -48,16 +50,20 @@ public class MyApp extends Application {
private void initialConstants(){ private void initialConstants(){
Config config= Config.createConfig(this); Config config= Config.createConfig(this);
Constants.SEX = config.getSexOption(); Constants.SEX = config.getSexOption();
Constants.SHOWAD =config.isShowAd();
Constants.PRE_LOAD_CHAPT =config.isPreLoadChapter(); Constants.PRE_LOAD_CHAPT =config.isPreLoadChapter();
Gson gson = new Gson();
Constants.AD_SETTING = gson.fromJson(config.getAdSetting(), AdSetting.class);
if(Constants.AD_SETTING==null){
Constants.AD_SETTING = new AdSetting();
}
/* Constants.SHOWAD =config.isShowAd();
Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT = config.getAdTopBannerRate(); Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT = config.getAdTopBannerRate();
Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT= config.getAdNativeBannerInLinesRate() ; Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT= config.getAdNativeBannerInLinesRate() ;
Constants.AD_SPLASH_SOURCE=config.getAdSplashSource(); Constants.AD_SPLASH_SOURCE=config.getAdSplashSource();
Constants.AD_UNIFIED_RECYCLE_SOURCE=config.getAdUnifiedRecycleSource(); Constants.AD_UNIFIED_RECYCLE_SOURCE=config.getAdUnifiedRecycleSource();
Constants.AD_NATIVE_BANNER_SOURCE=config.getAdNativeBannerSource(); Constants.AD_NATIVE_BANNER_SOURCE=config.getAdNativeBannerSource();
Constants.AD_BANNER_SOURCE=config.getAdBannerSource(); Constants.AD_BANNER_SOURCE=2;//config.getAdBannerSource();*/

View File

@ -1100,14 +1100,9 @@ public class ReadActivity extends Activity_base implements AdInterface {
} }
private void hideAdSlot(ViewGroup view){ private void hideAdSlot(ViewGroup view){
if(view.getChildCount()>0) { if(view.getVisibility() ==View.VISIBLE) {
view.removeAllViews();
Log.d(TAG, "loadBannerAd: hideAdSlot()");
}
/* if(view.getVisibility() ==View.VISIBLE) {
view.setVisibility(View.GONE); view.setVisibility(View.GONE);
}*/ }
/* FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); /* FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.width =0; params.width =0;
view.setLayoutParams(params);*/ view.setLayoutParams(params);*/
@ -1143,8 +1138,13 @@ public class ReadActivity extends Activity_base implements AdInterface {
if( adY >390*Constants.ONE_DP_SIZE){ if( adY >390*Constants.ONE_DP_SIZE){
return; return;
} }
tmpFrame =mBannerContainer;
if(mBannerContainer.getChildCount()>0) {
mBannerContainer.removeAllViews();
Log.d(TAG, "loadBannerAd: hideAdSlot()");
}
tmpFrame =mBannerContainer;
mLastBannerTime=0;
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));
loadNativeBannerAd(mBannerContainer); loadNativeBannerAd(mBannerContainer);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams(); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams();
@ -1162,17 +1162,18 @@ public class ReadActivity extends Activity_base implements AdInterface {
// hideSystemUI(); // hideSystemUI();
// mTopBannerContainer.setVisibility(View.INVISIBLE);//翻页引起抖动 // mTopBannerContainer.setVisibility(View.INVISIBLE);//翻页引起抖动
//mTopBannerContainer.removeAllViews(); //mTopBannerContainer.removeAllViews();
Log.d(TAG, String.format("loadBannerAd:showTopBanner width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY)); // Log.d(TAG, String.format("loadBannerAd:showTopBanner width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY));
tmpFrame =mBannerContainer; tmpFrame =mBannerContainer;
hideAdSlot(mBannerContainer); // hideAdSlot(mBannerContainer);
if(adHeight<=0){ if(adHeight<=0){
return; return;
} }
int topMargin = adY >200*Constants.ONE_DP_SIZE ? adY -15*Constants.ONE_DP_SIZE :adY -5*Constants.ONE_DP_SIZE;
Log.d(TAG, String.format("loadBannerAd:showTopBanner width %s, height %s ,adY %s ",Constants.SCREEN_WIDTH_PIX-50,adHeight,adY)); 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) mBannerContainer.getLayoutParams(); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBannerContainer.getLayoutParams();
loadBanner(mBannerContainer, Constants.SCREEN_WIDTH_PIX-50,adHeight); loadBanner(mBannerContainer, Constants.SCREEN_WIDTH_PIX-50,adHeight);
// loadNativeBannerAd(mTopBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID, 304,200); // loadNativeBannerAd(mTopBannerContainer,BuildConfig.AD_SLOT_TOUTIAO_BANNER_NATIVE_ID, 304,200);
params.setMargins(10*Constants.ONE_DP_SIZE, adY -5*Constants.ONE_DP_SIZE, 10*Constants.ONE_DP_SIZE, 0); params.setMargins(10*Constants.ONE_DP_SIZE, topMargin, 10*Constants.ONE_DP_SIZE, 0 );
params.width =-1; params.width =-1;
params.height = (int) getResources().getDimension(R.dimen.topBannerHeight); params.height = (int) getResources().getDimension(R.dimen.topBannerHeight);
mBannerContainer.setLayoutParams(params); mBannerContainer.setLayoutParams(params);
@ -1191,7 +1192,7 @@ public class ReadActivity extends Activity_base implements AdInterface {
if(!Constants.SHOWAD){ if(!Constants.AD_SETTING.isShowAdsense()){
return; return;
} }
@ -1223,12 +1224,6 @@ public class ReadActivity extends Activity_base implements AdInterface {
showAdSlot(mNative_status_banner_container); showAdSlot(mNative_status_banner_container);
// mNative_banner_container.setVisibility(View.VISIBLE); // mNative_banner_container.setVisibility(View.VISIBLE);
// showTopBanner(0,0); // showTopBanner(0,0);
}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);*/
} }

View File

@ -1,22 +1,129 @@
package com.novelbook.android.bean; package com.novelbook.android.bean;
public class AdSetting { public class AdSetting {
private int splashInterval; private String[] appIds={};
private int splashPageCount; private slot splash = new slot();
private slot splash2 = new slot();
private slot informationFlow = new slot();
private slot chapterBanner = new slot();
private slot chapterContentBanner = new slot();
private slot chapterEndBanner = new slot();
private slot pop = new slot();
private boolean showAdsense;
public int getSplashInterval() { public boolean isShowAdsense() {
return splashInterval; return true;//showAdsense;
} }
public void setSplashInterval(int splashInterval) { public void setShowAdsense(boolean showAdsense) {
this.splashInterval = splashInterval; this.showAdsense = showAdsense;
} }
public int getSplashPageCount() { public String[] getAppIds() {
return splashPageCount; return appIds;
} }
public void setSplashPageCount(int splashPageCount) { public slot getSplash() {
this.splashPageCount = splashPageCount; return splash;
}
public slot getSplash2() {
return splash2;
}
public slot getInformationFlow() {
return informationFlow;
}
public slot getChapterBanner() {
return chapterBanner;
}
public slot getChapterContentBanner() {
return chapterContentBanner;
}
public slot getChapterEndBanner() {
return chapterEndBanner;
}
public slot getPop() {
return pop;
}
public class slot{
private boolean show;
private int source;
private int interval4Display;
private int pageCount4Display;
private String[] slotIds={};
private int lifeCycleSecond;
private int displayPosition;
public int getDisplayPosition() {
//return 2;
return displayPosition;
}
public void setDisplayPosition(int displayPosition) {
this.displayPosition = displayPosition;
}
public boolean isShow() {
return show;
}
public void setShow(boolean show) {
this.show = show;
}
public int getSource() {
// return source;
return 1;
}
public void setSource(int source) {
this.source = source;
}
public int getInterval4Display() {
return interval4Display;
}
public void setInterval4Display(int interval4Display) {
this.interval4Display = interval4Display;
}
public int getPageCount4Display() {
return pageCount4Display;
}
public void setPageCount4Display(int pageCount4Display) {
this.pageCount4Display = pageCount4Display;
}
public String[] getSlotIds() {
return slotIds;
}
public void setSlotIds(String[] slotIds) {
this.slotIds = slotIds;
}
public int getLifeCycleSecond() {
return lifeCycleSecond;
}
public void setLifeCycleSecond(int lifeCycleSecond) {
this.lifeCycleSecond = lifeCycleSecond;
}
public String getSlotId(int sourceType){
if(sourceType>0 && slotIds!=null && slotIds.length >sourceType-1){
return slotIds[sourceType-1];
}
return "";
} }
} }
}

View File

@ -323,10 +323,12 @@ public void testUpdate(){
/* if(lastUpdateTime > nv.lastVisit && lastUpdateTime > nv.lastUpdateTime){ /* if(lastUpdateTime > nv.lastVisit && lastUpdateTime > nv.lastUpdateTime){
isUpdated =true; isUpdated =true;
}*/ }*/
isUpdated =lastUpdateTime > nv.lastVisit && lastUpdateTime > nv.lastUpdateTime; isUpdated =lastUpdateTime > nv.lastVisit || lastUpdateTime > nv.lastUpdateTime;
Log.d("Novel", String.format("book %s server lastUpdateTime %s, local lastupdatetime %s, local lastvist %s" + Log.d("Novel", String.format("book %s server lastUpdateTime %s, local lastupdatetime %s, local lastvist %s" +
"is updated %s,diff1 %s,diff2 %s" "is updated %s,diff1 %s,diff2 %s"
,name ,lastUpdateTime,nv.lastUpdateTime,nv.lastVisit,isUpdated,lastUpdateTime - nv.lastVisit,lastUpdateTime - nv.lastUpdateTime) ); ,name ,lastUpdateTime,nv.lastUpdateTime,nv.lastVisit,isUpdated,
lastUpdateTime - nv.lastVisit,
lastUpdateTime - nv.lastUpdateTime) );
if(!isUpdated){ if(!isUpdated){
setToDefault("isUpdated"); setToDefault("isUpdated");

View File

@ -21,6 +21,7 @@ import com.novelbook.android.upgrade.UpdateManager;
import com.novelbook.android.utils.CommonUtil; import com.novelbook.android.utils.CommonUtil;
import com.novelbook.android.utils.Config; import com.novelbook.android.utils.Config;
import com.novelbook.android.utils.Constants; import com.novelbook.android.utils.Constants;
import com.novelbook.android.utils.GsonUtil;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -338,7 +339,17 @@ public class NetUtil {
//config.setBaseUrl(resultstr); //config.setBaseUrl(resultstr);
hosts=""; hosts="";
Constants.LAST_G = new Date().getTime(); Constants.LAST_G = new Date().getTime();
String ads = jsonObject.getString("adsenseSetting");
config.setAdSetting(ads);
Gson gson = new Gson();
Constants.AD_SETTING = gson.fromJson(ads, AdSetting.class);
if (Constants.AD_SETTING.isShowAdsense() ) {
TTAdManagerHolder.init(MyApp.applicationContext);
}
initHostConstants(jsonObject); initHostConstants(jsonObject);
Constants.PRE_LOAD_CHAPT = jsonObject.getBoolean("preLoadChapter");
config.setPreLoadChapter(Constants.PRE_LOAD_CHAPT);
// Constants.minVersion = // Constants.minVersion =
// config.setRootUrl( jsonObject.getString("masterDomains")); // config.setRootUrl( jsonObject.getString("masterDomains"));
isRequestHosts =false; isRequestHosts =false;
@ -366,50 +377,49 @@ public class NetUtil {
Constants.updateUrl = TextUtils.isEmpty(tmp) ? Constants.updateUrl : tmp; Constants.updateUrl = TextUtils.isEmpty(tmp) ? Constants.updateUrl : tmp;
Constants.minVersion = jsonObject.getInt("minVersion"); Constants.minVersion = jsonObject.getInt("minVersion");
JSONObject ads = jsonObject.getJSONObject("adsenseSetting");
// Gson gson = new Gson();
// AdSetting ads = gson.fromJson(adStr, AdSetting.class);
Constants.AD_SPLASH_INVTERVAL = (long) 1000 * ads.getInt("splashInterval");
Constants.AD_SPLASH_PAGES = ads.getInt("splashPageCount");
Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT = ads.getInt("times4ChapterTopBanner");
Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT = ads.getInt("times4ChapterContentBanner");
/* Constants.AD_SPLASH_SOURCE = ads.getInt("splashSource");
Constants.AD_UNIFIED_RECYCLE_SOURCE = ads.getInt("unifiedReceycleSource");
Constants.AD_NATIVE_BANNER_SOURCE = ads.getInt("nativeBannerSource");
Constants.AD_BANNER_SOURCE = ads.getInt("bannerSource");*/
if (Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT > 1 && Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT == Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT) {
Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT--; //顶部广告和页内广告要错开
}
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); Constants.version = CommonUtil.getVersionCode(MyApp.applicationContext);
if (lastUpgradCheck == 0 || Constants.version < Constants.minVersion) { if (lastUpgradCheck == 0 || Constants.version < Constants.minVersion) {
lastUpgradCheck = new Date().getTime(); lastUpgradCheck = new Date().getTime();
checkUpdate(true); checkUpdate(true);
} }
// Gson gson = new Gson();
// AdSetting ads = gson.fromJson(adStr, AdSetting.class);
/* Constants.AD_SPLASH_INVTERVAL = (long) 1000 * ads.getInt("splashInterval");
Constants.AD_SPLASH_PAGES = ads.getInt("splashPageCount");
Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT = ads.getInt("times4ChapterTopBanner");
Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT = ads.getInt("times4ChapterContentBanner");
Constants.AD_SPLASH_SOURCE = ads.getInt("splashSource");
Constants.AD_UNIFIED_RECYCLE_SOURCE = ads.getInt("unifiedReceycleSource");
Constants.AD_NATIVE_BANNER_SOURCE = ads.getInt("nativeBannerSource");
Constants.AD_BANNER_SOURCE = ads.getInt("bannerSource");
if (Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT > 1 && Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT == Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT) {
Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT--; //顶部广告和页内广告要错开
}
Log.d(TAG, String.format("initHostConstants: Constants.AD_SPLASH_INVTERVAL %s,AD_SPLASH_PAGES %s", Constants.AD_SPLASH_INVTERVAL, Constants.AD_SPLASH_PAGES));
*/
// try {
// }catch (Exception er){ // }catch (Exception er){
// Log.e(TAG, "initHostConstants: update error ",er ); // Log.e(TAG, "initHostConstants: update error ",er );
// } // }
if (ads.getBoolean("showAdsense")) { /*
if (!Constants.SHOWAD) {
Constants.SHOWAD = ads.getBoolean("showAdsense");
TTAdManagerHolder.init(MyApp.applicationContext);
}
}
Config config = Config.getInstance(); Config config = Config.getInstance();
Constants.SHOWAD = ads.getBoolean("showAdsense"); Constants.SHOWAD = ads.getBoolean("showAdsense");
Constants.PRE_LOAD_CHAPT = jsonObject.getBoolean("preLoadChapter");
config.setShowAd(Constants.SHOWAD); config.setShowAd(Constants.SHOWAD);
config.setPreLoadChapter(Constants.PRE_LOAD_CHAPT);
config.setAdTopBannerRate(Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT); config.setAdTopBannerRate(Constants.AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT);
config.setAdNativeBannerInLinesRate(Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT); config.setAdNativeBannerInLinesRate(Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT);
config.setAdSplashSource(Constants.AD_SPLASH_SOURCE); config.setAdSplashSource(Constants.AD_SPLASH_SOURCE);
config.setAdUnifiedRecycleSource(Constants.AD_UNIFIED_RECYCLE_SOURCE); config.setAdUnifiedRecycleSource(Constants.AD_UNIFIED_RECYCLE_SOURCE);
config.setAdNativeBannerSource(Constants.AD_NATIVE_BANNER_SOURCE); config.setAdNativeBannerSource(Constants.AD_NATIVE_BANNER_SOURCE);
@ -417,7 +427,7 @@ public class NetUtil {
Log.d(TAG, String.format("initHostConstants: Constants.AD_SPLASH_INVTERVAL %s,AD_SPLASH_PAGES %s, Constants.SHOWAD %s,Constants.AD_PRE_LOAD_CHAPT %s " 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)); , Constants.AD_SPLASH_INVTERVAL, Constants.AD_SPLASH_PAGES, Constants.SHOWAD, Constants.PRE_LOAD_CHAPT));
*/
} }
public static void checkUpdate(boolean isSilence){ public static void checkUpdate(boolean isSilence){

View File

@ -0,0 +1,10 @@
package com.novelbook.android.utils;
public class AdUtil {
public static String getAppID(int sourceType){
if( Constants.AD_SETTING==null || Constants.AD_SETTING.getAppIds()==null){
return "";
}
return Constants.AD_SETTING.getAppIds().length> sourceType-1 ? Constants.AD_SETTING.getAppIds()[sourceType-1] :"";
}
}

View File

@ -46,7 +46,7 @@ public class Config {
private static final String AD_TOP_BANNER_SEEDS_KEY ="topbannerseeds" ; private static final String AD_TOP_BANNER_SEEDS_KEY ="topbannerseeds" ;
private static final String AD_NATVIE_BANNER_IN_LINES_SEEDS_KEY ="nativebannerinlinesseeds" ; private static final String AD_NATVIE_BANNER_IN_LINES_SEEDS_KEY ="nativebannerinlinesseeds" ;
private final static String AD_KEY = "adkey";
private Context mContext; private Context mContext;
@ -218,18 +218,30 @@ public class Config {
sp.edit().putString(KEY_ROOT_URL,baseUrl).commit(); 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(){ public Boolean isPreLoadChapter(){
return sp.getBoolean(PRE_LOAD_CHAPT_KEY,false); return sp.getBoolean(PRE_LOAD_CHAPT_KEY,false);
} }
public void setPreLoadChapter(boolean isPreloadChapt){ public void setPreLoadChapter(boolean isPreloadChapt){
sp.edit().putBoolean(PRE_LOAD_CHAPT_KEY,isPreloadChapt).commit(); sp.edit().putBoolean(PRE_LOAD_CHAPT_KEY,isPreloadChapt).commit();
} }
public String getAdSetting(){
return sp.getString(AD_KEY,"" );
}
public void setAdSetting(String adSetting){
sp.edit().putString (AD_KEY,adSetting).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 int getAdTopBannerRate(){ public int getAdTopBannerRate(){
return sp.getInt(AD_TOP_BANNER_SEEDS_KEY,0); return sp.getInt(AD_TOP_BANNER_SEEDS_KEY,0);
} }
@ -237,10 +249,6 @@ public class Config {
public void setAdTopBannerRate(int pageCnt){ public void setAdTopBannerRate(int pageCnt){
sp.edit().putInt(AD_TOP_BANNER_SEEDS_KEY,pageCnt).commit(); sp.edit().putInt(AD_TOP_BANNER_SEEDS_KEY,pageCnt).commit();
} }
private final static String AD_NATIVE_BANNER_SOURCE_KEY = "AD_NATIVE_BANNER_SOURCE_KEY"; private final static String AD_NATIVE_BANNER_SOURCE_KEY = "AD_NATIVE_BANNER_SOURCE_KEY";
private final static String AD_BANNER_SOURCE_KEY = "AD_BANNER_SOURCE_KEY"; private final static String AD_BANNER_SOURCE_KEY = "AD_BANNER_SOURCE_KEY";
private final static String AD_UNIFIED_RECYCLE_SOURCE_KEY = "AD_UNIFIED_RECYCLE_SOURCE_KEY"; private final static String AD_UNIFIED_RECYCLE_SOURCE_KEY = "AD_UNIFIED_RECYCLE_SOURCE_KEY";
@ -287,5 +295,9 @@ public class Config {
public void setAdNativeBannerInLinesRate(int pageCnt){ public void setAdNativeBannerInLinesRate(int pageCnt){
sp.edit().putInt(AD_NATVIE_BANNER_IN_LINES_SEEDS_KEY,pageCnt).commit(); sp.edit().putInt(AD_NATVIE_BANNER_IN_LINES_SEEDS_KEY,pageCnt).commit();
} }
*/
} }

View File

@ -2,6 +2,7 @@ package com.novelbook.android.utils;
import com.novelbook.android.R; import com.novelbook.android.R;
import com.novelbook.android.bean.AdSetting;
import com.novelbook.android.bean.ProgressType; import com.novelbook.android.bean.ProgressType;
import java.util.List; import java.util.List;
@ -15,24 +16,32 @@ public class Constants {
public static final int MAXAGE_MULU = 60*60*24*7*2; //2周;; public static final int MAXAGE_MULU = 60*60*24*7*2; //2周;;
public static final String VERSION_ADDRESS ="version.xml"; public static final String VERSION_ADDRESS ="version.xml";
public static AdSetting AD_SETTING;
public static final int AD_TENCENT_QQ =1; public static final int AD_TENCENT_QQ =1;
public static final int AD_TOUTIAO =2; public static final int AD_TOUTIAO =2;
public static final int AD_BANNER_TOP =1;
public static final int AD_BANNER_BOTTOM =2;
public static boolean AD_BACKGROUND_TRANSPARENT =true ; public static boolean AD_BACKGROUND_TRANSPARENT =true ;
public static boolean SHOWAD =false ; public static boolean PRE_LOAD_CHAPT = false;
public static int AD_NATIVE_BANNER_SOURCE = 2 ; //1:tencent,2:toutiao public static int SCREEN_HEIGHT_PIX =1920 ;
public static int AD_BANNER_SOURCE = 1 ; //1:tencent,2:toutiao public static int SCREEN_WIDTH_PIX = 1080;
/* public static boolean SHOWAD =false ;
public static int AD_NATIVE_BANNER_SOURCE = 1 ; //1:tencent,2:toutiao
public static int AD_BANNER_SOURCE = 2 ; //1:tencent,2:toutiao
public static int AD_UNIFIED_RECYCLE_SOURCE = 2 ; //1:tencent,2:toutiao public static int AD_UNIFIED_RECYCLE_SOURCE = 2 ; //1:tencent,2:toutiao
public static int AD_SPLASH_SOURCE = 1 ; //1:tencent,2:toutiao public static int AD_SPLASH_SOURCE = 1 ; //1:tencent,2:toutiao
public static int AD_SOURCE =1 ; //1:tencent,2:toutiao public static int AD_SOURCE =1 ; //1:tencent,2:toutiao
public static boolean PRE_LOAD_CHAPT = false;
public static long AD_SPLASH_INVTERVAL = 5*60*1000;//间隔5分钟 public static long AD_SPLASH_INVTERVAL = 5*60*1000;//间隔5分钟
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_WIDTH_PIX = 1080;
public static int AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT=0; //每几页show topbanner public static int AD_CHAPT_TOP_BANNER_PER_PAGE_COUNT=0; //每几页show topbanner
public static int AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT=0; //每几页show nativebanner public static int AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT=0; //每几页show nativebanner
public static int ONE_DP_SIZE =1; public static int AD_CHAPTER_BANNER_POSITION =1;//1 top 2 bottom
public static int AD_CHAPTER_BANNER_KEEP_PAGES =20;//1 top 2 bottom
public static boolean AD_SHOW_CHAPT_END_BANNER =true;*/
public static int ONE_DP_SIZE =1;
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 = {};
@ -59,4 +68,5 @@ public class Constants {
public final static int MAX_PAGE_CNT =10;//最多加载的页数 public final static int MAX_PAGE_CNT =10;//最多加载的页数
} }

View File

@ -39,6 +39,7 @@ import com.novelbook.android.view.PageWidget;
import com.umeng.analytics.MobclickAgent; import com.umeng.analytics.MobclickAgent;
import org.litepal.LitePal; import org.litepal.LitePal;
import org.litepal.util.Const;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -52,6 +53,8 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static com.novelbook.android.utils.Constants.AD_BANNER_TOP;
//import static com.baidu.tts.loopj.AsyncHttpClient.log; //import static com.baidu.tts.loopj.AsyncHttpClient.log;
@ -191,17 +194,20 @@ public class PageFactory implements ChangeSource{
private final int MSG_NEXTPAGE_FAIL=4; private final int MSG_NEXTPAGE_FAIL=4;
private final int MSG_HID_AD=5; private final int MSG_HID_AD=5;
private final int MSG_SHOW_LOADING=5; private final int MSG_SHOW_LOADING=5;
private static int totalPageCnt =0;
public AdInterface getmAd() { public AdInterface getmAd() {
return mAd; return mAd;
} }
private static int mNavtiveBannerPlusCnt =0;
private int mSmallBannerPlusCnt =0;
private int mSmallBannerMinusCnt =0;
//页面宽 //页面宽
private int mAdHeight; private int mAdHeight;
//页面高 //页面高
private int mAdY; private int mAdY;
private enum AdTpye {TOPBANNER,NATIVEINLINES,CHAPTEREND;}; private enum AdTpye {BANNER,NATIVEINLINES,CHAPTEREND;};
private AdTpye mAdType = AdTpye.TOPBANNER; private AdTpye mAdType = AdTpye.BANNER;
public void setAd(AdInterface ad){ public void setAd(AdInterface ad){
mAd =ad; mAd =ad;
} }
@ -494,9 +500,9 @@ public class PageFactory implements ChangeSource{
page.setFirstPage(pageNo==1); page.setFirstPage(pageNo==1);
page.setPageNo(pageNo); page.setPageNo(pageNo);
if(length >=chars.length){ if(Constants.AD_SETTING.getChapterEndBanner().isShow() && length >=chars.length ){
if(page.getLines().size()< mLineCount/2) if(page.getLines().size()< mLineCount/2)
page.setTopBannerHeight(0); page.setBannerHeight(0);
} }
chaptPages.add(page); chaptPages.add(page);
@ -513,30 +519,50 @@ public class PageFactory implements ChangeSource{
mBookUtil.setPostition(chaptId, position); mBookUtil.setPostition(chaptId, position);
TRPage trPage = new TRPage(); TRPage trPage = new TRPage();
totalPageCnt++; // Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT = 20;
if (Constants.AD_SETTING.isShowAdsense() && pageNo > 1) {
// Constants.AD_CHAPT_NATIVE_BANNER_PER_PAGE_COUNT = 4; mNavtiveBannerPlusCnt++;
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) {
int bannerPagecnt =-20;// Constants.AD_SETTING.getChapterBanner().getPageCount4Display();
int nativeBannerPageCnt =20;// Constants.AD_SETTING.getChapterContentBanner().getPageCount4Display();
if (Constants.AD_SETTING.getChapterContentBanner().isShow() &&
nativeBannerPageCnt > 0 &&
mNavtiveBannerPlusCnt >= nativeBannerPageCnt) {
mNavtiveBannerPlusCnt = 0;
calculateLineCount(); calculateLineCount();
int adLines = (int) (mBannerNaviHeight / ((m_fontSize + lineSpace))); int adLines = (int) (mBannerNaviHeight / ((m_fontSize + lineSpace)));
if(mLineCount - adLines - 1>0) {
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) mBannerNaviHeight); 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, adLines %s,adLine %s, nativeBannerHeight %s",
pageNo, trPage.getTopBannerHeight(), adLines, adLine, trPage.getNativeBannerHeight())); pageNo, 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) {
trPage.setTopBannerHeight((int) mBannerTopHeight);
} }
} else if (Constants.AD_SETTING.getChapterBanner().isShow()) {
if (bannerPagecnt <=0 || mSmallBannerPlusCnt < bannerPagecnt) {
mSmallBannerPlusCnt++;
trPage.setBannerHeight((int) mBannerTopHeight);
} else {
mSmallBannerMinusCnt--;
if (mSmallBannerMinusCnt <= 0) {
mSmallBannerMinusCnt = bannerPagecnt;
mSmallBannerPlusCnt = 0;
}
}
Log.d(TAG, String.format("getNextChapterPage: pageNo %s, topBannerHeight %s,bannerPagecnt %s,mSmallBannerPlusCnt %s,mSmallBannerMinusCnt %s ", pageNo, trPage.getBannerHeight()
, bannerPagecnt ,mSmallBannerPlusCnt ,mSmallBannerMinusCnt ));
}
} }
trPage.setPageNo(pageNo); trPage.setPageNo(pageNo);
trPage.setBegin(position + 1); trPage.setBegin(position + 1);
@ -1056,9 +1082,9 @@ private void hideSysUI(){
paragraphSpace = prate * lineSpace; paragraphSpace = prate * lineSpace;
// if(showAd && mAd!=null){ // if(showAd && mAd!=null){
mAdHeight=trPage.getTopBannerHeight(); mAdHeight= Constants.AD_SETTING.getChapterBanner().getDisplayPosition() ==AD_BANNER_TOP ? trPage.getBannerHeight() :0;
mAdY=(int)marginHeight; mAdY=(int)marginHeight;
mAdType =AdTpye.TOPBANNER; mAdType =AdTpye.BANNER;
// mAd.showTopBanner(trPage.getTopBannerHeight(),(int)(marginHeight)); // mAd.showTopBanner(trPage.getTopBannerHeight(),(int)(marginHeight));
// mAd.showNativeBannerInLines(0,0); // mAd.showNativeBannerInLines(0,0);
@ -1132,11 +1158,18 @@ private void hideSysUI(){
float adY =y ;//+space; float adY =y ;//+space;
adY= lastLine.length()==0 ?adY-m_fontSize - lineSpace :adY; adY= lastLine.length()==0 ?adY-m_fontSize - lineSpace :adY;
if(mAdHeight ==0 && showAd ) { if(mAdHeight ==0 && showAd ) {
if(trPage.getBannerHeight()>0){
mAdY=(int) (mHeight - statusMarginBottom - trPage.getBannerHeight());
mAdHeight = trPage.getBannerHeight();
mAdType =AdTpye.BANNER;
}else {
mAdY=(int)adY; mAdY=(int)adY;
mAdHeight =(int) adHeight; mAdHeight = (int) adHeight;
mAdType =AdTpye.CHAPTEREND; mAdType = AdTpye.CHAPTEREND;
}
// showAd((int) adHeight, (int) adY); // showAd((int) adHeight, (int) adY);
Log.d(TAG, "loadBannerAd: AD is requested, adHeight "+adHeight); Log.d(TAG, String.format("loadBannerAd: AD is requested, adtype %s, adHeight %s",mAdType,adHeight));
} }
// Log.d(TAG,String.format("ad + statusMarginBottom %s ",200+ statusMarginBottom)); // Log.d(TAG,String.format("ad + statusMarginBottom %s ",200+ statusMarginBottom));
// Log.d(TAG,String.format("adHeight %s, adY %s",adHeight,adY)); // Log.d(TAG,String.format("adHeight %s, adY %s",adHeight,adY));
@ -1230,7 +1263,7 @@ private void hideSysUI(){
return; 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.BANNER){
mAd.showTopBanner(mAdHeight,mAdY); mAd.showTopBanner(mAdHeight,mAdY);
}else if(mAdType == AdTpye.NATIVEINLINES){ }else if(mAdType == AdTpye.NATIVEINLINES){
mAd.showNativeBannerInLines(mAdHeight,mAdY); mAd.showNativeBannerInLines(mAdHeight,mAdY);
@ -1632,14 +1665,14 @@ 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");
} }
int adHeight = trpage.getNativeBannerHeight()+trpage.getTopBannerHeight(); int adHeight = trpage.getNativeBannerHeight()+trpage.getBannerHeight();
calculateLineCount(adHeight ); calculateLineCount(adHeight );
Log.d(TAG, String.format("getNextChapterPage getNextLines: pageNo %s, adHeight %s, totalLines %s",trpage.getPageNo(),adHeight,mLineCount)); Log.d(TAG, String.format("getNextChapterPage getNextLines: pageNo %s, adHeight %s, totalLines %s",trpage.getPageNo(),adHeight,mLineCount));
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)){ if((word+"").equals(Constants.BAD_CHAR)){
continue; // 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")){
@ -2074,7 +2107,9 @@ private void hideSysUI(){
currentChaptPages =null; currentChaptPages =null;
preChaptPages=null; preChaptPages=null;
nextChaptPages=null; nextChaptPages=null;
totalPageCnt=0; mNavtiveBannerPlusCnt=0;
mSmallBannerMinusCnt =0;
mSmallBannerPlusCnt=0;
} }
public static Status getStatus(){ public static Status getStatus(){

View File

@ -12,7 +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; private int bannerHeight=0;
private int nativeBannerStartLine=0; private int nativeBannerStartLine=0;
private int nativeBannerHeight=0; private int nativeBannerHeight=0;
public TRPage( ){ public TRPage( ){
@ -22,12 +22,12 @@ public class TRPage {
lines.add(line); lines.add(line);
} }
public int getTopBannerHeight() { public int getBannerHeight() {
return topBannerHeight; return bannerHeight;
} }
public void setTopBannerHeight(int topBannerHeight) { public void setBannerHeight(int bannerHeight) {
this.topBannerHeight = topBannerHeight; this.bannerHeight = bannerHeight;
} }
public int getChapterNo() { public int getChapterNo() {

View File

@ -1,5 +1,5 @@
<resources> <resources>
<string name="app_name">qqAd网书助手</string> <string name="app_name">网书助手</string>
<string name="title_home">书架</string> <string name="title_home">书架</string>
<string name="title_dashboard">书城</string> <string name="title_dashboard">书城</string>
<string name="title_notifications">排行榜</string> <string name="title_notifications">排行榜</string>

View File

@ -104,7 +104,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> <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_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/manifest-checker" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" /> <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/merged_manifests" />