package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Activity;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.graphics.drawable.Drawable;
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.transition.Transition;
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.widget.ResizableImageView;
|
import com.tejia.lijin.app.R;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class RedPacketHintDialog extends Dialog {
|
|
public RedPacketHintDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
|
public RedPacketHintDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Activity mContext;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
private String img;
|
|
public Builder(Activity context) {
|
this.mContext = context;
|
}
|
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @return
|
*/
|
public Builder setPositiveButton(
|
OnClickListener listener) {
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
|
public Builder setNegativeButton(OnClickListener listener) {
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder imgUrl(String img) {
|
this.img = img;
|
return this;
|
}
|
|
public RedPacketHintDialog create() {
|
LayoutInflater inflater = (LayoutInflater) mContext
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final RedPacketHintDialog dialog = new RedPacketHintDialog(mContext, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.dialog_1111_red_packet, null);
|
final ResizableImageView iv_img = layout.findViewById(R.id.iv_img);
|
final ImageView iv_close = layout.findViewById(R.id.iv_close);
|
Glide.with(mContext).load(img).into(new SimpleTarget<Drawable>() {
|
@Override
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
|
}
|
});
|
|
Glide.with(mContext).load(img).into(new SimpleTarget<Drawable>() {
|
@Override
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
iv_img.setImageDrawable(resource);
|
iv_close.setImageResource(R.drawable.ic_login_first_close);
|
dialog.show();
|
}
|
});
|
|
iv_close.setVisibility(View.VISIBLE);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
// set the confirm button
|
iv_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
dialog.dismiss();
|
}
|
});
|
if (positiveButtonClickListener != null) {
|
iv_img.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
}
|
});
|
}
|
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(mContext));
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
// dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
}
|
}
|