diff --git a/.gitignore b/.gitignore index 603b140..6f6d9f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.iml .gradle /local.properties +/.idea /.idea/caches /.idea/libraries /.idea/modules.xml diff --git a/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt b/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt index 693258a..2f22b83 100644 --- a/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt +++ b/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt @@ -17,14 +17,15 @@ import com.yutou.popdialog.utils.POPDialogUtils import com.yutou.popdialog.views.ExitButton -class POPDialog(context: Activity) : Dialog(context) { - private val activityContext: Activity = context +class POPDialog : Dialog { + private val activityContext: Activity + private var defLayoutResId = R.layout.pop_dialog_layout private lateinit var title: TextView - private val layout: FrameLayout by lazy { - findViewById(R.id.title) + private val layout: ViewGroup by lazy { + findViewById(R.id.pop_dialog_title) } - private val dialogContext: FrameLayout by lazy { - findViewById(R.id.context) + private val dialogContext: ViewGroup by lazy { + findViewById(R.id.pop_dialog_content) } private lateinit var view: View @@ -35,7 +36,15 @@ class POPDialog(context: Activity) : Dialog(context) { private var showModel = 0 private var expansionY = 0f - init { + constructor(context: Activity) : super(context) { + activityContext = context + requestWindowFeature(Window.FEATURE_NO_TITLE) + initView() + } + + constructor(context: Activity, layoutResID: Int) : super(context) { + defLayoutResId = layoutResID + activityContext = context requestWindowFeature(Window.FEATURE_NO_TITLE) initView() } @@ -43,7 +52,7 @@ class POPDialog(context: Activity) : Dialog(context) { private fun initView() { mainView = FrameLayout(activityContext) view = - LayoutInflater.from(context).inflate(R.layout.dialog, mainView, false) as LinearLayout + LayoutInflater.from(context).inflate(defLayoutResId, mainView, false) val animation = AnimationUtils.loadAnimation( context, R.anim.enter_anim @@ -83,11 +92,11 @@ class POPDialog(context: Activity) : Dialog(context) { */ public fun setMessage(text: String) { val textView = TextView(ContextThemeWrapper(activityContext, R.style.messageText)) - val params = FrameLayout.LayoutParams( + val params = ViewGroup.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT - ); - textView.layoutParams = params; + ) + textView.layoutParams = params textView.text = text dialogContext.addView(textView) } @@ -128,7 +137,8 @@ class POPDialog(context: Activity) : Dialog(context) { * 不允许设置资源id * @param layoutResID 正文id */ - @Deprecated("设置资源id会导致内容无法控制,不建议使用", + @Deprecated( + "设置资源id会导致内容无法控制,不建议使用", ReplaceWith("throw RuntimeException") ) override fun setContentView(layoutResID: Int) { @@ -191,7 +201,8 @@ class POPDialog(context: Activity) : Dialog(context) { ) params.height = (dialogContext.height / 1.25).toInt() dialogContext.layoutParams = params - view.y =(POPDialogUtils.getDisplay(activityContext).mode.physicalHeight / 2).toFloat() + view.y = + (POPDialogUtils.getDisplay(activityContext).mode.physicalHeight / 2).toFloat() expansionY = view.y } configTouch() @@ -208,8 +219,8 @@ class POPDialog(context: Activity) : Dialog(context) { ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT ) - params.width= (POPDialogUtils.getDisplay(activityContext).mode.physicalWidth*0.8).toInt() - params.gravity=Gravity.CENTER + params.width = (POPDialogUtils.getDisplay(activityContext).mode.physicalWidth * 0.8).toInt() + params.gravity = Gravity.CENTER layout.layoutParams = params layout.setOnTouchListener(object : View.OnTouchListener { override fun onTouch(p0: View?, p1: MotionEvent?): Boolean { diff --git a/POPDialog/src/main/res/layout/dialog.xml b/POPDialog/src/main/res/layout/pop_dialog_layout.xml similarity index 81% rename from POPDialog/src/main/res/layout/dialog.xml rename to POPDialog/src/main/res/layout/pop_dialog_layout.xml index 8f067aa..bab112c 100644 --- a/POPDialog/src/main/res/layout/dialog.xml +++ b/POPDialog/src/main/res/layout/pop_dialog_layout.xml @@ -1,13 +1,12 @@ \ No newline at end of file diff --git a/POPDialog/src/main/res/values/styles.xml b/POPDialog/src/main/res/values/styles.xml index 1d85a50..1b06424 100644 --- a/POPDialog/src/main/res/values/styles.xml +++ b/POPDialog/src/main/res/values/styles.xml @@ -18,6 +18,7 @@ diff --git a/app/src/main/res/layout/demo.xml b/app/src/main/res/layout/demo.xml new file mode 100644 index 0000000..aebefab --- /dev/null +++ b/app/src/main/res/layout/demo.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file