You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.2 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.rehome.sgbaxj.weight;
/**
* Create By HuangWenFei
* 创建日期2023-07-25 14:39
* 描述:免检提交对话框
*/
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.rehome.sgbaxj.R;
/**
* Created by Administrator on 2018/1/31.
*/
public class MjEditDialog extends Dialog {
private Button yes, no;//确定按钮
private TextView titleTv;//消息标题文本
private EditText et_phone;//输入电话
private String titleStr;//从外界设置的title文本
private String messageStr;//从外界设置的消息文本
//确定文本和取消文本的显示内容
private String yesStr, noStr;
private DialogListener listener;//取消,确定按钮被点击了的监听器
public MjEditDialog(Context context, DialogListener listener) {
super(context, R.style.Dialog_Msg);
this.listener = listener;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_mj_edit);
//按空白处不能取消动画
setCanceledOnTouchOutside(false);
//初始化界面控件
initView();
//初始化界面数据
initData();
//初始化界面控件的事件
initEvent();
}
/**
* 初始化界面的确定和取消监听器
*/
private void initEvent() {
//设置确定按钮被点击后,向外界提供监听
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//dismiss();
if (listener != null) {
if (TextUtils.isEmpty(et_phone.getText().toString().trim())) {
et_phone.setError("免检原因必填");
listener.onYesClick("");
} else {
dismiss();
listener.onYesClick(et_phone.getText().toString().trim());
}
}
}
});
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (listener != null) {
listener.onNoClick();
}
}
});
}
/**
* 初始化界面控件的显示数据
*/
private void initData() {
//如果用户自定了title和message
if (titleStr != null) {
titleTv.setText(titleStr);
}
if (messageStr != null) {
et_phone.setText(messageStr);
}
//如果设置按钮的文字
if (yesStr != null) {
yes.setText(yesStr);
}
}
/**
* 初始化界面控件
*/
private void initView() {
yes = (Button) findViewById(R.id.yes);
no = (Button) findViewById(R.id.no);
titleTv = (TextView) findViewById(R.id.title);
et_phone = (EditText) findViewById(R.id.et_phone);
}
/**
* 从外界Activity为Dialog设置标题
*
* @param title
*/
public void setTitle(String title) {
titleStr = title;
}
/**
* 从外界Activity为Dialog设置dialog的message
*
* @param message
*/
public void setMessage(String message) {
messageStr = message;
}
/**
* 设置确定按钮和取消被点击的接口
*/
public interface DialogListener {
public void onYesClick(String noCheckReason);
public void onNoClick();
}
@Override
public void show() {
super.show();
/**
* 设置宽度全屏要设置在show的后面
*/
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
getWindow().getDecorView().setPadding(0, 0, 0, 0);
getWindow().setAttributes(layoutParams);
}
}