197 lines
4.2 KiB
Java
197 lines
4.2 KiB
Java
package com.aoleyun.sn.dialog;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import com.aoleyun.sn.R;
|
|
|
|
|
|
/**
|
|
* description:自定义dialog
|
|
*/
|
|
|
|
public class UpdateDialog extends AlertDialog {
|
|
/**
|
|
* 显示的标题
|
|
*/
|
|
private TextView titleTv;
|
|
|
|
/**
|
|
* 显示的消息
|
|
*/
|
|
private TextView messageTv;
|
|
|
|
/**
|
|
* 确认和取消按钮
|
|
*/
|
|
private TextView positiveBn;
|
|
|
|
/**
|
|
* 按钮之间的分割线
|
|
*/
|
|
// private View columnLineView;
|
|
|
|
private Context mContext;
|
|
|
|
public UpdateDialog(Context context) {
|
|
super(context, R.style.CustomDialog);
|
|
this.mContext = context;
|
|
}
|
|
|
|
/**
|
|
* 都是内容数据
|
|
*/
|
|
private String message;
|
|
private String title;
|
|
private String positive;
|
|
private int imageResId = -1;
|
|
|
|
/**
|
|
* 底部是否只有一个按钮
|
|
*/
|
|
private boolean isSingle = false;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.update_dialog);
|
|
//按空白处不能取消动画
|
|
setCanceledOnTouchOutside(false);
|
|
//初始化界面控件
|
|
initView();
|
|
//初始化界面数据
|
|
refreshView();
|
|
//初始化界面控件的事件
|
|
initEvent();
|
|
}
|
|
|
|
/**
|
|
* 初始化界面的确定和取消监听器
|
|
*/
|
|
private void initEvent() {
|
|
//设置确定按钮被点击后,向外界提供监听
|
|
positiveBn.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (onClickBottomListener != null) {
|
|
onClickBottomListener.onPositiveClick();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 初始化界面控件的显示数据
|
|
*/
|
|
private void refreshView() {
|
|
//如果用户自定了title和message
|
|
if (!TextUtils.isEmpty(title)) {
|
|
titleTv.setText(title);
|
|
titleTv.setVisibility(View.VISIBLE);
|
|
} else {
|
|
titleTv.setVisibility(View.GONE);
|
|
}
|
|
if (!TextUtils.isEmpty(message)) {
|
|
messageTv.setText(message);
|
|
}
|
|
//如果设置按钮的文字
|
|
if (!TextUtils.isEmpty(positive)) {
|
|
positiveBn.setText(positive);
|
|
} else {
|
|
positiveBn.setText("确定");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void show() {
|
|
super.show();
|
|
refreshView();
|
|
}
|
|
|
|
/**
|
|
* 初始化界面控件
|
|
*/
|
|
private void initView() {
|
|
positiveBn = findViewById(R.id.positive);
|
|
titleTv = findViewById(R.id.title);
|
|
messageTv = findViewById(R.id.message);
|
|
}
|
|
|
|
/**
|
|
* 设置确定取消按钮的回调
|
|
*/
|
|
private OnClickBottomListener onClickBottomListener;
|
|
|
|
public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
|
|
this.onClickBottomListener = onClickBottomListener;
|
|
}
|
|
|
|
public interface OnClickBottomListener {
|
|
/**
|
|
* 点击确定按钮事件
|
|
*/
|
|
void onPositiveClick();
|
|
|
|
/**
|
|
* 点击取消按钮事件
|
|
*/
|
|
void onNegtiveClick();
|
|
}
|
|
|
|
public String getMessage() {
|
|
return message;
|
|
}
|
|
|
|
public UpdateDialog setMessage(String message) {
|
|
this.message = message;
|
|
return this;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public UpdateDialog setTitle(String title) {
|
|
this.title = title;
|
|
return this;
|
|
}
|
|
|
|
public String getPositive() {
|
|
return positive;
|
|
}
|
|
|
|
public UpdateDialog setPositive(String positive) {
|
|
this.positive = positive;
|
|
return this;
|
|
}
|
|
|
|
public int getImageResId() {
|
|
return imageResId;
|
|
}
|
|
|
|
public boolean isSingle() {
|
|
return isSingle;
|
|
}
|
|
|
|
public UpdateDialog setSingle(boolean single) {
|
|
isSingle = single;
|
|
return this;
|
|
}
|
|
|
|
public UpdateDialog setImageResId(int imageResId) {
|
|
this.imageResId = imageResId;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void dismiss() {
|
|
super.dismiss();
|
|
}
|
|
}
|