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.graphics.Color;
|
import android.text.method.LinkMovementMethod;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
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.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.util.ui.TextViewUtil;
|
|
/**
|
* 用户协议弹框
|
*/
|
public class MultiImageDownloadDialog extends Dialog {
|
|
private static String TAG = "UserProtocolDialog";
|
|
public MultiImageDownloadDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public MultiImageDownloadDialog(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 int downloadCount = 8;
|
private int totalCount = 9;
|
|
private Activity context;
|
String title;
|
|
public Builder setTotalCount(int count) {
|
this.totalCount = count;
|
return this;
|
}
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setData(String data) {
|
return this;
|
}
|
|
ImageView iv_progress_bg;
|
ImageView iv_progress;
|
ImageView iv_percent_top;
|
View ll_percent;
|
TextView tv_percent;
|
TextView tv_progress_desc;
|
|
|
public MultiImageDownloadDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
final MultiImageDownloadDialog dialog = new MultiImageDownloadDialog(context, R.style.Dialog);
|
final View layout = inflater.inflate(R.layout.dialog_img_download_progress, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
dialog.setContentView(layout);
|
iv_progress_bg = layout.findViewById(R.id.iv_progress_bg);
|
iv_progress = layout.findViewById(R.id.iv_progress);
|
iv_percent_top = layout.findViewById(R.id.iv_percent_top);
|
ll_percent = layout.findViewById(R.id.ll_percent);
|
tv_percent = layout.findViewById(R.id.tv_percent);
|
tv_progress_desc = layout.findViewById(R.id.tv_progress_desc);
|
//初始化进度
|
setDownloadCount(0);
|
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;
|
}
|
|
|
public void setDownloadCount(int count) {
|
int totalWidth = iv_progress_bg.getMeasuredWidth();
|
int percentWidth = count * totalWidth / totalCount;
|
if (percentWidth > totalWidth)
|
percentWidth = totalWidth;
|
//设置值
|
ViewGroup.LayoutParams params1 = iv_progress.getLayoutParams();
|
params1.width = percentWidth;
|
iv_progress.setLayoutParams(params1);
|
tv_percent.setText(count * 100 / totalCount + "%");
|
tv_progress_desc.setText(String.format("已下载%s/%s张图片,请稍后...", count, totalCount));
|
//设置偏移量
|
|
ViewGroup.MarginLayoutParams param2 = (ViewGroup.MarginLayoutParams) iv_percent_top.getLayoutParams();
|
ViewGroup.MarginLayoutParams param3 = (ViewGroup.MarginLayoutParams) tv_percent.getLayoutParams();
|
ViewGroup.MarginLayoutParams param4 = (ViewGroup.MarginLayoutParams) ll_percent.getLayoutParams();
|
if (percentWidth > 0)
|
param4.leftMargin = percentWidth - (param2.leftMargin - param3.leftMargin);
|
else
|
param4.leftMargin = DimenUtils.dip2px(context, 10);
|
ll_percent.requestLayout();
|
}
|
}
|
|
public interface MeasureCallBack {
|
public void onMeasure(int height);
|
}
|
}
|