|
@@ -1,69 +1,21 @@
|
|
|
package com.atmob.keyboard_android.util.loading
|
|
package com.atmob.keyboard_android.util.loading
|
|
|
|
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
-import android.graphics.Color
|
|
|
|
|
-import android.graphics.drawable.ColorDrawable
|
|
|
|
|
-import android.view.Gravity
|
|
|
|
|
-import android.view.LayoutInflater
|
|
|
|
|
import android.view.Window
|
|
import android.view.Window
|
|
|
-import android.view.WindowManager
|
|
|
|
|
-import android.widget.PopupWindow
|
|
|
|
|
import com.atmob.keyboard_android.R
|
|
import com.atmob.keyboard_android.R
|
|
|
|
|
+import com.atmob.keyboard_android.ui.popup.base.BasePopupDialog
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Loading弹窗
|
|
* Loading弹窗
|
|
|
*/
|
|
*/
|
|
|
-class LoadingDialog(private val context: Context, private val hostWindow: Window) {
|
|
|
|
|
- private var mPopupWindow: PopupWindow? = null
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 显示Loading
|
|
|
|
|
- */
|
|
|
|
|
- fun show() {
|
|
|
|
|
- if (mPopupWindow?.isShowing == true) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 填充布局
|
|
|
|
|
- val contentView = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null, false)
|
|
|
|
|
-
|
|
|
|
|
- // 配置 PopupWindow
|
|
|
|
|
- mPopupWindow = PopupWindow(
|
|
|
|
|
- contentView,
|
|
|
|
|
- WindowManager.LayoutParams.MATCH_PARENT,
|
|
|
|
|
- WindowManager.LayoutParams.MATCH_PARENT
|
|
|
|
|
- ).apply {
|
|
|
|
|
- // 不获取焦点,否则获取焦点会将软键盘关闭
|
|
|
|
|
- isFocusable = false
|
|
|
|
|
- // 保持输入法活跃
|
|
|
|
|
- inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
|
|
|
|
|
- // 禁止点击外部区域,关闭弹窗
|
|
|
|
|
- isOutsideTouchable = false
|
|
|
|
|
- // 设置背景,否则还是会关闭
|
|
|
|
|
- setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 显示在屏幕中央
|
|
|
|
|
- mPopupWindow?.showAtLocation(
|
|
|
|
|
- hostWindow.decorView,
|
|
|
|
|
- Gravity.CENTER,
|
|
|
|
|
- 0,
|
|
|
|
|
- 0
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 是否正在显示
|
|
|
|
|
- */
|
|
|
|
|
- fun isShowing(): Boolean {
|
|
|
|
|
- return mPopupWindow?.isShowing == true
|
|
|
|
|
|
|
+class LoadingDialog(context: Context, hostWindow: Window) :
|
|
|
|
|
+ BasePopupDialog(context, hostWindow) {
|
|
|
|
|
+ override fun onInflaterViewId(): Int {
|
|
|
|
|
+ return R.layout.dialog_loading
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 隐藏Loading
|
|
|
|
|
- */
|
|
|
|
|
- fun dismiss() {
|
|
|
|
|
- mPopupWindow?.dismiss()
|
|
|
|
|
- mPopupWindow = null
|
|
|
|
|
|
|
+ override fun isCanOutsideTouchable(): Boolean {
|
|
|
|
|
+ // 禁止点击外部区域,关闭弹窗
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|