package com.example.august.customtheme;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomProgressDialog extends Dialog {
/**
* 从我们的布局文件loading_layout加载的View
*/
private View mContentView;
/**
* 我们的两个小空控件,显示图片和显示文字
*/
private ImageView mImageView;
private TextView mTextView;
/**
* 我们只去覆写指定主题的方法,并且我们就只有这么一个构造器
* @param context
* @param themeResId
* @param LayoutID
* @param imageViewID
* @param textViewID
*/
public CustomProgressDialog(Context context, int themeResId, int LayoutID, int imageViewID, int textViewID) {
super(context, themeResId);
mContentView = LayoutInflater.from(context).inflate(LayoutID, null);
mImageView = (ImageView) mContentView.findViewById(imageViewID);
/**
* 为图片设置一个旋转动画
*/
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new AccelerateInterpolator());
rotateAnimation.setDuration(1500);
rotateAnimation.setRepeatCount(-1);
mImageView.startAnimation(rotateAnimation);
mTextView = (TextView) mContentView.findViewById(textViewID);
setContentView(mContentView);
}
public void setMessage(String text) {
if (mTextView != null) {
mTextView.setText(text);
}
}
public void setProgressBitmap(Bitmap bitmap) {
if (mImageView != null) {
mImageView.setImageBitmap(bitmap);
}
}
}