package com.dayu.qiheonlinelibrary.view;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.text.Editable;
|
import android.text.TextUtils;
|
import android.text.TextWatcher;
|
import android.view.Gravity;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.view.WindowManager;
|
import android.widget.EditText;
|
import android.widget.TextView;
|
|
import com.dayu.baselibrary.utils.TipUtil;
|
import com.dayu.baselibrary.view.EdtDialog;
|
import com.dayu.qiheonlinelibrary.R;
|
|
/**
|
* author: zuo
|
* Date: 2024-08-09
|
* Time: 14:52
|
* 备注:补卡工本费
|
*/
|
public class ReplacementPriceDialog extends Dialog {
|
|
Intent intent;
|
Context mContext;
|
DialogBack mDialogBack;
|
|
String mTitle;
|
|
|
public ReplacementPriceDialog(Context context, DialogBack dialogBack) {
|
super(context, com.dayu.baselibrary.R.style.ws_pay_showSelfDialog);
|
mContext = context;
|
mDialogBack = dialogBack;
|
initView();
|
}
|
|
|
private void initView() {
|
getWindow().setGravity(Gravity.CENTER);
|
setContentView(R.layout.dialog_replace_price);
|
setCanceledOnTouchOutside(false);
|
TextView textView = (TextView) this.findViewById(com.dayu.baselibrary.R.id.pw_ok);
|
EditText editText = (EditText) this.findViewById(com.dayu.baselibrary.R.id.pw_et);
|
setPricePoint(editText);
|
TextView title = this.findViewById(com.dayu.baselibrary.R.id.title);
|
if (!TextUtils.isEmpty(mTitle)) {
|
title.setVisibility(View.VISIBLE);
|
title.setText(mTitle);
|
}
|
textView.setOnClickListener(v -> {
|
String data = editText.getText().toString();
|
if (TextUtils.isEmpty(data)) {
|
TipUtil.show("请输入工本费");
|
} else {
|
if (mDialogBack != null) {
|
mDialogBack.onOk(data);
|
}
|
}
|
|
});
|
// 设置 OnKeyListener 拦截返回键事件
|
setOnKeyListener((dialog, keyCode, event) -> {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
// 拦截返回键事件,返回 true
|
return true;
|
}
|
return false;
|
});
|
}
|
|
@Override
|
public void show() {
|
|
super.show();
|
/**
|
* 设置宽度全屏,要设置在show的后面
|
*/
|
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
|
layoutParams.gravity = Gravity.CENTER;
|
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
getWindow().getDecorView().setPadding(0, 0, 0, 0);
|
getWindow().setAttributes(layoutParams);
|
}
|
|
public interface DialogBack {
|
void onOk(String data);
|
}
|
|
|
//校验金额
|
public void setPricePoint(final EditText editText) {
|
editText.addTextChangedListener(new TextWatcher() {
|
@Override
|
public void onTextChanged(CharSequence s, int start, int before,
|
int count) {
|
if (s.toString().contains(".")) {
|
if (s.length() - 1 - s.toString().indexOf(".") > 2) {
|
s = s.toString().subSequence(0,
|
s.toString().indexOf(".") + 3);
|
editText.setText(s);
|
editText.setSelection(s.length());
|
}
|
}
|
if (s.toString().trim().substring(0).equals(".")) {
|
s = "0" + s;
|
editText.setText(s);
|
editText.setSelection(2);
|
}
|
|
if (s.toString().startsWith("0")
|
&& s.toString().trim().length() > 1) {
|
if (!s.toString().substring(1, 2).equals(".")) {
|
editText.setText(s.subSequence(0, 1));
|
editText.setSelection(1);
|
}
|
}
|
String morny = editText.getText().toString();
|
if (!TextUtils.isEmpty(morny)) {
|
// rechageWater = MornyUtil.intDiv(MornyUtil.changeY2F(editText.getText().toString()), waterPrice);
|
// binding.redRechargeWater.setText("充值水量:" + rechageWater + " 立方米(吨)");
|
}
|
|
|
}
|
|
@Override
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
int after) {
|
|
}
|
|
@Override
|
public void afterTextChanged(Editable s) {
|
// TODO Auto-generated method stub
|
|
}
|
|
});
|
|
}
|
}
|