Commit cf3b7ef7 authored by mengcuiguang's avatar mengcuiguang

添加开屏广告

parent 7fb14a0a
......@@ -82,6 +82,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activitys.SplashBackActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="false"
android:theme="@style/AppTheme.TranslucentSplash">
</activity>
<activity
android:name=".ui.activitys.SplashAdActivity"
android:exported="false"
......
......@@ -60,6 +60,9 @@ public class MintsApplication extends MultiDexApplication {
// 三方配置
if (isMainProcess(this)) {
// 判断应用是否在前台
ForegroundOrBackground.init(this);
thirdConfig();
}
}
......@@ -121,8 +124,7 @@ public class MintsApplication extends MultiDexApplication {
if (AppPreferencesManager.INSTANCE.get()
.getBoolean(Constant.LOAN_PERMISSION_FLAG, true)) return;
// 判断应用是否在前台
ForegroundOrBackground.init(this);
// 数美初始化
ShumeiManager.getInstance().initShumei();
......
......@@ -32,7 +32,7 @@ class SplashActivity : BaseActivity() {
var powerDialog: PowerDialog? = null
var powerDialog2: PowerDialog2? = null
private var mProgressBar: CycleProgress? = null
private val AD_TIME_OUT = 3000
private val AD_TIME_OUT = 4000
var timer: CountDownTimerSupport? = null
private var isAdSuc = false
......
package com.duben.dayplaylet.ui.activitys
import android.view.KeyEvent
import com.duben.dayplaylet.R
import com.duben.dayplaylet.ad.splash.SplashManager
import com.duben.dayplaylet.ui.activitys.base.BaseActivity
import com.duben.dayplaylet.ui.widgets.CycleProgress
import com.duben.dayplaylet.ui.widgets.countdowntimer.CountDownTimerSupport
import com.duben.dayplaylet.ui.widgets.countdowntimer.OnCountDownTimerListener
import com.duben.dayplaylet.utils.LogUtil
/**
* 描述:启动页
* 作者:孟崔广
* 时间:2022/12/4 18:06
*/
class SplashBackActivity : BaseActivity() {
private var mProgressBar: CycleProgress? = null
private val AD_TIME_OUT = 3000
var timer: CountDownTimerSupport? = null
private var isAdSuc = false
override fun toggleOverridePendingTransition() = true
override fun getOverridePendingTransitionMode() = TransitionMode.FADE
override fun getContentViewLayoutID(): Int {
return R.layout.activity_splash_back
}
override fun initViewsAndEvents() {
mProgressBar = findViewById(R.id.progressBar)
initData()
}
private fun initData() {
SplashManager.preLoadAd(this@SplashBackActivity)
mProgressBar!!.startOneAnim()
try {
startTimer()
} catch (e: Exception) {
goToMainActivity()
}
}
fun startTimer() {
if (timer != null) { //防止计时器重复
timer!!.stop()
timer = null
}
timer = CountDownTimerSupport(AD_TIME_OUT.toLong(), 1000)
timer!!.setOnCountDownTimerListener(object : OnCountDownTimerListener {
override fun onTick(millisUntilFinished: Long) {
if (!isFinishing) {
}
}
override fun onFinish() {
if (!isFinishing) {
if (mProgressBar != null) {
mProgressBar!!.setCompleteNoAnim()
}
if (SplashManager.isSuccessStatus()) {
LogUtil.d("SplashNewActivity-->", "SplashNewActivity--> ad show")
isAdSuc = true
if (mProgressBar != null) {
mProgressBar!!.setCompleteNoAnim()
}
// 跳转广告
readyGoThenKill(SplashForeAdActivity::class.java)
} else {
goToMainActivity()
}
}
}
})
timer!!.start()
}
override fun onDestroy() {
super.onDestroy()
if (timer != null) {
timer!!.stop()
timer = null
}
}
override fun isApplyKitKatTranslucency(): Boolean {
return false
}
/**
* 跳转到主页面
*/
private fun goToMainActivity() {
finish()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
return if (keyCode == KeyEvent.KEYCODE_BACK) {
true
} else super.onKeyDown(
keyCode,
event
)
}
}
\ No newline at end of file
......@@ -12,6 +12,8 @@ import com.duben.dayplaylet.manager.ActivityPageManager;
import com.duben.dayplaylet.manager.TrackManager;
import com.duben.dayplaylet.mvp.presenters.VersionUpdatePresenter;
import com.duben.dayplaylet.ui.activitys.MainActivity;
import com.duben.dayplaylet.ui.activitys.SplashBackActivity;
import com.duben.dayplaylet.ui.activitys.SplashForeAdActivity;
import java.lang.ref.WeakReference;
......@@ -80,44 +82,44 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
if (activity == null)
return;
// String simpleName = activity.getClass().getSimpleName();
// if (TextUtils.equals(simpleName, "SplashActivity") ||
// TextUtils.equals(simpleName, "SplashAdActivity") ||
// TextUtils.equals(simpleName, "SplashForeAdActivity") ||
// TextUtils.equals(simpleName, "VipActivity")) {
// count++;
// System.out.println("mcg __>>>>>>>:: onActivityStarted simpleName="+simpleName+" 进入 count=" + count);
//
// return;
// }
//
// if (count == 0) {
String simpleName = activity.getClass().getSimpleName();
if (TextUtils.equals(simpleName, "SplashActivity") ||
TextUtils.equals(simpleName, "SplashAdActivity") ||
TextUtils.equals(simpleName, "SplashForeAdActivity") ||
TextUtils.equals(simpleName, "SplashBackActivity")) {
count++;
System.out.println("mcg __>>>>>>>:: onActivityStarted simpleName=" + simpleName + " 进入 count=" + count);
return;
}
if (count == 0) {
// long currentTimeMillis = System.currentTimeMillis();
// long diff = currentTimeMillis - activityStoppedTime;
// long diffInSeconds = diff / 1000;
// System.out.println("mcg -->>>>>:: diffInSeconds=" + diffInSeconds + " adSuccessStatus=" + SplashManager.INSTANCE.isSuccessStatus());
// if (diffInSeconds >= 10 && SplashManager.INSTANCE.isSuccessStatus()) {
// activity.startActivity(new Intent(activity, SplashForeAdActivity.class));
activity.startActivity(new Intent(activity, SplashBackActivity.class));
// }
// }
// count++;
//
// System.out.println("mcg __>>>>>>>:: onActivityStarted simpleName="+simpleName+" 进入 count=" + count);
}
count++;
System.out.println("mcg __>>>>>>>:: onActivityStarted simpleName=" + simpleName + " 进入 count=" + count);
}
@Override
public void onActivityStopped(Activity activity) {
// String simpleName = activity.getClass().getSimpleName();
//
// count--;
// System.out.println("mcg __>>>>>>>:: onActivityStopped simpleName="+simpleName+" 关闭 count=" + count);
// if (count < 0) {
// count = 0;
// }
String simpleName = activity.getClass().getSimpleName();
count--;
System.out.println("mcg __>>>>>>>:: onActivityStopped simpleName=" + simpleName + " 关闭 count=" + count);
if (count < 0) {
count = 0;
}
// if (count == 0) {
// System.out.println("mcg -->>>>>:: onActivityStopped");
// activityStoppedTime = System.currentTimeMillis();
// SplashManager.INSTANCE.preLoadAd(activity);
//// SplashManager.INSTANCE.preLoadAd(activity);
// }
}
......
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="match_parent">
<ImageView
android:id="@+id/app_logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:src="@mipmap/ic_launcher_main" />
<TextView
android:layout_below="@+id/app_logo"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_height="wrap_content"
android:layout_above="@id/progressBar"
android:text="@string/app_name"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="36sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/progressBar"
android:layout_centerHorizontal="true"
android:text="正在加载功能模块..."
android:textColor="@color/black"
android:textSize="16sp" />
<com.duben.dayplaylet.ui.widgets.CycleProgress
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/app_logo"
android:layout_alignParentBottom="true"
android:layout_marginStart="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="50dp" />
</RelativeLayout>
\ 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