package com.yeshi.ec.rebate.myapplication.ui.dialog;
|
|
import android.app.Activity;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup.LayoutParams;
|
import android.widget.EditText;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.util.common.StringUtils;
|
import com.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.callBack.GeneralBackCallback;
|
import com.yeshi.ec.rebate.myapplication.util.MoneyTextWatcher;
|
import com.yeshi.ec.rebate.myapplication.util.ToolUtil;
|
|
public class GiveRedpacketDialog extends Dialog {
|
|
public GiveRedpacketDialog(Context context) {
|
super(context);
|
}
|
|
public GiveRedpacketDialog(Context context, int theme) {
|
super(context, theme);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private String message;
|
private String title;
|
private String balance;
|
private String giveMin = "";
|
private String giveMax = "";
|
private String hint = "";
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private GeneralBackCallback positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(String message) {
|
this.message = message;
|
return this;
|
}
|
|
public Builder setTitle(String title) {
|
this.title = title;
|
return this;
|
}
|
|
public Builder setBalance(String balance) {
|
this.balance = balance;
|
return this;
|
}
|
|
public Builder setGiveMin(String giveMin) {
|
this.giveMin = giveMin;
|
return this;
|
}
|
|
public Builder setGiveMax(String giveMax) {
|
this.giveMax = giveMax;
|
return this;
|
}
|
|
public Builder setHint(String hint) {
|
this.hint = hint;
|
return this;
|
}
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @param positiveButtonText
|
* @return
|
*/
|
public Builder setPositiveButton(int positiveButtonText,
|
GeneralBackCallback listener) {
|
this.positiveButtonText = (String) context
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setPositiveButton(String positiveButtonText,
|
GeneralBackCallback listener) {
|
this.positiveButtonText = positiveButtonText;
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(int negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = (String) context
|
.getText(negativeButtonText);
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(String negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = negativeButtonText;
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
GiveRedpacketDialog dialog;
|
Double num = 0.0;
|
|
public GiveRedpacketDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
dialog = new GiveRedpacketDialog(context, R.style.Dialog);
|
|
View layout = inflater.inflate(R.layout.dialog_give_redpacket, null);
|
dialog.addContentView(layout, new LayoutParams(
|
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
// set the cancel button
|
dialog.setContentView(layout);
|
|
TextView tv_title = layout.findViewById(R.id.tv_title);
|
TextView tv_confirm = layout.findViewById(R.id.tv_confirm);//确认
|
final LinearLayout tv_numbg = layout.findViewById(R.id.tv_numbg);
|
final EditText tv_num = layout.findViewById(R.id.tv_num);//金额输入框
|
TextView tv_desc = layout.findViewById(R.id.tv_desc);//提示
|
// final ImageView iv_num_addition = layout.findViewById(R.id.iv_num_addition);
|
tv_title.setText(title);
|
tv_desc.setText(message);
|
ToolUtil.setShape_bg(context, 8, "#fff3f3f3", tv_numbg);
|
//默认两位小数 最大金额 提示语
|
tv_num.addTextChangedListener(new MoneyTextWatcher(tv_num));
|
if (positiveButtonClickListener != null) {
|
tv_confirm.setText(positiveButtonText);
|
tv_confirm.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
String confirm = tv_num.getText().toString();
|
if (!StringUtils.isEmpty(confirm)) {
|
num = Double.valueOf(confirm);
|
}
|
if (num > 0) {
|
if (!StringUtils.isEmpty(giveMin) && num < Integer.valueOf(giveMin)) {
|
tv_num.setText("");
|
Toast.makeText(context, hint, Toast.LENGTH_LONG).show();
|
} else if (!StringUtils.isEmpty(giveMax) && num > Integer.valueOf(giveMax)) {
|
tv_num.setText("");
|
Toast.makeText(context, hint, Toast.LENGTH_LONG).show();
|
} else {
|
positiveButtonClickListener.onSuccess((DialogInterface) dialog, num);
|
}
|
} else
|
Toast.makeText(context, "请输入金额", Toast.LENGTH_LONG).show();
|
}
|
});
|
}
|
|
layout.findViewById(R.id.iv_cancle)
|
.
|
|
setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
dialog.dismiss();
|
}
|
});
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow()
|
.getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(context) * 3) / 4);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().
|
|
setAttributes(params);
|
|
dialog.setCanceledOnTouchOutside(true);
|
return dialog;
|
}
|
}
|
}
|