|
|
@@ -1,22 +1,25 @@
|
|
|
-package com.atmob.keyboard_android.ui.popup.guide
|
|
|
+package com.atmob.keyboard_android.component.child.impl
|
|
|
|
|
|
import android.content.Context
|
|
|
+import android.util.AttributeSet
|
|
|
import android.view.View
|
|
|
-import android.view.Window
|
|
|
import android.widget.TextView
|
|
|
import com.atmob.keyboard_android.R
|
|
|
+import com.atmob.keyboard_android.component.base.BaseUIComponent
|
|
|
+import com.atmob.keyboard_android.component.child.IKeyboardGuideComponent
|
|
|
import com.atmob.keyboard_android.ext.click
|
|
|
import com.atmob.keyboard_android.ext.measureView
|
|
|
import com.atmob.keyboard_android.model.AiKeyboardKeyModel
|
|
|
-import com.atmob.keyboard_android.ui.popup.base.BasePopupDialog
|
|
|
import com.atmob.keyboard_android.util.ViewLocationUtil
|
|
|
import com.blankj.utilcode.util.ConvertUtils
|
|
|
|
|
|
/**
|
|
|
- * 键盘引导弹窗
|
|
|
+ * 键盘引导组件实现
|
|
|
*/
|
|
|
-class KeyboardGuideDialog(context: Context, hostWindow: Window) :
|
|
|
- BasePopupDialog(context, hostWindow) {
|
|
|
+class KeyboardGuideComponent @JvmOverloads constructor(
|
|
|
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
|
|
+) : BaseUIComponent<IKeyboardGuideComponent>(context, attrs, defStyleAttr),
|
|
|
+ IKeyboardGuideComponent {
|
|
|
private lateinit var vRoot: View
|
|
|
private lateinit var vFakeTargetView: View
|
|
|
private lateinit var vKeyText: TextView
|
|
|
@@ -29,45 +32,30 @@ class KeyboardGuideDialog(context: Context, hostWindow: Window) :
|
|
|
/**
|
|
|
* 操作回调
|
|
|
*/
|
|
|
- private var mOnActionCallback: OnActionCallback? = null
|
|
|
+ private var mOnActionCallback: IKeyboardGuideComponent.OnActionCallback? = null
|
|
|
|
|
|
- override fun onInflaterViewId(): Int {
|
|
|
- return R.layout.layout_keyboard_guide
|
|
|
+ override fun onInflateViewId(): Int {
|
|
|
+ return R.layout.component_keyboard_guide
|
|
|
}
|
|
|
|
|
|
- override fun onInflaterViewAfter(view: View) {
|
|
|
- super.onInflaterViewAfter(view)
|
|
|
+ override fun findView(view: View) {
|
|
|
vRoot = view.findViewById(R.id.root)
|
|
|
vFakeTargetView = view.findViewById(R.id.fake_target_view)
|
|
|
vKeyText = view.findViewById(R.id.key_text)
|
|
|
}
|
|
|
|
|
|
- override fun onBindView(view: View) {
|
|
|
- super.onBindView(view)
|
|
|
+ override fun bindView(view: View) {
|
|
|
vRoot.click {
|
|
|
- // 关闭弹窗
|
|
|
- dismiss()
|
|
|
+ // 隐藏
|
|
|
+ hide()
|
|
|
// 结束引导
|
|
|
mOnActionCallback?.onFinishGuide()
|
|
|
}
|
|
|
render()
|
|
|
}
|
|
|
|
|
|
- override fun isCanOutsideTouchable(): Boolean {
|
|
|
- // 禁止点击外部区域关闭弹窗,自定义点击事件来实现关闭
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- override fun onSetupDialogFrameSize(
|
|
|
- context: Context,
|
|
|
- windowWidth: Int,
|
|
|
- windowHeight: Int
|
|
|
- ): IntArray {
|
|
|
- return intArrayOf(
|
|
|
- windowWidth,
|
|
|
- // 键盘的高度
|
|
|
- context.resources.getDimensionPixelSize(R.dimen.keyboard_height)
|
|
|
- )
|
|
|
+ override fun getComponentInterfaceClazz(): Class<IKeyboardGuideComponent> {
|
|
|
+ return IKeyboardGuideComponent::class.java
|
|
|
}
|
|
|
|
|
|
private fun render() {
|
|
|
@@ -111,17 +99,11 @@ class KeyboardGuideDialog(context: Context, hostWindow: Window) :
|
|
|
val dataModel: AiKeyboardKeyModel
|
|
|
)
|
|
|
|
|
|
- interface OnActionCallback {
|
|
|
- /**
|
|
|
- * 结束引导时回调
|
|
|
- */
|
|
|
- fun onFinishGuide()
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 绑定目标View
|
|
|
- */
|
|
|
- fun bindTargetView(targetView: View, dataModel: AiKeyboardKeyModel): KeyboardGuideDialog {
|
|
|
+ override fun bindGuideData(
|
|
|
+ targetView: View,
|
|
|
+ dataModel: AiKeyboardKeyModel,
|
|
|
+ finishCallback: IKeyboardGuideComponent.OnActionCallback
|
|
|
+ ) {
|
|
|
// View在Window中的位置
|
|
|
val viewLocationInWindow = ViewLocationUtil.getViewLocationInWindow(targetView)
|
|
|
// View的宽高
|
|
|
@@ -138,15 +120,6 @@ class KeyboardGuideDialog(context: Context, hostWindow: Window) :
|
|
|
|
|
|
// 重新渲染
|
|
|
render()
|
|
|
-
|
|
|
- return this
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 绑定操作回调
|
|
|
- */
|
|
|
- fun bindOnActionCallback(callback: OnActionCallback): KeyboardGuideDialog {
|
|
|
- this.mOnActionCallback = callback
|
|
|
- return this
|
|
|
+ this.mOnActionCallback = finishCallback
|
|
|
}
|
|
|
}
|