自定义dialog

时间:2018-12-02 13:30:11
【文件属性】:

文件名称:自定义dialog

文件大小:2KB

文件格式:JAVA

更新时间:2018-12-02 13:30:11

dialog

package com.zidiangyi.dialog; import com.zidinglyi_dialog.activity.R; import android.app.Dialog; import android.content.Context; import android.graphics.drawable.AnimationDrawable; import android.view.Gravity; import android.widget.ImageView; import android.widget.TextView; public class CentreProgressDialog extends Dialog { private Context context = null; private static CentreProgressDialog customProgressDialog = null; //1、 有一个参数的构造方法 public CentreProgressDialog(Context context){ super(context); this.context = context; } // 2、有两个参数的 构造方法 // 第一个参数是 上下文本 、第二个参数 dialog样式 public CentreProgressDialog(Context context, int theme) { super(context, theme); } //3、静态的方法 设置dialog的样式以及布局 public static CentreProgressDialog createDialog(Context context){ customProgressDialog = new CentreProgressDialog(context,R.style.CustomProgressDialog); customProgressDialog.setContentView(R.layout.centre_progressdialog); customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER; // 设置点击屏幕Dialog不消失 customProgressDialog.setCanceledOnTouchOutside(false); return customProgressDialog; } // 4、设置 dialog的加载动画 public void onWindowFocusChanged(boolean hasFocus){ if (customProgressDialog == null){ return; } ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView); AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground(); animationDrawable.start(); } //5、设置dialog的title public CentreProgressDialog setTitile(String strTitle){ return customProgressDialog; } // 6、设置dialog的提示语 public CentreProgressDialog setMessage(String strMessage){ TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.id_tv_loadingmsg); if (tvMsg != null){ tvMsg.setText(strMessage); } return customProgressDialog; } } package com.zidiangyi.dialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; import android.util.AttributeSet; //圆形图片实现类 public class CircularImage extends MaskedImage { public CircularImage(Context paramContext) { super(paramContext); } public CircularImage(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); } public CircularImage(Context paramContext, AttributeSet paramAttributeSet, int paramInt) { super(paramContext, paramAttributeSet, paramInt); } public Bitmap createMask() { int i = getWidth(); int j = getHeight(); Bitmap.Config localConfig = Bitmap.Config.ARGB_8888; Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig); Canvas localCanvas = new Canvas(localBitmap); Paint localPaint = new Paint(1); localPaint.setColor(-16777216); float f1 = getWidth(); float f2 = getHeight(); RectF localRectF = new RectF(0.0F, 0.0F, f1, f2); localCanvas.drawOval(localRectF, localPaint); return localBitmap; } } package com.zidiangyi.dialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Xfermode; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; /** 作者: 时间:2015年11月11日下午5:57:03 修改人: 类描述: 版本: 修改地址:*/ public abstract class MaskedImage extends ImageView{ private static final Xfermode MASK_XFERMODE; private Bitmap mask; private Paint paint; static { PorterDuff.Mode localMode = PorterDuff.Mode.DST_IN; MASK_XFERMODE = new PorterDuffXfermode(localMode); } public MaskedImage(Context paramContext) { super(paramContext); } public MaskedImage(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); } public MaskedImage(Context paramContext, AttributeSet paramAttributeSet, int paramInt) { super(paramContext, paramAttributeSet, paramInt); } public abstract Bitmap createMask(); protected void onDraw(Canvas paramCanvas) { Drawable localDrawable = getDrawable(); if (localDrawable == null) return; try { if (this.paint == null) { Paint localPaint1 = new Paint(); this.paint = localPaint1; this.paint.setFilterBitmap(false); Paint localPaint2 = this.paint; Xfermode localXfermode1 = MASK_XFERMODE; Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1); } float f1 = getWidth(); float f2 = getHeight(); int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31); int j = getWidth(); int k = getHeight(); localDrawable.setBounds(0, 0, j, k); localDrawable.draw(paramCanvas); if ((this.mask == null) || (this.mask.isRecycled())) { Bitmap localBitmap1 = createMask(); this.mask = localBitmap1; } Bitmap localBitmap2 = this.mask; Paint localPaint3 = this.paint; paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3); paramCanvas.restoreToCount(i); return; } catch (Exception localException) { StringBuilder localStringBuilder = new StringBuilder() .append("Attempting to draw with recycled bitmap. View ID = "); System.out.println("localStringBuilder=="+localStringBuilder); } } }


网友评论