From c64e8678a0e5d9e753a3e60f82e74b033f65d4ca Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 26 May 2022 10:18:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E6=94=AF=E6=8C=81=EF=BC=8C=E5=8F=AF=E5=8F=82?= =?UTF-8?q?=E8=80=83app\src\main\res\layout\demo.xml=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=B8=83=E5=B1=80id=E5=91=BD=E5=90=8D=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E4=B8=8E=E5=AE=BF=E4=B8=BBid=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../java/com/yutou/popdialog/POPDialog.kt | 41 ++++++++++++------- .../{dialog.xml => pop_dialog_layout.xml} | 13 +++--- POPDialog/src/main/res/values/styles.xml | 1 + app/src/main/res/layout/demo.xml | 21 ++++++++++ 5 files changed, 55 insertions(+), 22 deletions(-) rename POPDialog/src/main/res/layout/{dialog.xml => pop_dialog_layout.xml} (81%) create mode 100644 app/src/main/res/layout/demo.xml 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