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.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.util.common.StringUtils;
|
import com.yeshi.ec.rebate.myapplication.R;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class BindDialog extends Dialog {
|
|
public BindDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
|
public BindDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private String message;
|
private int cancelColor = 0;
|
private int confirm = 0;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(String message) {
|
this.message = message;
|
return this;
|
}
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @param positiveButtonText
|
* @return
|
*/
|
public Builder setPositiveButton(int positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = (String) context
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setPositiveButtonColor(int color) {
|
confirm = color;
|
return this;
|
}
|
|
public Builder setPositiveButton(String positiveButtonText,
|
OnClickListener 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;
|
}
|
|
public Builder setNegativeButtonColor(int color) {
|
cancelColor = color;
|
return this;
|
}
|
|
public BindDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final BindDialog dialog = new BindDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.item_bind, null);
|
TextView tv_info = layout.findViewById(R.id.tv_info);
|
TextView tv_cancle = layout.findViewById(R.id.tv_cancle);
|
ImageView iv_close = layout.findViewById(R.id.iv_close);
|
iv_close.setVisibility(View.VISIBLE);
|
tv_info.setText(message);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
// set the confirm button
|
if (cancelColor > 0) {
|
tv_cancle.setBackgroundResource(R.drawable.shape_login_select);
|
tv_cancle.setTextColor(context.getResources().getColor(R.color.black));
|
}
|
if (positiveButtonClickListener != null) {
|
iv_close.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
if (negativeButtonClickListener != null) {
|
if (!StringUtils.isEmpty(negativeButtonText)) {
|
tv_cancle.setText(negativeButtonText);
|
}
|
tv_cancle.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_NEGATIVE);
|
}
|
});
|
}
|
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;
|
}
|
}
|
}
|