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.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup.LayoutParams;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.entity.TaoBaoGoodsBrief;
|
|
import java.math.BigDecimal;
|
|
public class SaveImgDialog extends Dialog {
|
|
public SaveImgDialog(Context context) {
|
super(context);
|
}
|
|
public SaveImgDialog(Context context, int theme) {
|
super(context, theme);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
|
/**
|
* 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;
|
}
|
|
SaveImgDialog dialog;
|
|
public SaveImgDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
WindowManager wm = (WindowManager) context
|
.getSystemService(Context.WINDOW_SERVICE);
|
|
int width = wm.getDefaultDisplay().getWidth();
|
dialog = new SaveImgDialog(context,
|
R.style.Dialog);
|
|
View layout = inflater.inflate(R.layout.dialog_save_img, null);
|
dialog.addContentView(layout, new LayoutParams(
|
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
// set the cancel button
|
dialog.setContentView(layout);
|
|
TextView tv_cancel = layout.findViewById(R.id.tv_cancel);
|
TextView tv_save_img = layout.findViewById(R.id.tv_save_img);
|
|
if (negativeButtonClickListener != null) {
|
tv_cancel.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
|
}
|
});
|
}
|
if (positiveButtonClickListener != null) {
|
tv_save_img.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
|
}
|
});
|
}
|
|
WindowManager.LayoutParams params = dialog.getWindow()
|
.getAttributes();
|
params.gravity = Gravity.BOTTOM;
|
params.width = width;
|
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.getWindow().setWindowAnimations(R.style.bottomstyle);
|
|
dialog.setCanceledOnTouchOutside(true);
|
return dialog;
|
}
|
|
}
|
}
|