content: package com.google.android.material.circularreveal;
  
  import android.graphics.Bitmap;
  import android.graphics.BitmapShader;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Path;
  import android.graphics.Rect;
  import android.graphics.Shader;
  import android.graphics.drawable.Drawable;
  import android.os.Build;
  import android.view.View;
  import androidx.core.internal.view.SupportMenu;
  import androidx.core.view.ViewCompat;
  import com.google.android.material.circularreveal.CircularRevealWidget;
  import com.google.android.material.math.MathUtils;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  
  public class CircularRevealHelper {
      public static final int BITMAP_SHADER = 0;
      public static final int CLIP_PATH = 1;
      private static final boolean DEBUG = false;
      public static final int REVEAL_ANIMATOR = 2;
      public static final int STRATEGY;
      private boolean buildingCircularRevealCache;
      private Paint debugPaint;
      private final Delegate delegate;
      private boolean hasCircularRevealCache;
      private Drawable overlayDrawable;
      private CircularRevealWidget.RevealInfo revealInfo;
      private final Paint revealPaint = new Paint(7);
      private final Path revealPath = new Path();
      private final Paint scrimPaint;
      private final View view;
  
      public interface Delegate {
          void actualDraw(Canvas canvas);
  
          boolean actualIsOpaque();
      }
  
      @Retention(RetentionPolicy.SOURCE)
      public @interface Strategy {
      }
  
      static {
          if (Build.VERSION.SDK_INT >= 21) {
              STRATEGY = 2;
          } else if (Build.VERSION.SDK_INT >= 18) {
              STRATEGY = 1;
          } else {
              STRATEGY = 0;
          }
      }
  
      public CircularRevealHelper(Delegate delegate2) {
          this.delegate = delegate2;
          View view2 = (View) delegate2;
          this.view = view2;
          view2.setWillNotDraw(false);
          Paint paint = new Paint(1);
          this.scrimPaint = paint;
          paint.setColor(0);
      }
  
      private void drawDebugCircle(Canvas canvas, int color, float width) {
          this.debugPaint.setColor(color);
          this.debugPaint.setStrokeWidth(width);
          canvas.drawCircle(this.revealInfo.centerX, this.revealInfo.centerY, this.revealInfo.radius - (width / 2.0f), this.debugPaint);
      }
  
      private void drawDebugMode(Canvas canvas) {
          this.delegate.actualDraw(canvas);
          if (shouldDrawScrim()) {
              canvas.drawCircle(this.revealInfo.centerX, this.revealInfo.centerY, this.revealInfo.radius, this.scrimPaint);
          }
          if (shouldDrawCircularReveal()) {
              drawDebugCircle(canvas, ViewCompat.MEASURED_STATE_MASK, 10.0f);
              drawDebugCircle(canvas, SupportMenu.CATEGORY_MASK, 5.0f);
          }
          drawOverlayDrawable(canvas);
      }
  
      private void drawOverlayDrawable(Canvas canvas) {
          if (shouldDrawOverlayDrawable()) {
              Rect bounds = this.overlayDrawable.getBounds();
              float width = this.revealInfo.centerX - (((float) bounds.width()) / 2.0f);
              float height = this.revealInfo.centerY - (((float) bounds.height()) / 2.0f);
              canvas.translate(width, height);
              this.overlayDrawable.draw(canvas);
              canvas.translate(-width, -height);
          }
      }
  
      private float getDistanceToFurthestCorner(CircularRevealWidget.RevealInfo revealInfo2) {
          return MathUtils.distanceToFurthestCorner(revealInfo2.centerX, revealInfo2.centerY, 0.0f, 0.0f, (float) this.view.getWidth(), (float) this.view.getHeight());
      }
  
      private void invalidateRevealInfo() {
          if (STRATEGY == 1) {
              this.revealPath.rewind();
              CircularRevealWidget.RevealInfo revealInfo2 = this.revealInfo;
              if (revealInfo2 != null) {
                  this.revealPath.addCircle(revealInfo2.centerX, this.revealInfo.centerY, this.revealInfo.radius, Path.Direction.CW);
              }
          }
          this.view.invalidate();
      }
  
      private boolean shouldDrawCircularReveal() {
          CircularRevealWidget.RevealInfo revealInfo2 = this.revealInfo;
          boolean z = revealInfo2 == null || revealInfo2.isInvalid();
          return STRATEGY == 0 ? !z && this.hasCircularRevealCache : !z;
      }
  
      private boolean shouldDrawOverlayDrawable() {
          return (this.buildingCircularRevealCache || this.overlayDrawable == null || this.revealInfo == null) ? false : true;
      }
  
      private boolean shouldDrawScrim() {
          return !this.buildingCircularRevealCache && Color.alpha(this.scrimPaint.getColor()) != 0;
      }
  
      public void buildCircularRevealCache() {
          if (STRATEGY == 0) {
              this.buildingCircularRevealCache = true;
              this.hasCircularRevealCache = false;
              this.view.buildDrawingCache();
              Bitmap drawingCache = this.view.getDrawingCache();
              if (!(drawingCache != null || this.view.getWidth() == 0 || this.view.getHeight() == 0)) {
                  drawingCache = Bitmap.createBitmap(this.view.getWidth(), this.view.getHeight(), Bitmap.Config.ARGB_8888);
                  this.view.draw(new Canvas(drawingCache));
              }
              if (drawingCache != null) {
                  this.revealPaint.setShader(new BitmapShader(drawingCache, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
              }
              this.buildingCircularRevealCache = false;
              this.hasCircularRevealCache = true;
          }
      }
  
      public void destroyCircularRevealCache() {
          if (STRATEGY == 0) {
              this.hasCircularRevealCache = false;
              this.view.destroyDrawingCache();
              this.revealPaint.setShader((Shader) null);
              this.view.invalidate();
          }
      }
  
      public void draw(Canvas canvas) {
          if (shouldDrawCircularReveal()) {
              int i = STRATEGY;
              switch (i) {
                  case 0:
                      canvas.drawCircle(this.revealInfo.centerX, this.revealInfo.centerY, this.revealInfo.radius, this.revealPaint);
                      if (shouldDrawScrim()) {
                          canvas.drawCircle(this.revealInfo.centerX, this.revealInfo.centerY, this.revealInfo.radius, this.scrimPaint);
                          break;
                      }
                      break;
                  case 1:
                      int save = canvas.save();
                      canvas.clipPath(this.revealPath);
                      this.delegate.actualDraw(canvas);
                      if (shouldDrawScrim()) {
                          canvas.drawRect(0.0f, 0.0f, (float) this.view.getWidth(), (float) this.view.getHeight(), this.scrimPaint);
                      }
                      canvas.restoreToCount(save);
                      break;
                  case 2:
                      this.delegate.actualDraw(canvas);
                      if (shouldDrawScrim()) {
                          canvas.drawRect(0.0f, 0.0f, (float) this.view.getWidth(), (float) this.view.getHeight(), this.scrimPaint);
                          break;
                      }
                      break;
                  default:
                      throw new IllegalStateException("Unsupported strategy " + i);
              }
          } else {
              this.delegate.actualDraw(canvas);
              if (shouldDrawScrim()) {
                  canvas.drawRect(0.0f, 0.0f, (float) this.view.getWidth(), (float) this.view.getHeight(), this.scrimPaint);
              }
          }
          drawOverlayDrawable(canvas);
      }
  
      public Drawable getCircularRevealOverlayDrawable() {
          return this.overlayDrawable;
      }
  
      public int getCircularRevealScrimColor() {
          return this.scrimPaint.getColor();
      }
  
      public CircularRevealWidget.RevealInfo getRevealInfo() {
          if (this.revealInfo == null) {
              return null;
          }
          CircularRevealWidget.RevealInfo revealInfo2 = new CircularRevealWidget.RevealInfo(this.revealInfo);
          if (revealInfo2.isInvalid()) {
              revealInfo2.radius = getDistanceToFurthestCorner(revealInfo2);
          }
          return revealInfo2;
      }
  
      public boolean isOpaque() {
          return this.delegate.actualIsOpaque() && !shouldDrawCircularReveal();
      }
  
      public void setCircularRevealOverlayDrawable(Drawable drawable) {
          this.overlayDrawable = drawable;
          this.view.invalidate();
      }
  
      public void setCircularRevealScrimColor(int color) {
          this.scrimPaint.setColor(color);
          this.view.invalidate();
      }
  
      public void setRevealInfo(CircularRevealWidget.RevealInfo revealInfo2) {
          if (revealInfo2 == null) {
              this.revealInfo = null;
          } else {
              CircularRevealWidget.RevealInfo revealInfo3 = this.revealInfo;
              if (revealInfo3 == null) {
                  this.revealInfo = new CircularRevealWidget.RevealInfo(revealInfo2);
              } else {
                  revealInfo3.set(revealInfo2);
              }
              if (MathUtils.geq(revealInfo2.radius, getDistanceToFurthestCorner(revealInfo2), 1.0E-4f)) {
                  this.revealInfo.radius = Float.MAX_VALUE;
              }
          }
          invalidateRevealInfo();
      }
  }
  