Commit 78a05aab authored by wanglei's avatar wanglei

...启动页

parent 32115b77
......@@ -17,15 +17,13 @@
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:theme="@style/Theme.PdfOneRead"
tools:targetApi="31">
<activity
android:name=".ui.document.DocumentActivity"
android:exported="false" />
<activity
android:name=".ui.splash.SystemStartActivity"
android:exported="true"
......@@ -39,54 +37,60 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.splash.MyStartActivity"
android:exported="false"
android:launchMode="singleTask"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.search.SearchActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.pdf.PdfActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.pdf.PdfMergeActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.pdf.PdfSelectActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.pdf.PdfSplitActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.pdf.PdfLoadingActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.document.DocumentActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<provider
android:name="androidx.core.content.FileProvider"
......
......@@ -20,6 +20,16 @@ object ConstObject {
const val DO_LOCK_PDF = "do_lock_pdf"
const val DO_UNLOCK_PDF = "do_unlock_pdf"
//是否第一次启动
var isFirstStart = true
get() {
return AppPreferences.getInstance().getBoolean("isFirstStart", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("isFirstStart", value, true)
}
var ifAgreePrivacy = false
get() {
return AppPreferences.getInstance().getBoolean("ifAgreePrivacy", field)
......@@ -28,7 +38,6 @@ object ConstObject {
field = value
AppPreferences.getInstance().put("ifAgreePrivacy", value, true)
}
var haveSaveDemo = false
get() {
return AppPreferences.getInstance().getBoolean("haveSaveDemo", field)
......@@ -47,4 +56,5 @@ object ConstObject {
AppPreferences.getInstance().put("haveGuideGesture", value, true)
}
}
\ No newline at end of file
package com.base.pdfoneread.helper
import android.app.Activity
import android.content.Context
import com.base.pdfoneread.BuildConfig
import com.base.pdfoneread.utils.AppPreferences
import com.base.pdfoneread.utils.LogEx
import com.google.android.ump.ConsentDebugSettings
import com.google.android.ump.ConsentForm
import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentRequestParameters
import com.google.android.ump.FormError
import com.google.android.ump.UserMessagingPlatform
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
object UmpUtils {
var umpCanAd = true
get() {
return AppPreferences.getInstance().getBoolean("umpCanAd", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("umpCanAd", value, true)
}
var umpCalled = false
get() {
return AppPreferences.getInstance().getBoolean("umpCalled", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("umpCalled", value, true)
}
private fun Context.umpTest(): ConsentDebugSettings {
val debugSettings = ConsentDebugSettings.Builder(this)
debugSettings.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
//通过TEST-DEVICE-HASHED-ID log过滤ConsentDebugSettings 打印测试id,使用测试id来测试
// debugSettings.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
debugSettings.addTestDeviceHashedId("73FE7C2634104D50A11BE9B902AA0FA6")
return debugSettings.build()
}
var callback: ((canAd: Boolean) -> Unit)? = null
private val TAG = "UmpUtils"
fun requestUMP(activity: Activity) {
val paramsBuild = ConsentRequestParameters.Builder()
if (BuildConfig.DEBUG) {
paramsBuild.setConsentDebugSettings(activity.umpTest())
}
// 指示用户是否低于同意年龄; true 低于同意年龄
// 未满同意年龄的用户不会收到 GDPR 消息表单
paramsBuild.setTagForUnderAgeOfConsent(false)
val params = paramsBuild.build()
val consentInformation: ConsentInformation = UserMessagingPlatform.getConsentInformation(activity)
if (BuildConfig.DEBUG) {
consentInformation.reset()
}
val updateSuccessListener = ConsentInformation.OnConsentInfoUpdateSuccessListener {
LogEx.logDebug(TAG, "isConsentFormAvailable=${consentInformation.isConsentFormAvailable}")
if (consentInformation.isConsentFormAvailable) {
MainScope().launch(Dispatchers.Main) {
delay(500)
loadAndShowConsentFormIfRequired(activity, consentInformation)
}
} else {
callback?.invoke(true)
callback = null
}
}
val updateFailureListener = ConsentInformation.OnConsentInfoUpdateFailureListener {
LogEx.logDebug(TAG, "message=${it.message} errorCode=${it.errorCode}")
callback?.invoke(true)
callback = null
}
consentInformation.requestConsentInfoUpdate(activity, params, updateSuccessListener, updateFailureListener)
}
fun loadAndShowConsentFormIfRequired(activity: Activity, consentInformation: ConsentInformation) {
UserMessagingPlatform.loadConsentForm(
activity,
object : UserMessagingPlatform.OnConsentFormLoadSuccessListener {
override fun onConsentFormLoadSuccess(consentForm: ConsentForm) {
LogEx.logDebug(TAG, "onConsentFormLoadSuccess")
consentForm.show(activity) {
callback?.invoke(consentInformation.canRequestAds())
callback = null
}
}
},
object : UserMessagingPlatform.OnConsentFormLoadFailureListener {
override fun onConsentFormLoadFailure(p0: FormError) {
//https://groups.google.com/g/google-admob-ads-sdk/c/x-fyDOfMSqU/m/MeZX3mO4AAAJ
LogEx.logDebug(TAG, "onConsentFormLoadFailure ${p0.message} ${p0.errorCode}")
callback?.invoke(true)
callback = null
}
})
// UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { loadAndShowError: FormError? ->
// LogEx.logDebug(
// TAG,
// "loadAndShowConsentFormIfRequired message=${loadAndShowError?.message} errorCode=${loadAndShowError?.errorCode}"
// )
// if (loadAndShowError != null) {
// callback?.invoke(false)
// callback = null
// } else {
// callback?.invoke(consentInformation.canRequestAds())
// callback = null
// }
// }
}
}
\ No newline at end of file
......@@ -11,7 +11,8 @@ import com.base.pdfoneread.utils.ActivityLauncher
import com.base.pdfoneread.utils.ActivityManagerUtils
abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
private val TAG = "BaseActivity"
val TAG = javaClass.simpleName ?: ""
protected abstract val binding: T
......
......@@ -32,8 +32,6 @@ import java.io.File
class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack {
private val TAG = "DocumentActivity"
var type: String = ""
override val binding: ActivityDocumentBinding by lazy {
......
......@@ -54,8 +54,6 @@ import java.io.File
class PdfActivity : BaseActivity<ActivityPdfBinding>() {
private val TAG = "PdfActivity"
private lateinit var pdfPageAdapter: PdfPagerAdapter
private lateinit var pdfViewModel: PdfViewModel
......
......@@ -22,7 +22,6 @@ import kotlin.random.Random
class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
private val TAG = "PdfLoadingActivity"
private var doWhat = ""
private var srcPath: String = ""
private var newPath: String = ""
......
......@@ -23,7 +23,6 @@ import java.util.concurrent.BlockingQueue
class PdfMergeActivity : BaseActivity<ActivityPdfMergeBinding>() {
private val TAG = "PdfMergeActivity"
override val binding: ActivityPdfMergeBinding by lazy {
ActivityPdfMergeBinding.inflate(layoutInflater)
}
......
......@@ -29,7 +29,6 @@ import kotlinx.coroutines.launch
class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() {
private val TAG = "PdfSelectActivity"
private lateinit var pdfViewModel: PdfViewModel
private lateinit var adapter: DocumentAdapter
......
......@@ -18,7 +18,6 @@ import com.base.pdfoneread.utils.LogEx
class SearchActivity : BaseActivity<ActivitySearchBinding>() {
private val TAG = "SearchActivity"
private lateinit var searchViewModel: SearchViewModel
override val binding: ActivitySearchBinding by lazy {
......
package com.base.pdfoneread.ui.splash
import android.content.Intent
import android.graphics.Color
import androidx.core.view.updatePadding
import androidx.lifecycle.ViewModelProvider
import com.base.pdfoneread.R
import com.base.pdfoneread.ads.AdmobHelper.initAdmobAd
import com.base.pdfoneread.ads.admob.AdmobInterstitialUtils
import com.base.pdfoneread.ads.admob.AdmobOpenUtils
import com.base.pdfoneread.bean.ConstObject.ifAgreePrivacy
import com.base.pdfoneread.bean.ConstObject.isFirstStart
import com.base.pdfoneread.databinding.ActivityMyStartBinding
import com.base.pdfoneread.helper.EventUtils
import com.base.pdfoneread.helper.UmpUtils
import com.base.pdfoneread.helper.UmpUtils.requestUMP
import com.base.pdfoneread.helper.UmpUtils.umpCalled
import com.base.pdfoneread.helper.UmpUtils.umpCanAd
import com.base.pdfoneread.ui.BaseActivity
import com.base.pdfoneread.ui.main.MainActivity
import com.base.pdfoneread.utils.BarUtils
import com.base.pdfoneread.utils.LogEx
import com.base.pdfoneread.utils.SpannableUtils
import java.util.concurrent.atomic.AtomicBoolean
class MyStartActivity : BaseActivity<ActivityMyStartBinding>() {
private lateinit var splashViewModel: SplashViewModel
override val binding: ActivityMyStartBinding by lazy {
ActivityMyStartBinding.inflate(layoutInflater)
}
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.WHITE)
binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
splashViewModel = ViewModelProvider(this)[SplashViewModel::class.java]
val appNameString = resources.getString(R.string.app_name)
binding.tvAppName.text =
SpannableUtils.colorSpanner(appNameString, Color.parseColor("#FD3C00"), appNameString.length - 12, appNameString.length)
val isHotLaunch = intent.extras?.getBoolean("isHotLaunch") ?: false
ifAgreePrivacy = true
if (ifAgreePrivacy) {
agreePrivacy()
} else {
if (isHotLaunch) {
agreePrivacy()
} else {
if (!umpCalled) {//第一次请求ump
UmpUtils.callback = {
umpCalled = true
umpCanAd = it
LogEx.logDebug(TAG, "UmpUtils.callback $it")
// (application as MyApplication).initSolarEngine(it)
agreePrivacy()
EventUtils.event("ump", "umpCanAd=$umpCanAd")
}
requestUMP(this)
} else {
agreePrivacy()
}
}
}
}
private fun agreePrivacy() {
initAdmobAd(this)
showOpenAd()
splashViewModel.startJumpJob = true
splashViewModel.startJumpJob(this)
}
private fun showOpenAd() {
LogEx.logDebug(TAG, "showAd")
if (AdmobOpenUtils.haveReadAd()) {
showReadOpenAd()
} else {
if (AdmobInterstitialUtils.haveReadAd()) {
showReadOpenAd()
} else {
AdmobOpenUtils.loadAppOpenAd { loaded ->
LogEx.logDebug(TAG, "loadAppOpenAd loaded=$loaded")
if (loaded) {
showReadOpenAd()
} else {
LogEx.logDebug(TAG, "no load ad jumpNext")
jumpNext()
}
}
}
}
}
private fun showReadOpenAd() {
AdmobOpenUtils.showAppOpenAd(this, showBefore = {
if (it) {
splashViewModel.pauseJumpJob()
}
}, onHidden = {
LogEx.logDebug(TAG, "ad jumpNext")
jumpNext()
})
}
private var jump: AtomicBoolean = AtomicBoolean(false)
fun jumpNext() {
if (jump.get()) {
return
}
jump.set(true)
binding.root.postDelayed({
if (isFirstStart) {
firstStartJump()
} else {
startActivity(Intent(this, MainActivity::class.java))
}
}, 100)
}
private fun firstStartJump() {
isFirstStart = false
startActivity(Intent(this, MainActivity::class.java))
}
override fun onPause() {
super.onPause()
splashViewModel.pauseJumpJob()
}
override fun onResume() {
super.onResume()
splashViewModel.startJumpJob(this)
}
}
\ No newline at end of file
package com.base.pdfoneread.ui.splash
import android.content.ContentValues.TAG
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.base.pdfoneread.ads.AdmobHelper.open_ad_loading
import com.base.pdfoneread.bean.ConstObject
import com.base.pdfoneread.utils.AppPreferences
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import com.base.pdfoneread.utils.LogEx
class SplashViewModel : ViewModel() {
var startJumpJob: Boolean = false
private var jumpJob: Job? = null
private var loadingTime = AppPreferences.getInstance().getString(open_ad_loading, "15").toInt()
/**
* 超时跳转
*/
fun startJumpJob(splashActivity: MyStartActivity) {
if (ConstObject.ifAgreePrivacy && startJumpJob) {
if (jumpJob == null) {
val startTime = System.currentTimeMillis()
jumpJob = viewModelScope.launch {
LogEx.logDebug(TAG, "open_ad_loading=$loadingTime")
delay(loadingTime * 1000L)
val endTime = System.currentTimeMillis()
LogEx.logDebug(TAG, "超时跳转 time=${endTime - startTime}")
splashActivity.jumpNext()
}
}
}
}
/**
* 暂停超时跳转
*/
fun pauseJumpJob() {
jumpJob?.cancel()
jumpJob = null
}
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ class SystemStartActivity : AppCompatActivity() {
mKeepOnAtomicBool.get()
}
LogEx.logDebug(TAG, "setKeepOnScreenCondition...")
startActivity(Intent(this@SystemStartActivity, MainActivity::class.java))
startActivity(Intent(this@SystemStartActivity, MyStartActivity::class.java))
this@SystemStartActivity.finish()
overridePendingTransition(0, 0)
mKeepOnAtomicBool.compareAndSet(true, false)
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".ui.splash.MyStartActivity">
<ImageView
android:id="@+id/iv"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_marginTop="160dp"
android:src="@mipmap/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="65dp"
android:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv"
tools:text="PDF Reader &amp; PDF Editor" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/bj"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:textColor="#8E95A0"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_app_name"
android:text="Your full document reader" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -10,7 +10,7 @@
<item name="windowSplashScreenBackground">@color/white</item>
<!-- <item name="android:windowBackground">@drawable/splash_bp</item>-->
<!-- 启动画面icon图标:这里可以是图片、帧动画等-->
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/logo</item>
<item name="splashScreenIconSize">50dp</item>
<item name="windowSplashScreenIconBackgroundColor">@android:color/transparent</item>
<!-- icon动画在关闭之前显示的时长:最长时间为1000毫秒-->
......
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