package MyJar;
|
|
import android.content.Context;
|
import android.content.res.TypedArray;
|
import android.util.AttributeSet;
|
import android.view.View;
|
import android.widget.ImageView;
|
|
|
|
public class LoadingView extends ImageView {
|
private LoadingDrawable mLoadingDrawable;
|
|
public LoadingView(Context context,int ic_leaf,int ic_loading,int ic_eletric_fan) {
|
super(context);
|
setLoadingRenderer(new ElectricFanLoadingRenderer(context, ic_leaf, ic_loading, ic_eletric_fan));
|
}
|
|
public void setLoadingRenderer(LoadingRenderer loadingRenderer) {
|
mLoadingDrawable = new LoadingDrawable(loadingRenderer);
|
setImageDrawable(mLoadingDrawable);
|
}
|
|
@Override
|
protected void onAttachedToWindow() {
|
super.onAttachedToWindow();
|
startAnimation();
|
}
|
|
@Override
|
protected void onDetachedFromWindow() {
|
super.onDetachedFromWindow();
|
stopAnimation();
|
}
|
|
@Override
|
protected void onVisibilityChanged(View changedView, int visibility) {
|
super.onVisibilityChanged(changedView, visibility);
|
|
final boolean visible = visibility == VISIBLE && getVisibility() == VISIBLE;
|
if (visible) {
|
startAnimation();
|
} else {
|
stopAnimation();
|
}
|
}
|
|
private void startAnimation() {
|
if (mLoadingDrawable != null) {
|
mLoadingDrawable.start();
|
}
|
}
|
|
private void stopAnimation() {
|
if (mLoadingDrawable != null) {
|
mLoadingDrawable.stop();
|
}
|
}
|
}
|