package com.haicaojie.android.util;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.EditText;
|
import android.widget.FrameLayout;
|
import android.widget.Toast;
|
|
import com.lcjian.library.util.SystemCommon;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.haicaojie.android.R;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class BindingDialog extends Dialog {
|
public BindingDialog(Context context) {
|
super(context);
|
}
|
|
public BindingDialog(Context context, int theme) {
|
super(context, theme);
|
}
|
|
public static class Builder {
|
private Context context;
|
private String title;
|
private String message;
|
private String positiveButtonText;
|
private DialogInterface.OnClickListener positiveButtonClickListener;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(String message) {
|
this.message = message;
|
return this;
|
}
|
|
/**
|
* Set the Dialog message from resource
|
*
|
* @return
|
*/
|
public Builder setMessage(int message) {
|
this.message = (String) context.getText(message);
|
return this;
|
}
|
|
/**
|
* Set the Dialog title from resource
|
*
|
* @param title
|
* @return
|
*/
|
public Builder setTitle(int title) {
|
this.title = (String) context.getText(title);
|
return this;
|
}
|
|
public String account;
|
public String name;
|
|
/**
|
* Set the Dialog title from String
|
*
|
* @param title
|
* @return
|
*/
|
|
public Builder setTitle(String title) {
|
this.title = title;
|
return this;
|
}
|
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @param positiveButtonText
|
* @return
|
*/
|
public Builder setPositiveButton(int positiveButtonText,
|
DialogInterface.OnClickListener listener) {
|
this.positiveButtonText = (String) context
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setPositiveButton(String positiveButtonText,
|
DialogInterface.OnClickListener listener) {
|
this.positiveButtonText = positiveButtonText;
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public BindingDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final BindingDialog dialog = new BindingDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.item_dialog_withdraw1, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
// set the confirm button
|
final EditText et_account = (EditText) layout.findViewById(R.id.et_binding_account);
|
final EditText et_name = (EditText) layout.findViewById(R.id.et_real_name);
|
if (positiveButtonText != null) {
|
if (positiveButtonClickListener != null) {
|
layout.findViewById(R.id.tv_next)
|
.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
account = et_account.getText().toString();
|
name = et_name.getText().toString();
|
if (StringUtils.isEmpty(account) || StringUtils.isEmpty(name)) {
|
Toast.makeText(context, "账号或收款人姓名不能为空!", Toast.LENGTH_LONG).show();
|
return;
|
}
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
}
|
dialog.setContentView(layout);
|
|
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(false);
|
return dialog;
|
}
|
}
|
}
|