Commit e5c7dbbb authored by wanglei's avatar wanglei

...

parent 50ec98e3
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
tools:targetApi="34"> tools:targetApi="34">
<activity <activity
android:name=".ui.activity.SplashActivity" android:name=".ui.activity.splash.Splash2Activity"
android:exported="true" android:exported="true"
android:launchMode="singleTask"> android:launchMode="singleTask">
<intent-filter> <intent-filter>
......
...@@ -4,8 +4,12 @@ import android.app.Activity ...@@ -4,8 +4,12 @@ import android.app.Activity
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.base.browserwhite.fcm.FCMManager
import com.base.browserwhite.fcm.ScreenStatusReceiver
import com.base.browserwhite.help.BlackUtils
import com.base.browserwhite.help.ConfigHelper import com.base.browserwhite.help.ConfigHelper
import com.base.browserwhite.ui.activity.SplashActivity import com.base.browserwhite.help.InstallHelps
import com.base.browserwhite.ui.activity.splash.Splash2Activity
import com.base.browserwhite.utils.ActivityManagerUtils import com.base.browserwhite.utils.ActivityManagerUtils
import com.base.browserwhite.utils.LogEx import com.base.browserwhite.utils.LogEx
import com.facebook.FacebookSdk import com.facebook.FacebookSdk
...@@ -27,9 +31,21 @@ class MyApplication : Application() { ...@@ -27,9 +31,21 @@ class MyApplication : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
context = this context = this
}
fun initApp() {
FacebookSdk.sdkInitialize(applicationContext) FacebookSdk.sdkInitialize(applicationContext)
val topic = ConfigHelper.packageName + "_push"
LogEx.logDebug(TAG, "topic=${topic}")
FCMManager.initFirebase(this)
FCMManager.subscribeToTopic(topic)
ScreenStatusReceiver.setupScreenStatusListener(this)
InstallHelps.init()
BlackUtils.requestBlack()
initLifeListener() initLifeListener()
initPRDownloader() initFileDownloader()
} }
...@@ -67,14 +83,14 @@ class MyApplication : Application() { ...@@ -67,14 +83,14 @@ class MyApplication : Application() {
if (activity.localClassName.contains("AppLovinFullscreenActivity")) { if (activity.localClassName.contains("AppLovinFullscreenActivity")) {
flag = false flag = false
} }
LogEx.logDebug(TAG, "flag=$flag" + " activity:" + activity.localClassName) LogEx.logDebug(TAG, "flag=$flag" + " activity:" + activity.localClassName)
if (flag) { if (flag) {
topActivity?.startActivity( topActivity?.startActivity(
Intent( Intent(
topActivity, topActivity,
SplashActivity::class.java Splash2Activity::class.java
).apply { ).apply {
putExtra("isHotLaunch", true) putExtra("isHotLaunch", true)
putExtra("type", -1) putExtra("type", -1)
...@@ -108,7 +124,7 @@ class MyApplication : Application() { ...@@ -108,7 +124,7 @@ class MyApplication : Application() {
}) })
} }
private fun initPRDownloader() { private fun initFileDownloader() {
// 创建 FileDownloader 的配置对象 // 创建 FileDownloader 的配置对象
// val config = FileDownloader.Config.Builder() // val config = FileDownloader.Config.Builder()
...@@ -121,4 +137,6 @@ class MyApplication : Application() { ...@@ -121,4 +137,6 @@ class MyApplication : Application() {
// 初始化 FileDownloader // 初始化 FileDownloader
FileDownloader.setupOnApplicationOnCreate(this) FileDownloader.setupOnApplicationOnCreate(this)
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ import androidx.core.graphics.drawable.IconCompat ...@@ -16,7 +16,7 @@ import androidx.core.graphics.drawable.IconCompat
import com.base.browserwhite.MyApplication import com.base.browserwhite.MyApplication
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.help.EventUtils import com.base.browserwhite.help.EventUtils
import com.base.browserwhite.ui.activity.SplashActivity import com.base.browserwhite.ui.activity.splash.Splash2Activity
import com.base.browserwhite.utils.AppPreferences import com.base.browserwhite.utils.AppPreferences
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
...@@ -54,7 +54,7 @@ object NotificationUtil { ...@@ -54,7 +54,7 @@ object NotificationUtil {
bigRemoteViews.setOnClickPendingIntent(0, cancelNotificationPendingIntent(context, actionId)) bigRemoteViews.setOnClickPendingIntent(0, cancelNotificationPendingIntent(context, actionId))
//跳转 //跳转
val intent = Intent(context, SplashActivity::class.java) val intent = Intent(context, Splash2Activity::class.java)
intent.putExtra("actionId", actionId) intent.putExtra("actionId", actionId)
val btnRequestCode = Random().nextInt(1000) val btnRequestCode = Random().nextInt(1000)
val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE) val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE)
......
package com.base.browserwhite.help
import android.os.Build
import com.base.browserwhite.BuildConfig
import com.base.browserwhite.ads.AdmobMaxHelper
import com.base.browserwhite.utils.AppPreferences
import com.base.browserwhite.utils.LogEx
import okhttp3.Call
import okhttp3.Callback
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject
import java.io.IOException
object BlackUtils {
private val TAG = "BlackUtils"
private val blcurl by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/${
pkg.filter { it.isLowerCase() }.substring(4, 9)
}cl"
)
url.append("?pkg=$pkg")
url.toString()
}
fun requestBlack() {
val pkg = ConfigHelper.packageName
val s = JSONObject()
val s2 = JSONObject()
.put("${pkg}_3", AppPreferences.getInstance().getString("Equipment", ""))
.put("${pkg}_4", AppPreferences.getInstance().getString("Manufacturer", ""))
// .put("${pkg}_5", AppPreferences.getInstance().getString("svn", ""))
.put("${pkg}_5", Build.VERSION.SDK_INT)
.put("${pkg}_8", BuildConfig.VERSION_NAME)
.put("${pkg}_9", AppPreferences.getInstance().getString("uuid", ""))
.put("${pkg}_10", AppPreferences.getInstance().getString("gid", ""))
.put("${pkg}_13", "android")
.put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_15", "google")
.put("${pkg}_24", BuildConfig.BUILD_TYPE)
val data = JSONObject()
.put("data", s)
.put("bp", s2)
.toString()
val body = AESHelper.encrypt(data)
.toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
val client = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
}
}.build()
val request = Request.Builder()
.url(blcurl)
.post(body)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
}
override fun onResponse(call: Call, response: Response) {
response.body?.string()?.let {
val i = Regex("\"data\":\"(.*?)\"").find(it)
if (i.toString() != "null") {
i!!.groupValues[1].let {
val str = AESHelper.decrypt(it)
LogEx.logDebug(TAG, "black str=$str")
AdmobMaxHelper.isBlack = str.equals("true")
}
}
}
}
})
}
}
\ No newline at end of file
package com.base.browserwhite.help package com.base.browserwhite.help
import com.base.browserwhite.ui.activity.SplashActivity import com.base.browserwhite.ui.activity.splash.Splash2Activity
object ConfigHelper { object ConfigHelper {
...@@ -41,7 +40,7 @@ object ConfigHelper { ...@@ -41,7 +40,7 @@ object ConfigHelper {
"adActivity", "adActivity",
"AdActivity", "AdActivity",
"AppLovinFullscreenActivity", "AppLovinFullscreenActivity",
// SplashActivity::class.java.simpleName Splash2Activity::class.java.simpleName
// 返回前台时不跳转启动页的 activity // 返回前台时不跳转启动页的 activity
) )
......
...@@ -18,8 +18,8 @@ import androidx.core.graphics.drawable.IconCompat ...@@ -18,8 +18,8 @@ import androidx.core.graphics.drawable.IconCompat
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.bean.ConstObject import com.base.browserwhite.bean.ConstObject
import com.base.browserwhite.ui.activity.MainActivity import com.base.browserwhite.ui.activity.MainActivity
import com.base.browserwhite.ui.activity.SplashActivity
import com.base.browserwhite.help.EventUtils import com.base.browserwhite.help.EventUtils
import com.base.browserwhite.ui.activity.splash.Splash2Activity
import kotlin.random.Random import kotlin.random.Random
...@@ -100,7 +100,7 @@ class StayNotificationService : Service() { ...@@ -100,7 +100,7 @@ class StayNotificationService : Service() {
val expendView = RemoteViews(context.packageName, R.layout.stay_notification_big) val expendView = RemoteViews(context.packageName, R.layout.stay_notification_big)
val requestCode1 = Random.nextInt(1800) val requestCode1 = Random.nextInt(1800)
val intent0 = Intent(context, SplashActivity::class.java).apply { val intent0 = Intent(context, Splash2Activity::class.java).apply {
putExtra("actionId", ConstObject.ID_JUNK_CLEANER) putExtra("actionId", ConstObject.ID_JUNK_CLEANER)
} }
val pendingIntent1 = val pendingIntent1 =
...@@ -109,7 +109,7 @@ class StayNotificationService : Service() { ...@@ -109,7 +109,7 @@ class StayNotificationService : Service() {
expendView.setOnClickPendingIntent(R.id.ll_1, pendingIntent1) expendView.setOnClickPendingIntent(R.id.ll_1, pendingIntent1)
val requestCode2 = Random.nextInt(1800) val requestCode2 = Random.nextInt(1800)
val intent2 = Intent(context, SplashActivity::class.java).apply { val intent2 = Intent(context, Splash2Activity::class.java).apply {
putExtra("actionId", ConstObject.ID_NEWS) putExtra("actionId", ConstObject.ID_NEWS)
} }
val pendingIntent2 = val pendingIntent2 =
...@@ -118,7 +118,7 @@ class StayNotificationService : Service() { ...@@ -118,7 +118,7 @@ class StayNotificationService : Service() {
expendView.setOnClickPendingIntent(R.id.ll_2, pendingIntent2) expendView.setOnClickPendingIntent(R.id.ll_2, pendingIntent2)
val requestCode3 = Random.nextInt(1800) val requestCode3 = Random.nextInt(1800)
val intent3 = Intent(context, SplashActivity::class.java).apply { val intent3 = Intent(context, Splash2Activity::class.java).apply {
putExtra("actionId", ConstObject.ID_SCAN_CODE) putExtra("actionId", ConstObject.ID_SCAN_CODE)
} }
val pendingIntent3 = val pendingIntent3 =
...@@ -128,7 +128,7 @@ class StayNotificationService : Service() { ...@@ -128,7 +128,7 @@ class StayNotificationService : Service() {
val requestCode4 = Random.nextInt(1800) val requestCode4 = Random.nextInt(1800)
val intent4 = Intent(context, SplashActivity::class.java).apply { val intent4 = Intent(context, Splash2Activity::class.java).apply {
putExtra("actionId", ConstObject.ID_APP_PROCESS) putExtra("actionId", ConstObject.ID_APP_PROCESS)
} }
val pendingIntent4 = val pendingIntent4 =
......
package com.base.browserwhite.ui.activity.splash
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.text.SpannableString
import android.text.Spanned
import android.text.style.UnderlineSpan
import com.base.browserwhite.MyApplication
import com.base.browserwhite.bean.ConstObject.ifAgreePrivacy
import com.base.browserwhite.databinding.ActivitySplashBinding
import com.base.browserwhite.help.ConfigHelper
class PrivacyManager {
private val binding: ActivitySplashBinding
private val context: Activity
private val listener: onUserPrivacyAggreementListener
constructor(
binding: ActivitySplashBinding,
context: Activity,
listener: onUserPrivacyAggreementListener
) {
this.binding = binding
this.context = context
this.listener = listener
initView()
}
private fun initView() {
val spannableString = SpannableString("Privacy Policy")
spannableString.setSpan(
UnderlineSpan(),
0,
spannableString.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
binding.idTvPrivacyPolicy.text = spannableString
binding.idTvPrivacyPolicy.setOnClickListener {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse(ConfigHelper.privacyPolicy)
)
context.startActivity(intent)
}
var clicked = false
binding.idTvStart.setOnClickListener {
if (clicked) {
return@setOnClickListener
}
clicked = true
ifAgreePrivacy = true
(context.application as MyApplication).initApp()
listener.onAgreePrivacy()
}
}
interface onUserPrivacyAggreementListener {
fun onAgreePrivacy()
}
}
\ No newline at end of file
package com.base.browserwhite.ui.activity.splash
import CloseNotificationReceiver
import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.Handler
import android.view.KeyEvent
import androidx.activity.result.contract.ActivityResultContracts
import com.base.browserwhite.ads.AdmobMaxHelper
import com.base.browserwhite.bean.ConstObject.ifAgreePrivacy
import com.base.browserwhite.databinding.ActivitySplashBinding
import com.base.browserwhite.fcm.NotificationUtil
import com.base.browserwhite.help.EventUtils
import com.base.browserwhite.service.StayNotificationService.Companion.startStayNotification
import com.base.browserwhite.ui.activity.BaseActivity
import com.base.browserwhite.utils.BarUtils
@SuppressLint("CustomSplashScreen")
class Splash2Activity : BaseActivity<ActivitySplashBinding>(),
PrivacyManager.onUserPrivacyAggreementListener, TaskManager.ProgressListener {
private val TAG = "NewStartActivity"
private fun initStatusBar() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
if (Build.VERSION.SDK_INT >= 33) {
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}.launch(
Manifest.permission.POST_NOTIFICATIONS
)
}
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK) {
EventUtils.event("back")
}
return super.onKeyDown(keyCode, event)
}
override val binding: ActivitySplashBinding by lazy {
ActivitySplashBinding.inflate(layoutInflater)
}
private var mTaskManager: TaskManager? = null
var jumpType = 0
override fun initView() {
initStatusBar()
if (isDestroyed) {
return
}
NotificationUtil.stopNotificationHandler()
jumpType = intent.getIntExtra("actionId", 0)
closeNotification()
mTaskManager = TaskManager(binding, this)
if (ifAgreePrivacy) {
onAgreePrivacy()
} else {
PrivacyManager(binding, this, this)
}
}
private fun closeNotification() {
sendBroadcast(Intent(this, CloseNotificationReceiver::class.java).apply {
this.action = CloseNotificationReceiver.Action
this.putExtra(CloseNotificationReceiver.NotificationId, jumpType)
})
}
override fun onAgreePrivacy() {
EventUtils.event("app_start")
if (jumpType == 0) {
startStayNotification()
}
AdmobMaxHelper.preloadAd(this)
mTaskManager?.startProgress()
loadAd()
}
override fun onProgressMax() {
Handler().postDelayed({
StartUtils.jumpNextPage(this)
}, 500)
}
private fun loadAd() {
AdmobMaxHelper.admobMaxShowOpenAd(this, {
mTaskManager?.pauseProgress()
}, {
mTaskManager?.pauseProgress()
runOnUiThread {
mTaskManager?.maxProgress()
}
})
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
}
private var isPause = false
override fun onStart() {
super.onStart()
isPause = false
}
override fun onPause() {
super.onPause()
isPause = true
EventUtils.event("onPause")
}
override fun onResume() {
super.onResume()
isPause = false
EventUtils.event("onResume")
}
override fun onStop() {
super.onStop()
isPause = true
}
}
\ No newline at end of file
package com.base.browserwhite.ui.activity.splash
import android.app.Activity
import android.content.Intent
import android.util.Log
import com.base.browserwhite.ui.activity.MainActivity
object StartUtils {
private val TAG = "SplashJumpUtils"
fun jumpNextPage(context: Activity) {
var jumpType = context.intent.getIntExtra("actionId", 0)
Log.e(TAG, "actionId: $jumpType")
if (jumpType == 0) {
val uri = context.intent.data
val str = (uri?.getQueryParameter("type") ?: "0")
jumpType = str.toIntOrNull() ?: 0
if (jumpType != 0) {
}
}
when (jumpType) {
//=================================主动广播=======================================
//================================被动广播=========================================
else -> {
val isHotLaunch = context.intent?.extras?.getBoolean("isHotLaunch", false) ?: false
if (!isHotLaunch) {
context.startActivity(Intent(context, MainActivity::class.java))
}
}
}
context.finish()
}
}
\ No newline at end of file
package com.base.browserwhite.ui.activity.splash
import android.os.Handler
import android.view.View
import androidx.core.view.isVisible
import com.base.browserwhite.databinding.ActivitySplashBinding
class TaskManager {
private val binding: ActivitySplashBinding
private var mHandler: Handler
private var mIsPaused = false
private var mProgress = 0
private val listener: ProgressListener
constructor(binding: ActivitySplashBinding, listener: ProgressListener) {
this.binding = binding
this.listener = listener
mHandler = Handler()
initView()
}
var loadTime: Int = 15
private fun initView() {
//loadTime = SPUtils.getInstance().getInt("loading_page_time", 15)
binding.pb.max = loadTime
binding.pb.progress = 0
}
fun startProgress() {
binding.idTvStart.isVisible = false
binding.llStart.visibility = View.GONE
binding.llProgress.visibility = View.VISIBLE
val mRunnable: Runnable = object : Runnable {
override fun run() {
if (!mIsPaused) {
mProgress++ // 计算进度
binding.pb.progress = mProgress
if (mProgress < loadTime) {
mHandler.postDelayed(this, 1000) // 每秒钟更新一次进度
} else {
listener.onProgressMax()
pauseProgress()
}
}
}
}
mHandler.postDelayed(mRunnable, 1000)
}
fun pauseProgress() {
if (!mIsPaused) {
mIsPaused = true
mHandler.removeCallbacksAndMessages(null)
}
}
fun maxProgress() {
binding.pb.progress = binding.pb.max
listener.onProgressMax()
}
interface ProgressListener {
fun onProgressMax()
}
}
\ 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