mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-16 10:57:17 +01:00
155 lines
5.6 KiB
Java
155 lines
5.6 KiB
Java
package androidx.constraintlayout.utils.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Outline;
|
|
import android.graphics.Path;
|
|
import android.graphics.RectF;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.view.ViewOutlineProvider;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.appcompat.widget.AppCompatButton;
|
|
import androidx.constraintlayout.widget.R;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes13.dex */
|
|
public class MotionButton extends AppCompatButton {
|
|
private Path mPath;
|
|
RectF mRect;
|
|
private float mRound;
|
|
private float mRoundPercent;
|
|
ViewOutlineProvider mViewOutlineProvider;
|
|
|
|
public MotionButton(Context context) {
|
|
super(context);
|
|
this.mRoundPercent = 0.0f;
|
|
this.mRound = Float.NaN;
|
|
init(context, null);
|
|
}
|
|
|
|
private void init(Context context, AttributeSet attributeSet) {
|
|
setPadding(0, 0, 0, 0);
|
|
if (attributeSet != null) {
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.ImageFilterView);
|
|
int indexCount = obtainStyledAttributes.getIndexCount();
|
|
for (int i = 0; i < indexCount; i++) {
|
|
int index = obtainStyledAttributes.getIndex(i);
|
|
if (index == R.styleable.ImageFilterView_round) {
|
|
setRound(obtainStyledAttributes.getDimension(index, 0.0f));
|
|
} else if (index == R.styleable.ImageFilterView_roundPercent) {
|
|
setRoundPercent(obtainStyledAttributes.getFloat(index, 0.0f));
|
|
}
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void draw(@NonNull Canvas canvas) {
|
|
super.draw(canvas);
|
|
}
|
|
|
|
public float getRound() {
|
|
return this.mRound;
|
|
}
|
|
|
|
public float getRoundPercent() {
|
|
return this.mRoundPercent;
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public void setRound(float f) {
|
|
if (Float.isNaN(f)) {
|
|
this.mRound = f;
|
|
float f2 = this.mRoundPercent;
|
|
this.mRoundPercent = -1.0f;
|
|
setRoundPercent(f2);
|
|
return;
|
|
}
|
|
boolean z = this.mRound != f;
|
|
this.mRound = f;
|
|
if (f != 0.0f) {
|
|
if (this.mPath == null) {
|
|
this.mPath = new Path();
|
|
}
|
|
if (this.mRect == null) {
|
|
this.mRect = new RectF();
|
|
}
|
|
if (this.mViewOutlineProvider == null) {
|
|
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() { // from class: androidx.constraintlayout.utils.widget.MotionButton.2
|
|
@Override // android.view.ViewOutlineProvider
|
|
public void getOutline(View view, Outline outline) {
|
|
outline.setRoundRect(0, 0, MotionButton.this.getWidth(), MotionButton.this.getHeight(), MotionButton.this.mRound);
|
|
}
|
|
};
|
|
this.mViewOutlineProvider = viewOutlineProvider;
|
|
setOutlineProvider(viewOutlineProvider);
|
|
}
|
|
setClipToOutline(true);
|
|
this.mRect.set(0.0f, 0.0f, getWidth(), getHeight());
|
|
this.mPath.reset();
|
|
Path path = this.mPath;
|
|
RectF rectF = this.mRect;
|
|
float f3 = this.mRound;
|
|
path.addRoundRect(rectF, f3, f3, Path.Direction.CW);
|
|
} else {
|
|
setClipToOutline(false);
|
|
}
|
|
if (z) {
|
|
invalidateOutline();
|
|
}
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public void setRoundPercent(float f) {
|
|
boolean z = this.mRoundPercent != f;
|
|
this.mRoundPercent = f;
|
|
if (f != 0.0f) {
|
|
if (this.mPath == null) {
|
|
this.mPath = new Path();
|
|
}
|
|
if (this.mRect == null) {
|
|
this.mRect = new RectF();
|
|
}
|
|
if (this.mViewOutlineProvider == null) {
|
|
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() { // from class: androidx.constraintlayout.utils.widget.MotionButton.1
|
|
@Override // android.view.ViewOutlineProvider
|
|
public void getOutline(View view, Outline outline) {
|
|
outline.setRoundRect(0, 0, MotionButton.this.getWidth(), MotionButton.this.getHeight(), (MotionButton.this.mRoundPercent * Math.min(r3, r4)) / 2.0f);
|
|
}
|
|
};
|
|
this.mViewOutlineProvider = viewOutlineProvider;
|
|
setOutlineProvider(viewOutlineProvider);
|
|
}
|
|
setClipToOutline(true);
|
|
int width = getWidth();
|
|
int height = getHeight();
|
|
float min = (Math.min(width, height) * this.mRoundPercent) / 2.0f;
|
|
this.mRect.set(0.0f, 0.0f, width, height);
|
|
this.mPath.reset();
|
|
this.mPath.addRoundRect(this.mRect, min, min, Path.Direction.CW);
|
|
} else {
|
|
setClipToOutline(false);
|
|
}
|
|
if (z) {
|
|
invalidateOutline();
|
|
}
|
|
}
|
|
|
|
public MotionButton(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.mRoundPercent = 0.0f;
|
|
this.mRound = Float.NaN;
|
|
init(context, attributeSet);
|
|
}
|
|
|
|
public MotionButton(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.mRoundPercent = 0.0f;
|
|
this.mRound = Float.NaN;
|
|
init(context, attributeSet);
|
|
}
|
|
}
|