Skip to content

Commit

Permalink
[优化]部分注释
Browse files Browse the repository at this point in the history
  • Loading branch information
awakem committed Apr 1, 2023
1 parent 7fb1d82 commit fe044bf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 27 deletions.
26 changes: 11 additions & 15 deletions EaseDialogModule/src/main/java/com/night/dialog/DialogBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DialogBuilder : BaseDialogBuilder() {
*
* @param positive 确认按钮文本颜色
*/
fun setPositiveTextColor(positive: Int): DialogBuilder {
fun setPositiveTextColor(@ColorInt positive: Int): DialogBuilder {
this.mPositionTextColor = positive
return this
}
Expand All @@ -166,6 +166,14 @@ class DialogBuilder : BaseDialogBuilder() {
return this
}

/**
* 设置PopMenu弹出坐标
*
* @param x 相对父容器X轴坐标
* @param y 相对父容器Y轴坐标
* @param rawX 相对屏幕X轴坐标
* @param rawY 相对屏幕Y轴坐标
*/
fun setTouchCoordinate(x: Float, y: Float, rawX: Float, rawY: Float): DialogBuilder {
mPopMenuHelp.setTouchCoordinate(x, y, rawX, rawY)
return this
Expand Down Expand Up @@ -249,17 +257,11 @@ class DialogBuilder : BaseDialogBuilder() {
* 构建单选菜单
*
* @param activity Activity
* @param title 对话框标题
* @param menu 菜单内容
* @param defIndex 默认选中位置
* @param callback 状态回调[IDialogActionCallback]
*/
fun toSingleMenu(
activity: Activity,
menu: MutableList<String>,
defIndex: Int = -1,
callback: IDialogActionCallback?
) {
fun toSingleMenu(activity: Activity, menu: MutableList<String>, defIndex: Int = -1, callback: IDialogActionCallback?) {
DialogTools.showDialog(activity, object : IBindDialogView(R.layout.dialog_single_menu) {
override fun onBind(dialog: BaseDialog) {
val mTitleView = dialog.findViewById<AppCompatTextView>(R.id.tv_menu_title)
Expand Down Expand Up @@ -305,17 +307,11 @@ class DialogBuilder : BaseDialogBuilder() {
* 构建多选菜单
*
* @param activity Activity
* @param title 对话框标题
* @param menu 菜单内容
* @param defIndex 默认选中位置
* @param callback 状态回调[IDialogActionCallback]
*/
fun toMultipleMenu(
activity: Activity,
menu: MutableList<String>,
defIndex: MutableList<Int>? = null,
callback: IDialogActionCallback?
) {
fun toMultipleMenu(activity: Activity, menu: MutableList<String>, defIndex: MutableList<Int>? = null, callback: IDialogActionCallback?) {
DialogTools.showDialog(activity, object : IBindDialogView(R.layout.dialog_multiple_menu) {
override fun onBind(dialog: BaseDialog) {
val mTitleView = dialog.findViewById<AppCompatTextView>(R.id.tv_menu_title)
Expand Down
14 changes: 10 additions & 4 deletions EaseDialogModule/src/main/java/com/night/dialog/DialogTools.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
package com.night.dialog


import android.app.Activity
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.Toast
import androidx.annotation.StyleRes
import com.hjq.toast.ToastParams
import com.hjq.toast.Toaster
import com.night.dialog.base.BaseDialog
import com.night.dialog.callback.*
import com.night.dialog.callback.IBindDialogView
import com.night.dialog.callback.IBindView
import com.night.dialog.tools.ToastHelp
import java.lang.ref.WeakReference

object DialogTools {
private var mShowDialog: WeakReference<BaseDialog>? = null

/**
* 弹出Dialog
*
* @param styleId Dialog样式
* @param gravity 弹出位置
* @param isCancel 是否可取消
*/
fun showDialog(activity: Activity, bindView: IBindDialogView, @StyleRes styleId: Int, gravity: Int, isCancel: Boolean) {
fun showDialog(
activity: Activity,
bindView: IBindDialogView,
@StyleRes styleId: Int,
gravity: Int,
isCancel: Boolean
) {
if (mShowDialog != null && mShowDialog!!.get() != null) {
mShowDialog!!.get()!!.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ object EaseDialog {
}
return mApplication.applicationContext
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ import com.night.dialog.entity.TextInfoEntity

internal object DialogHelp {

fun setTextViewInfo(view: TextView?,info: TextInfoEntity?){
if(view == null || info == null){
/**
* 设置View属性
*
* @param view TextView
* @param info 属性实体
*/
fun setTextViewInfo(view: TextView?, info: TextInfoEntity?) {
if (view == null || info == null) {
return
}
view.paint.isFakeBoldText = info.isBold
if(!TextUtils.isEmpty(info.text)){
view.text =info.text
if (!TextUtils.isEmpty(info.text)) {
view.text = info.text
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX,info.mTextSize)
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, info.mTextSize)
view.setTextColor(info.textColor)
}

/**
* 是否为横屏
* @return 是否为横屏
*/
fun isLandscape(): Boolean {
val configuration = EaseDialog.getContext().resources.configuration.orientation
Expand All @@ -44,17 +51,42 @@ internal object DialogHelp {
return EaseDialog.getContext().getString(id)
}

/**
* 获取资源文件下内容
* @param id 资源文件ID
* @return 对应内容
*/
@ColorInt
fun getColor(@ColorRes id: Int): Int {
return ContextCompat.getColor(EaseDialog.getContext(), id)
}

/**
* dp转px
*
* @param dp dp值
* @return px值
*/
fun dpToPx(dp: Float): Int {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, EaseDialog.getContext().resources.displayMetrics).toInt()
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp,
EaseDialog.getContext().resources.displayMetrics
).toInt()
}

/**
* sp转px
*
* @param dp sp值
* @return px值
*/
fun spToPx(dp: Float): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, EaseDialog.getContext().resources.displayMetrics)
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
dp,
EaseDialog.getContext().resources.displayMetrics
)
}

/**
Expand Down

0 comments on commit fe044bf

Please sign in to comment.