ADD week 5
This commit is contained in:
		| @@ -0,0 +1,133 @@ | ||||
| package com.google.android.material.floatingactionbutton; | ||||
|  | ||||
| import android.animation.Animator; | ||||
| import android.animation.AnimatorSet; | ||||
| import android.content.Context; | ||||
| import android.content.res.ColorStateList; | ||||
| import android.graphics.Color; | ||||
| import android.util.Property; | ||||
| import android.view.View; | ||||
| import androidx.core.util.Preconditions; | ||||
| import com.google.android.material.animation.AnimationUtils; | ||||
| import com.google.android.material.animation.AnimatorSetCompat; | ||||
| import com.google.android.material.animation.MotionSpec; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| abstract class BaseMotionStrategy implements MotionStrategy { | ||||
|     private final Context context; | ||||
|     private MotionSpec defaultMotionSpec; | ||||
|     private final ExtendedFloatingActionButton fab; | ||||
|     private final ArrayList<Animator.AnimatorListener> listeners = new ArrayList<>(); | ||||
|     private MotionSpec motionSpec; | ||||
|     private final AnimatorTracker tracker; | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public final List<Animator.AnimatorListener> getListeners() { | ||||
|         return this.listeners; | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public MotionSpec getMotionSpec() { | ||||
|         return this.motionSpec; | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public final void setMotionSpec(MotionSpec motionSpec) { | ||||
|         this.motionSpec = motionSpec; | ||||
|     } | ||||
|  | ||||
|     BaseMotionStrategy(ExtendedFloatingActionButton extendedFloatingActionButton, AnimatorTracker animatorTracker) { | ||||
|         this.fab = extendedFloatingActionButton; | ||||
|         this.context = extendedFloatingActionButton.getContext(); | ||||
|         this.tracker = animatorTracker; | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public final MotionSpec getCurrentMotionSpec() { | ||||
|         MotionSpec motionSpec = this.motionSpec; | ||||
|         if (motionSpec != null) { | ||||
|             return motionSpec; | ||||
|         } | ||||
|         if (this.defaultMotionSpec == null) { | ||||
|             this.defaultMotionSpec = MotionSpec.createFromResource(this.context, getDefaultMotionSpecResource()); | ||||
|         } | ||||
|         return (MotionSpec) Preconditions.checkNotNull(this.defaultMotionSpec); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public final void addAnimationListener(Animator.AnimatorListener animatorListener) { | ||||
|         this.listeners.add(animatorListener); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public final void removeAnimationListener(Animator.AnimatorListener animatorListener) { | ||||
|         this.listeners.remove(animatorListener); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public void onAnimationStart(Animator animator) { | ||||
|         this.tracker.onNextAnimationStart(animator); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public void onAnimationEnd() { | ||||
|         this.tracker.clear(); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public void onAnimationCancel() { | ||||
|         this.tracker.clear(); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.floatingactionbutton.MotionStrategy | ||||
|     public AnimatorSet createAnimator() { | ||||
|         return createAnimator(getCurrentMotionSpec()); | ||||
|     } | ||||
|  | ||||
|     AnimatorSet createAnimator(MotionSpec motionSpec) { | ||||
|         ArrayList arrayList = new ArrayList(); | ||||
|         if (motionSpec.hasPropertyValues("opacity")) { | ||||
|             arrayList.add(motionSpec.getAnimator("opacity", this.fab, View.ALPHA)); | ||||
|         } | ||||
|         if (motionSpec.hasPropertyValues("scale")) { | ||||
|             arrayList.add(motionSpec.getAnimator("scale", this.fab, View.SCALE_Y)); | ||||
|             arrayList.add(motionSpec.getAnimator("scale", this.fab, View.SCALE_X)); | ||||
|         } | ||||
|         if (motionSpec.hasPropertyValues("width")) { | ||||
|             arrayList.add(motionSpec.getAnimator("width", this.fab, ExtendedFloatingActionButton.WIDTH)); | ||||
|         } | ||||
|         if (motionSpec.hasPropertyValues("height")) { | ||||
|             arrayList.add(motionSpec.getAnimator("height", this.fab, ExtendedFloatingActionButton.HEIGHT)); | ||||
|         } | ||||
|         if (motionSpec.hasPropertyValues("paddingStart")) { | ||||
|             arrayList.add(motionSpec.getAnimator("paddingStart", this.fab, ExtendedFloatingActionButton.PADDING_START)); | ||||
|         } | ||||
|         if (motionSpec.hasPropertyValues("paddingEnd")) { | ||||
|             arrayList.add(motionSpec.getAnimator("paddingEnd", this.fab, ExtendedFloatingActionButton.PADDING_END)); | ||||
|         } | ||||
|         if (motionSpec.hasPropertyValues("labelOpacity")) { | ||||
|             arrayList.add(motionSpec.getAnimator("labelOpacity", this.fab, new Property<ExtendedFloatingActionButton, Float>(Float.class, "LABEL_OPACITY_PROPERTY") { // from class: com.google.android.material.floatingactionbutton.BaseMotionStrategy.1 | ||||
|                 @Override // android.util.Property | ||||
|                 public Float get(ExtendedFloatingActionButton extendedFloatingActionButton) { | ||||
|                     return Float.valueOf(AnimationUtils.lerp(0.0f, 1.0f, (Color.alpha(extendedFloatingActionButton.getCurrentTextColor()) / 255.0f) / Color.alpha(extendedFloatingActionButton.originalTextCsl.getColorForState(extendedFloatingActionButton.getDrawableState(), BaseMotionStrategy.this.fab.originalTextCsl.getDefaultColor())))); | ||||
|                 } | ||||
|  | ||||
|                 @Override // android.util.Property | ||||
|                 public void set(ExtendedFloatingActionButton extendedFloatingActionButton, Float f) { | ||||
|                     int colorForState = extendedFloatingActionButton.originalTextCsl.getColorForState(extendedFloatingActionButton.getDrawableState(), BaseMotionStrategy.this.fab.originalTextCsl.getDefaultColor()); | ||||
|                     ColorStateList valueOf = ColorStateList.valueOf(Color.argb((int) (AnimationUtils.lerp(0.0f, Color.alpha(colorForState) / 255.0f, f.floatValue()) * 255.0f), Color.red(colorForState), Color.green(colorForState), Color.blue(colorForState))); | ||||
|                     if (f.floatValue() == 1.0f) { | ||||
|                         extendedFloatingActionButton.silentlyUpdateTextColor(extendedFloatingActionButton.originalTextCsl); | ||||
|                     } else { | ||||
|                         extendedFloatingActionButton.silentlyUpdateTextColor(valueOf); | ||||
|                     } | ||||
|                 } | ||||
|             })); | ||||
|         } | ||||
|         AnimatorSet animatorSet = new AnimatorSet(); | ||||
|         AnimatorSetCompat.playTogether(animatorSet, arrayList); | ||||
|         return animatorSet; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user