GLDriver/app/src/main/java/com/dahe/gldriver/mypop/AgreementAlert.kt

98 lines
3.8 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.dahe.gldriver.mypop
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.text.SpannableStringBuilder
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.dahe.gldriver.R
import com.dahe.gldriver.base.WebActivity
import com.dahe.gldriver.callback.OnResultListener
import com.lxj.xpopup.core.CenterPopupView
/**
* @author hlh
* @version 1.0.0
* @date 2021/10/13 10:30
* @description:
*/
class AgreementAlert(
private val con: Context,
private val url: String,
private val url2: String,
private val listener: OnResultListener
) : CenterPopupView(
con
) {
override fun getImplLayoutId(): Int {
return R.layout.alert_ok_cancel
}
// 执行初始化操作比如findView设置点击或者任何你弹窗内的业务逻辑
override fun onCreate() {
super.onCreate()
val tv_title = findViewById<TextView>(R.id.tv_title)
val tv_content = findViewById<TextView>(R.id.tv_content)
val tv_cancel = findViewById<Button>(R.id.tv_cancel)
val tv_confirm = findViewById<Button>(R.id.tv_confirm)
tv_content.gravity = Gravity.LEFT
tv_confirm.text = "同意"
tv_title.text = "用户服务协议和隐私政策"
val str = """
请你务必审慎阅读、充分理解此内容中的“用户服务协议和隐私政策”各条款、包括但不限于:为了向你提供身份认证、接单、运单查询、消息推送等服务我们需要收集你的设备信息、操作日志等个人信息。
你可阅读《用户服务协议》和《隐私政策》了解详细信息。如果你同意,请点击“同意”开始接受我们的服务。
""".trimIndent()
val ssb = SpannableStringBuilder()
ssb.append(str)
//第一个出现的位置
val start = str.indexOf("")
ssb.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
//用户服务协议点击事件
val `in` = Intent(context, WebActivity::class.java)
`in`.putExtra("url", url2)
`in`.putExtra("title", "用户服务协议")
context.startActivity(`in`)
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
//设置文件颜色
ds.color = resources.getColor(R.color.theme_color, null)
// 去掉下划线
ds.isUnderlineText = false
}
}, start, start + 8, 0)
val end = str.lastIndexOf("")
ssb.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
//用户服务协议点击事件
val `in` = Intent(context, WebActivity::class.java)
`in`.putExtra("url", url)
`in`.putExtra("title", "隐私政策")
context.startActivity(`in`)
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
//设置文件颜色
ds.color = resources.getColor(R.color.theme_color, null)
// 去掉下划线
ds.isUnderlineText = false
}
}, end, end + 6, 0)
tv_content.movementMethod = LinkMovementMethod.getInstance()
tv_content.setText(ssb, TextView.BufferType.SPANNABLE)
tv_cancel.setOnClickListener { v: View? -> System.exit(1) }
tv_confirm.setOnClickListener { v: View? ->
listener.onResult(true)
dismiss() }
}
}