package com.weikou.beibeivideo.util.ad;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
import com.weikou.beibeivideo.entity.ad.AdTypeVO;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.weikou.beibeivideo.util.downutil.StringUtils;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
//广告帮助
|
public class AdUtil {
|
|
public enum AD_TYPE {
|
gdt("广点通"), csj("穿山甲"), gdt2("广点通2.0");
|
|
private String name;
|
|
private AD_TYPE(String name) {
|
this.name = name;
|
}
|
|
}
|
|
public final static String POSITION_SPLASH = "splash";//开屏
|
public final static String POSITION_VIDEO_PLAY_PRE = "videoPlayPre";//视频播放前贴
|
public final static String POSITION_EXIT_APP = "exitApp";//APP退出广告
|
|
public static AD_TYPE getSmallExpressAdType() {
|
if (BeibeiConstant.AD_TYPE != null && AdTypeVO.TYPE_CSJ.equalsIgnoreCase(BeibeiConstant.AD_TYPE.getExpressSmallType())) {
|
return AD_TYPE.csj;
|
} else {
|
return AD_TYPE.gdt;
|
}
|
}
|
|
public static AD_TYPE getBigExpressAdType() {
|
if (BeibeiConstant.AD_TYPE != null && AdTypeVO.TYPE_CSJ.equalsIgnoreCase(BeibeiConstant.AD_TYPE.getExpressBigType())) {
|
return AD_TYPE.csj;
|
} else {
|
return AD_TYPE.gdt2;
|
}
|
}
|
|
/**
|
* 保存广告配置
|
*
|
* @param context
|
* @param json
|
*/
|
public static void saveAdConfig(Context context, JSONObject json) {
|
SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = share.edit();
|
editor.putString("config", json.toString());
|
editor.commit();
|
}
|
|
/**
|
* 获取广告类型
|
*
|
* @param context
|
* @param positionName
|
* @return
|
*/
|
public static AD_TYPE getAdType(Context context, String positionName) {
|
SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
|
String config = share.getString("config", "");
|
if (!StringUtils.isNullOrEmpty(config)) {//万一没设置起就用广点通
|
try {
|
JSONObject object = new JSONObject(config);
|
return AD_TYPE.valueOf(object.optString(positionName));
|
} catch (JSONException e) {
|
e.printStackTrace();
|
} catch (Exception e1) {
|
return null;
|
}
|
} else {
|
return AD_TYPE.gdt;
|
}
|
return null;
|
}
|
|
|
}
|