553 lines
18 KiB
Java
553 lines
18 KiB
Java
package com.google.android.material.floatingactionbutton;
|
|
|
|
import android.R;
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
import android.animation.AnimatorSet;
|
|
import android.animation.ObjectAnimator;
|
|
import android.animation.TimeInterpolator;
|
|
import android.animation.ValueAnimator;
|
|
import android.content.res.ColorStateList;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.Rect;
|
|
import android.graphics.RectF;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Build;
|
|
import android.util.Property;
|
|
import android.view.View;
|
|
import android.view.ViewTreeObserver;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import com.google.android.material.R$animator;
|
|
import com.google.android.material.animation.AnimationUtils;
|
|
import com.google.android.material.animation.AnimatorSetCompat;
|
|
import com.google.android.material.animation.ImageMatrixProperty;
|
|
import com.google.android.material.animation.MatrixEvaluator;
|
|
import com.google.android.material.animation.MotionSpec;
|
|
import com.google.android.material.internal.CircularBorderDrawable;
|
|
import com.google.android.material.internal.StateListAnimator;
|
|
import com.google.android.material.internal.VisibilityAwareImageButton;
|
|
import com.google.android.material.ripple.RippleUtils;
|
|
import com.google.android.material.shadow.ShadowDrawableWrapper;
|
|
import com.google.android.material.shadow.ShadowViewDelegate;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
|
|
/* loaded from: classes.dex */
|
|
class FloatingActionButtonImpl {
|
|
static final TimeInterpolator B = AnimationUtils.c;
|
|
static final int[] C = {R.attr.state_pressed, R.attr.state_enabled};
|
|
static final int[] D = {R.attr.state_hovered, R.attr.state_focused, R.attr.state_enabled};
|
|
static final int[] E = {R.attr.state_focused, R.attr.state_enabled};
|
|
static final int[] F = {R.attr.state_hovered, R.attr.state_enabled};
|
|
static final int[] G = {R.attr.state_enabled};
|
|
static final int[] H = new int[0];
|
|
private ViewTreeObserver.OnPreDrawListener A;
|
|
Animator b;
|
|
MotionSpec c;
|
|
MotionSpec d;
|
|
private MotionSpec e;
|
|
private MotionSpec f;
|
|
ShadowDrawableWrapper h;
|
|
private float i;
|
|
Drawable j;
|
|
Drawable k;
|
|
CircularBorderDrawable l;
|
|
Drawable m;
|
|
float n;
|
|
float o;
|
|
float p;
|
|
int q;
|
|
private ArrayList<Animator.AnimatorListener> s;
|
|
private ArrayList<Animator.AnimatorListener> t;
|
|
final VisibilityAwareImageButton u;
|
|
final ShadowViewDelegate v;
|
|
int a = 0;
|
|
float r = 1.0f;
|
|
private final Rect w = new Rect();
|
|
private final RectF x = new RectF();
|
|
private final RectF y = new RectF();
|
|
private final Matrix z = new Matrix();
|
|
private final StateListAnimator g = new StateListAnimator();
|
|
|
|
private class DisabledElevationAnimation extends ShadowAnimatorImpl {
|
|
DisabledElevationAnimation(FloatingActionButtonImpl floatingActionButtonImpl) {
|
|
super();
|
|
}
|
|
}
|
|
|
|
private class ElevateToHoveredFocusedTranslationZAnimation extends ShadowAnimatorImpl {
|
|
ElevateToHoveredFocusedTranslationZAnimation() {
|
|
super();
|
|
}
|
|
}
|
|
|
|
private class ElevateToPressedTranslationZAnimation extends ShadowAnimatorImpl {
|
|
ElevateToPressedTranslationZAnimation() {
|
|
super();
|
|
}
|
|
}
|
|
|
|
interface InternalVisibilityChangedListener {
|
|
void a();
|
|
|
|
void b();
|
|
}
|
|
|
|
private class ResetElevationAnimation extends ShadowAnimatorImpl {
|
|
ResetElevationAnimation() {
|
|
super();
|
|
}
|
|
}
|
|
|
|
private abstract class ShadowAnimatorImpl extends AnimatorListenerAdapter implements ValueAnimator.AnimatorUpdateListener {
|
|
private boolean a;
|
|
private float b;
|
|
private float c;
|
|
|
|
private ShadowAnimatorImpl() {
|
|
}
|
|
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationEnd(Animator animator) {
|
|
FloatingActionButtonImpl.this.h.b(this.c);
|
|
throw null;
|
|
}
|
|
|
|
@Override // android.animation.ValueAnimator.AnimatorUpdateListener
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
|
if (!this.a) {
|
|
FloatingActionButtonImpl.this.h.b();
|
|
throw null;
|
|
}
|
|
ShadowDrawableWrapper shadowDrawableWrapper = FloatingActionButtonImpl.this.h;
|
|
float f = this.b;
|
|
shadowDrawableWrapper.b(f + ((this.c - f) * valueAnimator.getAnimatedFraction()));
|
|
throw null;
|
|
}
|
|
}
|
|
|
|
FloatingActionButtonImpl(VisibilityAwareImageButton visibilityAwareImageButton, ShadowViewDelegate shadowViewDelegate) {
|
|
this.u = visibilityAwareImageButton;
|
|
this.v = shadowViewDelegate;
|
|
this.g.a(C, a((ShadowAnimatorImpl) new ElevateToPressedTranslationZAnimation()));
|
|
this.g.a(D, a((ShadowAnimatorImpl) new ElevateToHoveredFocusedTranslationZAnimation()));
|
|
this.g.a(E, a((ShadowAnimatorImpl) new ElevateToHoveredFocusedTranslationZAnimation()));
|
|
this.g.a(F, a((ShadowAnimatorImpl) new ElevateToHoveredFocusedTranslationZAnimation()));
|
|
this.g.a(G, a((ShadowAnimatorImpl) new ResetElevationAnimation()));
|
|
this.g.a(H, a((ShadowAnimatorImpl) new DisabledElevationAnimation(this)));
|
|
this.i = this.u.getRotation();
|
|
}
|
|
|
|
private void q() {
|
|
if (this.A == null) {
|
|
this.A = new ViewTreeObserver.OnPreDrawListener() { // from class: com.google.android.material.floatingactionbutton.FloatingActionButtonImpl.3
|
|
@Override // android.view.ViewTreeObserver.OnPreDrawListener
|
|
public boolean onPreDraw() {
|
|
FloatingActionButtonImpl.this.m();
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
private MotionSpec r() {
|
|
if (this.f == null) {
|
|
this.f = MotionSpec.a(this.u.getContext(), R$animator.design_fab_hide_motion_spec);
|
|
}
|
|
return this.f;
|
|
}
|
|
|
|
private MotionSpec s() {
|
|
if (this.e == null) {
|
|
this.e = MotionSpec.a(this.u.getContext(), R$animator.design_fab_show_motion_spec);
|
|
}
|
|
return this.e;
|
|
}
|
|
|
|
private boolean t() {
|
|
return ViewCompat.x(this.u) && !this.u.isInEditMode();
|
|
}
|
|
|
|
private void u() {
|
|
if (Build.VERSION.SDK_INT == 19) {
|
|
if (this.i % 90.0f != 0.0f) {
|
|
if (this.u.getLayerType() != 1) {
|
|
this.u.setLayerType(1, null);
|
|
}
|
|
} else if (this.u.getLayerType() != 0) {
|
|
this.u.setLayerType(0, null);
|
|
}
|
|
}
|
|
ShadowDrawableWrapper shadowDrawableWrapper = this.h;
|
|
if (shadowDrawableWrapper != null) {
|
|
shadowDrawableWrapper.a(-this.i);
|
|
throw null;
|
|
}
|
|
CircularBorderDrawable circularBorderDrawable = this.l;
|
|
if (circularBorderDrawable == null) {
|
|
return;
|
|
}
|
|
circularBorderDrawable.a(-this.i);
|
|
throw null;
|
|
}
|
|
|
|
void a(ColorStateList colorStateList) {
|
|
Drawable drawable = this.j;
|
|
if (drawable != null) {
|
|
DrawableCompat.a(drawable, colorStateList);
|
|
}
|
|
CircularBorderDrawable circularBorderDrawable = this.l;
|
|
if (circularBorderDrawable == null) {
|
|
return;
|
|
}
|
|
circularBorderDrawable.a(colorStateList);
|
|
throw null;
|
|
}
|
|
|
|
void b(ColorStateList colorStateList) {
|
|
Drawable drawable = this.k;
|
|
if (drawable != null) {
|
|
DrawableCompat.a(drawable, RippleUtils.a(colorStateList));
|
|
}
|
|
}
|
|
|
|
void b(Rect rect) {
|
|
}
|
|
|
|
final void c(float f) {
|
|
this.r = f;
|
|
Matrix matrix = this.z;
|
|
a(f, matrix);
|
|
this.u.setImageMatrix(matrix);
|
|
}
|
|
|
|
float d() {
|
|
return this.o;
|
|
}
|
|
|
|
float e() {
|
|
return this.p;
|
|
}
|
|
|
|
final MotionSpec f() {
|
|
return this.c;
|
|
}
|
|
|
|
boolean g() {
|
|
return this.u.getVisibility() == 0 ? this.a == 1 : this.a != 2;
|
|
}
|
|
|
|
boolean h() {
|
|
return this.u.getVisibility() != 0 ? this.a == 2 : this.a != 1;
|
|
}
|
|
|
|
void i() {
|
|
this.g.a();
|
|
}
|
|
|
|
void j() {
|
|
if (n()) {
|
|
q();
|
|
this.u.getViewTreeObserver().addOnPreDrawListener(this.A);
|
|
}
|
|
}
|
|
|
|
void k() {
|
|
}
|
|
|
|
void l() {
|
|
if (this.A != null) {
|
|
this.u.getViewTreeObserver().removeOnPreDrawListener(this.A);
|
|
this.A = null;
|
|
}
|
|
}
|
|
|
|
void m() {
|
|
float rotation = this.u.getRotation();
|
|
if (this.i != rotation) {
|
|
this.i = rotation;
|
|
u();
|
|
}
|
|
}
|
|
|
|
boolean n() {
|
|
return true;
|
|
}
|
|
|
|
final void o() {
|
|
c(this.r);
|
|
}
|
|
|
|
final void p() {
|
|
Rect rect = this.w;
|
|
a(rect);
|
|
b(rect);
|
|
this.v.a(rect.left, rect.top, rect.right, rect.bottom);
|
|
}
|
|
|
|
final void d(float f) {
|
|
if (this.p != f) {
|
|
this.p = f;
|
|
a(this.n, this.o, this.p);
|
|
}
|
|
}
|
|
|
|
float b() {
|
|
return this.n;
|
|
}
|
|
|
|
void a(PorterDuff.Mode mode) {
|
|
Drawable drawable = this.j;
|
|
if (drawable != null) {
|
|
DrawableCompat.a(drawable, mode);
|
|
}
|
|
}
|
|
|
|
final void b(float f) {
|
|
if (this.o != f) {
|
|
this.o = f;
|
|
a(this.n, this.o, this.p);
|
|
}
|
|
}
|
|
|
|
final MotionSpec c() {
|
|
return this.d;
|
|
}
|
|
|
|
void d(Animator.AnimatorListener animatorListener) {
|
|
ArrayList<Animator.AnimatorListener> arrayList = this.s;
|
|
if (arrayList == null) {
|
|
return;
|
|
}
|
|
arrayList.remove(animatorListener);
|
|
}
|
|
|
|
public void c(Animator.AnimatorListener animatorListener) {
|
|
ArrayList<Animator.AnimatorListener> arrayList = this.t;
|
|
if (arrayList == null) {
|
|
return;
|
|
}
|
|
arrayList.remove(animatorListener);
|
|
}
|
|
|
|
final void a(float f) {
|
|
if (this.n != f) {
|
|
this.n = f;
|
|
a(this.n, this.o, this.p);
|
|
}
|
|
}
|
|
|
|
final void b(MotionSpec motionSpec) {
|
|
this.c = motionSpec;
|
|
}
|
|
|
|
void b(Animator.AnimatorListener animatorListener) {
|
|
if (this.s == null) {
|
|
this.s = new ArrayList<>();
|
|
}
|
|
this.s.add(animatorListener);
|
|
}
|
|
|
|
private void a(float f, Matrix matrix) {
|
|
matrix.reset();
|
|
if (this.u.getDrawable() == null || this.q == 0) {
|
|
return;
|
|
}
|
|
RectF rectF = this.x;
|
|
RectF rectF2 = this.y;
|
|
rectF.set(0.0f, 0.0f, r0.getIntrinsicWidth(), r0.getIntrinsicHeight());
|
|
int i = this.q;
|
|
rectF2.set(0.0f, 0.0f, i, i);
|
|
matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.CENTER);
|
|
int i2 = this.q;
|
|
matrix.postScale(f, f, i2 / 2.0f, i2 / 2.0f);
|
|
}
|
|
|
|
void b(final InternalVisibilityChangedListener internalVisibilityChangedListener, final boolean z) {
|
|
if (h()) {
|
|
return;
|
|
}
|
|
Animator animator = this.b;
|
|
if (animator != null) {
|
|
animator.cancel();
|
|
}
|
|
if (t()) {
|
|
if (this.u.getVisibility() != 0) {
|
|
this.u.setAlpha(0.0f);
|
|
this.u.setScaleY(0.0f);
|
|
this.u.setScaleX(0.0f);
|
|
c(0.0f);
|
|
}
|
|
MotionSpec motionSpec = this.c;
|
|
if (motionSpec == null) {
|
|
motionSpec = s();
|
|
}
|
|
AnimatorSet a = a(motionSpec, 1.0f, 1.0f, 1.0f);
|
|
a.addListener(new AnimatorListenerAdapter() { // from class: com.google.android.material.floatingactionbutton.FloatingActionButtonImpl.2
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationEnd(Animator animator2) {
|
|
FloatingActionButtonImpl floatingActionButtonImpl = FloatingActionButtonImpl.this;
|
|
floatingActionButtonImpl.a = 0;
|
|
floatingActionButtonImpl.b = null;
|
|
InternalVisibilityChangedListener internalVisibilityChangedListener2 = internalVisibilityChangedListener;
|
|
if (internalVisibilityChangedListener2 != null) {
|
|
internalVisibilityChangedListener2.a();
|
|
}
|
|
}
|
|
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationStart(Animator animator2) {
|
|
FloatingActionButtonImpl.this.u.a(0, z);
|
|
FloatingActionButtonImpl floatingActionButtonImpl = FloatingActionButtonImpl.this;
|
|
floatingActionButtonImpl.a = 2;
|
|
floatingActionButtonImpl.b = animator2;
|
|
}
|
|
});
|
|
ArrayList<Animator.AnimatorListener> arrayList = this.s;
|
|
if (arrayList != null) {
|
|
Iterator<Animator.AnimatorListener> it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
a.addListener(it.next());
|
|
}
|
|
}
|
|
a.start();
|
|
return;
|
|
}
|
|
this.u.a(0, z);
|
|
this.u.setAlpha(1.0f);
|
|
this.u.setScaleY(1.0f);
|
|
this.u.setScaleX(1.0f);
|
|
c(1.0f);
|
|
if (internalVisibilityChangedListener != null) {
|
|
internalVisibilityChangedListener.a();
|
|
}
|
|
}
|
|
|
|
final void a(MotionSpec motionSpec) {
|
|
this.d = motionSpec;
|
|
}
|
|
|
|
void a(float f, float f2, float f3) {
|
|
ShadowDrawableWrapper shadowDrawableWrapper = this.h;
|
|
if (shadowDrawableWrapper == null) {
|
|
return;
|
|
}
|
|
shadowDrawableWrapper.a(f, this.p + f);
|
|
throw null;
|
|
}
|
|
|
|
void a(int[] iArr) {
|
|
this.g.a(iArr);
|
|
}
|
|
|
|
public void a(Animator.AnimatorListener animatorListener) {
|
|
if (this.t == null) {
|
|
this.t = new ArrayList<>();
|
|
}
|
|
this.t.add(animatorListener);
|
|
}
|
|
|
|
void a(final InternalVisibilityChangedListener internalVisibilityChangedListener, final boolean z) {
|
|
if (g()) {
|
|
return;
|
|
}
|
|
Animator animator = this.b;
|
|
if (animator != null) {
|
|
animator.cancel();
|
|
}
|
|
if (t()) {
|
|
MotionSpec motionSpec = this.d;
|
|
if (motionSpec == null) {
|
|
motionSpec = r();
|
|
}
|
|
AnimatorSet a = a(motionSpec, 0.0f, 0.0f, 0.0f);
|
|
a.addListener(new AnimatorListenerAdapter() { // from class: com.google.android.material.floatingactionbutton.FloatingActionButtonImpl.1
|
|
private boolean a;
|
|
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationCancel(Animator animator2) {
|
|
this.a = true;
|
|
}
|
|
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationEnd(Animator animator2) {
|
|
FloatingActionButtonImpl floatingActionButtonImpl = FloatingActionButtonImpl.this;
|
|
floatingActionButtonImpl.a = 0;
|
|
floatingActionButtonImpl.b = null;
|
|
if (this.a) {
|
|
return;
|
|
}
|
|
floatingActionButtonImpl.u.a(z ? 8 : 4, z);
|
|
InternalVisibilityChangedListener internalVisibilityChangedListener2 = internalVisibilityChangedListener;
|
|
if (internalVisibilityChangedListener2 != null) {
|
|
internalVisibilityChangedListener2.b();
|
|
}
|
|
}
|
|
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationStart(Animator animator2) {
|
|
FloatingActionButtonImpl.this.u.a(0, z);
|
|
FloatingActionButtonImpl floatingActionButtonImpl = FloatingActionButtonImpl.this;
|
|
floatingActionButtonImpl.a = 1;
|
|
floatingActionButtonImpl.b = animator2;
|
|
this.a = false;
|
|
}
|
|
});
|
|
ArrayList<Animator.AnimatorListener> arrayList = this.t;
|
|
if (arrayList != null) {
|
|
Iterator<Animator.AnimatorListener> it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
a.addListener(it.next());
|
|
}
|
|
}
|
|
a.start();
|
|
return;
|
|
}
|
|
this.u.a(z ? 8 : 4, z);
|
|
if (internalVisibilityChangedListener != null) {
|
|
internalVisibilityChangedListener.b();
|
|
}
|
|
}
|
|
|
|
private AnimatorSet a(MotionSpec motionSpec, float f, float f2, float f3) {
|
|
ArrayList arrayList = new ArrayList();
|
|
ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.u, (Property<VisibilityAwareImageButton, Float>) View.ALPHA, f);
|
|
motionSpec.a("opacity").a((Animator) ofFloat);
|
|
arrayList.add(ofFloat);
|
|
ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this.u, (Property<VisibilityAwareImageButton, Float>) View.SCALE_X, f2);
|
|
motionSpec.a("scale").a((Animator) ofFloat2);
|
|
arrayList.add(ofFloat2);
|
|
ObjectAnimator ofFloat3 = ObjectAnimator.ofFloat(this.u, (Property<VisibilityAwareImageButton, Float>) View.SCALE_Y, f2);
|
|
motionSpec.a("scale").a((Animator) ofFloat3);
|
|
arrayList.add(ofFloat3);
|
|
a(f3, this.z);
|
|
ObjectAnimator ofObject = ObjectAnimator.ofObject(this.u, new ImageMatrixProperty(), new MatrixEvaluator(), new Matrix(this.z));
|
|
motionSpec.a("iconScale").a((Animator) ofObject);
|
|
arrayList.add(ofObject);
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
AnimatorSetCompat.a(animatorSet, arrayList);
|
|
return animatorSet;
|
|
}
|
|
|
|
final Drawable a() {
|
|
return this.m;
|
|
}
|
|
|
|
void a(Rect rect) {
|
|
this.h.getPadding(rect);
|
|
throw null;
|
|
}
|
|
|
|
private ValueAnimator a(ShadowAnimatorImpl shadowAnimatorImpl) {
|
|
ValueAnimator valueAnimator = new ValueAnimator();
|
|
valueAnimator.setInterpolator(B);
|
|
valueAnimator.setDuration(100L);
|
|
valueAnimator.addListener(shadowAnimatorImpl);
|
|
valueAnimator.addUpdateListener(shadowAnimatorImpl);
|
|
valueAnimator.setFloatValues(0.0f, 1.0f);
|
|
return valueAnimator;
|
|
}
|
|
}
|