初始代码提交
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.sw.inbound.dialog
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.activity.FoodCollectionActivity
|
||||
import com.sw.inbound.activity.GoodsListActivity
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
|
||||
abstract class BaseDialog(
|
||||
context: Context,
|
||||
var defWidth: Int = 1500.dp,
|
||||
var defHeight: Int = 900.dp
|
||||
) : Dialog(context, R.style.DialogTheme) {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val rootView = getRootView()
|
||||
setContentView(rootView)
|
||||
setCancelable(false)
|
||||
setCanceledOnTouchOutside(false)
|
||||
window?.apply {
|
||||
setLayout(defWidth, defHeight)
|
||||
setBackgroundDrawable(ColorDrawable())
|
||||
setGravity(Gravity.CENTER)
|
||||
}
|
||||
rootView.setOnClickListener { it.hideKeyboard() }
|
||||
initView()
|
||||
}
|
||||
|
||||
abstract fun getRootView(): View
|
||||
|
||||
abstract fun initView()
|
||||
|
||||
fun getReceiptActivity(): GoodsListActivity? {
|
||||
var ctx = context
|
||||
while (ctx is ContextWrapper) {
|
||||
ctx = ctx.baseContext
|
||||
if (ctx is GoodsListActivity) {
|
||||
return ctx
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getFoodCollectionActivity(): FoodCollectionActivity? {
|
||||
var ctx = context
|
||||
while (ctx is ContextWrapper) {
|
||||
ctx = ctx.baseContext
|
||||
if (ctx is FoodCollectionActivity) {
|
||||
return ctx
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
DialogManager.addDialog(this)
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
super.dismiss()
|
||||
DialogManager.removeDialog(this)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user