Commit 9f72bded authored by wanglei's avatar wanglei

...

parent 24da9f80
......@@ -211,6 +211,13 @@
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.webview.WebBrowserActivity"
android:exported="false"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
......
......@@ -45,6 +45,7 @@ import com.base.pdfviewerscannerwhite.ui.set.SetActivity
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.ui.view.ProgressBean
import com.base.pdfviewerscannerwhite.ui.weather.WeatherInterface
import com.base.pdfviewerscannerwhite.ui.webview.WebBrowserActivity
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
......@@ -203,6 +204,9 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
binding.llWeather.setOnClickListener {
startActivity(Intent(requireContext(), WeatherInterface::class.java))
}
binding.tvZodiac.setOnClickListener {
startActivity(Intent(requireContext(), WebBrowserActivity::class.java))
}
}
override fun onResume() {
......
......@@ -22,7 +22,6 @@ import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.helper.WeatherUtils
import com.base.pdfviewerscannerwhite.ui.guide.GuideActivity
import com.base.pdfviewerscannerwhite.ui.main.MainActivity
import com.base.pdfviewerscannerwhite.ui.permission.PermissionActivity
import com.base.pdfviewerscannerwhite.ui.set.SetLanguageActivity
import com.base.pdfviewerscannerwhite.utils.AnimationUtils
import com.base.pdfviewerscannerwhite.utils.BarUtils
......@@ -54,6 +53,7 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
LogEx.logDebug("time",System.currentTimeMillis().toString())
// binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
if (Build.VERSION.SDK_INT >= 33) {
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}.launch(
......@@ -112,7 +112,10 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
if (BuildConfig.DEBUG) {
// toast("isHotLaunch=$isHotLaunch")
}
LogEx.logDebug("time",System.currentTimeMillis().toString()+"startWeatherAnimation")
startWeatherAnimation()
LogEx.logDebug("time",System.currentTimeMillis().toString()+"startWeatherAnimation_end")
ifAgreePrivacy = true
if (ifAgreePrivacy) {
......@@ -120,11 +123,13 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
agreePrivacy()
} else {
if (!umpCalled) {//第一次请求ump
LogEx.logDebug("time",System.currentTimeMillis().toString()+"_UMP_START")
UmpUtils.callback = {
umpCalled = true
umpCanAd = it
LogEx.logDebug(TAG, "UmpUtils.callback $it")
(application as MyApplication).initSolarEngine(it)
LogEx.logDebug("time",System.currentTimeMillis().toString()+"_UMP_end")
agreePrivacy()
EventUtils.event("ump", "umpCanAd=$umpCanAd")
}
......@@ -145,7 +150,10 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
if (AdmobInterstitialUtils.haveReadAd()) {
showReadInterAd()
} else {
LogEx.logDebug("time",System.currentTimeMillis().toString()+"loadAppOpenAd")
AdmobOpenUtils.loadAppOpenAd { loaded ->
LogEx.logDebug("time",System.currentTimeMillis().toString()+"loaded")
LogEx.logDebug(TAG, "loadAppOpenAd loaded=$loaded")
if (loaded) {
showReadOpenAd()
......@@ -161,6 +169,7 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
private fun showReadOpenAd() {
AdmobOpenUtils.showAppOpenAd(this, showBefore = {
LogEx.logDebug("time",System.currentTimeMillis().toString()+"showReadOpenAd")
if (it) {
splashPresenter.pauseJumpJob()
}
......@@ -179,6 +188,7 @@ class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
override fun agreePrivacy() {
if (umpCanAd) {
LogEx.logDebug("time",System.currentTimeMillis().toString()+"_agreePrivacy")
initAdmobAd(this)
showAd()
splashPresenter.startJumpJob = true
......
package com.base.pdfviewerscannerwhite.ui.webview
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.net.http.SslError
import android.view.View
import android.webkit.CookieManager
import android.webkit.JsResult
import android.webkit.SslErrorHandler
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebSettings
import android.webkit.WebStorage
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.ads.admob.AdmobInterstitialUtils
import com.base.pdfviewerscannerwhite.ads.admob.AdmobNativeUtils
import com.base.pdfviewerscannerwhite.databinding.ActivityWebBrowserBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.random.Random
class WebBrowserActivity : BaseActivity<ActivityWebBrowserBinding>() {
override val binding: ActivityWebBrowserBinding by lazy {
ActivityWebBrowserBinding.inflate(layoutInflater)
}
var showed: Boolean = false
override fun initView() {
initWebSettings()
binding.webView.loadUrl("https://www.horoscope.com/us/index.aspx")
AdmobNativeUtils.showNativeAd(this, binding.flNative, R.layout.layout_admob_document_in)
AdmobInterstitialUtils.showInterstitialAd(this) {
showed = it
}
}
override fun initListener() {
super.initListener()
binding.refreshLayout.setOnRefreshListener {
lifecycleScope.launch {
binding.refreshLayout.isRefreshing = true
delay(Random.nextLong(1500, 2500))
binding.refreshLayout.isRefreshing = false
}
binding.webView.reload()
}
onBackPressedDispatcher.addCallback {
if (binding.webView.canGoBack()) {
binding.webView.goBack()
} else {
if (showed) {
finishToMainTop()
} else {
AdmobInterstitialUtils.showInterstitialAd(this@WebBrowserActivity) {
finishToMainTop()
}
}
}
}
}
@SuppressLint("JavascriptInterface")
private fun initWebSettings() {
val webSettings = binding.webView.settings
webSettings.allowFileAccess = true// 设置允许访问文件数据
webSettings.setSupportZoom(false)
webSettings.builtInZoomControls = true
webSettings.cacheMode = WebSettings.LOAD_NO_CACHE
webSettings.domStorageEnabled = true
webSettings.databaseEnabled = true
@Suppress("DEPRECATION")
webSettings.allowFileAccessFromFileURLs = true
WebStorage.getInstance().deleteAllData()
// 关键性代码,这里要给webView添加这行代码,才可以点击之后正常播放音频。记录一下。
webSettings.mediaPlaybackRequiresUserGesture = false
//设置WebView属性,能够执行Javascript脚本
webSettings.javaScriptEnabled = true
//设置混合内容模式:对于HTTPS和HTTP混合内容的加载,需要设置WebView以允许混合内容:
webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
//使用CookieManager设置允许跨域Cookie
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webView, true)
//适应屏幕设置
webSettings.useWideViewPort = true
webSettings.loadWithOverviewMode = true
//网页使用localStorage等Web存储API,需要启用DOM存储
webSettings.domStorageEnabled = true
webSettings.setUseWideViewPort(false)
webSettings.setLoadsImagesAutomatically(true) // 确保自动加载图片
//设置WebChromeClient
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
binding.progressBar.progress = newProgress
if (binding.progressBar.progress >= 100) {
binding.progressBar.visibility = View.GONE
}
}
override fun onReceivedTitle(view: WebView?, title: String?) {
super.onReceivedTitle(view, title)
}
override fun onShowFileChooser(
webView: WebView?,
filePathCallback: ValueCallback<Array<Uri?>?>,
fileChooserParams: FileChooserParams?
): Boolean {
return true
}
override fun onJsAlert(
view: WebView?,
url: String?,
message: String?,
result: JsResult?
): Boolean = true
}
binding.webView.webViewClient = object : WebViewClient() {
override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest?): WebResourceResponse? {
val url = request?.url.toString()
if (url.contains("//ads.") || url.contains("https://play.google.com")) {
return WebResourceResponse(null, null, null) // 拦截广告请
}
return super.shouldInterceptRequest(view, request)
}
override fun onLoadResource(view: WebView?, url: String?) {
super.onLoadResource(view, url)
}
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
if (request != null) {
val uri = request.url
val scheme = uri.scheme
// 检查 URL 是否是 scheme 类型
if (scheme != null && (scheme == "http" || scheme == "https")) {
} else {
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (packageManager != null && intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
return true // 返回 true,表示 URL 已经被处理
}
return super.shouldOverrideUrlLoading(view, request)
}
return false
}
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
}
override fun onPageFinished(view: WebView?, url: String?) {
val jsCode = "javascript:" +
"var ads = document.querySelectorAll('.ad-container');" + // 替换为广告的CSS选择器
"for (var i = 0; i < ads.length; i++) {" +
" ads[i].parentNode.removeChild(ads[i]);" +
"}"
view?.loadUrl(jsCode)
}
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
}
}
//设置Cookie
val instance = CookieManager.getInstance()
instance.setAcceptThirdPartyCookies(binding.webView, true)
binding.webView.addJavascriptInterface(this, "android")
binding.webView.swipeRefreshLayout = binding.refreshLayout
}
}
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.webview
import android.content.Context
import android.util.AttributeSet
import android.webkit.WebView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
/**
*Create by SleepDog on 2025-01-21
*/
class WebRefreshView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : WebView(context, attrs) {
var swipeRefreshLayout: SwipeRefreshLayout? = null
override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
super.onScrollChanged(l, t, oldl, oldt)
swipeRefreshLayout?.isEnabled = scrollY == 0
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FFFEAE25"
android:endColor="#FFFF790C"
android:angle="0" />
<corners android:radius="20dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景色 -->
<item android:id="@android:id/background">
<shape>
<solid android:color="@android:color/transparent" />
</shape>
</item>
<!-- 设置进度条颜色 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#0571ED" />
</shape>
</clip>
</item>
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progress_bar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginVertical="3dp"
android:max="100"
android:progressDrawable="@drawable/progress_bar_web"
tools:progress="50" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.base.pdfviewerscannerwhite.ui.webview.WebRefreshView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<FrameLayout
android:id="@+id/flNative"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
......@@ -39,6 +39,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_tittle">
<TextView
android:id="@+id/tv_wendu"
android:layout_width="wrap_content"
......@@ -72,6 +73,25 @@
</LinearLayout>
<TextView
android:id="@+id/tv_zodiac"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_marginEnd="16dp"
android:background="@drawable/bg_gradient_zodiac"
android:drawablePadding="3dp"
android:gravity="center"
android:paddingHorizontal="13dp"
android:paddingVertical="8dp"
android:text="@string/zodiac"
android:textColor="@color/white"
android:textSize="15sp"
app:drawableStartCompat="@mipmap/ic_zodiac"
app:layout_constraintBottom_toBottomOf="@id/ll_weather"
app:layout_constraintEnd_toStartOf="@id/ll_weather"
app:layout_constraintTop_toTopOf="@id/ll_weather" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
......
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