252 lines
5.9 KiB
Java
252 lines
5.9 KiB
Java
package com.uiuios.aios.dialog;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import com.uiuios.aios.R;
|
|
|
|
|
|
/**
|
|
* description:自定义dialog
|
|
*/
|
|
|
|
public class SingleDialog extends AlertDialog {
|
|
/**
|
|
* 显示的图片
|
|
*/
|
|
private ImageView imageIv;
|
|
|
|
/**
|
|
* 显示的标题
|
|
*/
|
|
private TextView titleTv;
|
|
|
|
/**
|
|
* 显示的消息
|
|
*/
|
|
private TextView messageTv;
|
|
|
|
/**
|
|
* 确认和取消按钮
|
|
*/
|
|
private TextView positiveBn;
|
|
// private TextView negtiveBn;
|
|
|
|
/**
|
|
* 按钮之间的分割线
|
|
*/
|
|
// private View columnLineView;
|
|
|
|
private Context mContext;
|
|
|
|
public SingleDialog(Context context) {
|
|
super(context, R.style.CustomDialog);
|
|
this.mContext = context;
|
|
}
|
|
|
|
/**
|
|
* 都是内容数据
|
|
*/
|
|
private String message;
|
|
private String title;
|
|
private String positive, negtive;
|
|
private int imageResId = -1;
|
|
|
|
/**
|
|
* 底部是否只有一个按钮
|
|
*/
|
|
private boolean isSingle = false;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.single_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();
|
|
}
|
|
}
|
|
});
|
|
//设置取消按钮被点击后,向外界提供监听
|
|
// negtiveBn.setOnClickListener(new View.OnClickListener() {
|
|
// @Override
|
|
// public void onClick(View v) {
|
|
// if (onClickBottomListener != null) {
|
|
// onClickBottomListener.onNegtiveClick();
|
|
// }
|
|
// }
|
|
// });
|
|
}
|
|
|
|
/**
|
|
* 初始化界面控件的显示数据
|
|
*/
|
|
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("确定");
|
|
}
|
|
// if (!TextUtils.isEmpty(negtive)) {
|
|
// negtiveBn.setText(negtive);
|
|
// } else {
|
|
// negtiveBn.setText("取消");
|
|
// }
|
|
|
|
if (imageResId != -1) {
|
|
imageIv.setImageResource(imageResId);
|
|
imageIv.setVisibility(View.VISIBLE);
|
|
} else {
|
|
imageIv.setVisibility(View.GONE);
|
|
}
|
|
/**
|
|
* 只显示一个按钮的时候隐藏取消按钮,回掉只执行确定的事件
|
|
*/
|
|
// if (isSingle) {
|
|
//// columnLineView.setVisibility(View.GONE);
|
|
// negtiveBn.setVisibility(View.GONE);
|
|
// } else {
|
|
// negtiveBn.setVisibility(View.VISIBLE);
|
|
//// columnLineView.setVisibility(View.VISIBLE);
|
|
// }
|
|
}
|
|
|
|
@Override
|
|
public void show() {
|
|
super.show();
|
|
refreshView();
|
|
}
|
|
|
|
/**
|
|
* 初始化界面控件
|
|
*/
|
|
private void initView() {
|
|
// negtiveBn = findViewById(R.id.negtive);
|
|
positiveBn = findViewById(R.id.positive);
|
|
titleTv = findViewById(R.id.title);
|
|
messageTv = findViewById(R.id.message);
|
|
imageIv = findViewById(R.id.image);
|
|
// columnLineView = findViewById(R.id.column_line);
|
|
}
|
|
|
|
/**
|
|
* 设置确定取消按钮的回调
|
|
*/
|
|
private OnClickBottomListener onClickBottomListener;
|
|
|
|
public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
|
|
this.onClickBottomListener = onClickBottomListener;
|
|
}
|
|
|
|
public interface OnClickBottomListener {
|
|
/**
|
|
* 点击确定按钮事件
|
|
*/
|
|
void onPositiveClick();
|
|
|
|
/**
|
|
* 点击取消按钮事件
|
|
*/
|
|
// void onNegtiveClick();
|
|
}
|
|
|
|
public String getMessage() {
|
|
return message;
|
|
}
|
|
|
|
public SingleDialog setMessage(String message) {
|
|
this.message = message;
|
|
return this;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public SingleDialog setTitle(String title) {
|
|
this.title = title;
|
|
return this;
|
|
}
|
|
|
|
public String getPositive() {
|
|
return positive;
|
|
}
|
|
|
|
public SingleDialog setPositive(String positive) {
|
|
this.positive = positive;
|
|
return this;
|
|
}
|
|
|
|
public String getNegtive() {
|
|
return negtive;
|
|
}
|
|
|
|
public SingleDialog setNegtive(String negtive) {
|
|
this.negtive = negtive;
|
|
return this;
|
|
}
|
|
|
|
// public SingleDialog setNegtiveText(String negtive) {
|
|
// negtiveBn.setText(negtive);
|
|
// return this;
|
|
// }
|
|
|
|
public int getImageResId() {
|
|
return imageResId;
|
|
}
|
|
|
|
public boolean isSingle() {
|
|
return isSingle;
|
|
}
|
|
|
|
public SingleDialog setSingle(boolean single) {
|
|
isSingle = single;
|
|
return this;
|
|
}
|
|
|
|
public SingleDialog setImageResId(int imageResId) {
|
|
this.imageResId = imageResId;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void dismiss() {
|
|
super.dismiss();
|
|
}
|
|
}
|