任务幸运币UI。
This commit is contained in:
@@ -38,6 +38,7 @@ import com.xscm.modulemain.activity.user.conacts.DailyTasksConacts;
|
||||
import com.xscm.modulemain.activity.user.presenter.DailyTasksPresenter;
|
||||
import com.xscm.modulemain.BaseMvpActivity;
|
||||
import com.xscm.modulemain.activity.WebViewActivity;
|
||||
import com.xscm.modulemain.dialog.DialogLuckyDraw;
|
||||
import com.xscm.modulemain.dialog.SignInDialog;
|
||||
import com.xscm.modulemain.manager.RoomManager;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
@@ -205,6 +206,13 @@ public class DailyTasksActivity extends BaseMvpActivity<DailyTasksPresenter, Act
|
||||
});
|
||||
|
||||
|
||||
mBinding.davLucky.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new DialogLuckyDraw(DailyTasksActivity.this).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,14 +50,40 @@ class DialogLuckyDraw(context: Context) : BaseDialog<DialogLuckyDrawLayoutBindin
|
||||
mBinding.ivOnOrOff.setOnClickListener {
|
||||
if (mBinding.ivOnOrOff.tag == 1) {
|
||||
mBinding.ivOnOrOff.tag = 0
|
||||
mBinding.ivOnOrOff.setImageResource(R.mipmap.icon_lucky_donghua_pre)
|
||||
mBinding.ivOnOrOff.setImageResource(R.mipmap.icon_lucky_donghua_nor)
|
||||
} else {
|
||||
mBinding.ivOnOrOff.tag = 1
|
||||
mBinding.ivOnOrOff.setImageResource(R.mipmap.icon_lucky_donghua_nor)
|
||||
mBinding.ivOnOrOff.setImageResource(R.mipmap.icon_lucky_donghua_pre)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mBinding.tvLeft1.setOnClickListener {
|
||||
|
||||
}
|
||||
|
||||
mBinding.tvLeft2.setOnClickListener {
|
||||
|
||||
}
|
||||
|
||||
mBinding.tvLeft3.setOnClickListener {
|
||||
|
||||
}
|
||||
|
||||
mBinding.tvRight1.setOnClickListener {
|
||||
|
||||
}
|
||||
mBinding.tvRight2.setOnClickListener {
|
||||
|
||||
}
|
||||
mBinding.tvRight3.setOnClickListener {
|
||||
|
||||
}
|
||||
mBinding.tvRight4.setOnClickListener {
|
||||
|
||||
}
|
||||
}
|
||||
//913073443 13837096053
|
||||
|
||||
private fun lottery(count: Int) {
|
||||
if (isLottery) {
|
||||
ToastUtils.showShort("正在抽取中...")
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package com.xscm.modulemain.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.view.*
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import com.xscm.modulemain.R
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class DraggableAdsorbView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null
|
||||
) : FrameLayout(context, attrs) {
|
||||
|
||||
private lateinit var textView: TextView
|
||||
|
||||
private var lastRawX = 0f
|
||||
private var lastRawY = 0f
|
||||
private var isDragging = false
|
||||
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
|
||||
init {
|
||||
initView()
|
||||
initAttrs(attrs)
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
isClickable = true
|
||||
isFocusable = true
|
||||
|
||||
textView = TextView(context)
|
||||
addView(
|
||||
textView,
|
||||
LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT
|
||||
).apply {
|
||||
gravity = Gravity.CENTER
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 XML 属性
|
||||
*/
|
||||
private fun initAttrs(attrs: AttributeSet?) {
|
||||
if (attrs == null) return
|
||||
|
||||
val ta = context.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.DraggableAdsorbView
|
||||
)
|
||||
|
||||
val text = ta.getString(R.styleable.DraggableAdsorbView_dav_text)
|
||||
val textFontResId = ta.getResourceId(R.styleable.DraggableAdsorbView_dav_textFont,0)
|
||||
val textColor = ta.getColor(
|
||||
R.styleable.DraggableAdsorbView_dav_textColor,
|
||||
Color.WHITE
|
||||
)
|
||||
val textSize = ta.getDimension(
|
||||
R.styleable.DraggableAdsorbView_dav_textSize,
|
||||
sp2px(14f)
|
||||
)
|
||||
val textGravity = ta.getInt(
|
||||
R.styleable.DraggableAdsorbView_dav_textGravity,
|
||||
Gravity.CENTER
|
||||
)
|
||||
|
||||
val padding = ta.getDimensionPixelSize(
|
||||
R.styleable.DraggableAdsorbView_dav_textPadding,
|
||||
0
|
||||
)
|
||||
|
||||
val paddingLeft = ta.getDimensionPixelSize(
|
||||
R.styleable.DraggableAdsorbView_dav_textPaddingLeft,
|
||||
padding
|
||||
)
|
||||
val paddingTop = ta.getDimensionPixelSize(
|
||||
R.styleable.DraggableAdsorbView_dav_textPaddingTop,
|
||||
padding
|
||||
)
|
||||
val paddingRight = ta.getDimensionPixelSize(
|
||||
R.styleable.DraggableAdsorbView_dav_textPaddingRight,
|
||||
padding
|
||||
)
|
||||
val paddingBottom = ta.getDimensionPixelSize(
|
||||
R.styleable.DraggableAdsorbView_dav_textPaddingBottom,
|
||||
padding
|
||||
)
|
||||
|
||||
ta.recycle()
|
||||
|
||||
// 应用属性
|
||||
textView.text = text
|
||||
textView.setTextColor(textColor)
|
||||
textView.textSize = px2sp(textSize)
|
||||
textView.setPadding(
|
||||
paddingLeft,
|
||||
paddingTop,
|
||||
paddingRight,
|
||||
paddingBottom
|
||||
)
|
||||
|
||||
// 核心修复2:安全设置字体 - 校验ID有效性 + try-catch异常兜底
|
||||
if (textFontResId != 0) { // 0为无效资源ID,跳过未设置的情况
|
||||
try {
|
||||
// 传入正确的Int类型资源ID,无类型不匹配问题
|
||||
val typeface = ResourcesCompat.getFont(context, textFontResId)
|
||||
textView.typeface = typeface
|
||||
} catch (e: Exception) {
|
||||
// 异常兜底:字体加载失败时使用系统默认字体,避免View崩溃
|
||||
e.printStackTrace()
|
||||
textView.typeface = Typeface.DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
(textView.layoutParams as LayoutParams).gravity = textGravity
|
||||
}
|
||||
|
||||
// ===================== 拖拽逻辑 =====================
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
parent.requestDisallowInterceptTouchEvent(true)
|
||||
lastRawX = event.rawX
|
||||
lastRawY = event.rawY
|
||||
isDragging = false
|
||||
return true
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val dx = event.rawX - lastRawX
|
||||
val dy = event.rawY - lastRawY
|
||||
|
||||
if (!isDragging) {
|
||||
if (abs(dx) > touchSlop || abs(dy) > touchSlop) {
|
||||
isDragging = true
|
||||
} else return true
|
||||
}
|
||||
|
||||
val parentView = parent as? View ?: return true
|
||||
|
||||
var newX = x + dx
|
||||
var newY = y + dy
|
||||
|
||||
newX = min(
|
||||
max(0f, newX),
|
||||
parentView.width - width.toFloat()
|
||||
)
|
||||
newY = min(
|
||||
max(0f, newY),
|
||||
parentView.height - height.toFloat()
|
||||
)
|
||||
|
||||
x = newX
|
||||
y = newY
|
||||
|
||||
lastRawX = event.rawX
|
||||
lastRawY = event.rawY
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP,
|
||||
MotionEvent.ACTION_CANCEL -> {
|
||||
parent.requestDisallowInterceptTouchEvent(false)
|
||||
if (isDragging) {
|
||||
adsorbToEdge()
|
||||
} else {
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun performClick(): Boolean {
|
||||
return super.performClick()
|
||||
}
|
||||
|
||||
/**
|
||||
* 吸附左右边
|
||||
*/
|
||||
private fun adsorbToEdge() {
|
||||
val parentView = parent as? View ?: return
|
||||
val parentWidth = parentView.width
|
||||
val centerX = x + width / 2
|
||||
|
||||
val targetX = if (centerX < parentWidth / 2) {
|
||||
0f
|
||||
} else {
|
||||
parentWidth - width.toFloat()
|
||||
}
|
||||
|
||||
ViewCompat.animate(this)
|
||||
.x(targetX)
|
||||
.setDuration(250)
|
||||
.start()
|
||||
}
|
||||
|
||||
// ===================== 对外 API =====================
|
||||
|
||||
fun setText(text: CharSequence) {
|
||||
textView.text = text
|
||||
}
|
||||
|
||||
fun setTextGravity(gravity: Int) {
|
||||
(textView.layoutParams as LayoutParams).gravity = gravity
|
||||
textView.requestLayout()
|
||||
}
|
||||
|
||||
// ===================== 工具 =====================
|
||||
|
||||
private fun sp2px(sp: Float): Float {
|
||||
return sp * resources.displayMetrics.scaledDensity
|
||||
}
|
||||
|
||||
private fun px2sp(px: Float): Float {
|
||||
return px / resources.displayMetrics.scaledDensity
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user