129 lines
5.2 KiB
Java
129 lines
5.2 KiB
Java
package androidx.swiperefreshlayout.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.RadialGradient;
|
|
import android.graphics.Shader;
|
|
import android.graphics.drawable.ShapeDrawable;
|
|
import android.graphics.drawable.shapes.OvalShape;
|
|
import android.view.animation.Animation;
|
|
import android.widget.ImageView;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.swiperefreshlayout.R;
|
|
public class CircleImageView extends ImageView {
|
|
private static final int DEFAULT_BACKGROUND_COLOR = -328966;
|
|
private static final int FILL_SHADOW_COLOR = 1023410176;
|
|
private static final int KEY_SHADOW_COLOR = 503316480;
|
|
private static final int SHADOW_ELEVATION = 4;
|
|
private static final float SHADOW_RADIUS = 3.5f;
|
|
private static final float X_OFFSET = 0.0f;
|
|
private static final float Y_OFFSET = 1.75f;
|
|
private int mBackgroundColor;
|
|
private Animation.AnimationListener mListener;
|
|
private int mShadowRadius;
|
|
|
|
public static class OvalShadow extends OvalShape {
|
|
private CircleImageView mCircleImageView;
|
|
private Paint mShadowPaint = new Paint();
|
|
private int mShadowRadius;
|
|
|
|
public OvalShadow(CircleImageView circleImageView, int i) {
|
|
this.mCircleImageView = circleImageView;
|
|
this.mShadowRadius = i;
|
|
updateRadialGradient((int) rect().width());
|
|
}
|
|
|
|
private void updateRadialGradient(int i) {
|
|
float f = (float) (i / 2);
|
|
this.mShadowPaint.setShader(new RadialGradient(f, f, (float) this.mShadowRadius, new int[]{1023410176, 0}, (float[]) null, Shader.TileMode.CLAMP));
|
|
}
|
|
|
|
@Override // android.graphics.drawable.shapes.OvalShape, android.graphics.drawable.shapes.Shape, android.graphics.drawable.shapes.RectShape
|
|
public void draw(Canvas canvas, Paint paint) {
|
|
int width = this.mCircleImageView.getWidth() / 2;
|
|
float f = (float) width;
|
|
float height = (float) (this.mCircleImageView.getHeight() / 2);
|
|
canvas.drawCircle(f, height, f, this.mShadowPaint);
|
|
canvas.drawCircle(f, height, (float) (width - this.mShadowRadius), paint);
|
|
}
|
|
|
|
@Override // android.graphics.drawable.shapes.Shape, android.graphics.drawable.shapes.RectShape
|
|
public void onResize(float f, float f2) {
|
|
super.onResize(f, f2);
|
|
updateRadialGradient((int) f);
|
|
}
|
|
}
|
|
|
|
public CircleImageView(Context context) {
|
|
super(context);
|
|
ShapeDrawable shapeDrawable;
|
|
float f = getContext().getResources().getDisplayMetrics().density;
|
|
int i = (int) (1.75f * f);
|
|
int i2 = (int) (0.0f * f);
|
|
this.mShadowRadius = (int) (3.5f * f);
|
|
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(R.styleable.SwipeRefreshLayout);
|
|
this.mBackgroundColor = obtainStyledAttributes.getColor(R.styleable.SwipeRefreshLayout_swipeRefreshLayoutProgressSpinnerBackgroundColor, -328966);
|
|
obtainStyledAttributes.recycle();
|
|
if (elevationSupported()) {
|
|
shapeDrawable = new ShapeDrawable(new OvalShape());
|
|
ViewCompat.setElevation(this, f * 4.0f);
|
|
} else {
|
|
ShapeDrawable shapeDrawable2 = new ShapeDrawable(new OvalShadow(this, this.mShadowRadius));
|
|
setLayerType(1, shapeDrawable2.getPaint());
|
|
shapeDrawable2.getPaint().setShadowLayer((float) this.mShadowRadius, (float) i2, (float) i, 503316480);
|
|
int i3 = this.mShadowRadius;
|
|
setPadding(i3, i3, i3, i3);
|
|
shapeDrawable = shapeDrawable2;
|
|
}
|
|
shapeDrawable.getPaint().setColor(this.mBackgroundColor);
|
|
ViewCompat.setBackground(this, shapeDrawable);
|
|
}
|
|
|
|
private boolean elevationSupported() {
|
|
return true;
|
|
}
|
|
|
|
public int getBackgroundColor() {
|
|
return this.mBackgroundColor;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onAnimationEnd() {
|
|
super.onAnimationEnd();
|
|
Animation.AnimationListener animationListener = this.mListener;
|
|
if (animationListener != null) {
|
|
animationListener.onAnimationEnd(getAnimation());
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onAnimationStart() {
|
|
super.onAnimationStart();
|
|
Animation.AnimationListener animationListener = this.mListener;
|
|
if (animationListener != null) {
|
|
animationListener.onAnimationStart(getAnimation());
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.ImageView, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
if (!elevationSupported()) {
|
|
setMeasuredDimension((this.mShadowRadius * 2) + getMeasuredWidth(), (this.mShadowRadius * 2) + getMeasuredHeight());
|
|
}
|
|
}
|
|
|
|
public void setAnimationListener(Animation.AnimationListener animationListener) {
|
|
this.mListener = animationListener;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setBackgroundColor(int i) {
|
|
if (getBackground() instanceof ShapeDrawable) {
|
|
((ShapeDrawable) getBackground()).getPaint().setColor(i);
|
|
this.mBackgroundColor = i;
|
|
}
|
|
}
|
|
}
|