package com.haicaojie.android.util;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.text.Spannable;
|
import android.text.SpannableString;
|
import android.text.Spanned;
|
import android.text.style.RelativeSizeSpan;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import com.lcjian.library.util.SystemCommon;
|
import com.haicaojie.android.R;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class CouponHintDialog extends Dialog {
|
public CouponHintDialog(Context context) {
|
super(context);
|
}
|
|
public CouponHintDialog(Context context, int theme) {
|
super(context, theme);
|
}
|
|
public static class Builder {
|
private Context context;
|
private String receivestatus;
|
private String couponfrom;
|
private String deadline;
|
private String servicecondition;
|
private String money;
|
private String positiveButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private String negativeButtonText;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
|
public Builder setReveive(String receivestatus) {
|
this.receivestatus = receivestatus;
|
return this;
|
}
|
|
/**
|
* Set the Dialog title from String
|
*
|
* @param deadline
|
* @return
|
*/
|
|
public Builder setDeadline(String deadline) {
|
this.deadline = deadline;
|
return this;
|
}
|
|
public Builder setCoupon(String couponfrom) {
|
this.couponfrom = couponfrom;
|
return this;
|
}
|
|
public Builder setServiceCondition(String servicecondition) {
|
this.servicecondition = servicecondition;
|
return this;
|
}
|
|
|
public Builder setMoney(String money) {
|
this.money = money;
|
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 CouponHintDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final CouponHintDialog dialog = new CouponHintDialog(context, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.item_coupon_hint, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
ImageView iv_close = (ImageView) layout.findViewById(R.id.iv_close);
|
ImageView iv_doubt = (ImageView) layout.findViewById(R.id.iv_doubt);
|
TextView tv_coupon_from = (TextView) layout.findViewById(R.id.tv_coupon_from);
|
TextView tv_coupon_deadline = (TextView) layout.findViewById(R.id.tv_coupon_deadline);
|
TextView tv_service_condition = (TextView) layout.findViewById(R.id.tv_service_condition);
|
TextView tv_money = (TextView) layout.findViewById(R.id.tv_money);
|
TextView tv_confirm = (TextView) layout.findViewById(R.id.tv_confirm);
|
FrameLayout fl_refresh = (FrameLayout) layout.findViewById(R.id.fl_refresh);
|
tv_coupon_from.setText(couponfrom + "");
|
tv_coupon_deadline.setText(deadline + "");
|
tv_service_condition.setText(servicecondition);
|
if (receivestatus.contains("已经领取")) {
|
tv_confirm.setTextColor(context.getResources().getColor(R.color.gray));
|
tv_confirm.setText("已经领取了");
|
tv_confirm.setClickable(false);
|
} else {
|
tv_confirm.setTextColor(context.getResources().getColor(R.color.main_text_color));
|
tv_confirm.setText("确认领取");
|
tv_confirm.setClickable(true);
|
}
|
int count = money.indexOf(".");
|
Spannable span = new SpannableString(money);
|
span.setSpan(new RelativeSizeSpan(1.5f), 2, count <= 0 ? money.length() : count, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
tv_money.setText(span);
|
iv_doubt.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
|
}
|
});
|
fl_refresh.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
|
}
|
});
|
tv_confirm.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
|
}
|
});
|
// set the confirm button
|
if (positiveButtonText != null) {
|
if (positiveButtonClickListener != null) {
|
tv_confirm.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
}
|
if (negativeButtonText != null) {
|
if (negativeButtonClickListener != null) {
|
iv_close.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;
|
}
|
}
|
}
|