package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.Gravity;
|
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.DimenUtils;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.R;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class UserTearcherNotifyDialog extends Dialog {
|
|
public UserTearcherNotifyDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public UserTearcherNotifyDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
|
public static class Builder {
|
public final static int TEXT_ALIGIN_LEFT = 1;
|
public final static int TEXT_ALIGIN_MIDDLE = 2;
|
public final static int TEXT_ALIGIN_RIGHT = 3;
|
|
private Context context;
|
String message;
|
String title;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
private OnClickListener closeButtonClickListener;
|
private int messageAligin = 1;//消息文本对齐,默认左对齐
|
private boolean messageBold = false;//消息文本是否粗,默认不加粗
|
private Float fontRate = 1.0f;//字体大小比例
|
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(String message) {
|
this.message = message;
|
return this;
|
}
|
|
public Builder setMessageTextAligin(int aligin) {
|
this.messageAligin = aligin;
|
return this;
|
}
|
|
public Builder setMessageBold(boolean bold) {
|
this.messageBold = bold;
|
return this;
|
}
|
|
public Builder setFontRate(float rate) {
|
this.fontRate = rate;
|
return this;
|
}
|
|
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,
|
OnClickListener listener) {
|
this.positiveButtonText = (String) context
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
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 setCloseButton(OnClickListener listener) {
|
this.closeButtonClickListener = listener;
|
return this;
|
}
|
|
public UserTearcherNotifyDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final UserTearcherNotifyDialog dialog = new UserTearcherNotifyDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.item_user_notify_dialog, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
TextView tv_title = layout.findViewById(R.id.tv_title);
|
TextView tv_content = layout.findViewById(R.id.tv_content);
|
TextView tv_confirm = layout.findViewById(R.id.tv_confirm);
|
FrameLayout fl_confirm = layout.findViewById(R.id.fl_confirm);
|
TextView tv_left = layout.findViewById(R.id.tv_left);
|
FrameLayout fl_left = layout.findViewById(R.id.fl_left);
|
ImageView iv_cancle = layout.findViewById(R.id.iv_cancle);
|
if (!StringUtils.isEmpty(title))
|
tv_title.setText(title);
|
if (!StringUtils.isEmpty(message)) {
|
tv_content.setText(message);
|
if (messageBold) {
|
tv_content.getPaint().setFakeBoldText(true);//设置粗体
|
}
|
switch (messageAligin) {
|
case TEXT_ALIGIN_LEFT:
|
tv_content.setGravity(Gravity.LEFT);
|
break;
|
case TEXT_ALIGIN_MIDDLE:
|
tv_content.setGravity(Gravity.CENTER_HORIZONTAL);
|
break;
|
case TEXT_ALIGIN_RIGHT:
|
tv_content.setGravity(Gravity.RIGHT);
|
break;
|
}
|
if (fontRate != null)
|
tv_content.setTextSize(DimenUtils.px2sp(context, tv_content.getTextSize() * fontRate));
|
}
|
// set the confirm button
|
if (positiveButtonClickListener != null) {
|
tv_confirm.setText(positiveButtonText);
|
fl_confirm.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
|
|
if (negativeButtonClickListener != null) {
|
tv_left.setText(negativeButtonText);
|
fl_left.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_NEGATIVE);
|
}
|
});
|
fl_left.setVisibility(View.VISIBLE);
|
} else {
|
fl_left.setVisibility(View.GONE);
|
}
|
|
if (closeButtonClickListener != null)
|
iv_cancle.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
closeButtonClickListener.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);
|
return dialog;
|
}
|
}
|
}
|