package com.hdl.photovoltaic.widget;
|
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.os.Bundle;
|
import android.os.Message;
|
import android.text.TextUtils;
|
import android.view.View;
|
import android.widget.TextView;
|
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
|
import com.hdl.photovoltaic.R;
|
import com.hdl.photovoltaic.base.BaseDialog;
|
import com.hdl.photovoltaic.databinding.DialogConfirmCancelBinding;
|
|
/**
|
* 确认取消框
|
*/
|
public class ConfirmationCancelDialog extends BaseDialog {
|
public ConfirmationCancelDialog(@NonNull Context context) {
|
super(context, R.style.Custom_Dialog);
|
this.mContext = context;
|
}
|
|
private final Context mContext;
|
private onNoOnclickListener noOnclickListener;//取消按钮被点击了的监听器
|
private onYesOnclickListener yesOnclickListener;//确定按钮被点击了的监听器
|
private DialogConfirmCancelBinding viewBinding;
|
private String titleStr, contentStr, yesStr, noStr;
|
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
viewBinding = DialogConfirmCancelBinding.inflate(getLayoutInflater());
|
setContentView(viewBinding.getRoot());
|
|
// setCancelable(true);//系统后退可以取消
|
//空白处不能取消动画
|
// setCanceledOnTouchOutside(false);
|
//初始化界面控件
|
initView();
|
//初始化界面数据
|
initData();
|
//初始化界面控件的事件
|
initEvent();
|
|
}
|
|
/**
|
* 自定义"标题"文本
|
*
|
* @param title 内容
|
*/
|
public void setTitle(String title) {
|
if (TextUtils.isEmpty(title)) {
|
return;
|
}
|
titleStr = title;
|
if (viewBinding != null) {
|
viewBinding.loadingConfirmationTitleTv.setText(titleStr);
|
}
|
|
}
|
|
|
/**
|
* 隐藏自定义"标题"组件
|
*
|
* @param isHideTitle true 隐藏
|
*/
|
public void isHideTitle(boolean isHideTitle) {
|
if (isHideTitle) {
|
if (viewBinding != null) {
|
viewBinding.loadingConfirmationTitleTv.setVisibility(View.GONE);
|
}
|
}
|
}
|
|
/**
|
* 自定义"确认"文本
|
*
|
* @param confirm 内容
|
*/
|
public void setConfirmation(String confirm) {
|
if (TextUtils.isEmpty(confirm)) {
|
return;
|
}
|
yesStr = confirm;
|
|
|
if (viewBinding != null) {
|
viewBinding.dialogConfirmTv.setText(yesStr);
|
}
|
|
|
}
|
|
/**
|
* 自定义"取消"文本
|
*
|
* @param cancel 内容
|
*/
|
public void setCancel(String cancel) {
|
if (TextUtils.isEmpty(cancel)) {
|
return;
|
}
|
noStr = cancel;
|
if (viewBinding != null) {
|
viewBinding.dialogCancelTv.setText(noStr);
|
}
|
|
}
|
|
/**
|
* 自定义"内容"文本
|
*
|
* @param content 内容
|
*/
|
public void setContent(String content) {
|
if (TextUtils.isEmpty(content)) {
|
return;
|
}
|
contentStr = content;
|
if (viewBinding != null) {
|
viewBinding.loadingConfirmationContentTv.setText(contentStr);
|
}
|
}
|
|
public TextView getContentTextView() {
|
if (viewBinding == null) {
|
return null;
|
}
|
return viewBinding.loadingConfirmationContentTv;
|
}
|
|
private void initEvent() {
|
viewBinding.dialogCancelLy.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (noOnclickListener != null) {
|
noOnclickListener.Cancel();
|
}
|
}
|
});
|
viewBinding.dialogConfirmLy.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (yesOnclickListener != null) {
|
yesOnclickListener.Confirm();
|
}
|
}
|
});
|
|
|
}
|
|
|
/**
|
* 初始化界面控件的显示数据
|
*/
|
private void initData() {
|
//如果用户自定了title和message
|
if (!TextUtils.isEmpty(titleStr)) {
|
viewBinding.loadingConfirmationTitleTv.setText(titleStr);
|
}
|
if (!TextUtils.isEmpty(contentStr)) {
|
viewBinding.loadingConfirmationContentTv.setText(contentStr);
|
}
|
//如果设置按钮文字
|
if (!TextUtils.isEmpty(yesStr)) {
|
viewBinding.dialogConfirmTv.setText(yesStr);
|
}
|
if (!TextUtils.isEmpty(noStr)) {
|
viewBinding.dialogCancelTv.setText(noStr);
|
}
|
}
|
|
private void initView() {
|
|
|
}
|
|
/**
|
* 设置取消按钮监听
|
*
|
* @param onNoOnclickListener -
|
*/
|
public void setNoOnclickListener(onNoOnclickListener onNoOnclickListener) {
|
if (onNoOnclickListener != null) {
|
this.noOnclickListener = onNoOnclickListener;
|
}
|
}
|
|
/**
|
* 设置确定按钮监听
|
*
|
* @param yesOnclickListener -
|
*/
|
public void setYesOnclickListener(onYesOnclickListener yesOnclickListener) {
|
if (yesOnclickListener != null) {
|
this.yesOnclickListener = yesOnclickListener;
|
}
|
|
}
|
|
public interface onNoOnclickListener {
|
void Cancel();
|
|
}
|
|
public interface onYesOnclickListener {
|
void Confirm();
|
}
|
}
|