diff --git a/EaseDialogModule/src/main/java/com/night/dialog/DialogBuilder.kt b/EaseDialogModule/src/main/java/com/night/dialog/DialogBuilder.kt index b15a9ea..fdfe478 100644 --- a/EaseDialogModule/src/main/java/com/night/dialog/DialogBuilder.kt +++ b/EaseDialogModule/src/main/java/com/night/dialog/DialogBuilder.kt @@ -209,7 +209,7 @@ class DialogBuilder : BaseDialogBuilder() { activity: AppCompatActivity, msg: String = DialogHelp.getString(R.string.loading), callback: ILoadingCallback? = null - ) { + ): LoadingDialogFragment{ val mFragmentManage = activity.supportFragmentManager val mHistoryDialog = mFragmentManage.findFragmentByTag("LoadingDialog") if (mHistoryDialog != null && mHistoryDialog is LoadingDialogFragment) { @@ -220,6 +220,7 @@ class DialogBuilder : BaseDialogBuilder() { mLoadingDialog.setMainTextInfo(mMainTextInfo) mLoadingDialog.setCallback(callback) mLoadingDialog.showNow(mFragmentManage, "LoadingDialog") + return mLoadingDialog } /** diff --git a/EaseDialogModule/src/main/java/com/night/dialog/DialogTools.kt b/EaseDialogModule/src/main/java/com/night/dialog/DialogTools.kt index 39e4445..681b1ce 100644 --- a/EaseDialogModule/src/main/java/com/night/dialog/DialogTools.kt +++ b/EaseDialogModule/src/main/java/com/night/dialog/DialogTools.kt @@ -2,10 +2,12 @@ package com.night.dialog import android.view.Gravity import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity import com.hjq.toast.ToastParams import com.hjq.toast.Toaster import com.night.dialog.callback.IBindView import com.night.dialog.tools.ToastHelp +import com.night.dialog.ui.loading.LoadingDialogFragment object DialogTools { @@ -43,10 +45,27 @@ object DialogTools { } } } + + /** + * 关闭Toast + */ fun dismissToast() { Toaster.cancel() } + /** + * 关闭加载框 + * + * @param activity AppCompatActivity + */ + fun dismissLoadingDialog(activity: AppCompatActivity) { + val mFragmentManage = activity.supportFragmentManager + val mHistoryDialog = mFragmentManage.findFragmentByTag("LoadingDialog") + if (mHistoryDialog != null && mHistoryDialog is LoadingDialogFragment) { + mHistoryDialog.dismiss() + } + } + fun getDialogBuilder(): DialogBuilder { return DialogBuilder() } diff --git a/app/src/main/java/com/night/easedialog/MainActivity.kt b/app/src/main/java/com/night/easedialog/MainActivity.kt index 4ab5a63..a4d18a2 100644 --- a/app/src/main/java/com/night/easedialog/MainActivity.kt +++ b/app/src/main/java/com/night/easedialog/MainActivity.kt @@ -3,6 +3,8 @@ package com.night.easedialog import android.annotation.SuppressLint import android.graphics.Color import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.view.MotionEvent import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.AppCompatTextView @@ -41,163 +43,167 @@ class MainActivity : AppCompatActivity() { "周日", "周一", "周二", "周三", "周四", "周五", "周六", "黑色星期一" ) private val mSelectMultipleIndex = mutableListOf() + @SuppressLint("ClickableViewAccessibility") -override fun onCreate(savedInstanceState: Bundle?) { -super.onCreate(savedInstanceState) -setContentView(R.layout.activity_main) -mTipsView = findViewById(R.id.btn_tips_dialog) -mWarnView = findViewById(R.id.btn_warn_dialog) -mSingleView = findViewById(R.id.btn_single_dialog) -mMultipleView = findViewById(R.id.btn_multiple_dialog) -mSingleMenuleView = findViewById(R.id.btn_single_menu) -mDateTimePickerleView = findViewById(R.id.btn_date_time_picker) -mAddressPickerleView = findViewById(R.id.btn_address_picker) -mColorPickerleView = findViewById(R.id.btn_color_picker) -mLoadingView = findViewById(R.id.btn_loading) -mToastView = findViewById(R.id.btn_toast) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + mTipsView = findViewById(R.id.btn_tips_dialog) + mWarnView = findViewById(R.id.btn_warn_dialog) + mSingleView = findViewById(R.id.btn_single_dialog) + mMultipleView = findViewById(R.id.btn_multiple_dialog) + mSingleMenuleView = findViewById(R.id.btn_single_menu) + mDateTimePickerleView = findViewById(R.id.btn_date_time_picker) + mAddressPickerleView = findViewById(R.id.btn_address_picker) + mColorPickerleView = findViewById(R.id.btn_color_picker) + mLoadingView = findViewById(R.id.btn_loading) + mToastView = findViewById(R.id.btn_toast) -//提示性质模态框 -mTipsView.setOnClickListener { -DialogTools.getDialogBuilder() - .setTitleText("允许日历联网") - .setMainText("下载或更新节假日、班休、历法、订阅等信息。") - .setPositiveTextColor(Color.RED) - .toTipsDialog(this, object : ITipsModalCallback { - override fun onPositive() { - DialogTools.getToastBuilder().toToast("点击确定") - } + //提示性质模态框 + mTipsView.setOnClickListener { + DialogTools.getDialogBuilder() + .setTitleText("允许日历联网") + .setMainText("下载或更新节假日、班休、历法、订阅等信息。") + .setPositiveTextColor(Color.RED) + .toTipsDialog(this, object : ITipsModalCallback { + override fun onPositive() { + DialogTools.getToastBuilder().toToast("点击确定") + } - override fun onCancel() { - DialogTools.getToastBuilder().toToast("点击取消") - } - }) -} -//警告性质模态框 -mWarnView.setOnClickListener { -DialogTools.getDialogBuilder() - .setMainText("确定删除当前联系人?") - .setPositiveTextColor(Color.RED) - .setPositiveText("删除") - .toWarnDialog(this, object : IWarnModalCallback { - override fun onPositive() { - DialogTools.getToastBuilder().toToast("点击确定") + override fun onCancel() { + DialogTools.getToastBuilder().toToast("点击取消") + } + }) } + //警告性质模态框 + mWarnView.setOnClickListener { + DialogTools.getDialogBuilder() + .setMainText("确定删除当前联系人?") + .setPositiveTextColor(Color.RED) + .setPositiveText("删除") + .toWarnDialog(this, object : IWarnModalCallback { + override fun onPositive() { + DialogTools.getToastBuilder().toToast("点击确定") + } - override fun onCancel() { - DialogTools.getToastBuilder().toToast("点击取消") + override fun onCancel() { + DialogTools.getToastBuilder().toToast("点击取消") + } + }) } - }) -} -//底部单选菜单 -mSingleView.setOnClickListener { -DialogTools.getDialogBuilder() - .setTitleText("重复") - .toSingleMenu( - this, - mSingleList, - mSelectSingleIndex, - object : ISingleMenuCallback { - override fun onPositive(title: String, menuIndex: Int) { - mSelectSingleIndex = menuIndex - DialogTools.getToastBuilder().toToast("选中内容:$title") - } + //底部单选菜单 + mSingleView.setOnClickListener { + DialogTools.getDialogBuilder() + .setTitleText("重复") + .toSingleMenu( + this, + mSingleList, + mSelectSingleIndex, + object : ISingleMenuCallback { + override fun onPositive(title: String, menuIndex: Int) { + mSelectSingleIndex = menuIndex + DialogTools.getToastBuilder().toToast("选中内容:$title") + } - override fun onCancel() { - DialogTools.getToastBuilder().toToast("点击取消") - } - }) -} -//底部多选菜单 -mMultipleView.setOnClickListener { -DialogTools.getDialogBuilder() - .setTitleText("重复") - .toMultipleMenu(this, mMultipleList, mSelectMultipleIndex, - object : IMultipleMenuCallback { - override fun onPositive(title: List, menuIndex: List) { - mSelectMultipleIndex.clear() - mSelectMultipleIndex.addAll(menuIndex) - DialogTools.getToastBuilder().toToast("选中内容:${menuIndex.size}个") - } + override fun onCancel() { + DialogTools.getToastBuilder().toToast("点击取消") + } + }) + } + //底部多选菜单 + mMultipleView.setOnClickListener { + DialogTools.getDialogBuilder() + .setTitleText("重复") + .toMultipleMenu(this, mMultipleList, mSelectMultipleIndex, + object : IMultipleMenuCallback { + override fun onPositive(title: List, menuIndex: List) { + mSelectMultipleIndex.clear() + mSelectMultipleIndex.addAll(menuIndex) + DialogTools.getToastBuilder().toToast("选中内容:${menuIndex.size}个") + } - override fun onCancel() { - DialogTools.getToastBuilder().toToast("点击取消") - } - }) -} -//时间日期选择器 -mDateTimePickerleView.setOnClickListener { -DialogTools.getPickerBuilder() - .setTitleText("请选择日期和时间") - .setMinDateTime(mStartDateTime) - .setMaxDateTime(mEndDateTime) - .setSelDateTime(mSelectDateTime) - .toDateTimePicker(this, PICKER_ALL, object : IDateTimeCallback { - override fun onPositive(result: EaseDateTimeEntity) { - DialogTools.getToastBuilder() - .toToast(result.getDateTime()) + override fun onCancel() { + DialogTools.getToastBuilder().toToast("点击取消") + } + }) } + //时间日期选择器 + mDateTimePickerleView.setOnClickListener { + DialogTools.getPickerBuilder() + .setTitleText("请选择日期和时间") + .setMinDateTime(mStartDateTime) + .setMaxDateTime(mEndDateTime) + .setSelDateTime(mSelectDateTime) + .toDateTimePicker(this, PICKER_ALL, object : IDateTimeCallback { + override fun onPositive(result: EaseDateTimeEntity) { + DialogTools.getToastBuilder() + .toToast(result.getDateTime()) + } - override fun onCancel() { - super.onCancel() - DialogTools.getToastBuilder() - .toToast("取消") + override fun onCancel() { + super.onCancel() + DialogTools.getToastBuilder() + .toToast("取消") + } + }) } - }) -} -//地址选择器 -mAddressPickerleView.setOnClickListener { -DialogTools.getPickerBuilder() - .setTitleText("请选择地址") - .setSelectProvince(mProvince) - .setSelectCity(mCity) - .setSelectCounty(mCounty) - .toAddressPicker(this, PICKER_ADDRESS_PROVINCE_CITY, object : ILocationCallback { - override fun onPositive( - province: EaseLocationEntity, - city: EaseLocationEntity, - county: EaseLocationEntity - ) { - mProvince = province - mCity = city - mCounty = county - DialogTools.getToastBuilder().toToast(province.name + city.name + county.name) + //地址选择器 + mAddressPickerleView.setOnClickListener { + DialogTools.getPickerBuilder() + .setTitleText("请选择地址") + .setSelectProvince(mProvince) + .setSelectCity(mCity) + .setSelectCounty(mCounty) + .toAddressPicker(this, PICKER_ADDRESS_PROVINCE_CITY, object : ILocationCallback { + override fun onPositive( + province: EaseLocationEntity, + city: EaseLocationEntity, + county: EaseLocationEntity + ) { + mProvince = province + mCity = city + mCounty = county + DialogTools.getToastBuilder().toToast(province.name + city.name + county.name) + } + }) } - }) -} -//颜色选择器 -mColorPickerleView.setOnClickListener { -DialogTools.getPickerBuilder() - .setTitleText("请选择颜色") - .toColorPicker(this, object : IColorSelectCallback { - override fun onPositive(red: Int, green: Int, blue: Int) { - DialogTools.getToastBuilder() - .toToast("R:".plus(red).plus("|G:").plus(green).plus("|B:").plus(blue)) + //颜色选择器 + mColorPickerleView.setOnClickListener { + DialogTools.getPickerBuilder() + .setTitleText("请选择颜色") + .toColorPicker(this, object : IColorSelectCallback { + override fun onPositive(red: Int, green: Int, blue: Int) { + DialogTools.getToastBuilder() + .toToast("R:".plus(red).plus("|G:").plus(green).plus("|B:").plus(blue)) + } + }) } - }) -} -//加载框 -mLoadingView.setOnClickListener { - DialogTools.getDialogBuilder() - .toLoadingDialog(this, "正在加载中...") -} -//Toast -mToastView.setOnClickListener { - DialogTools.getToastBuilder() - .toToast("文件删除成功~") -} -//单选菜单 + //加载框 + mLoadingView.setOnClickListener { + val mLoading = DialogTools.getDialogBuilder() + .toLoadingDialog(this, "3秒...") + Handler(Looper.getMainLooper()).postDelayed({ + mLoading.dismiss() + },3000) -mSingleMenuleView.setOnTouchListener { v, event -> -if (event.action == MotionEvent.ACTION_UP) { -DialogTools.getDialogBuilder() - .setTouchCoordinate(event.x, event.y, event.rawX, event.rawY) - .toPopMenu(this, v, mutableListOf("删除", "编辑", "复制"), object : IPopMenuCallback { - override fun onPositive(title: String, menuIndex: Int) { - DialogTools.getToastBuilder().toToast(title) } - }) -} -true -} -} + //Toast + mToastView.setOnClickListener { + DialogTools.getToastBuilder() + .toToast("文件删除成功~") + } + //单选菜单 + mSingleMenuleView.setOnTouchListener { v, event -> + if (event.action == MotionEvent.ACTION_UP) { + DialogTools.getDialogBuilder() + .setTouchCoordinate(event.x, event.y, event.rawX, event.rawY) + .toPopMenu(this, v, mutableListOf("删除", "编辑", "复制"), object : IPopMenuCallback { + override fun onPositive(title: String, menuIndex: Int) { + DialogTools.getToastBuilder().toToast(title) + } + }) + } + true + } + } } \ No newline at end of file