package com.haicaojie.android.util;
|
|
import android.app.Dialog;
|
import android.content.ClipData;
|
import android.content.ClipboardManager;
|
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.bumptech.glide.Glide;
|
import com.haicaojie.android.R;
|
import com.lcjian.library.util.SystemCommon;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class CopyLinkDialog extends Dialog {
|
|
public CopyLinkDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public CopyLinkDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Context context;
|
String message;
|
String imgUrl;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(String message) {
|
this.message = message;
|
return this;
|
}
|
|
public Builder setImgUrl(String imgUrl) {
|
this.imgUrl = imgUrl;
|
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 CopyLinkDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final CopyLinkDialog dialog = new CopyLinkDialog(context, R.style.Dialog1);
|
View layout = inflater.inflate(R.layout.item_copy_link, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
TextView tv_goods_description = (TextView) layout.findViewById(R.id.tv_goods_description);
|
ImageView iv_goods_img = (ImageView) layout.findViewById(R.id.iv_goods_img);
|
tv_goods_description.setText(message);
|
Glide.with(context).load(imgUrl).placeholder(R.drawable.ic_goods_default).error(R.drawable.ic_goods_default).into(iv_goods_img);
|
// set the confirm button
|
final ClipboardManager clipboard =
|
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
if (positiveButtonClickListener != null) {
|
layout.findViewById(R.id.tv_login)
|
.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
clipboard.setPrimaryClip(ClipData.newPlainText("", ""));
|
}
|
});
|
}
|
if (negativeButtonClickListener != null) {
|
layout.findViewById(R.id.tv_close)
|
.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_NEGATIVE);
|
clipboard.setPrimaryClip(ClipData.newPlainText("", ""));
|
}
|
});
|
}
|
dialog.setContentView(layout);
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow()
|
.getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(context) * 19) / 20);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
}
|
}
|