列表,个人中心
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.juhabi.birds.custom
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.PopupWindow
|
||||
import com.juhabi.birds.R
|
||||
|
||||
/** 添加设备菜单,提供手动添加和扫一扫两个操作回调。 */
|
||||
class AddDevicePopupWindow(context: Context) {
|
||||
private val popupWindow: PopupWindow
|
||||
|
||||
init {
|
||||
val content = LayoutInflater.from(context).inflate(R.layout.popup_add_device, null)
|
||||
// 让按下态绿色能裁切到卡片圆角内
|
||||
content.clipToOutline = true
|
||||
popupWindow = PopupWindow(
|
||||
content,
|
||||
dp(context, 142),
|
||||
dp(context, 84),
|
||||
true
|
||||
).apply {
|
||||
isOutsideTouchable = true
|
||||
elevation = dp(context, 6).toFloat()
|
||||
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
}
|
||||
content.findViewById<View>(R.id.action_manual_add).setOnClickListener {
|
||||
popupWindow.dismiss()
|
||||
manualAddAction?.invoke()
|
||||
}
|
||||
content.findViewById<View>(R.id.action_scan).setOnClickListener {
|
||||
popupWindow.dismiss()
|
||||
scanAction?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
private var manualAddAction: (() -> Unit)? = null
|
||||
private var scanAction: (() -> Unit)? = null
|
||||
|
||||
/** 在指定锚点下方显示菜单,并设置两个操作的回调。 */
|
||||
fun show(
|
||||
anchor: View,
|
||||
onManualAdd: () -> Unit,
|
||||
onScan: () -> Unit
|
||||
) {
|
||||
manualAddAction = onManualAdd
|
||||
scanAction = onScan
|
||||
popupWindow.showAsDropDown(
|
||||
anchor,
|
||||
-dp(anchor.context, 104),
|
||||
-dp(anchor.context, 4)
|
||||
)
|
||||
}
|
||||
|
||||
private fun dp(context: Context, value: Int): Int =
|
||||
(value * context.resources.displayMetrics.density).toInt()
|
||||
}
|
||||
Reference in New Issue
Block a user