Commit 34487f7d authored by jyx's avatar jyx

大转盘换原生

parent 5ad33492
......@@ -273,7 +273,13 @@ dependencies {
implementation(name: 'tzsdk_core-3.0.0-20200807131516-release', ext: 'aar')
implementation(name: 'tzsdk_reporter-3.0.0-20200807131516-release', ext: 'aar')
// 快手
implementation(name: 'kssdk-ad-3.3.6-publishRelease', ext: 'aar')
// implementation(name: 'kssdk-ad-3.3.6-publishRelease', ext: 'aar')
implementation(name: 'kssdk-all--3.3.16-publishRelease-9ffe2b94e', ext: 'aar')
// SDK v2.6.4版本开始,SDK依赖appcompat-v7库,请确保工程中有appcompat-v7
implementation 'com.android.support:appcompat-v7:27.0.2'
// 2.6.5之后的版本,SDK有依赖recyclerview-v7
implementation 'com.android.support:recyclerview-v7:27.0.2'
// 抖音滑动LayoutManager
implementation(name: 'LayoutManagerGroup', ext: 'aar')
// 蘑菇星球
......@@ -285,11 +291,14 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-scalars:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
// 跑马灯
implementation 'com.sunfusheng:marqueeview:1.2.0'
// 激励视频RTA
implementation(name: 'taskwake1.0', ext: 'aar')
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
// testImplementation 'junit:junit:4.13'
// androidTestImplementation 'androidx.test.ext:junit:1.1.2'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
......
......@@ -122,7 +122,7 @@ public class MintsApplication extends MultiDexApplication {
TtCsjAdManager.init(this);
// 快手
// KsManager.INSTANCE.initKs(this);
KsManager.INSTANCE.initKs(this);
// 闪电盒子
WnManager.INSTANCE.initWn(this);
......@@ -131,7 +131,7 @@ public class MintsApplication extends MultiDexApplication {
MhManager.INSTANCE.initMn(this);
// 天卓珊瑚
// TzManager.INSTANCE.initTz(this);
TzManager.INSTANCE.initTz(this);
// 一览视频
YlVideoManager.INSTANCE.init(this);
......
package com.mints.fairyland.ad.express
import android.annotation.SuppressLint
import android.content.DialogInterface
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
......@@ -190,6 +191,10 @@ object KsPreLoadExpressManager {
// Toast.makeText(mContext, "广告" + ad.appName + "展示", Toast.LENGTH_SHORT).show()
}
}
override fun handleDownloadDialog(p0: DialogInterface.OnClickListener?): Boolean {
return false
}
})
// 广告描述
......
......@@ -120,6 +120,10 @@ class KsVideoAdManager private constructor(activity: Activity) :
}
}
override fun onRequestResult(p0: Int) {
}
})
......
......@@ -7,7 +7,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;
import com.mints.fairyland.MintsApplication;
import com.mints.fairyland.ad.video.base.VideoAdStatusListener;
import com.mints.fairyland.common.AppConfig;
import com.mints.fairyland.common.Constant;
......@@ -17,10 +16,11 @@ import com.mints.fairyland.mvp.model.WeightBean;
import com.mints.fairyland.service.AppInstallService;
import com.mints.fairyland.utils.AppUtil;
import com.mints.fairyland.utils.LogUtil;
import com.mints.fairyland.utils.ToastUtil;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
/**
......@@ -32,9 +32,6 @@ public class VideoAdingManager {
private static VideoAdingManager _inst;
// APP下载回调广播
private BroadcastReceiver mReceiverBroadcastReceiver = null;
private VideoAdingListener videoAdingListener;
private WnVideoAdManager wnVideoAdManager;
......@@ -44,7 +41,6 @@ public class VideoAdingManager {
private ShVideoAdManager shVideoAdManager;
private CsjFullVideoAdManager csjFullVideoAdManager;
private KsVideoAdManager ksVideoAdManager;
private RTAVideoAdManager rtaVideoAdManager;
private int wnWeight;
private int ylhWeight;
......@@ -53,7 +49,6 @@ public class VideoAdingManager {
private int shVideoWeight;
private int csjFullVideoWeight;
private int ksVideoWeight;
private int rtaVideoWeight;
private ArrayList<WeightBean> weightList;
......@@ -64,6 +59,9 @@ public class VideoAdingManager {
private Activity activity;
private boolean isVideoAdDownload = false;// 是否点击广告下载 true-点击
private ArrayList<String> currentRandomAdList;//当前随机出的广告渠道
private ArrayList<String> adList;//广告渠道
public static VideoAdingManager getInstance(Activity activity) {
if (_inst == null) {
WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
......@@ -79,21 +77,23 @@ public class VideoAdingManager {
/**
* 初始化广告manager
*
* @param activity _
* @param activity
*/
private void init(Activity activity) {
this.activity = activity;
csjVideoAdManager = CsjVideoAdManager.getInstance(activity);
ylhVideoAdManager = YlhVideoAdManager.getInstance();
csjFullVideoAdManager = CsjFullVideoAdManager.getInstance(activity);
wnVideoAdManager = WnVideoAdManager.Companion.getInstance(activity);
mhVideoAdManager = MhVideoAdManager.Companion.getInstance(activity);
shVideoAdManager = ShVideoAdManager.Companion.getInstance(activity);
csjFullVideoAdManager = CsjFullVideoAdManager.getInstance(activity);
ksVideoAdManager = KsVideoAdManager.Companion.getInstance(activity);
rtaVideoAdManager = RTAVideoAdManager.Companion.getInstance(activity);
weightList = new ArrayList<>();
}
// APP下载回调广播
private BroadcastReceiver mReceiverBroadcastReceiver = null;
private void registerBroad() {
if (AppConfig.isSuperTask) {
return;
......@@ -133,10 +133,14 @@ public class VideoAdingManager {
/**
* 初始化广告权重
*/
public void initAdWeight(int csjVideoWeight, int ylhWeight,
int wnWeight, int flVideoWeight,
int shVideoWeight, int csjFullVideoWeight,
int ksVideoWeight, int rtaVideoWeight) {
public void initAdWeight(
int csjVideoWeight,
int ylhWeight,
int wnWeight,
int flVideoWeight,
int shVideoWeight,
int csjFullVideoWeight,
int ksVideoWeight) {
this.csjVideoWeight = csjVideoWeight;
this.ylhWeight = ylhWeight;
this.wnWeight = wnWeight;
......@@ -144,84 +148,58 @@ public class VideoAdingManager {
this.shVideoWeight = shVideoWeight;
this.csjFullVideoWeight = csjFullVideoWeight;
this.ksVideoWeight = ksVideoWeight;
this.rtaVideoWeight = rtaVideoWeight;
}
/**
* 根据类型加载对应视频(第一次加载)
*
* @param bean _
* @param bean
*/
public void loadAding(Activity activity, VideoAdingBean bean) {
WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
this.activity = activityWeakReference.get();
isVideoAdDownload = false;
if (AppConfig.flVideoFlag) {
// 先展示枫岚视频
firstLoadFlVideo(bean);
} else {
// 权重自有逻辑
loadAdVideo(getVideoAdType(), bean);
}
}
/**
* 根据载体优先加载枫岚
*
* @param bean _
*/
private void firstLoadFlVideo(VideoAdingBean bean) {
String adType;
switch (bean.getCarrierType()) {
case Constant.CARRIER_VERSUS_VIDEO:
case Constant.CARRIER_HOMEWATER:
case Constant.CARRIER_WALK:
case Constant.CARRIER_WALK_BUBBLE:
case Constant.CARRIER_SIGNIN_HOMEPAGE_CARD:
case Constant.CARRIER_OFFLINE_DOUBLE:
case Constant.CARRIER_EATMEAL_SUBSIDY:
adType = Constant.FL_VEDIO_AD;
// ToastUtil.showLong(activity, "载体优先类型:" + Constant.FL_VEDIO_AD);
break;
default:
adType = getVideoAdType();
break;
}
loadAdVideo(adType, bean);
}
/**
* 加载失败优先级对应视频
*
* @param bean _
* @param bean
*/
public void loadFailAding(Activity activity, VideoAdingBean bean) {
WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
this.activity = activityWeakReference.get();
isVideoAdDownload = false;
loadAdVideo(getNextAdType(), bean);
loadAdVideo(getNextFailAdType(), bean);
}
/**
* 根据广告优先级获取下一个
* 穿山甲->优量汇->穿山甲全屏->快手->珊瑚->闪电盒子->RTA->枫岚(兜底)
* <p>
* 穿山甲>优量汇>穿山甲全屏>快手>珊瑚>闪电盒子>枫岚(兜底)
*/
private String getNextAdType() {
String nextAdType;
if (AppConfig.csjVideoAdCount > 0) {
nextAdType = Constant.CSJ_VEDIO_AD;
} else if (AppConfig.ylhAdCount > 0) {
nextAdType = Constant.YLH_VEDIO_AD;
} else if (AppConfig.csjFullVideoAdCount > 0) {
nextAdType = Constant.CSJ_FULL_AD;
} else if (AppConfig.ksVideoAdCount > 0) {
nextAdType = Constant.KS_VEDIO_AD;
} else if (AppConfig.shVideoAdCount > 0) {
nextAdType = Constant.SH_VEDIO_AD;
} else {
nextAdType = Constant.FL_VEDIO_AD;
private String getNextFailAdType() {
// 高额任务时 会为空
if (adList == null || currentRandomAdList == null) {
return getHighWeight();
}
String nextAdType = Constant.FL_VEDIO_AD;
try {
List<String> tempList = listrem(adList, currentRandomAdList);
for (String code : tempList) {
nextAdType = getAdtype(code);
currentRandomAdList.add(code);
LogUtil.d(TAG, "失败返回adType:" + nextAdType);
break;
}
} catch (Exception e) {
LogUtil.d(TAG, "失败返回Error");
e.printStackTrace();
}
return nextAdType;
}
......@@ -239,6 +217,10 @@ public class VideoAdingManager {
}
isHighWeight = false;
if (currentRandomAdList != null) {
currentRandomAdList.add(getCode(adType));
}
LogUtil.d(TAG, "权重结果返回的广告类型:" + adType);
return adType;
}
......@@ -250,7 +232,7 @@ public class VideoAdingManager {
/**
* 高额任务广告类型
*
* @return _
* @return
*/
private String getHighWeight() {
isTTVideoAd = !isTTVideoAd;
......@@ -264,9 +246,18 @@ public class VideoAdingManager {
/**
* 根据权重获取广告类型
*
* @return _
* @return
*/
private String getRandomWeight() {
if (currentRandomAdList == null) {
currentRandomAdList = new ArrayList<>();
}
currentRandomAdList.clear();
if (adList == null) {
adList = new ArrayList<>();
}
adList.clear();
if (weightList != null) {
weightList.clear();
}
......@@ -276,41 +267,43 @@ public class VideoAdingManager {
weightList.add(new WeightBean(csjVideoWeight, Constant.CSJ_VEDIO_AD));
weight = weight + csjVideoWeight;
LogUtil.d(TAG, "权重值:csjVideoWeight:" + csjVideoWeight);
adList.add("a");
}
if (AppConfig.ylhAdCount > 0) {
weightList.add(new WeightBean(ylhWeight, Constant.YLH_VEDIO_AD));
weight = weight + ylhWeight;
LogUtil.d(TAG, "权重值:ylhWeight:" + ylhWeight);
adList.add("b");
}
if (AppConfig.csjFullVideoAdCount > 0) {
if (AppConfig.csjFullVedioAdCount > 0) {
weightList.add(new WeightBean(csjFullVideoWeight, Constant.CSJ_FULL_AD));
weight = weight + csjFullVideoWeight;
LogUtil.d(TAG, "权重值:csjFullVideoWeight:" + csjFullVideoWeight);
adList.add("c");
}
if (AppConfig.ksVideoAdCount > 0) {
weightList.add(new WeightBean(ksVideoWeight, Constant.KS_VEDIO_AD));
weight = weight + ksVideoWeight;
LogUtil.d(TAG, "权重值:ksWeight:" + ksVideoWeight);
if (AppConfig.wnVideoAdCount > 0) {
weightList.add(new WeightBean(wnWeight, Constant.SDHZ_VEDIO_AD));
weight = weight + wnWeight;
LogUtil.d(TAG, "权重值:sdhzWeight:" + wnWeight);
adList.add("d");
}
if (AppConfig.shVideoAdCount > 0) {
weightList.add(new WeightBean(shVideoWeight, Constant.SH_VEDIO_AD));
weight = weight + shVideoWeight;
LogUtil.d(TAG, "权重值:shWeight:" + shVideoWeight);
adList.add("e");
}
if (AppConfig.wnVideoAdCount > 0) {
weightList.add(new WeightBean(wnWeight, Constant.SDHZ_VEDIO_AD));
weight = weight + wnWeight;
LogUtil.d(TAG, "权重值:sdhzWeight:" + wnWeight);
}
if (AppConfig.rtaVideoAdCount > 0) {
weightList.add(new WeightBean(rtaVideoWeight, Constant.RTA_VEDIO_AD));
weight = weight + rtaVideoWeight;
LogUtil.d(TAG, "权重值:rtaWeight:" + rtaVideoWeight);
if (AppConfig.ksVideoAdCount > 0) {
weightList.add(new WeightBean(ksVideoWeight, Constant.KS_VEDIO_AD));
weight = weight + ksVideoWeight;
LogUtil.d(TAG, "权重值:ksWeight:" + ksVideoWeight);
adList.add("f");
}
if (AppConfig.flVideoAdCount > 0) {
weightList.add(new WeightBean(flVideoWeight, Constant.FL_VEDIO_AD));
weight = weight + flVideoWeight;
LogUtil.d(TAG, "权重值:flVideoWeight:" + flVideoWeight);
adList.add("g");
}
// 权重随机
......@@ -319,9 +312,7 @@ public class VideoAdingManager {
Random r = new Random();
int randomWeight = r.nextInt(weight) + 1;
LogUtil.d(TAG, "2、权重随机值:" + randomWeight);
// ToastUtil.show(MintsApplication.getContext(), "权重随机值:" + randomWeight);
// ToastUtil.show(MintsApplication.getContext(),"权重随机值:" + randomWeight);
for (WeightBean weightBean : weightList) {
randomWeight -= weightBean.getWeight();
if (randomWeight <= 0) {
......@@ -353,19 +344,8 @@ public class VideoAdingManager {
int wnAdCount = AppConfig.wnVideoAdCount;
int flVideoAdCount = AppConfig.flVideoAdCount;
int tzVideoAdCount = AppConfig.shVideoAdCount;
int ksVideoAdCount = AppConfig.ksVideoAdCount;
int rtaVideoAdCount = AppConfig.rtaVideoAdCount;
int csjFullVideoAdCount = AppConfig.csjFullVideoAdCount;
if (ylhAdCount <= 0 &&
csjVideoAdCount <= 0 &&
wnAdCount <= 0 &&
flVideoAdCount <= 0 &&
tzVideoAdCount <= 0 &&
csjFullVideoAdCount <= 0 &&
ksVideoAdCount <= 0 &&
rtaVideoAdCount <= 0) {
// showToast("今日视频已看完,请明天再来吧");
if (ylhAdCount <= 0 && csjVideoAdCount <= 0 && wnAdCount <= 0 && flVideoAdCount <= 0 && tzVideoAdCount <= 0) {
return true;
}
return false;
......@@ -405,16 +385,6 @@ public class VideoAdingManager {
shVideoAdManager.onDestroy();
shVideoAdManager = null;
}
if (ksVideoAdManager != null) {
ksVideoAdManager.setVideoAdStatusListener(null);
ksVideoAdManager.onDestroy();
ksVideoAdManager = null;
}
if (rtaVideoAdManager != null) {
rtaVideoAdManager.setVideoAdStatusListener(null);
rtaVideoAdManager.onDestroy();
rtaVideoAdManager = null;
}
if (mReceiverBroadcastReceiver != null) {
activity.stopService(new Intent(activity, AppInstallService.class));
......@@ -422,9 +392,30 @@ public class VideoAdingManager {
mReceiverBroadcastReceiver = null;
}
currentRandomAdList = null;
adList = null;
activity = null;
}
/**
* 从listA里删除listB里有的数据
*
* @param adList
* @param currentRandomAdList
* @return
*/
public List<String> listrem(List<String> adList, List<String> currentRandomAdList) {
HashSet hs1 = new HashSet(adList);
HashSet hs2 = new HashSet(currentRandomAdList);
// LogUtil.d(TAG, "权重List:" + JsonUtil.toJson(adList));
// LogUtil.d(TAG, "过滤List:" + JsonUtil.toJson(currentRandomAdList));
hs1.removeAll(hs2);
List<String> listC = new ArrayList<String>();
listC.addAll(hs1);
return listC;
}
public void setVideoAdingListener(VideoAdingListener videoAdingListener) {
this.videoAdingListener = videoAdingListener;
}
......@@ -611,7 +602,7 @@ public class VideoAdingManager {
csjFullVideoAdManager.setVideoAdStatusListener(new VideoAdStatusListener() {
@Override
public void adSuccess() {
AppConfig.csjFullVideoAdCount--;
AppConfig.csjFullVedioAdCount--;
if (videoAdingListener != null) {
videoAdingListener.videoAdingListenerSuccess(Constant.CSJ_FULL_AD);
}
......@@ -708,50 +699,62 @@ public class VideoAdingManager {
});
ksVideoAdManager.loadAd(activity, bean.getCurCoin(), bean.getCarrierType(), bean.getExtraId());
} else if (TextUtils.equals(videoAdType, Constant.RTA_VEDIO_AD)) {
// RTA广告激励视频
if (rtaVideoAdManager == null) {
if (activity == null) {
if (videoAdingListener != null) {
videoAdingListener.videoAdingListenerError(Constant.RTA_VEDIO_AD);
}
return;
}
rtaVideoAdManager = RTAVideoAdManager.Companion.getInstance(activity);
}
rtaVideoAdManager.setVideoAdStatusListener(new VideoAdStatusListener() {
@Override
public void adSuccess() {
AppConfig.rtaVideoAdCount--;
if (videoAdingListener != null) {
videoAdingListener.videoAdingListenerSuccess(Constant.RTA_VEDIO_AD);
}
}
@Override
public void adFail() {
} catch (Exception e) {
e.printStackTrace();
if (videoAdingListener != null) {
videoAdingListener.videoAdingListenerFail(Constant.RTA_VEDIO_AD);
videoAdingListener.videoAdingListenerError(bean.getCarrierType());
}
}
@Override
public void adDownload() {
isVideoAdDownload = true;
// 注册下载任务监听
registerBroad();
}
});
rtaVideoAdManager.loadAd(activity, bean.getCurCoin(), bean.getCarrierType(), bean.getExtraId());
private String getCode(String adtype) {
String code = "g";
switch (adtype) {
case Constant.CSJ_VEDIO_AD:
code = "a";
break;
case Constant.YLH_VEDIO_AD:
code = "b";
break;
case Constant.CSJ_FULL_AD:
code = "c";
break;
case Constant.SDHZ_VEDIO_AD:
code = "d";
break;
case Constant.SH_VEDIO_AD:
code = "e";
break;
case Constant.KS_VEDIO_AD:
code = "f";
break;
}
} catch (Exception e) {
e.printStackTrace();
if (videoAdingListener != null) {
videoAdingListener.videoAdingListenerError(bean.getCarrierType());
return code;
}
private String getAdtype(String code) {
String adtype = Constant.FL_VEDIO_AD;
switch (code) {
case "a":
adtype = Constant.CSJ_VEDIO_AD;
break;
case "b":
adtype = Constant.YLH_VEDIO_AD;
break;
case "c":
adtype = Constant.CSJ_FULL_AD;
break;
case "d":
adtype = Constant.SDHZ_VEDIO_AD;
break;
case "e":
adtype = Constant.SH_VEDIO_AD;
break;
case "f":
adtype = Constant.KS_VEDIO_AD;
break;
}
return adtype;
}
}
\ No newline at end of file
......@@ -101,7 +101,10 @@ public class AppConfig {
* rtaVideo 剩余广告播放数
*/
public static int rtaVideoAdCount = 5;
/**
* csjFull 剩余广告播放数
*/
public static int csjFullVedioAdCount = 0;
/**
* 高额试玩任务标识
*/
......@@ -132,4 +135,8 @@ public class AppConfig {
*/
public static boolean isSuperTask = false;
/**
* 激励视频是否休眠 false-不休眠 提示:加载失败,请稍后重试。
*/
public static boolean isVideoSleep = false;
}
......@@ -12,17 +12,17 @@ import com.mints.fairyland.R
*/
object KsManager {
private const val KS_APP_ID = ""
private const val KS_APP_ID = "574600003"
/* splash-postid */
const val KS_AD_SPLASH_POSTID = 0L
/*信息流*/
val KS_AD_NATIVEEXPRESS_DRAW = 0L
const val KS_AD_NATIVEEXPRESS_AWARD = 0L
const val KS_AD_NATIVEEXPRESS_AWARD = 5746000012L
/* vedio-postid */
const val KS_AD_VEDIO_POSTID = 0L
const val KS_AD_VEDIO_POSTID = 5746000011L
/**
* 初始化
......
......@@ -125,4 +125,11 @@ public class TrackManager {
trackPresenter.reportAddCoinMsg(activity, vo);
}
}
public void getAdWeight() {
if (trackPresenter != null && !TextUtils.isEmpty(UserManager.getInstance().getUserID())) {
trackPresenter.getAdWeight();
}
}
}
......@@ -18,8 +18,8 @@ object TzManager {
fun initTz(application: Application) {
ADEngine.getInstance(application)
.start(ADEngineConfig.Builder(application)
.appKey("")
.appSecret("")
.appKey("4f064c84540f458eed9e99d3545525fd")
.appSecret("ffd0594f3fb0b57258c3a611575c6aa1")
.appChannel(CommonUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME"))
.forTest(false)
.build(),
......
package com.mints.fairyland.manager
import com.mints.fairyland.ad.video.VideoAdingManager
import com.mints.fairyland.common.AppConfig
import com.mints.fairyland.mvp.model.UserTaskMsgBean
import com.mints.fairyland.utils.ForegroundOrBackground
import com.mints.fairyland.utils.LogUtil
/**
* 描述:用户广告视频数和权重
* 作者:孟崔广
*/
object UserWeight {
private val TAG = UserWeight::class.java.simpleName
private val videoAdingManager by lazy { VideoAdingManager.getInstance(ForegroundOrBackground.getApp_activity()) }
fun initAdWeight(data: UserTaskMsgBean) {
AppConfig.isVideoSleep = data.vedioRules.isVedioSleep
videoAdingManager.run {
initAdWeight(data.vedioRules.csJ_VEDIO.rate,
data.vedioRules.ylH_VEDIO.rate,
data.vedioRules.sdhZ_VEDIO.rate,
data.vedioRules.fL_VEDIO.rate,
data.vedioRules.corAl_VIDEO.rate,
data.vedioRules.csjfulL_VEDIO.rate,
data.vedioRules.kS_VEDIO.rate)
}
LogUtil.d(TAG, "首页权重值:csjWeight:${data.vedioRules.csJ_VEDIO.rate} " +
"ylhWeight:${data.vedioRules.ylH_VEDIO.rate} " +
"sdhzWeight:${data.vedioRules.sdhZ_VEDIO.rate} " +
"csjFullWeight:${data.vedioRules.csjfulL_VEDIO.rate} " +
"shWeight:${data.vedioRules.corAl_VIDEO.rate} " +
"flWeight:${data.vedioRules.fL_VEDIO.rate} " +
"ksWeight:${data.vedioRules.kS_VEDIO.rate} ")
// 广告视频数
AppConfig.csjVideoAdCount = data.vedioRules.csJ_VEDIO.surplus
AppConfig.ylhAdCount = data.vedioRules.ylH_VEDIO.surplus
AppConfig.wnVideoAdCount = data.vedioRules.sdhZ_VEDIO.surplus
AppConfig.flVideoAdCount = data.vedioRules.fL_VEDIO.surplus
AppConfig.csjFullVedioAdCount = data.vedioRules.csjfulL_VEDIO.surplus
AppConfig.shVideoAdCount = data.vedioRules.corAl_VIDEO.surplus
AppConfig.ksVideoAdCount = data.vedioRules.kS_VEDIO.surplus
LogUtil.d(TAG, "首页视频数:csjCount:${AppConfig.csjVideoAdCount} " +
"ylhCount:${AppConfig.ylhAdCount} " +
"sdhzCount:${AppConfig.wnVideoAdCount} " +
"shCount:${AppConfig.shVideoAdCount} " +
"flCount:${AppConfig.flVideoAdCount} " +
"ksCount:${AppConfig.ksVideoAdCount} ")
}
}
\ No newline at end of file
package com.mints.fairyland.mvp.model;
import java.io.Serializable;
public class ClickTurnBean implements Serializable {
/**
* config : {"count":250,"type":"coin","key":"t5","index":5,"title":"250金币"}
* sumCoin : 7580
* coinKey : 2108214495303800003
* turntableKey : 2108214495303800003
*/
private ConfigBean config;
private int sumCoin;
private String coinKey;
private String turntableKey;
public ConfigBean getConfig() {
return config;
}
public void setConfig(ConfigBean config) {
this.config = config;
}
public int getSumCoin() {
return sumCoin;
}
public void setSumCoin(int sumCoin) {
this.sumCoin = sumCoin;
}
public String getCoinKey() {
return coinKey;
}
public void setCoinKey(String coinKey) {
this.coinKey = coinKey;
}
public String getTurntableKey() {
return turntableKey;
}
public void setTurntableKey(String turntableKey) {
this.turntableKey = turntableKey;
}
public class ConfigBean implements Serializable{
/**
* count : 250
* type : coin
* key : t5
* index : 5
* title : 250金币
*/
private int count;
private String type;
private String key;
private int index;
private String title;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
}
package com.mints.fairyland.mvp.model;
import java.io.Serializable;
import java.util.List;
public class TurnBean implements Serializable {
/**
* configs : [{"count":150,"type":"coin","key":"t1","index":0,"title":"150金币"},{"count":10,"type":"cash","key":"t2","index":1,"title":"现金10元"},{"count":200,"type":"coin","key":"t8","index":2,"title":"200金币"},{"count":100,"type":"coin","key":"t3","index":3,"title":"100金币"},{"count":300,"type":"coin","key":"t4","index":4,"title":"300金币"},{"count":250,"type":"coin","key":"t5","index":5,"title":"250金币"},{"count":350,"type":"coin","key":"t6","index":6,"title":"350金币"},{"count":40,"type":"cash","key":"t7","index":7,"title":"现金40元"}]
* max : 30
*/
private List<ConfigsBean> configs;
private int max;
private String titleMsg;
private int surplus;
private List<BottomsBean> bottoms;
public List<ConfigsBean> getConfigs() {
return configs;
}
public String getTitleMsg() {
return titleMsg;
}
public void setTitleMsg(String titleMsg) {
this.titleMsg = titleMsg;
}
public int getSurplus() {
return surplus;
}
public void setSurplus(int surplus) {
this.surplus = surplus;
}
public void setConfigs(List<ConfigsBean> configs) {
this.configs = configs;
}
public int getMax() {
return max;
}
public void setMax(int max) {
this.max = max;
}
public List<BottomsBean> getBottoms() {
return bottoms;
}
public void setBottoms(List<BottomsBean> bottoms) {
this.bottoms = bottoms;
}
public class BottomsBean implements Serializable {
/**
* title : 高额赚
* icon : https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg_goodmoney/img/readnews.png
* toOtherKey : 1
* rewardTitle : 抽奖 +1
*/
private String title;
private String icon;
private String toOtherKey;
private String rewardTitle;
private ParamsBean params;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getToOtherKey() {
return toOtherKey;
}
public void setToOtherKey(String toOtherKey) {
this.toOtherKey = toOtherKey;
}
public String getRewardTitle() {
return rewardTitle;
}
public void setRewardTitle(String rewardTitle) {
this.rewardTitle = rewardTitle;
}
public class ParamsBean implements Serializable {
private int max;
private int complete;
private int coin;
public int getMax() {
return max;
}
public int getComplete() {
return complete;
}
public int getCoin() {
return coin;
}
}
}
public class ConfigsBean implements Serializable {
/**
* count : 150
* type : coin
* key : t1
* index : 0
* title : 150金币
*/
private int count;
private String type;
private String key;
private int index;
private String title;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
}
package com.mints.fairyland.mvp.model;
import com.mints.fairyland.mvp.model.AdcodeBean;
import com.mints.fairyland.mvp.model.FlowAdRulesBean;
import com.mints.fairyland.mvp.model.OfflineBean;
import com.mints.fairyland.mvp.model.UserRiskAppsBean;
import com.mints.fairyland.mvp.model.VedioRulesBean;
import java.io.Serializable;
import java.util.ArrayList;
public class UserTaskMsgBean implements Serializable {
......
......@@ -10,9 +10,18 @@ public class VedioRulesBean implements Serializable {
private FLVedioBean FL_VEDIO;
private CsjfullVedioBean CSJFULL_VEDIO;
private CORALVedioBean CORAL_VEDIO;
private KSVedioBean KS_VEDIO;
private RTAVedioBean RTA_VEDIO;
public KsVedioBean getKS_VEDIO() {
return KS_VEDIO;
}
public void setKS_VEDIO(KsVedioBean KS_VEDIO) {
this.KS_VEDIO = KS_VEDIO;
}
private KsVedioBean KS_VEDIO;
private boolean flVideoFlag;
private boolean vedioSleep;
public class CsjVedioBean implements Serializable {
private int surplus;//剩余可看视频数
......@@ -79,7 +88,7 @@ public class VedioRulesBean implements Serializable {
}
}
public class KSVedioBean implements Serializable {
public class CsjfullVedioBean implements Serializable {
private int surplus;
private int rate;
......@@ -90,22 +99,10 @@ public class VedioRulesBean implements Serializable {
public int getRate() {
return rate;
}
}
public class RTAVedioBean implements Serializable {
private int surplus;
private int rate;
public int getSurplus() {
return surplus;
}
public int getRate() {
return rate;
}
}
public class CsjfullVedioBean implements Serializable {
public class KsVedioBean implements Serializable {
private int surplus;
private int rate;
......@@ -139,18 +136,6 @@ public class VedioRulesBean implements Serializable {
return CORAL_VEDIO;
}
public RTAVedioBean getRTA_VEDIO() {
return RTA_VEDIO;
}
public void setRTA_VEDIO(RTAVedioBean RTA_VEDIO) {
this.RTA_VEDIO = RTA_VEDIO;
}
public KSVedioBean getKS_VEDIO() {
return KS_VEDIO;
}
public CsjfullVedioBean getCSJFULL_VEDIO() {
return CSJFULL_VEDIO;
}
......@@ -158,4 +143,8 @@ public class VedioRulesBean implements Serializable {
public boolean isFlVideoFlag() {
return flVideoFlag;
}
public boolean isVedioSleep() {
return vedioSleep;
}
}
......@@ -7,8 +7,10 @@ import com.mints.fairyland.MintsApplication;
import com.mints.fairyland.common.AppConfig;
import com.mints.fairyland.common.Constant;
import com.mints.fairyland.manager.AppHttpManager;
import com.mints.fairyland.manager.UserWeight;
import com.mints.fairyland.mvp.model.BaseResponse;
import com.mints.fairyland.mvp.model.CommonParamBean;
import com.mints.fairyland.mvp.model.UserTaskMsgBean;
import com.mints.library.net.neterror.BaseSubscriber;
import com.mints.library.net.neterror.Throwable;
......@@ -224,6 +226,29 @@ public class TrackPresenter extends BaseTrackPresenter {
});
}
/**
* 获取权重
*/
public void getAdWeight() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.vedioPlans(),
new BaseSubscriber<BaseResponse<UserTaskMsgBean>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(BaseResponse<UserTaskMsgBean> baseResponse) {
UserWeight.INSTANCE.initAdWeight(baseResponse.getData());
}
});
}
/**
* 首页是否显示微转
*/
......
package com.mints.fairyland.mvp.presenters
import android.text.TextUtils
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken
import com.mints.fairyland.MintsApplication
import com.mints.fairyland.common.DeviceInfo
import com.mints.fairyland.manager.AppHttpManager
import com.mints.fairyland.manager.ShumeiManager
import com.mints.fairyland.manager.UserManager
import com.mints.fairyland.mvp.model.BaseResponse
import com.mints.fairyland.mvp.model.ClickTurnBean
import com.mints.fairyland.mvp.model.TurnBean
import com.mints.fairyland.mvp.model.UserBean
import com.mints.fairyland.mvp.views.TurnTableView
import com.mints.fairyland.utils.DeviceUuidFactory
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
import java.util.*
class TurnTablePresenter : BasePresenter<TurnTableView>() {
fun getTurnMsg() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.getTurnMsg(),
object : BaseSubscriber<BaseResponse<TurnBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.showToast(e.message)
}
override fun onNext(baseResponse: BaseResponse<TurnBean>) {
if (isLinkView) return
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
when (code) {
200 -> {
view.getTurnTableSuc(baseResponse.data)
}
else -> view.showToast(message)
}
}
})
}
fun addTurnToOtherMsg(toOtherKey: String) {
val vo = HashMap<String, Any>()
vo["toOther"] = toOtherKey
AppHttpManager.getInstance(loanApplication)
.call(loanService.addTurnToOtherMsg(vo),
object : BaseSubscriber<BaseResponse<Any>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.showToast(e.message)
}
override fun onNext(baseResponse: BaseResponse<Any>) {
if (isLinkView) return
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
when (code) {
200 -> {
}
else -> view.showToast(message)
}
}
})
}
fun cashoutLeaders() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.cashoutLeaders(),
object : BaseSubscriber<BaseResponse<JsonObject>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
}
override fun onNext(baseResponse: BaseResponse<JsonObject>) {
if (isLinkView) return
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
when (code) {
200 -> {
val data = baseResponse.data
if (data.get("list") != null) {
val listArray = Gson().fromJson(data.get("list"),
object : TypeToken<ArrayList<String>>() {}.type) as ArrayList<String>
view.cashoutLeadersSuc(listArray)
}
}
else -> view.showToast(message)
}
}
})
}
fun clickForTurn() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.clickForTurn(),
object : BaseSubscriber<BaseResponse<ClickTurnBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.showToast(e.message)
}
override fun onNext(baseResponse: BaseResponse<ClickTurnBean>) {
if (isLinkView) return
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
when (code) {
200 -> {
view.clickForTurnSuc(baseResponse.data)
}
else -> view.showToast(message)
}
}
})
}
/**
* 游客登录
*/
fun userLogin() {
val vo = HashMap<String, Any>()
vo["device"] = DeviceUuidFactory().deviceUuid.toString()
vo["shumeiId"] = ShumeiManager.getInstance().shumeiDeviceId
AppHttpManager.getInstance(loanApplication)
.call(loanService.visitorlogin(vo),
object : BaseSubscriber<BaseResponse<UserBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
}
override fun onNext(baseResponse: BaseResponse<UserBean>) {
if (isLinkView) return
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
val data: UserBean? = baseResponse.getData()
when (code) {
200 -> if (data != null) {
UserManager.getInstance().saveUserInfo(data)
saveTerminalInfo()
}
else -> view.showToast(message)
}
}
})
}
/**
* 提交设备信息
*
* @param context
*/
fun saveTerminalInfo() {
val vo = HashMap<String, Any>()
val deviceInfo: DeviceInfo = DeviceInfo.instance
val macAddress: String = deviceInfo.getMacAddress()
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
vo["androidid"] = deviceInfo.getAndroidId(null)
vo["imei"] = deviceInfo.iMEI
if (!TextUtils.isEmpty(MintsApplication.OAID)) {
vo["oaid"] = MintsApplication.OAID
}
vo["os"] = "android"
vo["model"] = deviceInfo.newModel
vo["uuid"] = DeviceUuidFactory().deviceUuid
vo["osversion"] = deviceInfo.oSVersion
vo["appversion"] = deviceInfo.versionName
vo["shumeiId"] = ShumeiManager.getInstance().getShumeiDeviceId()
AppHttpManager.getInstance(loanApplication)
.call(loanService.saveTerminalInfo(vo),
object : BaseSubscriber<BaseResponse<Any>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<Any>) {
if (isLinkView) return
val code = baseResponse.status
when (code) {
200 -> {
getTurnMsg()
}
}
}
})
}
}
\ No newline at end of file
package com.mints.fairyland.mvp.views
import com.mints.fairyland.mvp.model.ClickTurnBean
import com.mints.fairyland.mvp.model.TurnBean
interface TurnTableView : BaseView {
fun getTurnTableSuc(data: TurnBean)
fun cashoutLeadersSuc(data:ArrayList<String>)
fun clickForTurnSuc(data: ClickTurnBean)
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import com.mints.fairyland.BuildConfig;
import com.mints.fairyland.mvp.model.AccountMsgBean;
import com.mints.fairyland.mvp.model.BannerBean;
import com.mints.fairyland.mvp.model.BaseResponse;
import com.mints.fairyland.mvp.model.ClickTurnBean;
import com.mints.fairyland.mvp.model.CommonParamBean;
import com.mints.fairyland.mvp.model.DrawcashBean;
import com.mints.fairyland.mvp.model.DrawcashRecordBean;
......@@ -20,6 +21,7 @@ import com.mints.fairyland.mvp.model.MorningClockBean;
import com.mints.fairyland.mvp.model.MyInfo;
import com.mints.fairyland.mvp.model.SignCardBean;
import com.mints.fairyland.mvp.model.TaskCpdBean;
import com.mints.fairyland.mvp.model.TurnBean;
import com.mints.fairyland.mvp.model.UserBean;
import com.mints.fairyland.mvp.model.UserTaskMsgBean;
import com.mints.fairyland.mvp.model.Version;
......@@ -569,6 +571,47 @@ public interface LoanService {
@POST("api/getCpdUseAppModelMsg")
Observable<BaseResponse<TaskCpdBean>> getCpdUseAppModelMsg();
/**
* 获取大转盘信息
*
* @return
*/
@POST("api/turn/getTurnMsg")
Observable<BaseResponse<TurnBean>> getTurnMsg();
/**
* 点击获取转盘信息
*
* @return
*/
@POST("api/turn/clickForTurn")
Observable<BaseResponse<ClickTurnBean>> clickForTurn();
/**
* 大转盘点击入口
*
* @return
*/
@POST("api/turn/addTurnToOtherMsg")
Observable<BaseResponse<Object>> addTurnToOtherMsg(@Body Map<String, Object> vo);
/**
* 提现列表展示
*
* @return
*/
@POST("common/cashoutLeadersForApp")
Observable<BaseResponse<JsonObject>> cashoutLeaders();
/**
* 获取权重信息
*
* @return
*/
@POST("api/vedioPlans")
Observable<BaseResponse<UserTaskMsgBean>> vedioPlans();
/**
* 默认http工厂
*/
......
......@@ -502,7 +502,10 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
* 获取激励视频
*/
private fun awardVideo() {
if (videoAdingManager.videoFinishFlag) {
if (AppConfig.isVideoSleep) {
showToast("加载失败,请稍后重试。")
return
} else if (videoAdingManager.videoFinishFlag) {
showToast("今日视频已看完,请明天再来吧")
return
}
......
......@@ -305,16 +305,13 @@ class DrawcashActivity : BaseActivity(),
data.fL_VEDIO,
data.coraL_VEDIO,
data.csjfulL_VEDIO,
data.kS_VEDIO,
data.rtA_VEDIO
)
data.kS_VEDIO)
LogUtil.d(TAG, "提现权重值:csjWeight:${data.csJ_VEDIO} " +
"ylhWeight:${data.ylH_VEDIO} " +
"sdhzWeight:${data.sdhZ_VEDIO} " +
"csjFullWeight:${data.csjfulL_VEDIO} " +
"shWeight:${data.coraL_VEDIO} " +
"flWeight:${data.fL_VEDIO} " +
"rtaWeight:${data.rtA_VEDIO} " +
"ksWeight:${data.kS_VEDIO}"
)
// 广告视频数
......@@ -325,7 +322,6 @@ class DrawcashActivity : BaseActivity(),
AppConfig.shVideoAdCount = 10
AppConfig.csjFullVideoAdCount = 10
AppConfig.ksVideoAdCount = 10
AppConfig.rtaVideoAdCount = 10
}
/**
......
......@@ -14,6 +14,7 @@ import com.mints.fairyland.call.business.VideoDBHelper
import com.mints.fairyland.call.detail.DetailApplyActivity
import com.mints.fairyland.call.permission.PermissionActivity
import com.mints.fairyland.call.permission.PermissionManager
import com.mints.fairyland.common.AppConfig
import com.mints.fairyland.common.Constant
import com.mints.fairyland.manager.UserManager
import com.mints.fairyland.mvp.model.KylBean
......@@ -163,7 +164,10 @@ class KylVideoActivity : BaseActivity(), View.OnClickListener, KylVideoView {
* 获取激励视频
*/
private fun awardVideo() {
if (videoAdingManager.videoFinishFlag) {
if (AppConfig.isVideoSleep) {
showToast("加载失败,请稍后重试。")
return
} else if (videoAdingManager.videoFinishFlag) {
showToast("今日视频已看完,请明天再来吧")
return
}
......
......@@ -265,7 +265,7 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
private fun clickTab3Layout() {
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_THREE
if (panFragment == null) {
panFragment = PanFragment()
panFragment = TurnTableFragment()
}
addOrShowFragment(supportFragmentManager, panFragment!!, Constant.FRAGMENT_TAG_THREE)
tab_iv_one.isSelected = false
......
......@@ -8,6 +8,7 @@ import com.mints.fairyland.R
import com.mints.fairyland.ad.video.VideoAdingManager
import com.mints.fairyland.common.Constant
import com.mints.fairyland.ad.express.TTPreLoadCarrierExpressManager
import com.mints.fairyland.common.AppConfig
import com.mints.fairyland.manager.TtCsjAdManager
import com.mints.fairyland.mvp.model.MorningClockBean
import com.mints.fairyland.mvp.model.VideoAdingBean
......@@ -107,7 +108,10 @@ class MorningClockActivity : BaseActivity(), View.OnClickListener, MorningClockV
* 获取激励视频
*/
private fun awardVideo() {
if (videoAdingManager.videoFinishFlag) {
if (AppConfig.isVideoSleep) {
showToast("加载失败,请稍后重试。")
return
} else if (videoAdingManager.videoFinishFlag) {
showToast("今日视频已看完,请明天再来吧")
return
}
......
......@@ -100,6 +100,10 @@ class SplashKsADActivity : BaseActivity() {
next()
}
override fun onRequestResult(p0: Int) {
}
override fun onSplashScreenAdLoad(p0: KsSplashScreenAd?) {
LogUtil.d(TAG, "onSplashScreenAdLoad")
......
package com.mints.fairyland.ui.adapter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.mints.fairyland.R;
import com.mints.fairyland.mvp.model.TurnBean;
import com.mints.fairyland.utils.rxutil.CommonRxTask;
import com.mints.fairyland.utils.rxutil.RxjavaUtil;
import com.mints.library.utils.GlideUtils;
import java.util.List;
public class TurnTableAdapter extends BaseAdapter {
private List<TurnBean.BottomsBean> orders;
private Activity activity;
private YoYo.AnimationComposer rope;
public TurnTableAdapter(Activity activity, List<TurnBean.BottomsBean> orders) {
this.orders = orders;
this.activity = activity;
rope = YoYo.with(Techniques.Pulse).duration(1000).repeat(0);
}
@Override
public int getCount() {
return orders == null ? 0 : orders.size();
}
@Override
public Object getItem(int position) {
return orders.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressLint("WrongViewCast")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(activity);
convertView = inflater.inflate(R.layout.item_list_turn, null);
viewHolder = new ViewHolder();
viewHolder.ic_turn_icon = convertView.findViewById(R.id.ic_turn_icon);
viewHolder.tv_turn_top = convertView.findViewById(R.id.tv_turn_top);
viewHolder.tv_turn_bottom = convertView.findViewById(R.id.tv_turn_bottom);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
TurnBean.BottomsBean data = orders.get(position);
if (data != null) {
GlideUtils.loadImageView(activity, data.getIcon(), viewHolder.ic_turn_icon);
viewHolder.tv_turn_top.setText(TextUtils.isEmpty(data.getRewardTitle()) ? "" : data.getRewardTitle());
viewHolder.tv_turn_bottom.setText(data.getTitle());
if (!TextUtils.isEmpty(data.getRewardTitle())) {
RxjavaUtil.executeRxTask(new CommonRxTask<String>("") {
@Override
public void doInIOThread() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void doInUIThread() {
rope.playOn(viewHolder.ic_turn_icon);
}
});
}
}
return convertView;
}
class ViewHolder {
public ImageView ic_turn_icon;
public TextView tv_turn_top;
public TextView tv_turn_bottom;
}
}
......@@ -9,10 +9,14 @@ import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.daimajia.androidanimations.library.YoYo.YoYoString
import com.kwad.sdk.api.KsAdSDK
import com.kwad.sdk.api.KsContentPage
import com.kwad.sdk.api.KsScene
import com.mints.fairyland.MintsApplication
import com.mints.fairyland.R
import com.mints.fairyland.ad.express.PreLoadExpressManager
......@@ -29,20 +33,17 @@ import com.mints.fairyland.mvp.views.HomeView
import com.mints.fairyland.ui.activitys.AwardActivity
import com.mints.fairyland.ui.activitys.WebActivity
import com.mints.fairyland.ui.fragment.base.BaseFragment
import com.mints.fairyland.ui.widgets.dialog.BindWxDialog
import com.mints.fairyland.ui.widgets.dialog.DialogListener
import com.mints.fairyland.ui.widgets.countdowntimer.CountDownTimerSupport
import com.mints.fairyland.ui.widgets.countdowntimer.OnCountDownTimerListener
import com.mints.fairyland.ui.widgets.dialog.BindWxDialog
import com.mints.fairyland.ui.widgets.dialog.DialogListener
import com.mints.fairyland.ui.widgets.dialog.DialogUtils
import com.mints.fairyland.ui.widgets.seekbar.BubbleUtils
import com.mints.fairyland.utils.LogUtil
import com.mints.fairyland.utils.TimeRender
import com.mints.library.utils.CommonUtils
import com.yilan.sdk.player.ylplayer.YLPlayerConfig
import com.yilan.sdk.player.ylplayer.callback.OnPlayerCallBack
import com.yilan.sdk.ui.configs.YLUIConfig
import com.yilan.sdk.ui.little.YLLittleVideoFragment
import com.yilan.sdk.ylad.YLAdListener
import kotlinx.android.synthetic.main.layout_red_bag.*
import kotlinx.android.synthetic.main.layout_red_box.*
import net.grandcentrix.tray.AppPreferences
......@@ -66,7 +67,11 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
// 视频相关
private var rewardDoubleCoin = 0 // 大金币
private var rewardCoin = 0 // 小金币
private var littleVideoFragment: YLLittleVideoFragment? = null
// 快手视频相关
private var ksFragment: Fragment? = null
private var mKsContentPage: KsContentPage? = null
private val videoMaxCount = 12 // 当前缓存视频id最大数
private val videoIdList by lazy { ArrayList<String>() }//记录播放的视频id
......@@ -119,7 +124,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
override fun onHiddenChanged(hidden: Boolean) {
littleVideoFragment?.onHiddenChanged(hidden)
ksFragment?.onHiddenChanged(hidden)
if (hidden) {
onPause()
......@@ -147,8 +152,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
}
registerPlayerCallBack()
littleVideoFragment?.onResume()
ksFragment?.onResume()
}
}
......@@ -169,10 +173,11 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
// 福袋动画停止
stopRedbox()
// 倒计时红包暂停
// pauseDownloadTime()
pauseDownloadTime()
destroyTimerRedbox()
littleVideoFragment?.onPause()
ksFragment?.onPause()
if (isToCreateReward) {
// 防止界面切换 重置红包动画
......@@ -185,7 +190,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
littleVideoFragment?.userVisibleHint = isVisibleToUser
ksFragment?.userVisibleHint = isVisibleToUser
}
override fun onDestroyView() {
......@@ -328,120 +333,110 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
* 一览视频初始化
*/
private fun showLittle() {
val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
if (littleVideoFragment == null) {
littleVideoFragment = YLLittleVideoFragment.newInstance()
transaction.add(R.id.yilan_fragment_frame_container, littleVideoFragment!!, YLLittleVideoFragment::class.java.simpleName)
val adScene = KsScene.Builder(5746000003L).build()
mKsContentPage = KsAdSDK.getLoadManager().loadContentPage(adScene)
registerPlayerCallBack()
val transaction: FragmentTransaction = childFragmentManager.beginTransaction()
if (ksFragment == null) {
ksFragment = mKsContentPage?.fragment
transaction.add(R.id.yilan_fragment_frame_container, ksFragment!!, "ks_fragment")
} else {
transaction.show(littleVideoFragment!!)
transaction.show(ksFragment!!)
}
transaction.commitAllowingStateLoss()
}
private fun registerPlayerCallBack() {
YLPlayerConfig.config().registerPlayerCallBack(object : OnPlayerCallBack {
override fun onStart(pager: String, videoid: String, p2: String?) {
// 防止网络异常时, 第一次加载倒计时红包
if (isFirstLoadVideo) {
isFirstLoadVideo = false
initTimeview()
} else {
resumeDownloadTime(videoid)
}
}
mKsContentPage?.let {
override fun onPause(pager: String, p1: String?, p2: String?) {
pauseDownloadTime()
it.setPageListener(object : KsContentPage.PageListener {
override fun onPagePause(p0: KsContentPage.ContentItem?) {
LogUtil.d("onPagePause")
}
override fun onResume(pager: String, videoid: String, p2: String?) {
resumeDownloadTime(videoid)
override fun onPageResume(p0: KsContentPage.ContentItem?) {
LogUtil.d("onPageResume")
}
override fun onComplete(pager: String, videoid: String, p2: String?) {
override fun onPageEnter(p0: KsContentPage.ContentItem?) {
LogUtil.d("onPageEnter")
}
override fun onLoopComplete(pager: String?, videoID: String, taskID: String?, num: Int) {
// LogUtil.d(TAG, "registerPlayerCallBack onLoopComplete")
addVideoIdList(videoID)
pauseDownloadTime()
}
override fun onStuckStart(pager: String, p1: String?, p2: String?) {
override fun onPageLeave(p0: KsContentPage.ContentItem?) {
LogUtil.d("onPageLeave")
}
})
override fun onStuckEnd(pager: String, p1: String?, p2: String?) {
}
override fun onError(pager: String, p1: String?, p2: String?) {
// 视频播放回调
it.setVideoListener(object : KsContentPage.VideoListener {
override fun onVideoPlayCompleted(p0: KsContentPage.ContentItem?) {
LogUtil.d("onVideoPlayCompleted")
addVideoIdList(p0!!.id)
pauseDownloadTime()
}
override fun onStop(pager: String, p1: String?, p2: String?) {
// LogUtil.d(TAG, "registerPlayerCallBack onStop")
// pauseDownloadTime()
}
})
}
override fun onVideoPlayPaused(p0: KsContentPage.ContentItem?) {
LogUtil.d("onVideoPlayPaused")
private fun initListener() {
val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)
params.setMargins(0, 0, 0, BubbleUtils.dp2px(270))
cdvvYilanTime.layoutParams = params
val paramsRedBox = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
paramsRedBox.setMargins(0, BubbleUtils.dp2px(40), 0, 0)
paramsRedBox.gravity = Gravity.END
rl_fragment_main_redbox.layoutParams = paramsRedBox
cdvvYilanTime.setOnClickListener(this)
rl_fragment_main_redbox.setOnClickListener(this)
rl_fragment_main_redbox.isClickable = false
// 广告回调
YLUIConfig.getInstance().registerAdListener(object : YLAdListener() {
override fun onSuccess(p0: String?, p1: Int, p2: String?, p3: String?) {
pauseDownloadTime()
}
override fun onError(p0: String?, p1: Int, p2: String?, p3: Int, p4: String?, p5: String?) {
}
override fun onVideoPlayStart(p0: KsContentPage.ContentItem?) {
LogUtil.d("onVideoPlayStart")
override fun onRenderError(p0: String?, p1: Int, p2: String?, p3: Int, p4: String?, p5: String?) {
// 防止网络异常时, 第一次加载倒计时红包
if (isFirstLoadVideo) {
isFirstLoadVideo = false
initTimeview()
} else {
resumeDownloadTime(p0!!.id)
}
override fun onShow(p0: String?, p1: Int, p2: String?, p3: String) {
resumeAdTime()
}
override fun onClick(p0: String?, p1: Int, p2: String?, p3: String?) {}
override fun onSkip(p0: String?, p1: Int, p2: String?, p3: String?) {}
override fun onVideoPlayError(p0: KsContentPage.ContentItem?, p1: Int, p2: Int) {
LogUtil.d("onVideoPlayError")
override fun onTimeOver(p0: String?, p1: Int, p2: String?, p3: String?) {}
override fun onClose(p0: String?, p1: Int, p2: String?, p3: String?) {}
pauseDownloadTime()
}
override fun onAdEmpty(p0: String?, p1: Int, p2: String?, p3: String?) {}
override fun onVideoPlayResume(p0: KsContentPage.ContentItem?) {
LogUtil.d("onVideoPlayResume")
override fun onVideoStart(p0: String?, p1: Int, p2: String?, p3: String) {
// 防止网络异常时, 第一次加载倒计时红包
if (isFirstLoadVideo) {
isFirstLoadVideo = false
initTimeview()
} else {
resumeDownloadTime(p0!!.id)
}
override fun onVideoPause(p0: String?, p1: Int, p2: String?, p3: String?) {
pauseDownloadTime()
}
override fun onVideoResume(p0: String?, p1: Int, p2: String?, p3: String?) {
resumeAdTime()
}
})
override fun onVideoComplete(p0: String?, p1: Int, p2: String?, p3: String?) {
pauseDownloadTime()
}
}
override fun onVideoError(p0: String?, p1: Int, p2: String?, p3: String?) {}
private fun initListener() {
val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)
params.setMargins(0, 0, 0, BubbleUtils.dp2px(320))
cdvvYilanTime.layoutParams = params
})
val paramsRedBox = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
paramsRedBox.setMargins(0, BubbleUtils.dp2px(40), 0, 0)
paramsRedBox.gravity = Gravity.END
rl_fragment_main_redbox.layoutParams = paramsRedBox
cdvvYilanTime.setOnClickListener(this)
rl_fragment_main_redbox.setOnClickListener(this)
rl_fragment_main_redbox.isClickable = false
}
private fun resumeAdTime() {
......@@ -576,16 +571,13 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
data.vedioRules.fL_VEDIO.rate,
data.vedioRules.corAl_VIDEO.rate,
data.vedioRules.csjfulL_VEDIO.rate,
data.vedioRules.kS_VEDIO.rate,
data.vedioRules.rtA_VEDIO.rate
)
data.vedioRules.kS_VEDIO.rate)
LogUtil.d(TAG, "首页权重值:csjWeight:${data.vedioRules.csJ_VEDIO.rate} " +
"ylhWeight:${data.vedioRules.ylH_VEDIO.rate} " +
"sdhzWeight:${data.vedioRules.sdhZ_VEDIO.rate} " +
"csjFullWeight:${data.vedioRules.csjfulL_VEDIO.rate} " +
"shWeight:${data.vedioRules.corAl_VIDEO.rate} " +
"flWeight:${data.vedioRules.fL_VEDIO.rate} " +
"rtaWeight:${data.vedioRules.rtA_VEDIO.rate} " +
"ksWeight:${data.vedioRules.kS_VEDIO.rate}"
)
// 广告视频数
......@@ -596,14 +588,12 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
AppConfig.csjFullVideoAdCount = data.vedioRules.csjfulL_VEDIO.surplus
AppConfig.shVideoAdCount = data.vedioRules.corAl_VIDEO.surplus
AppConfig.ksVideoAdCount = data.vedioRules.kS_VEDIO.surplus
AppConfig.rtaVideoAdCount = data.vedioRules.rtA_VEDIO.surplus
LogUtil.d(TAG, "首页视频数:csjCount:${AppConfig.csjVideoAdCount} " +
"ylhCount:${AppConfig.ylhAdCount} " +
"sdhzCount:${AppConfig.wnVideoAdCount} " +
"csjFullCount:${AppConfig.csjFullVideoAdCount} " +
"shCount:${AppConfig.shVideoAdCount} " +
"flCount:${AppConfig.flVideoAdCount} " +
"ratCount:${AppConfig.rtaVideoAdCount} " +
"ksCount:${AppConfig.ksVideoAdCount}"
)
}
......
......@@ -19,7 +19,6 @@ import androidx.viewpager.widget.ViewPager
import com.component.dly.xzzq_ywsdk.YwSDK_WebActivity.Companion.open
import com.fly.scenemodule.SceneUtil
import com.mints.fairyland.BuildConfig
import com.mints.fairyland.MintsApplication
import com.mints.fairyland.R
import com.mints.fairyland.ad.banner.BannerManager
import com.mints.fairyland.ad.express.PreLoadExpressManager
......@@ -1048,7 +1047,10 @@ class MyFragment : BaseFragment(),
* 获取激励视频
*/
private fun awardVideo(coin: Int, carrierType: String) {
if (videoAdingManager.videoFinishFlag) {
if (AppConfig.isVideoSleep) {
showToast("加载失败,请稍后重试。")
return
} else if (videoAdingManager.videoFinishFlag) {
showToast("今日视频已看完,请明天再来吧")
return
}
......@@ -1211,8 +1213,7 @@ class MyFragment : BaseFragment(),
data.vedioRules.fL_VEDIO.rate,
data.vedioRules.corAl_VIDEO.rate,
data.vedioRules.csjfulL_VEDIO.rate,
data.vedioRules.kS_VEDIO.rate,
data.vedioRules.rtA_VEDIO.rate
data.vedioRules.kS_VEDIO.rate
)
LogUtil.d(TAG, "首页权重值:csjWeight:${data.vedioRules.csJ_VEDIO.rate} " +
"ylhWeight:${data.vedioRules.ylH_VEDIO.rate} " +
......@@ -1220,7 +1221,6 @@ class MyFragment : BaseFragment(),
"csjFullWeight:${data.vedioRules.csjfulL_VEDIO.rate} " +
"shWeight:${data.vedioRules.corAl_VIDEO.rate} " +
"flWeight:${data.vedioRules.fL_VEDIO.rate} " +
"rtaWeight:${data.vedioRules.rtA_VEDIO.rate} " +
"ksWeight:${data.vedioRules.kS_VEDIO.rate}"
)
// 广告视频数
......@@ -1230,7 +1230,6 @@ class MyFragment : BaseFragment(),
AppConfig.flVideoAdCount = data.vedioRules.fL_VEDIO.surplus
AppConfig.shVideoAdCount = data.vedioRules.corAl_VIDEO.surplus
AppConfig.ksVideoAdCount = data.vedioRules.kS_VEDIO.surplus
AppConfig.rtaVideoAdCount = data.vedioRules.rtA_VEDIO.surplus
LogUtil.d(TAG, "首页视频数:csjCount:${AppConfig.csjVideoAdCount} " +
"ylhCount:${AppConfig.ylhAdCount} " +
"sdhzCount:${AppConfig.wnVideoAdCount} " +
......
package com.mints.fairyland.ui.fragment
import android.animation.ValueAnimator
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.AdapterView
import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.mints.fairyland.R
import com.mints.fairyland.common.AppConfig
import com.mints.fairyland.common.Constant
import com.mints.fairyland.manager.TrackManager
import com.mints.fairyland.manager.UserManager
import com.mints.fairyland.mvp.model.ClickTurnBean
import com.mints.fairyland.mvp.model.TurnBean
import com.mints.fairyland.mvp.presenters.TurnTablePresenter
import com.mints.fairyland.mvp.views.TurnTableView
import com.mints.fairyland.ui.activitys.*
import com.mints.fairyland.ui.adapter.TurnTableAdapter
import com.mints.fairyland.ui.fragment.base.BaseFragment
import com.mints.fairyland.ui.widgets.seekbar.BubbleUtils
import com.mints.fairyland.ui.widgets.wheelsruf.listener.RotateListener
import com.mints.fairyland.ui.widgets.wheelsruf.view.WheelSurfView
import com.mints.fairyland.utils.SpanUtils
import com.mints.library.net.netstatus.NetUtils
import kotlinx.android.synthetic.main.fragment_main_turntable.*
import kotlinx.android.synthetic.main.layout_turn_btn.*
import net.grandcentrix.tray.AppPreferences
import java.util.*
import kotlin.collections.ArrayList
import kotlin.concurrent.schedule
/**
* 描述:大转盘
* 作者:孟崔广
* 时间:2021/3/22 10:20
*/
class TurnTableFragment : BaseFragment(), TurnTableView, AdapterView.OnItemClickListener {
private val turnTablePresenter by lazy { TurnTablePresenter() }
private val userManager by lazy { UserManager.getInstance() }
private var rope: YoYo.YoYoString? = null
// 转盘
private val firstColor = "#FF7C00"
private val secondColor = "#fbaa7e"
private var desList: MutableList<String> = ArrayList()
private var colorsArray: MutableList<Int> = ArrayList()
private var bitmapList: MutableList<Bitmap> = ArrayList()
private var isTurnTable = true
private var clickTurnData: ClickTurnBean? = null
private var turnTableData: TurnBean? = null
// 第一次拉取的转盘size 若size被改变 需要重置转盘
private var firstPanSize = 0
// 提现列表展示
private var drawcashList: MutableList<String> = mutableListOf()
override fun getContentViewLayoutID() = R.layout.fragment_main_turntable
override fun initViewsAndEvents() {
turnTablePresenter.attachView(this)
gvTurnTable.onItemClickListener = this
tvTurnMore.setOnClickListener {
val activity: MainActivity? = activity as MainActivity?
activity?.let {
it.turnDayTask()
}
}
}
override fun onHiddenChanged(hidden: Boolean) {
if (hidden) { // 不在最前端界面显示
onPause()
} else { // 重新显示到最前端中
onResume()
}
super.onHiddenChanged(hidden)
}
override fun onResume() {
super.onResume()
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_THREE) {
if (!TextUtils.isEmpty(userManager.userID)) {
// 通用
turnTablePresenter.getTurnMsg()
} else {
// 游客登录
turnTablePresenter.userLogin()
}
marqueeView.startFlipping()
}
}
override fun onPause() {
super.onPause()
rope?.stop()
marqueeView.stopFlipping()
}
override fun onDestroy() {
super.onDestroy()
turnTableView.setRotateListener(null)
turnTablePresenter.detachView()
}
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
turnTableData?.let {
actionPageForType(it.bottoms[position].toOtherKey, position)
}
}
override fun getTurnTableSuc(data: TurnBean) {
TrackManager.getInstance().getAdWeight()
if (AppConfig.fragmentClickFlag != Constant.FRAGMENT_CLICK_THREE ||
activity == null || requireActivity().isFinishing) {
return
}
if (drawcashList.size == 0) {
turnTablePresenter.cashoutLeaders()
}
initTurnView(data)
}
override fun cashoutLeadersSuc(data: ArrayList<String>) {
drawcashList = data
initMarqueeView()
}
override fun clickForTurnSuc(data: ClickTurnBean) {
if (AppConfig.fragmentClickFlag != Constant.FRAGMENT_CLICK_THREE ||
activity == null || requireActivity().isFinishing) {
return
}
clickTurnData = data
val position = data.config.index
turnTableView.startRotate(bitmapList.size - position + 1)
}
private fun initTurnView(data: TurnBean) {
if (AppConfig.fragmentClickFlag != Constant.FRAGMENT_CLICK_THREE ||
activity == null || requireActivity().isFinishing) {
return
}
// LogUtil.d("initTurnView", "initTurnView")
turnTableData = data
if (data.configs.size == 0) {
showToast("网络数据异常,请联系客服")
return
}
// 大转盘异常校验
if (firstPanSize == 0) {
firstPanSize = data.configs.size
}
if (firstPanSize != data.configs.size) {
showToast("大转盘异常,请退出应用,重新进入")
return
}
colorsArray.clear()
desList.clear()
bitmapList.clear()
for (index in 0..data.configs.size - 1) {
//颜色
if (index % 2 == 0) {
colorsArray.add(Color.parseColor(firstColor))
} else {
colorsArray.add(Color.parseColor(secondColor))
}
//图标
if (TextUtils.equals(data.configs[index].type, "coin")) {
bitmapList.add(BitmapFactory.decodeResource(resources, R.mipmap.ic_turn_gold))
} else {
bitmapList.add(BitmapFactory.decodeResource(resources, R.mipmap.ic_turn_money))
}
//文字
desList.add(data.configs[index].title)
}
//主动旋转一下图片
bitmapList = WheelSurfView.rotateBitmaps(bitmapList) as ArrayList<Bitmap>
val build = WheelSurfView.Builder()
.setmColors(colorsArray.toTypedArray())
.setmDeses(desList.toTypedArray())
.setmIcons(bitmapList)
.setmType(1)
.setmMinTimes(5)
.setmTypeNum(data.configs.size)
.setmTextColor(Color.parseColor("#FFFFFF"))
.build()
turnTableView.setConfig(build)
//添加滚动监听
turnTableView.setRotateListener(object : RotateListener {
override fun rotateEnd(position: Int, des: String) {
isTurnTable = true
clickTurnData?.let {
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, it.config.count)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_CHALLENGE_TURN)
bundle.putString(Constant.MAIN_EXTRA_ID, it.turntableKey)
readyGo(AwardActivity::class.java, bundle)
}
}
override fun rotating(valueAnimator: ValueAnimator) {}
override fun rotateBefore(goImg: ImageView) {
if (!NetUtils.isNetworkConnected(context)) {
showToast("网络异常,请检测网络")
return
}
if (data.surplus <= 0) {
showToast("抽奖次数已用完")
return
}
if (isTurnTable) {
isTurnTable = false
turnTablePresenter.clickForTurn()
}
}
})
tvHintTurnTable.text = data.titleMsg
tvTurnTimes.text = SpanUtils()
.append("本轮抽奖将剩余").setForegroundColor(ContextCompat.getColor(mContext, R.color.black))
.append(data.surplus.toString()).setFontSize(BubbleUtils.dp2px(28)).setForegroundColor(ContextCompat.getColor(mContext, R.color.color_E72C2B))
.append("次机会").setForegroundColor(ContextCompat.getColor(mContext, R.color.black))
.create()
gvTurnTable.setAdapter(TurnTableAdapter(activity, data.bottoms))
Timer().schedule(1000) {
activity?.runOnUiThread {
rope = YoYo.with(Techniques.Pulse).duration(1000).repeat(-1).playOn(tvTurnMore)
}
}
}
private fun actionPageForType(toOtherKey: String, position: Int) {
if (!userManager.userIsLogin()) {
readyGo(WxLoginActivity::class.java)
return
}
//0-微转,1-珊瑚下载,2-分红,3-鱼丸盒子,4-每日任务
when (toOtherKey) {
"0" -> {
shareArticle()
}
"1" -> {
readyGo(TaskCpdActivity::class.java)
}
"2" -> {
val bundle = Bundle()
bundle.putInt(Constant.WRAPPER_TYPE, Constant.WRAPPER_TYPE_FRIENDS)
readyGo(WrapperActivity::class.java, bundle)
}
"3" -> {
}
}
turnTableData?.let {
if (!TextUtils.isEmpty(it.bottoms[position].rewardTitle)) {
turnTablePresenter.addTurnToOtherMsg(toOtherKey)
}
}
}
/**
* 分享文章
*/
private fun shareArticle() {
val bundle = Bundle()
bundle.putInt(Constant.WRAPPER_TYPE, Constant.WRAPPER_TYPE_WZ)
readyGo(WrapperActivity::class.java, bundle)
}
private fun initMarqueeView() {
marqueeView.startWithList(drawcashList)
}
}
\ No newline at end of file
package com.mints.fairyland.ui.widgets.wheelsruf.listener;
import android.animation.ValueAnimator;
import android.widget.ImageView;
/**
* 用于回调动画过程和结果
*/
public interface RotateListener {
/**
* 动画结束 返回当前位置 注意 位置是最上面是1 然后依次逆时针递增
*
* @param position
* @param des 所指分区文字描述
*/
void rotateEnd(int position, String des);
/**
* 动画进行中 返回动画中间量
*
* @param valueAnimator
*/
void rotating(ValueAnimator valueAnimator);
/**
* 点击了按钮 但是没有旋转 调用者可以在这里处理一些逻辑 比如弹出对话框确定用户是否要抽奖
*
* @param goImg
*/
void rotateBefore(ImageView goImg);
}
package com.mints.fairyland.ui.widgets.wheelsruf.view;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.mints.fairyland.R;
import com.mints.fairyland.ui.widgets.wheelsruf.listener.RotateListener;
import java.util.ArrayList;
import java.util.List;
public class WheelSurfPanView extends View {
private Context mContext;
//记录视图的大小
private int mWidth;
//记录当前有几个分类
private Paint mPaint;
//文字画笔
private Paint mTextPaint;
//圆环图片
private Bitmap mYuanHuan;
//大图片
private Bitmap mMain;
//中心点横坐标
private int mCenter;
//绘制扇形的半径 减掉50是为了防止边界溢出 具体效果你自己注释掉-50自己测试
private int mRadius;
//每一个扇形的角度
private float mAngle;
private List<Bitmap> mListBitmap;
//动画回调监听
private RotateListener rotateListener;
public RotateListener getRotateListener() {
return rotateListener;
}
public void setRotateListener(RotateListener rotateListener) {
this.rotateListener = rotateListener;
}
public WheelSurfPanView(Context context) {
super(context);
init(context, null);
}
public WheelSurfPanView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public WheelSurfPanView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
//当前类型 1 自定义模式 2 暴力模式
private int mType;
//最低圈数 默认值3 也就是说每次旋转都会最少转3圈
private int mMinTimes;
//分类数量 如果数量为负数 通过代码设置样式
private int mTypeNum = 6;
//每个扇形旋转的时间
private int mVarTime = 75;
//文字描述集合
private String[] mDeses;
//自定义图标集合
private Integer[] mIcons;
//背景颜色
private Integer[] mColors;
//整个旋转图的背景 只有类型为2时才需要
private Integer mMainImgRes;
//圆环的图片引用
private Integer mHuanImgRes;
//文字大小
private float mTextSize;
//文字颜色
private int mTextColor;
public void setmType(int mType) {
this.mType = mType;
}
public void setmMinTimes(int mMinTimes) {
this.mMinTimes = mMinTimes;
}
public void setmVarTime(int mVarTime) {
this.mVarTime = mVarTime;
}
public void setmTypeNum(int mTypeNum) {
this.mTypeNum = mTypeNum;
}
public void setmDeses(String[] mDeses) {
this.mDeses = mDeses;
}
public void setmIcons(List<Bitmap> mIcons) {
this.mListBitmap = mIcons;
}
public void setmColors(Integer[] mColors) {
this.mColors = mColors;
}
public void setmMainImgRes(Integer mMainImgRes) {
this.mMainImgRes = mMainImgRes;
}
public void setmHuanImgRes(Integer mHuanImgRes) {
this.mHuanImgRes = mHuanImgRes;
}
public void setmTextSize(float mTextSize) {
this.mTextSize = mTextSize;
}
public void setmTextColor(int mTextColor) {
this.mTextColor = mTextColor;
}
private void init(Context context, AttributeSet attrs) {
mContext = context;
setBackgroundColor(Color.TRANSPARENT);
if ( attrs != null ) {
//获得这个控件对应的属性。
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.wheelSurfView);
try {
mType = typedArray.getInteger(R.styleable.wheelSurfView_type, 1);
mVarTime = typedArray.getInteger(R.styleable.wheelSurfView_vartime, 0);
mMinTimes = typedArray.getInteger(R.styleable.wheelSurfView_minTimes, 3);
mTypeNum = typedArray.getInteger(R.styleable.wheelSurfView_typenum, 0);
if ( mTypeNum == -1 ) {
//用代码去配置这些参数
} else {
if ( mVarTime == 0 )
mVarTime = 75;
if ( mTypeNum == 0 )
throw new RuntimeException("找不到分类数量mTypeNum");
//每一个扇形的角度
mAngle = ( float ) (360.0 / mTypeNum);
if ( mType == 1 ) {
mHuanImgRes = typedArray.getResourceId(R.styleable.wheelSurfView_huanImg, 0);
if ( mHuanImgRes == 0 )
mYuanHuan = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.yuanhuan);
else {
mYuanHuan = BitmapFactory.decodeResource(mContext.getResources(), mHuanImgRes);
}
//文字大小
mTextSize = typedArray.getDimension(R.styleable.wheelSurfView_textSize, 14 * getScale());
//文字颜色 默认粉红色
mTextColor = typedArray.getColor(R.styleable.wheelSurfView_textColor, Color.parseColor("#ff00ff"));
//描述
int nameArray = typedArray.getResourceId(R.styleable.wheelSurfView_deses, -1);
if ( nameArray == -1 ) throw new RuntimeException("找不到描述");
mDeses = context.getResources().getStringArray(nameArray);
//图片
int iconArray = typedArray.getResourceId(R.styleable.wheelSurfView_icons, -1);
if ( iconArray == -1 ) throw new RuntimeException("找不到分类的图片资源");
String[] iconStrs = context.getResources().getStringArray(iconArray);
List<Integer> iconLists = new ArrayList<>();
for ( int i = 0; i < iconStrs.length; i++ ) {
iconLists.add(context.getResources().getIdentifier(iconStrs[i], "mipmap", context.getPackageName()));
}
mIcons = iconLists.toArray(new Integer[iconLists.size()]);
//颜色
int colorArray = typedArray.getResourceId(R.styleable.wheelSurfView_colors, -1);
if ( colorArray == -1 ) throw new RuntimeException("找不到背景颜色");
String[] colorStrs = context.getResources().getStringArray(colorArray);
if ( mDeses == null || mIcons == null || colorStrs == null )
throw new RuntimeException("找不到描述或图片或背景颜色资源");
if ( mDeses.length != mTypeNum || mIcons.length != mTypeNum || colorStrs.length != mTypeNum )
throw new RuntimeException("资源或描述或背景颜色的长度和mTypeNum不一致");
mColors = new Integer[mTypeNum];
//分析背景颜色
for ( int i = 0; i < colorStrs.length; i++ ) {
try {
mColors[i] = Color.parseColor(colorStrs[i]);
} catch ( Exception e ) {
throw new RuntimeException("颜色值有误");
}
}
//加载分类图片 存放图片的集合
mListBitmap = new ArrayList<>();
for ( int i = 0; i < mTypeNum; i++ ) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), mIcons[i]);
int ww = bitmap.getWidth();
int hh = bitmap.getHeight();
// 定义矩阵对象
Matrix matrix = new Matrix();
// 缩放原图
matrix.postScale(1f, 1f);
// 向左旋转45度,参数为正则向右旋转
matrix.postRotate(mAngle * i);
//bmp.getWidth(), 500分别表示重绘后的位图宽高
Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, ww, hh,
matrix, true);
mListBitmap.add(dstbmp);
}
//文字画笔
mTextPaint = new Paint();
//设置填充样式
mTextPaint.setStyle(Paint.Style.FILL);
//设置抗锯齿
mTextPaint.setAntiAlias(true);
//设置边界模糊
mTextPaint.setDither(true);
//设置画笔颜色
mTextPaint.setColor(mTextColor);
//设置字体大小
mTextPaint.setTextSize(mTextSize);
} else if ( mType == 2 ) {
mMainImgRes = typedArray.getResourceId(R.styleable.wheelSurfView_mainImg, 0);
//直接大图
if ( mMainImgRes == 0 )
throw new RuntimeException("类型为2必须要传大图mMainImgRes");
mMain = BitmapFactory.decodeResource(mContext.getResources(), mMainImgRes);
} else {
throw new RuntimeException("类型type错误");
}
}
} finally { //回收这个对象
typedArray.recycle();
}
}
//其他画笔
mPaint = new Paint();
//设置填充样式
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
//设置抗锯齿
mPaint.setAntiAlias(true);
//设置边界模糊
mPaint.setDither(true);
}
//目前的角度
private float currAngle = 0;
//记录上次的位置
private int lastPosition;
/**
* 开始转动
* pos 位置 1 开始 这里的位置上是按照逆时针递增的 比如当前指的那个选项是第一个 那么他左边的那个是第二个 以此类推
*/
public void startRotate(final int pos) {
//最低圈数是mMinTimes圈
int newAngle = ( int ) (360 * mMinTimes + (pos - 1) * mAngle + currAngle - (lastPosition == 0 ? 0 : ((lastPosition - 1) * mAngle)));
//计算目前的角度划过的扇形份数
int num = ( int ) ((newAngle - currAngle) / mAngle);
ObjectAnimator anim = ObjectAnimator.ofFloat(WheelSurfPanView.this, "rotation", currAngle, newAngle);
currAngle = newAngle;
lastPosition = pos;
// 动画的持续时间,执行多久?
anim.setDuration(num * mVarTime);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//将动画的过程态回调给调用者
if ( rotateListener != null )
rotateListener.rotating(animation);
}
});
final float[] f = {0};
anim.setInterpolator(new TimeInterpolator() {
@Override
public float getInterpolation(float t) {
float f1 = ( float ) (Math.cos((t + 1) * Math.PI) / 2.0f) + 0.5f;
Log.e("HHHHHHHh", "" + t + " " + (f[0] - f1));
f[0] = ( float ) (Math.cos((t + 1) * Math.PI) / 2.0f) + 0.5f;
return f[0];
}
});
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//当旋转结束的时候回调给调用者当前所选择的内容
if ( rotateListener != null ) {
if ( mType == 1 ) {
//去空格和前后空格后输出
String des = mDeses[(mTypeNum - pos + 1) %
mTypeNum].trim().replaceAll(" ", "");
rotateListener.rotateEnd(pos, des);
} else {
rotateListener.rotateEnd(pos, "");
}
}
}
});
// 正式开始启动执行动画
anim.start();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//视图是个正方形的 所以有宽就足够了 默认值是500 也就是WRAP_CONTENT的时候
int desiredWidth = 800;
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int width;
//Measure Width
if ( widthMode == MeasureSpec.EXACTLY ) {
//Must be this size
width = widthSize;
} else if ( widthMode == MeasureSpec.AT_MOST ) {
//Can't be bigger than...
width = Math.min(desiredWidth, widthSize);
} else {
//Be whatever you want
width = desiredWidth;
}
//将测得的宽度保存起来
mWidth = width;
mCenter = mWidth / 2;
//绘制扇形的半径 减掉50是为了防止边界溢出 具体效果你自己注释掉-50自己测试
mRadius = mWidth / 2 - 50;
//MUST CALL THIS
setMeasuredDimension(width, width);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if ( mTypeNum == -1 ) {
//先不管
} else {
if ( mType == 1 ) {
// 计算初始角度
// 从最上面开始绘制扇形会好看一点
float startAngle = -mAngle / 2 - 90;
final int paddingLeft = getPaddingLeft();
final int paddingRight = getPaddingRight();
final int paddingTop = getPaddingTop();
final int paddingBottom = getPaddingBottom();
int width = getWidth() - paddingLeft - paddingRight;
int height = getHeight() - paddingTop - paddingBottom;
for ( int i = 0; i < mTypeNum; i++ ) {
//设置绘制时画笔的颜色
mPaint.setColor(mColors[i]);
//画一个扇形
RectF rect = new RectF(mCenter - mRadius, mCenter - mRadius, mCenter
+ mRadius, mCenter + mRadius);
canvas.drawArc(rect, startAngle, mAngle, true, mPaint);
mTextPaint.setColor(mTextColor);
drawText(startAngle, mDeses[i], mRadius, mTextPaint, canvas);
int imgWidth = mRadius / 3;
int w = ( int ) (Math.abs(Math.cos(Math.toRadians(Math.abs(180 - mAngle * i)))) *
imgWidth + imgWidth * Math.abs(Math.sin(Math.toRadians(Math.abs(180 - mAngle * i)))));
int h = ( int ) (Math.abs(Math.sin(Math.toRadians(Math.abs(180 - mAngle * i)))) *
imgWidth + imgWidth * Math.abs(Math.cos(Math.toRadians(Math.abs(180 - mAngle * i)))));
float angle = ( float ) Math.toRadians(startAngle + mAngle / 2);
//确定图片在圆弧中 中心点的位置
float x = ( float ) (width / 2 + (mRadius / 2 + mRadius / 12) * Math.cos(angle));
float y = ( float ) (height / 2 + (mRadius / 2 + mRadius / 12) * Math.sin(angle));
// 确定绘制图片的位置
RectF rect1 = new RectF(x - w / 2, y - h / 2, x + w / 2, y + h / 2);
canvas.drawBitmap(mListBitmap.get(i), null, rect1, null);
//重置开始角度
startAngle = startAngle + mAngle;
}
//最后绘制圆环
Rect mDestRect = new Rect(0, 0, mWidth, mWidth);
canvas.drawBitmap(mYuanHuan, null, mDestRect, mPaint);
} else {
//大圆盘
Rect mDestRect = new Rect(0, 0, mWidth, mWidth);
canvas.drawBitmap(mMain, null, mDestRect, mPaint);
}
}
}
//绘制文字
private void drawText(float startAngle, String string, int radius, Paint textPaint, Canvas canvas) {
//创建绘制路径
Path circlePath = new Path();
//范围也是整个圆盘
RectF rect = new RectF(mCenter - radius, mCenter - radius, mCenter
+ radius, mCenter + radius);
//给定扇形的范围
circlePath.addArc(rect, startAngle, mAngle);
//圆弧的水平偏移
float textWidth = textPaint.measureText(string);
//圆弧的垂直偏移
float hOffset = ( float ) (Math.sin(mAngle / 2 / 180 * Math.PI) * radius) - textWidth / 2;
//绘制文字
canvas.drawTextOnPath(string, circlePath, hOffset, radius / 4, textPaint);
}
//再一次onDraw
public void show() {
//做最后的准备工作 检查数据是否合理
if ( mType == 1 ) {
if ( mHuanImgRes == null || mHuanImgRes == 0 )
mYuanHuan = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.yuanhuan);
else {
mYuanHuan = BitmapFactory.decodeResource(mContext.getResources(), mHuanImgRes);
}
//文字大小
if ( mTextSize == 0 )
mTextSize = 14 * getScale();
//文字颜色 默认粉红色
if ( mTextColor == 0 )
mTextColor = Color.parseColor("#ff00ff");
if ( mListBitmap.size() != mDeses.length || mListBitmap.size() != mColors.length
|| mDeses.length != mColors.length ) {
throw new RuntimeException("Icons数量和Deses和Colors三者数量必须与mTypeNum一致");
}
} else {
//直接大图
if ( mMainImgRes == null || mMainImgRes == 0 )
throw new RuntimeException("类型为2必须要传大图mMainImgRes");
mMain = BitmapFactory.decodeResource(mContext.getResources(), mMainImgRes);
}
if ( mTextPaint == null ) {
//文字画笔
mTextPaint = new Paint();
//设置填充样式
mTextPaint.setStyle(Paint.Style.FILL);
//设置抗锯齿
mTextPaint.setAntiAlias(true);
//设置边界模糊
mTextPaint.setDither(true);
//设置画笔颜色
mTextPaint.setColor(mTextColor);
//设置字体大小
mTextPaint.setTextSize(mTextSize);
}
if ( mTypeNum != 0 )
mAngle = ( float ) (360.0 / mTypeNum);
if ( mVarTime == 0 )
mVarTime = 75;
//重绘
invalidate();
}
private float getScale() {
TextView textView = new TextView(mContext);
textView.setTextSize(1);
return textView.getTextSize();
}
}
package com.mints.fairyland.ui.widgets.wheelsruf.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.mints.fairyland.R;
import com.mints.fairyland.ui.widgets.wheelsruf.listener.RotateListener;
import java.util.ArrayList;
import java.util.List;
public class WheelSurfView extends RelativeLayout {
//当前的圆盘VIew
private WheelSurfPanView mWheelSurfPanView;
//Context
private Context mContext;
//开始按钮
private ImageView mStart;
//动画回调监听
private RotateListener rotateListener;
public void setRotateListener(RotateListener rotateListener) {
mWheelSurfPanView.setRotateListener(rotateListener);
this.rotateListener = rotateListener;
}
public WheelSurfView(Context context) {
super(context);
init(context, null);
}
public WheelSurfView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public WheelSurfView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
//开始抽奖的图标
private Integer mGoImgRes;
private void init(Context context, AttributeSet attrs) {
mContext = context;
if ( attrs != null ) {
//获得这个控件对应的属性。
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.wheelSurfView);
try {
mGoImgRes = typedArray.getResourceId(R.styleable.wheelSurfView_goImg, 0);
} finally { //回收这个对象
typedArray.recycle();
}
}
//添加圆盘视图
mWheelSurfPanView = new WheelSurfPanView(mContext, attrs);
LayoutParams layoutParams =
new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mWheelSurfPanView.setLayoutParams(layoutParams);
addView(mWheelSurfPanView);
//添加开始按钮
mStart = new ImageView(mContext);
//如果用户没有设置自定义的图标就使用默认的
if ( mGoImgRes == 0 ) {
mStart.setImageResource(R.mipmap.node);
} else {
mStart.setImageResource(mGoImgRes);
}
//给图片设置LayoutParams
LayoutParams llStart =
new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llStart.addRule(RelativeLayout.CENTER_IN_PARENT);
mStart.setLayoutParams(llStart);
addView(mStart);
mStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//调用此方法是将主动权交个调用者 由调用者调用开始旋转的方法
if ( rotateListener != null )
rotateListener.rotateBefore(( ImageView ) v);
}
});
}
public void setConfig(Builder builder) {
if ( builder.mColors != null )
mWheelSurfPanView.setmColors(builder.mColors);
if ( builder.mDeses != null )
mWheelSurfPanView.setmDeses(builder.mDeses);
if ( builder.mHuanImgRes != 0 )
mWheelSurfPanView.setmHuanImgRes(builder.mHuanImgRes);
if ( builder.mIcons != null )
mWheelSurfPanView.setmIcons(builder.mIcons);
if ( builder.mMainImgRes != 0 )
mWheelSurfPanView.setmMainImgRes(builder.mMainImgRes);
if ( builder.mMinTimes != 0 )
mWheelSurfPanView.setmMinTimes(builder.mMinTimes);
if ( builder.mTextColor != 0 )
mWheelSurfPanView.setmTextColor(builder.mTextColor);
if ( builder.mTextSize != 0 )
mWheelSurfPanView.setmTextSize(builder.mTextSize);
if ( builder.mType != 0 )
mWheelSurfPanView.setmType(builder.mType);
if ( builder.mVarTime != 0 )
mWheelSurfPanView.setmVarTime(builder.mVarTime);
if ( builder.mTypeNum != 0 )
mWheelSurfPanView.setmTypeNum(builder.mTypeNum);
mWheelSurfPanView.show();
}
/**
* 开始旋转
*
* @param pisition 旋转最终的位置 注意 从1 开始 而且是逆时针递增
*/
public void startRotate(int pisition) {
if ( mWheelSurfPanView != null ) {
mWheelSurfPanView.startRotate(pisition);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//视图是个正方形的 所以有宽就足够了 默认值是500 也就是WRAP_CONTENT的时候
setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
// Children are just made to fill our space.
final int childWidthSize = getMeasuredWidth();
//高度和宽度一样
heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
//onMeasure调用获取到当前视图大小之后,
// 手动按照一定的比例计算出中间开始按钮的大小,
// 再设置给那个按钮,免得造成用户传的图片不合适之后显示贼难看
// 只设置一次
if ( isFirst ) {
isFirst = !isFirst;
//获取中间按钮的大小
ViewTreeObserver vto = mStart.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi( Build.VERSION_CODES.KITKAT )
@Override
public void onGlobalLayout() {
mStart.getViewTreeObserver().removeGlobalOnLayoutListener(this);
float w = mStart.getMeasuredWidth();
float h = mStart.getMeasuredHeight();
//计算新的大小 默认为整个大小最大值的0.17 至于为什么是0.17 我只想说我乐意。。。。
int newW = ( int ) ((( float ) childWidthSize) * 0.17);
int newH = ( int ) ((( float ) childWidthSize) * 0.17 * h / w);
ViewGroup.LayoutParams layoutParams = mStart.getLayoutParams();
layoutParams.width = newW;
layoutParams.height = newH;
mStart.setLayoutParams(layoutParams);
}
});
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
//记录当前是否是第一次回调onMeasure
private boolean isFirst = true;
//建造者模式
public static final class Builder {
//当前类型 1 自定义模式 2 暴力模式
private int mType = 0;
//最低圈数 默认值3 也就是说每次旋转都会最少转3圈
private int mMinTimes = 0;
//分类数量 如果数量为负数 通过代码设置样式
private int mTypeNum = 0;
//每个扇形旋转的时间
private int mVarTime = 0;
//文字描述集合
private String[] mDeses;
//自定义图标集合
private List<Bitmap> mIcons;
//背景颜色
private Integer[] mColors;
//整个旋转图的背景 只有类型为2时才需要
private Integer mMainImgRes = 0;
//GO图标
private Integer mGoImgRes = 0;
//圆环的图片引用
private Integer mHuanImgRes = 0;
//文字大小
private float mTextSize = 0;
//文字颜色
private int mTextColor = 0;
public final Builder setmType(int mType) {
this.mType = mType;
return this;
}
public final Builder setmTypeNum(int mTypeNum) {
this.mTypeNum = mTypeNum;
return this;
}
public final Builder setmGoImgRes(int mGoImgRes) {
this.mGoImgRes = mGoImgRes;
return this;
}
public final Builder setmMinTimes(int mMinTimes) {
this.mMinTimes = mMinTimes;
return this;
}
public final Builder setmVarTime(int mVarTime) {
this.mVarTime = mVarTime;
return this;
}
public final Builder setmDeses(String[] mDeses) {
this.mDeses = mDeses;
return this;
}
public final Builder setmIcons(List<Bitmap> mIcons) {
this.mIcons = mIcons;
return this;
}
public final Builder setmColors(Integer[] mColors) {
this.mColors = mColors;
return this;
}
public final Builder setmMainImgRes(Integer mMainImgRes) {
this.mMainImgRes = mMainImgRes;
return this;
}
public final Builder setmHuanImgRes(Integer mHuanImgRes) {
this.mHuanImgRes = mHuanImgRes;
return this;
}
public final Builder setmTextSize(float mTextSize) {
this.mTextSize = mTextSize;
return this;
}
public final Builder setmTextColor(int mTextColor) {
this.mTextColor = mTextColor;
return this;
}
public final Builder build() {
return this;
}
}
//旋转图片
public static List<Bitmap> rotateBitmaps(List<Bitmap> source) {
float mAngle = ( float ) (360.0 / source.size());
List<Bitmap> result = new ArrayList<>();
for ( int i = 0; i < source.size(); i++ ) {
Bitmap bitmap = source.get(i);
int ww = bitmap.getWidth();
int hh = bitmap.getHeight();
// 定义矩阵对象
Matrix matrix = new Matrix();
// 缩放原图
matrix.postScale(1f, 1f);
// 向左旋转45度,参数为正则向右旋转
matrix.postRotate(mAngle * i);
//bmp.getWidth(), 500分别表示重绘后的位图宽高
Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, ww, hh,
matrix, true);
result.add(dstbmp);
}
return result;
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="#50ffffff" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="10dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:wheelSurfView="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/bg_turn"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="40dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="6dp"
android:src="@mipmap/ic_voice" />
<com.sunfusheng.marqueeview.MarqueeView
android:id="@+id/marqueeView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:mvAnimDuration="1000"
app:mvInterval="4000"
app:mvSingleLine="true"
app:mvTextColor="@color/color_cb4a39"
app:mvTextSize="15sp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="@mipmap/bg_turn_font" />
<TextView
android:id="@+id/tvHintTurnTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textColor="@color/red"
android:textSize="18sp"
tools:text="每日0点重置抽奖次数" />
<com.mints.fairyland.ui.widgets.wheelsruf.view.WheelSurfView
android:id="@+id/turnTableView"
android:layout_width="330dp"
android:layout_height="330dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
wheelSurfView:typenum="-1" />
<include layout="@layout/layout_turn_btn" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<TextView
android:id="@+id/tv_turn_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="6dp"
tools:text="抽奖+1"
android:textColor="@color/red"
android:textSize="14sp" />
<ImageView
android:id="@+id/ic_turn_icon"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
tools:src="@mipmap/ic_launcher_main" />
<TextView
android:id="@+id/tv_turn_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
tools:text="搜索赚"
android:textColor="@color/red"
android:textSize="14sp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="5dp"
android:background="@drawable/shape_turn_btn"
android:elevation="18dp"
android:orientation="vertical"
android:paddingTop="4dp"
android:paddingBottom="10dp">
<TextView
android:id="@+id/tvTurnTimes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="6dp"
android:textColor="@color/black"
android:textSize="12sp" />
<com.mints.fairyland.ui.widgets.ExpandableGridView
android:id="@+id/gvTurnTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="80dp"
android:divider="@null"
android:dividerHeight="10pt"
android:elevation="6dip"
android:listSelector="#00000000"
android:numColumns="4"
android:scrollbars="none"
android:stretchMode="spacingWidthUniform" />
<TextView
android:id="@+id/tvTurnMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableTop="@mipmap/ic_arrow_down"
android:drawablePadding="4dp"
android:text="点击获取更多奖励"
android:textColor="@color/red"
android:textSize="14sp"></TextView>
</LinearLayout>
\ No newline at end of file
......@@ -180,4 +180,31 @@
<attr name="text" format="string" />
<attr name="radius" format="integer" />
</declare-styleable>
<declare-styleable name="wheelSurfView">
<!--类型 根据类型来加载资源 1 默认类型 用户需要提供文字和图片 2 暴力模式 用户只需要提供一张圆形的用来旋转的图片-->
<attr name="type" format="integer"/>
<!--最低圈数 默认值3 也就是说每次旋转都会最少转3圈-->
<attr name="minTimes" format="integer"/>
<!--扇形的数量 也就是奖品的份数-->
<attr name="typenum" format="integer"/>
<!--每一个扇形旋转消耗的时间-->
<attr name="vartime" format="integer"/>
<!--类型为1的时候 需要提供每个扇形上面的文字描述 长度必须和typenum一致-->
<attr name="deses" format="reference"/>
<!--类型为1的时候 需要提供每个扇形上面的图片展示 长度必须和typenum一致-->
<attr name="icons" format="reference"/>
<!--类型为1的时候 需要提供每个扇形背景颜色 长度必须和typenum一致-->
<attr name="colors" format="reference"/>
<!--中间图片的引用 有默认值 不填则使用默认值-->
<attr name="goImg" format="reference"/>
<!--圆环的图片引用 有默认值 不填则使用默认值-->
<attr name="huanImg" format="reference"/>
<!--如果类型为2 此值必填-->
<attr name="mainImg" format="reference"/>
<!--文字大小-->
<attr name="textSize" format="dimension"/>
<!--文字颜色-->
<attr name="textColor" format="reference|color"/>
</declare-styleable>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment